Working on #21 : Created classes
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
from parsers.state_machine import End, ManageUnrecognized, PrepareReadTokens, ReadConcept, ReadTokens, Start, \
|
||||
StateMachine, StateMachineContext
|
||||
from parsers.tokenizer import Token
|
||||
|
||||
|
||||
class SyaConceptsParser:
|
||||
""""
|
||||
This class is to parse concepts with parameter
|
||||
ex : def concept a plus b as a + b
|
||||
It parses a sequence of concepts
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
tokens_wkf = {
|
||||
Start("start", next_states=["prepare read tokens"]),
|
||||
PrepareReadTokens("prepare read tokens", next_states=["read tokens"]),
|
||||
ReadTokens("read tokens", next_states=["read tokens", "eof", "concepts found"]),
|
||||
ManageUnrecognized("eof", next_states=["end"]),
|
||||
ManageUnrecognized("concepts found", next_states=["#concept_wkf"]),
|
||||
End("end", next_states=None)
|
||||
}
|
||||
|
||||
concept_wkf = {
|
||||
Start("start", next_states=["read concept"]),
|
||||
ReadConcept("read concept", next_states=["#tokens_wkf"]),
|
||||
}
|
||||
|
||||
self.workflows = {
|
||||
"#tokens_wkf": {t.name: t for t in tokens_wkf},
|
||||
"#concept_wkf": {t.name: t for t in concept_wkf},
|
||||
}
|
||||
self.error_sink = []
|
||||
|
||||
@staticmethod
|
||||
def get_metadata_from_first_token(context, token: Token):
|
||||
pass
|
||||
|
||||
def parse(self, context, parser_input):
|
||||
sm = StateMachine(self.workflows)
|
||||
sm_context = StateMachineContext(context, parser_input, self.get_metadata_from_first_token)
|
||||
sm.run("#tokens_wkf", "start", sm_context)
|
||||
pass
|
||||
Reference in New Issue
Block a user