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