guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: help with peg module and character classes


From: Matt Wette
Subject: Re: help with peg module and character classes
Date: Thu, 13 Feb 2020 16:55:21 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1



On 2/13/20 11:37 AM, Malte Frank Gerdes wrote:
Hey guile-user,

i'm currently trying to use the peg module to parse android bp files. I
have never used pegs before so i might have done an obvious mistake.

Maybe start with something simple.   I hacked this today.  First PEG program. Though I prefer S-expression format.  This just parses    key : "value"  with
optional comments.

(use-modules (ice-9 peg))
(use-modules (ice-9 pretty-print))

(define-peg-pattern ws none
  (+ (or " " "\n")))
(define-peg-pattern c-comment none
  (and "/*" (* (and (not-followed-by "*/") peg-any)) "*/"))
(define-peg-pattern key all
  (and (? ws)
       (? (and c-comment (? ws)))
       (+ (or (range #\a #\z) "_"))))
(define-peg-pattern string-val all
  (and "\"" (* (and (not-followed-by "\"") (or "\\\"" peg-any))) "\""))
(define-peg-pattern object-val all
  (and "{" (* key-val) "}"))
(define-peg-pattern key-val body
  (and key (? ws) ":" (? ws) string-val))

;; (peg:tree (match-pattern key-val "abc : \"def\""))
;; => ((key "abc") ":" (string-val "\"def\""))





reply via email to

[Prev in Thread] Current Thread [Next in Thread]