1 ;;; semantic/grammar-wy.el --- Generated parser support file
3 ;; Copyright (C) 2002-2004, 2009-2012 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/>.
22 ;; This file was generated from admin/grammars/grammar.wy.
26 (require 'semantic/lex)
27 (eval-when-compile (require 'semantic/bovine))
31 (defvar semantic-grammar-lex-c-char-re)
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)
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)
47 ("%nonassoc" . NONASSOC)
48 ("%package" . PACKAGE)
49 ("%provide" . PROVIDE)
52 ("%quotemode" . QUOTEMODE)
54 ("%scopestart" . SCOPESTART)
58 ("%use-macros" . USE-MACROS))
60 "Table of language keywords.")
62 (defconst semantic-grammar-wy--token-table
63 (semantic-lex-make-type-table
77 (BRACE_BLOCK . "(LBRACE RBRACE)")
78 (PAREN_BLOCK . "(LPAREN RPAREN)"))
80 (EPILOGUE . "%%...EOF")
81 (PROLOGUE . "%{...%}"))
89 (PERCENT_PERCENT . "\\`%%\\'")
93 '(("punctuation" :declared t)
95 ("sexp" matchdatatype sexp)
98 ("qlist" matchdatatype sexp)
99 ("qlist" syntax "\\s'\\s-*(")
100 ("qlist" :declared t)
101 ("char" syntax semantic-grammar-lex-c-char-re)
103 ("symbol" syntax ":?\\(\\sw\\|\\s_\\)+")
104 ("symbol" :declared t)
105 ("string" :declared t)
106 ("keyword" :declared t)))
107 "Table of lexical tokens.")
109 (defconst semantic-grammar-wy--parse-table
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)
125 (semantic-tag-new-code "prologue" nil))))
129 (semantic-tag-new-code "epilogue" nil))))
134 ((default_prec_decl))
135 ((no_default_prec_decl))
136 ((languagemode_decl))
151 (semantic-tag "default-prec" 'assoc :value
153 (no_default_prec_decl
156 (semantic-tag "default-prec" 'assoc :value
159 ((LANGUAGEMODE symbols)
161 (semantic-tag ',(car $2)
162 'languagemode :rest ',(cdr $2)))))
166 (semantic-tag-new-package ',$2 nil))))
170 (semantic-tag ',$2 'provide))))
172 ((associativity token_type_opt items)
174 (semantic-tag ',$1 'assoc :type ',$2 :value ',$3))))
183 ((PUT put_name put_value)
185 (semantic-tag ',$2 'put :value ',(list $3))))
186 ((PUT put_name put_value_list)
188 (semantic-tag ',$2 'put :value ',$3)))
189 ((PUT put_name_list put_value)
191 (semantic-tag ',(car $2)
192 'put :rest ',(cdr $2)
193 :value ',(list $3))))
194 ((PUT put_name_list put_value_list)
196 (semantic-tag ',(car $2)
197 'put :rest ',(cdr $2)
201 (mapcar 'semantic-tag-name
202 (semantic-parse-region
213 (semantic-tag $1 'put-name))))
219 (mapcar 'semantic-tag-code-detail
220 (semantic-parse-region
231 (semantic-tag-new-code "put-value" $1))))
238 (semantic-tag ',$2 'scopestart))))
242 (semantic-tag ',$2 'quotemode))))
246 (semantic-tag ',(car $2)
247 'start :rest ',(cdr $2)))))
249 ((KEYWORD SYMBOL string_value)
251 (semantic-tag ',$2 'keyword :value ',$3))))
253 ((TOKEN token_type_opt SYMBOL string_value)
255 (semantic-tag ',$3 ',(if $2 'token 'keyword)
256 :type ',$2 :value ',$4)))
257 ((TOKEN token_type_opt symbols)
259 (semantic-tag ',(car $3)
260 'token :type ',$2 :rest ',(cdr $3)))))
268 ((TYPE token_type plist_opt)
270 (semantic-tag ',$2 'type :value ',$3))))
283 (mapcar 'semantic-tag-name
284 (semantic-parse-region
295 (semantic-tag $1 'use-name))))
297 ((USE-MACROS SYMBOL use_name_list)
299 (semantic-tag "macro" 'macro :type ',$2 :value ',$3))))
313 ((lifo_symbols SYMBOL)
319 (setq semantic-grammar-wy--nterm $1 semantic-grammar-wy--rindx 0)
322 (semantic-tag $1 'nonterminal :children $4))))
328 ((lifo_rules OR rule)
335 ((nterm semantic-grammar-wy--nterm)
336 (rindx semantic-grammar-wy--rindx)
338 comps prec action elt)
339 (setq semantic-grammar-wy--rindx
340 (1+ semantic-grammar-wy--rindx))
349 (error "Duplicate %%prec in `%s:%d' rule" nterm rindx))
357 semantic-grammar-wy--rindx
358 (1+ semantic-grammar-wy--rindx))
367 (format "%s:%d" nterm rindx)
369 (if comps "group" "empty")
370 :value comps :prec prec :expr action))))))
387 (format "(progn\n%s)"
391 (string-match "^{[
\n ]*" s)
396 (string-match "[
\n ]*}$" s)
399 (match-beginning 0))))
412 '(grammar prologue epilogue declaration nonterminal rule put_names put_values use_names)))
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))
432 (define-lex-block-type-analyzer semantic-grammar-wy--<block>-block-analyzer
433 "block analyzer for <block> tokens."
435 '((("(" LPAREN PAREN_BLOCK)
436 ("{" LBRACE BRACE_BLOCK))
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
447 (define-lex-regex-type-analyzer semantic-grammar-wy--<symbol>-regexp-analyzer
448 "regexp analyzer for <symbol> tokens."
449 ":?\\(\\sw\\|\\s_\\)+"
450 '((PERCENT_PERCENT . "\\`%%\\'"))
453 (define-lex-sexp-type-analyzer semantic-grammar-wy--<qlist>-sexp-analyzer
454 "sexp analyzer for <qlist> tokens."
458 (define-lex-sexp-type-analyzer semantic-grammar-wy--<string>-sexp-analyzer
459 "sexp analyzer for <string> tokens."
463 (define-lex-string-type-analyzer semantic-grammar-wy--<punctuation>-string-analyzer
464 "string analyzer for <punctuation> tokens."
465 "\\(\\s.\\|\\s$\\|\\s'\\)+"
473 (define-lex-keyword-type-analyzer semantic-grammar-wy--<keyword>-keyword-analyzer
474 "keyword analyzer for <keyword> tokens."
475 "\\(\\sw\\|\\s_\\)+")
477 (define-lex-sexp-type-analyzer semantic-grammar-wy--<sexp>-sexp-analyzer
478 "sexp analyzer for <sexp> tokens."
489 (provide 'semantic/grammar-wy)
491 ;;; semantic/grammar-wy.el ends here