Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make whitespace? and word? backtracking, export new symbols.

  • Loading branch information...
commit bdf0843a234936e9d54062d2c13bcfdd372aa62f 1 parent 653c140
@Ramarren authored
Showing with 18 additions and 4 deletions.
  1. +10 −0 greedy.lisp
  2. +3 −0  package.lisp
  3. +5 −4 token-parsers.lisp
View
10 greedy.lisp
@@ -112,6 +112,16 @@ non-recursively and has better memory performance."
:tree init-x :suffix inp))))))
(bind p #'rest-chain))))
+(def-cached-arg-parser whitespace* (&key (result-type nil) (accept-empty nil))
+ "Non-backtracking parser: accept a sequence of whitespace characters."
+ (gather-if* (rcurry #'member '(#\Space #\Newline #\ ))
+ :result-type result-type
+ :accept-empty accept-empty))
+
+(def-cached-parser 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
3  package.lisp
@@ -18,6 +18,9 @@
#:letter?
#:alphanum?
#:word?
+ #:word*
+ #:whitespace?
+ #:whitespace*
#:string?
#:many?
#:many1?
View
9 token-parsers.lisp
@@ -26,13 +26,14 @@
(def-cached-arg-parser whitespace? (&key (result-type nil) (accept-empty nil))
"Parser: accept a sequence of whitespace characters."
- (gather-if* (rcurry #'member '(#\Space #\Newline #\ ))
- :result-type result-type
- :accept-empty accept-empty))
+ (between? (sat (rcurry #'member '(#\Space #\Newline #\ )))
+ (if accept-empty nil 1)
+ nil
+ result-type))
(def-cached-parser word?
"Parser: accept a string of alphabetic characters"
- (gather-if* #'alpha-char-p :result-type 'string))
+ (between? (alphanum?) 1 nil 'string))
;; naive implementation using monadic combinators, unfortunately rather slow
;; (defun int? ()

0 comments on commit bdf0843

Please sign in to comment.
Something went wrong with that request. Please try again.