Browse Source

extend concrete syntax: edge can be defined as (src -> tgt) OR (tgt <- src)

Joeri Exelmans 8 months ago
parent
commit
838bb18630
1 changed files with 7 additions and 2 deletions
  1. 7 2
      concrete_syntax/textual_od/parser.py

+ 7 - 2
concrete_syntax/textual_od/parser.py

@@ -33,9 +33,10 @@ INDENTED_CODE: /```[^`]*```/
 type_name: IDENTIFIER
 
 #        name (optional)      type        
-object: [IDENTIFIER]     ":"  type_name [link_spec] ["{" slot* "}"]
+object: [IDENTIFIER]     ":"  type_name [link_spec | rev_link_spec] ["{" slot* "}"]
 
-link_spec: "(" IDENTIFIER "->" IDENTIFIER ")"
+link_spec:     "(" IDENTIFIER "->" IDENTIFIER ")"
+rev_link_spec: "(" IDENTIFIER "<-" IDENTIFIER ")"
 
 slot: IDENTIFIER "=" literal ";"
 """
@@ -64,6 +65,10 @@ def parse_od(state, m_text, mm, type_transform=lambda type_name: type_name):
             [src, tgt] = el
             return (src, tgt)
 
+        def rev_link_spec(self, el):
+            [tgt, src] = el # <-- reversed :)
+            return (src, tgt)
+
         def type_name(self, el):
             type_name = el[0]
             if type_name in primitive_types: