[Top][All Lists]

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

Trouble with the PEG parser

From: swedebugia
Subject: Trouble with the PEG parser
Date: Sun, 30 Dec 2018 20:33:56 +0100


I thought out a useful pet project to learn to use the PEG module.

Unfortunately I ended up avoiding it because it errors out when it encounters a s-exp.

This is what I tried to do:

run a command in a pipe returning the contents of all source files of guix (once)
parse this large string with PEG
create stats on the number of lines with comments etc.

This is what I ended up doing:

run a multiple commands in a pipe with sed|grep|wc -l-foo returning the numbers I was interested in.
avoid PEG
print stats.

In the process I learned a lot.
1. (get-string-all) does not return a proper string (string? => #f). I dont understand this as the manual says it should return a string.
2. (ice-9 match) only works on lists it seems.
3. (ice-9 peg) returns #f if it encounters a paren. Maybe there is a way to avoid this - in that case it is not documented in the manual (or I could not find it). (see my example in the file attached) 4. Maybe I misunderstood how to use the PEG parser and matching. In that case a working example and a tip would be very welcome :D

Any thoughts?

Cheers Swedebugia

Attachment: comment-lines-statistics.scm
Description: Text Data

reply via email to

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