Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ericchapman committed Sep 22, 2021
1 parent 7981c3d commit 6bba293
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions OMPython/OMTypedParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def convertTuple(t):
FALSE = Keyword("false").setParseAction(replaceWith(False))
NONE = (Keyword("NONE") + Suppress("(") + Suppress(")")).setParseAction(replaceWith(None))
SOME = (Suppress(Keyword("SOME")) + Suppress("(") + omcValue + Suppress(")"))
VARIABLE_ARRAY = Keyword(":").setParseAction(replaceWith(":"))

omcString = QuotedString(quoteChar='"', escChar='\\', multiline=True).setParseAction(convertString)
omcNumber = Combine(Optional('-') + ('0' | Word('123456789', nums)) +
Expand All @@ -107,7 +108,7 @@ def convertTuple(t):
omcValues = delimitedList(omcValue)
omcTuple = Group(Suppress('(') + Optional(omcValues) + Suppress(')')).setParseAction(convertTuple)
omcArray = Group(Suppress('{') + Optional(omcValues) + Suppress('}')).setParseAction(convertTuple)
omcValue << (omcString | omcNumber | omcRecord | omcArray | omcTuple | SOME | TRUE | FALSE | NONE | Combine(fqident))
omcValue << (omcString | omcNumber | omcRecord | omcArray | omcTuple | SOME | TRUE | FALSE | NONE | VARIABLE_ARRAY | Combine(fqident))
recordMember = delimitedList(Group(ident + Suppress('=') + omcValue))
omcRecord << Group(Suppress('record') + Suppress(fqident) + Dict(recordMember) + Suppress('end') + Suppress(fqident) + Suppress(';')).setParseAction(convertDict)

Expand All @@ -125,13 +126,13 @@ def parseString(string):

if __name__ == "__main__":
testdata = """
(1.0,{{1,true,3},{"4\\"
(1.0,:,{{1,true,3},{"4\\"
",5.9,6,NONE ( )},record ABC
startTime = ErrorLevel.warning,
'stop*Time' = SOME(1.0)
end ABC;})
"""
expected = (1.0, ((1, True, 3), ('4"\n', 5.9, 6, None), {"'stop*Time'": 1.0, 'startTime': 'ErrorLevel.warning'}))
expected = (1.0, ":", ((1, True, 3), ('4"\n', 5.9, 6, None), {"'stop*Time'": 1.0, 'startTime': 'ErrorLevel.warning'}))
results = parseString(testdata)
if results != expected:
print("Results:", results)
Expand Down

0 comments on commit 6bba293

Please sign in to comment.