-
Notifications
You must be signed in to change notification settings - Fork 1
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
Challenge: match Parboiled2 result value expressiveness #81
Comments
This rule: OWS ~ optional(test(ctx.headerPresent) ~ header ~ NL) ~
oneOrMore(record).separatedBy(NL) ~ optional(NL) ~ EOI must have a type of When two rules of type I don't know how I don't think SubScript's implementation will be similar to Parboiled2. Parboiled2 parses linearly, hence it is possible to have a value stack and safely work with it. SubScript traverses its call graph in much more complicated way - so we can't use the value stack. I think, if we're intended to use SubScript for parsing, we should create some parsing tests-challenges for it, and also a module that will turn SubScript into a parser. So that we can see how it performs as we add new features. |
Parboiled2 is quite expressive for result values; with help of Shapeless.
E.g. the following lines are extracted from the CSV parser example:
I have no idea how
~> CsvFile
gets two parameters for the construction of a CsvFile; one from the optionalheader
and one from the one-or-morerecord
s.Anyway, it is a challenge to improve SubScript's expressiveness so that it would understand a similar parser specification.
If no result values had been required the specification would simply be:
However, result values are needed. The main challenge is to hand the two parameters to the constructor of
CsvFile
.Suppose we would write:
^1
and2
would imply that the result of the enclosing script (notfile
here, but a lambda, because of the arrow), must be a tupel with 2 fields. This tuple is filled in 2 steps. It is then transferred using the arrow, and handed as 2 parameters to CsvFile.But as long as I don't understand the Parboiled2 code, I cannot be more specific here.
Scripts such as
optional
could probably be defined as:Note that
r^{Option(_)}
sets the result of the enclosing script to the result of the call tor
, wrapped in anOption
.There would be more issues, but it would be good to have a proper explanation of the Parboiled2 code first.
BTW the script
success
may look a bit weird. It starts with a tiny code fragment that sets the result value. This code fragment behaves successfully, butsuccess
should act like a 1. Therefore the tiny code fragment is put in a sequential composition with(+)
i.e. the 1 element.Maybe a shorter notation would be needed; then we may think of
and
The text was updated successfully, but these errors were encountered: