diff --git a/src/instaparse/gll.clj b/src/instaparse/gll.clj index a95bea8..360bb22 100644 --- a/src/instaparse/gll.clj +++ b/src/instaparse/gll.clj @@ -872,6 +872,11 @@ ;; Parsing functions (defn start-parser [tramp parser partial?] + (let [starting-prod (:keyword parser) + known-productions (into #{} (map first (:grammar tramp)))] + (when (not (known-productions starting-prod)) + (throw (IllegalArgumentException. + (str "Nonexistent starting production: " starting-prod))))) (if partial? (push-listener tramp [0 parser] (TopListener tramp)) (push-full-listener tramp [0 parser] (TopListener tramp)))) diff --git a/test/instaparse/core_test.clj b/test/instaparse/core_test.clj index bf6cafd..8775591 100644 --- a/test/instaparse/core_test.clj +++ b/test/instaparse/core_test.clj @@ -684,6 +684,15 @@ 15 )) +(deftest error-nonexistent-starting-production + (let [parser (insta/parser "cat = 'mjau'")] + (is (thrown-with-msg? + IllegalArgumentException + #"Nonexistent starting production: :dog" + (insta/parse parser "mjau" :start :dog))) + (is (= [:cat "mjau"] + (insta/parse parser "mjau" :start :cat))))) + (defn round-trip [parser] (insta/parser (prn-str parser)))