Add 2012 to FSF copyright years for Emacs files
[bpt/emacs.git] / lisp / cedet / semantic / grammar-wy.el
1 ;;; semantic/grammar-wy.el --- Generated parser support file
2
3 ;; Copyright (C) 2002-2004, 2009-2012 Free Software Foundation, Inc.
4
5 ;; Author: David Ponce <david@dponce.com>
6 ;; Keywords: syntax
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22
23 ;;; Commentary:
24 ;;
25 ;; This file was generated from admin/grammars/grammar.wy.
26
27 ;;; Code:
28
29 (require 'semantic/lex)
30 (defvar semantic-grammar-lex-c-char-re)
31
32 ;; Current parsed nonterminal name.
33 (defvar semantic-grammar-wy--nterm nil)
34 ;; Index of rule in a nonterminal clause.
35 (defvar semantic-grammar-wy--rindx nil)
36 \f
37 ;;; Declarations
38 ;;
39 (defconst semantic-grammar-wy--keyword-table
40 (semantic-lex-make-keyword-table
41 '(("%default-prec" . DEFAULT-PREC)
42 ("%no-default-prec" . NO-DEFAULT-PREC)
43 ("%keyword" . KEYWORD)
44 ("%languagemode" . LANGUAGEMODE)
45 ("%left" . LEFT)
46 ("%nonassoc" . NONASSOC)
47 ("%package" . PACKAGE)
48 ("%prec" . PREC)
49 ("%put" . PUT)
50 ("%quotemode" . QUOTEMODE)
51 ("%right" . RIGHT)
52 ("%scopestart" . SCOPESTART)
53 ("%start" . START)
54 ("%token" . TOKEN)
55 ("%type" . TYPE)
56 ("%use-macros" . USE-MACROS))
57 'nil)
58 "Table of language keywords.")
59
60 (defconst semantic-grammar-wy--token-table
61 (semantic-lex-make-type-table
62 '(("punctuation"
63 (GT . ">")
64 (LT . "<")
65 (OR . "|")
66 (SEMI . ";")
67 (COLON . ":"))
68 ("close-paren"
69 (RBRACE . "}")
70 (RPAREN . ")"))
71 ("open-paren"
72 (LBRACE . "{")
73 (LPAREN . "("))
74 ("block"
75 (BRACE_BLOCK . "(LBRACE RBRACE)")
76 (PAREN_BLOCK . "(LPAREN RPAREN)"))
77 ("code"
78 (EPILOGUE . "%%...EOF")
79 (PROLOGUE . "%{...%}"))
80 ("sexp"
81 (SEXP))
82 ("qlist"
83 (PREFIXED_LIST))
84 ("char"
85 (CHARACTER))
86 ("symbol"
87 (PERCENT_PERCENT . "\\`%%\\'")
88 (SYMBOL))
89 ("string"
90 (STRING)))
91 '(("punctuation" :declared t)
92 ("block" :declared t)
93 ("sexp" matchdatatype sexp)
94 ("sexp" syntax "\\=")
95 ("sexp" :declared t)
96 ("qlist" matchdatatype sexp)
97 ("qlist" syntax "\\s'\\s-*(")
98 ("qlist" :declared t)
99 ("char" syntax semantic-grammar-lex-c-char-re)
100 ("char" :declared t)
101 ("symbol" syntax ":?\\(\\sw\\|\\s_\\)+")
102 ("symbol" :declared t)
103 ("string" :declared t)
104 ("keyword" :declared t)))
105 "Table of lexical tokens.")
106
107 (defconst semantic-grammar-wy--parse-table
108 (progn
109 (eval-when-compile
110 (require 'semantic/wisent/comp))
111 (wisent-compile-grammar
112 '((DEFAULT-PREC NO-DEFAULT-PREC KEYWORD LANGUAGEMODE LEFT NONASSOC PACKAGE PREC PUT QUOTEMODE RIGHT SCOPESTART START TOKEN TYPE USE-MACROS STRING SYMBOL PERCENT_PERCENT CHARACTER PREFIXED_LIST SEXP PROLOGUE EPILOGUE PAREN_BLOCK BRACE_BLOCK LPAREN RPAREN LBRACE RBRACE COLON SEMI OR LT GT)
113 nil
114 (grammar
115 ((prologue))
116 ((epilogue))
117 ((declaration))
118 ((nonterminal))
119 ((PERCENT_PERCENT)))
120 (prologue
121 ((PROLOGUE)
122 (wisent-raw-tag
123 (semantic-tag-new-code "prologue" nil))))
124 (epilogue
125 ((EPILOGUE)
126 (wisent-raw-tag
127 (semantic-tag-new-code "epilogue" nil))))
128 (declaration
129 ((decl)
130 (eval $1)))
131 (decl
132 ((default_prec_decl))
133 ((no_default_prec_decl))
134 ((languagemode_decl))
135 ((package_decl))
136 ((precedence_decl))
137 ((put_decl))
138 ((quotemode_decl))
139 ((scopestart_decl))
140 ((start_decl))
141 ((keyword_decl))
142 ((token_decl))
143 ((type_decl))
144 ((use_macros_decl)))
145 (default_prec_decl
146 ((DEFAULT-PREC)
147 `(wisent-raw-tag
148 (semantic-tag "default-prec" 'assoc :value
149 '("t")))))
150 (no_default_prec_decl
151 ((NO-DEFAULT-PREC)
152 `(wisent-raw-tag
153 (semantic-tag "default-prec" 'assoc :value
154 '("nil")))))
155 (languagemode_decl
156 ((LANGUAGEMODE symbols)
157 `(wisent-raw-tag
158 (semantic-tag ',(car $2)
159 'languagemode :rest ',(cdr $2)))))
160 (package_decl
161 ((PACKAGE SYMBOL)
162 `(wisent-raw-tag
163 (semantic-tag-new-package ',$2 nil))))
164 (precedence_decl
165 ((associativity token_type_opt items)
166 `(wisent-raw-tag
167 (semantic-tag ',$1 'assoc :type ',$2 :value ',$3))))
168 (associativity
169 ((LEFT)
170 (progn "left"))
171 ((RIGHT)
172 (progn "right"))
173 ((NONASSOC)
174 (progn "nonassoc")))
175 (put_decl
176 ((PUT put_name put_value)
177 `(wisent-raw-tag
178 (semantic-tag ',$2 'put :value ',(list $3))))
179 ((PUT put_name put_value_list)
180 `(wisent-raw-tag
181 (semantic-tag ',$2 'put :value ',$3)))
182 ((PUT put_name_list put_value)
183 `(wisent-raw-tag
184 (semantic-tag ',(car $2)
185 'put :rest ',(cdr $2)
186 :value ',(list $3))))
187 ((PUT put_name_list put_value_list)
188 `(wisent-raw-tag
189 (semantic-tag ',(car $2)
190 'put :rest ',(cdr $2)
191 :value ',$3))))
192 (put_name_list
193 ((BRACE_BLOCK)
194 (mapcar 'semantic-tag-name
195 (semantic-parse-region
196 (car $region1)
197 (cdr $region1)
198 'put_names 1))))
199 (put_names
200 ((LBRACE)
201 nil)
202 ((RBRACE)
203 nil)
204 ((put_name)
205 (wisent-raw-tag
206 (semantic-tag $1 'put-name))))
207 (put_name
208 ((SYMBOL))
209 ((token_type)))
210 (put_value_list
211 ((BRACE_BLOCK)
212 (mapcar 'semantic-tag-code-detail
213 (semantic-parse-region
214 (car $region1)
215 (cdr $region1)
216 'put_values 1))))
217 (put_values
218 ((LBRACE)
219 nil)
220 ((RBRACE)
221 nil)
222 ((put_value)
223 (wisent-raw-tag
224 (semantic-tag-new-code "put-value" $1))))
225 (put_value
226 ((SYMBOL any_value)
227 (cons $1 $2)))
228 (scopestart_decl
229 ((SCOPESTART SYMBOL)
230 `(wisent-raw-tag
231 (semantic-tag ',$2 'scopestart))))
232 (quotemode_decl
233 ((QUOTEMODE SYMBOL)
234 `(wisent-raw-tag
235 (semantic-tag ',$2 'quotemode))))
236 (start_decl
237 ((START symbols)
238 `(wisent-raw-tag
239 (semantic-tag ',(car $2)
240 'start :rest ',(cdr $2)))))
241 (keyword_decl
242 ((KEYWORD SYMBOL string_value)
243 `(wisent-raw-tag
244 (semantic-tag ',$2 'keyword :value ',$3))))
245 (token_decl
246 ((TOKEN token_type_opt SYMBOL string_value)
247 `(wisent-raw-tag
248 (semantic-tag ',$3 ',(if $2 'token 'keyword)
249 :type ',$2 :value ',$4)))
250 ((TOKEN token_type_opt symbols)
251 `(wisent-raw-tag
252 (semantic-tag ',(car $3)
253 'token :type ',$2 :rest ',(cdr $3)))))
254 (token_type_opt
255 (nil)
256 ((token_type)))
257 (token_type
258 ((LT SYMBOL GT)
259 (progn $2)))
260 (type_decl
261 ((TYPE token_type plist_opt)
262 `(wisent-raw-tag
263 (semantic-tag ',$2 'type :value ',$3))))
264 (plist_opt
265 (nil)
266 ((plist)))
267 (plist
268 ((plist put_value)
269 (append
270 (list $2)
271 $1))
272 ((put_value)
273 (list $1)))
274 (use_name_list
275 ((BRACE_BLOCK)
276 (mapcar 'semantic-tag-name
277 (semantic-parse-region
278 (car $region1)
279 (cdr $region1)
280 'use_names 1))))
281 (use_names
282 ((LBRACE)
283 nil)
284 ((RBRACE)
285 nil)
286 ((SYMBOL)
287 (wisent-raw-tag
288 (semantic-tag $1 'use-name))))
289 (use_macros_decl
290 ((USE-MACROS SYMBOL use_name_list)
291 `(wisent-raw-tag
292 (semantic-tag "macro" 'macro :type ',$2 :value ',$3))))
293 (string_value
294 ((STRING)
295 (read $1)))
296 (any_value
297 ((SYMBOL))
298 ((STRING))
299 ((PAREN_BLOCK))
300 ((PREFIXED_LIST))
301 ((SEXP)))
302 (symbols
303 ((lifo_symbols)
304 (nreverse $1)))
305 (lifo_symbols
306 ((lifo_symbols SYMBOL)
307 (cons $2 $1))
308 ((SYMBOL)
309 (list $1)))
310 (nonterminal
311 ((SYMBOL
312 (setq semantic-grammar-wy--nterm $1 semantic-grammar-wy--rindx 0)
313 COLON rules SEMI)
314 (wisent-raw-tag
315 (semantic-tag $1 'nonterminal :children $4))))
316 (rules
317 ((lifo_rules)
318 (apply 'nconc
319 (nreverse $1))))
320 (lifo_rules
321 ((lifo_rules OR rule)
322 (cons $3 $1))
323 ((rule)
324 (list $1)))
325 (rule
326 ((rhs)
327 (let*
328 ((nterm semantic-grammar-wy--nterm)
329 (rindx semantic-grammar-wy--rindx)
330 (rhs $1)
331 comps prec action elt)
332 (setq semantic-grammar-wy--rindx
333 (1+ semantic-grammar-wy--rindx))
334 (while rhs
335 (setq elt
336 (car rhs)
337 rhs
338 (cdr rhs))
339 (cond
340 ((vectorp elt)
341 (if prec
342 (error "Duplicate %%prec in `%s:%d' rule" nterm rindx))
343 (setq prec
344 (aref elt 0)))
345 ((consp elt)
346 (if
347 (or action comps)
348 (setq comps
349 (cons elt comps)
350 semantic-grammar-wy--rindx
351 (1+ semantic-grammar-wy--rindx))
352 (setq action
353 (car elt))))
354 (t
355 (setq comps
356 (cons elt comps)))))
357 (wisent-cook-tag
358 (wisent-raw-tag
359 (semantic-tag
360 (format "%s:%d" nterm rindx)
361 'rule :type
362 (if comps "group" "empty")
363 :value comps :prec prec :expr action))))))
364 (rhs
365 (nil)
366 ((rhs item)
367 (cons $2 $1))
368 ((rhs action)
369 (cons
370 (list $2)
371 $1))
372 ((rhs PREC item)
373 (cons
374 (vector $3)
375 $1)))
376 (action
377 ((PAREN_BLOCK))
378 ((PREFIXED_LIST))
379 ((BRACE_BLOCK)
380 (format "(progn\n%s)"
381 (let
382 ((s $1))
383 (if
384 (string-match "^{[ \n ]*" s)
385 (setq s
386 (substring s
387 (match-end 0))))
388 (if
389 (string-match "[ \n ]*}$" s)
390 (setq s
391 (substring s 0
392 (match-beginning 0))))
393 s))))
394 (items
395 ((lifo_items)
396 (nreverse $1)))
397 (lifo_items
398 ((lifo_items item)
399 (cons $2 $1))
400 ((item)
401 (list $1)))
402 (item
403 ((SYMBOL))
404 ((CHARACTER))))
405 '(grammar prologue epilogue declaration nonterminal rule put_names put_values use_names)))
406 "Parser table.")
407
408 (defun semantic-grammar-wy--install-parser ()
409 "Setup the Semantic Parser."
410 (semantic-install-function-overrides
411 '((parse-stream . wisent-parse-stream)))
412 (setq semantic-parser-name "LALR"
413 semantic--parse-table semantic-grammar-wy--parse-table
414 semantic-debug-parser-source "semantic-grammar.wy"
415 semantic-flex-keywords-obarray semantic-grammar-wy--keyword-table
416 semantic-lex-types-obarray semantic-grammar-wy--token-table)
417 ;; Collect unmatched syntax lexical tokens
418 (semantic-make-local-hook 'wisent-discarding-token-functions)
419 (add-hook 'wisent-discarding-token-functions
420 'wisent-collect-unmatched-syntax nil t))
421
422 \f
423 ;;; Analyzers
424
425 (define-lex-sexp-type-analyzer semantic-grammar-wy--<sexp>-sexp-analyzer
426 "sexp analyzer for <sexp> tokens."
427 "\\="
428 'SEXP)
429
430 (define-lex-sexp-type-analyzer semantic-grammar-wy--<qlist>-sexp-analyzer
431 "sexp analyzer for <qlist> tokens."
432 "\\s'\\s-*("
433 'PREFIXED_LIST)
434
435 (define-lex-keyword-type-analyzer semantic-grammar-wy--<keyword>-keyword-analyzer
436 "keyword analyzer for <keyword> tokens."
437 "\\(\\sw\\|\\s_\\)+")
438
439 (define-lex-block-type-analyzer semantic-grammar-wy--<block>-block-analyzer
440 "block analyzer for <block> tokens."
441 "\\s(\\|\\s)"
442 '((("(" LPAREN PAREN_BLOCK)
443 ("{" LBRACE BRACE_BLOCK))
444 (")" RPAREN)
445 ("}" RBRACE))
446 )
447
448 (define-lex-regex-type-analyzer semantic-grammar-wy--<char>-regexp-analyzer
449 "regexp analyzer for <char> tokens."
450 semantic-grammar-lex-c-char-re
451 nil
452 'CHARACTER)
453
454 (define-lex-sexp-type-analyzer semantic-grammar-wy--<string>-sexp-analyzer
455 "sexp analyzer for <string> tokens."
456 "\\s\""
457 'STRING)
458
459 (define-lex-regex-type-analyzer semantic-grammar-wy--<symbol>-regexp-analyzer
460 "regexp analyzer for <symbol> tokens."
461 ":?\\(\\sw\\|\\s_\\)+"
462 '((PERCENT_PERCENT . "\\`%%\\'"))
463 'SYMBOL)
464
465 (define-lex-string-type-analyzer semantic-grammar-wy--<punctuation>-string-analyzer
466 "string analyzer for <punctuation> tokens."
467 "\\(\\s.\\|\\s$\\|\\s'\\)+"
468 '((GT . ">")
469 (LT . "<")
470 (OR . "|")
471 (SEMI . ";")
472 (COLON . ":"))
473 'punctuation)
474
475 (provide 'semantic/grammar-wy)
476
477 ;;; semantic/grammar-wy.el ends here