1 ;;; semantic/grammar-wy.el --- Generated parser support file
3 ;; Copyright (C) 2002-2004, 2009-2012 Free Software Foundation, Inc.
5 ;; Author: David Ponce <david@dponce.com>
8 ;; This file is part of GNU Emacs.
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.
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.
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/>.
25 ;; This file was generated from admin/grammars/grammar.wy.
29 (require 'semantic/lex)
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)
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)
46 ("%nonassoc" . NONASSOC)
47 ("%package" . PACKAGE)
50 ("%quotemode" . QUOTEMODE)
52 ("%scopestart" . SCOPESTART)
56 ("%use-macros" . USE-MACROS))
58 "Table of language keywords.")
60 (defconst semantic-grammar-wy--token-table
61 (semantic-lex-make-type-table
75 (BRACE_BLOCK . "(LBRACE RBRACE)")
76 (PAREN_BLOCK . "(LPAREN RPAREN)"))
78 (EPILOGUE . "%%...EOF")
79 (PROLOGUE . "%{...%}"))
87 (PERCENT_PERCENT . "\\`%%\\'")
91 '(("punctuation" :declared t)
93 ("sexp" matchdatatype sexp)
96 ("qlist" matchdatatype sexp)
97 ("qlist" syntax "\\s'\\s-*(")
99 ("char" syntax semantic-grammar-lex-c-char-re)
101 ("symbol" syntax ":?\\(\\sw\\|\\s_\\)+")
102 ("symbol" :declared t)
103 ("string" :declared t)
104 ("keyword" :declared t)))
105 "Table of lexical tokens.")
107 (defconst semantic-grammar-wy--parse-table
110 (require 'semantic/wisent/comp))
111 (wisent-compile-grammar
112 '((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)
123 (semantic-tag-new-code "prologue" nil))))
127 (semantic-tag-new-code "epilogue" nil))))
132 ((default_prec_decl))
133 ((no_default_prec_decl))
134 ((languagemode_decl))
148 (semantic-tag "default-prec" 'assoc :value
150 (no_default_prec_decl
153 (semantic-tag "default-prec" 'assoc :value
156 ((LANGUAGEMODE symbols)
158 (semantic-tag ',(car $2)
159 'languagemode :rest ',(cdr $2)))))
163 (semantic-tag-new-package ',$2 nil))))
165 ((associativity token_type_opt items)
167 (semantic-tag ',$1 'assoc :type ',$2 :value ',$3))))
176 ((PUT put_name put_value)
178 (semantic-tag ',$2 'put :value ',(list $3))))
179 ((PUT put_name put_value_list)
181 (semantic-tag ',$2 'put :value ',$3)))
182 ((PUT put_name_list put_value)
184 (semantic-tag ',(car $2)
185 'put :rest ',(cdr $2)
186 :value ',(list $3))))
187 ((PUT put_name_list put_value_list)
189 (semantic-tag ',(car $2)
190 'put :rest ',(cdr $2)
194 (mapcar 'semantic-tag-name
195 (semantic-parse-region
206 (semantic-tag $1 'put-name))))
212 (mapcar 'semantic-tag-code-detail
213 (semantic-parse-region
224 (semantic-tag-new-code "put-value" $1))))
231 (semantic-tag ',$2 'scopestart))))
235 (semantic-tag ',$2 'quotemode))))
239 (semantic-tag ',(car $2)
240 'start :rest ',(cdr $2)))))
242 ((KEYWORD SYMBOL string_value)
244 (semantic-tag ',$2 'keyword :value ',$3))))
246 ((TOKEN token_type_opt SYMBOL string_value)
248 (semantic-tag ',$3 ',(if $2 'token 'keyword)
249 :type ',$2 :value ',$4)))
250 ((TOKEN token_type_opt symbols)
252 (semantic-tag ',(car $3)
253 'token :type ',$2 :rest ',(cdr $3)))))
261 ((TYPE token_type plist_opt)
263 (semantic-tag ',$2 'type :value ',$3))))
276 (mapcar 'semantic-tag-name
277 (semantic-parse-region
288 (semantic-tag $1 'use-name))))
290 ((USE-MACROS SYMBOL use_name_list)
292 (semantic-tag "macro" 'macro :type ',$2 :value ',$3))))
306 ((lifo_symbols SYMBOL)
312 (setq semantic-grammar-wy--nterm $1 semantic-grammar-wy--rindx 0)
315 (semantic-tag $1 'nonterminal :children $4))))
321 ((lifo_rules OR rule)
328 ((nterm semantic-grammar-wy--nterm)
329 (rindx semantic-grammar-wy--rindx)
331 comps prec action elt)
332 (setq semantic-grammar-wy--rindx
333 (1+ semantic-grammar-wy--rindx))
342 (error "Duplicate %%prec in `%s:%d' rule" nterm rindx))
350 semantic-grammar-wy--rindx
351 (1+ semantic-grammar-wy--rindx))
360 (format "%s:%d" nterm rindx)
362 (if comps "group" "empty")
363 :value comps :prec prec :expr action))))))
380 (format "(progn\n%s)"
384 (string-match "^{[
\n ]*" s)
389 (string-match "[
\n ]*}$" s)
392 (match-beginning 0))))
405 '(grammar prologue epilogue declaration nonterminal rule put_names put_values use_names)))
408 (defun semantic-grammar-wy--install-parser ()
409 "Setup the Semantic Parser."
410 (semantic-install-function-overrides
411 '((parse-stream . wisent-parse-stream)))
412 (setq semantic-parser-name "LALR"
413 semantic--parse-table semantic-grammar-wy--parse-table
414 semantic-debug-parser-source "semantic-grammar.wy"
415 semantic-flex-keywords-obarray semantic-grammar-wy--keyword-table
416 semantic-lex-types-obarray semantic-grammar-wy--token-table)
417 ;; Collect unmatched syntax lexical tokens
418 (semantic-make-local-hook 'wisent-discarding-token-functions)
419 (add-hook 'wisent-discarding-token-functions
420 'wisent-collect-unmatched-syntax nil t))
425 (define-lex-sexp-type-analyzer semantic-grammar-wy--<sexp>-sexp-analyzer
426 "sexp analyzer for <sexp> tokens."
430 (define-lex-sexp-type-analyzer semantic-grammar-wy--<qlist>-sexp-analyzer
431 "sexp analyzer for <qlist> tokens."
435 (define-lex-keyword-type-analyzer semantic-grammar-wy--<keyword>-keyword-analyzer
436 "keyword analyzer for <keyword> tokens."
437 "\\(\\sw\\|\\s_\\)+")
439 (define-lex-block-type-analyzer semantic-grammar-wy--<block>-block-analyzer
440 "block analyzer for <block> tokens."
442 '((("(" LPAREN PAREN_BLOCK)
443 ("{" LBRACE BRACE_BLOCK))
448 (define-lex-regex-type-analyzer semantic-grammar-wy--<char>-regexp-analyzer
449 "regexp analyzer for <char> tokens."
450 semantic-grammar-lex-c-char-re
454 (define-lex-sexp-type-analyzer semantic-grammar-wy--<string>-sexp-analyzer
455 "sexp analyzer for <string> tokens."
459 (define-lex-regex-type-analyzer semantic-grammar-wy--<symbol>-regexp-analyzer
460 "regexp analyzer for <symbol> tokens."
461 ":?\\(\\sw\\|\\s_\\)+"
462 '((PERCENT_PERCENT . "\\`%%\\'"))
465 (define-lex-string-type-analyzer semantic-grammar-wy--<punctuation>-string-analyzer
466 "string analyzer for <punctuation> tokens."
467 "\\(\\s.\\|\\s$\\|\\s'\\)+"
475 (provide 'semantic/grammar-wy)
477 ;;; semantic/grammar-wy.el ends here