SHADE-AI / daidepp

Repo to store universal communication specification
2 stars 7 forks source link

SCD cannot be parsed correctly #48

Closed delaschwein closed 1 year ago

delaschwein commented 1 year ago

I tried to parse a SCD arrangement using the following code snippet:

from daidepp import create_daide_grammar, daide_visitor

grammar = create_daide_grammar(level=130, string_type='all')
message = 'SCD (FRA HOL)'
parse_tree = grammar.parse(message)
output = daide_visitor.visit(parse_tree)
print(output)

Error message is as follows:

Traceback (most recent call last):
  File "C:\Users\daidepp\keywords.py", line 21, in __post_init__
    _grammar.parse(str(self))
  File "C:\Users\parsimonious\grammar.py", line 111, in parse
    return self.default_rule.parse(text, pos=pos)
  File "C:\Users\parsimonious\expressions.py", line 130, in parse
    node = self.match(text, pos=pos)
  File "C:\Users\parsimonious\expressions.py", line 147, in match
    raise error
parsimonious.exceptions.ParseError: Rule 'supply_center' didn't match at '['HOL'] )' (line 1, column 11).

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\parsimonious\nodes.py", line 213, in visit
    return method(node, [self.visit(n) for n in node])
  File "C:\Users\daidepp\daide_visitor.py", line 263, in visit_scd
    return SCD(*power_and_supply_centers)
  File "C:\Users\daidepp\keywords.py", line 376, in __init__
    self.__post_init__()
  File "C:\Users\daidepp\keywords.py", line 23, in __post_init__
    raise Exception("Incorrect values passed, object is not valid DAIDE")
Exception: Incorrect values passed, object is not valid DAIDE

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\Users\validation.py", line 6, in <module>
    output = daide_visitor.visit(parse_tree)
  File "C:\Users\parsimonious\nodes.py", line 213, in visit
    return method(node, [self.visit(n) for n in node])
  File "C:\Users\parsimonious\nodes.py", line 213, in <listcomp>
    return method(node, [self.visit(n) for n in node])
  File "C:\Users\parsimonious\nodes.py", line 225, in visit
    raise VisitationError(exc, exc_class, node)
parsimonious.exceptions.VisitationError: Exception: Incorrect values passed, object is not valid DAIDE

Parse tree:
<Node called "scd" matching "SCD (FRA HOL)">  <-- *** We were here. ***
    <Node matching "SCD">
        <Node matching " (FRA HOL)">
            <RegexNode called "lpar" matching " (">
            <Node called "power" matching "FRA">
                <Node matching "FRA">
            <RegexNode called "ws" matching " ">
            <Node called "supply_center" matching "HOL">
                <Node matching "HOL">
            <Node matching "">
            <RegexNode called "rpar" matching ")">

SCD object can be constructed using SCD(PowerAndSupplyCenters("FRA ", Location("HOL")) just can't be parsed using the above snippet.