Permalink
Browse files

.

  • Loading branch information...
1 parent df67786 commit 3807f4b28c147afec0e866cc48103e9a082bea4a @richard-lyman committed Dec 30, 2011
Showing with 17 additions and 11 deletions.
  1. +17 −11 src/com/lithinos/amotoen/core.clj
View
28 src/com/lithinos/amotoen/core.clj
@@ -57,7 +57,7 @@
:Either [\( \| :_ :Body '(* [:_* :Body]) :_* \)]
:ZeroOrMore [\( \* :_ :Body :_* \)]
:ZeroOrOne [\( \? :_ :Body :_* \)]
- :AnyNot [\( \% :_ '(| :Keyword :Char) :_* \)]
+ :AnyNot [\( \% :_ :Body :_* \)]
:Char [\\ '(| :TabChar :SpaceChar :NewlineChar (% \space))]
:TabChar (pegs "tab")
:SpaceChar (pegs "space")
@@ -69,7 +69,7 @@
;
; So. The two below are supposed to be 'faster'... when the body you're running is slow-ish... in comparison... and it's not...
; ... that might be because for most situations the 'backtracking' is only a single character worth
-; ... and the two below are more complex
+; ... and the two below could be harder to maintain anyway...
;
#_(let [[result resultw] (first (remove #(nil? (first %))
(pmap #(let [cw (clone w)] [(pegasus % g cw) cw])
@@ -93,7 +93,7 @@
(let [t (first n)
b (second n)]
(cond (= t '|) (let [temp (either n g w)] (debug w "Either returning:" temp) temp)
- (= t '*) (list (doall (take-while #(if (keyword? b) (b %) %) ; When it's not keyword?, it's list? or vector? or char?
+ (= t '*) (list (doall (take-while #(if (keyword? b) (b %) %)
(repeatedly #(pegasus b g w)))))
(= t '?) (pegasus b g w)
; If we succeed, then we fail - that's the point of AnyNot... If we fail, then we accept the current char
@@ -130,14 +130,20 @@
(de w)
result))
-; Maybe bring this out into a resource file that can be read in at run-time?
-;(def grammar-ast (pr-str '{:Grammar [\{ {:_* (())} {:Rule [{:Keyword [\: {:ValidKeywordChar \_} (({:ValidKeywordChar \*}))]} {:_ [{:Whitespace \space} (())]} {:Body {:Grouping {:ZeroOrMore [\( \* {:_ [{:Whitespace \space} (())]} {:Body {:Keyword [\: {:ValidKeywordChar \W} (({:ValidKeywordChar \h} {:ValidKeywordChar \i} {:ValidKeywordChar \t} {:ValidKeywordChar \e} {:ValidKeywordChar \s} {:ValidKeywordChar \p} {:ValidKeywordChar \a} {:ValidKeywordChar \c} {:ValidKeywordChar \e}))]}} {:_* (())} \)]}}}]} (([{:_ [{:Whitespace \,} (({:Whitespace \space}))]} {:Rule [{:Keyword [\: {:ValidKeywordChar \Z} (({:ValidKeywordChar \e} {:ValidKeywordChar \r} {:ValidKeywordChar \o} {:ValidKeywordChar \O} {:ValidKeywordChar \r} {:ValidKeywordChar \M} {:ValidKeywordChar \o} {:ValidKeywordChar \r} {:ValidKeywordChar \e}))]} {:_ [{:Whitespace \space} (())]} {:Body {:Grouping {:Sequence [\[ {:_* (())} {:Body {:Char [\\ \(]}} (([{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \*]}}] [{:_* (({:Whitespace \space}))} {:Body {:Keyword [\: {:ValidKeywordChar \_} (())]}}] [{:_* (({:Whitespace \space}))} {:Body {:Keyword [\: {:ValidKeywordChar \B} (({:ValidKeywordChar \o} {:ValidKeywordChar \d} {:ValidKeywordChar \y}))]}}] [{:_* (({:Whitespace \space}))} {:Body {:Keyword [\: {:ValidKeywordChar \_} (({:ValidKeywordChar \*}))]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \)]}}])) {:_* (())} \]]}}}]}] [{:_ [{:Whitespace \,} (({:Whitespace \space}))]} {:Rule [{:Keyword [\: {:ValidKeywordChar \B} (({:ValidKeywordChar \o} {:ValidKeywordChar \d} {:ValidKeywordChar \y}))]} {:_ [{:Whitespace \space} (())]} {:Body {:Grouping {:Either [\( \| {:_ [{:Whitespace \space} (())]} {:Body {:Keyword [\: {:ValidKeywordChar \K} (({:ValidKeywordChar \e} {:ValidKeywordChar \y} {:ValidKeywordChar \w} {:ValidKeywordChar \o} {:ValidKeywordChar \r} {:ValidKeywordChar \d}))]}} (([{:_* (({:Whitespace \space}))} {:Body {:Keyword [\: {:ValidKeywordChar \C} (({:ValidKeywordChar \h} {:ValidKeywordChar \a} {:ValidKeywordChar \r}))]}}] [{:_* (({:Whitespace \space}))} {:Body {:Keyword [\: {:ValidKeywordChar \G} (({:ValidKeywordChar \r} {:ValidKeywordChar \o} {:ValidKeywordChar \u} {:ValidKeywordChar \p} {:ValidKeywordChar \i} {:ValidKeywordChar \n} {:ValidKeywordChar \g}))]}}])) {:_* (())} \)]}}}]}] [{:_ [{:Whitespace \,} (({:Whitespace \space}))]} {:Rule [{:Keyword [\: {:ValidKeywordChar \S} (({:ValidKeywordChar \p} {:ValidKeywordChar \a} {:ValidKeywordChar \c} {:ValidKeywordChar \e} {:ValidKeywordChar \C} {:ValidKeywordChar \h} {:ValidKeywordChar \a} {:ValidKeywordChar \r}))]} {:_ [{:Whitespace \space} (())]} {:Body {:Grouping {:Sequence [\[ {:_* (())} {:Body {:Char [\\ \s]}} (([{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \p]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \a]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \c]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \e]}}])) {:_* (())} \]]}}}]}] [{:_ [{:Whitespace \,} (({:Whitespace \space}))]} {:Rule [{:Keyword [\: {:ValidKeywordChar \_} (())]} {:_ [{:Whitespace \space} (())]} {:Body {:Grouping {:Sequence [\[ {:_* (())} {:Body {:Keyword [\: {:ValidKeywordChar \W} (({:ValidKeywordChar \h} {:ValidKeywordChar \i} {:ValidKeywordChar \t} {:ValidKeywordChar \e} {:ValidKeywordChar \s} {:ValidKeywordChar \p} {:ValidKeywordChar \a} {:ValidKeywordChar \c} {:ValidKeywordChar \e}))]}} (([{:_* (({:Whitespace \space}))} {:Body {:Grouping {:ZeroOrMore [\( \* {:_ [{:Whitespace \space} (())]} {:Body {:Keyword [\: {:ValidKeywordChar \W} (({:ValidKeywordChar \h} {:ValidKeywordChar \i} {:ValidKeywordChar \t} {:ValidKeywordChar \e} {:ValidKeywordChar \s} {:ValidKeywordChar \p} {:ValidKeywordChar \a} {:ValidKeywordChar \c} {:ValidKeywordChar \e}))]}} {:_* (())} \)]}}}])) {:_* (())} \]]}}}]}] [{:_ [{:Whitespace \,} (({:Whitespace \space}))]} {:Rule [{:Keyword [\: {:ValidKeywordChar \S} (({:ValidKeywordChar \e} {:ValidKeywordChar \q} {:ValidKeywordChar \u} {:ValidKeywordChar \e} {:ValidKeywordChar \n} {:ValidKeywordChar \c} {:ValidKeywordChar \e}))]} {:_ [{:Whitespace \space} (())]} {:Body {:Grouping {:Sequence [\[ {:_* (())} {:Body {:Char [\\ \[]}} (([{:_* (({:Whitespace \space}))} {:Body {:Keyword [\: {:ValidKeywordChar \_} (({:ValidKeywordChar \*}))]}}] [{:_* (({:Whitespace \space}))} {:Body {:Keyword [\: {:ValidKeywordChar \B} (({:ValidKeywordChar \o} {:ValidKeywordChar \d} {:ValidKeywordChar \y}))]}}] [{:_* (({:Whitespace \space}))} {:Body {:Grouping {:ZeroOrMore [\( \* {:_ [{:Whitespace \space} (())]} {:Body {:Grouping {:Sequence [\[ {:_* (())} {:Body {:Keyword [\: {:ValidKeywordChar \_} (({:ValidKeywordChar \*}))]}} (([{:_* (({:Whitespace \space}))} {:Body {:Keyword [\: {:ValidKeywordChar \B} (({:ValidKeywordChar \o} {:ValidKeywordChar \d} {:ValidKeywordChar \y}))]}}])) {:_* (())} \]]}}} {:_* (())} \)]}}}] [{:_* (({:Whitespace \space}))} {:Body {:Keyword [\: {:ValidKeywordChar \_} (({:ValidKeywordChar \*}))]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \]]}}])) {:_* (())} \]]}}}]}] [{:_ [{:Whitespace \,} (({:Whitespace \space}))]} {:Rule [{:Keyword [\: {:ValidKeywordChar \V} (({:ValidKeywordChar \a} {:ValidKeywordChar \l} {:ValidKeywordChar \i} {:ValidKeywordChar \d} {:ValidKeywordChar \K} {:ValidKeywordChar \e} {:ValidKeywordChar \y} {:ValidKeywordChar \w} {:ValidKeywordChar \o} {:ValidKeywordChar \r} {:ValidKeywordChar \d} {:ValidKeywordChar \C} {:ValidKeywordChar \h} {:ValidKeywordChar \a} {:ValidKeywordChar \r}))]} {:_ [{:Whitespace \space} (())]} {:Body {:Grouping {:Either [\( \| {:_ [{:Whitespace \space} (())]} {:Body {:Char [\\ \A]}} (([{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \B]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \C]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \D]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \E]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \F]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \G]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \H]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \I]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \J]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \K]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \L]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \M]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \N]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \O]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \P]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \Q]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \R]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \S]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \T]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \U]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \V]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \W]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \X]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \Y]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \Z]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \a]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \b]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \c]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \d]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \e]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \f]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \g]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \h]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \i]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \j]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \k]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \l]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \m]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \n]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \o]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \p]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \q]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \r]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \s]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \t]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \u]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \v]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \w]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \x]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \y]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \z]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \0]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \1]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \2]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \3]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \4]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \5]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \6]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \7]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \8]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \9]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \:]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \/]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \*]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \+]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \!]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \_]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \?]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \-]}}])) {:_* (())} \)]}}}]}] [{:_ [{:Whitespace \,} (({:Whitespace \space}))]} {:Rule [{:Keyword [\: {:ValidKeywordChar \A} (({:ValidKeywordChar \n} {:ValidKeywordChar \y} {:ValidKeywordChar \N} {:ValidKeywordChar \o} {:ValidKeywordChar \t}))]} {:_ [{:Whitespace \space} (())]} {:Body {:Grouping {:Sequence [\[ {:_* (())} {:Body {:Char [\\ \(]}} (([{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \%]}}] [{:_* (({:Whitespace \space}))} {:Body {:Keyword [\: {:ValidKeywordChar \_} (())]}}] [{:_* (({:Whitespace \space}))} {:Body {:Grouping {:Either [\( \| {:_ [{:Whitespace \space} (())]} {:Body {:Keyword [\: {:ValidKeywordChar \K} (({:ValidKeywordChar \e} {:ValidKeywordChar \y} {:ValidKeywordChar \w} {:ValidKeywordChar \o} {:ValidKeywordChar \r} {:ValidKeywordChar \d}))]}} (([{:_* (({:Whitespace \space}))} {:Body {:Keyword [\: {:ValidKeywordChar \C} (({:ValidKeywordChar \h} {:ValidKeywordChar \a} {:ValidKeywordChar \r}))]}}])) {:_* (())} \)]}}}] [{:_* (({:Whitespace \space}))} {:Body {:Keyword [\: {:ValidKeywordChar \_} (({:ValidKeywordChar \*}))]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \)]}}])) {:_* (())} \]]}}}]}] [{:_ [{:Whitespace \,} (({:Whitespace \space}))]} {:Rule [{:Keyword [\: {:ValidKeywordChar \E} (({:ValidKeywordChar \i} {:ValidKeywordChar \t} {:ValidKeywordChar \h} {:ValidKeywordChar \e} {:ValidKeywordChar \r}))]} {:_ [{:Whitespace \space} (())]} {:Body {:Grouping {:Sequence [\[ {:_* (())} {:Body {:Char [\\ \(]}} (([{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \|]}}] [{:_* (({:Whitespace \space}))} {:Body {:Keyword [\: {:ValidKeywordChar \_} (())]}}] [{:_* (({:Whitespace \space}))} {:Body {:Keyword [\: {:ValidKeywordChar \B} (({:ValidKeywordChar \o} {:ValidKeywordChar \d} {:ValidKeywordChar \y}))]}}] [{:_* (({:Whitespace \space}))} {:Body {:Grouping {:ZeroOrMore [\( \* {:_ [{:Whitespace \space} (())]} {:Body {:Grouping {:Sequence [\[ {:_* (())} {:Body {:Keyword [\: {:ValidKeywordChar \_} (({:ValidKeywordChar \*}))]}} (([{:_* (({:Whitespace \space}))} {:Body {:Keyword [\: {:ValidKeywordChar \B} (({:ValidKeywordChar \o} {:ValidKeywordChar \d} {:ValidKeywordChar \y}))]}}])) {:_* (())} \]]}}} {:_* (())} \)]}}}] [{:_* (({:Whitespace \space}))} {:Body {:Keyword [\: {:ValidKeywordChar \_} (({:ValidKeywordChar \*}))]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \)]}}])) {:_* (())} \]]}}}]}] [{:_ [{:Whitespace \,} (({:Whitespace \space}))]} {:Rule [{:Keyword [\: {:ValidKeywordChar \T} (({:ValidKeywordChar \a} {:ValidKeywordChar \b} {:ValidKeywordChar \C} {:ValidKeywordChar \h} {:ValidKeywordChar \a} {:ValidKeywordChar \r}))]} {:_ [{:Whitespace \space} (())]} {:Body {:Grouping {:Sequence [\[ {:_* (())} {:Body {:Char [\\ \t]}} (([{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \a]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \b]}}])) {:_* (())} \]]}}}]}] [{:_ [{:Whitespace \,} (({:Whitespace \space}))]} {:Rule [{:Keyword [\: {:ValidKeywordChar \N} (({:ValidKeywordChar \e} {:ValidKeywordChar \w} {:ValidKeywordChar \l} {:ValidKeywordChar \i} {:ValidKeywordChar \n} {:ValidKeywordChar \e} {:ValidKeywordChar \C} {:ValidKeywordChar \h} {:ValidKeywordChar \a} {:ValidKeywordChar \r}))]} {:_ [{:Whitespace \space} (())]} {:Body {:Grouping {:Sequence [\[ {:_* (())} {:Body {:Char [\\ \n]}} (([{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \e]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \w]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \l]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \i]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \n]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \e]}}])) {:_* (())} \]]}}}]}] [{:_ [{:Whitespace \,} (({:Whitespace \space}))]} {:Rule [{:Keyword [\: {:ValidKeywordChar \R} (({:ValidKeywordChar \u} {:ValidKeywordChar \l} {:ValidKeywordChar \e}))]} {:_ [{:Whitespace \space} (())]} {:Body {:Grouping {:Sequence [\[ {:_* (())} {:Body {:Keyword [\: {:ValidKeywordChar \K} (({:ValidKeywordChar \e} {:ValidKeywordChar \y} {:ValidKeywordChar \w} {:ValidKeywordChar \o} {:ValidKeywordChar \r} {:ValidKeywordChar \d}))]}} (([{:_* (({:Whitespace \space}))} {:Body {:Keyword [\: {:ValidKeywordChar \_} (())]}}] [{:_* (({:Whitespace \space}))} {:Body {:Keyword [\: {:ValidKeywordChar \B} (({:ValidKeywordChar \o} {:ValidKeywordChar \d} {:ValidKeywordChar \y}))]}}])) {:_* (())} \]]}}}]}] [{:_ [{:Whitespace \,} (({:Whitespace \space}))]} {:Rule [{:Keyword [\: {:ValidKeywordChar \W} (({:ValidKeywordChar \h} {:ValidKeywordChar \i} {:ValidKeywordChar \t} {:ValidKeywordChar \e} {:ValidKeywordChar \s} {:ValidKeywordChar \p} {:ValidKeywordChar \a} {:ValidKeywordChar \c} {:ValidKeywordChar \e}))]} {:_ [{:Whitespace \space} (())]} {:Body {:Grouping {:Either [\( \| {:_ [{:Whitespace \space} (())]} {:Body {:Char [\\ {:SpaceChar [\s \p \a \c \e]}]}} (([{:_* (({:Whitespace \space}))} {:Body {:Char [\\ {:NewlineChar [\n \e \w \l \i \n \e]}]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ {:TabChar [\t \a \b]}]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \,]}}])) {:_* (())} \)]}}}]}] [{:_ [{:Whitespace \,} (({:Whitespace \space}))]} {:Rule [{:Keyword [\: {:ValidKeywordChar \G} (({:ValidKeywordChar \r} {:ValidKeywordChar \a} {:ValidKeywordChar \m} {:ValidKeywordChar \m} {:ValidKeywordChar \a} {:ValidKeywordChar \r}))]} {:_ [{:Whitespace \space} (())]} {:Body {:Grouping {:Sequence [\[ {:_* (())} {:Body {:Char [\\ \{]}} (([{:_* (({:Whitespace \space}))} {:Body {:Keyword [\: {:ValidKeywordChar \_} (({:ValidKeywordChar \*}))]}}] [{:_* (({:Whitespace \space}))} {:Body {:Keyword [\: {:ValidKeywordChar \R} (({:ValidKeywordChar \u} {:ValidKeywordChar \l} {:ValidKeywordChar \e}))]}}] [{:_* (({:Whitespace \space}))} {:Body {:Grouping {:ZeroOrMore [\( \* {:_ [{:Whitespace \space} (())]} {:Body {:Grouping {:Sequence [\[ {:_* (())} {:Body {:Keyword [\: {:ValidKeywordChar \_} (())]}} (([{:_* (({:Whitespace \space}))} {:Body {:Keyword [\: {:ValidKeywordChar \R} (({:ValidKeywordChar \u} {:ValidKeywordChar \l} {:ValidKeywordChar \e}))]}}])) {:_* (())} \]]}}} {:_* (())} \)]}}}] [{:_* (({:Whitespace \space}))} {:Body {:Keyword [\: {:ValidKeywordChar \_} (({:ValidKeywordChar \*}))]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \}]}}])) {:_* (())} \]]}}}]}] [{:_ [{:Whitespace \,} (({:Whitespace \space}))]} {:Rule [{:Keyword [\: {:ValidKeywordChar \C} (({:ValidKeywordChar \h} {:ValidKeywordChar \a} {:ValidKeywordChar \r}))]} {:_ [{:Whitespace \space} (())]} {:Body {:Grouping {:Sequence [\[ {:_* (())} {:Body {:Char [\\ \\]}} (([{:_* (({:Whitespace \space}))} {:Body {:Grouping {:Either [\( \| {:_ [{:Whitespace \space} (())]} {:Body {:Keyword [\: {:ValidKeywordChar \T} (({:ValidKeywordChar \a} {:ValidKeywordChar \b} {:ValidKeywordChar \C} {:ValidKeywordChar \h} {:ValidKeywordChar \a} {:ValidKeywordChar \r}))]}} (([{:_* (({:Whitespace \space}))} {:Body {:Keyword [\: {:ValidKeywordChar \S} (({:ValidKeywordChar \p} {:ValidKeywordChar \a} {:ValidKeywordChar \c} {:ValidKeywordChar \e} {:ValidKeywordChar \C} {:ValidKeywordChar \h} {:ValidKeywordChar \a} {:ValidKeywordChar \r}))]}}] [{:_* (({:Whitespace \space}))} {:Body {:Keyword [\: {:ValidKeywordChar \N} (({:ValidKeywordChar \e} {:ValidKeywordChar \w} {:ValidKeywordChar \l} {:ValidKeywordChar \i} {:ValidKeywordChar \n} {:ValidKeywordChar \e} {:ValidKeywordChar \C} {:ValidKeywordChar \h} {:ValidKeywordChar \a} {:ValidKeywordChar \r}))]}}] [{:_* (({:Whitespace \space}))} {:Body {:Grouping {:AnyNot [\( \% {:_ [{:Whitespace \space} (())]} {:Char [\\ {:SpaceChar [\s \p \a \c \e]}]} {:_* (())} \)]}}}])) {:_* (())} \)]}}}])) {:_* (())} \]]}}}]}] [{:_ [{:Whitespace \,} (({:Whitespace \space}))]} {:Rule [{:Keyword [\: {:ValidKeywordChar \G} (({:ValidKeywordChar \r} {:ValidKeywordChar \o} {:ValidKeywordChar \u} {:ValidKeywordChar \p} {:ValidKeywordChar \i} {:ValidKeywordChar \n} {:ValidKeywordChar \g}))]} {:_ [{:Whitespace \space} (())]} {:Body {:Grouping {:Either [\( \| {:_ [{:Whitespace \space} (())]} {:Body {:Keyword [\: {:ValidKeywordChar \S} (({:ValidKeywordChar \e} {:ValidKeywordChar \q} {:ValidKeywordChar \u} {:ValidKeywordChar \e} {:ValidKeywordChar \n} {:ValidKeywordChar \c} {:ValidKeywordChar \e}))]}} (([{:_* (({:Whitespace \space}))} {:Body {:Keyword [\: {:ValidKeywordChar \E} (({:ValidKeywordChar \i} {:ValidKeywordChar \t} {:ValidKeywordChar \h} {:ValidKeywordChar \e} {:ValidKeywordChar \r}))]}}] [{:_* (({:Whitespace \space}))} {:Body {:Keyword [\: {:ValidKeywordChar \Z} (({:ValidKeywordChar \e} {:ValidKeywordChar \r} {:ValidKeywordChar \o} {:ValidKeywordChar \O} {:ValidKeywordChar \r} {:ValidKeywordChar \M} {:ValidKeywordChar \o} {:ValidKeywordChar \r} {:ValidKeywordChar \e}))]}}] [{:_* (({:Whitespace \space}))} {:Body {:Keyword [\: {:ValidKeywordChar \Z} (({:ValidKeywordChar \e} {:ValidKeywordChar \r} {:ValidKeywordChar \o} {:ValidKeywordChar \O} {:ValidKeywordChar \r} {:ValidKeywordChar \O} {:ValidKeywordChar \n} {:ValidKeywordChar \e}))]}}] [{:_* (({:Whitespace \space}))} {:Body {:Keyword [\: {:ValidKeywordChar \A} (({:ValidKeywordChar \n} {:ValidKeywordChar \y} {:ValidKeywordChar \N} {:ValidKeywordChar \o} {:ValidKeywordChar \t}))]}}])) {:_* (())} \)]}}}]}] [{:_ [{:Whitespace \,} (({:Whitespace \space}))]} {:Rule [{:Keyword [\: {:ValidKeywordChar \K} (({:ValidKeywordChar \e} {:ValidKeywordChar \y} {:ValidKeywordChar \w} {:ValidKeywordChar \o} {:ValidKeywordChar \r} {:ValidKeywordChar \d}))]} {:_ [{:Whitespace \space} (())]} {:Body {:Grouping {:Sequence [\[ {:_* (())} {:Body {:Char [\\ \:]}} (([{:_* (({:Whitespace \space}))} {:Body {:Keyword [\: {:ValidKeywordChar \V} (({:ValidKeywordChar \a} {:ValidKeywordChar \l} {:ValidKeywordChar \i} {:ValidKeywordChar \d} {:ValidKeywordChar \K} {:ValidKeywordChar \e} {:ValidKeywordChar \y} {:ValidKeywordChar \w} {:ValidKeywordChar \o} {:ValidKeywordChar \r} {:ValidKeywordChar \d} {:ValidKeywordChar \C} {:ValidKeywordChar \h} {:ValidKeywordChar \a} {:ValidKeywordChar \r}))]}}] [{:_* (({:Whitespace \space}))} {:Body {:Grouping {:ZeroOrMore [\( \* {:_ [{:Whitespace \space} (())]} {:Body {:Keyword [\: {:ValidKeywordChar \V} (({:ValidKeywordChar \a} {:ValidKeywordChar \l} {:ValidKeywordChar \i} {:ValidKeywordChar \d} {:ValidKeywordChar \K} {:ValidKeywordChar \e} {:ValidKeywordChar \y} {:ValidKeywordChar \w} {:ValidKeywordChar \o} {:ValidKeywordChar \r} {:ValidKeywordChar \d} {:ValidKeywordChar \C} {:ValidKeywordChar \h} {:ValidKeywordChar \a} {:ValidKeywordChar \r}))]}} {:_* (())} \)]}}}])) {:_* (())} \]]}}}]}] [{:_ [{:Whitespace \,} (({:Whitespace \space}))]} {:Rule [{:Keyword [\: {:ValidKeywordChar \Z} (({:ValidKeywordChar \e} {:ValidKeywordChar \r} {:ValidKeywordChar \o} {:ValidKeywordChar \O} {:ValidKeywordChar \r} {:ValidKeywordChar \O} {:ValidKeywordChar \n} {:ValidKeywordChar \e}))]} {:_ [{:Whitespace \space} (())]} {:Body {:Grouping {:Sequence [\[ {:_* (())} {:Body {:Char [\\ \(]}} (([{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \?]}}] [{:_* (({:Whitespace \space}))} {:Body {:Keyword [\: {:ValidKeywordChar \_} (())]}}] [{:_* (({:Whitespace \space}))} {:Body {:Keyword [\: {:ValidKeywordChar \B} (({:ValidKeywordChar \o} {:ValidKeywordChar \d} {:ValidKeywordChar \y}))]}}] [{:_* (({:Whitespace \space}))} {:Body {:Keyword [\: {:ValidKeywordChar \_} (({:ValidKeywordChar \*}))]}}] [{:_* (({:Whitespace \space}))} {:Body {:Char [\\ \)]}}])) {:_* (())} \]]}}}]}])) {:_* (())} \}]} ))
+(defn validate
+ ([g] (validate g false))
+ ([g d]
+ (dosync (ref-set *debug* d))
+ (if (nil? (pegasus :Grammar grammar-grammar (gen-ps (pr-str g))))
+ (println "Fail")
+ (println "Pass"))
+ (dosync (ref-set *debug* false))))
-;(defn self-check []
-; (let [result (pr-str (pegasus :Grammar grammar-grammar (gen-ps (pr-str grammar-grammar))))]
-; (if (= result grammar-ast)
-; (println "Good")
-; (println "Fail"))))
+(defn self-check [] (validate grammar-grammar))
-(defn self-check [] (println "Too large for AOT"))
+
+; TODO
+;
+; If pegasus is given a keyword, but it doesn't exist in the given grammar, a useful error should be thrown
+;

0 comments on commit 3807f4b

Please sign in to comment.