starscope 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +7 -1
- data/Gemfile.lock +1 -1
- data/README.md +3 -3
- data/lib/starscope/datum.rb +8 -2
- data/lib/starscope/db.rb +5 -1
- data/lib/starscope/langs/go.rb +161 -0
- data/lib/starscope/version.rb +1 -1
- metadata +5 -4
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -10,9 +10,9 @@ Anyone who has done much programming in C (or C++) on a unix-based OS has come
|
|
10
10
|
across the fantastic Cscope tool [1]. Sadly, it only works for C (and sort of
|
11
11
|
works for C++).
|
12
12
|
|
13
|
-
StarScope is a similar tool for Ruby, with a design intended to make it
|
14
|
-
add support for other languages at some point within the same framework
|
15
|
-
the name StarScope, ie \*scope).
|
13
|
+
StarScope is a similar tool for Ruby and Go, with a design intended to make it
|
14
|
+
easy to add support for other languages at some point within the same framework
|
15
|
+
(thus the name StarScope, ie \*scope).
|
16
16
|
|
17
17
|
Install it as a gem:
|
18
18
|
```
|
data/lib/starscope/datum.rb
CHANGED
@@ -8,13 +8,19 @@ class StarScope::Datum
|
|
8
8
|
end
|
9
9
|
|
10
10
|
if args[:scope]
|
11
|
-
|
11
|
+
if args[:scope].empty?
|
12
|
+
args.delete(:scope)
|
13
|
+
else
|
14
|
+
args[:scope] = args[:scope].map {|x| x.to_sym}
|
15
|
+
end
|
12
16
|
end
|
13
17
|
|
14
18
|
args
|
15
19
|
end
|
16
20
|
|
17
21
|
def self.score_match(dat, fqn)
|
22
|
+
return 0 if not dat[:scope]
|
23
|
+
|
18
24
|
score = 0
|
19
25
|
|
20
26
|
i = -1
|
@@ -36,7 +42,7 @@ class StarScope::Datum
|
|
36
42
|
|
37
43
|
def self.to_s(key, dat)
|
38
44
|
str = ""
|
39
|
-
str << "#{dat[:scope].join " "} "
|
45
|
+
str << "#{dat[:scope].join " "} " if dat[:scope]
|
40
46
|
str << "#{key} -- #{location dat}"
|
41
47
|
str << " (#{dat[:line].strip})"
|
42
48
|
end
|
data/lib/starscope/db.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'starscope/langs/go'
|
1
2
|
require 'starscope/langs/ruby'
|
2
3
|
require 'starscope/datum'
|
3
4
|
require 'date'
|
@@ -5,7 +6,10 @@ require 'oj'
|
|
5
6
|
require 'zlib'
|
6
7
|
require 'ruby-progressbar'
|
7
8
|
|
8
|
-
LANGS = [
|
9
|
+
LANGS = [
|
10
|
+
StarScope::Lang::Go,
|
11
|
+
StarScope::Lang::Ruby
|
12
|
+
]
|
9
13
|
|
10
14
|
class StarScope::DB
|
11
15
|
|
@@ -0,0 +1,161 @@
|
|
1
|
+
module StarScope::Lang
|
2
|
+
module Go
|
3
|
+
FUNC_CALL = /([\w\.]+?)\(.*\)/
|
4
|
+
BUILTIN_FUNCS = ['new', 'make', 'len', 'close', 'copy', 'delete',
|
5
|
+
'int', 'int8', 'int16', 'int32', 'int64',
|
6
|
+
'uint', 'uint8', 'uint16', 'uint32', 'uint64',
|
7
|
+
'string', 'byte']
|
8
|
+
|
9
|
+
def self.match_file(name)
|
10
|
+
name =~ /.*\.go$/
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.extract(file)
|
14
|
+
stack = []
|
15
|
+
scope = []
|
16
|
+
str = File.readlines(file).each_with_index do |line, line_no|
|
17
|
+
# strip single-line comments like // foo
|
18
|
+
match = /(.*)\/\//.match(line)
|
19
|
+
if match
|
20
|
+
line = match[1]
|
21
|
+
end
|
22
|
+
# strip single-line comments like foo /* foo */ foo
|
23
|
+
match = /(.*?)\/\*.*\*\/(.*)/.match(line)
|
24
|
+
if match
|
25
|
+
line = match[1] + match[2]
|
26
|
+
end
|
27
|
+
# strip end-of-line comment starters like foo /* foo \n
|
28
|
+
match = /(.*?)\/\*/.match(line)
|
29
|
+
if match
|
30
|
+
line = match[1]
|
31
|
+
ends_with_comment = true
|
32
|
+
else
|
33
|
+
ends_with_comment = false
|
34
|
+
end
|
35
|
+
# if we're in a block comment, wait for it to end
|
36
|
+
if stack[-1] == :comment
|
37
|
+
match = /\*\/(.*)/.match(line)
|
38
|
+
if match
|
39
|
+
line = match[1]
|
40
|
+
stack.pop
|
41
|
+
else
|
42
|
+
next
|
43
|
+
end
|
44
|
+
end
|
45
|
+
# poor-man's parser
|
46
|
+
case stack[-1]
|
47
|
+
when :struct
|
48
|
+
case line
|
49
|
+
when /\s*(\w+)\s+\w+/
|
50
|
+
yield :defs, $1, line_no: line_no+1, scope: scope
|
51
|
+
when /}/
|
52
|
+
stack.pop
|
53
|
+
scope.pop
|
54
|
+
end
|
55
|
+
when :interface
|
56
|
+
case line
|
57
|
+
when /\s*(\w+)\(.*\)\s+/
|
58
|
+
yield :defs, $1, line_no: line_no+1, scope: scope
|
59
|
+
when /}/
|
60
|
+
stack.pop
|
61
|
+
scope.pop
|
62
|
+
end
|
63
|
+
when :def
|
64
|
+
case line
|
65
|
+
when /\s*(\w+)\s+/
|
66
|
+
yield :defs, $1, line_no: line_no+1, scope: scope
|
67
|
+
when /\)/
|
68
|
+
stack.pop
|
69
|
+
end
|
70
|
+
when :import
|
71
|
+
case line
|
72
|
+
when /"(.+)"/
|
73
|
+
name = $1.split('/')
|
74
|
+
yield :imports, name[-1], line_no: line_no+1, scope: name[0...-1]
|
75
|
+
when /\)/
|
76
|
+
stack.pop
|
77
|
+
end
|
78
|
+
else
|
79
|
+
if stack[-1] == :func and /^}/ =~ line
|
80
|
+
stack.pop
|
81
|
+
end
|
82
|
+
case line
|
83
|
+
when /^func\s+(\w+)\(/
|
84
|
+
yield :defs, $1, line_no: line_no+1, scope: scope
|
85
|
+
stack.push(:func)
|
86
|
+
when /^func\s+\(\w+\s+\*?(\w+)\)\s*(\w+)\(/
|
87
|
+
yield :defs, $2, line_no: line_no+1, scope: scope + [$1]
|
88
|
+
stack.push(:func)
|
89
|
+
when /^package\s+(\w+)/
|
90
|
+
yield :defs, $1, line_no: line_no+1, scope: scope
|
91
|
+
scope.push($1)
|
92
|
+
when /^type\s+(\w+)\s+struct\s*{/
|
93
|
+
yield :defs, $1, line_no: line_no+1, scope: scope
|
94
|
+
scope.push($1)
|
95
|
+
stack.push(:struct)
|
96
|
+
when /^type\s+(\w+)\s+interface\s*{/
|
97
|
+
yield :defs, $1, line_no: line_no+1, scope: scope
|
98
|
+
scope.push($1)
|
99
|
+
stack.push(:interface)
|
100
|
+
when /^type\s+(\w+)/
|
101
|
+
yield :defs, $1, line_no: line_no+1, scope: scope
|
102
|
+
when /^import\s+"(.+)"/
|
103
|
+
name = $1.split('/')
|
104
|
+
yield :imports, name[-1], line_no: line_no+1, scope: name[0...-1]
|
105
|
+
when /^import\s+\(/
|
106
|
+
stack.push(:import)
|
107
|
+
when /^var\s+\(/
|
108
|
+
stack.push(:def)
|
109
|
+
when /^var\s+(\w+)\s+\w+/
|
110
|
+
yield :defs, $1, line_no: line_no+1, scope: scope
|
111
|
+
when /^const\s+\(/
|
112
|
+
stack.push(:def)
|
113
|
+
when /^const\s+(\w+)\s+\w+/
|
114
|
+
yield :defs, $1, line_no: line_no+1, scope: scope
|
115
|
+
when /^\s+(.*?) :?= ((.*?)\(.*\))?/
|
116
|
+
$1.split(',').each do |var|
|
117
|
+
var = var.strip
|
118
|
+
name = var.split('.')
|
119
|
+
case name.length
|
120
|
+
when 1
|
121
|
+
yield :assigns, name[0], line_no: line_no+1, scope: scope
|
122
|
+
when 2
|
123
|
+
yield :assigns, name[1], line_no: line_no+1, scope: [name[0]]
|
124
|
+
end
|
125
|
+
end
|
126
|
+
if $2
|
127
|
+
match = FUNC_CALL.match($2)
|
128
|
+
if match
|
129
|
+
tmp = parse_call(match[1], line_no, scope)
|
130
|
+
yield tmp if tmp
|
131
|
+
end
|
132
|
+
end
|
133
|
+
when FUNC_CALL
|
134
|
+
tmp = parse_call($1, line_no, scope)
|
135
|
+
yield tmp if tmp
|
136
|
+
end
|
137
|
+
end
|
138
|
+
# if the line looks like "foo /* foo" then we enter the comment state
|
139
|
+
# after parsing the usable part of the line
|
140
|
+
if ends_with_comment
|
141
|
+
stack.push(:comment)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def self.parse_call(line, line_no, scope)
|
147
|
+
name = line.split('.').select {|chunk| not chunk.empty?}
|
148
|
+
case name.length
|
149
|
+
when 1
|
150
|
+
return nil if name[0] == 'func'
|
151
|
+
if BUILTIN_FUNCS.include?(name[0])
|
152
|
+
return :calls, name[0], line_no: line_no+1
|
153
|
+
else
|
154
|
+
return :calls, name[0], line_no: line_no+1, scope: scope
|
155
|
+
end
|
156
|
+
else
|
157
|
+
return :calls, name[-1], line_no: line_no+1, scope: name[0...-1]
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
data/lib/starscope/version.rb
CHANGED
metadata
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
name: starscope
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Evan Huus
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-08-
|
12
|
+
date: 2013-08-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
prerelease: false
|
@@ -142,6 +142,7 @@ files:
|
|
142
142
|
- lib/starscope.rb
|
143
143
|
- lib/starscope/datum.rb
|
144
144
|
- lib/starscope/db.rb
|
145
|
+
- lib/starscope/langs/go.rb
|
145
146
|
- lib/starscope/langs/ruby.rb
|
146
147
|
- lib/starscope/value.rb
|
147
148
|
- lib/starscope/version.rb
|
@@ -159,7 +160,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
159
160
|
- !ruby/object:Gem::Version
|
160
161
|
segments:
|
161
162
|
- 0
|
162
|
-
hash: -
|
163
|
+
hash: -2462571532840130105
|
163
164
|
version: '0'
|
164
165
|
none: false
|
165
166
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
@@ -168,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
169
|
- !ruby/object:Gem::Version
|
169
170
|
segments:
|
170
171
|
- 0
|
171
|
-
hash: -
|
172
|
+
hash: -2462571532840130105
|
172
173
|
version: '0'
|
173
174
|
none: false
|
174
175
|
requirements: []
|