Permalink
Browse files

lexeme symbols and string literals

  • Loading branch information...
1 parent 5a0016b commit 2c6b2c4adcb871dba23e2289a26da1dbb850abbf @mmikulicic committed Jan 4, 2010
Showing with 21 additions and 2 deletions.
  1. +21 −2 src/clarsec.clj
View
@@ -78,6 +78,9 @@
(defn is-char [c]
(satisfy (partial = c)))
+(defn not-char [c]
+ (satisfy #(not (= c %))))
+
(defn optional [p]
(<|> p (result nil)))
@@ -133,8 +136,14 @@
(def spaces (many space))
-(def semicolon (is-char \;))
-(def comma (is-char \,))
+(defn lexeme [p]
+ (>> spaces p))
+
+(defn symb [name]
+ (lexeme (string name)))
+
+(def semicolon (symb ";"))
+(def comma (symb ","))
@@ -143,6 +152,16 @@
cs (many (either letter digit))]
(result (apply str (cons c cs)))))
+(defn between [open close p]
+ (let-bind [_ open
+ x p
+ _ close]
+ (result x)))
+
+(def stringLiteral
+ (let-bind [x (lexeme (between (is-char \") (is-char \") (many (not-char \"))))]
+ (result (apply str x))))
+
(defn parse [parser input]
((monad parser) input)
)

0 comments on commit 2c6b2c4

Please sign in to comment.