node-ebnf icon indicating copy to clipboard operation
node-ebnf copied to clipboard

Better error messages ?

Open mingodad opened this issue 9 months ago • 0 comments

While testing converting grammars from https://mingodad.github.io/cpp-peglib/ (select 'scc parser' from Examples) I'm getting unhelpful error messages at https://menduz.github.io/ebnf-highlighter/ (it fills up the whole viewable section and hide the editor).

Would be nice to have more grammars there like in https://mingodad.github.io/cpp-peglib

For example this converted grammar from scc parser:

/*From https://github.com/dccarter/scc/blob/main/grammar/parser.g*/
program         ::= S_ before? namespace? after?
namespace       ::= namespacekey S_ scoped S_ '{' S_ nscontent? S_ '}' S_
namespacekey    ::= 'namespace'
nscontent       ::= (variable | class | struct | native | comment | invoke | enum)+
enum            ::= enumkey S_ genanno? S_ ident (S_ ':' S_ ident)? S_ '{' S_ enumcontent? S_ '}' sp ';' S_
nestedenum      ::= enumkey S_ annotations? S_ ident (S_ ':' S_ ident)? S_ '{' S_ enumcontent? S_ '}' sp ';' S_
enumcontent     ::= (comment | (enummember sp ',' S_))* enummember comment?
enummember      ::= annotations? S_ ident (S_ '=' S_ int)?
enumkey         ::= 'enum'
class           ::= classkey S_ genanno? S_ ident (S_ ':' S_ bases)? S_ '{' S_ members? S_ '}' sp ';' S_
classkey        ::= 'class'
struct          ::= structkey S_ genanno? S_ ident S_ '{' S_ fields? S_ '}' sp ';' S_
nestedstruct    ::= structkey S_ annotations? S_ ident S_ '{' S_ fields? S_ '}' sp ';' S_
structkey       ::= 'struct' | 'union'
members         ::= (modifier | constructor | method | field | nestedstruct | nestedenum | comment | native)+
fields          ::= (field | comment | native | nestedstruct | nestedenum)+
bases           ::= base (S_ ',' S_ base)*
base            ::= encapsul? sp generic
modifier        ::= encapsul sp ':' S_
encapsul        ::= 'public' | 'protected' | 'private'
method          ::= annotations? S_ (const sp)? generic typemode? S_ ident S_ '(' (S_ params)? S_ ')' (sp const)? sp ';' S_
constructor     ::= annotations? S_ ident S_ '(' (S_ params)? S_ ')' sp ';' S_
params          ::= param (S_ ',' S_ param)*
param           ::= (annotations S_)? (const sp)? generic typemode? S_ ident
field           ::= annotations? S_ const? sp generic typemode? sp ident (sp fieldvalue)? sp ';' S_
fieldvalue      ::= '{' literal '}'
generic         ::= scoped '<' sp generic? (sp ',' sp generic)* '>' | scoped
genanno         ::= ((annotation | generator) S_)+
annotations     ::= annotation (S_ annotation)*
annotation      ::= (annotidx | annotgen) (S_ comments)?
annotgen        ::= '[[' S_ annotnamegen ( '(' S_ annotgenparams S_ ')' ) S_ ']]'
annotidx        ::= '[[' S_ annotnameidx ( '(' S_ annotidxparams S_ ')' )? S_ ']]'
annotnameidx    ::= annottag ident '::' ident
annotnamegen    ::= annottag ident
annottag        ::= '$'
annotidxparams  ::= literal (sp ',' (S_ comments)? S_ literal)* (S_ comments)?
annotgenparams  ::= annotgenparam (sp ',' (S_ comments)? S_ annotgenparam)* (S_ comments)?
annotgenparam   ::= ident sp '=' sp literal
generator       ::= '[[' gentag '(' S_ gennames S_ ')' S_ ']]' (S_ comments)?
gennames        ::= genname (',' S_ genname)*
genname         ::= ident ('/' ident)?
gentag          ::= 'gen'
scoped          ::= ident ('::' ident)*
before          ::= (variable | include | comment | symbol | load | native | invoke) +
after           ::= (variable | native | comment | invoke)+
load            ::= '#pragma' sp loadkey sp ident (sp str)? S_
loadkey         ::= 'load'
symbol          ::= '#pragma' sp symbolkey sp ident S_
symbolkey       ::= 'symbol'
invoke          ::= '#pragma' sp 'invoke' cpp? sp invokecmd sp '(' sp (ident | kvps)? sp ')' S_
invokecmd       ::= ident '::' ident '.' ident
variable        ::= '#pragma' sp 'var' sp ident sp kvps S_
kvps            ::= '{' S_ kvp (sp ',' S_ kvp)* S_ '}'
kvp             ::= ident sp ':' sp literal
include         ::= includekey sp (str | include0) S_
include0        ::= [<] (![<>] any)* [>] 
includekey      ::= '#include'
literal         ::= numext | null | bool | number | string | char
char            ::= ['] escaped | (!['] any) [']
escaped         ::= [\] ['"?\abfnrtv]
null            ::= 'nullptr'
bool            ::= 'true' | 'false'
numext          ::= number '_' ident
number          ::= exp | float | hex | bin | oct | int
exp             ::=  (float | oct | int) [eE] int 
bin             ::=  [-+]? '0' [bB] [0-1]+ 
hex             ::=  [-+]? '0' [xX] [0-9a-fA-F]+ 
float           ::= int ('.' [0-9]*) 
oct             ::=  [-+]? [0] [1-7]+ 
int             ::=  [-+]? [1-9][0-9]*  | [0]
string          ::= str | rawstr
str             ::= ["] (!["] any)* ["]
rawstr          ::= 'R"(' (!rawstrend any)* rawstrend
rawstrend       ::= ')\"'
comments        ::= (comment S_)+
comment         ::= linecomment | blockcomment
blockcomment    ::= startcomment commentblock endcomment
linecomment     ::= '//' lcommentdetails S_
lcommentdetails ::= (!nl any)*
startcomment    ::= '/*'
commentblock    ::= (!endcomment any)*
endcomment      ::= '*/' S_
native          ::= startnative nativeblock endnative
startnative     ::= '#pragma' sp 'native' cpp? S_
cpp             ::= '[' sp 'cpp' sp ']'
nativeblock     ::= (!endnative any)*
endnative       ::= '#pragma' sp 'endnative' S_
typemode        ::=  '&&' | '&' | '*'
const           ::= 'const'
ident           ::= [a-zA-Z_$] [a-zA-Z0-9_$]*
nl             ::=  [#x0D][#x0A]? | [#x0A][#x0D]? | EOF
sp             ::= [ #x09]*
S_              ::= [ #x09#x0D#x0A]*
any  ::= [#x00-#xffff]

mingodad avatar Jul 06 '25 15:07 mingodad