luobo 0.0.1 → 0.0.2
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/README.rdoc +2 -0
- data/bin/tuzi +28 -2
- data/example/parser.lub +0 -0
- data/lib/luobo/base.rb +10 -5
- data/lib/luobo/driver.rb +9 -1
- data/lib/luobo/version.rb +1 -1
- data/luobo.gemspec +0 -0
- data/spec/parser_spec.rb +0 -0
- metadata +3 -3
data/README.rdoc
CHANGED
data/bin/tuzi
CHANGED
@@ -3,10 +3,36 @@
|
|
3
3
|
|
4
4
|
$: << 'lib'
|
5
5
|
|
6
|
+
require "optparse"
|
6
7
|
require "luobo"
|
7
8
|
|
8
|
-
|
9
|
+
options = Hash.new
|
10
|
+
|
11
|
+
OptionParser.new do |opt|
|
12
|
+
opt.banner = "Usage: tuzi [OPTIONS] filename"
|
13
|
+
opt.separator ""
|
14
|
+
opt.separator "Options"
|
15
|
+
|
16
|
+
opt.on("-d DRIVER","--driver DRIVER","specify a driver") do |driver|
|
17
|
+
options[:driver] = driver
|
18
|
+
end
|
19
|
+
|
20
|
+
options[:output] = STDOUT
|
21
|
+
opt.on("-o OUTPUT","--output OUTPUT","the output file or file handler") do |output|
|
22
|
+
options[:output] = output
|
23
|
+
end
|
24
|
+
|
25
|
+
opt.on("-h","--help","help") do
|
26
|
+
puts opt
|
27
|
+
exit
|
28
|
+
end
|
29
|
+
end.parse!
|
30
|
+
|
31
|
+
|
32
|
+
# ---------
|
9
33
|
file = ARGV[0]
|
10
34
|
out = STDOUT
|
11
35
|
|
12
|
-
Luobo::Base.new(
|
36
|
+
lb = Luobo::Base.new(ARGV[0], out)
|
37
|
+
lb.driver = options[:driver].new if options[:driver]
|
38
|
+
lb.process
|
data/example/parser.lub
CHANGED
File without changes
|
data/lib/luobo/base.rb
CHANGED
@@ -9,8 +9,13 @@ module Luobo
|
|
9
9
|
def initialize file, output
|
10
10
|
@source_file = file
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
if output.is_a?(IO)
|
13
|
+
@output = output
|
14
|
+
elsif output.is_a?(String)
|
15
|
+
@output_file = output
|
16
|
+
@output = File.open(output, "w")
|
17
|
+
end
|
18
|
+
|
14
19
|
# initialize:
|
15
20
|
@token_stack = Array.new
|
16
21
|
|
@@ -47,7 +52,7 @@ module Luobo
|
|
47
52
|
end
|
48
53
|
|
49
54
|
def dump contents
|
50
|
-
@output
|
55
|
+
@driver.dump(@output, contents)
|
51
56
|
end
|
52
57
|
|
53
58
|
# travel up through the token stack, close all token with
|
@@ -157,7 +162,7 @@ module Luobo
|
|
157
162
|
# ensure first line as driver definition
|
158
163
|
unless @driver
|
159
164
|
if matches = /^#{regex_proc_head}DRIVER#{regex_proc_end}(?<dname_>\w+)\s*$/.match(line)
|
160
|
-
@driver = Driver.create(matches["dname_"])
|
165
|
+
@driver = Driver.create(matches["dname_"])
|
161
166
|
self.dump(@driver.setup)
|
162
167
|
next
|
163
168
|
else
|
@@ -204,7 +209,7 @@ module Luobo
|
|
204
209
|
self.close_stack 0
|
205
210
|
|
206
211
|
self.dump(@driver.exit)
|
207
|
-
@output.close
|
212
|
+
@output.close if @output_file
|
208
213
|
self
|
209
214
|
end
|
210
215
|
end
|
data/lib/luobo/driver.rb
CHANGED
@@ -27,6 +27,10 @@ module Luobo
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
def dump output, contents
|
31
|
+
output.print contents if contents
|
32
|
+
end
|
33
|
+
|
30
34
|
def exit; end
|
31
35
|
def setup; end
|
32
36
|
|
@@ -35,7 +39,11 @@ module Luobo
|
|
35
39
|
end
|
36
40
|
|
37
41
|
def do__raw token
|
38
|
-
|
42
|
+
if token.line_code.size > 0
|
43
|
+
indent(token) + token.line_code.gsub(/^\s*/, "") + "\n"
|
44
|
+
else
|
45
|
+
""
|
46
|
+
end
|
39
47
|
end
|
40
48
|
|
41
49
|
def do__missing token
|
data/lib/luobo/version.rb
CHANGED
data/luobo.gemspec
CHANGED
File without changes
|
data/spec/parser_spec.rb
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: luobo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -91,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
91
|
version: '0'
|
92
92
|
requirements: []
|
93
93
|
rubyforge_project:
|
94
|
-
rubygems_version: 1.8.
|
94
|
+
rubygems_version: 1.8.25
|
95
95
|
signing_key:
|
96
96
|
specification_version: 3
|
97
97
|
summary: Easy to extend code generator
|