]> code.delx.au - gnu-emacs-elpa/blob - packages/realgud/realgud/lang/ruby.el
aa1ffa47f4ebfd21a69f3e58a26efc9fb7325555
[gnu-emacs-elpa] / packages / realgud / realgud / lang / ruby.el
1 ;;; Copyright (C) 2010, 2014 Rocky Bernstein <rocky@gnu.org>
2 ;;; Common Ruby 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 (declare-function realgud-goto-line-for-pt 'realgud-track)
10
11 (defconst realgud-rails-backtrace-loc-pat
12 (make-realgud-loc-pat
13 :regexp "^\\([^:]+\\):\\([0-9]+\\)\\(?:[:]in `.*'\\)?"
14 :file-group 1
15 :line-group 2)
16 "A realgud-loc-pat struct that describes a Rails backtrace (or
17 traceback) line." )
18
19 ;; Regular expression that describes a Ruby YARV 1.9 syntax error line.
20 ;; SyntaxError: /tmp/columnize.rb:270: syntax error, unexpected $end, ...
21 (defconst realgud-ruby-YARV-syntax-error-pat
22 (make-realgud-loc-pat
23 :regexp "^SyntaxError: \\([^:]+\\):\\([0-9]+\\): syntax error"
24 :file-group 1
25 :line-group 2)
26 "A realgud-loc-pat struct that describes a Ruby YARV syntax error message")
27
28 (defconst realgud-ruby-backtrace-loc-pat
29 (make-realgud-loc-pat
30 :regexp "^[ \t]+from \\([^:]+\\):\\([0-9]+\\)\\(?: in `.*'\\)?"
31 :file-group 1
32 :line-group 2)
33 "A realgud-loc-pat struct that describes a Ruby backtrace (or
34 traceback) line." )
35
36 (defconst realgud-rubinius-backtrace-loc-pat
37 (make-realgud-loc-pat
38 :regexp "^\\(?:\e\\[0;3[1-4]m\\)?[ \t]+.* at \\([^:]+\\):\\([0-9]+\\)"
39 :file-group 1
40 :line-group 2)
41 "A realgud-loc-pat struct that describes a Rubinius backtrace (or
42 traceback) line." )
43
44 (defconst realgud-rubinius-Xagent-backtrace-loc-pat
45 (make-realgud-loc-pat
46 :regexp "^\\(?:\e\\[0;3[1-4]m\\)?0x[a-f0-9]\\{8\\}: .* in \\([^:]+\\):\\([0-9]+\\) ([+][0-9]+)"
47 :file-group 1
48 :line-group 2)
49 "A realgud-loc-pat struct that describes a Rubinius Xagent backtrace (or
50 traceback) line." )
51
52 (defconst realgud-ruby-dollar-bang-loc-pat
53 (make-realgud-loc-pat
54 :regexp "^[ \t]*[[]?\\(.+\\):\\([0-9]+\\):in `.*'"
55 :file-group 1
56 :line-group 2)
57 "A realgud-loc-pat that struct that describes a Ruby $! string."
58 )
59
60 ;; FIXME: there is probably a less redundant way to do the following
61 ;; FNS.
62 (defun realgud:rails-goto-backtrace-line (pt)
63 "Display the location mentioned by the Rails backtrace line
64 described by PT."
65 (interactive "d")
66 (realgud-goto-line-for-pt pt "rails-backtrace"))
67
68 (defun realgud:rubinius-goto-Xagent-backtrace-line (pt)
69 "Display the location mentioned by the Rubinius Xagent- backtrace line
70 described by PT."
71 (interactive "d")
72 (realgud-goto-line-for-pt pt "rubinius-backtrace-Xagent"))
73
74 (defun realgud:ruby-goto-backtrace-line (pt)
75 "Display the location mentioned by the Ruby backtrace line
76 described by PT."
77 (interactive "d")
78 (realgud-goto-line-for-pt pt "lang-backtrace"))
79
80 (defun realgud:ruby-goto-dollar-bang-line (pt)
81 "Display the location mentioned by the Ruby backtrace line
82 described by PT."
83 (interactive "d")
84 (realgud-goto-line-for-pt pt "dollar-bang-backtrace"))
85
86 (defun realgud:ruby-populate-command-keys (&optional map)
87 "Bind the debugger function key layout used by many debuggers.
88
89 \\{realgud-example-map-standard}"
90 (define-key map (kbd "C-c !l") 'realgud:goto-lang-backtrace-line)
91 (define-key map (kbd "C-c !!") 'realgud:ruby-goto-dollar-bang-line)
92 (define-key map (kbd "C-c !b") 'realgud:goto-debugger-backtrace-line)
93 (define-key map (kbd "C-c !r") 'realgud:rails-goto-backtrace-line)
94 )
95
96
97 ;; Some things common to all trepan debuggers (Rubinius and Ruby 1.9.2)
98 (defconst realgud:trepan-frame-start-regexp
99 "\\(?:^\\|\n\\)\\(-->\\| \\)")
100
101 (defconst realgud:trepan-frame-num-regexp
102 "#\\([0-9]+\\)")
103
104 (defconst realgud:trepan-frame-line-regexp
105 "[ \t\n]+at line \\([0-9]+\\)\\(?:\n\\|$\\)")
106
107
108 (provide-me "realgud-lang-")