Skip to content

Grammar railroad diagram #1

@mingodad

Description

@mingodad

Manually converting this project grammar to an EBNF understood by https://github.com/GuntherRademacher/rr we can get a nice navigable railroad diagram (see instructions bellow at the top).

//
// 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.
//

program::=
	  nl_zom stmt nl_stmt_zom nl_exportStmt_zom nl_zom

nl_exportStmt_zom::=
	  /*%empty*/
	| nl_oom exportStmt

nl_stmt_zom::=
	  /*%empty*/
	| nl_stmt_zom nl_oom stmt

nl_oom::=
	  NL
	| nl_oom NL

nl_zom::=
	  /*%empty*/
	| nl_zom NL

stmt::=
	  assignStmt
	| typeDefinition
	| importStmt
	| expr

assignStmt::=
	  assignKwd IDENTIFIER '=' expr

typeDefinition::=
	  "type" IDENTIFIER '=' typeExpr

typeExpr::=
	  adtType
	| recordType
	| tupleType
	| primitiveType

adtType::=
	  nl_zom orBar_opt adtOption adtType_5 nl_zom

adtType_5::=
	  /*%empty*/
	| adtType_5 nl_zom '|' adtOption

orBar_opt::=
	  /*%empty*/
	| '|'

adtOption::=
	  IDENTIFIER '(' nl_zom '{' nl_zom adtTypeAnnotation ',' nl_zom adtTypeAnnotation comma_opt nl_zom '}' nl_zom ')'
	| IDENTIFIER '(' primitiveType ')'
	| IDENTIFIER

comma_opt::=
	  /*%empty*/
	| ','

adtTypeAnnotation::=
	  IDENTIFIER ':' primitiveType_or_IDENTIFIER

primitiveType_or_IDENTIFIER::=
	  primitiveType
	| IDENTIFIER

recordType::=
	  '{' nl_zom recordTypeAnontation recordType_4 comma_opt nl_zom '}'

recordType_4::=
	  /*%empty*/
	| recordType_4 ',' nl_zom recordTypeAnontation

recordTypeAnontation::=
	  IDENTIFIER ':' recordTypeAnontation_1

recordTypeAnontation_1::=
	  primitiveType_or_IDENTIFIER
	| recordType

tupleType::=
	  '[' nl_zom tupleField tupleType_4 comma_opt nl_zom ']'

tupleType_4::=
	  /*%empty*/
	| tupleType_4 ',' nl_zom tupleField

tupleField::=
	  primitiveType
	| IDENTIFIER

primitiveType::=
	  "number"
	| "string"
	| "boolean"

importStmt::=
	  "import" IDENTIFIER "from" STRING
	| "import" IDENTIFIER ',' destructuringImportIdentifier "from" STRING
	| "import" destructuringImportIdentifier "from" STRING

destructuringImportIdentifier::=
	  /*%empty*/
	| '{' nl_zom IDENTIFIER destructuringImportIdentifier_4 nl_zom '}'

destructuringImportIdentifier_4::=
	  /*%empty*/
	| destructuringImportIdentifier_4 ',' nl_zom IDENTIFIER

exportStmt::=
	  "export" '{' nl_zom IDENTIFIER destructuringImportIdentifier_4 comma_opt nl_zom '}'

expr::=
	  primaryExpr tailExpr_zom

tailExpr_zom::=
	  /*%empty*/
	| tailExpr_zom tailExpr

primaryExpr::=
	  '(' expr ')'
	| ifExpr
	| funcExpr
	| jsxExpr
	| matchExpr
	| blockExpr
	| IDENTIFIER
	| literal

tailExpr::=
	  '.' IDENTIFIER
	| '[' expr ']'
	| callExpr
	| OPERATOR expr

ifExpr::=
	  justIfExpr if_else_zom else_expr_opt

else_expr_opt::=
	  /*%empty*/
	| "else" expr

if_else_zom::=
	  /*%empty*/
	| if_else_zom "else" justIfExpr

justIfExpr::=
	  "if" '(' expr ')' expr

funcExpr::=
	  '(' nl_zom parameterList_opt nl_zom ')' "=>" nl_zom expr

parameterList_opt::=
	  /*%empty*/
	| parameterList

parameterList::=
	  IDENTIFIER
	| parameterList ',' IDENTIFIER

callExpr::=
	  '(' nl_zom expr_comma_sep_zom nl_zom ')'

expr_comma_sep_zom::=
	  /*%empty*/
	| expr
	| expr_comma_sep_zom ',' nl_zom expr

matchExpr::=
	  "match" '(' expr ')' '{' nl_zom matchArm comma_matchArm_zom comma_opt nl_zom '}'

comma_matchArm_zom::=
	  /*%empty*/
	| comma_matchArm_zom ',' nl_zom matchArm

matchArm::=
	  matchPattern "=>" expr

matchPattern::=
	  IDENTIFIER
	| IDENTIFIER '(' IDENTIFIER ')'
	| IDENTIFIER '(' literal ')'
	| '_'
	| literal

blockExpr::=
	  '{' nl_zom stmt_zom expr nl_zom '}'

stmt_zom::=
	  /*%empty*/
	| stmt_zom stmt nl_zom

assignKwd::=
	  LET_KWD
	| CONST_KWD

literal::=
	  STRING
	| NUMBER
	| TRUE_KWD
	| FALSE_KWD

jsxExpr::=
	  jsxOpeningElement nl_zom jsxChild_zom nl_zom jsxClosingElement
	| jsxSelfClosingElement

jsxChild_zom::=
	  /*%empty*/
	| jsxChild_zom nl_zom jsxChild

jsxOpeningElement::=
	  '<' IDENTIFIER nl_zom jsxAttributes_opt nl_zom '>'

jsxAttributes_opt::=
	  /*%empty*/
	| jsxAttributes

jsxClosingElement::=
	  "</" IDENTIFIER '>'

jsxSelfClosingElement::=
	  '<' IDENTIFIER nl_zom jsxAttributes_opt nl_zom "/>"

jsxAttributes::=
	  jsxAttribute
	| jsxAttributes nl_zom jsxAttribute

jsxAttribute::=
	  IDENTIFIER '=' jsxAttributeValue

jsxAttributeValue::=
	  '{' expr '}'
	| STRING
	| NUMBER

jsxChild::=
	  jsxExpr
	| '{' expr '}'


//Tokens

LET_KWD::= 'let'
CONST_KWD::= 'const'
TRUE_KWD::= 'true'
FALSE_KWD::= 'false'

IDENTIFIER::= [a-zA-Z_][a-zA-Z0-9_]*

OPERATOR::= '+' | '-' | '*' | '/' | '==' | '!=' | '<' | '>' | '<=' | '>=' | '&&' | '||'

// TODO: Handle escaping
STRING::= '"' ([^"\n])* '"'

NUMBER::= [0-9]+ ('.' [0-9]+)?

NL::= '\n'
WS::= [ \r\n\t]+ //-> channel(HIDDEN);

COMMENT::= '//'[^\n]* //-> channel(HIDDEN);
MULTILINE_COMMENT::= '/*' ( [^*] | '*'+ [^*/] )* '*'* '*/' //'/*' .*? '*/' //-> channel(HIDDEN);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions