The Virtual Brain Project

Table Of Contents

Previous topic

model Package

Next topic

run Package

This Page

parser Package

@author: Gautham Ganapathy @organization: LEMS (http://neuroml.org/lems/, https://github.com/organizations/LEMS) @contact: gautham@lisphacker.org

LEMS

LEMS XML file format parser.

@author: Gautham Ganapathy @organization: LEMS (http://neuroml.org/lems/, https://github.com/organizations/LEMS) @contact: gautham@lisphacker.org

MAvdVlag: altered attributes for constants, state_variables, derived_variables, time_derivatives, conditional_derived_variable and exposures

class tvb.dsl_cuda.lems.parser.LEMS.LEMSFileParser(model, include_dirs=[], include_includes=True)[source]

Bases: lems.base.base.LEMSBase

LEMS XML file format parser class.

id_counter = None

Counter generator for generating unique ids. @type: generator(int)

include_dirs = None

List of directories to search for included files. @type: list(str)

include_includes = None

Whether to include LEMS definitions in <Include> elements @type: boolean

init_parser()[source]

Initializes the parser

model = None

Model instance to be populated from the parsed file. @type: lems.model.model.Model

parse(xmltext)[source]

Parse a string containing LEMS XML text.

@param xmltext: String containing LEMS XML formatted text. @type xmltext: str

parse_assertion(node)[source]

Parses <Assertion>

@param node: Node containing the <Assertion> element @type node: xml.etree.Element

parse_attachments(node)[source]

Parses <Attachments>

@param node: Node containing the <Attachments> element @type node: xml.etree.Element

parse_case(node)[source]

Parses <Case>

@param node: Node containing the <Case> element @type node: xml.etree.Element

@raise ParseError: When no condition or value is specified

parse_child(node)[source]

Parses <Child>

@param node: Node containing the <Child> element @type node: xml.etree.Element

parse_child_instance(node)[source]

Parses <ChildInstance>

@param node: Node containing the <ChildInstance> element @type node: xml.etree.Element

parse_children(node)[source]

Parses <Children>

@param node: Node containing the <Children> element @type node: xml.etree.Element

parse_component(node)[source]

Parses <Component>

@param node: Node containing the <Component> element @type node: xml.etree.Element

parse_component_by_typename(node, type_)[source]

Parses components defined directly by component name.

@param node: Node containing the <Component> element @type node: xml.etree.Element

@param type_: Type of this component. @type type_: string

@raise ParseError: Raised when the component does not have an id.

parse_component_reference(node)[source]

Parses <ComponentReference>

@param node: Node containing the <ComponentTypeRef> element @type node: xml.etree.Element

parse_component_requirement(node)[source]

Parses <ComponentRequirement>

@param node: Node containing the <ComponentRequirement> element @type node: xml.etree.Element

parse_component_type(node)[source]

Parses <ComponentType>

@param node: Node containing the <ComponentType> element @type node: xml.etree.Element

@raise ParseError: Raised when the component type does not have a name.

parse_conditional_derived_variable(node)[source]

Parses <ConditionalDerivedVariable>

@param node: Node containing the <ConditionalDerivedVariable> element @type node: xml.etree.Element

@raise ParseError: Raised when no name or value is specified for the conditional derived variable.

parse_constant(node)[source]

Parses <Constant>

@param node: Node containing the <Constant> element @type node: xml.etree.Element

MV: fixed the symbol part. It was not there for constant parsing

parse_data_display(node)[source]

Parses <DataDisplay>

@param node: Node containing the <DataDisplay> element @type node: xml.etree.Element

parse_data_writer(node)[source]

Parses <DataWriter>

@param node: Node containing the <DataWriter> element @type node: xml.etree.Element

parse_derived_parameter(node)[source]

Parses <DerivedParameter>

@param node: Node containing the <DerivedParameter> element @type node: xml.etree.Element

parse_derived_variable(node)[source]

Parses <DerivedVariable>

@param node: Node containing the <DerivedVariable> element @type node: xml.etree.Element

@raise ParseError: Raised when no name of specified for the derived variable.

parse_dimension(node)[source]

Parses <Dimension>

@param node: Node containing the <Dimension> element @type node: xml.etree.Element

@raise ParseError: When the name is not a string or if the dimension is not a signed integer.

parse_dynamics(node)[source]

Parses <Dynamics>

@param node: Node containing the <Behaviour> element @type node: xml.etree.Element

parse_event_connection(node)[source]

Parses <EventConnection>

@param node: Node containing the <EventConnection> element @type node: xml.etree.Element

parse_event_out(node)[source]

Parses <EventOut>

@param node: Node containing the <EventOut> element @type node: xml.etree.Element

parse_event_port(node)[source]

Parses <EventPort>

@param node: Node containing the <EventPort> element @type node: xml.etree.Element

parse_event_record(node)[source]

Parses <EventRecord>

@param node: Node containing the <EventRecord> element @type node: xml.etree.Element

parse_event_writer(node)[source]

Parses <EventWriter>

@param node: Node containing the <EventWriter> element @type node: xml.etree.Element

parse_exposure(node)[source]

Parses <Exposure>

@param node: Node containing the <Exposure> element @type node: xml.etree.Element

@raise ParseError: Raised when the exposure name is not being defined in the context of a component type.

parse_fixed(node)[source]

Parses <Fixed>

@param node: Node containing the <Fixed> element @type node: xml.etree.Element

parse_for_each(node)[source]

Parses <ForEach>

@param node: Node containing the <ForEach> element @type node: xml.etree.Element

parse_function(node)[source]

Parses <Function>

@param node: Node containing the <Function> element @type node: xml.etree.Element

MV: added function for pre and post coupling behavior

parse_include(node)[source]

Parses <Include>

@param node: Node containing the <Include> element @type node: xml.etree.Element

@raise ParseError: Raised when the file to be included is not specified.

parse_index_parameter(node)[source]

Parses <IndexParameter>

@param node: Node containing the <IndexParameter> element @type node: xml.etree.Element

@raise ParseError: Raised when the IndexParameter does not have a name.

parse_instance_requirement(node)[source]

Parses <InstanceRequirement>

@param node: Node containing the <InstanceRequirement> element @type node: xml.etree.Element

parse_kinetic_scheme(node)[source]

Parses <KineticScheme>

@param node: Node containing the <KineticScheme> element @type node: xml.etree.Element

Parses <Link>

@param node: Node containing the <Link> element @type node: xml.etree.Element

parse_multi_instantiate(node)[source]

Parses <MultiInstantiate>

@param node: Node containing the <MultiInstantiate> element @type node: xml.etree.Element

parse_on_condition(node)[source]

Parses <OnCondition>

@param node: Node containing the <OnCondition> element @type node: xml.etree.Element

parse_on_entry(node)[source]

Parses <OnEntry>

@param node: Node containing the <OnEntry> element @type node: xml.etree.Element

parse_on_event(node)[source]

Parses <OnEvent>

@param node: Node containing the <OnEvent> element @type node: xml.etree.Element

parse_on_start(node)[source]

Parses <OnStart>

@param node: Node containing the <OnStart> element @type node: xml.etree.Element

parse_parameter(node)[source]

Parses <Parameter>

@param node: Node containing the <Parameter> element @type node: xml.etree.Element

@raise ParseError: Raised when the parameter does not have a name. @raise ParseError: Raised when the parameter does not have a dimension.

parse_path(node)[source]

Parses <Path>

@param node: Node containing the <Path> element @type node: xml.etree.Element

parse_property(node)[source]

Parses <Property>

@param node: Node containing the <Property> element @type node: xml.etree.Element

@raise ParseError: Raised when the property does not have a name. @raise ParseError: Raised when the property does not have a dimension.

parse_record(node)[source]

Parses <Record>

@param node: Node containing the <Record> element @type node: xml.etree.Element

parse_regime(node)[source]

Parses <Regime>

@param node: Node containing the <Behaviour> element @type node: xml.etree.Element

parse_requirement(node)[source]

Parses <Requirement>

@param node: Node containing the <Requirement> element @type node: xml.etree.Element

parse_run(node)[source]

Parses <Run>

@param node: Node containing the <Run> element @type node: xml.etree.Element

parse_show(node)[source]

Parses <Show>

@param node: Node containing the <Show> element @type node: xml.etree.Element

parse_simulation(node)[source]

Parses <Simulation>

@param node: Node containing the <Simulation> element @type node: xml.etree.Element

parse_state_assignment(node)[source]

Parses <StateAssignment>

@param node: Node containing the <StateAssignment> element @type node: xml.etree.Element

parse_state_variable(node)[source]

Parses <StateVariable>

@param node: Node containing the <StateVariable> element @type node: xml.etree.Element

@raise ParseError: Raised when the state variable is not being defined in the context of a component type.

parse_structure(node)[source]

Parses <Structure>

@param node: Node containing the <Structure> element @type node: xml.etree.Element

parse_target(node)[source]

Parses <Target>

@param node: Node containing the <Target> element @type node: xml.etree.Element

parse_text(node)[source]

Parses <Text>

@param node: Node containing the <Text> element @type node: xml.etree.Element

parse_time_derivative(node)[source]

Parses <TimeDerivative>

@param node: Node containing the <TimeDerivative> element @type node: xml.etree.Element

@raise ParseError: Raised when the time derivative does not hava a variable name of a value.

parse_transition(node)[source]

Parses <Transition>

@param node: Node containing the <Transition> element @type node: xml.etree.Element

parse_tunnel(node)[source]

Parses <Tunnel>

@param node: Node containing the <Tunnel> element @type node: xml.etree.Element

@raise ParseError: Raised when the Tunnel does not have a name.

parse_unit(node)[source]

Parses <Unit>

@param node: Node containing the <Unit> element @type node: xml.etree.Element

@raise ParseError: When the name is not a string or the unit specfications are incorrect.

@raise ModelError: When the unit refers to an undefined dimension.

parse_with(node)[source]

Parses <With>

@param node: Node containing the <With> element @type node: xml.etree.Element

process_nested_tags(node, tag='')[source]

Process child tags.

@param node: Current node being parsed. @type node: xml.etree.Element

@raise ParseError: Raised when an unexpected nested tag is found.

raise_error(message, *params, **key_params)[source]

Raise a parse error.

tag_parse_table = None

Dictionary of xml tags to parse methods @type: dict(string -> function)

valid_children = None

Dictionary mapping each tag to it’s list of valid child tags. @type: dict(string -> string)

class tvb.dsl_cuda.lems.parser.LEMS.LEMSXMLNode(pyxmlnode)[source]

Bases: builtins.object

tvb.dsl_cuda.lems.parser.LEMS.get_nons_tag_from_node(node)[source]

expr

Expression parser

@author: Gautham Ganapathy @organization: LEMS (http://neuroml.org/lems/, https://github.com/organizations/LEMS) @contact: gautham@lisphacker.org

MV: added pow(f,l) function for c translations

class tvb.dsl_cuda.lems.parser.expr.ExprNode(type)[source]

Bases: lems.base.base.LEMSBase

Base class for a node in the expression parse tree.

FUNC1 = 3
OP = 1
VALUE = 2
type = None

Node type. @type: enum(ExprNode.OP, ExprNode.VALUE)

class tvb.dsl_cuda.lems.parser.expr.ExprParser(parse_string)[source]

Bases: lems.base.base.LEMSBase

Parser class for parsing an expression and generating a parse tree.

cleanup_stacks()[source]
debug = False
depth = 0

Dictionary mapping operators to their priorities. @type: dict(string -> Integer)

is_func(str)[source]

Checks if a token string contains a function.

@param str: Token string to be checked. @type str: string

@return: True if the token string contains a function. @rtype: Boolean

is_op(str)[source]

Checks if a token string contains an operator.

@param str: Token string to be checked. @type str: string

@return: True if the token string contains an operator. @rtype: Boolean

is_sym(str)[source]

Checks if a token string contains a symbol.

@param str: Token string to be checked. @type str: string

@return: True if the token string contains a symbol. @rtype: Boolean

MV: Added the part to recognize ** for power

make_op_node(op, right)[source]
op_priority = {'$': -5, 'func': 8, '**': 6, '+': 5, '-': 5, '*': 6, '/': 6, '^': 7, '~': 8, 'exp': 8, '.and.': 1, '.or.': 1, '.gt.': 2, '.ge.': 2, '.geq.': 2, '.lt.': 2, '.le.': 2, '.eq.': 2, '.neq.': 2, '.ne.': 2}
parse()[source]

Tokenizes and parses an arithmetic expression into a parse tree.

@return: Returns a token string. @rtype: lems.parser.expr.ExprNode

parse2()[source]
parse_string = None

Expression to be parsed. @type: string

parse_token_list_rec(min_precedence)[source]

Parses a tokenized arithmetic expression into a parse tree. It calls itself recursively to handle bracketed subexpressions.

@return: Returns a token string. @rtype: lems.parser.expr.ExprNode

@attention: Does not handle unary minuses at the moment. Needs to be fixed.

priority(op)[source]
token_list = None

List of tokens from the expression to be parsed. @type: list(string)

tokenize()[source]

Tokenizes the string stored in the parser object into a list of tokens.

class tvb.dsl_cuda.lems.parser.expr.Func1Node(func, param)[source]

Bases: tvb.dsl_cuda.lems.parser.expr.ExprNode

Unary function node in an expression parse tree. This will always be a non-leaf node.

func = None

Funcion stored in this node. @type: string

param = None

Parameter. @type: lems.parser.expr.ExprNode

to_python_expr()[source]
class tvb.dsl_cuda.lems.parser.expr.OpNode(op, left, right)[source]

Bases: tvb.dsl_cuda.lems.parser.expr.ExprNode

Operation node in an expression parse tree. This will always be a non-leaf node.

left = None

Left operand. @type: lems.parser.expr.ExprNode

op = None

Operation stored in this node. @type: string

right = None

Right operand. @type: lems.parser.expr.ExprNode

to_python_expr()[source]
class tvb.dsl_cuda.lems.parser.expr.ValueNode(value)[source]

Bases: tvb.dsl_cuda.lems.parser.expr.ExprNode

Value node in an expression parse tree. This will always be a leaf node.

clean_up()[source]

To make sure an integer is returned as a float. No division by integers!!

to_python_expr()[source]
value = None

Value to be stored in this node. @type: string