]> code.delx.au - gnu-emacs-elpa/blob - packages/realgud/realgud/lang/python.el
d94fb35427686d8378fafd19fcef9378437fcd54
[gnu-emacs-elpa] / packages / realgud / realgud / lang / python.el
1 ;;; Copyright (C) 2011, 2014-2015 Rocky Bernstein <rocky@gnu.org>
2 ;;; Common Python constants and regular expressions.
3 (eval-when-compile (require 'cl))
4
5 (require 'load-relative)
6 (require-relative-list '("../common/regexp" "../common/loc" "../common/track")
7 "realgud-")
8
9 (defconst realgud-python-backtrace-loc-pat
10 (make-realgud-loc-pat
11 :regexp "^[ \t]+File \"\\(.+\\)\", line \\([0-9]+\\)"
12 :file-group 1
13 :line-group 2)
14 "A realgud-loc-pat struct that describes a Python backtrace (or
15 traceback) line." )
16
17 ;; Regular expression that pseudo-files in caller. For example:
18 ;; <string>
19 (defconst realgud-python-ignore-file-re "<string>"
20 "Regular expression that pseudo-files of caller()")
21
22 (defun realgud-python-populate-command-keys (&optional map)
23 "Bind the debugger function key layout used by many debuggers.
24
25 \\{realgud-example-map-standard}"
26 (define-key map (kbd "C-c !b") 'realgud:goto-debugger-backtrace-line)
27 (define-key map (kbd "C-c !!") 'realgud:goto-lang-backtrace-line)
28 )
29
30
31 ;; Things common to the trepan Python debuggers
32
33 (defconst realgud:python-trepan-frame-start-regexp
34 "\\(?:^\\|\n\\)\\(->\\|##\\)")
35
36 (defconst realgud:python-trepan-frame-num-regexp
37 "\\([0-9]+\\)")
38
39 ;; Regular expression that describes a trepan2/3k location generally shown
40 ;; before a command prompt.
41 ;;
42 ;; For example:
43 ;; (/usr/bin/zonetab2pot.py:15): <module>
44 ;; (/usr/bin/zonetab2pot.py:15 remapped <string>): <module>
45 ;; or MS Windows:
46 ;; (c:\\mydirectory\\gcd.py:10): <module>
47
48 (defconst realgud:python-trepan-loc-pat
49 (make-realgud-loc-pat
50 :regexp "^(\\(\\(?:[a-zA-Z]:\\)?[-a-zA-Z0-9_/.\\\\ ]+\\):\\([0-9]+\\)\\(?: remapped .*?\\)?): \\(?:<module>\\)?\\(?:\n.. [0-9]+ \\(.*?\\)\n\\)?"
51 :file-group 1
52 :line-group 2
53 :text-group 3
54 :ignore-file-re realgud-python-ignore-file-re)
55 "A realgud-loc-pat struct that describes a Python trepan
56 location line." )
57
58 ;; Regular expression that describes a trepan2/3k backtrace line.
59 ;; For example:
60 ;; ->0 get_distribution(dist='trepan==0.3.9')
61 ;; called from file '/python2.7/dist-packages/pkg_res.py' at line 341
62 ;; ##1 load_entry_point(dist='tr=0.3.9', group='console_scripts', name='tr')
63 ;; called from file '/python2.7/dist-packages/pkg_res.py' at line 351
64 ;; ##2 <module> exec()
65
66 (defconst realgud:python-trepan-backtrace-pat
67 (make-realgud-loc-pat
68 :regexp (concat
69 realgud:python-trepan-frame-start-regexp
70 realgud:python-trepan-frame-num-regexp "[ ]"
71 "\\(?:.*?)\\)\\(?:[\n\t ]+?\\)"
72 "\\(?:called from file \\)?'\\([^:]+?\\)' at line \\([0-9]+\\)")
73 :num 2
74 :file-group 3
75 :line-group 4
76 :ignore-file-re realgud-python-ignore-file-re)
77 "A realgud-loc-pat struct that describes a Python trepan
78 backtrace location line." )
79
80 ;; Regular expression that describes a "breakpoint set" line
81 (defconst realgud:python-trepan-brkpt-set-pat
82 (make-realgud-loc-pat
83 :regexp "^Breakpoint \\([0-9]+\\) set at line \\([0-9]+\\)[ \t\n]+of file \\(.+\\)\\(\n\\|$\\)"
84 :num 1
85 :file-group 3
86 :line-group 2))
87
88 ;; Regular expression that describes a debugger "delete" (breakpoint) response.
89 (defconst realgud:python-trepan-brkpt-del-pat
90 (make-realgud-loc-pat
91 :regexp "^Deleted breakpoint \\([0-9]+\\)\n"
92 :num 1))
93
94 (defconst realgud:python-debugger-font-lock-keywords
95 '(
96 ;; The frame number and first type name, if present.
97 ("^\\(->\\|##\\)\\([0-9]+\\) \\(<module>\\)? *\\([a-zA-Z_][a-zA-Z0-9_]*\\)(\\(.+\\))?"
98 (2 realgud-backtrace-number-face)
99 (4 font-lock-function-name-face nil t)) ; t means optional.
100
101 ;; Parameter sequence, E.g. gcd(a=3, b=5)
102 ;; ^^^^^^^^^
103 ("(\\(.+\\))"
104 (1 font-lock-variable-name-face))
105
106 ;; File name. E.g file '/test/gcd.py'
107 ;; ------^^^^^^^^^^^^-
108 ("[ \t]+file '\\([^ ]+*\\)'"
109 (1 realgud-file-name-face))
110
111 ;; Line number. E.g. at line 28
112 ;; ---------^^
113 ("[ \t]+at line \\([0-9]+\\)$"
114 (1 realgud-line-number-face))
115
116 ;; Function name.
117 ("\\<\\([a-zA-Z_][a-zA-Z0-9_]*\\)\\.\\([a-zA-Z_][a-zA-Z0-9_]*\\)"
118 (1 font-lock-type-face)
119 (2 font-lock-function-name-face))
120 ;; (trepan2-frames-match-current-line
121 ;; (0 trepan2-frames-current-frame-face append))
122 ))
123
124
125
126 (provide-me "realgud-lang-")