Commit | Line | Data |
---|---|---|
a2095e2e CY |
1 | ;;; semantic/grammar-wy.el --- Generated parser support file |
2 | ||
ab422c4d | 3 | ;; Copyright (C) 2002-2004, 2009-2013 Free Software Foundation, Inc. |
a2095e2e | 4 | |
a2095e2e CY |
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 | ;; | |
78adbf9c | 22 | ;; This file was generated from admin/grammars/grammar.wy. |
a2095e2e CY |
23 | |
24 | ;;; Code: | |
25 | ||
3f2a848d DE |
26 | (require 'semantic) |
27 | ||
62a81506 CY |
28 | ;;; Prologue |
29 | ;; | |
a2095e2e CY |
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) | |
62a81506 | 48 | ("%provide" . PROVIDE) |
a2095e2e CY |
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 | |
62a81506 | 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) |
a2095e2e CY |
114 | nil |
115 | (grammar | |
78adbf9c CY |
116 | ((prologue)) |
117 | ((epilogue)) | |
118 | ((declaration)) | |
119 | ((nonterminal)) | |
120 | ((PERCENT_PERCENT))) | |
a2095e2e | 121 | (prologue |
78adbf9c CY |
122 | ((PROLOGUE) |
123 | (wisent-raw-tag | |
124 | (semantic-tag-new-code "prologue" nil)))) | |
a2095e2e | 125 | (epilogue |
78adbf9c CY |
126 | ((EPILOGUE) |
127 | (wisent-raw-tag | |
128 | (semantic-tag-new-code "epilogue" nil)))) | |
a2095e2e | 129 | (declaration |
78adbf9c CY |
130 | ((decl) |
131 | (eval $1))) | |
a2095e2e | 132 | (decl |
78adbf9c CY |
133 | ((default_prec_decl)) |
134 | ((no_default_prec_decl)) | |
135 | ((languagemode_decl)) | |
136 | ((package_decl)) | |
62a81506 | 137 | ((provide_decl)) |
78adbf9c CY |
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))) | |
a2095e2e | 147 | (default_prec_decl |
78adbf9c CY |
148 | ((DEFAULT-PREC) |
149 | `(wisent-raw-tag | |
150 | (semantic-tag "default-prec" 'assoc :value | |
151 | '("t"))))) | |
a2095e2e | 152 | (no_default_prec_decl |
78adbf9c CY |
153 | ((NO-DEFAULT-PREC) |
154 | `(wisent-raw-tag | |
155 | (semantic-tag "default-prec" 'assoc :value | |
156 | '("nil"))))) | |
a2095e2e | 157 | (languagemode_decl |
78adbf9c CY |
158 | ((LANGUAGEMODE symbols) |
159 | `(wisent-raw-tag | |
160 | (semantic-tag ',(car $2) | |
161 | 'languagemode :rest ',(cdr $2))))) | |
a2095e2e | 162 | (package_decl |
78adbf9c CY |
163 | ((PACKAGE SYMBOL) |
164 | `(wisent-raw-tag | |
165 | (semantic-tag-new-package ',$2 nil)))) | |
62a81506 CY |
166 | (provide_decl |
167 | ((PROVIDE SYMBOL) | |
168 | `(wisent-raw-tag | |
169 | (semantic-tag ',$2 'provide)))) | |
a2095e2e | 170 | (precedence_decl |
78adbf9c CY |
171 | ((associativity token_type_opt items) |
172 | `(wisent-raw-tag | |
173 | (semantic-tag ',$1 'assoc :type ',$2 :value ',$3)))) | |
a2095e2e | 174 | (associativity |
78adbf9c CY |
175 | ((LEFT) |
176 | (progn "left")) | |
177 | ((RIGHT) | |
178 | (progn "right")) | |
179 | ((NONASSOC) | |
180 | (progn "nonassoc"))) | |
a2095e2e | 181 | (put_decl |
78adbf9c CY |
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)))) | |
a2095e2e | 198 | (put_name_list |
78adbf9c CY |
199 | ((BRACE_BLOCK) |
200 | (mapcar 'semantic-tag-name | |
201 | (semantic-parse-region | |
202 | (car $region1) | |
203 | (cdr $region1) | |
204 | 'put_names 1)))) | |
a2095e2e | 205 | (put_names |
78adbf9c CY |
206 | ((LBRACE) |
207 | nil) | |
208 | ((RBRACE) | |
209 | nil) | |
210 | ((put_name) | |
211 | (wisent-raw-tag | |
212 | (semantic-tag $1 'put-name)))) | |
a2095e2e | 213 | (put_name |
78adbf9c CY |
214 | ((SYMBOL)) |
215 | ((token_type))) | |
a2095e2e | 216 | (put_value_list |
78adbf9c CY |
217 | ((BRACE_BLOCK) |
218 | (mapcar 'semantic-tag-code-detail | |
219 | (semantic-parse-region | |
220 | (car $region1) | |
221 | (cdr $region1) | |
222 | 'put_values 1)))) | |
a2095e2e | 223 | (put_values |
78adbf9c CY |
224 | ((LBRACE) |
225 | nil) | |
226 | ((RBRACE) | |
227 | nil) | |
228 | ((put_value) | |
229 | (wisent-raw-tag | |
230 | (semantic-tag-new-code "put-value" $1)))) | |
a2095e2e | 231 | (put_value |
78adbf9c CY |
232 | ((SYMBOL any_value) |
233 | (cons $1 $2))) | |
a2095e2e | 234 | (scopestart_decl |
78adbf9c CY |
235 | ((SCOPESTART SYMBOL) |
236 | `(wisent-raw-tag | |
237 | (semantic-tag ',$2 'scopestart)))) | |
a2095e2e | 238 | (quotemode_decl |
78adbf9c CY |
239 | ((QUOTEMODE SYMBOL) |
240 | `(wisent-raw-tag | |
241 | (semantic-tag ',$2 'quotemode)))) | |
a2095e2e | 242 | (start_decl |
78adbf9c CY |
243 | ((START symbols) |
244 | `(wisent-raw-tag | |
245 | (semantic-tag ',(car $2) | |
246 | 'start :rest ',(cdr $2))))) | |
a2095e2e | 247 | (keyword_decl |
78adbf9c CY |
248 | ((KEYWORD SYMBOL string_value) |
249 | `(wisent-raw-tag | |
250 | (semantic-tag ',$2 'keyword :value ',$3)))) | |
a2095e2e | 251 | (token_decl |
78adbf9c CY |
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))))) | |
a2095e2e | 260 | (token_type_opt |
78adbf9c CY |
261 | (nil) |
262 | ((token_type))) | |
a2095e2e | 263 | (token_type |
78adbf9c CY |
264 | ((LT SYMBOL GT) |
265 | (progn $2))) | |
a2095e2e | 266 | (type_decl |
78adbf9c CY |
267 | ((TYPE token_type plist_opt) |
268 | `(wisent-raw-tag | |
269 | (semantic-tag ',$2 'type :value ',$3)))) | |
a2095e2e | 270 | (plist_opt |
78adbf9c CY |
271 | (nil) |
272 | ((plist))) | |
a2095e2e | 273 | (plist |
78adbf9c CY |
274 | ((plist put_value) |
275 | (append | |
276 | (list $2) | |
277 | $1)) | |
278 | ((put_value) | |
279 | (list $1))) | |
a2095e2e | 280 | (use_name_list |
78adbf9c CY |
281 | ((BRACE_BLOCK) |
282 | (mapcar 'semantic-tag-name | |
283 | (semantic-parse-region | |
284 | (car $region1) | |
285 | (cdr $region1) | |
286 | 'use_names 1)))) | |
a2095e2e | 287 | (use_names |
78adbf9c CY |
288 | ((LBRACE) |
289 | nil) | |
290 | ((RBRACE) | |
291 | nil) | |
292 | ((SYMBOL) | |
293 | (wisent-raw-tag | |
294 | (semantic-tag $1 'use-name)))) | |
a2095e2e | 295 | (use_macros_decl |
78adbf9c CY |
296 | ((USE-MACROS SYMBOL use_name_list) |
297 | `(wisent-raw-tag | |
298 | (semantic-tag "macro" 'macro :type ',$2 :value ',$3)))) | |
a2095e2e | 299 | (string_value |
78adbf9c CY |
300 | ((STRING) |
301 | (read $1))) | |
a2095e2e | 302 | (any_value |
78adbf9c CY |
303 | ((SYMBOL)) |
304 | ((STRING)) | |
305 | ((PAREN_BLOCK)) | |
306 | ((PREFIXED_LIST)) | |
307 | ((SEXP))) | |
a2095e2e | 308 | (symbols |
78adbf9c CY |
309 | ((lifo_symbols) |
310 | (nreverse $1))) | |
a2095e2e | 311 | (lifo_symbols |
78adbf9c CY |
312 | ((lifo_symbols SYMBOL) |
313 | (cons $2 $1)) | |
314 | ((SYMBOL) | |
315 | (list $1))) | |
a2095e2e | 316 | (nonterminal |
78adbf9c CY |
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)))) | |
a2095e2e | 322 | (rules |
78adbf9c CY |
323 | ((lifo_rules) |
324 | (apply 'nconc | |
325 | (nreverse $1)))) | |
a2095e2e | 326 | (lifo_rules |
78adbf9c CY |
327 | ((lifo_rules OR rule) |
328 | (cons $3 $1)) | |
329 | ((rule) | |
330 | (list $1))) | |
a2095e2e | 331 | (rule |
78adbf9c CY |
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) | |
343 | 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) | |
352 | (if | |
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)))) | |
360 | (t | |
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)))))) | |
a2095e2e | 370 | (rhs |
78adbf9c CY |
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))) | |
a2095e2e | 382 | (action |
78adbf9c CY |
383 | ((PAREN_BLOCK)) |
384 | ((PREFIXED_LIST)) | |
385 | ((BRACE_BLOCK) | |
386 | (format "(progn\n%s)" | |
387 | (let | |
388 | ((s $1)) | |
389 | (if | |
390 | (string-match "^{[\r\n ]*" s) | |
391 | (setq s | |
392 | (substring s | |
393 | (match-end 0)))) | |
394 | (if | |
395 | (string-match "[\r\n ]*}$" s) | |
396 | (setq s | |
397 | (substring s 0 | |
398 | (match-beginning 0)))) | |
399 | s)))) | |
a2095e2e | 400 | (items |
78adbf9c CY |
401 | ((lifo_items) |
402 | (nreverse $1))) | |
a2095e2e | 403 | (lifo_items |
78adbf9c CY |
404 | ((lifo_items item) |
405 | (cons $2 $1)) | |
406 | ((item) | |
407 | (list $1))) | |
a2095e2e | 408 | (item |
78adbf9c CY |
409 | ((SYMBOL)) |
410 | ((CHARACTER)))) | |
a2095e2e CY |
411 | '(grammar prologue epilogue declaration nonterminal rule put_names put_values use_names))) |
412 | "Parser table.") | |
413 | ||
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" | |
78adbf9c | 419 | semantic--parse-table semantic-grammar-wy--parse-table |
62a81506 | 420 | semantic-debug-parser-source "grammar.wy" |
78adbf9c CY |
421 | semantic-flex-keywords-obarray semantic-grammar-wy--keyword-table |
422 | semantic-lex-types-obarray semantic-grammar-wy--token-table) | |
a2095e2e CY |
423 | ;; Collect unmatched syntax lexical tokens |
424 | (semantic-make-local-hook 'wisent-discarding-token-functions) | |
425 | (add-hook 'wisent-discarding-token-functions | |
62a81506 | 426 | 'wisent-collect-unmatched-syntax nil t)) |
a2095e2e CY |
427 | |
428 | \f | |
429 | ;;; Analyzers | |
62a81506 | 430 | ;; |
a2095e2e CY |
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)) | |
438 | ) | |
439 | ||
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 | |
443 | nil | |
444 | 'CHARACTER) | |
445 | ||
a2095e2e CY |
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) | |
451 | ||
62a81506 CY |
452 | (define-lex-sexp-type-analyzer semantic-grammar-wy--<qlist>-sexp-analyzer |
453 | "sexp analyzer for <qlist> tokens." | |
454 | "\\s'\\s-*(" | |
455 | 'PREFIXED_LIST) | |
456 | ||
457 | (define-lex-sexp-type-analyzer semantic-grammar-wy--<string>-sexp-analyzer | |
458 | "sexp analyzer for <string> tokens." | |
459 | "\\s\"" | |
460 | 'STRING) | |
461 | ||
a2095e2e CY |
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) | |
471 | ||
62a81506 CY |
472 | (define-lex-keyword-type-analyzer semantic-grammar-wy--<keyword>-keyword-analyzer |
473 | "keyword analyzer for <keyword> tokens." | |
474 | "\\(\\sw\\|\\s_\\)+") | |
475 | ||
476 | (define-lex-sexp-type-analyzer semantic-grammar-wy--<sexp>-sexp-analyzer | |
477 | "sexp analyzer for <sexp> tokens." | |
478 | "\\=" | |
479 | 'SEXP) | |
480 | ||
481 | \f | |
482 | ;;; Epilogue | |
483 | ;; | |
484 | ||
485 | ||
486 | ||
487 | ||
a2095e2e CY |
488 | (provide 'semantic/grammar-wy) |
489 | ||
490 | ;;; semantic/grammar-wy.el ends here |