Skip to content

Commit

Permalink
lexeme symbols and string literals
Browse files Browse the repository at this point in the history
  • Loading branch information
Marko Mikulicic committed Jan 4, 2010
1 parent 5a0016b commit 2c6b2c4
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/clarsec.clj
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@
(defn is-char [c]
(satisfy (partial = c)))

(defn not-char [c]
(satisfy #(not (= c %))))

(defn optional [p]
(<|> p (result nil)))

Expand Down Expand Up @@ -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 ","))



Expand All @@ -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)
)
Expand Down

0 comments on commit 2c6b2c4

Please sign in to comment.