On 1/15/17 12:43 PM, Dicebot wrote:
Sounds intriguing!

On 01/15/2017 01:26 AM, Dmitry Olshansky wrote:
- versatility, generating some goofy parse tree is not a goal, the goal
is extraction of data the way the user specifies

Can you show an example of what you have in mind for this?


Each parser has a value type that it extracts from the stream. It can be an AST node but doesn't have to. For instance, taking a page form the calculator example:

auto expr = dynamic!int;
auto primary = any(
        range!('0', '9').rep.map!(x => x.to!int),
        seq(tk!'(', expr, tk!')').map!(x => x[1])
);


Here 'expr' is a parser that produces an int that will be defined later. Then we see how digits are converted to string: 'range' has value of parsed digit, rep tells to apply it repeatedly and use the slice of input as the value. Finally map converts parser producing slice to parser producing int.

Similarly the result of 'seq' is a tuple and map takes the middle one ('expr'), that produces an int.


I could have wasted time by creating nodes and assigning values in the map functions but if you just want the result of calculation it's all moot.

---
Dmitry Olshansky

Reply via email to