Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to turn off "NOT" statements generated during negative lookahead #116

Open
zmaril opened this issue Nov 18, 2015 · 6 comments
Open

Comments

@zmaril
Copy link

zmaril commented Nov 18, 2015

I have a grammar with about 50 reserved keywords. Sometimes when I get a parse error now, I get an error message that I have to scroll up 50 lines of reserved keywords to understand. Is there a way of turning off the NOT part of the parse error message?

@zmaril
Copy link
Author

zmaril commented Nov 18, 2015

Figured this out! I had forgotten to include whitespace inside the negative lookahead along with the reserved keywords.

@zmaril zmaril closed this as completed Nov 18, 2015
@zmaril zmaril reopened this Nov 18, 2015
@zmaril
Copy link
Author

zmaril commented Nov 18, 2015

Sorry for the churn, but this option would still be nice. It is coming up in other situations and being able to turn off all the reserved keyword spam would be really nice.

@Engelberg
Copy link
Owner

Can you show me an example of the verbose error messages you're seeing, just so I can get a better sense for what you're dealing with? Thanks.

@zmaril
Copy link
Author

zmaril commented Nov 20, 2015

A contrived example:

(ns example
  (:refer-clojure :exclude [cat])
  (:require [instaparse.core :as insta]
            [instaparse.combinators :refer :all]))

(def s "abcdef")

(def grammar
  {:word (cat (neg (nt :forbidden)) (regexp "[a-z]+"))
   :forbidden (->> (for [i s j s] (str i j))
                   (map string)
                   (apply alt))})
(def parse
  (insta/parser grammar :start :word))

And the weird error message. It's pretty long and the ordering of the lines don't quite make sense to me either.

=>(parser "ab")
Parse error at line 1, column 1:
ab
^
Expected one of:
"ff"
"fe"
"fd"
"fc"
"fb"
"fa"
"ef"
"ee"
"ed"
"ec"
"eb"
"ea"
"df"
"de"
"dd"
"dc"
"db"
"da"
"cf"
"ce"
"cd"
"cc"
"cb"
"ca"
"bf"
"be"
"bd"
"bc"
"bb"
"ba"
"af"
"ae"
"ad"
"ac"
NOT forbidden
"aa"

@Engelberg
Copy link
Owner

OK, thanks for the explanation. The reason why it prints this way is fairly subtle, but I understand what is going on. It's not a trivial fix, but next time I have an opportunity to work on instaparse, my plan is to overhaul the way that negative lookahead is processed, and when I do, this problem will go away.

@zmaril
Copy link
Author

zmaril commented Nov 20, 2015

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants