The package represents parsing functionality of Splicer and contains following classes:
TM1RuleParser
- implements custom actions that get called from the generated parser to create object tree representing parsed TM1 rule.ArgumentParser
- implements CLI parsing and is used bySplicer.py
to run required actions by instantiatingTM1SpliceExecutor
and running its method corresponding to the action required from CLI.
TM1RuleParser (class in TM1RuleParser.py)
This class is responsible to translate parsed rule into objects in memory that represent the parsed syntax. Methods with name starting with make_
or add_
match custom actions as defined in TM1RuleGrammar.peg
(described later). These methods are called during parsing of the TM1 rule and are fed with data from the parser defined in TM1RuleGrammar.py
.
Let’s explain how the parser stores the parsed rule in memory on following example.
Note: The below code is a simplified rule content to demonstrate parsing and resulting representation in memory, it doesn’t represent a functional rule.
SKIPCHECK; FEEDSTRINGS; #Expand-Area-Definition(ACT_YEARS, id_ACT_YEARS):'T Year':@mdx #Region ACT_YEARS [ 'T Month':'T Month':'M00', 'T Year':'T Year':'2023' ] = N:0; #EndRegion ACT_YEARS
This rule will be parsed by the TM1RuleParser
method get_parse_tree
and the parsing result will be returned in an instance of TM1Splice.Parser.Grammar.TM1RuleGrammar.TreeNode
class. The class contains elements
property, which is a list of parsed tokens. You may see a simplified representation of the parsed rule on below picture.
The class defines following attributes:
Attribute | Type | Usage |
---|---|---|
| ||
| ||
| ||
| ||
|
ArgumentParser (class in ArgumentParser.py)
The class implements command line parsing and is used by main application defined in Splicer.py
.
The class is using argparse
library which doesn’t allow too much flexibility as library click
does. Consider changing the library to allow better CLI user experience. The class might also serve as support to expose Splicer as a web service and provide basic parsing of web service headers.