Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
Marko Mikulicic committed Mar 29, 2010
0 parents commit 84187d5
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pom.xml
*jar
lib
classes
15 changes: 15 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# haml-macro

Example of Off-side rule parser using monadic parsers

## Usage

FIXME: write

## Installation

FIXME: write

## License

FIXME: write
6 changes: 6 additions & 0 deletions project.clj
Original file line number Diff line number Diff line change
@@ -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"]
])
37 changes: 37 additions & 0 deletions src/haml_macro/core.clj
Original file line number Diff line number Diff line change
@@ -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)))
6 changes: 6 additions & 0 deletions test/haml_macro/core_test.clj
Original file line number Diff line number Diff line change
@@ -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.