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