Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

  • Loading branch information...
commit 3f5e33baf16bbcf974a975d6650fc5dfb3ee9914 1 parent 3e1f1fa
@Ramarren authored
View
4 greedy.lisp
@@ -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
4 package.lisp
@@ -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
8 test-parsers.lisp
@@ -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
4 token-parsers.lisp
@@ -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"
Please sign in to comment.
Something went wrong with that request. Please try again.