-
Notifications
You must be signed in to change notification settings - Fork 0
/
se_core.rb
executable file
·162 lines (138 loc) · 2.58 KB
/
se_core.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/env ruby
require 'singleton'
$typedef_group = 'cppUserTypedefs'
$struct_group = 'cppUserStructs'
$class_group = 'cppUserClasses'
$def_colors = {
"typedef" => "guifg=white gui=bold",
"class" => "guifg=white gui=bold",
"struct" => "guifg=white gui=bold"
}
#{{{
class Array
def each_group(num)
0.step(size-1, num) { |x| yield self[x, num] }
end
end
#}}}
#{{{
class Keywords
include Singleton
attr_reader :typdefs, :structs, :classes
def initialize
@typdefs = Array.new
@structs = Array.new
@classes = Array.new
end
def add_typedef(word)
@typdefs << word
end
def add_struct(word)
@structs << word
end
def add_class(word)
@classes << word
end
def typedefs?
@typdefs.empty?
end
def structs?
@structs.empty?
end
def classes?
@classes.empty?
end
end
#}}}
#{{{
class Highlighter
def initialize
@keeper = Keywords.instance
end
def write_syn
#print "to file"
if not @keeper.typedefs?
td = @keeper.typdefs
td.uniq!
td.compact!
td.each_group(5) { |words|
yield ":syn keyword #{$typedef_group} #{words.join(' ')}"
}
end
if not @keeper.structs?
st = @keeper.structs
st.uniq!
st.compact!
st.each_group(5) { |words|
yield ":syn keyword #{$struct_group} #{words.join(' ')}"
}
end
if not @keeper.classes?
cl = @keeper.classes
cl.uniq!
cl.compact!
cl.each_group(5) { |words|
yield ":syn keyword #{$class_group} #{words.join(' ')}"
}
end
end
def write_hi(hsh=$def_colors)
yield ''
yield ":hi cppUserTypedefs #{hsh['typedef']}"
yield ":hi cppUserStructs #{hsh['struct']}"
yield ":hi cppUserClasses #{hsh['class']}"
end
end
#}}}
#{{{
class FindKeywords
@@typedef = /^\s*typedef\s+.*/
@@class = /^\s*class\s*(\w*)\s*.*/
@@struct = /^\s*struct\s*(\w*)\s*.*/
def initialize
@keeper = Keywords.instance
end
#{{{
def parse(fname)
#p "parsing"
File.open(fname, File::RDONLY) { |file|
in_struct = false
matched_typedef = false
file.each { |line|
case line
when @@typedef
#p line
if line =~ /(struct|enum|union)/
in_struct = true
else
parse_typedef line
end
when @@class
@keeper.add_class $1
when @@struct
@keeper.add_struct $1
when in_struct
#p line
in_struct = line =~ /\}(.*);/
if not in_struct
$1.split(',').each { |type|
@keeper.add_typedef type
}
end
end
}
}
end
#}}}
def parse_typedef(tdstring)
#p tdstring
md = tdstring =~ /typedef\s*.*\s+(.+?);/
m = $1
if m
if not m =~ /[()*]/
@keeper.add_typedef m.strip
end
end
end
end
#}}}