You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Token types from internal rules end up in parser #302
The definition of String should not end up in the lexer, and no parser for String should be generated.
Here is an example where parsing actually fails, similar to #204:
Main. Prg ::= Ident ;
internal IId. Prg ::= Id ;
token Id letter+ ; -- This overlaps with Ident, but should not confuse the parser.
The generated (Haskell) parser does not accept input foo but should, since this is an Ident and Id is only used internally. (Dead code should not affect the semantics.)
Hi,
I've been playing around writing a parser for Lilypond and I've been having an issue that I think relates to this issue.
In particular, the following should be equivalent, but I could only parse the latter: c_\ff, c _\ff.
I believe parsing fails because c_ is a valid Ident, however I am not using any Idents in my bnfc rules.
I managed to work around this by removing removing the references to identifier character, or $i in (Haskell backend) the generated Lex.x file.
Will this be solved by this issue, or could it be a separate issue?
Kind regards,
Jacob
Atm BNFC does not correctly support grammars that do not have a notion of identifier. This is because keywords are first parsed (more precisely: lexed) as identifiers, and then looked up in a keyword dictionary. For instance, keyword "if" matches also the regex for an Ident and is lexed as that and then turned into a keyword token.
A fix would be to include keywords in the generated lexer definition as their separate rules. However, this blows up the generated lexer significantly. (This might even exceed the limits on the automaton size in e.g. in ocamllex.) Thus, in practice, one lexes keywords as identifiers.
I think allowing the redefinition of Ident (#197) would solve your problem.
Does this mean that everything that can be lexed must match an Ident? Not sure if I follow.
No, but BNFC puts a regex for Ident in the lexer definition, whether you use it or not. This means that e.g. c_\ff will be lexed as Ident("c_") \ff rather than c _\ff because of the longest match rule (the match "c_" is longer than the match "c" and thus takes precedence). This explains the problems you are experiencing with your generated lexer.
Your problem would be fixed if Ident was not included in the lexer definition, but then the lexer has handle keywords differently.
No, but BNFC puts a regex for Ident in the lexer definition, whether you use it or not. This means that e.g. c_\ff will be lexed as Ident("c_") \ff rather than c _\ff because of the longest match rule (the match "c_" is longer than the match "c" and thus takes precedence). This explains the problems you are experiencing with your generated lexer.
Your problem would be fixed if Ident was not included in the lexer definition, but then the lexer has handle keywords differently.
Let me ask for a command line option to omit auto-including Ident.
I do not want to have this as a default behavior, just would like to be able to have the flag in my Makefile when I need it...
Since long I used workarounds (diff/patch) to omit this but every now and then after an upgrade my patchfile gets broken...
Activity
[ WIP #302 ] isUsedCat distinguishes between Internal and Parsable
fonfalleh commentedon Nov 1, 2020
Hi,
I've been playing around writing a parser for Lilypond and I've been having an issue that I think relates to this issue.
In particular, the following should be equivalent, but I could only parse the latter:
c_\ff,c _\ff.I believe parsing fails because
c_is a valid Ident, however I am not using any Idents in my bnfc rules.I managed to work around this by removing removing the references to identifier character, or
$iin (Haskell backend) the generated Lex.x file.Will this be solved by this issue, or could it be a separate issue?
Kind regards,
Jacob
andreasabel commentedon Nov 2, 2020
Hello @fonfalleh, thanks for he report.
Atm BNFC does not correctly support grammars that do not have a notion of identifier. This is because keywords are first parsed (more precisely: lexed) as identifiers, and then looked up in a keyword dictionary. For instance, keyword "if" matches also the regex for an
Identand is lexed as that and then turned into a keyword token.A fix would be to include keywords in the generated lexer definition as their separate rules. However, this blows up the generated lexer significantly. (This might even exceed the limits on the automaton size in e.g. in
ocamllex.) Thus, in practice, one lexes keywords as identifiers.I think allowing the redefinition of
Ident(#197) would solve your problem.fonfalleh commentedon Nov 10, 2020
Thanks!
I make use of token for variable declarations and references, but they can only contain letters, so I didn't use Ident for that in particular.
Does this mean that everything that can be lexed must match an Ident? Not sure if I follow.
andreasabel commentedon Nov 11, 2020
No, but BNFC puts a regex for
Identin the lexer definition, whether you use it or not. This means that e.g.c_\ffwill be lexed asIdent("c_") \ffrather thanc _\ffbecause of the longest match rule (the match "c_" is longer than the match "c" and thus takes precedence). This explains the problems you are experiencing with your generated lexer.Your problem would be fixed if
Identwas not included in the lexer definition, but then the lexer has handle keywords differently.fonfalleh commentedon Nov 11, 2020
I see, thank you!
jasper-e commentedon Sep 3, 2023
Let me ask for a command line option to omit auto-including Ident.
I do not want to have this as a default behavior, just would like to be able to have the flag in my Makefile when I need it...
Since long I used workarounds (diff/patch) to omit this but every now and then after an upgrade my patchfile gets broken...