Skip to content

Commit

Permalink
Tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
ragnard committed Feb 22, 2013
1 parent 0d879a6 commit fb4d7c7
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/hamelito/parser.clj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
(defrecord Element [name id classes attributes text children])
(defrecord Comment [text condition children])

;;;;--------------------------------------------------------------------
;;;; Parse tree construction

(def empty-document (->Document [] []))
Expand Down Expand Up @@ -62,6 +63,11 @@
(update-children next push-node [(dec level) node]))))
(vec-conj nodes node)))



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; HAML(ish) parser

;;;; Parser state functions

(defn- add-doctype
Expand All @@ -76,14 +82,8 @@
[state indent]
(assoc state :indent indent))

;;;; general parsers


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; HAML(ish) parser

;;;; general

;; TODO: Improve this
(def identifier2 (<|> alpha-num (sym* \-) (sym* \_)))

(def vspace (many new-line*))
Expand Down Expand Up @@ -127,7 +127,9 @@

(def indent (<*> space space))

;;;;--------------------------------------------------------------------
;;;; doctype

(def doctype-def (token* "!!!" ))
(def doctype-value (>> (sym* \space)
(<+> (many (anything-but \newline)))))
Expand All @@ -137,9 +139,9 @@
(return {:doctype (or value :default)})))
(def doctypes (sep-end-by vspace doctype))

;;;;--------------------------------------------------------------------
;;;; attributes


;; html-style attributes

(def html-name (<|> (<+> (many1 identifier2))
Expand Down Expand Up @@ -181,6 +183,7 @@
(def attributes (<|> html-attributes ruby-attributes))


;;;;--------------------------------------------------------------------
;;;; element

(def element (prefixed-identifier "%"))
Expand Down Expand Up @@ -222,6 +225,7 @@
:self-close? (boolean cl)
:inline-content (string/trim ic)})))))

;;;;--------------------------------------------------------------------
;;;; Comments

(def comment-cond (brackets* (<+> (many (anything-but \])))))
Expand All @@ -233,13 +237,15 @@
{:text (string/trim text)
:condition condition}))))

;;;;--------------------------------------------------------------------
;;;; Text Content

(def nested-content (bind [text (<+> (anything-but \space)
(many (anything-but \newline)))]
(return (map->Text
{:text text}))))

;;;;--------------------------------------------------------------------
;;;; Filtered Content

(def filter-type (bind [_ (sym* \:)
Expand All @@ -266,6 +272,7 @@
{:type type
:lines lines}))))

;;;;--------------------------------------------------------------------
;;; Main

(def tag-line (bind [level (many indent)
Expand Down

0 comments on commit fb4d7c7

Please sign in to comment.