lbradstreet / instaparse-cljs

Port of Instaparse to Clojurescript
89 stars 4 forks source link

Misc bugs preventing Failures from pretty-printing properly #4

Closed aengelberg closed 9 years ago

aengelberg commented 9 years ago

IPrintWithWriter was not implemented yet on the Failure record, and there was also a stray java class in the instaparse.failure namespace.

After this patch, in a Figwheel REPL I get this when there is an error in the input to a parser:

cljs.user=> (def p (insta/parser "S = 'a'+"))
S = "a"+
cljs.user=> (p "aab")
Parse error at line 1 , column 3 :

aab
  ^
Expected:
"a"

But I get this when there is a parse error in a grammar:

cljs.user=> (insta/parser "S")
"Error parsing grammar specification:\nParse error at line 1 , column 2 :\n\nS\n ^\nExpected one of:
\n\"=\"\n\"::=\"\n\":=\"\n\":\"\n\"(*\"\n\n"

which isn't especially pretty. I'm not sure if this is just a limitation of the REPL specifically (what happens when it catches a string being thrown), or whether we should rethink how to report these multi-line failures on the cljs end. Any thoughts on that?

lbradstreet commented 9 years ago

Thanks! This may shed a little light on the newline issue. https://github.com/bhauman/lein-figwheel/issues/100 and https://github.com/clojure/clojurescript/commit/fe28e87a960620386494045044f6b76e0374f1bb

It may just be that we need to bump the Clojurescript dependency and things will work better (see #6 for tracking on this issue).

lbradstreet commented 9 years ago

I think this is fixed by bumping all the dependencies. In a rhino cljsbuild repl, I now get the following error:

cljs.user=> (insta/parser "S") org.mozilla.javascript.JavaScriptException: Error parsing grammar specification: Parse error at line 1 , column 2 :

S
 ^
Expected one of:
"="
"::="
":="
":"
"(*"

 (.cljs_rhino_repl/goog/../instaparse/cfg.js#335)
         instaparse$cfg$build_parser (.cljs_rhino_repl/instaparse/cfg.cljs:244:7)
         (.cljs_rhino_repl/instaparse/core.cljs:170:9)
         (.cljs_rhino_repl/instaparse/core.cljs:170:9)
         (.cljs_rhino_repl/instaparse/core.cljs:149:4)
         (NO_SOURCE_FILE <cljs repl>:1:0)
         (NO_SOURCE_FILE <cljs repl>:1:0)