diff --git a/cobol_testgen/cond.py b/cobol_testgen/cond.py index dd6a83e..2352669 100644 --- a/cobol_testgen/cond.py +++ b/cobol_testgen/cond.py @@ -100,6 +100,9 @@ def parse_single_condition(text, fields=None): # Bare field reference (no operator, no NOT): WS-EOF → WS-EOF = 'Y' if re.match(r'^[A-Z][A-Z0-9_-]*(?:\([^)]*\))?\s*$', text, re.IGNORECASE): + bare = __import__('re').match(r'^[A-Z][A-Z0-9_-]*', text, re.IGNORECASE) + if bare: + return (bare.group(0), '=', 'Y') return (text, '=', 'Y') # Bare NOT field reference (no operator): NOT WS-EOF → WS-EOF <> 'Y' @@ -159,6 +162,10 @@ def parse_single_condition(text, fields=None): # Clean trailing ' NOT' that got swallowed by lazy match if field.upper().endswith(' NOT'): field = field[:-4].strip() + # Strip subscript: WS-KEY-DUP-CNT(WS-J) -> WS-KEY-DUP-CNT + bare_m = __import__('re').match(r'^(\w[\w-]*)', field) + if bare_m: + field = bare_m.group(1) return (field, m.group(2), m.group(3).strip().strip("'").strip('"')) # Standard regex: FIELD OP VALUE @@ -176,6 +183,9 @@ def parse_single_condition(text, fields=None): # Bare field: WS-EOF (no operator) -> WS-EOF = 'Y' if re.match(r'^[A-Z][A-Z0-9_-]*(?:\([^)]*\))?\s*$', text, re.IGNORECASE): + bare = __import__('re').match(r'^[A-Z][A-Z0-9_-]*', text, re.IGNORECASE) + if bare: + return (bare.group(0), '=', 'Y') return (text, '=', 'Y') return None