mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-29 06:20:30 +02:00
PEG: Add full support for PEG + some extensions
This commit adds support for PEG as described in: <https://bford.info/pub/lang/peg.pdf> It adds support for the missing features (comments, underscores in identifiers and escaping) while keeping the extensions (dashes in identifiers, < and <--). The naming system tries to be as close as possible to the one proposed in the paper. * module/ice-9/peg/string-peg.scm: Rewrite PEG parser. * test-suite/tests/peg.test: Fix import Signed-off-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
parent
47807c9b11
commit
ff11753df1
4 changed files with 313 additions and 180 deletions
|
@ -28,17 +28,25 @@
|
|||
;; the nonterminals defined in the PEG parser written with
|
||||
;; S-expressions.
|
||||
(define grammar-mapping
|
||||
'((grammar peg-grammar)
|
||||
(pattern peg-pattern)
|
||||
(alternative peg-alternative)
|
||||
(suffix peg-suffix)
|
||||
(primary peg-primary)
|
||||
(literal peg-literal)
|
||||
(charclass peg-charclass)
|
||||
(CCrange charclass-range)
|
||||
(CCsingle charclass-single)
|
||||
(nonterminal peg-nonterminal)
|
||||
(sp peg-sp)))
|
||||
'((Grammar Grammar)
|
||||
(Definition Definition)
|
||||
(Expression Expression)
|
||||
(Sequence Sequence)
|
||||
(Prefix Prefix)
|
||||
(Suffix Suffix)
|
||||
(Primary Primary)
|
||||
(Identifier Identifier)
|
||||
(Literal Literal)
|
||||
(Class Class)
|
||||
(Range Range)
|
||||
(Char Char)
|
||||
(LEFTARROW LEFTARROW)
|
||||
(AND AND)
|
||||
(NOT NOT)
|
||||
(QUESTION QUESTION)
|
||||
(STAR STAR)
|
||||
(PLUS PLUS)
|
||||
(DOT DOT)))
|
||||
|
||||
;; Transforms the nonterminals defined in the PEG parser written as a PEG to the nonterminals defined in the PEG parser written with S-expressions.
|
||||
(define (grammar-transform x)
|
||||
|
@ -69,7 +77,7 @@
|
|||
(peg:tree (match-pattern (@@ (ice-9 peg) peg-grammar) (@@ (ice-9 peg) peg-as-peg)))
|
||||
(tree-map
|
||||
grammar-transform
|
||||
(peg:tree (match-pattern grammar (@@ (ice-9 peg) peg-as-peg)))))))
|
||||
(peg:tree (match-pattern Grammar (@@ (ice-9 peg) peg-as-peg)))))))
|
||||
|
||||
;; A grammar for pascal-style comments from Wikipedia.
|
||||
(define comment-grammar
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue