Skip to content

Commit

Permalink
Merge pull request #99 from mopichalova/98-zooming-syntax
Browse files Browse the repository at this point in the history
Reverting to BCSL Original Syntax: Implementing "::"
  • Loading branch information
xtrojak authored Mar 14, 2024
2 parents 8f6600a + 152831a commit 0caa5e5
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Testing/models/model_cmplx_in_abstr_seq1.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#! rules
S{i}:A():A2::cell => A()::cell
S{i}::A()::A2::cell => A()::cell

#! complexes
A2 = A().A()
2 changes: 1 addition & 1 deletion Testing/models/model_cmplx_in_abstr_seq2.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#! rules
S{i}:A():A().A()::cell => A()::cell
S{i}::A()::A().A()::cell => A()::cell
8 changes: 4 additions & 4 deletions Testing/models/model_miyoshi.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#! rules
S{u}:KaiC():KaiC6::cyt => S{p}:KaiC():KaiC6::cyt @ (kcat1*[KaiA2()::cyt]*[KaiC6::cyt])/(Km + [KaiC6::cyt])
S{p}:KaiC():KaiC6::cyt => S{u}:KaiC():KaiC6::cyt @ (kcat2*[KaiB4{a}.KaiA2()::cyt]*[KaiC6::cyt])/(Km + [KaiC6::cyt])
T{u}:KaiC():KaiC6::cyt => T{p}:KaiC():KaiC6::cyt @ (kcat3*[KaiA2()::cyt]*[KaiC6::cyt])/(Km + [KaiC6::cyt])
T{p}:KaiC():KaiC6::cyt => T{u}:KaiC():KaiC6::cyt @ (kcat4*[KaiB4{a}.KaiA2()::cyt]*[KaiC6::cyt])/(Km + [KaiC6::cyt])
S{u}::KaiC()::KaiC6::cyt => S{p}::KaiC()::KaiC6::cyt @ (kcat1*[KaiA2()::cyt]*[KaiC6::cyt])/(Km + [KaiC6::cyt])
S{p}::KaiC()::KaiC6::cyt => S{u}::KaiC()::KaiC6::cyt @ (kcat2*[KaiB4{a}.KaiA2()::cyt]*[KaiC6::cyt])/(Km + [KaiC6::cyt])
T{u}::KaiC()::KaiC6::cyt => T{p}::KaiC()::KaiC6::cyt @ (kcat3*[KaiA2()::cyt]*[KaiC6::cyt])/(Km + [KaiC6::cyt])
T{p}::KaiC()::KaiC6::cyt => T{u}::KaiC()::KaiC6::cyt @ (kcat4*[KaiB4{a}.KaiA2()::cyt]*[KaiC6::cyt])/(Km + [KaiC6::cyt])
KaiB4{i}::cyt => KaiB4{a}::cyt @ (kcatb2*[KaiB4{i}::cyt])/(Kmb2 + [KaiB4{i}::cyt])
KaiB4{a}::cyt => KaiB4{i}::cyt @ (kcatb1*[KaiB4{a}::cyt])/(Kmb1 + [KaiB4{a}::cyt])
KaiB4{a}.KaiA2()::cyt => KaiB4{a}::cyt + KaiA2()::cyt @ k12*[KaiB4{a}.KaiA2()::cyt]
Expand Down
8 changes: 4 additions & 4 deletions Testing/models/model_with_complexes.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#! rules
#! rules
// commenting
X(T{a}):XX::rep => X(T{o}):XX::rep @ k2*[X().X()::rep]
K{i}:X():XYZ::rep => K{p}:X():XYZ::rep @ k1*[X().Y().Z()::rep] // also here
=> P{f}:XP::rep @ 1/(1+([X().P{_}::rep])**4) // ** means power (^)
X(T{a})::XX::rep => X(T{o})::XX::rep @ k2*[X().X()::rep]
K{i}::X()::XYZ::rep => K{p}::X()::XYZ::rep @ k1*[X().Y().Z()::rep] // also here
=> P{f}::XP::rep @ 1/(1+([X().P{_}::rep])**4) // ** means power (^)

#! inits
// here
Expand Down
4 changes: 2 additions & 2 deletions Testing/models/model_with_variable.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! rules
// commenting
T{a}:X():?::rep => T{o}:X():?::rep @ k2*[X().X()::rep] ; ? = { XX, XY }
K{i}:X():XY::rep => K{p}:X():XY::rep @ k1*[X().Y().Z().X()::rep] // also here
T{a}::X()::?::rep => T{o}::X()::?::rep @ k2*[X().X()::rep] ; ? = { XX, XY }
K{i}::X()::XY::rep => K{p}::X()::XY::rep @ k1*[X().Y().Z().X()::rep] // also here

#! inits
// here
Expand Down
36 changes: 23 additions & 13 deletions eBCSgen/Parsing/ParseBCSL.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from numpy import inf
from copy import deepcopy
from lark import Lark, Transformer, Tree
from lark import UnexpectedCharacters, UnexpectedToken
from lark import UnexpectedCharacters, UnexpectedToken, UnexpectedEOF
from lark.load_grammar import _TERMINAL_NAMES
import regex
from sortedcontainers import SortedList
Expand Down Expand Up @@ -106,16 +106,16 @@ def to_side(self):
model: (sections)* rules (sections | rules)*
sections: inits | definitions | complexes | regulation
rules: RULES_START _NL+ ((rule|COMMENT) _NL+)* rule _NL*
inits: INITS_START _NL+ ((init|COMMENT) _NL+)* init _NL*
definitions: DEFNS_START _NL+ ((definition|COMMENT) _NL+)* definition _NL*
complexes: COMPLEXES_START _NL+ ((cmplx_dfn|COMMENT) _NL+)* cmplx_dfn _NL*
rules: RULES_START _NL+ (rule _NL+)* rule _NL*
inits: INITS_START _NL+ (init _NL+)* init _NL*
definitions: DEFNS_START _NL+ (definition _NL+)* definition _NL*
complexes: COMPLEXES_START _NL+ (cmplx_dfn _NL+)* cmplx_dfn _NL*
regulation: REGULATION_START _NL+ regulation_def _NL*
init: const? rate_complex (COMMENT)?
definition: def_param "=" number (COMMENT)?
rule: ((label)? side ARROW side ("@" rate)? (";" variable)? (COMMENT)?) | ((label)? side BI_ARROW side ("@" rate "|" rate)? (";" variable)? (COMMENT)?)
cmplx_dfn: cmplx_name "=" value (COMMENT)?
init: const? rate_complex
definition: def_param "=" number
rule: ((label)? side ARROW side ("@" rate)? (";" variable)?) | ((label)? side BI_ARROW side ("@" rate "|" rate )? (";" variable)?)
cmplx_dfn: cmplx_name "=" value
side: (const? complex "+")* (const? complex)?
complex: (abstract_sequence|value|cmplx_name) DOUBLE_COLON compartment
Expand Down Expand Up @@ -157,9 +157,9 @@ def to_side(self):

EXTENDED_GRAMMAR = """
abstract_sequence: atomic_complex | atomic_structure_complex | structure_complex
atomic_complex: atomic ":" (VAR | value)
atomic_structure_complex: atomic ":" structure ":" (VAR | value)
structure_complex: structure ":" (VAR | value)
atomic_complex: atomic "::" (VAR | value)
atomic_structure_complex: atomic "::" structure "::" (VAR | value)
structure_complex: structure "::" (VAR | value)
variable: VAR "=" "{" cmplx_name ("," cmplx_name)+ "}"
VAR: "?"
Expand Down Expand Up @@ -695,7 +695,7 @@ def __init__(self, start):
+ REGULATIONS_GRAMMAR
)
self.parser = Lark(
grammar, parser="lalr", propagate_positions=False, maybe_placeholders=False
grammar, parser="earley", propagate_positions=False, maybe_placeholders=False
)

self.terminals = dict((v, k) for k, v in _TERMINAL_NAMES.items())
Expand Down Expand Up @@ -796,4 +796,14 @@ def syntax_check(self, expression: str) -> Result:
"column": u.column,
},
)
except UnexpectedEOF as u:
return Result(
False,
{
"unexpected": str(u.token),
"expected": self.replace(u.expected),
"line": u.line,
"column": u.column,
},
)
return Result(True, tree)

0 comments on commit 0caa5e5

Please sign in to comment.