From 6bba293d3e93729ad6d977be6ecc16ff12fed55a Mon Sep 17 00:00:00 2001 From: Eric Chapman Date: Wed, 22 Sep 2021 14:03:05 -0500 Subject: [PATCH] Closes #138 --- OMPython/OMTypedParser.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/OMPython/OMTypedParser.py b/OMPython/OMTypedParser.py index 84a4f60..bf143d5 100644 --- a/OMPython/OMTypedParser.py +++ b/OMPython/OMTypedParser.py @@ -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)) + @@ -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) @@ -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)