Mercurial > emacs
annotate lisp/cedet/semantic/wisent/wisent.el @ 112115:f423bf015fa8
* NEWS: Extended behaviour of dbus-register-{method,property}.
author | Michael Albinus <michael.albinus@gmx.de> |
---|---|
date | Tue, 04 Jan 2011 13:44:17 +0100 |
parents | 1d1d5d9bd884 |
children | 376148b31b5e |
rev | line source |
---|---|
104478
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1 ;;; semantic/wisent/wisent.el --- GNU Bison for Emacs - Runtime |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2 |
106815 | 3 ;;; Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010 |
104478
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
4 ;;; Free Software Foundation, Inc. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
5 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
6 ;; Author: David Ponce <david@dponce.com> |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
7 ;; Maintainer: David Ponce <david@dponce.com> |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
8 ;; Created: 30 January 2002 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
9 ;; Keywords: syntax |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
10 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
11 ;; This file is part of GNU Emacs. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
12 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
13 ;; GNU Emacs is free software: you can redistribute it and/or modify |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
14 ;; it under the terms of the GNU General Public License as published by |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
15 ;; the Free Software Foundation, either version 3 of the License, or |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
16 ;; (at your option) any later version. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
17 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
18 ;; GNU Emacs is distributed in the hope that it will be useful, |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
21 ;; GNU General Public License for more details. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
22 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
23 ;; You should have received a copy of the GNU General Public License |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
25 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
26 ;;; Commentary: |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
27 ;; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
28 ;; Parser engine and runtime of Wisent. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
29 ;; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
30 ;; Wisent (the European Bison ;-) is an Elisp implementation of the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
31 ;; GNU Compiler Compiler Bison. The Elisp code is a port of the C |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
32 ;; code of GNU Bison 1.28 & 1.31. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
33 ;; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
34 ;; For more details on the basic concepts for understanding Wisent, |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
35 ;; read the Bison manual ;) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
36 ;; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
37 ;; For more details on Wisent itself read the Wisent manual. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
38 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
39 ;;; History: |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
40 ;; |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
41 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
42 ;;; Code: |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
43 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
44 (defgroup wisent nil |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
45 " |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
46 /\\_.-^^^-._/\\ The GNU |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
47 \\_ _/ |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
48 ( `o ` (European ;-) Bison |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
49 \\ ` / |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
50 ( D ,¨ for Emacs! |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
51 ` ~ ,¨ |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
52 `\"\"" |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
53 :group 'semantic) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
54 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
55 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
56 ;;;; ------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
57 ;;;; Runtime stuff |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
58 ;;;; ------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
59 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
60 ;;; Compatibility |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
61 (eval-and-compile |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
62 (if (fboundp 'char-valid-p) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
63 (defalias 'wisent-char-p 'char-valid-p) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
64 (defalias 'wisent-char-p 'char-or-char-int-p))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
65 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
66 ;;; Printed representation of terminals and nonterminals |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
67 (defconst wisent-escape-sequence-strings |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
68 '( |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
69 (?\a . "'\\a'") ; C-g |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
70 (?\b . "'\\b'") ; backspace, BS, C-h |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
71 (?\t . "'\\t'") ; tab, TAB, C-i |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
72 (?\n . "'\\n'") ; newline, C-j |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
73 (?\v . "'\\v'") ; vertical tab, C-k |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
74 (?\f . "'\\f'") ; formfeed character, C-l |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
75 (?\r . "'\\r'") ; carriage return, RET, C-m |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
76 (?\e . "'\\e'") ; escape character, ESC, C-[ |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
77 (?\\ . "'\\'") ; backslash character, \ |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
78 (?\d . "'\\d'") ; delete character, DEL |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
79 ) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
80 "Printed representation of usual escape sequences.") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
81 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
82 (defsubst wisent-item-to-string (item) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
83 "Return a printed representation of ITEM. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
84 ITEM can be a nonterminal or terminal symbol, or a character literal." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
85 (if (wisent-char-p item) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
86 (or (cdr (assq item wisent-escape-sequence-strings)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
87 (format "'%c'" item)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
88 (symbol-name item))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
89 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
90 (defsubst wisent-token-to-string (token) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
91 "Return a printed representation of lexical token TOKEN." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
92 (format "%s%s(%S)" (wisent-item-to-string (car token)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
93 (if (nth 2 token) (format "@%s" (nth 2 token)) "") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
94 (nth 1 token))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
95 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
96 ;;; Special symbols |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
97 (defconst wisent-eoi-term '$EOI |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
98 "End Of Input token.") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
99 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
100 (defconst wisent-error-term 'error |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
101 "Error recovery token.") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
102 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
103 (defconst wisent-accept-tag 'accept |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
104 "Accept result after input successfully parsed.") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
105 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
106 (defconst wisent-error-tag 'error |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
107 "Process a syntax error.") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
108 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
109 ;;; Special functions |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
110 (defun wisent-automaton-p (obj) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
111 "Return non-nil if OBJ is a LALR automaton. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
112 If OBJ is a symbol check its value." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
113 (and obj (symbolp obj) (boundp obj) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
114 (setq obj (symbol-value obj))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
115 (and (vectorp obj) (= 4 (length obj)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
116 (vectorp (aref obj 0)) (vectorp (aref obj 1)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
117 (= (length (aref obj 0)) (length (aref obj 1))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
118 (listp (aref obj 2)) (vectorp (aref obj 3)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
119 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
120 (defsubst wisent-region (&rest positions) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
121 "Return the start/end positions of the region including POSITIONS. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
122 Each element of POSITIONS is a pair (START-POS . END-POS) or nil. The |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
123 returned value is the pair (MIN-START-POS . MAX-END-POS) or nil if no |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
124 POSITIONS are available." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
125 (let ((pl (delq nil positions))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
126 (if pl |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
127 (cons (apply #'min (mapcar #'car pl)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
128 (apply #'max (mapcar #'cdr pl)))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
129 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
130 ;;; Reporting |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
131 (defvar wisent-parse-verbose-flag nil |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
132 "*Non-nil means to issue more messages while parsing.") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
133 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
134 (defun wisent-parse-toggle-verbose-flag () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
135 "Toggle whether to issue more messages while parsing." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
136 (interactive) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
137 (setq wisent-parse-verbose-flag (not wisent-parse-verbose-flag)) |
106197
019d906c8f48
* cedet/srecode/map.el (srecode-get-maps):
Chong Yidong <cyd@stupidchicken.com>
parents:
105423
diff
changeset
|
138 (when (called-interactively-p 'interactive) |
104478
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
139 (message "More messages while parsing %sabled" |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
140 (if wisent-parse-verbose-flag "en" "dis")))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
141 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
142 (defsubst wisent-message (string &rest args) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
143 "Print a one-line message if `wisent-parse-verbose-flag' is set. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
144 Pass STRING and ARGS arguments to `message'." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
145 (and wisent-parse-verbose-flag |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
146 (apply 'message string args))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
147 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
148 ;;;; -------------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
149 ;;;; The LR parser engine |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
150 ;;;; -------------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
151 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
152 (defcustom wisent-parse-max-stack-size 500 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
153 "The parser stack size." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
154 :type 'integer |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
155 :group 'wisent) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
156 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
157 (defcustom wisent-parse-max-recover 3 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
158 "Number of tokens to shift before turning off error status." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
159 :type 'integer |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
160 :group 'wisent) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
161 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
162 (defvar wisent-discarding-token-functions nil |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
163 "List of functions to be called when discarding a lexical token. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
164 These functions receive the lexical token discarded. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
165 When the parser encounters unexpected tokens, it can discards them, |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
166 based on what directed by error recovery rules. Either when the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
167 parser reads tokens until one is found that can be shifted, or when an |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
168 semantic action calls the function `wisent-skip-token' or |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
169 `wisent-skip-block'. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
170 For language specific hooks, make sure you define this as a local |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
171 hook.") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
172 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
173 (defvar wisent-pre-parse-hook nil |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
174 "Normal hook run just before entering the LR parser engine.") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
175 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
176 (defvar wisent-post-parse-hook nil |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
177 "Normal hook run just after the LR parser engine terminated.") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
178 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
179 (defvar wisent-loop nil |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
180 "The current parser action. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
181 Stop parsing when set to nil. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
182 This variable only has meaning in the scope of `wisent-parse'.") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
183 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
184 (defvar wisent-nerrs nil |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
185 "The number of parse errors encountered so far.") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
186 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
187 (defvar wisent-lookahead nil |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
188 "The lookahead lexical token. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
189 This value is non-nil if the parser terminated because of an |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
190 unrecoverable error.") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
191 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
192 ;; Variables and macros that are useful in semantic actions. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
193 (defvar wisent-parse-lexer-function nil |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
194 "The user supplied lexer function. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
195 This function don't have arguments. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
196 This variable only has meaning in the scope of `wisent-parse'.") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
197 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
198 (defvar wisent-parse-error-function nil |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
199 "The user supplied error function. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
200 This function must accept one argument, a message string. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
201 This variable only has meaning in the scope of `wisent-parse'.") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
202 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
203 (defvar wisent-input nil |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
204 "The last token read. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
205 This variable only has meaning in the scope of `wisent-parse'.") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
206 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
207 (defvar wisent-recovering nil |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
208 "Non-nil means that the parser is recovering. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
209 This variable only has meaning in the scope of `wisent-parse'.") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
210 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
211 ;; Variables that only have meaning in the scope of a semantic action. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
212 ;; These global definitions avoid byte-compiler warnings. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
213 (defvar $region nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
214 (defvar $nterm nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
215 (defvar $action nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
216 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
217 (defmacro wisent-lexer () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
218 "Obtain the next terminal in input." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
219 '(funcall wisent-parse-lexer-function)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
220 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
221 (defmacro wisent-error (msg) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
222 "Call the user supplied error reporting function with message MSG." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
223 `(funcall wisent-parse-error-function ,msg)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
224 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
225 (defmacro wisent-errok () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
226 "Resume generating error messages immediately for subsequent syntax errors. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
227 This is useful primarily in error recovery semantic actions." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
228 '(setq wisent-recovering nil)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
229 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
230 (defmacro wisent-clearin () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
231 "Discard the current lookahead token. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
232 This will cause a new lexical token to be read. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
233 This is useful primarily in error recovery semantic actions." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
234 '(setq wisent-input nil)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
235 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
236 (defmacro wisent-abort () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
237 "Abort parsing and save the lookahead token. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
238 This is useful primarily in error recovery semantic actions." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
239 '(setq wisent-lookahead wisent-input |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
240 wisent-loop nil)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
241 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
242 (defmacro wisent-set-region (start end) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
243 "Change the region of text matched by the current nonterminal. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
244 START and END are respectively the beginning and end positions of the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
245 region. If START or END values are not a valid positions the region |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
246 is set to nil." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
247 `(setq $region (and (number-or-marker-p ,start) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
248 (number-or-marker-p ,end) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
249 (cons ,start ,end)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
250 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
251 (defun wisent-skip-token () |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
252 "Skip the lookahead token in order to resume parsing. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
253 Return nil. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
254 Must be used in error recovery semantic actions." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
255 (if (eq (car wisent-input) wisent-eoi-term) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
256 ;; Does nothing at EOI to avoid infinite recovery loop. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
257 nil |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
258 (wisent-message "%s: skip %s" $action |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
259 (wisent-token-to-string wisent-input)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
260 (run-hook-with-args |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
261 'wisent-discarding-token-functions wisent-input) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
262 (wisent-clearin) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
263 (wisent-errok))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
264 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
265 (defun wisent-skip-block (&optional bounds) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
266 "Safely skip a parenthesized block in order to resume parsing. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
267 Return nil. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
268 Must be used in error recovery semantic actions. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
269 Optional argument BOUNDS is a pair (START . END) which indicates where |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
270 the parenthesized block starts. Typically the value of a `$regionN' |
105423
309bc750556d
* files-x.el (modify-dir-local-variable)
Juanma Barranquero <lekktu@gmail.com>
parents:
105377
diff
changeset
|
271 variable, where `N' is the Nth element of the current rule components |
309bc750556d
* files-x.el (modify-dir-local-variable)
Juanma Barranquero <lekktu@gmail.com>
parents:
105377
diff
changeset
|
272 that match the block beginning. It defaults to the value of the |
309bc750556d
* files-x.el (modify-dir-local-variable)
Juanma Barranquero <lekktu@gmail.com>
parents:
105377
diff
changeset
|
273 `$region' variable." |
104478
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
274 (let ((start (car (or bounds $region))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
275 end input) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
276 (if (not (number-or-marker-p start)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
277 ;; No nonterminal region available, skip the lookahead token. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
278 (wisent-skip-token) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
279 ;; Try to skip a block. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
280 (if (not (setq end (save-excursion |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
281 (goto-char start) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
282 (and (looking-at "\\s(") |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
283 (condition-case nil |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
284 (1- (scan-lists (point) 1 0)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
285 (error nil)))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
286 ;; Not actually a block, skip the lookahead token. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
287 (wisent-skip-token) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
288 ;; OK to safely skip the block, so read input until a matching |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
289 ;; close paren or EOI is encountered. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
290 (setq input wisent-input) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
291 (while (and (not (eq (car input) wisent-eoi-term)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
292 (< (nth 2 input) end)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
293 (run-hook-with-args |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
294 'wisent-discarding-token-functions input) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
295 (setq input (wisent-lexer))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
296 (wisent-message "%s: in enclosing block, skip from %s to %s" |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
297 $action |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
298 (wisent-token-to-string wisent-input) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
299 (wisent-token-to-string input)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
300 (if (eq (car wisent-input) wisent-eoi-term) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
301 ;; Does nothing at EOI to avoid infinite recovery loop. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
302 nil |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
303 (wisent-clearin) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
304 (wisent-errok)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
305 ;; Set end of $region to end of block. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
306 (wisent-set-region (car $region) (1+ end)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
307 nil)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
308 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
309 ;;; Core parser engine |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
310 (defsubst wisent-production-bounds (stack i j) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
311 "Determine the start and end locations of a production value. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
312 Return a pair (START . END), where START is the first available start |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
313 location, and END the last available end location, in components |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
314 values of the rule currently reduced. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
315 Return nil when no component location is available. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
316 STACK is the parser stack. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
317 I and J are the indices in STACK of respectively the value of the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
318 first and last components of the current rule. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
319 This function is for internal use by semantic actions' generated |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
320 lambda-expression." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
321 (let ((f (cadr (aref stack i))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
322 (l (cddr (aref stack j)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
323 (while (/= i j) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
324 (cond |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
325 ((not f) (setq f (cadr (aref stack (setq i (+ i 2)))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
326 ((not l) (setq l (cddr (aref stack (setq j (- j 2)))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
327 ((setq i j)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
328 (and f l (cons f l)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
329 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
330 (defmacro wisent-parse-action (i al) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
331 "Return the next parser action. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
332 I is a token item number and AL is the list of (item . action) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
333 available at current state. The first element of AL contains the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
334 default action for this state." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
335 `(cdr (or (assq ,i ,al) (car ,al)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
336 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
337 (defsubst wisent-parse-start (start starts) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
338 "Return the first lexical token to shift for START symbol. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
339 STARTS is the table of allowed start symbols or nil if the LALR |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
340 automaton has only one entry point." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
341 (if (null starts) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
342 ;; Only one entry point, return the first lexical token |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
343 ;; available in input. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
344 (wisent-lexer) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
345 ;; Multiple start symbols defined, return the internal lexical |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
346 ;; token associated to START. By default START is the first |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
347 ;; nonterminal defined in STARTS. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
348 (let ((token (cdr (if start (assq start starts) (car starts))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
349 (if token |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
350 (list token (symbol-name token)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
351 (error "Invalid start symbol %s" start))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
352 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
353 (defun wisent-parse (automaton lexer &optional error start) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
354 "Parse input using the automaton specified in AUTOMATON. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
355 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
356 - AUTOMATON is an LALR(1) automaton generated by |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
357 `wisent-compile-grammar'. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
358 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
359 - LEXER is a function with no argument called by the parser to obtain |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
360 the next terminal (token) in input. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
361 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
362 - ERROR is an optional reporting function called when a parse error |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
363 occurs. It receives a message string to report. It defaults to the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
364 function `wisent-message'. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
365 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
366 - START specify the start symbol (nonterminal) used by the parser as |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
367 its goal. It defaults to the start symbol defined in the grammar |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
368 \(see also `wisent-compile-grammar')." |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
369 (run-hooks 'wisent-pre-parse-hook) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
370 (let* ((actions (aref automaton 0)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
371 (gotos (aref automaton 1)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
372 (starts (aref automaton 2)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
373 (stack (make-vector wisent-parse-max-stack-size nil)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
374 (sp 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
375 (wisent-loop t) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
376 (wisent-parse-error-function (or error 'wisent-message)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
377 (wisent-parse-lexer-function lexer) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
378 (wisent-recovering nil) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
379 (wisent-input (wisent-parse-start start starts)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
380 state tokid choices choice) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
381 (setq wisent-nerrs 0 ;; Reset parse error counter |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
382 wisent-lookahead nil) ;; and lookahead token |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
383 (aset stack 0 0) ;; Initial state |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
384 (while wisent-loop |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
385 (setq state (aref stack sp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
386 tokid (car wisent-input) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
387 wisent-loop (wisent-parse-action tokid (aref actions state))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
388 (cond |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
389 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
390 ;; Input successfully parsed |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
391 ;; ------------------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
392 ((eq wisent-loop wisent-accept-tag) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
393 (setq wisent-loop nil)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
394 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
395 ;; Syntax error in input |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
396 ;; --------------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
397 ((eq wisent-loop wisent-error-tag) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
398 ;; Report this error if not already recovering from an error. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
399 (setq choices (aref actions state)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
400 (or wisent-recovering |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
401 (wisent-error |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
402 (format "Syntax error, unexpected %s, expecting %s" |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
403 (wisent-token-to-string wisent-input) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
404 (mapconcat 'wisent-item-to-string |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
405 (delq wisent-error-term |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
406 (mapcar 'car (cdr choices))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
407 ", ")))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
408 ;; Increment the error counter |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
409 (setq wisent-nerrs (1+ wisent-nerrs)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
410 ;; If just tried and failed to reuse lookahead token after an |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
411 ;; error, discard it. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
412 (if (eq wisent-recovering wisent-parse-max-recover) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
413 (if (eq tokid wisent-eoi-term) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
414 (wisent-abort) ;; Terminate if at end of input. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
415 (wisent-message "Error recovery: skip %s" |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
416 (wisent-token-to-string wisent-input)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
417 (run-hook-with-args |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
418 'wisent-discarding-token-functions wisent-input) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
419 (setq wisent-input (wisent-lexer))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
420 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
421 ;; Else will try to reuse lookahead token after shifting the |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
422 ;; error token. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
423 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
424 ;; Each real token shifted decrements this. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
425 (setq wisent-recovering wisent-parse-max-recover) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
426 ;; Pop the value/state stack to see if an action associated |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
427 ;; to special terminal symbol 'error exists. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
428 (while (and (>= sp 0) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
429 (not (and (setq state (aref stack sp) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
430 choices (aref actions state) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
431 choice (assq wisent-error-term choices)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
432 (natnump (cdr choice))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
433 (setq sp (- sp 2))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
434 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
435 (if (not choice) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
436 ;; No 'error terminal was found. Just terminate. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
437 (wisent-abort) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
438 ;; Try to recover and continue parsing. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
439 ;; Shift the error terminal. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
440 (setq state (cdr choice) ; new state |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
441 sp (+ sp 2)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
442 (aset stack (1- sp) nil) ; push value |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
443 (aset stack sp state) ; push new state |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
444 ;; Adjust input to error recovery state. Unless 'error |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
445 ;; triggers a reduction, eat the input stream until an |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
446 ;; expected terminal symbol is found, or EOI is reached. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
447 (if (cdr (setq choices (aref actions state))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
448 (while (not (or (eq (car wisent-input) wisent-eoi-term) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
449 (assq (car wisent-input) choices))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
450 (wisent-message "Error recovery: skip %s" |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
451 (wisent-token-to-string wisent-input)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
452 (run-hook-with-args |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
453 'wisent-discarding-token-functions wisent-input) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
454 (setq wisent-input (wisent-lexer))))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
455 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
456 ;; Shift current token on top of the stack |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
457 ;; --------------------------------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
458 ((natnump wisent-loop) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
459 ;; Count tokens shifted since error; after |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
460 ;; `wisent-parse-max-recover', turn off error status. |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
461 (setq wisent-recovering (and (natnump wisent-recovering) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
462 (> wisent-recovering 1) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
463 (1- wisent-recovering))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
464 (setq sp (+ sp 2)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
465 (aset stack (1- sp) (cdr wisent-input)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
466 (aset stack sp wisent-loop) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
467 (setq wisent-input (wisent-lexer))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
468 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
469 ;; Reduce by rule (call semantic action) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
470 ;; ------------------------------------- |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
471 (t |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
472 (setq sp (funcall wisent-loop stack sp gotos)) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
473 (or wisent-input (setq wisent-input (wisent-lexer)))))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
474 (run-hooks 'wisent-post-parse-hook) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
475 (car (aref stack 1)))) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
476 |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
477 (provide 'semantic/wisent/wisent) |
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
478 |
105377 | 479 ;; arch-tag: c299c5a4-d96f-4f1c-8307-ef2af3c8bdcb |
104478
8b129ef893a2
lisp/cedet/semantic/wisent/comp.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
480 ;;; semantic/wisent/wisent.el ends here |