> All these funny exceptions exist because the bovinator has explicit
> return values which automatically compound tokens together if no
> actions are provided.
> In addition, the semantic-lambda expression is set up so you can
> write your grammar directly in Emacs Lisp notation. (Before there
> was a grammar file.) I do not think the bovinator will work at all
> if these exceptions are not handled.
> How to know if they are the first symbol or not is a tricky problem.
> I'd suggest having those exceptions just always exist, and not be
> available as configurable options. That way you can leave that code
> alone. EVAL and EXPAND are core to how the bovinator operates and
> can continue to be so.
I finally completed a first step in improving grammar macros design,
and replaced hard coded macro expanders with a more flexible
Now macros definitions are provided in the new variable
`semantic-grammar-macros', as a list of associations:
(MACRO-NAME . EXPANDER)
- MACRO-NAME is a symbol that identifies the macro (for example TAG,
- EXPANDER is the name of the function called to expand this macro.
This function is passed the macro arguments. It can be defined
using a generic form like this:
(defun my-expander-for-MACRO-NAME (&rest args)
Definitions of common macros used in BY and WY grammars are
respectively provided in the new libraries: bovine-grammar-macros.el
and wisent-grammar-macros.el. They are installed as a mode local
value of `semantic-grammar-macros' like this:
(defvar-mode-local bovine-grammar-mode semantic-grammar-macros
(defvar-mode-local wisent-grammar-mode semantic-grammar-macros
As you suggested EXPAND and EVAL macro calls are handled in a
particular way in bovine grammars (I am not sure that the EVAL macro
actually ever did something).
There are TODO placeholders in semantic-grammar.el, in functions
`semantic-grammar-macros' and `semantic--grammar-macros-regexp-2' for
a future extension to handle macros defined locally in the grammar.
As soon as we'll have decided of what %macro syntax to use ;)
Generation of lisp code is improved. Now generation-evaluation occurs
after each insertion of a coherent unit of code:
- Definition of keywords.
- Definition of tokens.
- Definition of parse table.
This way, each unit of code can refer to latest values in preceding
In grammars, font-locking of macro calls is dynamic, and automatically
takes into account the local value of `semantic-grammar-macros'.
Finally, I also simplified the implementation of the grammar indenter
in semantic-grammar.el. The new code should be easier to understand
(and maintain) and works as previously :-)
Attached you will find a tarball of the following files:
A big patch for semantic-grammar-wy.el, semantic-grammar.el,
semantic-grammar.wy, bovine-grammar.el, and wisent-grammar.el!
New file. Define macros used in WY grammars.
New file. Define macros used in BY grammars.
I did some tests with BY and WY grammars in the distribution, and all
seems to work nicely :-)
I would appreciate if you could try the new code. And, if you don't
have objection, I will check these changes in.
I am looking forward for your feedback.
P.S.: The change log!
2003-08-09 David Ponce <david@...>
(semantic-grammar-macros): New variable and function.
(semantic-grammar-header-template): Use %C and %V for respectively
the copyright line and the version keyword.
(semantic-grammar-copyright-line): New function.
(semantic-grammar-header): Use it. Setup %C and %V. No more
(semantic-grammar-footer): Doc fix. No more inlined.
(semantic-grammar-setup-data): No more inlined.
(semantic-grammar-create-package): Improve generation-evaluation
of lisp code.
(semantic--grammar-macros-regexp-1): New variable and function.
(semantic--grammar-macros-regexp-2): New variable.
(semantic--grammar-macros-matcher): New function.
(semantic-grammar-map): Add ':' to electric punctuations.
(semantic-grammar-anchored-indentation): New function.
(semantic-grammar-do-grammar-indent): Simplify. Use above new
(decl): Remove extra empty rule.
(bovine-grammar-macros): Require it.
(bovine--grammar-macros): New variable.
(bovine-grammar-expand-CODE-TAG): Remove. New definition in
(bovine-grammar-expand-form): Don't use hard-coded expanders.
(bovine-grammar-parsetable-builder): Initialize macro definitions.
(wisent-grammar-macros): Require it.
(wisent-grammar-builtin-names): Remove. New definition in
(wisent-grammar-expand-builtins): Move and rename...
(wisent-grammar-expand-macros): New function.
(wisent-grammar--macros): New variable.
(wisent-grammar-nonterminals): Use `wisent-grammar-expand-macros'.
Initialize macro definitions.
(wisent-grammar-mode): Don't setup