]> code.delx.au - gnu-emacs-elpa/blob - packages/realgud/realgud/lang/posix-shell.el
a3fdc7e35d28e4e31c0bd2cf9e485c187f079e83
[gnu-emacs-elpa] / packages / realgud / realgud / lang / posix-shell.el
1 ;;; Copyright (C) 2010-2011, 2015 Rocky Bernstein <rocky@gnu.org>
2 ;;;
3 ;;; Common POSIX-Shell like constants and regular expressions.
4 ;;; Actually a lot of this is not about POSIX shell as it is about the
5 ;;; common-ness of bashdb, zshdb, and kshdb. But since those are the
6 ;;; *only* debuggers I know of for POSIX shells, it's not too much of
7 ;;; a stretch to think of this as for all "shell".
8 (eval-when-compile (require 'cl))
9
10 (require 'load-relative)
11 (require-relative-list '("../common/regexp" "../common/loc"
12 "../common/track" "../common/send")
13 "realgud-")
14
15 (defconst realgud-shell-backtrace-loc-pat
16 (make-realgud-loc-pat
17 :regexp "^[ \t]+from \\([^:]+\\):\\([0-9]+\\)\\(?: in `.*'\\)?"
18 :file-group 1
19 :line-group 2)
20 "A realgud-loc-pat struct that describes a Shell backtrace (or
21 traceback) line." )
22
23 (defconst realgud-shell-frame-start-regexp
24 "\\(?:^\\|\n\\)\\(->\\|##\\)")
25
26 (defconst realgud-shell-frame-num-regexp
27 "\\([0-9]+\\)")
28
29 (defconst realgud-shell-frame-file-regexp
30 "[ \t\n]+\\(?:in\\|from\\) file `\\(.+\\)'")
31
32 (defconst realgud-shell-frame-line-regexp
33 "[ \t\n]+at line \\([0-9]+\\)\\(?:\n\\|$\\)")
34
35 (defun realgud-posix-shell-populate-command-keys (&optional map)
36 "Bind the debugger function key layout used by many debuggers.
37
38 \\{realgud-example-map-standard}"
39 (define-key map (kbd "C-c !b") 'realgud:goto-debugger-backtrace-line)
40 (define-key map (kbd "C-c !!") 'realgud:goto-lang-backtrace-line)
41 )
42
43
44 ;; Patterns common to the my POSIX shell debuggers
45
46 (defconst realgud:python-trepan-frame-start-regexp
47 "\\(?:^\\|\n\\)\\(->\\|##\\)")
48
49 (defconst realgud:python-trepan-frame-num-regexp
50 "\\([0-9]+\\)")
51
52 ;; Regular expression that describes a bashdb/zshdb location generally shown
53 ;; before a command prompt.
54 ;; For example:
55 ;; (/etc/init.d/apparmor:35):
56 (defconst realgud:POSIX-debugger-loc-pat
57 (make-realgud-loc-pat
58 :regexp "\\(?:^\\|\n\\)(\\([^:]+\\):\\([0-9]*\\)):\\(?:\n\\(.+\\)\\)?"
59 :file-group 1
60 :line-group 2
61 :text-group 3)
62 "A realgud-loc-pat struct that describes a POSIX shell debugger
63 location line.")
64
65 ;; Regular expression that describes a debugger "backtrace" command line.
66 ;; For example:
67 ;; ->0 in file `/etc/apparmor/fns' at line 24
68 ;; ##1 /etc/apparmor/fns called from file `/etc/init.d/apparmor' at line 35
69 ;; ##2 /etc/init.d/apparmor called from file `/usr/bin/zshdb' at line 129
70 (defconst realgud:POSIX-debugger-backtrace-pat
71 (make-realgud-loc-pat
72 :regexp (concat realgud-shell-frame-start-regexp
73 realgud-shell-frame-num-regexp "[ ]?"
74 "\\(.*\\)"
75 realgud-shell-frame-file-regexp
76 "\\(?:" realgud-shell-frame-line-regexp "\\)?"
77 )
78 :num 2
79 :file-group 4
80 :line-group 5)
81 "A realgud-loc-pat struct that describes a Python trepan
82 backtrace location line." )
83
84 ;; Regular expression that describes a "breakpoint set" line
85 (defconst realgud:POSIX-debugger-brkpt-set-pat
86 (make-realgud-loc-pat
87 :regexp "^Breakpoint \\([0-9]+\\) set in file \\(.+\\), line \\([0-9]+\\).\n"
88 :num 1
89 :file-group 2
90 :line-group 3))
91
92 ;; Regular expression that describes a debugger "delete" (breakpoint) response.
93 ;; For example:
94 ;; Removed 1 breakpoint(s).
95 (defconst realgud:POSIX-debugger-brkpt-del-pat
96 (make-realgud-loc-pat
97 :regexp "^Removed \\([0-9]+\\) breakpoint(s).\n"
98 :num 1))
99
100 (defconst realgud:POSIX-debugger-font-lock-keywords
101 '(
102 ;; The frame number and first type name, if present.
103 ;; E.g. ->0 in file `/etc/init.d/apparmor' at line 35
104 ;; --^-
105 ("^\\(->\\|##\\)\\([0-9]+\\) "
106 (2 realgud-backtrace-number-face))
107
108 ;; File name.
109 ;; E.g. ->0 in file `/etc/init.d/apparmor' at line 35
110 ;; ---------^^^^^^^^^^^^^^^^^^^^-
111 ("[ \t]+\\(in\\|from\\) file `\\(.+\\)'"
112 (2 realgud-file-name-face))
113
114 ;; File name.
115 ;; E.g. ->0 in file `/etc/init.d/apparmor' at line 35
116 ;; --------^^
117 ;; Line number.
118 ("[ \t]+at line \\([0-9]+\\)$"
119 (1 realgud-line-number-face))
120 ;; (trepan-frames-match-current-line
121 ;; (0 trepan-frames-current-frame-face append))
122 ))
123
124 (provide-me "realgud-lang-")