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