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
Simple syntax extensions to shorten grammars #545
Comments
+1 for the Also: #235 |
@rafaelclp Thanks for the link! I probably caught the idea there back in 2014 when I've made my own PEG parser generator. (Well, there is no better explanation why I've chosen the same @ sign.) |
@polkovnikov-ph Since I'm planning to use exprX = (#[+-] _)* exprY
exprY = ::expression ![+-] What do you think? |
@futagoza |
I chose |
@futagoza I'm fine with pretty much any way to do this. Specific character doesn't matter. It will never be worse than having to write |
While PEG.js is already a great tool for parsing, it requires a lot of boilerplate inside of the actions. As two cases constitute most of the time we need actions, some better syntax probably should be considered.
AST node creation
(Right associative operators used for simplicity.) In this example all the
are extraneous. When there is a sequence of named expressions without an action to use those names, it would be useful to imply object creation.
The only case when it's not enough while creating AST is when we need to put
type: 'smth'
into the generated object. Whileis totally an option, some syntactic sugar might be useful too. Here's an example, assuming that
type:
is commonly used as a name of node type tag (type
is a bad name though, because it's useful for typed languages.kind
would be better, but it's rare), and that users won't create AST nodes in arguments of/
choice operator.Cherry-picking
Actions like
happen a lot, because every lexeme in a programming language should be forwarded with something like
_
. It's tolerable when it happens on top level, but things likeare really annoying. It would be nice to have some better syntax like
where
@
sign means "leave this as the only scalar result". No more than one expression in a sequence should be modified with@
prefix operator, and it shouldn't be used in same sequence with named expressions.Alternatively
:
sign can be used instead to conserve@
for some future use, but it requires making currentname:expr
syntax whitespace-sensitive, and that's compatibility issue.The text was updated successfully, but these errors were encountered: