From 10aa42dfd1db3669c19ec1f82a1475d371962dad Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sun, 9 Aug 2015 10:36:33 -0400 Subject: Initial commit. --- README | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 README (limited to 'README') diff --git a/README b/README new file mode 100644 index 0000000..41f3d03 --- /dev/null +++ b/README @@ -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+ -- cgit v1.2.3