dlang-community / Pegged

A Parsing Expression Grammar (PEG) module, using the D programming language.
534 stars 66 forks source link

Context dependencies #260

Open Aphexus opened 5 years ago

Aphexus commented 5 years ago

Is there any way to have a context dependent rule?

A B

Where B depends on the "value" of A.

e.g.,

A = [abc] B = [efg]

A B{A=a}

The idea is that the rule B only matches if the rule A matched an a.

Probably a much better way to implement it, just trying to demonstrate a possible solution. For simple context dependent grammars, this should work well. I imagine one could do it by grossly complicating the grammar which I want to avoid... it can be done programmatically but I'd rather do it in the grammar if possible, and if not, extend pegged to do it if it is not too difficult.

veelo commented 4 years ago

There is none. I would just write it out:

<- 'a' B / A