Closed mingodad closed 1 year ago
@spoenemann Is this similar enough to https://github.com/langium/langium/issues/827 to warrant this being a duplicate?
It's similar but using a different tool that in my opnion is superior to the one chevotrain
produces, I didn't knew that issue before (I searched for railroad before creating this issue).
Also I'm including an actual usable EBNF
of langium-grammar.langium
.
It's not necessarily about about the diagram chevrotain
produces, but about syntax diagrams in general. We would use the solution best suited to get the job done. The discussion just was inspired by what Chevrotain does.
Let's keep it separate, we might even support both at some point.
I manually converted the
langium-grammar.langium
to anEBNF
understood by https://www.bottlecaps.de/rr/ui , would be nice iflangium
could generate it automatically like I did forbison/byacc/lemon
here https://github.com/mingodad/lalr-parser-test .Copy and paste the
EBNF
shown bellow on https://www.bottlecaps.de/rr/ui on the tabEdit Grammar
the click on the tabView Diagram
to see/download a navigable railroad diagram.EBNF diagram
``` /****************************************************************************** * Copyright 2021 TypeFox GmbH * This program and the accompanying materials are made available under the * terms of the MIT License, which is available in the project root. ******************************************************************************/ grammar LangiumGrammar entry Grammar : ( /*isDeclared?=*/'grammar' /*name=*/ID ('with' /*usedGrammars+=[Grammar:*/ID/*]*/ (',' /*usedGrammars+=[Grammar:*/ID/*]*/)*)? (/*definesHiddenTokens?=*/'hidden' '(' (/*hiddenTokens+=[AbstractRule:*/ID/*]*/ (',' /*hiddenTokens+=[AbstractRule:*/ID/*]*/)*)? ')')? )? /*imports+=*/GrammarImport* (/*rules+=*/AbstractRule | /*interfaces+=*/Interface | /*types+=*/Type)+ ; Interface : 'interface' /*name=*/ID ('extends' /*superTypes+=[AbstractType:*/ID/*]*/ (',' /*superTypes+=[AbstractType:*/ID/*]*/)*)? SchemaType ; /*fragment*/ SchemaType : '{' /*attributes+=*/TypeAttribute* '}' ';'? ; TypeAttribute : /*name=*/FeatureName (/*isOptional?=*/'?')? ':' /*type=*/TypeDefinition ';'? ; TypeDefinition : UnionType ; UnionType /*infers TypeDefinition*/ : ArrayType (/*{infer UnionType.types+=current}*/ ('|' /*types+=*/ArrayType)+)? ; ArrayType /*infers TypeDefinition*/ : ReferenceType (/*{infer ArrayType.elementType=current}*/ '[' ']')? ; ReferenceType /*infers TypeDefinition*/ : SimpleType | /*{infer ReferenceType}*/ '@' /*referenceType=*/SimpleType ; SimpleType /*infers TypeDefinition*/ : '(' TypeDefinition ')' | /*{infer SimpleType}*/ (/*typeRef=[AbstractType:*/ID/*]*/ | /*primitiveType=*/PrimitiveType | /*stringType=*/STRING) ; PrimitiveType returns string : 'string' | 'number' | 'boolean' | 'Date' | 'bigint' ; /*type*/ AbstractType : Interface | Type | Action | ParserRule ; Type : 'type' /*name=*/ID '=' /*type=*/TypeDefinition ';'? ; AbstractRule : ParserRule | TerminalRule ; GrammarImport : 'import' /*path=*/STRING ';'? ; ParserRule : (/*entry?=*/'entry' | /*fragment?=*/'fragment')? RuleNameAndParams (/*wildcard?=*/'*' | ('returns' (/*returnType=[AbstractType:*/ID/*]*/ | /*dataType=*/PrimitiveType)) | /*inferredType=*/InferredType/*