Initial Commit
[packages] / xemacs-packages / semantic / bovine / bovine-debug.el
1 ;;; bovine-debug.el --- Debugger support for bovinator
2
3 ;;; Copyright (C) 2003 Eric M. Ludlam
4
5 ;; Author: Eric M. Ludlam <zappo@gnu.org>
6 ;; X-RCS: $Id: bovine-debug.el,v 1.1 2007-11-26 15:11:49 michaels Exp $
7
8 ;; This file is not part of GNU Emacs.
9
10 ;; This is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; This software is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
24 ;; 
25 ;;; Commentary:
26 ;;
27 ;; Implementation of the semantic debug support framework for the
28 ;; bovine parser.
29 ;;
30
31 (require 'semantic-debug)
32
33 ;;; Code:
34
35 ;;; Support a frame for the Bovinator
36 ;;
37 (defclass semantic-bovine-debug-frame (semantic-debug-frame)
38   ((nonterm :initarg :nonterm
39             :type symbol
40             :documentation
41             "The name of the semantic nonterminal for this frame.")
42    (rule :initarg :rule
43          :type number
44          :documentation
45          "The index into NONTERM's rule list.  0 based.")
46    (match :initarg :match
47           :type number
48           :documentation
49           "The index into NONTERM's RULE's match.  0 based..")
50    (collection :initarg :collection
51                :type list
52                :documentation
53                "List of things matched so far.")
54    (lextoken :initarg :lextoken
55              :type list
56              :documentation
57              "A Token created by `semantic-lex-token'.
58 This is the lexical token being matched by the parser.")
59    )
60   "Debugger frame representation for the bovinator.")
61
62 ;;;###autoload
63 (defun semantic-bovine-debug-create-frame (nonterm rule match collection
64                                                    lextoken)
65   "Create one bovine frame.
66 NONTERM is the name of a rule we are currently parsing.
67 RULE is the index into the list of rules in NONTERM.
68 MATCH is the index into the list of matches in RULE.
69 For example:
70   this: that
71       | other thing
72       | here
73       ;
74 The NONTERM is THIS.
75 The RULE is for \"thing\" is 1.
76 The MATCH for \"thing\" is 1.
77 COLLECTION is a list of `things' that have been matched so far.
78 LEXTOKEN, is a token returned by the lexer which is being matched."
79   (let ((frame (semantic-bovine-debug-frame "frame"
80                                             :nonterm nonterm
81                                             :rule rule
82                                             :match match
83                                             :collection collection
84                                             :lextoken lextoken)))
85     (semantic-debug-set-frame semantic-debug-current-interface
86                               frame)
87     frame))
88
89 (defmethod semantic-debug-frame-highlight ((frame semantic-debug-frame))
90   "Highlight one parser frame."
91   (let* ((nonterm (oref frame nonterm))
92          (pb (oref semantic-debug-current-interface parser-buffer))
93          (start (semantic-find-nonterminal-by-token 'start pb))
94         )
95     ;; Make sure we get a good rule name, and that it is a string
96     (if (and (eq nonterm 'bovine-toplevel) start)
97         (setq nonterm (semantic-tag-name (car start)))
98       (setq nonterm (symbol-name nonterm)))
99
100     (semantic-debug-highlight-rule semantic-debug-current-interface
101                                    nonterm
102                                    (oref frame rule)
103                                    (oref frame match))
104     (semantic-debug-highlight-lexical-token semantic-debug-current-interface
105                                             (oref frame lextoken))
106     ))
107
108 (defmethod semantic-debug-frame-info ((frame semantic-debug-frame))
109   "Display info about this one parser frame."
110   (message "%S" (oref frame collection))
111   )
112
113 ;;; Lisp error thrown frame.
114 ;;
115 (defclass semantic-bovine-debug-error-frame (semantic-debug-frame)
116   ((condition :initarg :condition
117               :documentation
118               "An error condition caught in an action.")
119    )
120   "Debugger frame representaion of a lisp error thrown during parsing.")
121
122 (defun semantic-create-bovine-debug-error-frame (condition)
123   "Create an error frame for bovine debugger.
124 Argument CONDITION is the thrown error condition."
125   (let ((frame (semantic-bovine-debug-error-frame "frame"
126                                                   :condition condition)))
127     (semantic-debug-set-frame semantic-debug-current-interface
128                               frame)
129     frame))
130
131 (defmethod semantic-debug-frame-highlight ((frame semantic-bovine-debug-error-frame))
132   "Highlight a frame from an action."
133   ;; How do I get the location of the action in the source buffer?
134   )
135
136 (defmethod semantic-debug-frame-info ((frame semantic-bovine-debug-error-frame))
137   "Display info about the error thrown."
138   (message "Error: %S" (oref frame condition)))
139
140 ;;; Parser support for the debugger
141 ;;
142 ;;;###autoload 
143 (defclass semantic-bovine-debug-parser (semantic-debug-parser)
144   (
145    )
146   "Represents a parser and its state.")
147
148
149 (provide 'bovine-debug)
150
151 ;;; bovine-debug.el ends here