Discussion:
Bug in peg parser for double-quotes?
Mark Carter
2018-02-24 19:01:32 UTC
Permalink
I'm trying to use peg pattern matching to match quoted strings. It's not
complete, but I think I found a bug that is holding me back. consider
the following code:

(use-modules (ice-9 peg string-peg))
(use-modules (ice-9 peg using-parsers))
(define-peg-pattern DQ body "\"")
(define-peg-pattern astring body "(DQ .*)")

(define (pma str) (peg:tree (match-pattern DQ str)))
(define (pma1 str) (peg:tree (match-pattern astring str)))


If I execute:

    (pma "\"hello")

then I get

    $1 = "\""

which is correct. It matched the double-quote, as expected.


However, if I execute:

    (pma1 "\"hello")

then I get

    $2 = #f

which is wrong, I think. I'm expected it to match the double-quote, and
any other characters that it enounters. But it doesn't match anything.

Can someone confirm if this appears to be a bug in guile?
Mark Carter
2018-02-24 19:40:06 UTC
Permalink
My bad. I needed to do something like:

(define-peg-string-patterns "astring <-- DQ .*")

My original definition as

(define-peg-pattern astring body "(DQ .*)")

was just wrong.

Loading...