Modular Middle Finder Here is a different PEG solution for the middle finder CFG:
A = x A x | 'a' x = 'a' | 'b' A PEG for the first layer: A <- x C x / 'a' C <- (x &x)+ x <- 'a' / 'b' This will accept 'a' or xCx , where C is a centre span of x's. So far this is a standard PEG, nothing special. Now lets imagine that we can write an extension, a second rule for C, acting as a modular refinement of C: C <- A This rule can be applied any time after C has matched, but it is applied strictly to the string that matched. This PEG is now equivalent to the CFG middle finder. I like this much better, a simple version was easy to implement. The modular model needs more work of course, it is a bit different from a modular choice extension, it is more like a second level grammar. Peter. PS It is not clear if this is still linear time. Maybe it is if it just boils down to a nested PEG sub tree? _______________________________________________ PEG mailing list PEG@lists.csail.mit.edu https://lists.csail.mit.edu/mailman/listinfo/peg