def primary(tokens, state): kw = keyword parser = (token_type("number") | token_type("string") | kw("false") | kw("true") | (name | kw("der") | kw("initial")) + function_call_args | component_reference | op("(") + output_expression_list + op(")") | (op("[") + expression_list + maybe(many(op(";") + expression_list)) + op("]")) | op("{") + function_arguments + op("}") | kw("end")) return (parser >> Primary).run(tokens, state)
def short_class_definition(tokens, state): # circular import! from modparc.syntax.class_definition import (class_prefixes, enum_list, base_prefix) parser = (class_prefixes + token_type("ident") + op("=") + (base_prefix + name + maybe(array_subscript) + maybe(class_modification) + comment | keyword('enumeration') + op('(') + (maybe(enum_list) | op(":")) + op(')') + comment)) return (parser >> ShortClassDefinition).run(tokens, state)
def class_specifier(tokens, state): normal = (token_type('ident') + string_comment + composition + keyword('end') + token_type('ident')) derived = (token_type('ident') + op("=") + base_prefix + name + maybe(array_subscript) + maybe(class_modification) + comment) enum_def = (token_type('ident') + op("=") + keyword('enumeration') + op("(") + (maybe(enum_list) | op(":")) + op(")") + comment) derivative = (token_type('ident') + op("=") + keyword('der') + op("(") + name + op(",") + token_type('ident') + maybe(many(op(",") + token_type('ident'))) + op(")") + comment) extended = (keyword('extends') + token_type('ident') + maybe(class_modification) + string_comment + composition + keyword("end") + token_type('ident')) parser = (normal | derived | enum_def | derivative | extended) return (parser >> ClassSpecifier).run(tokens, state)
# pylint: disable=no-name-in-module, missing-docstring from modparc.syntax import keyword, op, token_type from modparc.syntax.expressions import (expression, simple_expression, name, comment, function_call_args, component_reference, output_expression_list) from modparc.syntax.syntax_elements import ( ForIndex, ForIndices, ConnectClause, Equation, IfEquation, ForEquation, WhileEquation, WhenEquation, Statement, IfStatement, ForStatement, WhileStatement, WhenStatement, EquationSection, AlgorithmSection, Assertion) # pylint: enable=no-name-in-module for_index = ( token_type('ident') + maybe(keyword('in') + expression) >> ForIndex) for_indices = for_index + maybe(many(op(',') + for_index)) >> ForIndices connect_clause = (keyword("connect") + op("(") + component_reference + op(",") + component_reference + op(")")) >> ConnectClause assertion = keyword("assert") + function_call_args >> Assertion @Parser def equation(tokens, state): parser = ((simple_expression + op("=") + expression | if_equation | for_equation | connect_clause
from modparc.syntax import keyword, op, token_type from modparc.syntax.component_clause import type_prefix, component_clause from modparc.syntax.equations import equation_section, algorithm_section from modparc.syntax.expressions import (name, comment, annotation, string_comment, component_reference, array_subscript, expression_list) from modparc.syntax.extends import extends_clause, constraining_clause from modparc.syntax.modification import class_modification from modparc.syntax.syntax_elements import ( LanguageSpecification, BasePrefix, ExternalFunctionCall, ClassDefinition, Element, ElementList, Composition, ClassSpecifier, ClassPrefixes, EnumerationLiteral, EnumList, ImportList, ImportClause) # pylint: enable=no-name-in-module language_specification = token_type('string') >> LanguageSpecification base_prefix = type_prefix >> BasePrefix external_function_call = ( maybe(component_reference + op("=")) + token_type('ident') + op("(") + maybe(expression_list) + op(")") >> ExternalFunctionCall) @Parser def class_definition(tokens, state): parser = maybe(keyword("encapsulated")) + class_prefixes + class_specifier return (parser >> ClassDefinition).run(tokens, state) def km(key):
def named_argument(tokens, state): parser = token_type('ident') + op('=') + function_argument return (parser >> NamedArgument).run(tokens, state)
""" from funcparserlib.parser import many, maybe, Parser # pylint: disable=no-name-in-module, missing-docstring from modparc.syntax import keyword, op, token_type from modparc.syntax.syntax_elements import ( Expression, SimpleExpression, LogicalExpression, LogicalTerm, LogicalFactor, Relation, ArithmeticExpression, Term, Factor, Primary, RelOp, MulOp, AddOp, Name, NamedArgument, NamedArguments, FunctionArgument, FunctionArguments, FunctionCallArgs, ExpressionList, OutputExpressionList, Subscript, ArraySubscript, ComponentReference, StringComment, Annotation, Comment) # pylint: enable=no-name-in-module name = (maybe(op(".")) + (token_type("ident") | keyword("assert")) + maybe(many(op(".") + (token_type("ident") | keyword("assert")))) >> Name) rel_op = op("<") | op("<=") | op(">") | op(">=") | op("==") | op("<>") >> RelOp add_op = op("+") | op("-") | op(".+") | op(".-") >> AddOp mul_op = op("*") | op("/") | op(".*") | op("./") >> MulOp @Parser def primary(tokens, state): kw = keyword parser = (token_type("number") | token_type("string")
def declaration(tokens, state): from .modification import modification parser = (token_type('ident') + maybe(array_subscript) + maybe(modification)) >> Declaration return parser.run(tokens, state)