Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

space handling in divs

  • Loading branch information...
commit 9c521bf0a7b34a581b070d1f4d949cc5e728a496 1 parent 56a223e
@mmikulicic authored
Showing with 29 additions and 7 deletions.
  1. +1 −1  example.haml
  2. +28 −6 src/haml_macro/core.clj
View
2  example.haml
@@ -7,7 +7,7 @@
%table
%tr
%td First
- %td Last
+ %td
UGO
%tr
%td Marko
View
34 src/haml_macro/core.clj
@@ -6,6 +6,18 @@
(defn not-nil? [p] (not (nil? p)))
+(defn >>= [pa pb]
+ (let-bind [a pa
+ b pb]
+ (result [a b])))
+
+(defn not-one-of [target-strn]
+ (let [str-chars (into #{} target-strn)]
+ (satisfy #(not (contains? str-chars %)))))
+
+
+(defn skipMany [p] (>>== (many p) (fn [x] nil)))
+
(def newlinep (one-of "\n"))
(def sspace (one-of " "))
@@ -24,7 +36,7 @@
(def anyChar (not-char \newline))
(defn text [l] (>>== (many anyChar) #(apply str %)))
-(defn textnl [l] (>>== (text l) #(str % "\n")))
+(defn textnl [l] (>>== (text l) #(apply str % "\n")))
(defn statement [l] (delay (either (tag l) (textnl l))))
@@ -38,12 +50,22 @@
(defn make-compojure-tag [t inline body]
(apply vector (filter not-nil? (apply vector t inline body))))
-(defn tag [l]
+
+;(def inlineTag (>> (many1 sspace) (text 0)))
+(def inlineTag (let-bind [p (not-one-of " \n")
+ rest (text 0)]
+ (result (apply str p rest))))
+
+(defn tagBody [l]
(let [nl (+ 2 l)]
- (let-bind [t tagName
- inline (optional (>> sspace (text 0)))
- body (optional (many1 (indented nl (statement nl))))]
- (result (make-compojure-tag t inline body)))))
+ (many1 (indented nl (statement nl)))))
+
+(defn tag [l]
+ (let-bind [t tagName
+ _ (many sspace)
+ inline (optional inlineTag)
+ rest (optional (tagBody l))]
+ (result (make-compojure-tag t inline rest))))
(defn statements [l] (followedBy (sepBy1 (statement l) newlinep) (optional newlinep)))
Please sign in to comment.
Something went wrong with that request. Please try again.