Next / Previous / Contents / Shipman's homepage

6.5. LINE_PAT

A compiled regular expression that matches a valid input line. We use this to match valid input lines, and also to extract the truth table part and discard any comment that may follow after whitespace. There are two named groups: TRUTH_GROUP is just the truth table part, and TAIL_GROUP is an optional group that matches a whitespace character and whatever follows. The re.IGNORECASE argument specifies case-insensitive matching.

tracecase
TRUTH_GROUP = 't'
TAIL_GROUP = 'z'
LINE_PAT = re.compile(
    r'(?P<{0}>'       # Start TRUTH_GROUP
      r'[{1}]+'       # Matches one or more T, F, or X
    r')'              # End TRUTH_GROUP
    r'(?P<{2}>'       # Start TAIL_GROUP
      r'\s'             # Matches one whitespace character
      r'.*'             # Matches zero or more of anything
    r')?'             # End TAIL_GROUP, and the group is optional
    r'$'              # Matches the end of the line
    .format(TRUTH_GROUP, TRUTH_CODES, TAIL_GROUP),
    re.IGNORECASE)