Closed scymtym closed 7 years ago
very nice work! Much kudos.
This is based on a very quick look, so a grain of salt may be needed:
Easy answers first.
Less easy:
Overall I value backwards compatibility highly. If keeping it doesn't make things clearly worse or implementation much harder, I would keep it. Therefore I would prefer ADD-RULE and &co to default to grammar at runtime, and have that as either a keyword or an optional argument. Analogously to how INTERN &co work.
DEFRULE on the other hand should IMO choose the grammar (if not explicitly given) at compile-time if at all possible. Earlier is better there, I suspect.
Not at all sure:
Naming things with string designators instead of symbols. I see the attraction, but this means that all rules in a grammar are public and prone to conflict, no?
If I have a grammar G1 in package BAR that specifies a rule called BAR:WHITESPACE and a G2 in FOO that specified FOO:WHITESPACE, then G3 in QUUX can use both without problems. If both rules are really called "WHITESPACE", things can get confusing pretty quickly...
Thanks for the feedback. I will rebase onto new master and try to address the remaining problems.
I updated the branch according to your suggestions. A detailed description can be found in the updated commit message.
In case you accept the pull request, please squash the two commits into one. If you have further feedback, just let me know.
In case #18 looks acceptable, please merge that one first and let me rebase this branch.
Many thanks in advance.
I am not sure about we really have an issue here. See multiple grammars with vanilla esrap: https://gist.github.com/4655164
But if using native Common Lisp packages system is a prohibited way, and we must reimplement it, we can use something like local nicknames - local prefixes for grammars, that will allow us to use grammars with the same names for different rules.
(defgrammar #:sexp
(:local-prefixes (#:xml "xml-")))
(in-grammar #:sexp)
(defrule :xml (and "(xml \"" :xml-xml "\")"))
(defgrammar #:xml
(:local-prefixes (#:sexp "sexp-")))
(in-grammar #:xml)
(defrule :sexp (and "<sexp>" :sexp-sexp "</sexp>"))
P.S. IMHO error on circular dependencies IS NOT good.
In the long run, I would also like to allow circular dependencies between grammars in order to support mutually recursive rules across grammars.
I omitted this ability from the proposal to reduce complexity while the proposal is in an early discussion stage. Should the proposal be accepted, I would like to add support for circular dependencies later.
Further development in scymtym/esrap.
This is a prototype implementation of package-like grammars. It is prototypical in the sense that much cleanup and some refactoring is necessary. However, I wanted to try and get some feedback before polishing this any further. Thanks for taking the time to consider this.
Commit message:
There are design decision, for which I could use some advice:
interface required?
STRING
. This allows clients to write. It also frees grammar writers from exporting rule names as symbols. However, it could lead to clashes between rule names in the
USE
-closure of some grammar. It also prevents "private" rules.?
or should these operations accept rule objects as in
or even
?
*non-existent*
tests use some compilation/signal-related trickery which can probably be improved.(setf (find-grammar ...) nil)
and then(defgrammar ...)
) after(parse ...)
calls have been compile-time optimized can lead to an old definition of a rule being used.