Comments (2)
Hi @mschlaipfer !
I'm sorry for the late reply. I'm not sure that every detail of your use case is clear to me: would you like to generate a random subset of the alternatives (i.e., generate every alternative zero or one time in a random order) or to generate a permutation of the alternatives (i.e., generate every alternative exactly one time in a random order)? Both of them is possible and your solution is quite close to the right one:
Subset generation:
entry [x=1,y=1,z=1]
: component[x,y,z] EOF
;
component [x,y,z]
: {x}? 'x' (',' component[0,y,z])?
| {y}? 'y' (',' component[x,0,z])?
| {z}? 'z' (',' component[x,y,0])?
| {x+y+z == 0}?
;
Permutation generation:
entry [x=1,y=1,z=1]
: component[x,y,z] EOF
;
component [x,y,z]
: {x}? 'x' (',' component[0,y,z])
| {y}? 'y' (',' component[x,0,z])
| {z}? 'z' (',' component[x,y,0])
| {x+y+z == 0}?
;
The solution is to add an artificial alternative which is selected if all the other alternatives are exhausted. For subsets, the recursive subrules should be optional, enabling to interrupt the recursion at any iteration. While in case of permutation, the only exit point for the recursive component
rule is the last alternative, which becomes available after all the other alternatives got executed.
I hope this helps! If you have any further questions, don't hesitate to ask, I'll try my best to reply much faster than this time. :)
Cheers,
Reni
from grammarinator.
Hi, thanks for getting back to me.
Both are of interest, actually I care about permutations with required and optional elements. Using your idea of the empty alternative I made progress and have something I'm happy with for generation. I didn't get parsing to work with ANTLR predicates, yet, though.
The above solution you proposed needed a bit more work to avoid trailing ,
. I don't have time to sanitize my code right now, but could share eventually.
Thanks again!
from grammarinator.
Related Issues (20)
- API usage HOT 2
- unrecognized arguments: -p HOT 1
- Enforce coverage of a grammar rule HOT 1
- undefined variables HOT 3
- Random seed initialisation not working HOT 1
- Exclude tests directory from installation HOT 2
- Can max depth >20? HOT 1
- Error in processor.py when processing PartiQL grammars HOT 2
- Example failing - ImportError: cannot import name 'UnparserRuleContext' from 'grammarinator.runtime' HOT 2
- Grammarinator crashes when generating sqlite test cases HOT 1
- Invalid files generated for the working example HOT 4
- Wrong indentation in generated Python code HOT 2
- Test case doesn't work anymore HOT 2
- How to get the value of `current` ? HOT 2
- Wrong python code generated HOT 3
- Can't set alt weights HOT 4
- AttributeError: type object 'JSONGenerator' has no attribute '<INVALID>' HOT 1
- ANTLR download fails due to SSLError HOT 2
- Generation seed not working HOT 1
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 grammarinator.