depager 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +4 -0
- data/Manifest.txt +52 -0
- data/README.en +64 -0
- data/README.ja +128 -0
- data/bin/depager +47 -0
- data/data/depager/misc/depager-mode.el +209 -0
- data/data/depager/sample/extension/paction.dr +15 -0
- data/data/depager/sample/extension/pactiontest.dr +14 -0
- data/data/depager/sample/pl0d/pl0ds.dr +334 -0
- data/data/depager/sample/pl0d/pl0test.pl0 +34 -0
- data/data/depager/sample/sample_calc/calc.action.dr +33 -0
- data/data/depager/sample/sample_calc/calc.astdf.dr +54 -0
- data/data/depager/sample/sample_calc/calc.astl.action.dr +66 -0
- data/data/depager/sample/sample_calc/calc.astl.dr +55 -0
- data/data/depager/sample/sample_calc/calc.atree.dr +43 -0
- data/data/depager/sample/sample_calc/calc.cst.dr +45 -0
- data/data/depager/sample/sample_calc/calc.dr +43 -0
- data/data/depager/sample/sample_calc/calc.lex.dr +29 -0
- data/data/depager/sample/sample_calc/calc.nvaction.dr +33 -0
- data/data/depager/sample/sample_calc/calc_prec.nvaction.dr +31 -0
- data/data/depager/sample/slex_test/slextest1.dr +37 -0
- data/data/depager/sample/slex_test/slextest2.dr +33 -0
- data/lib/depager.rb +608 -0
- data/lib/depager/Rakefile +30 -0
- data/lib/depager/action.rb +47 -0
- data/lib/depager/ast_base.dr +232 -0
- data/lib/depager/ast_base.rb +1249 -0
- data/lib/depager/astdf.rb +10 -0
- data/lib/depager/astl.rb +14 -0
- data/lib/depager/atree.dr +55 -0
- data/lib/depager/atree.rb +336 -0
- data/lib/depager/cst.dr +182 -0
- data/lib/depager/cst.rb +625 -0
- data/lib/depager/lex.dr +76 -0
- data/lib/depager/lex.rb +306 -0
- data/lib/depager/lr.rb +604 -0
- data/lib/depager/nvaction.rb +21 -0
- data/lib/depager/parse_action.rb +24 -0
- data/lib/depager/parser.rb +248 -0
- data/lib/depager/psrtmpl.rb +33 -0
- data/lib/depager/slex.dr +161 -0
- data/lib/depager/slex.rb +646 -0
- data/lib/depager/srp.rb +50 -0
- data/lib/depager/template/astdf.erbs +57 -0
- data/lib/depager/template/astl.erbs +57 -0
- data/lib/depager/template/extension_lalr_master.erb +51 -0
- data/lib/depager/template/extension_lalr_slave.erb +107 -0
- data/lib/depager/template/simple.erb +21 -0
- data/lib/depager/template/single_lalr_parser.erb +97 -0
- data/lib/depager/utils.rb +355 -0
- data/lib/depager/version.rb +9 -0
- data/setup.rb +1585 -0
- metadata +103 -0
data/ChangeLog
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
ChangeLog
|
2
|
+
Manifest.txt
|
3
|
+
README.en
|
4
|
+
README.ja
|
5
|
+
bin/depager
|
6
|
+
data/depager/misc/depager-mode.el
|
7
|
+
data/depager/sample/extension/paction.dr
|
8
|
+
data/depager/sample/extension/pactiontest.dr
|
9
|
+
data/depager/sample/pl0d/pl0ds.dr
|
10
|
+
data/depager/sample/pl0d/pl0test.pl0
|
11
|
+
data/depager/sample/sample_calc/calc.action.dr
|
12
|
+
data/depager/sample/sample_calc/calc.astdf.dr
|
13
|
+
data/depager/sample/sample_calc/calc.astl.action.dr
|
14
|
+
data/depager/sample/sample_calc/calc.astl.dr
|
15
|
+
data/depager/sample/sample_calc/calc.atree.dr
|
16
|
+
data/depager/sample/sample_calc/calc.cst.dr
|
17
|
+
data/depager/sample/sample_calc/calc.dr
|
18
|
+
data/depager/sample/sample_calc/calc.lex.dr
|
19
|
+
data/depager/sample/sample_calc/calc.nvaction.dr
|
20
|
+
data/depager/sample/sample_calc/calc_prec.nvaction.dr
|
21
|
+
data/depager/sample/slex_test/slextest1.dr
|
22
|
+
data/depager/sample/slex_test/slextest2.dr
|
23
|
+
lib/depager.rb
|
24
|
+
lib/depager/Rakefile
|
25
|
+
lib/depager/action.rb
|
26
|
+
lib/depager/ast_base.dr
|
27
|
+
lib/depager/ast_base.rb
|
28
|
+
lib/depager/astdf.rb
|
29
|
+
lib/depager/astl.rb
|
30
|
+
lib/depager/atree.dr
|
31
|
+
lib/depager/atree.rb
|
32
|
+
lib/depager/cst.dr
|
33
|
+
lib/depager/cst.rb
|
34
|
+
lib/depager/lex.dr
|
35
|
+
lib/depager/lex.rb
|
36
|
+
lib/depager/lr.rb
|
37
|
+
lib/depager/nvaction.rb
|
38
|
+
lib/depager/parse_action.rb
|
39
|
+
lib/depager/parser.rb
|
40
|
+
lib/depager/psrtmpl.rb
|
41
|
+
lib/depager/slex.dr
|
42
|
+
lib/depager/slex.rb
|
43
|
+
lib/depager/srp.rb
|
44
|
+
lib/depager/template/astdf.erbs
|
45
|
+
lib/depager/template/astl.erbs
|
46
|
+
lib/depager/template/extension_lalr_master.erb
|
47
|
+
lib/depager/template/extension_lalr_slave.erb
|
48
|
+
lib/depager/template/simple.erb
|
49
|
+
lib/depager/template/single_lalr_parser.erb
|
50
|
+
lib/depager/utils.rb
|
51
|
+
lib/depager/version.rb
|
52
|
+
setup.rb
|
data/README.en
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
Depager README
|
2
|
+
==============
|
3
|
+
|
4
|
+
Depager is a self extensible parser generator.
|
5
|
+
|
6
|
+
|
7
|
+
Requirements
|
8
|
+
------------
|
9
|
+
|
10
|
+
* Ruby 1.8
|
11
|
+
|
12
|
+
|
13
|
+
Install(gem)
|
14
|
+
------------
|
15
|
+
|
16
|
+
$ sudo gem install depager
|
17
|
+
|
18
|
+
|
19
|
+
Install(tgz)
|
20
|
+
------------
|
21
|
+
|
22
|
+
De-compress archive and enter its top directory.
|
23
|
+
Then type:
|
24
|
+
|
25
|
+
($ su)
|
26
|
+
# ruby setup.rb
|
27
|
+
|
28
|
+
These simple step installs this program under the default
|
29
|
+
location of Ruby libraries. You can also install files into
|
30
|
+
your favorite directory by supplying setup.rb some options.
|
31
|
+
Try "ruby setup.rb --help".
|
32
|
+
|
33
|
+
|
34
|
+
Usage
|
35
|
+
-----
|
36
|
+
|
37
|
+
$ depager -o outputfile inputfile
|
38
|
+
|
39
|
+
ex.
|
40
|
+
|
41
|
+
$ depager -o calc.tab.rb calc.dr
|
42
|
+
|
43
|
+
Try -h option for more detail.
|
44
|
+
|
45
|
+
|
46
|
+
License
|
47
|
+
-------
|
48
|
+
|
49
|
+
GPL
|
50
|
+
|
51
|
+
Stuff
|
52
|
+
-----
|
53
|
+
|
54
|
+
Author:
|
55
|
+
maita and Nakai "Language" lab.
|
56
|
+
|
57
|
+
Supervisor:
|
58
|
+
Hisashi Nakai
|
59
|
+
|
60
|
+
Original(Depage) Author:
|
61
|
+
Chikara Satake
|
62
|
+
|
63
|
+
|
64
|
+
maita <maita@fujiyama.slis.tsukuba.ac.jp>
|
data/README.ja
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
Depager README
|
2
|
+
==============
|
3
|
+
|
4
|
+
Deager�ϼ��ʳ�ĥ��ǽ�ʹ�ʸ���ϴ������ϤǤ���
|
5
|
+
|
6
|
+
|
7
|
+
ɬ�״Ķ�
|
8
|
+
--------
|
9
|
+
|
10
|
+
* Ruby 1.8
|
11
|
+
|
12
|
+
|
13
|
+
���ȡ�����ˡ(gem)
|
14
|
+
---------------------
|
15
|
+
|
16
|
+
gem��depager�Ȥ��Υ����ƥ�˥��ȡ��뤹���硢
|
17
|
+
���ޥ�ɥ饤��ǰʲ��Τ褦���Ǥ�����Ǥ���������
|
18
|
+
|
19
|
+
# sudo gem install depager
|
20
|
+
|
21
|
+
|
22
|
+
���ȡ�����ˡ(tgz)
|
23
|
+
---------------------
|
24
|
+
|
25
|
+
tgz��depager�Ȥ��Υ����ƥ�˥��ȡ��뤹���硢
|
26
|
+
���ޥ�ɥ饤��ǰʲ��Τ褦���Ǥ�����Ǥ���������
|
27
|
+
UNIX �� OS �ǤϤ����餯 root ���¤�ɬ�פˤʤ�ޤ���
|
28
|
+
|
29
|
+
($ su)
|
30
|
+
# ruby setup.rb
|
31
|
+
|
32
|
+
�ĿͤΥۡ���ǥ��쥯�ȥ�ʲ��˥��ȡ��뤹���硢
|
33
|
+
���ޥ�ɥ饤��ǰʲ��Τ褦���Ǥ�����Ǥ���������
|
34
|
+
('home'����ʬ�Ϥ��ʤ��Υۡ���ǥ��쥯�ȥ�Ǥ�*�ʤ�*��
|
35
|
+
'home'�Ȥ���ʸ����Ǥ�)
|
36
|
+
|
37
|
+
# ruby setup.rb all --installdirs=home
|
38
|
+
|
39
|
+
�ĿͤΥۡ���ǥ��쥯�ȥ�ʲ��˥��ȡ��뤷����硢
|
40
|
+
�Ķ��ѿ�RUBYLIB�˥ǥ��쥯�ȥ���ɲä��Ƥ���������
|
41
|
+
(�����餯 $HOME/lib/ruby �Ǥ�)
|
42
|
+
|
43
|
+
$ RUBYLIB=$RUBYLIB:$HOME/lib/ruby
|
44
|
+
$ export RUBYLIB
|
45
|
+
|
46
|
+
���ȡ�������ѹ������ꤹ�뤳�Ȥ�Ǥ��ޤ���
|
47
|
+
���ξ��� ruby setup.rb --help ��¹Ԥ��ƤߤƤ���������
|
48
|
+
|
49
|
+
����˾ܤ���setup.rb�λȤ����ˤĤ��Ƥϡ�
|
50
|
+
setup.rb ( LoveRubyNet )
|
51
|
+
http://i.loveruby.net/ja/projects/setup/
|
52
|
+
�Ȥ��Ƥ���������
|
53
|
+
|
54
|
+
|
55
|
+
��ñ�ʻȤ���
|
56
|
+
------------
|
57
|
+
|
58
|
+
# depager -o ���ϥե����� ���ϥե�����
|
59
|
+
|
60
|
+
��.
|
61
|
+
|
62
|
+
# depager -o calc.tab.rb calc.dr
|
63
|
+
|
64
|
+
�ܤ����� -h ���ץ��������Ѥ���������
|
65
|
+
|
66
|
+
|
67
|
+
�ե����������
|
68
|
+
--------------
|
69
|
+
|
70
|
+
/bin
|
71
|
+
depager �¹���
|
72
|
+
/lib
|
73
|
+
depager.rb �����ϥᥤ��
|
74
|
+
/depager
|
75
|
+
Rakefile �ӥ����
|
76
|
+
action.rb ����������ĥ
|
77
|
+
ast_base.rb AST�ϳ�ĥ�δ��쥯�饹
|
78
|
+
astdf.rb ����ͥ��õ��AST��ĥ
|
79
|
+
astl.rb ��ͳõ��AST��ĥ
|
80
|
+
atree.rb ����ˤ���ڹ��۳�ĥ
|
81
|
+
cst.rb CST��ĥ
|
82
|
+
lex.rb ������ϳ�ĥ
|
83
|
+
lr.rb LRɽ������
|
84
|
+
nvaction.rb ̾���ե���������ĥ
|
85
|
+
parse_action.rb ��ñ�ʥ�������������
|
86
|
+
parser.rb �����饤�֥��
|
87
|
+
psrtmpl.rb �ǥ��졼���ο���
|
88
|
+
srp.rb �����å�ɽ���ǥ��졼��
|
89
|
+
slex.rb �����ջ�����ϳ�ĥ
|
90
|
+
/template
|
91
|
+
astdf.erbs astdf�ƥ�ץ졼��
|
92
|
+
astl.erbs astl�ƥ�ץ졼��
|
93
|
+
extension_lalr_master.erb
|
94
|
+
��ĥ�ޥ����ƥ�ץ졼��
|
95
|
+
extension_lalr_slave.erb
|
96
|
+
��ĥ���졼�֥ƥ�ץ졼��
|
97
|
+
simple.rb
|
98
|
+
����ץ�ƥ�ץ졼��
|
99
|
+
single_lalr_parser.erb
|
100
|
+
ɸ��LR�ѡ����ƥ�ץ졼��
|
101
|
+
/data
|
102
|
+
/depager
|
103
|
+
/misc
|
104
|
+
depager-mode.el Emacs��depager-mode
|
105
|
+
/sample
|
106
|
+
/samlpe_calc ���������������ץ�
|
107
|
+
/pl0d PL0���ץ
|
108
|
+
/slextest �����ջ�����ϳ�ĥ����ץ�
|
109
|
+
|
110
|
+
|
111
|
+
�饤����
|
112
|
+
----------
|
113
|
+
|
114
|
+
GPL�˽��ä����ۤ��ޤ���
|
115
|
+
|
116
|
+
|
117
|
+
����¾
|
118
|
+
------
|
119
|
+
|
120
|
+
Depager�������δ��ĤΤ�ȡ�maita��������
|
121
|
+
���漼�ˤ�äƳ�ȯ����ޤ�����
|
122
|
+
|
123
|
+
Depager�δ�Ȥʤä�Depage��Ʊ���漼�κ����ϻ�ˤ�ä�
|
124
|
+
��ȯ����ޤ�����
|
125
|
+
|
126
|
+
|
127
|
+
maita <maita@fujiyama.slis.tsukuba.ac.jp>
|
128
|
+
��渦�漼 http://nakai2.slis.tsukuba.ac.jp/hiki/
|
data/bin/depager
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
require 'depager'
|
3
|
+
require 'optparse'
|
4
|
+
|
5
|
+
include Depager
|
6
|
+
begin
|
7
|
+
$MP_DEBUG = nil
|
8
|
+
dp = nil
|
9
|
+
output_file_name = nil
|
10
|
+
ARGV.options do |opt|
|
11
|
+
opt.on('-g') { $MP_DEBUG=true }
|
12
|
+
opt.on('-o [file]') {|ofn| output_file_name = ofn }
|
13
|
+
opt.parse!
|
14
|
+
end
|
15
|
+
unless ARGV[0]
|
16
|
+
warn "#{File.basename $0}: no input file."; exit 1
|
17
|
+
end
|
18
|
+
|
19
|
+
lineno = 0
|
20
|
+
File.open(ARGV[0]) do |f|
|
21
|
+
begin
|
22
|
+
dp = DeclParser.new
|
23
|
+
res = dp.parse(f, ARGV[0])
|
24
|
+
if output_file_name
|
25
|
+
File.open(output_file_name, "w"){|o| o.write res }
|
26
|
+
else
|
27
|
+
print res
|
28
|
+
end
|
29
|
+
rescue Exception
|
30
|
+
lineno = dp.files.lineno rescue '?'
|
31
|
+
raise
|
32
|
+
end
|
33
|
+
end
|
34
|
+
rescue SystemExit
|
35
|
+
rescue Exception
|
36
|
+
warn "#{File.basename $0}: fatal error."
|
37
|
+
warn "| #{$!}"
|
38
|
+
warn "| - #{dp.files.path}:#{lineno}" if dp
|
39
|
+
$@[0].match(/^(.+):(\d+)(:.+)?$/)
|
40
|
+
warn "| ( #{File.basename $1}:#{$2} )"
|
41
|
+
if $MP_DEBUG
|
42
|
+
warn "#{File.basename $0}: #{$@.unshift($!).join("\n")}"
|
43
|
+
else
|
44
|
+
warn "Try -g option if you want to see more error info."
|
45
|
+
end
|
46
|
+
exit 1
|
47
|
+
end
|
@@ -0,0 +1,209 @@
|
|
1
|
+
;; depager-mode.el
|
2
|
+
;; original is racc-mode.el
|
3
|
+
;; modified for Depager by M
|
4
|
+
;;
|
5
|
+
;; write the following in your .emacs file
|
6
|
+
;; depager-mode
|
7
|
+
;; (autoload 'depager-mode "depager-mode" "alternate mode for editing depager files" t)
|
8
|
+
;; (setq auto-mode-alist (append '(("\\.dr$" . depager-mode)) auto-mode-alist))
|
9
|
+
;;
|
10
|
+
;; racc-mode.el
|
11
|
+
;;
|
12
|
+
;; Copyright (c) 2001 sheepman
|
13
|
+
;; All rights reserved.
|
14
|
+
;;
|
15
|
+
;; Redistribution and use in source and binary forms, with or without
|
16
|
+
;; modification, are permitted provided that the following conditions
|
17
|
+
;; are met:
|
18
|
+
;; 1. Redistributions of source code must retain the above copyright
|
19
|
+
;; notice, this list of conditions and the following disclaimer.
|
20
|
+
;; 2. Redistributions in binary form must reproduce the above copyright
|
21
|
+
;; notice, this list of conditions and the following disclaimer in the
|
22
|
+
;; documentation and/or other materials provided with the distribution.
|
23
|
+
;; 3. The name of the author may not be used to endorse or promote products
|
24
|
+
;; derived from this software without specific prior written permission.
|
25
|
+
;;
|
26
|
+
;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
27
|
+
;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
28
|
+
;; OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
29
|
+
;; IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
30
|
+
;; INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
31
|
+
;; NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
32
|
+
;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
33
|
+
;; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
34
|
+
;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
35
|
+
;; THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
36
|
+
;;
|
37
|
+
|
38
|
+
(require 'derived)
|
39
|
+
|
40
|
+
(define-derived-mode depager-mode ruby-mode "Depager"
|
41
|
+
"Major mode for Depager editing."
|
42
|
+
(interactive)
|
43
|
+
(setq indent-line-function 'depager-indent-line)
|
44
|
+
(define-key depager-mode-map "\t" 'depager-indent-command)
|
45
|
+
(define-key depager-mode-map "\C-j" 'depager-reindent-newline-and-indent)
|
46
|
+
(run-hooks 'depager-mode-hook))
|
47
|
+
|
48
|
+
(defun depager-indent-command ()
|
49
|
+
(interactive)
|
50
|
+
(depager-indent-line t))
|
51
|
+
|
52
|
+
(defun depager-reindent-newline-and-indent ()
|
53
|
+
(interactive)
|
54
|
+
(depager-indent-command)
|
55
|
+
(newline)
|
56
|
+
(depager-indent-command))
|
57
|
+
|
58
|
+
(defun depager-indent-line (&optional flag)
|
59
|
+
(if (or (string-match "^#begin-rule[ \t]*$" (current-line))
|
60
|
+
(string-match "^#end-rule[ \t]*$" (current-line)))
|
61
|
+
(depager-indent-to 0)
|
62
|
+
(if (point-in-rule)
|
63
|
+
(depager-indent-to (depager-calculate-indent))
|
64
|
+
(if (point-before-rule)
|
65
|
+
(depager-indent-to (depager-calculate-indent-before-rule))
|
66
|
+
(ruby-indent-line t)))))
|
67
|
+
|
68
|
+
(defun beginning-of-rule ()
|
69
|
+
(beginning-of-buffer)
|
70
|
+
(re-search-forward "^#begin-rule")
|
71
|
+
(beginning-of-line))
|
72
|
+
|
73
|
+
(defun end-of-rule ()
|
74
|
+
(beginning-of-buffer)
|
75
|
+
(re-search-forward "^#end-rule")
|
76
|
+
(end-of-line))
|
77
|
+
|
78
|
+
(defun point-in-rule ()
|
79
|
+
(save-excursion
|
80
|
+
(let (forward-begin-rule (re-search-forward-without-moving-point "^#begin-rule"))
|
81
|
+
(backward-end-rule (re-search-backward-without-moving-point "^#end-rule"))
|
82
|
+
(forward-end-rule (re-search-forward-without-moving-point "^#end-rule"))
|
83
|
+
(tmp (print "???")))
|
84
|
+
(or (and forward-begin-rule
|
85
|
+
backward-end-rule
|
86
|
+
forward-end-rule
|
87
|
+
(< forward-end-rule forward-begin-rule)
|
88
|
+
(< forward-begin-rule backward-end-rule))
|
89
|
+
(and backward-begin-rule
|
90
|
+
forward-end-rule
|
91
|
+
(< forward-begin-rule backward-end-rule)))))
|
92
|
+
|
93
|
+
(defun point-before-rule ()
|
94
|
+
(save-excursion
|
95
|
+
(and (not (point-in-rule))
|
96
|
+
(re-search-forward-without-moving-point "^#begin-rule"))))
|
97
|
+
|
98
|
+
(defun point-in-p ()
|
99
|
+
(save-excursion
|
100
|
+
(and (point-before-rule)
|
101
|
+
(re-search-forward-without-moving-point "^%}")
|
102
|
+
(re-search-backward-without-moving-point "^%\\(.*\\){")
|
103
|
+
)))
|
104
|
+
|
105
|
+
(defun point-in-s-p (s)
|
106
|
+
(save-excursion
|
107
|
+
(and (point-before-rule)
|
108
|
+
(re-search-forward-without-moving-point "^%}")
|
109
|
+
(re-search-backward-without-moving-point "^%\\(.*\\){")
|
110
|
+
(string-match s (match-string 1))
|
111
|
+
)))
|
112
|
+
|
113
|
+
(defun point-in-token-statement ()
|
114
|
+
(save-excursion
|
115
|
+
(defun match-token-line (str)
|
116
|
+
(or (string-match "^[ \t]*|[ \t]*"
|
117
|
+
str)
|
118
|
+
(string-match "[ \t]*:[ \t]*\\(#.*\\)?\n$"
|
119
|
+
str)
|
120
|
+
(string-match "^[ \t]*=>[ \t]*"
|
121
|
+
str)
|
122
|
+
(string-match "^[ \t]*<.*>[ \t]*\n$"
|
123
|
+
str)
|
124
|
+
(string-match "^[ \t]*;[ \t]*\n$"
|
125
|
+
str)))
|
126
|
+
(defun match-token-line2 ()
|
127
|
+
(save-excursion
|
128
|
+
(forward-line -1)
|
129
|
+
(while (string-match "^[ \t]*\n$" (current-line))
|
130
|
+
(forward-line -1))
|
131
|
+
(string-match "[ \t]*:[ \t]*\\(#.*\\)?$"
|
132
|
+
(current-line))))
|
133
|
+
(and (point-in-rule)
|
134
|
+
(or (match-token-line (current-line))
|
135
|
+
(match-token-line2)))))
|
136
|
+
|
137
|
+
(defun point-in-action-statement ()
|
138
|
+
(and (point-in-rule)
|
139
|
+
(not (point-in-token-statement))))
|
140
|
+
|
141
|
+
(defun beginning-of-action ()
|
142
|
+
(if (point-in-action-statement)
|
143
|
+
(re-search-backward "^[ \t]*{" nil t)
|
144
|
+
nil))
|
145
|
+
|
146
|
+
(defvar depager-indent-level 2)
|
147
|
+
(setq depager-token-length-max 0)
|
148
|
+
|
149
|
+
(defun depager-indent-to (x)
|
150
|
+
(ruby-indent-to x))
|
151
|
+
|
152
|
+
(defun depager-calculate-indent ()
|
153
|
+
(save-excursion
|
154
|
+
(if (point-in-token-statement)
|
155
|
+
(cond ((string-match "^[ \t]*|[ \t]*" (current-line))
|
156
|
+
(* 2 depager-indent-level))
|
157
|
+
((string-match "[ \t]*:[ \t]*\\(#.*\\)?$" (current-line))
|
158
|
+
depager-indent-level)
|
159
|
+
((string-match "^[ \t]*=>[ \t]*" (current-line))
|
160
|
+
(* 3 depager-indent-level))
|
161
|
+
((string-match "^[ \t]*<.*>[ \t]*$" (current-line))
|
162
|
+
(* 3 depager-indent-level))
|
163
|
+
((string-match "^[ \t]*;[ \t]*$" (current-line))
|
164
|
+
depager-indent-level)
|
165
|
+
(t (* 3 depager-indent-level)))
|
166
|
+
(if (string-match "^[ \t]*[{}][ \t]*#*[ \t]*$" (current-line))
|
167
|
+
(* 3 depager-indent-level)
|
168
|
+
(ruby-calculate-indent (max (save-excursion
|
169
|
+
(ruby-beginning-of-indent)
|
170
|
+
(point))
|
171
|
+
(save-excursion
|
172
|
+
(beginning-of-action)
|
173
|
+
(point))))))))
|
174
|
+
|
175
|
+
(defun depager-calculate-indent-before-rule ()
|
176
|
+
(cond ((or (string-match "^%.*{[ \t]*$" (current-line))
|
177
|
+
(string-match "^%}[ \t]*$" (current-line)))
|
178
|
+
0)
|
179
|
+
((point-in-p)
|
180
|
+
(ruby-calculate-indent (max (save-excursion
|
181
|
+
(ruby-beginning-of-indent)
|
182
|
+
(point))
|
183
|
+
(save-excursion
|
184
|
+
(re-search-backward "^%.*\\({\\)" nil t)
|
185
|
+
(match-beginning 1)))))
|
186
|
+
(t 0)))
|
187
|
+
|
188
|
+
;;;;;;;;;;;;;;;;;;;;;;;;;
|
189
|
+
;; general functions
|
190
|
+
;;;;;;;;;;;;;;;;;;;;;;;;
|
191
|
+
|
192
|
+
(defun current-line ()
|
193
|
+
(save-excursion
|
194
|
+
(buffer-substring (save-excursion (beginning-of-line)
|
195
|
+
(point))
|
196
|
+
(save-excursion (end-of-line)
|
197
|
+
(1+ (point))))))
|
198
|
+
(defun string-length (str)
|
199
|
+
(- (string-match "$" str) (string-match "^" str)))
|
200
|
+
|
201
|
+
(defun re-search-forward-without-moving-point (str)
|
202
|
+
(save-excursion
|
203
|
+
(re-search-forward str nil t)))
|
204
|
+
|
205
|
+
(defun re-search-backward-without-moving-point (str)
|
206
|
+
(save-excursion
|
207
|
+
(re-search-backward str nil t)))
|
208
|
+
|
209
|
+
(provide 'depager-mode)
|