Remove non-free old and crusty clearcase pkg
[packages] / xemacs-packages / semantic / semantic-grammar-wy.el
1 ;;; semantic-grammar-wy.el --- Generated parser support file
2
3 ;; Copyright (C) 2002, 2003, 2004 David Ponce
4
5 ;; Author: David Ponce <david@dponce.com>
6 ;; Created: 2004-03-20 12:34:58+0100
7 ;; Keywords: syntax
8 ;; X-RCS: $Id: semantic-grammar-wy.el,v 1.1 2007-11-26 15:10:37 michaels Exp $
9
10 ;; This file is not part of GNU Emacs.
11 ;;
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.
16 ;;
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.
21 ;;
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.
26
27 ;;; Commentary:
28 ;;
29 ;; PLEASE DO NOT MANUALLY EDIT THIS FILE!  It is automatically
30 ;; generated from the grammar file semantic-grammar.wy.
31
32 ;;; History:
33 ;;
34
35 ;;; Code:
36 \f
37 ;;; Prologue
38 ;;
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)
43 \f
44 ;;; Declarations
45 ;;
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)
52      ("%left" . LEFT)
53      ("%nonassoc" . NONASSOC)
54      ("%package" . PACKAGE)
55      ("%prec" . PREC)
56      ("%put" . PUT)
57      ("%quotemode" . QUOTEMODE)
58      ("%right" . RIGHT)
59      ("%scopestart" . SCOPESTART)
60      ("%start" . START)
61      ("%token" . TOKEN)
62      ("%type" . TYPE)
63      ("%use-macros" . USE-MACROS))
64    'nil)
65   "Table of language keywords.")
66
67 (defconst semantic-grammar-wy--token-table
68   (semantic-lex-make-type-table
69    '(("punctuation"
70       (GT . ">")
71       (LT . "<")
72       (OR . "|")
73       (SEMI . ";")
74       (COLON . ":"))
75      ("close-paren"
76       (RBRACE . "}")
77       (RPAREN . ")"))
78      ("open-paren"
79       (LBRACE . "{")
80       (LPAREN . "("))
81      ("block"
82       (BRACE_BLOCK . "(LBRACE RBRACE)")
83       (PAREN_BLOCK . "(LPAREN RPAREN)"))
84      ("code"
85       (EPILOGUE . "%%...EOF")
86       (PROLOGUE . "%{...%}"))
87      ("sexp"
88       (SEXP))
89      ("qlist"
90       (PREFIXED_LIST))
91      ("char"
92       (CHARACTER))
93      ("symbol"
94       (PERCENT_PERCENT . "\\`%%\\'")
95       (SYMBOL))
96      ("string"
97       (STRING)))
98    '(("punctuation" :declared t)
99      ("block" :declared t)
100      ("sexp" matchdatatype sexp)
101      ("sexp" syntax "\\=")
102      ("sexp" :declared t)
103      ("qlist" matchdatatype sexp)
104      ("qlist" syntax "\\s'\\s-*(")
105      ("qlist" :declared t)
106      ("char" syntax semantic-grammar-lex-c-char-re)
107      ("char" :declared t)
108      ("symbol" syntax ":?\\(\\sw\\|\\s_\\)+")
109      ("symbol" :declared t)
110      ("string" :declared t)
111      ("keyword" :declared t)))
112   "Table of lexical tokens.")
113
114 (defconst semantic-grammar-wy--parse-table
115   (progn
116     (eval-when-compile
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)
120        nil
121        (grammar
122         ((prologue))
123         ((epilogue))
124         ((declaration))
125         ((nonterminal))
126         ((PERCENT_PERCENT)))
127        (prologue
128         ((PROLOGUE)
129          (wisent-raw-tag
130           (semantic-tag-new-code "prologue" nil))))
131        (epilogue
132         ((EPILOGUE)
133          (wisent-raw-tag
134           (semantic-tag-new-code "epilogue" nil))))
135        (declaration
136         ((decl)
137          (eval $1)))
138        (decl
139         ((default_prec_decl))
140         ((no_default_prec_decl))
141         ((languagemode_decl))
142         ((package_decl))
143         ((precedence_decl))
144         ((put_decl))
145         ((quotemode_decl))
146         ((scopestart_decl))
147         ((start_decl))
148         ((keyword_decl))
149         ((token_decl))
150         ((type_decl))
151         ((use_macros_decl)))
152        (default_prec_decl
153          ((DEFAULT-PREC)
154           `(wisent-raw-tag
155             (semantic-tag "default-prec" 'assoc :value
156                           '("t")))))
157        (no_default_prec_decl
158         ((NO-DEFAULT-PREC)
159          `(wisent-raw-tag
160            (semantic-tag "default-prec" 'assoc :value
161                          '("nil")))))
162        (languagemode_decl
163         ((LANGUAGEMODE symbols)
164          `(wisent-raw-tag
165            (semantic-tag ',(car $2)
166                          'languagemode :rest ',(cdr $2)))))
167        (package_decl
168         ((PACKAGE SYMBOL)
169          `(wisent-raw-tag
170            (semantic-tag-new-package ',$2 nil))))
171        (precedence_decl
172         ((associativity token_type_opt items)
173          `(wisent-raw-tag
174            (semantic-tag ',$1 'assoc :type ',$2 :value ',$3))))
175        (associativity
176         ((LEFT)
177          (progn "left"))
178         ((RIGHT)
179          (progn "right"))
180         ((NONASSOC)
181          (progn "nonassoc")))
182        (put_decl
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))))
199        (put_name_list
200         ((BRACE_BLOCK)
201          (mapcar 'semantic-tag-name
202                  (semantic-parse-region
203                   (car $region1)
204                   (cdr $region1)
205                   'put_names 1))))
206        (put_names
207         ((LBRACE)
208          nil)
209         ((RBRACE)
210          nil)
211         ((put_name)
212          (wisent-raw-tag
213           (semantic-tag $1 'put-name))))
214        (put_name
215         ((SYMBOL))
216         ((token_type)))
217        (put_value_list
218         ((BRACE_BLOCK)
219          (mapcar 'semantic-tag-code-detail
220                  (semantic-parse-region
221                   (car $region1)
222                   (cdr $region1)
223                   'put_values 1))))
224        (put_values
225         ((LBRACE)
226          nil)
227         ((RBRACE)
228          nil)
229         ((put_value)
230          (wisent-raw-tag
231           (semantic-tag-new-code "put-value" $1))))
232        (put_value
233         ((SYMBOL any_value)
234          (cons $1 $2)))
235        (scopestart_decl
236         ((SCOPESTART SYMBOL)
237          `(wisent-raw-tag
238            (semantic-tag ',$2 'scopestart))))
239        (quotemode_decl
240         ((QUOTEMODE SYMBOL)
241          `(wisent-raw-tag
242            (semantic-tag ',$2 'quotemode))))
243        (start_decl
244         ((START symbols)
245          `(wisent-raw-tag
246            (semantic-tag ',(car $2)
247                          'start :rest ',(cdr $2)))))
248        (keyword_decl
249         ((KEYWORD SYMBOL string_value)
250          `(wisent-raw-tag
251            (semantic-tag ',$2 'keyword :value ',$3))))
252        (token_decl
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)))))
261        (token_type_opt
262         (nil)
263         ((token_type)))
264        (token_type
265         ((LT SYMBOL GT)
266          (progn $2)))
267        (type_decl
268         ((TYPE token_type plist_opt)
269          `(wisent-raw-tag
270            (semantic-tag ',$2 'type :value ',$3))))
271        (plist_opt
272         (nil)
273         ((plist)))
274        (plist
275         ((plist put_value)
276          (append
277           (list $2)
278           $1))
279         ((put_value)
280          (list $1)))
281        (use_name_list
282         ((BRACE_BLOCK)
283          (mapcar 'semantic-tag-name
284                  (semantic-parse-region
285                   (car $region1)
286                   (cdr $region1)
287                   'use_names 1))))
288        (use_names
289         ((LBRACE)
290          nil)
291         ((RBRACE)
292          nil)
293         ((SYMBOL)
294          (wisent-raw-tag
295           (semantic-tag $1 'use-name))))
296        (use_macros_decl
297         ((USE-MACROS SYMBOL use_name_list)
298          `(wisent-raw-tag
299            (semantic-tag "macro" 'macro :type ',$2 :value ',$3))))
300        (string_value
301         ((STRING)
302          (read $1)))
303        (any_value
304         ((SYMBOL))
305         ((STRING))
306         ((PAREN_BLOCK))
307         ((PREFIXED_LIST))
308         ((SEXP)))
309        (symbols
310         ((lifo_symbols)
311          (nreverse $1)))
312        (lifo_symbols
313         ((lifo_symbols SYMBOL)
314          (cons $2 $1))
315         ((SYMBOL)
316          (list $1)))
317        (nonterminal
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))))
323        (rules
324         ((lifo_rules)
325          (apply 'nconc
326                 (nreverse $1))))
327        (lifo_rules
328         ((lifo_rules OR rule)
329          (cons $3 $1))
330         ((rule)
331          (list $1)))
332        (rule
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))))))
371        (rhs
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)))
383        (action
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))))
401        (items
402         ((lifo_items)
403          (nreverse $1)))
404        (lifo_items
405         ((lifo_items item)
406          (cons $2 $1))
407         ((item)
408          (list $1)))
409        (item
410         ((SYMBOL))
411         ((CHARACTER))))
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"
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))
428
429 \f
430 ;;; Analyzers
431 ;;
432 (require 'semantic-lex)
433
434 (define-lex-sexp-type-analyzer semantic-grammar-wy--<sexp>-sexp-analyzer
435   "sexp analyzer for <sexp> tokens."
436   "\\="
437   'SEXP)
438
439 (define-lex-sexp-type-analyzer semantic-grammar-wy--<qlist>-sexp-analyzer
440   "sexp analyzer for <qlist> tokens."
441   "\\s'\\s-*("
442   'PREFIXED_LIST)
443
444 (define-lex-keyword-type-analyzer semantic-grammar-wy--<keyword>-keyword-analyzer
445   "keyword analyzer for <keyword> tokens."
446   "\\(\\sw\\|\\s_\\)+")
447
448 (define-lex-block-type-analyzer semantic-grammar-wy--<block>-block-analyzer
449   "block analyzer for <block> tokens."
450   "\\s(\\|\\s)"
451   '((("(" LPAREN PAREN_BLOCK)
452      ("{" LBRACE BRACE_BLOCK))
453     (")" RPAREN)
454     ("}" RBRACE))
455   )
456
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
460   nil
461   'CHARACTER)
462
463 (define-lex-sexp-type-analyzer semantic-grammar-wy--<string>-sexp-analyzer
464   "sexp analyzer for <string> tokens."
465   "\\s\""
466   'STRING)
467
468 (define-lex-regex-type-analyzer semantic-grammar-wy--<symbol>-regexp-analyzer
469   "regexp analyzer for <symbol> tokens."
470   ":?\\(\\sw\\|\\s_\\)+"
471   '((PERCENT_PERCENT . "\\`%%\\'"))
472   'SYMBOL)
473
474 (define-lex-string-type-analyzer semantic-grammar-wy--<punctuation>-string-analyzer
475   "string analyzer for <punctuation> tokens."
476   "\\(\\s.\\|\\s$\\|\\s'\\)+"
477   '((GT . ">")
478     (LT . "<")
479     (OR . "|")
480     (SEMI . ";")
481     (COLON . ":"))
482   'punctuation)
483
484 \f
485 ;;; Epilogue
486 ;;
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
510   )
511
512 (provide 'semantic-grammar-wy)
513
514 ;;; semantic-grammar-wy.el ends here