Skip to content

Grammar railroad diagram #361

@mingodad

Description

@mingodad

Based on https://github.com/schibsted/jslt/blob/master/core/src/main/jjtree/jslt.jjt with a bit of manual changes we can have a nice navigable railroad diagram:

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

/** Root production. */
Start ::=
	Import* (Let | FunctionDecl)* Expr //<EOF>


///** Root production for module files */
//Module ::=
//	Import* (Let | FunctionDecl)* Expr? //<EOF>
//

Expr ::=
	OrExpr (PipeOperator OrExpr)*


OrExpr ::=
	AndExpr (OR OrExpr)?


AndExpr ::=
	ComparativeExpr (AND AndExpr)?


ComparativeExpr ::=
	AdditiveExpr (Comparator AdditiveExpr)?


// not necessary, but makes the tree easier to traverse
Comparator ::=
	EQUALS
	| UNEQUALS
	| BIGOREQ
	| BIGGER
	| SMALLER
	| SMALLOREQ


PipeOperator ::=
	PIPE


AdditiveExpr ::=
	MultiplicativeExpr (AdditiveOperator MultiplicativeExpr)*


// not necessary, but makes the tree easier to traverse
AdditiveOperator ::=
	PLUS
	| MINUS


MultiplicativeExpr ::=
	BaseExpr (MultiplicativeOperator BaseExpr)*


// not necessary, but makes the tree easier to traverse
MultiplicativeOperator ::=
	STAR
	| SLASH


BaseExpr ::=
	//(LOOKAHEAD(2)
	NULL
	| INTEGER
	| DECIMAL
	| STRING
	| TRUE
	| FALSE
	| Chainable
	| Parenthesis
	| IfStatement
	| Array
	//|(LOOKAHEAD(2)
	| Object
	| ObjectComprehension


Chainable ::=
	(FunctionCall | VARIABLE | DOT (IDENT | STRING)?) ChainLink?


ChainLink ::=
	(DotKey | ArraySlicing) ChainLink?


Parenthesis ::=
	LPAREN Expr RPAREN


DotKey ::=
	DOT (IDENT | STRING)


ArraySlicing ::=
	LBRACKET
	(
		Expr (Colon Expr?)?
		| Colon Expr
	)
	RBRACKET


Colon ::=
	COLON // need this to make parse tree manageable


ArrayElem /*#void*/  ::=
	Expr (COMMA ArrayElem?)?


Array ::=
	LBRACKET
	(
		FOR LPAREN Expr RPAREN Let* Expr
			(IF LPAREN Expr RPAREN)?
		| ArrayElem?
	)
	RBRACKET


Object ::=
	LCURLY Let* (Pair | Matcher)? RCURLY


Matcher ::=
	STAR MatcherMinus? COLON Expr


MatcherMinus ::=
	MINUS (IDENT | STRING) (COMMA (IDENT | STRING))*


Pair ::=
	Expr COLON Expr (COMMA (Pair | Matcher)?)?


ObjectComprehension ::=
	LCURLY FOR LPAREN Expr RPAREN Let* Expr COLON Expr
		(IF LPAREN Expr RPAREN)?
	RCURLY


IfStatement ::=
	IF LPAREN Expr RPAREN Let* Expr ElseBranch?


// not necessary, but makes it easier to walk the parse tree
ElseBranch ::=
	ELSE Let* Expr


FunctionCall ::=
	(IDENT | PIDENT) LPAREN (Expr (COMMA Expr)*)? RPAREN


Let ::=
	LET IDENT ASSIGN Expr


FunctionDecl ::=
	DEF IDENT LPAREN (IDENT (COMMA IDENT)*)? RPAREN Let* Expr


Import ::=
	IMPORT STRING AS IDENT

//Tokens

NULL ::= "null"
LBRACKET ::= "["
RBRACKET ::= "]"
COMMA ::= ","
COLON ::= ":"
LCURLY ::= "{"
RCURLY ::= "}"
TRUE ::= "true"
FALSE ::= "false"
OR ::= "or"
AND ::= "and"
DOT ::= "."
IF ::= "if"
ELSE ::= "else"
LPAREN ::= "("
RPAREN ::= ")"
LET ::= "let"
ASSIGN ::= "="
EQUALS ::= "=="
UNEQUALS ::= "!="
BIGOREQ ::= ">="
BIGGER ::= ">"
SMALLER ::= "<"
SMALLOREQ ::= "<="
PLUS ::= "+"
MINUS ::= "-"
STAR ::= "*"
SLASH ::= "/"
PIPE ::= "|"
FOR ::= "for"
DEF ::= "def"
IMPORT ::= "import"
AS ::= "as"

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions