-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Keywords token
and layout
are apparently not compatible
#372
Comments
The BNFC philosophy is that One could boost the layout mechanism by allowing also declared tokens as layout keywords, i.e.,
Beyond that, one could detect choice-less tokens such as In general, it would be nice to have BNFC produce a concrete syntax tree (CST) and a procedure to extract the AST from the CST. But this is a quite radical redesign. |
Thanks for the reply @andreasabel. So, without making keywords such as However, I think I must be misunderstanding about how to go about extracting positions generally. For example, if one were implementing a language server one would need to get positions for parse errors to highlight the location where the parsing fell over. But the |
I think the error reporting API also needs a overhaul. The error location shouldn't be mangled into the error message. In general, BNFC in its present state should be thought of as a wizard generating a parser and printer for prototyping rather than professional use. In the worst case, you can get a happy parser from BNFC that sort of does the thing and then hand-edit it to your satisfaction. That said, in general I am looking to make BNFC more professional without breaking backwards-compatibility if possible, so a better API to the parser and better position information in the syntax tree are definitely a way to go forward. |
I am getting doubts whether this would be a common use case or just feature bloat. It seems that the OP wants something like that only for getting position information, but providing more position information should rather be addressed more systematically. |
Perhaps a BNFC flag which adds the full range of input tokens parsed to create this node to each CST node? |
Atm, we do not produce CSTs. We currently only attach the starting position to each node (with I understand your proposal in this way: instead of just attaching a single position to each node, attach a list of start positions of each production item (be it terminal or nonterminal). E.g., a node for
would look like
This could be happening under a flag that addresses the parser. |
More or less, though instead of only providing the first position of each token it'd be better to provide the entire range, either as a pair of The reason is that you don't know the length of every token, so this information is difficult to reconstruct. |
That would certainly address our current problems. I can't help but wonder though if it's a bit hacky though, for example you would have to pattern match on the list and there's no static guarantee that it would have the right number of elements. I guess it could be made a tuple of the correct arity rather than a list... I don't know, offering the full CST seems like a much more principled way to go, although I realise it's a lot more effort. |
When using the parser generated by the grammar fragment
to parse:
I get
syntax error at line 2, column 8 before 'y'
.If instead I use the grammar:
then everything parses fine. The main problem with this is that I think(?) it means that I'm unable to get position information for the "let" and "in" tokens.
The text was updated successfully, but these errors were encountered: