-
Notifications
You must be signed in to change notification settings - Fork 15
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
Feature Request: Allow default tokens to be returned, for optional tokens #32
Comments
I'm not sure if this can be added in a backwards-compatible way, but it's good to consider in pest3 -- @TheVeryDarkness wdyt? |
I can think of a dirty hack that might just work. Allow a single reserved symbol (let's say Ex: Modify the rule I showed above as: As soon as pest's parser reads That's it. This requires very little modification to pest's grammar and logic, and only acts to short circuit the decision arm. The effect of So, I think this can be added as a new feature, in a backward compatible way. |
@oxcrow the changes to the grammar may result in semver-breaking changes (due to some old design choices / the lack of It could, however, potentially go under the |
There might be another simpler solution ... Instead of modifying pest's grammar, what if we modify pest-ast? If an This should work. However, the To solve that, Instead of an For example: #[derive(Debug, Clone, FromPest)]
#[pest_ast(rule(Rule::function))]
pub struct Function {
pub id: Id,
pub args: Args,
#[pest_ast_default(Void)] // <<< Users can set a default value using an attribute
pub r#type: Type, // <<< This should be just Type, not Option<Type>
pub items: Vec<FunctionItem>,
} This seems to be simpler than my previous hack idea, and will also be safer, since the pest grammar won't need to be modified. |
Yeah, that sounds like a better solution 👍 |
Thanks! I'm glad to help. 😃 Developing this feature may obviously take some time, so for users like me who will be waiting, I would recommend not to use such optional grammar right now, and instead chose to only use the base grammar. i.e // Don't support optional grammar
let x = 1;
// Instead, only support the base grammar
let const x = 1; This is for two reasons:
|
Hi, Has there been any progress regarding this feature? |
Hi,
Consider these statements ...
We often have such instances where the default token is assumed, if it is not given by the user.
Thus, it would be easier for us, if the default tokens were returned if optional tokens don't exist in our rules.
This would be helpful, as currently to represent the return type of the functions, I would need to use an
Option<>
, and modify the AST nodes after parsing, to set the function's return type asvoid
.This is rather tedious work, and complicates our compiler's AST representation.
In OCaml's Menhir parser generator, if a rule doesn't match anything, we are allowed to return a default node.
Such a feature would also be extremely helpful for pest.
The text was updated successfully, but these errors were encountered: