johnedquinn/kanonic

Add alias/name to variant items

Closed this issue · 1 comments

ANTLR allows:

topRule:
    : key=IDENT EQUALS value=IDENT # IdentEqualsIdent
    | key=IDENT EQUALS ref=someOtherRule # IdentEqualsRef
    ;

So, I have an idea about this.

  • Amend the definition of item to allow for aliases
  • For every aliased item (either token or rule -- don't allow groups for now):
    • Generated another rule, where, upon creating the node, the alias will be specified.
    • So, the definition of NodeCreator will be modified to take in an alias -- potentially an index for the list of all alias names.
  • Then, in the KanonicParser:
    • If a GeneratedNode has an alias, when popping its children, add its alias to the children nodes
    • If a Node has an alias, that will be used for grabbing the correct aliased Node.
  • In the NodeGenerator:
    • If a Variant's items contains a Node with an alias, create a helper function to grab that Node.

For now, stick with only aliasing a single node. Not gathering.