Comments (5)
Yeah, this looks like the same thing as Tatsu's "include operator": https://tatsu.readthedocs.io/en/stable/syntax.html#id29
The main goal would be to flatten the resulting structure, right?
I was thinking about implementing this feature, because I used it extensively back in the day, but by the current architecture converts rules independently from each-other, so a bunch of refactoring would be needed to do this. Or maybe a preprocessing step.
Out of curiosity, which parsing lib uses ~
for this?
from peginator.
By the way, for this specific case in peginator you could use an override rule to flatten the structure the same way by writing something like this:
assign_statement =
LET "(" pairs:assign_pair_list ")" [type_hint] SET assign_rhs [eos] |
LET "(" pairs:assign_pair_list ")" [type_hint] [eos] |
LET pairs:assign_pair_list SET assign_rhs [eos] |
LET pairs:assign_pair_list eos ;
assign_pair_list = @:assign_pair {Comma @:assign_pair} [Comma] ;
assign_pair = {MODIFIERS} Symbol [type_hint] ;
assign_rhs = if_statement|match_statement|expr ;
LET = "let" ;
SET = "=" ;
But I understand this does not solve the case where there are multiple fields in the inlined rule.
from peginator.
Yes, the main purpose is to get a flat structure and reduce redundant dot calls
from peginator.
I use a preprocessing to generate peginator ast to achieve inline
Can the grammar module be set to pub?
Line 153 in a8368bb
The current implementation uses interpolated strings, which are neither sound nor type-safe.
from peginator.
Sure I can, but I'm not sure if you want to go that low level (and I guess generate code directly from the AST), it will be pretty unstable.
Note that I'm working on this feature. The syntax will be:
ComplexRule = >OtherRule { >OtherRule2 };
OtherRule = x:Number "," y:Number;
OtherRule = "(" y:Number "," z:Number ")";
It will be preprocessed to be equivalent to the following:
ComplexRule = x:Number "," y:Number { y:Number "," z:Number };
OtherRule = x:Number "," y:Number;
OtherRule = "(" y:Number "," z:Number ")";
Note how the same field names are used.
I think "Dead" rules will not be automatically eliminated from the generated code, but instead I'll just disable the dead code warning for the generated part.
from peginator.
Related Issues (20)
- How to use custom char check? HOT 7
- Add case insensitive string literals HOT 1
- Generalized position HOT 1
- Precedence climbing HOT 12
- Flattened enums HOT 5
- Dead code elimination
- Left recursion
- Cannot add @position to external rules HOT 2
- Extension name? HOT 3
- How to make indentation? HOT 6
- How to force-include a char? HOT 15
- Automatic rule inlining and type deduction HOT 5
- Confusing error message in case of a syntax error HOT 4
- Later processing errors should give error position information
- Bug: non-overridden choice in all-choices rule creates struct and not enum HOT 8
- Duplicated rule names are allowed
- Referencing non-existent rules in fields are allowed
- Allow the names "state", "global", "result", etc. in field names
- Handle fields (and rules) that have a rust keyword name
- '--railroad' doesn't get included in the cli? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from peginator.