1 ;;; wisent-grammar-macros.el --- Semantic macros for LALR grammars
3 ;; Copyright (C) 2003 David Ponce
5 ;; Author: David Ponce <david@dponce.com>
6 ;; Maintainer: David Ponce <david@dponce.com>
7 ;; Created: 02 Aug 2003
9 ;; X-RCS: $Id: wisent-grammar-macros.el,v 1.1 2007-11-26 15:12:31 michaels Exp $
11 ;; This file is not part of GNU Emacs.
13 ;; This program is free software; you can redistribute it and/or
14 ;; modify it under the terms of the GNU General Public License as
15 ;; published by the Free Software Foundation; either version 2, or (at
16 ;; your option) any later version.
18 ;; This software is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 ;; General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 ;; Boston, MA 02110-1301, USA.
30 ;; This library defines the default set of Semantic grammar macros
31 ;; used in wisent (.wy) grammars.
38 (defsubst wisent-grammar-region-placeholder (symb)
39 "Given a $N placeholder symbol in SYMB, return a $regionN symbol.
40 Return nil if $N is not a valid placeholder symbol."
41 (let ((n (symbol-name symb)))
42 (if (string-match "^[$]\\([1-9][0-9]*\\)$" n)
43 (intern (concat "$region" (match-string 1 n))))))
45 (defun wisent-grammar-EXPAND (symb nonterm)
46 "Expand call to EXPAND grammar macro.
47 Return the form to parse from within a nonterminal.
48 SYMB is a $I placeholder symbol that gives the bounds of the area to
50 NONTERM is the nonterminal symbol to start with."
51 (unless (member nonterm (semantic-grammar-start))
52 (error "EXPANDFULL macro called with %s, but not used with %%start"
54 (let (($ri (wisent-grammar-region-placeholder symb)))
56 `(semantic-bovinate-from-nonterminal
57 (car ,$ri) (cdr ,$ri) ',nonterm)
58 (error "Invalid form (EXPAND %s %s)" symb nonterm))))
60 (defun wisent-grammar-EXPANDFULL (symb nonterm)
61 "Expand call to EXPANDFULL grammar macro.
62 Return the form to recursively parse an area.
63 SYMB is a $I placeholder symbol that gives the bounds of the area.
64 NONTERM is the nonterminal symbol to start with."
65 (unless (member nonterm (semantic-grammar-start))
66 (error "EXPANDFULL macro called with %s, but not used with %%start"
68 (let (($ri (wisent-grammar-region-placeholder symb)))
70 `(semantic-parse-region
71 (car ,$ri) (cdr ,$ri) ',nonterm 1)
72 (error "Invalid form (EXPANDFULL %s %s)" symb nonterm))))
74 (defun wisent-grammar-TAG (name class &rest attributes)
75 "Expand call to TAG grammar macro.
76 Return the form to create a generic semantic tag.
77 See the function `semantic-tag' for the meaning of arguments NAME,
78 CLASS and ATTRIBUTES."
80 (semantic-tag ,name ,class ,@attributes)))
82 (defun wisent-grammar-VARIABLE-TAG (name type default-value &rest attributes)
83 "Expand call to VARIABLE-TAG grammar macro.
84 Return the form to create a semantic tag of class variable.
85 See the function `semantic-tag-new-variable' for the meaning of
86 arguments NAME, TYPE, DEFAULT-VALUE and ATTRIBUTES."
88 (semantic-tag-new-variable ,name ,type ,default-value ,@attributes)))
90 (defun wisent-grammar-FUNCTION-TAG (name type arg-list &rest attributes)
91 "Expand call to FUNCTION-TAG grammar macro.
92 Return the form to create a semantic tag of class function.
93 See the function `semantic-tag-new-function' for the meaning of
94 arguments NAME, TYPE, ARG-LIST and ATTRIBUTES."
96 (semantic-tag-new-function ,name ,type ,arg-list ,@attributes)))
98 (defun wisent-grammar-TYPE-TAG (name type members parents &rest attributes)
99 "Expand call to TYPE-TAG grammar macro.
100 Return the form to create a semantic tag of class type.
101 See the function `semantic-tag-new-type' for the meaning of arguments
102 NAME, TYPE, MEMBERS, PARENTS and ATTRIBUTES."
104 (semantic-tag-new-type ,name ,type ,members ,parents ,@attributes)))
106 (defun wisent-grammar-INCLUDE-TAG (name system-flag &rest attributes)
107 "Expand call to INCLUDE-TAG grammar macro.
108 Return the form to create a semantic tag of class include.
109 See the function `semantic-tag-new-include' for the meaning of
110 arguments NAME, SYSTEM-FLAG and ATTRIBUTES."
112 (semantic-tag-new-include ,name ,system-flag ,@attributes)))
114 (defun wisent-grammar-PACKAGE-TAG (name detail &rest attributes)
115 "Expand call to PACKAGE-TAG grammar macro.
116 Return the form to create a semantic tag of class package.
117 See the function `semantic-tag-new-package' for the meaning of
118 arguments NAME, DETAIL and ATTRIBUTES."
120 (semantic-tag-new-package ,name ,detail ,@attributes)))
122 (defun wisent-grammar-CODE-TAG (name detail &rest attributes)
123 "Expand call to CODE-TAG grammar macro.
124 Return the form to create a semantic tag of class code.
125 See the function `semantic-tag-new-code' for the meaning of arguments
126 NAME, DETAIL and ATTRIBUTES."
128 (semantic-tag-new-code ,name ,detail ,@attributes)))
130 (defun wisent-grammar-ALIAS-TAG (name aliasclass definition &rest attributes)
131 "Expand call to ALIAS-TAG grammar macro.
132 Return the form to create a semantic tag of class alias.
133 See the function `semantic-tag-new-alias' for the meaning of arguments
134 NAME, ALIASCLASS, DEFINITION and ATTRIBUTES."
136 (semantic-tag-new-alias ,name ,aliasclass ,definition ,@attributes)))
138 (defun wisent-grammar-EXPANDTAG (raw-tag)
139 "Expand call to EXPANDTAG grammar macro.
140 Return the form to produce a list of cooked tags from raw form of
141 Semantic tag RAW-TAG."
142 `(wisent-cook-tag ,raw-tag))
144 (defun wisent-grammar-AST-ADD (ast &rest nodes)
145 "Expand call to AST-ADD grammar macro.
146 Return the form to update the abstract syntax tree AST with NODES.
147 See also the function `semantic-ast-add'."
148 `(semantic-ast-add ,ast ,@nodes))
150 (defun wisent-grammar-AST-PUT (ast &rest nodes)
151 "Expand call to AST-PUT grammar macro.
152 Return the form to update the abstract syntax tree AST with NODES.
153 See also the function `semantic-ast-put'."
154 `(semantic-ast-put ,ast ,@nodes))
156 (defun wisent-grammar-AST-GET (ast node)
157 "Expand call to AST-GET grammar macro.
158 Return the form to get, from the abstract syntax tree AST, the value
160 See also the function `semantic-ast-get'."
161 `(semantic-ast-get ,ast ,node))
163 (defun wisent-grammar-AST-GET1 (ast node)
164 "Expand call to AST-GET1 grammar macro.
165 Return the form to get, from the abstract syntax tree AST, the first
167 See also the function `semantic-ast-get1'."
168 `(semantic-ast-get1 ,ast ,node))
170 (defun wisent-grammar-AST-GET-STRING (ast node)
171 "Expand call to AST-GET-STRING grammar macro.
172 Return the form to get, from the abstract syntax tree AST, the value
174 See also the function `semantic-ast-get-string'."
175 `(semantic-ast-get-string ,ast ,node))
177 (defun wisent-grammar-AST-MERGE (ast1 ast2)
178 "Expand call to AST-MERGE grammar macro.
179 Return the form to merge the abstract syntax trees AST1 and AST2.
180 See also the function `semantic-ast-merge'."
181 `(semantic-ast-merge ,ast1 ,ast2))
183 (defun wisent-grammar-SKIP-BLOCK (&optional symb)
184 "Expand call to SKIP-BLOCK grammar macro.
185 Return the form to skip a parenthesized block.
186 Optional argument SYMB is a $I placeholder symbol that gives the
187 bounds of the block to skip. By default, skip the block at `$1'.
188 See also the function `wisent-skip-block'."
191 (unless (setq $ri (wisent-grammar-region-placeholder symb))
192 (error "Invalid form (SKIP-BLOCK %s)" symb)))
193 `(wisent-skip-block ,$ri)))
195 (defun wisent-grammar-SKIP-TOKEN ()
196 "Expand call to SKIP-TOKEN grammar macro.
197 Return the form to skip the lookahead token.
198 See also the function `wisent-skip-token'."
199 `(wisent-skip-token))
201 (defvar-mode-local wisent-grammar-mode semantic-grammar-macros
203 (ASSOC . semantic-grammar-ASSOC)
204 (EXPAND . wisent-grammar-EXPAND)
205 (EXPANDFULL . wisent-grammar-EXPANDFULL)
206 (TAG . wisent-grammar-TAG)
207 (VARIABLE-TAG . wisent-grammar-VARIABLE-TAG)
208 (FUNCTION-TAG . wisent-grammar-FUNCTION-TAG)
209 (TYPE-TAG . wisent-grammar-TYPE-TAG)
210 (INCLUDE-TAG . wisent-grammar-INCLUDE-TAG)
211 (PACKAGE-TAG . wisent-grammar-PACKAGE-TAG)
212 (EXPANDTAG . wisent-grammar-EXPANDTAG)
213 (CODE-TAG . wisent-grammar-CODE-TAG)
214 (ALIAS-TAG . wisent-grammar-ALIAS-TAG)
215 (AST-ADD . wisent-grammar-AST-ADD)
216 (AST-PUT . wisent-grammar-AST-PUT)
217 (AST-GET . wisent-grammar-AST-GET)
218 (AST-GET1 . wisent-grammar-AST-GET1)
219 (AST-GET-STRING . wisent-grammar-AST-GET-STRING)
220 (AST-MERGE . wisent-grammar-AST-MERGE)
221 (SKIP-BLOCK . wisent-grammar-SKIP-BLOCK)
222 (SKIP-TOKEN . wisent-grammar-SKIP-TOKEN)
224 "Semantic grammar macros used in wisent grammars.")
226 (provide 'wisent-grammar-macros)
228 ;;; wisent-grammar-macros.el ends here