Skip to content
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

Add equivalent of “important” blocks? #298

Open
LunaTheFoxgirl opened this issue Jan 30, 2021 · 3 comments
Open

Add equivalent of “important” blocks? #298

LunaTheFoxgirl opened this issue Jan 30, 2021 · 3 comments

Comments

@LunaTheFoxgirl
Copy link

LunaTheFoxgirl commented Jan 30, 2021

I have some grammar that needs to be able to repeat, it would be nice to have a tag you could wrap some grammar in to to force an error to be output instead of discarded when * or + is used.
Eg.

MyGrammar:
Body < Item+
Item <- :'#' {:'(' identifier :')'}

Would not throw an error if # was not encountered, but would if # was encountered followed by a malformed grammar inside the {}

#(MyItem)
^ Would not error

#MyItem2)
^ Expected '(' got 'M'

(MyItem2)
^ Body would be considered terminated as no # was found

That would make error handling a lot more useful for grammars that contain statements in a non recursive fashion.

@veelo
Copy link
Collaborator

veelo commented Jan 31, 2021

I don't quite understand what you propose. Maybe you can start with a currently working example, and describe what you don't like about its behaviour. Note that {...} are reserved for semantic actions. Poor error messages are a known limitation of Pegged, error reporting is probably the hardest part of a parser generator.

@LunaTheFoxgirl
Copy link
Author

I am unable to provide a "working example" at current time, but essentially what I want is a way to force pegged to stop parsing and output an error if a rule fails.
And yeah, I later realised that { and } are already taken.

But yeah, what I need is a way to tell pegged a way to halt parsing and display an error if a rule fails, without using semantic actions + throwing exceptions from that.

@veelo
Copy link
Collaborator

veelo commented Feb 1, 2021

I think there is a way to get what you want using parser composition and semantic actions. So why wouldn't you want to use semantic actions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants