I am trying to write a grammar for parsing a simple language to describe drum loops using Clojure and amotoen . The language looks like this: -
# Test Loop
I defined the grammar as follows: -
(def g { :Whitespace '(| \space \newline \tab \, :Comment) :_* '(* :Whitespace) :_ [:Whitespace '(* :Whitespace)] :Comment [\# '(* (% \newline)) \newline] :BPM [\B \P \M \: :_* '(* :Number) \newline] :Number '(* :Digit) :Digit (a/lpegs '| "0123456789") :Samples [\S \a \m \p \l \e \s \: \newline '(* :SampleDef)] :SampleDef [:_* :Name \: :_* :File \newline] :Name '(* (% \:)) :File '(* (% \newline)) :Body [\B \o \d \y \: \newline '(* :Pattern)] :Pattern [:_* :Name \: :_* '(* (| \/ \-)) '(| \newline \$)] :Document [:_* :BPM :_* :Samples :_* :Body :_* \$] })
When I call pegasus
for each part of the sample file separately, they are processed correctly. For instance: -
(pprint (a/pegasus :Body g (a/wrap-string "Body:\n BD: /---/---/---/---\n SD: ---/--/--/-/--/-\n CHH: --/---/---/---/-\n CSH: /---------------\n")))
However, when I call (pprint (a/pegasus :Document g (a/wrap-string (slurp "sample.orc"))))
, all I get is nil
. Similarly, if I replaced (a/wrap-string (slurp "sample.orc"))
with a string containing the text contained in sample.orc
.
So my question is: can anyone determine what happened to my grammar? I have all of the ideas, and I looked at him for several days. I'm sure this is something awkwardly simple, but I just don't see it!
Thanks in advance.
source share