Commit | Line | Data |
---|---|---|
a2095e2e CY |
1 | ;;; semantic/grammar-wy.el --- Generated parser support file |
2 | ||
73b0cd50 | 3 | ;; Copyright (C) 2002-2004, 2009-2011 Free Software Foundation, Inc. |
a2095e2e CY |
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 is generated from the grammar file semantic-grammar.wy in | |
26 | ;; the upstream CEDET repository. | |
27 | ||
28 | ;;; Code: | |
29 | ||
30 | (require 'semantic/lex) | |
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 | ("%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.") | |
60 | ||
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.") | |
107 | ||
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 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) | |
114 | nil | |
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 | ((precedence_decl)) | |
138 | ((put_decl)) | |
139 | ((quotemode_decl)) | |
140 | ((scopestart_decl)) | |
141 | ((start_decl)) | |
142 | ((keyword_decl)) | |
143 | ((token_decl)) | |
144 | ((type_decl)) | |
145 | ((use_macros_decl))) | |
146 | (default_prec_decl | |
147 | ((DEFAULT-PREC) | |
148 | `(wisent-raw-tag | |
149 | (semantic-tag "default-prec" 'assoc :value | |
150 | '("t"))))) | |
151 | (no_default_prec_decl | |
152 | ((NO-DEFAULT-PREC) | |
153 | `(wisent-raw-tag | |
154 | (semantic-tag "default-prec" 'assoc :value | |
155 | '("nil"))))) | |
156 | (languagemode_decl | |
157 | ((LANGUAGEMODE symbols) | |
158 | `(wisent-raw-tag | |
159 | (semantic-tag ',(car $2) | |
160 | 'languagemode :rest ',(cdr $2))))) | |
161 | (package_decl | |
162 | ((PACKAGE SYMBOL) | |
163 | `(wisent-raw-tag | |
164 | (semantic-tag-new-package ',$2 nil)))) | |
165 | (precedence_decl | |
166 | ((associativity token_type_opt items) | |
167 | `(wisent-raw-tag | |
168 | (semantic-tag ',$1 'assoc :type ',$2 :value ',$3)))) | |
169 | (associativity | |
170 | ((LEFT) | |
171 | (progn "left")) | |
172 | ((RIGHT) | |
173 | (progn "right")) | |
174 | ((NONASSOC) | |
175 | (progn "nonassoc"))) | |
176 | (put_decl | |
177 | ((PUT put_name put_value) | |
178 | `(wisent-raw-tag | |
179 | (semantic-tag ',$2 'put :value ',(list $3)))) | |
180 | ((PUT put_name put_value_list) | |
181 | `(wisent-raw-tag | |
182 | (semantic-tag ',$2 'put :value ',$3))) | |
183 | ((PUT put_name_list put_value) | |
184 | `(wisent-raw-tag | |
185 | (semantic-tag ',(car $2) | |
186 | 'put :rest ',(cdr $2) | |
187 | :value ',(list $3)))) | |
188 | ((PUT put_name_list put_value_list) | |
189 | `(wisent-raw-tag | |
190 | (semantic-tag ',(car $2) | |
191 | 'put :rest ',(cdr $2) | |
192 | :value ',$3)))) | |
193 | (put_name_list | |
194 | ((BRACE_BLOCK) | |
195 | (mapcar 'semantic-tag-name | |
196 | (semantic-parse-region | |
197 | (car $region1) | |
198 | (cdr $region1) | |
199 | 'put_names 1)))) | |
200 | (put_names | |
201 | ((LBRACE) | |
202 | nil) | |
203 | ((RBRACE) | |
204 | nil) | |
205 | ((put_name) | |
206 | (wisent-raw-tag | |
207 | (semantic-tag $1 'put-name)))) | |
208 | (put_name | |
209 | ((SYMBOL)) | |
210 | ((token_type))) | |
211 | (put_value_list | |
212 | ((BRACE_BLOCK) | |
213 | (mapcar 'semantic-tag-code-detail | |
214 | (semantic-parse-region | |
215 | (car $region1) | |
216 | (cdr $region1) | |
217 | 'put_values 1)))) | |
218 | (put_values | |
219 | ((LBRACE) | |
220 | nil) | |
221 | ((RBRACE) | |
222 | nil) | |
223 | ((put_value) | |
224 | (wisent-raw-tag | |
225 | (semantic-tag-new-code "put-value" $1)))) | |
226 | (put_value | |
227 | ((SYMBOL any_value) | |
228 | (cons $1 $2))) | |
229 | (scopestart_decl | |
230 | ((SCOPESTART SYMBOL) | |
231 | `(wisent-raw-tag | |
232 | (semantic-tag ',$2 'scopestart)))) | |
233 | (quotemode_decl | |
234 | ((QUOTEMODE SYMBOL) | |
235 | `(wisent-raw-tag | |
236 | (semantic-tag ',$2 'quotemode)))) | |
237 | (start_decl | |
238 | ((START symbols) | |
239 | `(wisent-raw-tag | |
240 | (semantic-tag ',(car $2) | |
241 | 'start :rest ',(cdr $2))))) | |
242 | (keyword_decl | |
243 | ((KEYWORD SYMBOL string_value) | |
244 | `(wisent-raw-tag | |
245 | (semantic-tag ',$2 'keyword :value ',$3)))) | |
246 | (token_decl | |
247 | ((TOKEN token_type_opt SYMBOL string_value) | |
248 | `(wisent-raw-tag | |
249 | (semantic-tag ',$3 ',(if $2 'token 'keyword) | |
250 | :type ',$2 :value ',$4))) | |
251 | ((TOKEN token_type_opt symbols) | |
252 | `(wisent-raw-tag | |
253 | (semantic-tag ',(car $3) | |
254 | 'token :type ',$2 :rest ',(cdr $3))))) | |
255 | (token_type_opt | |
256 | (nil) | |
257 | ((token_type))) | |
258 | (token_type | |
259 | ((LT SYMBOL GT) | |
260 | (progn $2))) | |
261 | (type_decl | |
262 | ((TYPE token_type plist_opt) | |
263 | `(wisent-raw-tag | |
264 | (semantic-tag ',$2 'type :value ',$3)))) | |
265 | (plist_opt | |
266 | (nil) | |
267 | ((plist))) | |
268 | (plist | |
269 | ((plist put_value) | |
270 | (append | |
271 | (list $2) | |
272 | $1)) | |
273 | ((put_value) | |
274 | (list $1))) | |
275 | (use_name_list | |
276 | ((BRACE_BLOCK) | |
277 | (mapcar 'semantic-tag-name | |
278 | (semantic-parse-region | |
279 | (car $region1) | |
280 | (cdr $region1) | |
281 | 'use_names 1)))) | |
282 | (use_names | |
283 | ((LBRACE) | |
284 | nil) | |
285 | ((RBRACE) | |
286 | nil) | |
287 | ((SYMBOL) | |
288 | (wisent-raw-tag | |
289 | (semantic-tag $1 'use-name)))) | |
290 | (use_macros_decl | |
291 | ((USE-MACROS SYMBOL use_name_list) | |
292 | `(wisent-raw-tag | |
293 | (semantic-tag "macro" 'macro :type ',$2 :value ',$3)))) | |
294 | (string_value | |
295 | ((STRING) | |
296 | (read $1))) | |
297 | (any_value | |
298 | ((SYMBOL)) | |
299 | ((STRING)) | |
300 | ((PAREN_BLOCK)) | |
301 | ((PREFIXED_LIST)) | |
302 | ((SEXP))) | |
303 | (symbols | |
304 | ((lifo_symbols) | |
305 | (nreverse $1))) | |
306 | (lifo_symbols | |
307 | ((lifo_symbols SYMBOL) | |
308 | (cons $2 $1)) | |
309 | ((SYMBOL) | |
310 | (list $1))) | |
311 | (nonterminal | |
312 | ((SYMBOL | |
313 | (setq semantic-grammar-wy--nterm $1 semantic-grammar-wy--rindx 0) | |
314 | COLON rules SEMI) | |
315 | (wisent-raw-tag | |
316 | (semantic-tag $1 'nonterminal :children $4)))) | |
317 | (rules | |
318 | ((lifo_rules) | |
319 | (apply 'nconc | |
320 | (nreverse $1)))) | |
321 | (lifo_rules | |
322 | ((lifo_rules OR rule) | |
323 | (cons $3 $1)) | |
324 | ((rule) | |
325 | (list $1))) | |
326 | (rule | |
327 | ((rhs) | |
328 | (let* | |
329 | ((nterm semantic-grammar-wy--nterm) | |
330 | (rindx semantic-grammar-wy--rindx) | |
331 | (rhs $1) | |
332 | comps prec action elt) | |
333 | (setq semantic-grammar-wy--rindx | |
334 | (1+ semantic-grammar-wy--rindx)) | |
335 | (while rhs | |
336 | (setq elt | |
337 | (car rhs) | |
338 | rhs | |
339 | (cdr rhs)) | |
340 | (cond | |
341 | ((vectorp elt) | |
342 | (if prec | |
9bf6c65c | 343 | (error "Duplicate %%prec in `%s:%d' rule" nterm rindx)) |
a2095e2e CY |
344 | (setq prec |
345 | (aref elt 0))) | |
346 | ((consp elt) | |
347 | (if | |
348 | (or action comps) | |
349 | (setq comps | |
350 | (cons elt comps) | |
351 | semantic-grammar-wy--rindx | |
352 | (1+ semantic-grammar-wy--rindx)) | |
353 | (setq action | |
354 | (car elt)))) | |
355 | (t | |
356 | (setq comps | |
357 | (cons elt comps))))) | |
358 | (wisent-cook-tag | |
359 | (wisent-raw-tag | |
360 | (semantic-tag | |
361 | (format "%s:%d" nterm rindx) | |
362 | 'rule :type | |
363 | (if comps "group" "empty") | |
364 | :value comps :prec prec :expr action)))))) | |
365 | (rhs | |
366 | (nil) | |
367 | ((rhs item) | |
368 | (cons $2 $1)) | |
369 | ((rhs action) | |
370 | (cons | |
371 | (list $2) | |
372 | $1)) | |
373 | ((rhs PREC item) | |
374 | (cons | |
375 | (vector $3) | |
376 | $1))) | |
377 | (action | |
378 | ((PAREN_BLOCK)) | |
379 | ((PREFIXED_LIST)) | |
380 | ((BRACE_BLOCK) | |
381 | (format "(progn\n%s)" | |
382 | (let | |
383 | ((s $1)) | |
384 | (if | |
385 | (string-match "^{[\r\n ]*" s) | |
386 | (setq s | |
387 | (substring s | |
388 | (match-end 0)))) | |
389 | (if | |
390 | (string-match "[\r\n ]*}$" s) | |
391 | (setq s | |
392 | (substring s 0 | |
393 | (match-beginning 0)))) | |
394 | s)))) | |
395 | (items | |
396 | ((lifo_items) | |
397 | (nreverse $1))) | |
398 | (lifo_items | |
399 | ((lifo_items item) | |
400 | (cons $2 $1)) | |
401 | ((item) | |
402 | (list $1))) | |
403 | (item | |
404 | ((SYMBOL)) | |
405 | ((CHARACTER)))) | |
406 | '(grammar prologue epilogue declaration nonterminal rule put_names put_values use_names))) | |
407 | "Parser table.") | |
408 | ||
409 | (defun semantic-grammar-wy--install-parser () | |
410 | "Setup the Semantic Parser." | |
411 | (semantic-install-function-overrides | |
412 | '((parse-stream . wisent-parse-stream))) | |
413 | (setq semantic-parser-name "LALR" | |
414 | semantic--parse-table semantic-grammar-wy--parse-table | |
415 | semantic-debug-parser-source "semantic-grammar.wy" | |
416 | semantic-flex-keywords-obarray semantic-grammar-wy--keyword-table | |
417 | semantic-lex-types-obarray semantic-grammar-wy--token-table) | |
418 | ;; Collect unmatched syntax lexical tokens | |
419 | (semantic-make-local-hook 'wisent-discarding-token-functions) | |
420 | (add-hook 'wisent-discarding-token-functions | |
421 | 'wisent-collect-unmatched-syntax nil t)) | |
422 | ||
423 | \f | |
424 | ;;; Analyzers | |
425 | ||
426 | (define-lex-sexp-type-analyzer semantic-grammar-wy--<sexp>-sexp-analyzer | |
427 | "sexp analyzer for <sexp> tokens." | |
428 | "\\=" | |
429 | 'SEXP) | |
430 | ||
431 | (define-lex-sexp-type-analyzer semantic-grammar-wy--<qlist>-sexp-analyzer | |
432 | "sexp analyzer for <qlist> tokens." | |
433 | "\\s'\\s-*(" | |
434 | 'PREFIXED_LIST) | |
435 | ||
436 | (define-lex-keyword-type-analyzer semantic-grammar-wy--<keyword>-keyword-analyzer | |
437 | "keyword analyzer for <keyword> tokens." | |
438 | "\\(\\sw\\|\\s_\\)+") | |
439 | ||
440 | (define-lex-block-type-analyzer semantic-grammar-wy--<block>-block-analyzer | |
441 | "block analyzer for <block> tokens." | |
442 | "\\s(\\|\\s)" | |
443 | '((("(" LPAREN PAREN_BLOCK) | |
444 | ("{" LBRACE BRACE_BLOCK)) | |
445 | (")" RPAREN) | |
446 | ("}" RBRACE)) | |
447 | ) | |
448 | ||
449 | (define-lex-regex-type-analyzer semantic-grammar-wy--<char>-regexp-analyzer | |
450 | "regexp analyzer for <char> tokens." | |
451 | semantic-grammar-lex-c-char-re | |
452 | nil | |
453 | 'CHARACTER) | |
454 | ||
455 | (define-lex-sexp-type-analyzer semantic-grammar-wy--<string>-sexp-analyzer | |
456 | "sexp analyzer for <string> tokens." | |
457 | "\\s\"" | |
458 | 'STRING) | |
459 | ||
460 | (define-lex-regex-type-analyzer semantic-grammar-wy--<symbol>-regexp-analyzer | |
461 | "regexp analyzer for <symbol> tokens." | |
462 | ":?\\(\\sw\\|\\s_\\)+" | |
463 | '((PERCENT_PERCENT . "\\`%%\\'")) | |
464 | 'SYMBOL) | |
465 | ||
466 | (define-lex-string-type-analyzer semantic-grammar-wy--<punctuation>-string-analyzer | |
467 | "string analyzer for <punctuation> tokens." | |
468 | "\\(\\s.\\|\\s$\\|\\s'\\)+" | |
469 | '((GT . ">") | |
470 | (LT . "<") | |
471 | (OR . "|") | |
472 | (SEMI . ";") | |
473 | (COLON . ":")) | |
474 | 'punctuation) | |
475 | ||
476 | (provide 'semantic/grammar-wy) | |
477 | ||
478 | ;;; semantic/grammar-wy.el ends here |