lems.parser package¶
Submodules¶
lems.parser.LEMS module¶
LEMS XML file format parser.
- author:
Gautham Ganapathy
- organization:
- class lems.parser.LEMS.LEMSFileParser(model, include_dirs=[], include_includes=True)¶
Bases:
LEMSBase
LEMS XML file format parser class.
- id_counter¶
Counter generator for generating unique ids.
- Type:
generator(int)
- include_dirs¶
List of directories to search for included files.
- Type:
list(str)
- include_includes¶
Whether to include LEMS definitions in <Include> elements
- Type:
boolean
- init_parser()¶
Initializes the parser
- model¶
Model instance to be populated from the parsed file.
- Type:
- parse(xmltext)¶
Parse a string containing LEMS XML text.
- Parameters:
xmltext (str) – String containing LEMS XML formatted text.
- parse_assertion(node)¶
Parses <Assertion>
- Parameters:
node (xml.etree.Element) – Node containing the <Assertion> element
- parse_attachments(node)¶
Parses <Attachments>
- Parameters:
node (xml.etree.Element) – Node containing the <Attachments> element
- parse_case(node)¶
Parses <Case>
- Parameters:
node (xml.etree.Element) – Node containing the <Case> element
- Raises:
ParseError – When no condition or value is specified
- parse_child(node)¶
Parses <Child>
- Parameters:
node (xml.etree.Element) – Node containing the <Child> element
- parse_child_instance(node)¶
Parses <ChildInstance>
- Parameters:
node (xml.etree.Element) – Node containing the <ChildInstance> element
- parse_children(node)¶
Parses <Children>
- Parameters:
node (xml.etree.Element) – Node containing the <Children> element
- parse_component(node)¶
Parses <Component>
- Parameters:
node (xml.etree.Element) – Node containing the <Component> element
- parse_component_by_typename(node, type_)¶
Parses components defined directly by component name.
- Parameters:
node (xml.etree.Element) – Node containing the <Component> element
type (string) – Type of this component.
- Raises:
ParseError – Raised when the component does not have an id.
- parse_component_reference(node)¶
Parses <ComponentReference>
- Parameters:
node (xml.etree.Element) – Node containing the <ComponentTypeRef> element
- parse_component_requirement(node)¶
Parses <ComponentRequirement>
- Parameters:
node (xml.etree.Element) – Node containing the <ComponentRequirement> element
- parse_component_type(node)¶
Parses <ComponentType>
- Parameters:
node (xml.etree.Element) – Node containing the <ComponentType> element
- Raises:
ParseError – Raised when the component type does not have a name.
- parse_conditional_derived_variable(node)¶
Parses <ConditionalDerivedVariable>
- Parameters:
node (xml.etree.Element) – Node containing the <ConditionalDerivedVariable> element
- Raises:
ParseError – Raised when no name or value is specified for the conditional derived variable.
- parse_constant(node)¶
Parses <Constant>
- Parameters:
node (xml.etree.Element) – Node containing the <Constant> element
- parse_data_display(node)¶
Parses <DataDisplay>
- Parameters:
node (xml.etree.Element) – Node containing the <DataDisplay> element
- parse_data_writer(node)¶
Parses <DataWriter>
- Parameters:
node (xml.etree.Element) – Node containing the <DataWriter> element
- parse_derived_parameter(node)¶
Parses <DerivedParameter>
- Parameters:
node (xml.etree.Element) – Node containing the <DerivedParameter> element
- parse_derived_variable(node)¶
Parses <DerivedVariable>
- Parameters:
node (xml.etree.Element) – Node containing the <DerivedVariable> element
- Raises:
ParseError – Raised when no name of specified for the derived variable.
- parse_dimension(node)¶
Parses <Dimension>
- Parameters:
node (xml.etree.Element) – Node containing the <Dimension> element
- Raises:
ParseError – When the name is not a string or if the dimension is not a signed integer.
- parse_dynamics(node)¶
Parses <Dynamics>
- Parameters:
node (xml.etree.Element) – Node containing the <Behaviour> element
- parse_event_connection(node)¶
Parses <EventConnection>
- Parameters:
node (xml.etree.Element) – Node containing the <EventConnection> element
- parse_event_out(node)¶
Parses <EventOut>
- Parameters:
node (xml.etree.Element) – Node containing the <EventOut> element
- parse_event_port(node)¶
Parses <EventPort>
- Parameters:
node (xml.etree.Element) – Node containing the <EventPort> element
- parse_event_record(node)¶
Parses <EventRecord>
- Parameters:
node (xml.etree.Element) – Node containing the <EventRecord> element
- parse_event_writer(node)¶
Parses <EventWriter>
- Parameters:
node (xml.etree.Element) – Node containing the <EventWriter> element
- parse_exposure(node)¶
Parses <Exposure>
- Parameters:
node (xml.etree.Element) – Node containing the <Exposure> element
- Raises:
ParseError – Raised when the exposure name is not being defined in the context of a component type.
- parse_fixed(node)¶
Parses <Fixed>
- Parameters:
node (xml.etree.Element) – Node containing the <Fixed> element
- parse_for_each(node)¶
Parses <ForEach>
- Parameters:
node (xml.etree.Element) – Node containing the <ForEach> element
- parse_include(node)¶
Parses <Include>
- Parameters:
node (xml.etree.Element) – Node containing the <Include> element
- Raises:
ParseError – Raised when the file to be included is not specified.
- parse_index_parameter(node)¶
Parses <IndexParameter>
- Parameters:
node (xml.etree.Element) – Node containing the <IndexParameter> element
- Raises:
ParseError – Raised when the IndexParameter does not have a name.
- parse_instance_requirement(node)¶
Parses <InstanceRequirement>
- Parameters:
node (xml.etree.Element) – Node containing the <InstanceRequirement> element
- parse_kinetic_scheme(node)¶
Parses <KineticScheme>
- Parameters:
node (xml.etree.Element) – Node containing the <KineticScheme> element
- parse_link(node)¶
Parses <Link>
- Parameters:
node (xml.etree.Element) – Node containing the <Link> element
- parse_multi_instantiate(node)¶
Parses <MultiInstantiate>
- Parameters:
node (xml.etree.Element) – Node containing the <MultiInstantiate> element
- parse_on_condition(node)¶
Parses <OnCondition>
- Parameters:
node (xml.etree.Element) – Node containing the <OnCondition> element
- parse_on_entry(node)¶
Parses <OnEntry>
- Parameters:
node (xml.etree.Element) – Node containing the <OnEntry> element
- parse_on_event(node)¶
Parses <OnEvent>
- Parameters:
node (xml.etree.Element) – Node containing the <OnEvent> element
- parse_on_start(node)¶
Parses <OnStart>
- Parameters:
node (xml.etree.Element) – Node containing the <OnStart> element
- parse_parameter(node)¶
Parses <Parameter>
- Parameters:
node (xml.etree.Element) – Node containing the <Parameter> element
- Raises:
ParseError – Raised when the parameter does not have a name.
ParseError – Raised when the parameter does not have a dimension.
- parse_path(node)¶
Parses <Path>
- Parameters:
node (xml.etree.Element) – Node containing the <Path> element
- parse_property(node)¶
Parses <Property>
- Parameters:
node (xml.etree.Element) – Node containing the <Property> element
- Raises:
ParseError – Raised when the property does not have a name.
ParseError – Raised when the property does not have a dimension.
- parse_record(node)¶
Parses <Record>
- Parameters:
node (xml.etree.Element) – Node containing the <Record> element
- parse_regime(node)¶
Parses <Regime>
- Parameters:
node (xml.etree.Element) – Node containing the <Behaviour> element
- parse_requirement(node)¶
Parses <Requirement>
- Parameters:
node (xml.etree.Element) – Node containing the <Requirement> element
- parse_run(node)¶
Parses <Run>
- Parameters:
node (xml.etree.Element) – Node containing the <Run> element
- parse_show(node)¶
Parses <Show>
- Parameters:
node (xml.etree.Element) – Node containing the <Show> element
- parse_simulation(node)¶
Parses <Simulation>
- Parameters:
node (xml.etree.Element) – Node containing the <Simulation> element
- parse_state_assignment(node)¶
Parses <StateAssignment>
- Parameters:
node (xml.etree.Element) – Node containing the <StateAssignment> element
- parse_state_variable(node)¶
Parses <StateVariable>
- Parameters:
node (xml.etree.Element) – Node containing the <StateVariable> element
- Raises:
ParseError – Raised when the state variable is not being defined in the context of a component type.
- parse_structure(node)¶
Parses <Structure>
- Parameters:
node (xml.etree.Element) – Node containing the <Structure> element
- parse_target(node)¶
Parses <Target>
- Parameters:
node (xml.etree.Element) – Node containing the <Target> element
- parse_text(node)¶
Parses <Text>
- Parameters:
node (xml.etree.Element) – Node containing the <Text> element
- parse_time_derivative(node)¶
Parses <TimeDerivative>
- Parameters:
node (xml.etree.Element) – Node containing the <TimeDerivative> element
- Raises:
ParseError – Raised when the time derivative does not hava a variable name of a value.
- parse_transition(node)¶
Parses <Transition>
- Parameters:
node (xml.etree.Element) – Node containing the <Transition> element
- parse_tunnel(node)¶
Parses <Tunnel>
- Parameters:
node (xml.etree.Element) – Node containing the <Tunnel> element
- Raises:
ParseError – Raised when the Tunnel does not have a name.
- parse_unit(node)¶
Parses <Unit>
- Parameters:
node (xml.etree.Element) – Node containing the <Unit> element
- Raises:
ParseError – When the name is not a string or the unit specfications are incorrect.
ModelError – When the unit refers to an undefined dimension.
- parse_with(node)¶
Parses <With>
- Parameters:
node (xml.etree.Element) – Node containing the <With> element
- process_nested_tags(node, tag='')¶
Process child tags.
- Parameters:
node (xml.etree.Element) – Current node being parsed.
- Raises:
ParseError – Raised when an unexpected nested tag is found.
- raise_error(message, *params, **key_params)¶
Raise a parse error.
- tag_parse_table¶
Dictionary of xml tags to parse methods
- Type:
dict(string, function)
- valid_children¶
Dictionary mapping each tag to it’s list of valid child tags.
- Type:
dict(string, string)
- class lems.parser.LEMS.LEMSXMLNode(pyxmlnode)¶
Bases:
object
- lems.parser.LEMS.get_nons_tag_from_node(node)¶
lems.parser.expr module¶
Expression parser
- author:
Gautham Ganapathy
- organization:
- class lems.parser.expr.ExprNode(type)¶
Bases:
LEMSBase
Base class for a node in the expression parse tree.
- FUNC1 = 3¶
- OP = 1¶
- VALUE = 2¶
- type¶
Node type.
- Type:
enum(ExprNode.OP, ExprNode.VALUE)
- class lems.parser.expr.ExprParser(parse_string)¶
Bases:
LEMSBase
Parser class for parsing an expression and generating a parse tree.
- cleanup_stacks()¶
- debug = False¶
- depth = 0¶
Dictionary mapping operators to their priorities.
- Type:
dict(string, Integer)
- is_func(str)¶
Checks if a token string contains a function.
- Parameters:
str (string) – Token string to be checked.
- Returns:
True if the token string contains a function.
- Return type:
Boolean
- is_op(str)¶
Checks if a token string contains an operator.
- Parameters:
str (string) – Token string to be checked.
- Returns:
True if the token string contains an operator.
- Return type:
Boolean
- is_sym(str)¶
Checks if a token string contains a symbol.
- Parameters:
str (string) – Token string to be checked.
- Returns:
True if the token string contains a symbol.
- Return type:
Boolean
- make_op_node(op, right)¶
- op_priority = {'$': -5, '*': 6, '+': 5, '-': 5, '.and.': 1, '.eq.': 2, '.ge.': 2, '.geq.': 2, '.gt.': 2, '.le.': 2, '.lt.': 2, '.ne.': 2, '.neq.': 2, '.or.': 1, '/': 6, '^': 7, 'exp': 8, 'func': 8, '~': 8}¶
- parse()¶
Tokenizes and parses an arithmetic expression into a parse tree.
- Returns:
Returns a token string.
- Return type:
- parse2()¶
- parse_string¶
Expression to be parsed.
- Type:
string
- parse_token_list_rec(min_precedence)¶
Parses a tokenized arithmetic expression into a parse tree. It calls itself recursively to handle bracketed subexpressions.
- Returns:
Returns a token string.
- Return type:
@attention: Does not handle unary minuses at the moment. Needs to be fixed.
- priority(op)¶
- token_list¶
List of tokens from the expression to be parsed.
- Type:
list(string)
- tokenize()¶
Tokenizes the string stored in the parser object into a list of tokens.
- class lems.parser.expr.Func1Node(func, param)¶
Bases:
ExprNode
Unary function node in an expression parse tree. This will always be a non-leaf node.
- func¶
Funcion stored in this node.
- Type:
string
- param¶
Parameter.
- to_python_expr()¶
Module contents¶
- author:
Gautham Ganapathy
- organization: