GNU bug report logs - #73188
PEG parser does not support full PEG grammar

Previous Next

Package: guile;

Reported by: Ekaitz Zarraga <ekaitz <at> elenq.tech>

Date: Wed, 11 Sep 2024 22:05:01 UTC

Severity: normal

Done: Ludovic Courtès <ludo <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


Message #43 received at 73188 <at> debbugs.gnu.org (full text, mbox):

From: Ekaitz Zarraga <ekaitz <at> elenq.tech>
To: 73188 <at> debbugs.gnu.org
Cc: ludo <at> gnu.org, Ekaitz Zarraga <ekaitz <at> elenq.tech>
Subject: [PATCH 1/3] PEG: fix [^...]
Date: Sun, 22 Dec 2024 21:01:06 +0100
---
 module/ice-9/peg/string-peg.scm | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/module/ice-9/peg/string-peg.scm b/module/ice-9/peg/string-peg.scm
index 0026f8930..745d8e8e7 100644
--- a/module/ice-9/peg/string-peg.scm
+++ b/module/ice-9/peg/string-peg.scm
@@ -301,11 +301,19 @@ EndOfFile < !.
 (define (Literal->defn lst for-syntax)
   (apply string (map (lambda (x) (Char->defn x for-syntax)) (cdr lst))))
 
-;; (NotInClass ...)
-;;  `-> (and ...)
+;; (NotInClass (Range ...) (Range ...))
+;;  `-> (and (followed-by (not-in-range ...))
+;;           (followed-by (not-in-range ...))
+;;           ...
+;;           (not-in-range ...))
+;; NOTE: the order doesn't matter, because all `not-in-range`s will always
+;; parse exactly one character, but all the elements but the last need not to
+;; consume the input.
 (define (NotInClass->defn lst for-syntax)
-  #`(and #,@(map (lambda (x) (NotInRange->defn x for-syntax))
-                 (cdr lst))))
+  #`(and
+      #,@(map (lambda (x) #`(followed-by #,(NotInRange->defn x for-syntax)))
+              (cddr lst))
+      #,(NotInRange->defn (cadr lst) for-syntax)))
 
 ;; (Class ...)
 ;;  `-> (or ...)
-- 
2.46.0





This bug report was last modified 143 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.