Parser for mini-language specifying profile and class requirements. We call the language LMIReSpL (openLMI Requirement Specification Language).
The only thing designed for use outside this module is bnf_parser().
Language is generated by BNF grammer which served as a model for parser.
Formal representation of BNF grammer is following:
expr ::= term [ op expr ]*
term ::= '!'? req
req ::= profile_cond | clsreq_cond | '(' expr ')'
profile_cond ::= 'profile'? [ profile | profile_quot ] cond?
clsreq_cond ::= 'class' [ clsname | clsname_quot] cond?
profile_quot ::= '"' /\w+[ +.a-zA-Z0-9_-]*/ '"'
profile ::= /\w+[+.a-zA-Z_-]*/
clsname_quot ::= '"' clsname '"'
clsname ::= /[a-zA-Z]+_[a-zA-Z][a-zA-Z0-9_]*/
cond ::= cmpop version
cmpop ::= /(<|=|>|!)=|<|>/
version ::= /[0-9]+(\.[0-9]+)*/
op ::= '&' | '|'
String surrounded by quotes is a literal. String enclosed with slashes is a regular expression. Square brackets encloses a group of words and limit the scope of some operation (like iteration).
Represents logical AND of two expressions. Short-circuit evaluation is being exploited here.
Parameters: |
---|
Initial non-terminal. Object of this class (or one of its subclasses) is a result of parsing.
Parameters: | term – An object of Term non-terminal. |
---|
Dictionary mapping supported comparison operators to a pair. First item is a function making the comparison and the second can be of two values (all or any). Former sayes that each part of first version string must be in relation to corresponding part of second version string in order to satisfy the condition. The latter causes the comparison to end on first satisfied part.
Represents logical OR of two expressions. Short-circuit evaluation is being exploited here.
Parameters: |
---|
Represents one of following subexpressions:
- single requirement on particular profile
- single requirement on particular class
- a subexpression
Represents single requirement on particular class or profile.
Parameters: |
|
---|
Base class for non-terminals. Just a minimal set of non-terminals is represented by objects the rest is represented by strings.
All subclasses need to define their own evaluate() method. The parser builds a tree of these non-terminals with single non-terminal being a root node. This node’s evaluate method returns a boolean saying whether the condition is satisfied. Root node is always an object of Expr.
Represents a subexpression originally enclosed in brackets.
Represents possible negation of expression.
Parameters: |
|
---|
A stack interface for parser. It defines methods modifying the stack with additional checks.
Operates upon a stack. It takes either one or two terms there and makes an expression object out of them. Terms need to be delimited with logical operator.
Handles clsreq_cond non-terminal in one go. It extracts corresponding tokens and pushes an object of ReqCond to a stack.
Handles profile_cond non-terminal in one go. It behaves in the same way as push_profile().
Builds a parser operating on provided stack.
Parameters: |
|
---|---|
Returns: | Parser object. |
Return type: | pyparsing,ParserElement |
Compare two version specifications. Each version string shall contain digits delimited with dots. Empty string is also valid version. It will be replaced with -1.
Parameters: |
|
---|---|
Returns: | True if the relation denoted by particular operation exists between two operands. |
Return type: | boolean |