Permalink
Browse files

Add pure-word?/* which accepts only alphabetic characters.

  • Loading branch information...
Ramarren committed Mar 4, 2012
1 parent 3e1f1fa commit 3f5e33baf16bbcf974a975d6650fc5dfb3ee9914
Showing with 19 additions and 1 deletion.
  1. +4 −0 greedy.lisp
  2. +3 −1 package.lisp
  3. +8 −0 test-parsers.lisp
  4. +4 −0 token-parsers.lisp
View
@@ -122,6 +122,10 @@ non-recursively and has better memory performance."
"Parser: accept a string of alphanumeric characters"
(gather-if* #'alphanumericp :result-type 'string))
+(def-cached-parser pure-word*
+ "Parser: accept a string of alphabetic characters"
+ (gather-if* #'alpha-char-p :result-type 'string))
+
(defun nat* (&optional (radix 10))
"Non-backtracking parser: accept natural number, consuming as many digits as possible"
(named-seq* (<- number (gather-if* (rcurry #'digit-char-p radix) :result-type 'string))
View
@@ -111,7 +111,9 @@
#:validate?
#:parse-sequence
#:parse-sequence*
- #:quoted?)
+ #:quoted?
+ #:pure-word?
+ #:pure-word*)
;; some function for creating -using-context parsers from other packages
(:export #:storage-of
#:common-of
View
@@ -44,6 +44,14 @@
("abc" "abc" "123" "123" "abc!def" "abc")
(" " ";,!"))
+(defparsertest test-pure-word? (pure-word?)
+ ("abc" "abc" "abc!def" "abc")
+ (" " ";,!" "123"))
+
+(defparsertest test-pure-word* (pure-word*)
+ ("abc" "abc" "abc!def" "abc")
+ (" " ";,!" "123"))
+
(defparsertest test-string? (string? (list #\a #\b #\c) :result-type 'list)
("abc" (list #\a #\b #\c) "abcd" (list #\a #\b #\c))
("cde" "abd" "aBc"))
View
@@ -35,6 +35,10 @@
"Parser: accept a string of alphanumeric characters"
(between? (alphanum?) 1 nil 'string))
+(def-cached-parser pure-word?
+ "Parser: accept a string of alphabetic characters"
+ (between? (letter?) 1 nil 'string))
+
;; naive implementation using monadic combinators, unfortunately rather slow
;; (defun int? ()
;; "Parser: accept an integer"

0 comments on commit 3f5e33b

Please sign in to comment.