instaparse icon indicating copy to clipboard operation
instaparse copied to clipboard

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

Open zmaril opened this issue 10 years ago • 6 comments

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 avatar Nov 18 '15 22:11 zmaril

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

zmaril avatar Nov 18 '15 22:11 zmaril

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.

zmaril avatar Nov 18 '15 22:11 zmaril

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.

Engelberg avatar Nov 19 '15 22:11 Engelberg

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"

zmaril avatar Nov 20 '15 16:11 zmaril

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.

Engelberg avatar Nov 20 '15 21:11 Engelberg

Thank you!

zmaril avatar Nov 20 '15 22:11 zmaril