Permalink
Browse files

handles empty lines (including lines filled with trailing spaces)

  • Loading branch information...
mmikulicic committed Mar 29, 2010
1 parent 5fe3764 commit 843f4f55ea60f78ff9d10cee0261cc031d6048d9
Showing with 24 additions and 9 deletions.
  1. +22 −9 src/haml_macro/core.clj
  2. +2 −0 views/example.haml
View
@@ -4,8 +4,12 @@
(declare tag)
+;; general helpers
+
(defn not-nil? [p] (not (nil? p)))
+;; parser helpers (should be in clarsec)
+
(defn >>= [pa pb]
(let-bind [a pa
b pb]
@@ -18,23 +22,29 @@
(defn skipMany [p] (>>== (many p) (fn [x] nil)))
-(def newlinep (one-of "\n"))
-(def sspace (one-of " "))
-
-(defn prefixed [ch p]
- (>> (is-char ch) p))
-
(defn repeated [n p]
(if (<= n 0)
(result [])
(m-sequence (repeat n p))))
+
+;; common tokens
+
+(def newlinep (one-of "\n"))
+(def sspace (one-of " "))
+
+
+;; parser
+
+(def anyChar (not-char \newline))
+
+(def skipEmptyLine (followedBy (many sspace) newlinep))
+
(defn indented [level p] (let-bind [_ newlinep
+ _ (many skipEmptyLine)
_ (repeated level sspace)]
p))
-(def anyChar (not-char \newline))
-
(defn text [l] (>>== (many anyChar) #(apply str %)))
(defn textnl [l] (>>== (text l) #(apply str % "\n")))
@@ -55,7 +65,6 @@
(apply vector (filter not-nil? (apply vector t inline body))))
-;(def inlineTag (>> (many1 sspace) (text 0)))
(def inlineTag (let-bind [p (not-one-of " \n")
rest (text 0)]
(result (apply str p rest))))
@@ -79,6 +88,10 @@
(def source
(followedBy body (lexeme eof)))
+;;; parser end
+
+;;; generators
+
(defn haml-str [strn]
(:value (parse source strn)))
View
@@ -1,8 +1,10 @@
#content
+
%span welcome
%strong man
#introduction
intro
+
second
%table
%tr

0 comments on commit 843f4f5

Please sign in to comment.