Obscure error when making a small mistake.
(defvar *dash/slash*
" DASH-OR-SLASH = DASH SLASH
DASH = \"-\" 4DIGITS
SLASH = \"/\" 2DIGITS "
"A grammar with a subtle error: DIGITS instead of DIGIT.")
(parse-abnf-grammar *dash/slash* :dash-or-slash :registering-rules '(:dash :slash))
You end up getting an error about a failing DESTRUCTURING-BIND. WTF?
After extensive debugging, I found my way to abnf.lisp:522 (line number after adding
several (declare (optimize (debug 3))) lines to different functions), which reads:
(destructuring-bind (rule-name rule-definition)
(or (assoc definition rule-set)
(assoc definition *abnf-default-rules*))
(let* ((already-expanded-rules
(cons definition already-expanded-rules))
Adding an error to the end of the or expression results in much easier debugging:
(destructuring-bind (rule-name rule-definition)
(or (assoc definition rule-set)
(assoc definition *abnf-default-rules*)
(error "Unknown rule: ~a" definition))
(let* ((already-expanded-rules
(cons definition already-expanded-rules))
Then, when you give it the grammar at the top, you get the error "Unknown rule: ABNF-DIGITS." It would be better if someone would bother to remove the ABNF- prefix, but even with the prefix it's a marked improvement.
The cl-abnf code hasn't seen many usage yet, so please consider improving it by sending pull requests if you're an interested user. Welcome to the project!