modparc.syntax package

Submodules

modparc.syntax.class_definition module

class_definition

Parser definition for funcparserlib. The parsers that need forward declaration are defined as function annotated by the Parser decorator.

The definitions are specified in the Appendix B.2.2 of the Modelica Specification 3.3.

modparc.syntax.class_definition.km(key)[source]

modparc.syntax.component_clause module

component_clause

Parser definition for funcparserlib. The parsers that need forward declaration are defined as function annotated by the Parser decorator.

The definitions are specified in the Appendix B.2.4 of the Modelica Specification 3.3.

modparc.syntax.equations module

equations

Parser definition for funcparserlib. The parsers that need forward declaration are defined as function annotated by the Parser decorator

The definitions are specified in the Appendix B.2.6 of the Modelica Specification 3.3.

Note that there’s no definition for the assertion statement/calls in the specification, so the Assertion parser is separately defined.

modparc.syntax.expressions module

expressions

Parser definition for funcparserlib. The parsers that need forward declaration are defined as function annotated by the Parser decorator

The definitions are specified in the Appendix B.2.7 of the Modelica Specification 3.3.

modparc.syntax.extends module

extends

Parser definition for funcparserlib. The parsers that need forward declaration are defined as function annotated by the Parser decorator.

The definitions are specified in the Appendix B.2.3 of the Modelica Specification 3.3.

modparc.syntax.modification module

modification

Parser definition for funcparserlib. The parsers that need forward declaration are defined as function annotated by the Parser decorator

The definitions are specified in the Appendix B.2.5 of the Modelica Specification 3.3.

modparc.syntax.modification.km(key)[source]

modparc.syntax.stored_definition module

stored_definition

Parser definition for funcparserlib.

The definitions are specified in the Appendix B.2.1 of the Modelica Specification 3.3.

This is the top-level module used by in the library api as it parses the contents of a Modelica source code file (files with suffix .mo).

modparc.syntax.syntax_elements module

syntax_element

Each syntax element is defined as a class in the syntax_element module, to enable basic formatting and query function for the parse tree.

class modparc.syntax.syntax_elements.AddOp(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.AlgorithmSection(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.Annotation(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.Argument(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.ArgumentList(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.ArithmeticExpression(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.ArraySubscript(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.Assertion(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.BasePrefix(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.ClassDefinition(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.ClassModification(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.ClassPrefixes(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.ClassSpecifier(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.Comment(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.ComponentClause(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.ComponentClause1(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.ComponentDeclaration(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.ComponentDeclaration1(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.ComponentList(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.ComponentReference(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.Composition(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.ConditionAttribute(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.ConnectClause(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.ConstrainingClause(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.Declaration(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.Element(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.ElementList(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.ElementModification(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.ElementModificationOrReplaceable(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.ElementRedeclaration(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.ElementReplaceable(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.EnumList(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.EnumerationLiteral(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.Equation(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.EquationSection(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.Expression(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.ExpressionList(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.ExtendsClause(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.ExternalFunctionCall(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.Factor(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.ForEquation(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.ForIndex(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.ForIndices(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.ForStatement(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.FunctionArgument(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.FunctionArguments(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.FunctionCallArgs(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.IfEquation(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.IfStatement(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.ImportClause(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.ImportList(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.LanguageSpecification(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.LogicalExpression(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.LogicalFactor(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.LogicalTerm(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.Modification(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.MulOp(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.Name(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.NamedArgument(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.NamedArguments(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.OutputExpressionList(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.Primary(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.RelOp(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.Relation(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.ShortClassDefinition(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.SimpleExpression(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.Statement(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.StoredDefinition(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.StringComment(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.Subscript(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.SyntaxElement(elements)[source]

Bases: object

The class is a base implementation for all the syntax elements

All the derived classes would inherit this syntax element, and they only differ in their names.

The base implemenation provides possibility for inspection and querying the parsed syntax elements.

code()[source]

Create a predefined representation of all the tokens in the instance

Returns:formatted tokens contained in the instance
static find(syntax_element, type_name, result)[source]

Search the matching elements with pre-order tree trasversal

Parameters:
  • syntax_element – the syntax element to be explored
  • type_name – type name to be searched
  • result – mutable list to store the results
Returns:

no explicit return, communication through result variable

search(type_name)[source]

Create a predefined representation of all the tokens in the instance

Parameters:type_name – use the class name to find all matching subelements
Returns:list of found elements of the class type_name
class modparc.syntax.syntax_elements.Term(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.TypePrefix(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.TypeSpecifier(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.WhenEquation(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.WhenStatement(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.WhileEquation(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

class modparc.syntax.syntax_elements.WhileStatement(elements)

Bases: modparc.syntax.syntax_elements.SyntaxElement

Module contents

syntax

The main utilities module for the parser implementation, with tokenizer and parser creation functions.

modparc.syntax.keyword(key, combinator=<function a>)[source]

Parser to match a keyword token with a key and a combinator

Parameters:
  • key – exact key of the keyword, e.g.: begin, assert etc.
  • combinator – use the combinator to create a parser
Returns:

a parser that matches a keyword

modparc.syntax.language_element(key, tok_type, combinator=<function a>)[source]

Parser to match language element by using a certain combinator

Parameters:
  • key – exact key of the token, e.g.: begin, model, )
  • tok_type – predefined token type to be matched
  • combinator – use the combinator to create a parser
Returns:

a parser that matches elements using the above condition

modparc.syntax.op(key, combinator=<function a>)[source]

Parser to match a operator token with a key and a combinator

Parameters:
  • key – exact key of the operator, e.g.: +, .* etc.
  • combinator – use the combinator to create a parser
Returns:

a parser that matches an operator

modparc.syntax.token_type(tok_type)[source]

Get a parser matching a certain type of tokens

Parameters:tok_type – predefined token type to be matched
Returns:a parser that matches token of type tok_type
modparc.syntax.tokenize(source_code)[source]

Tokenizer according to Modelica Specification §2 and Appendix B.1

Parameters:source_code – source code to be tokenized
Returns:list of tokens created