Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

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 by Splicer.py to run required actions by instantiating TM1SpliceExecutor 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

directives_resolver

TM1DirectiveResolver

Instance of directive resolver used for splicing (Containers (package)) of the rule.

regions

TM1RegionContainer

Regions container for splicing of the rule.

parser

Parser

Instance of parser (Parser/Grammar (package)) to be used to parse the rule.

current_rule_id

TM1RuleID

Checksum of the current rule calculated from the rule source code (unused).

generate_rule_id

bool

Flag indicating whether to generate rule IDs or not.

The class exposes following methods:

Method

Usage

make_empty_line

Create a TM1RuleToken instance representing an empty line.

make_comment

Creates a TM1RuleToken instance representing a comment or a directive.

make_command

Creates a TM1RuleToken or TM1RuleCommand instance based on type of parsed token. TM1RuleCommand instance will be created for calculation rule or a feeder rule (CalcRule non-terminal symbol in grammar), an instance of TM1RuleToken in other cases (skipcheck, feeders, feedstrings).

begin_region

Creates instance of TM1RegionStart when #Region was parsed.

end_region

Creates instance of TM1RegionEnd when #EndRegion was parsed.

make_directive

Will call directives_resolver.consume_directive to create an instance of a new TM1Directive in the directives_resolver.directives_by_scope internal store when the parser parsed a directive.

make_calc_rule

Creates a TM1CalcRule instance when a calculation rule statement was parsed.

make_feeder_rule

Creates a TM1CalcRule instance when a feeder rule statement was parsed.

make_area_statement

Creates a TM1RuleAreaStatement instance when an area statement of calculation or a feeder rule was parsed. The instance of the class is area_statementproperty of TM1CalcRule created by make_calc_rule or make_feeder_rule.

make_ident

Returns a string representing an identifier parsed by the parser - for example it may be a dimension, hierarchy or element name.

make_catalog_key

Returns a string representing an ID to use to retrieve MDX query from fpm.json Catalog object that is associated with a directive that has been parsed.

make_region_definition

add_dim_to_map

add_dim_to_map2

make_dim_elem_pair

make_hier_elem

ignore_dim_elem_pair

make_elem_list

make_elem_list2

make_mdx_query

make_hex_footprint

make_rule_id

splice_rule

get_rule

get_parse_tree

locate_region_subtrees

exclude_subtree

inject_subtree

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.

  • No labels