Permalink
Browse files

initial

  • Loading branch information...
0 parents commit 84187d574ad0df19f2442f79b0dcb8309a41b7ae @mmikulicic committed Mar 29, 2010
Showing with 68 additions and 0 deletions.
  1. +4 −0 .gitignore
  2. +15 −0 README
  3. +6 −0 project.clj
  4. +37 −0 src/haml_macro/core.clj
  5. +6 −0 test/haml_macro/core_test.clj
@@ -0,0 +1,4 @@
+pom.xml
+*jar
+lib
+classes
15 README
@@ -0,0 +1,15 @@
+# haml-macro
+
+Example of Off-side rule parser using monadic parsers
+
+## Usage
+
+FIXME: write
+
+## Installation
+
+FIXME: write
+
+## License
+
+FIXME: write
@@ -0,0 +1,6 @@
+(defproject haml-macro "1.0.0-SNAPSHOT"
+ :description "macro which takes haml and generate compojure compatible html rendering"
+ :dependencies [[org.clojure/clojure "1.1.0"]
+ [org.clojure/clojure-contrib "1.1.0"]
+ [clarsec "0.0.1-SNAPSHOT"]
+ ])
@@ -0,0 +1,37 @@
+(ns haml-macro.core
+ (:use [eu.dnetlib.clojure clarsec monad]))
+
+(def newlinep (one-of "\n"))
+
+(def anyChar (not-char \newline))
+
+(defn prefixed [ch p]
+ (>> (is-char ch) p))
+
+(def tagName (prefixed \% baseIdentifier))
+(def idName (prefixed \# baseIdentifier))
+(def className (prefixed \. baseIdentifier))
+
+(def tag (let-bind [t (optional tagName)
+ i (optional idName)
+ c (many className)
+ b (optional (>> space text))]
+ (let [cc (if (empty? c) nil c)
+ tn (if (nil? t) "div" t)]
+ (if (every? nil? [t i cc])
+ fail
+ (result [:tag tn i c b])))))
+
+(def text (>>== (many anyChar) #(vector :text (apply str %))))
+
+(def statement (either tag text))
+
+(def statements (followedBy (sepBy1 statement newlinep) (optional newlinep)))
+
+(def body statements)
+
+(def source
+ (followedBy body (lexeme eof)))
+
+(defn haml [strn]
+ (:value (parse source strn)))
@@ -0,0 +1,6 @@
+(ns haml-macro.core-test
+ (:use [haml-macro.core] :reload-all)
+ (:use [clojure.test]))
+
+(deftest replace-me ;; FIXME: write
+ (is false))

0 comments on commit 84187d5

Please sign in to comment.