diff options
author | David Thompson <davet@gnu.org> | 2015-08-09 10:36:33 -0400 |
---|---|---|
committer | David Thompson <davet@gnu.org> | 2015-08-09 10:36:33 -0400 |
commit | 10aa42dfd1db3669c19ec1f82a1475d371962dad (patch) | |
tree | 7e4828d103e7a41fd3ec1493a242eecba28aefe5 /README |
Initial commit.
Diffstat (limited to 'README')
-rw-r--r-- | README | 46 |
1 files changed, 46 insertions, 0 deletions
@@ -0,0 +1,46 @@ +-*- org -*- + +Guile Parser Combinators + +* About + + A simple, SRFI-41 stream-based, monadic parser combinator library + for Guile Scheme. + +* Example + + #+BEGIN_SRC scheme + (define stream->string (compose list->string stream->list)) + + (define (parse-string str) + (lambda (stream) + (let ((input (stream->string (stream-take (string-length str) stream)))) + (if (string=? str input) + (parse-result str (stream-drop (string-length str) stream)) + %parse-failure)))) + + (define article + (parse-any (parse-string "the ") (parse-string "a "))) + + (define noun + (parse-any (parse-string "student ") (parse-string "professor "))) + + (define verb + (parse-any (parse-string "studies ") (parse-string "lectures "))) + + (define noun-phrase + (parse-each article noun)) + + (define verb-phrase + (parse-each verb noun-phrase)) + + (define sentence + (parse-each noun-phrase verb-phrase)) + + (parse noun-phrase "the professor ") + (parse sentence "the professor lectures the student ") + #+END_SRC + +* License + + GNU LGPL3+ |