katef / kgt

BNF wrangling and railroad diagrams
BSD 2-Clause "Simplified" License
584 stars 29 forks source link

Feature request: add language from the "Railroad-diagram Generator" #48

Open dolmen opened 3 years ago

dolmen commented 3 years ago

Add support for the language from the Railroad-diagram Generator as input.

Example:

Diagram(
  Optional('+', 'skip'),
  Choice(0,
    NonTerminal('name-start char'),
    NonTerminal('escape')),
  ZeroOrMore(
    Choice(0,
      NonTerminal('name char'),
      NonTerminal('escape'))))

Online: https://tabatkins.github.io/railroad-diagrams/generator.html

Format documentation: https://github.com/tabatkins/railroad-diagrams#components

katef commented 3 years ago

Hi! Thanks! This is interesting. kgt's input is usually BNF, which is supposed to be a semantic representation of a grammar. Tab's structure here is for presentational information. For example, it offers Stack() for vertically placed alts.

kgt has several stages internally. Relevant here are the AST for BNF, and then the RRD tree (which is presentational, although still abstracted from layout coordinates).

So we'd have two options for parsing this;

Both could make sense.

https://github.com/katef/kgt/blob/main/src/ast.h https://github.com/katef/kgt/blob/main/src/rrd/node.h