parol icon indicating copy to clipboard operation
parol copied to clipboard

Grammar railroad diagram

Open mingodad opened this issue 8 months ago • 4 comments

I've just added parol grammar to https://mingodad.github.io/parsertl-playground/playground/ an Yacc/Lex compatible online editor/tester (select Parol parser from Examples then click Parse to see a parser tree for the content in Input source), it can also generate an EBNF understood by https://github.com/GuntherRademacher/rr to generate a nice navigable railroad diagram (see bellow) and a SQL description of the grammar too.

Would be nice if parol could also generate then.

//
// EBNF to be viewd at
//    (IPV6) https://www.bottlecaps.de/rr/ui
//    (IPV4) https://rr.red-dove.com/ui
//
// Copy and paste this at one of the urls shown above in the 'Edit Grammar' tab
// then click the 'View Diagram' tab.
//

Parol::=
	  Prolog GrammarDefinition

Prolog::=
	  StartDeclaration Declaration_zom ScannerState_zom

ScannerState_zom::=
	  /*%empty*/
	| ScannerState_zom ScannerState

Declaration_zom::=
	  /*%empty*/
	| Declaration_zom Declaration

StartDeclaration::=
	  "%start" Identifier

Declaration::=
	  "%title" String
	| "%comment" String
	| "%user_type" Identifier '=' UserTypeName
	| "%grammar_type" RawString
	| ScannerDirectives

ScannerDirectives::=
	  "%line_comment" TokenLiteral
	| "%block_comment" TokenLiteral TokenLiteral
	| "%auto_newline_off"
	| "%auto_ws_off"
	| "%on" IdentifierList "%enter" Identifier

GrammarDefinition::=
	  "%%" Production Production_zom

Production_zom::=
	  /*%empty*/
	| Production_zom Production

DoubleColon::=
	  "::"

Production::=
	  Identifier ':' Alternations ';'

Alternations::=
	  Alternation
	| Alternations '|' Alternation

Alternation::=
	  /*%empty*/
	| Alternation Factor

Factor::=
	  Group
	| Repeat
	| Optional
	| Symbol

Symbol::=
	  NonTerminal
	| SimpleToken
	| TokenWithStates
	| ScannerSwitch

TokenLiteral::=
	  String
	| RawString
	| Regex

SimpleToken::=
	  TokenLiteral ASTControl_opt

ASTControl_opt::=
	  /*%empty*/
	| ASTControl

TokenWithStates::=
	  '<' IdentifierList '>' TokenLiteral ASTControl_opt

Group::=
	  '(' Alternations ')'

Optional::=
	  '[' Alternations ']'

Repeat::=
	  '{' Alternations '}'

NonTerminal::=
	  Identifier ASTControl_opt

ScannerState::=
	  "%scanner" Identifier '{' ScannerDirectives_zom '}'

ScannerDirectives_zom::=
	  /*%empty*/
	| ScannerDirectives_zom ScannerDirectives

IdentifierList::=
	  Identifier
	| IdentifierList ',' Identifier

ScannerSwitch::=
	  "%sc" '(' Identifier_opt ')'
	| "%push" '(' Identifier ')'
	| "%pop" '(' ')'

Identifier_opt::=
	  /*%empty*/
	| Identifier

ASTControl::=
	  CutOperator
	| UserTypeDeclaration

CutOperator::=
	  '^'

UserTypeDeclaration::=
	  ':' UserTypeName

UserTypeName::=
	  Identifier
	| UserTypeName DoubleColon Identifier

mingodad avatar Jun 05 '24 11:06 mingodad