Comments (7)
important (and probably obvious) nuance: actions should be disallowed: they're ok in sequences, but not permutations, because the order may be scrambled
from parboiled.
Actually, Jason, I have been thinking about this a bit more and I find it really hard to come with a good general construct for permutations. The reason is that there are really quite a few dimensions along which one permutation application can differ from another:
- Do all the elements have to appear or are partial permutations, where only a subset of all elements is present, ok? Is the empty match (zero elements) ok?
- How are permutation elements separated? Only empty matches or things like commas, colons, and the like?
- Should a custom action be run after matching an element?
After having looked at a few of my own application I realized that sometimes I need a "partial, non-zero, comma separated permuation with a custom element action" and sometimes I need a "complete, unseparated permutation without element action".
So in total, this construct really seems very hard to generalize properly and I am actually inclined to not offer it but require applications to implement it themselves, to really fit there needs...
Cheers,
Mathias
from parboiled.
Do all the elements have to appear or are partial permutations, where only a subset of all elements is present, ok? Is the empty match (zero elements) ok?
If you want an element to be optional, you wrap it in an Optional()
rule, the same way you would in a Sequence()
.
How are permutation elements separated? Only empty matches or things like commas, colons, and the like?
I can see this as being a feature, but right now you don't offer this feature with other rules.
Should a custom action be run after matching an element?
No, if you want that, you wrap it in a Sequence()
.
For example:
Permutation(
Year(),
Sequence(FirstOf(WordMonth(),NumericMonth()), runSomeActionOnMonth())
Optional(NumericDayOfMonth())
)
I could see wanting a separator, but that's a feature, not a core property of a permutation. There's probably a way to implement it in other ways, but I can't think of it at the top of my head.
I still think this is a valuable primitive that is very difficult for users of Parboiled to implement (as compared to within the Parboiled library), and you should offer primitive constructs with a minimum of extra features.
from parboiled.
Ok, I see your logic.
If the production elements can be complex rules and not just primitives (e.g. Strings or Chars) than most problems seem solvable. The separator rule could be attached to a Permutation with a "withSeparator" modifier, like this:
Permutation(
Year(),
Sequence(FirstOf(WordMonth(),NumericMonth()), runSomeActionOnMonth())
Optional(NumericDayOfMonth())
).withSeparator(Sequence(',', OptWhiteSpace))
Looks doable...
I'll give it a first implementation with the next release...
Cheers and thanks for your ideas,
Mathias
from parboiled.
Cool! I like the withSeparator idea, I had no idea you could do things like that with rule objects.
from parboiled.
Actually, you can't generally.
But the Permutation rule would support 'withSeparator' to apply one...
[email protected]
http://www.parboiled.org
On 21.04.2011, at 14:09, jason-s wrote:
Cool! I like the withSeparator idea, I had no idea you could do things like that with rule objects.
Reply to this email directly or view it on GitHub:
#18 (comment)
from parboiled.
I have implemented something like this:
But it is not really "generic". I suppose it could be made generic enough if you registered rules instead of parser classes as I do now, but the effect is:
- I register n parsers/rules;
- some of them are required to match;
- I check that a rule only matches once.
It works beautifully well for me. But I don't know parboiled enough to make it general.
from parboiled.
Related Issues (20)
- Question: is there a way to obtain the # of tokens in the matched expression without building a parse tree?
- How to get source mapping for successfully parsed nodes HOT 2
- [JDK9] Illegal reflective access by org.parboiled.transform.AsmUtils to method java.lang.ClassLoader.findLoadedClass(java.lang.String) HOT 6
- Does parboiled support adding rules for detection errors?
- 2.13 support? HOT 2
- Special Emoji Support
- enable travis-ci HOT 1
- SimpleErrorRecoveryTest.testRecoveryTimeout unstable
- JDK11 reporting illegal reflective access HOT 25
- Can parboiled actually produce The Rule Tree ("tree") automatically? HOT 1
- Link to the wiki broken in the README
- Matched values for erroneous input HOT 2
- publish for Scala 2.13 HOT 1
- How to represent a) 2 digits b) 1 to 10 times in Parboiled?
- Is the project still active ? HOT 20
- Parboiled stopped working in Java 16 due to enforcement of encapsulation HOT 35
- Broken links in Wiki docs (http://www.decodified.com)
- "illegal writes to a local variable or parameter" in kotlin
- problem with string concatenation with parboiled java 1.4.1 HOT 2
- any clues on why this error
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 parboiled.