Parsing

ParseBCSL

class eBCSgen.Parsing.ParseBCSL.ExtractComplexNames

Bases: Transformer

Extracts definitions of cmplx_name from #! complexes part.

Also multiplies rule with variable to its instances using ReplaceVariables Transformer.

cmplx_dfn(matches)
rules(matches)
class eBCSgen.Parsing.ParseBCSL.Parser(start)

Bases: object

parse(expression: str) Result

Main method for parsing, first syntax_check is called which checks syntax and if it is correct, a parsed Tree is returned.

Then the tree is transformed using several Transformers in self.transform method.

Parameters:

expression – given string expression

Returns:

Result containing parsed object or error specification

replace(expected: set) set

Method used to replace expected tokens by their human-readable representations defined in self.terminals

Parameters:

expected – given set of expected tokens

Returns:

transformed tokens

syntax_check(expression: str) Result

Main method for parsing, calls Lark.parse method and creates Result containing parsed object (according to designed ‘start’ in grammar) or dict with specified error in case the given expression cannot be parsed.

Parameters:

expression – given string expression

Returns:

Result containing parsed object or error specification

transform(tree: Tree) Result

Apply several transformers to construct BCSL object from given tree.

Parameters:

tree – given parsed Tree

Returns:

Result containing constructed BCSL object

class eBCSgen.Parsing.ParseBCSL.ReplaceVariables(to_replace)

Bases: Transformer

This class is used to replace variables in rule (marked by ?) by the given cmplx_name (so far limited only to that).

VAR(matches)
class eBCSgen.Parsing.ParseBCSL.Result(success, data)

Bases: object

Class to represent output from the Parser.

class eBCSgen.Parsing.ParseBCSL.SideHelper

Bases: object

Class to represent side of a rule.

to_side()
class eBCSgen.Parsing.ParseBCSL.TransformAbstractSyntax(complex_defns)

Bases: Transformer

Transformer to remove “zooming” syntax.

Divided to three special cases (declared below). Based on replacing subtrees in parent trees.

abstract_sequence(matches)
atomic_complex(matches)

atomic:complex

atomic_structure_complex(matches)

atomic:structure:complex

cmplx_name(matches)
complex(matches)
get_name(agent)
insert_atomic_to_complex(atomic, complex)

Adds an atomic subtree to a complex tree. If a non-empty atomic with the same name is already present in the complex, it raises an error to prevent illegal nesting.

Args:

atomic: The atomic subtree to be added. complex: The complex tree where the atomic will be added.

Returns:

The updated complex tree with the atomic added.

Raises:

ComplexParsingError: If an atomic with the same name is already present in the complex.

insert_atomic_to_struct(atomic, struct)

Adds an atomic subtree to a struct tree. If a non-empty atomic with the same name already exists in the struct, it raises an error to prevent illegal nesting.

Args:

atomic: The atomic subtree to be added. struct: The struct tree where the atomic will be added.

Returns:

The updated struct tree with the atomic added.

Raises:

ComplexParsingError: If a non-empty atomic with the same name is already present in the struct.

insert_struct_to_complex(struct, complex)

Adds a struct subtree to a complex tree, or merges it with an existing struct subtree. This method first searches for a struct in the complex with the same name as the input struct. If found, it then checks for atomic incompatibility within the structs.

The method ensures that the struct being added does not contain atomics with names that match any atomics in the corresponding struct in the complex. This step is crucial to maintain the integrity of the complex by avoiding conflicting or duplicate atomic structures.

Args:

struct: The struct subtree to be added or merged. complex: The complex tree where the struct will be added or merged.

Returns:

The updated complex tree with the struct added or merged.

Raises:

ComplexParsingError: If no matching struct is found in the complex.

is_empty(agent)

Checks if the agent is empty.

structure_complex(matches)

structure:complex

class eBCSgen.Parsing.ParseBCSL.TransformRegulations(visit_tokens: bool = True)

Bases: Transformer

concurrent_free(matches)
conditional(matches)
context(matches)
order(matches)
ordered(matches)
programmed(matches)
regular(matches)
regulation(matches)
regulation_def(matches)
successors(matches)
class eBCSgen.Parsing.ParseBCSL.TreeToComplex(visit_tokens: bool = True)

Bases: Transformer

Creates actual Complexes in rates of the rules - there it is safe, order is not important. Does not apply to the rest of the rule!

atomic(matches)
compartment(matches)
rate_complex(matches)
state(matches)
structure(matches)
class eBCSgen.Parsing.ParseBCSL.TreeToObjects

Bases: Transformer

const(matches)
def_param(matches)
definitions(matches)
init(matches)
inits(matches)
label(matches)
model(matches)
number(matches)
observable(matches)
observables(matches)
param(matches)
rule(matches)
rules(matches)
side(matches)
eBCSgen.Parsing.ParseBCSL.load_TS_from_json(json_file: str) TransitionSystem

Loads given JSON and interprets it as a TransitionSystem.

Parameters:

json_file – given TS in JSON

Returns:

resulting TransitionSystem

eBCSgen.Parsing.ParseBCSL.remove_nested_complex_aliases(complex_defns)

Removes nested complex aliases from their definitions.

ParseCTLformula

class eBCSgen.Parsing.ParseCTLformula.CTLparser

Bases: object

A class to parse a CTL formula.

grammar = '\n        start: formula\n        !formula: "true"\n               | "false" \n               | ap\n               | "~" formula\n               | "(" formula ")"\n               | formula ("and" | "&") formula\n               | formula ("or" | "|") formula\n               | formula "-->" formula\n               | formula "<->" formula\n               | "A" "(" state_formula ")"\n               | "E" "(" state_formula ")"\n               \n        !state_formula: "X" "(" formula ")"\n                     | "F" "(" formula ")"\n                     | "G" "(" formula ")"\n                     | formula "U" formula\n                 \n        ap: LB rate_complex sign_ap number RB\n        sign: e_sign | ne_sign\n        e_sign.1: GE | LE\n        ne_sign.0: L | G\n        sign_ap: EQ | sign\n    \n        !pq.1: "P" "=" "?"\n        !pneq.0: "P" sign number\n    \n        EQ: "="\n        GE: ">="\n        G: ">"\n        LE: "<="\n        L: "<"\n        \n        LB: "["\n        RB: "]"\n    \n        number: NUMBER\n    \n        %import common.NUMBER\n        %import common.WS\n        %ignore WS\n\n        %import common.ESCAPED_STRING\n        %import common.WS\n        %ignore WS\n        '
parse(expression: str) Formula
replace(expected: set) set
class eBCSgen.Parsing.ParseCTLformula.TreeToStrings(visit_tokens: bool = True)

Bases: Transformer

agent(matches)
ap(matches)
number(matches)
sign(matches)
sign_ap(matches)

ParsePCTLformula

class eBCSgen.Parsing.ParsePCTLformula.PCTLparser

Bases: object

parse(expression: str) Formula
replace(expected: set) set
class eBCSgen.Parsing.ParsePCTLformula.TreeToStrings(visit_tokens: bool = True)

Bases: Transformer

AND(matches)
FUTURE(matches)
LB(matches)
NEXT(matches)
OR(matches)
UNTIL(matches)
agent(matches)
ap(matches)
number(matches)
sign(matches)
sign_ap(matches)