Mercurial > emacs
annotate lisp/cedet/semantic/wisent.el @ 105340:118ad0cdd9a8
Doc/message fixes.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Thu, 01 Oct 2009 04:54:05 +0000 |
parents | 108a3a6d8be0 |
children | 7f4c7f5c0eba |
rev | line source |
---|---|
104479
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
1 ;;; semantic/wisent.el --- Wisent - Semantic gateway |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
2 |
105285 | 3 ;; Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 |
4 ;; Free Software Foundation, Inc. | |
104479
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
5 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
6 ;; Author: David Ponce <david@dponce.com> |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
7 ;; Maintainer: David Ponce <david@dponce.com> |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
8 ;; Created: 30 Aug 2001 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
9 ;; Keywords: syntax |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
10 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
11 ;; This file is part of GNU Emacs. |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
12 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
13 ;; GNU Emacs is free software: you can redistribute it and/or modify |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
14 ;; it under the terms of the GNU General Public License as published by |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
15 ;; the Free Software Foundation, either version 3 of the License, or |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
16 ;; (at your option) any later version. |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
17 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
18 ;; GNU Emacs is distributed in the hope that it will be useful, |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
21 ;; GNU General Public License for more details. |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
22 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
23 ;; You should have received a copy of the GNU General Public License |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
25 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
26 ;;; Commentary: |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
27 ;; |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
28 ;; Here are functions necessary to use the Wisent LALR parser from |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
29 ;; Semantic environment. |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
30 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
31 ;;; History: |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
32 ;; |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
33 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
34 ;;; Code: |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
35 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
36 (require 'semantic) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
37 (require 'semantic/wisent/wisent) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
38 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
39 ;;; Lexical analysis |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
40 ;; |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
41 (defvar wisent-lex-istream nil |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
42 "Input stream of `semantic-lex' syntactic tokens.") |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
43 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
44 (defvar wisent-lex-lookahead nil |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
45 "Extra lookahead token. |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
46 When non-nil it is directly returned by `wisent-lex-function'.") |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
47 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
48 ;; Maintain this alias for compatibility until all WY grammars have |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
49 ;; been translated again to Elisp code. |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
50 (semantic-alias-obsolete 'wisent-lex-make-token-table |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
51 'semantic-lex-make-type-table) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
52 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
53 (defmacro wisent-lex-eoi () |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
54 "Return an End-Of-Input lexical token. |
105340 | 55 The EOI token is like this: ($EOI \"\" POINT-MAX . POINT-MAX)." |
104479
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
56 `(cons ',wisent-eoi-term |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
57 (cons "" |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
58 (cons (point-max) (point-max))))) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
59 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
60 (defmacro define-wisent-lexer (name doc &rest body) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
61 "Create a new lexical analyzer with NAME. |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
62 DOC is a documentation string describing this analyzer. |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
63 When a token is available in `wisent-lex-istream', eval BODY forms |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
64 sequentially. BODY must return a lexical token for the LALR parser. |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
65 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
66 Each token in input was produced by `semantic-lex', it is a list: |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
67 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
68 (TOKSYM START . END) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
69 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
70 TOKSYM is a terminal symbol used in the grammar. |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
71 START and END mark boundary in the current buffer of that token's |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
72 value. |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
73 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
74 Returned tokens must have the form: |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
75 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
76 (TOKSYM VALUE START . END) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
77 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
78 where VALUE is the buffer substring between START and END positions." |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
79 `(defun |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
80 ,name () ,doc |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
81 (cond |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
82 (wisent-lex-lookahead |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
83 (prog1 wisent-lex-lookahead |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
84 (setq wisent-lex-lookahead nil))) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
85 (wisent-lex-istream |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
86 ,@body) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
87 ((wisent-lex-eoi))))) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
88 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
89 (define-wisent-lexer wisent-lex |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
90 "Return the next available lexical token in Wisent's form. |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
91 The variable `wisent-lex-istream' contains the list of lexical tokens |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
92 produced by `semantic-lex'. Pop the next token available and convert |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
93 it to a form suitable for the Wisent's parser." |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
94 (let* ((tk (car wisent-lex-istream))) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
95 ;; Eat input stream |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
96 (setq wisent-lex-istream (cdr wisent-lex-istream)) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
97 (cons (semantic-lex-token-class tk) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
98 (cons (semantic-lex-token-text tk) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
99 (semantic-lex-token-bounds tk))))) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
100 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
101 ;;; Syntax analysis |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
102 ;; |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
103 (defvar wisent-error-function nil |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
104 "Function used to report parse error. |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
105 By default use the function `wisent-message'.") |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
106 (make-variable-buffer-local 'wisent-error-function) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
107 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
108 (defvar wisent-lexer-function 'wisent-lex |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
109 "Function used to obtain the next lexical token in input. |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
110 Should be a lexical analyzer created with `define-wisent-lexer'.") |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
111 (make-variable-buffer-local 'wisent-lexer-function) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
112 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
113 ;; Tag production |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
114 ;; |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
115 (defsubst wisent-raw-tag (semantic-tag) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
116 "Return raw form of given Semantic tag SEMANTIC-TAG. |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
117 Should be used in semantic actions, in grammars, to build a Semantic |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
118 parse tree." |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
119 (nconc semantic-tag |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
120 (if (or $region |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
121 (setq $region (nthcdr 2 wisent-input))) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
122 (list (car $region) (cdr $region)) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
123 (list (point-max) (point-max))))) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
124 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
125 (defsubst wisent-cook-tag (raw-tag) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
126 "From raw form of Semantic tag RAW-TAG, return a list of cooked tags. |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
127 Should be used in semantic actions, in grammars, to build a Semantic |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
128 parse tree." |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
129 (let* ((cooked (semantic--tag-expand raw-tag)) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
130 (l cooked)) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
131 (while l |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
132 (semantic--tag-put-property (car l) 'reparse-symbol $nterm) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
133 (setq l (cdr l))) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
134 cooked)) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
135 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
136 ;; Unmatched syntax collector |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
137 ;; |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
138 (defun wisent-collect-unmatched-syntax (nomatch) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
139 "Add lexical token NOMATCH to the cache of unmatched tokens. |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
140 See also the variable `semantic-unmatched-syntax-cache'. |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
141 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
142 NOMATCH is in Wisent's form: (SYMBOL VALUE START . END) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
143 and will be collected in `semantic-lex' form: (SYMBOL START . END)." |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
144 (let ((region (cddr nomatch))) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
145 (and (number-or-marker-p (car region)) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
146 (number-or-marker-p (cdr region)) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
147 (setq semantic-unmatched-syntax-cache |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
148 (cons (cons (car nomatch) region) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
149 semantic-unmatched-syntax-cache))))) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
150 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
151 ;; Parser plug-ins |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
152 ;; |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
153 ;; The following functions permit to plug the Wisent LALR parser in |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
154 ;; Semantic toolkit. They use the standard API provided by Semantic |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
155 ;; to plug parsers in. |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
156 ;; |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
157 ;; Two plug-ins are available, BUT ONLY ONE MUST BE USED AT A TIME: |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
158 ;; |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
159 ;; - `wisent-parse-stream' designed to override the standard function |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
160 ;; `semantic-parse-stream'. |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
161 ;; |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
162 ;; - `wisent-parse-region' designed to override the standard function |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
163 ;; `semantic-parse-region'. |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
164 ;; |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
165 ;; Maybe the latter is faster because it eliminates a lot of function |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
166 ;; call. |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
167 ;; |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
168 (defun wisent-parse-stream (stream goal) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
169 "Parse STREAM using the Wisent LALR parser. |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
170 GOAL is a nonterminal symbol to start parsing at. |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
171 Return the list (STREAM SEMANTIC-STREAM) where STREAM are those |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
172 elements of STREAM that have not been used. SEMANTIC-STREAM is the |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
173 list of semantic tags found. |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
174 The LALR parser automaton must be available in buffer local variable |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
175 `semantic--parse-table'. |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
176 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
177 Must be installed by `semantic-install-function-overrides' to override |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
178 the standard function `semantic-parse-stream'." |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
179 (let (wisent-lex-istream wisent-lex-lookahead la-elt cache) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
180 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
181 ;; IMPLEMENTATION NOTES: |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
182 ;; `wisent-parse' returns a lookahead token when it stopped |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
183 ;; parsing before encountering the end of input. To re-enter the |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
184 ;; parser it is necessary to push back in the lexical input stream |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
185 ;; the last lookahead token issued. Because the format of |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
186 ;; lookahead tokens and tokens in STREAM can be different the |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
187 ;; lookahead token is put in the variable `wisent-lex-lookahead' |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
188 ;; before calling `wisent-parse'. Wisent's lexers always pop the |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
189 ;; next lexical token from that variable when non nil, then from |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
190 ;; the lexical input stream. |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
191 ;; |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
192 ;; The first element of STREAM is used to keep lookahead tokens |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
193 ;; across successive calls to `wisent-parse-stream'. In fact |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
194 ;; what is kept is a stack of lookaheads encountered so far. It |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
195 ;; is cleared when `wisent-parse' returns a valid semantic tag, |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
196 ;; or twice the same lookahead token! The latter indicates that |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
197 ;; there is a syntax error on that token. If so, tokens currently |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
198 ;; in the lookahead stack have not been used, and are moved into |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
199 ;; `semantic-unmatched-syntax-cache'. When the parser will be |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
200 ;; re-entered, a new lexical token will be read from STREAM. |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
201 ;; |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
202 ;; The first element of STREAM that contains the lookahead stack |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
203 ;; has this format (compatible with the format of `semantic-lex' |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
204 ;; tokens): |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
205 ;; |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
206 ;; (LOOKAHEAD-STACK START . END) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
207 ;; |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
208 ;; where LOOKAHEAD-STACK is a list of lookahead tokens. And |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
209 ;; START/END are the bounds of the lookahead at top of stack. |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
210 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
211 ;; Retrieve lookahead token from stack |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
212 (setq la-elt (car stream)) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
213 (if (consp (car la-elt)) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
214 ;; The first elt of STREAM contains a lookahead stack |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
215 (setq wisent-lex-lookahead (caar la-elt) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
216 stream (cdr stream)) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
217 (setq la-elt nil)) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
218 ;; Parse |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
219 (setq wisent-lex-istream stream |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
220 cache (semantic-safe "wisent-parse-stream: %s" |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
221 (condition-case error-to-filter |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
222 (wisent-parse semantic--parse-table |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
223 wisent-lexer-function |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
224 wisent-error-function |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
225 goal) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
226 (args-out-of-range |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
227 (if (and (not debug-on-error) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
228 (= wisent-parse-max-stack-size |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
229 (nth 2 error-to-filter))) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
230 (progn |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
231 (message "wisent-parse-stream: %s" |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
232 (error-message-string error-to-filter)) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
233 (message "wisent-parse-max-stack-size \ |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
234 might need to be increased")) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
235 (apply 'signal error-to-filter)))))) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
236 ;; Manage returned lookahead token |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
237 (if wisent-lookahead |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
238 (if (eq (caar la-elt) wisent-lookahead) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
239 ;; It is already at top of lookahead stack |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
240 (progn |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
241 (setq cache nil |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
242 la-elt (car la-elt)) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
243 (while la-elt |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
244 ;; Collect unmatched tokens from the stack |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
245 (run-hook-with-args |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
246 'wisent-discarding-token-functions (car la-elt)) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
247 (setq la-elt (cdr la-elt)))) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
248 ;; New lookahead token |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
249 (if (or (consp cache) ;; Clear the stack if parse succeeded |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
250 (null la-elt)) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
251 (setq la-elt (cons nil nil))) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
252 ;; Push it into the stack |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
253 (setcar la-elt (cons wisent-lookahead (car la-elt))) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
254 ;; Update START/END |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
255 (setcdr la-elt (cddr wisent-lookahead)) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
256 ;; Push (LOOKAHEAD-STACK START . END) in STREAM |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
257 (setq wisent-lex-istream (cons la-elt wisent-lex-istream)))) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
258 ;; Return (STREAM SEMANTIC-STREAM) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
259 (list wisent-lex-istream |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
260 (if (consp cache) cache '(nil)) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
261 ))) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
262 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
263 (defun wisent-parse-region (start end &optional goal depth returnonerror) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
264 "Parse the area between START and END using the Wisent LALR parser. |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
265 Return the list of semantic tags found. |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
266 Optional arguments GOAL is a nonterminal symbol to start parsing at, |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
267 DEPTH is the lexical depth to scan, and RETURNONERROR is a flag to |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
268 stop parsing on syntax error, when non-nil. |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
269 The LALR parser automaton must be available in buffer local variable |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
270 `semantic--parse-table'. |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
271 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
272 Must be installed by `semantic-install-function-overrides' to override |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
273 the standard function `semantic-parse-region'." |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
274 (if (or (< start (point-min)) (> end (point-max)) (< end start)) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
275 (error "Invalid bounds [%s %s] passed to `wisent-parse-region'" |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
276 start end)) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
277 (let* ((case-fold-search semantic-case-fold) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
278 (wisent-lex-istream (semantic-lex start end depth)) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
279 ptree tag cooked lstack wisent-lex-lookahead) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
280 ;; Loop while there are lexical tokens available |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
281 (while wisent-lex-istream |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
282 ;; Parse |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
283 (setq wisent-lex-lookahead (car lstack) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
284 tag (semantic-safe "wisent-parse-region: %s" |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
285 (wisent-parse semantic--parse-table |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
286 wisent-lexer-function |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
287 wisent-error-function |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
288 goal))) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
289 ;; Manage returned lookahead token |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
290 (if wisent-lookahead |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
291 (if (eq (car lstack) wisent-lookahead) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
292 ;; It is already at top of lookahead stack |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
293 (progn |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
294 (setq tag nil) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
295 (while lstack |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
296 ;; Collect unmatched tokens from lookahead stack |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
297 (run-hook-with-args |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
298 'wisent-discarding-token-functions (car lstack)) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
299 (setq lstack (cdr lstack)))) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
300 ;; Push new lookahead token into the stack |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
301 (setq lstack (cons wisent-lookahead lstack)))) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
302 ;; Manage the parser result |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
303 (cond |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
304 ;; Parse succeeded, cook result |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
305 ((consp tag) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
306 (setq lstack nil ;; Clear the lookahead stack |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
307 cooked (semantic--tag-expand tag) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
308 ptree (append cooked ptree)) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
309 (while cooked |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
310 (setq tag (car cooked) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
311 cooked (cdr cooked)) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
312 (or (semantic--tag-get-property tag 'reparse-symbol) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
313 (semantic--tag-put-property tag 'reparse-symbol goal))) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
314 ) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
315 ;; Return on error if requested |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
316 (returnonerror |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
317 (setq wisent-lex-istream nil) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
318 )) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
319 ;; Work in progress... |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
320 (if wisent-lex-istream |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
321 (and (eq semantic-working-type 'percent) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
322 (boundp 'semantic--progress-reporter) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
323 semantic--progress-reporter |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
324 (progress-reporter-update |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
325 semantic--progress-reporter |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
326 (/ (* 100 (semantic-lex-token-start |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
327 (car wisent-lex-istream))) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
328 (point-max)))))) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
329 ;; Return parse tree |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
330 (nreverse ptree))) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
331 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
332 ;;; Interfacing with edebug |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
333 ;; |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
334 (add-hook |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
335 'edebug-setup-hook |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
336 #'(lambda () |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
337 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
338 (def-edebug-spec define-wisent-lexer |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
339 (&define name stringp def-body) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
340 ) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
341 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
342 )) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
343 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
344 (provide 'semantic/wisent) |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
345 |
55deb3a40b66
lisp/cedet/semantic/wisent.el: New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff
changeset
|
346 ;;; semantic/wisent.el ends here |