Skip to content
This repository has been archived by the owner on Mar 5, 2024. It is now read-only.

Commit

Permalink
Double checking the longer expression with two different parsers, def…
Browse files Browse the repository at this point in the history
…. something broken inside.
  • Loading branch information
Håkan Råberg committed Apr 11, 2013
1 parent 9faf78a commit ae3917f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/mimir/parse.clj
Expand Up @@ -215,7 +215,7 @@
`#(eval `(let [~'~locals ~~locals]
~(read-string %)))))

(def ^:dynamic *dynamic-reader*)
(def ^:dynamic *dynamic-reader* read-string)

(defn action? [x]
((some-fn fn? var?) x))
Expand Down
9 changes: 9 additions & 0 deletions test/mimir/test/parse.clj
Expand Up @@ -48,6 +48,7 @@
:decimal #"[0-9]+" read-string))

;; This gets wrong precedence, regardless of using choice / OrderedSet or not. So something else.
;; Should return 33.
(peg-expression "1-2/(3-4)+5*6")

(peg-expression "2+5*2")
Expand Down Expand Up @@ -97,12 +98,20 @@
:expr #{[:term #"[+-]" :expr]
:term} op
:term #{[:factor #"[*/]" :term]
["(" :expr ")"]
:factor} op
:factor #{#"[0-9]+" #"\w+"} #'*dynamic-reader*))

(let [x 1 y 3]
(right-recursive "x - 2 * y" :dynamic-reader (dynamic-reader)))

;; Extended the grammar to support parenthesis, now this fails the same way as peg-expression:
(right-recursive "1-2/(3-4)+5*6")
;; Gives -27, should be 33.

;; But the tree is much nicer, and could hint to the answer:
(right-recursive "1-2/(3-4)+5*6" :grammar-actions false :suppress-tags false)

;; Check that memoization actually works.
(comment
(let [x 1 y 3]
Expand Down

0 comments on commit ae3917f

Please sign in to comment.