I was wondering if anyone might have some advice for a beginner's question with abnf/lexgen. Clearly it has something to do with backtracking, and I hope I'm just missing something simple -- 1500 lines into my parser, I'd hate to have to start from scratch with another approach!
For matching a string of a's and b's that ends with an "a", clearly
(lex (seq (star (bar (lit "a") (lit "b")))
(lit "a"))
error "ababa") ; => error
For patterns on the same level, I can do manual backtracking:
(define-syntax vac
(syntax-rules ()
((_ fn) (lambda args (apply fn args)))))
(define (left-star-seq p1 p2) ; p1*p2
(vac
(bar
(seq p1 (left-star-seq p1 p2))
p2)))
(lex (left-star-seq
(bar (lit "a") (lit "b"))
(lit "a"))
error "ababa") ; => ((#\a #\b #\a #\b #\a) ())
but what if p1 and p2 are on completely different levels, something like:
(define p1 (star (bar (lit "a") (lit "b"))))
(define p2 (lit "a"))
...
(define q2 (seq q1 p1))
(define q4 (seq q3 q2))
(define Word (seq q4 p2))
Is there way to do "composable" backtracking with these tools? (and is the question even the right one?)
Thanks for any ideas,
Nathaniel