1 ;;; semantic-grammar-wy.el --- Generated parser support file
3 ;; Copyright (C) 2002, 2003, 2004 David Ponce
5 ;; Author: David Ponce <david@dponce.com>
6 ;; Created: 2004-03-20 12:34:58+0100
8 ;; X-RCS: $Id: semantic-grammar-wy.el,v 1.1 2007-11-26 15:10:37 michaels Exp $
10 ;; This file is not part of GNU Emacs.
12 ;; This program is free software; you can redistribute it and/or
13 ;; modify it under the terms of the GNU General Public License as
14 ;; published by the Free Software Foundation; either version 2, or (at
15 ;; your option) any later version.
17 ;; This software is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ;; General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
29 ;; PLEASE DO NOT MANUALLY EDIT THIS FILE! It is automatically
30 ;; generated from the grammar file semantic-grammar.wy.
39 ;; Current parsed nonterminal name.
40 (defvar semantic-grammar-wy--nterm nil)
41 ;; Index of rule in a nonterminal clause.
42 (defvar semantic-grammar-wy--rindx nil)
46 (defconst semantic-grammar-wy--keyword-table
47 (semantic-lex-make-keyword-table
48 '(("%default-prec" . DEFAULT-PREC)
49 ("%no-default-prec" . NO-DEFAULT-PREC)
50 ("%keyword" . KEYWORD)
51 ("%languagemode" . LANGUAGEMODE)
53 ("%nonassoc" . NONASSOC)
54 ("%package" . PACKAGE)
57 ("%quotemode" . QUOTEMODE)
59 ("%scopestart" . SCOPESTART)
63 ("%use-macros" . USE-MACROS))
65 "Table of language keywords.")
67 (defconst semantic-grammar-wy--token-table
68 (semantic-lex-make-type-table
82 (BRACE_BLOCK . "(LBRACE RBRACE)")
83 (PAREN_BLOCK . "(LPAREN RPAREN)"))
85 (EPILOGUE . "%%...EOF")
86 (PROLOGUE . "%{...%}"))
94 (PERCENT_PERCENT . "\\`%%\\'")
98 '(("punctuation" :declared t)
100 ("sexp" matchdatatype sexp)
101 ("sexp" syntax "\\=")
103 ("qlist" matchdatatype sexp)
104 ("qlist" syntax "\\s'\\s-*(")
105 ("qlist" :declared t)
106 ("char" syntax semantic-grammar-lex-c-char-re)
108 ("symbol" syntax ":?\\(\\sw\\|\\s_\\)+")
109 ("symbol" :declared t)
110 ("string" :declared t)
111 ("keyword" :declared t)))
112 "Table of lexical tokens.")
114 (defconst semantic-grammar-wy--parse-table
117 (require 'wisent-comp))
118 (wisent-compile-grammar
119 '((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)
130 (semantic-tag-new-code "prologue" nil))))
134 (semantic-tag-new-code "epilogue" nil))))
139 ((default_prec_decl))
140 ((no_default_prec_decl))
141 ((languagemode_decl))
155 (semantic-tag "default-prec" 'assoc :value
157 (no_default_prec_decl
160 (semantic-tag "default-prec" 'assoc :value
163 ((LANGUAGEMODE symbols)
165 (semantic-tag ',(car $2)
166 'languagemode :rest ',(cdr $2)))))
170 (semantic-tag-new-package ',$2 nil))))
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 "^{[
\r\n ]*" s)
396 (string-match "[
\r\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 "semantic-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 (require 'semantic-lex)
434 (define-lex-sexp-type-analyzer semantic-grammar-wy--<sexp>-sexp-analyzer
435 "sexp analyzer for <sexp> tokens."
439 (define-lex-sexp-type-analyzer semantic-grammar-wy--<qlist>-sexp-analyzer
440 "sexp analyzer for <qlist> tokens."
444 (define-lex-keyword-type-analyzer semantic-grammar-wy--<keyword>-keyword-analyzer
445 "keyword analyzer for <keyword> tokens."
446 "\\(\\sw\\|\\s_\\)+")
448 (define-lex-block-type-analyzer semantic-grammar-wy--<block>-block-analyzer
449 "block analyzer for <block> tokens."
451 '((("(" LPAREN PAREN_BLOCK)
452 ("{" LBRACE BRACE_BLOCK))
457 (define-lex-regex-type-analyzer semantic-grammar-wy--<char>-regexp-analyzer
458 "regexp analyzer for <char> tokens."
459 semantic-grammar-lex-c-char-re
463 (define-lex-sexp-type-analyzer semantic-grammar-wy--<string>-sexp-analyzer
464 "sexp analyzer for <string> tokens."
468 (define-lex-regex-type-analyzer semantic-grammar-wy--<symbol>-regexp-analyzer
469 "regexp analyzer for <symbol> tokens."
470 ":?\\(\\sw\\|\\s_\\)+"
471 '((PERCENT_PERCENT . "\\`%%\\'"))
474 (define-lex-string-type-analyzer semantic-grammar-wy--<punctuation>-string-analyzer
475 "string analyzer for <punctuation> tokens."
476 "\\(\\s.\\|\\s$\\|\\s'\\)+"
487 (define-lex semantic-grammar-lexer
488 "Lexical analyzer that handles Semantic grammar buffers.
489 It ignores whitespaces, newlines and comments."
490 semantic-lex-ignore-newline
491 semantic-lex-ignore-whitespace
492 ;; Must detect prologue/epilogue before other symbols/keywords!
493 semantic-grammar-lex-prologue
494 semantic-grammar-lex-epilogue
495 semantic-grammar-wy--<keyword>-keyword-analyzer
496 semantic-grammar-wy--<symbol>-regexp-analyzer
497 semantic-grammar-wy--<char>-regexp-analyzer
498 semantic-grammar-wy--<string>-sexp-analyzer
499 ;; Must detect comments after strings because `comment-start-skip'
500 ;; regexp match semicolons inside strings!
501 semantic-lex-ignore-comments
502 ;; Must detect prefixed list before punctuation because prefix chars
503 ;; are also punctuations!
504 semantic-grammar-wy--<qlist>-sexp-analyzer
505 ;; Must detect punctuations after comments because the semicolon can
506 ;; be a punctuation or a comment start!
507 semantic-grammar-wy--<punctuation>-string-analyzer
508 semantic-grammar-wy--<block>-block-analyzer
509 semantic-grammar-wy--<sexp>-sexp-analyzer
512 (provide 'semantic-grammar-wy)
514 ;;; semantic-grammar-wy.el ends here