luobo 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +14 -0
- data/backup/spec/parser_spec.rb +0 -0
- data/examples/loop_example.rb +0 -0
- data/examples/lua_loop.lua +0 -0
- data/lib/luobo.rb +13 -0
- data/lib/luobo/token.rb +4 -0
- data/lib/luobo/version.rb +1 -1
- data/spec/block_spec.rb +0 -0
- data/spec/inline_spec.rb +46 -0
- data/spec/loop_spec.rb +0 -0
- data/spec/lua_loop_spec.rb +0 -0
- data/spec/token_spec.rb +0 -0
- metadata +5 -3
data/README.rdoc
CHANGED
@@ -29,6 +29,20 @@ Then you will get those in stdout:
|
|
29
29
|
|
30
30
|
-- Hello, world!
|
31
31
|
|
32
|
+
Inline processor like:
|
33
|
+
|
34
|
+
save to file ##FILE: name##
|
35
|
+
|
36
|
+
If you define
|
37
|
+
|
38
|
+
def do_file token
|
39
|
+
'<tt class="filename">' + token.line_code + '</tt>'
|
40
|
+
end
|
41
|
+
|
42
|
+
will become:
|
43
|
+
|
44
|
+
<tt class="filename">token.line_code</tt>
|
45
|
+
|
32
46
|
TODO:
|
33
47
|
|
34
48
|
- block inside comments
|
data/backup/spec/parser_spec.rb
CHANGED
File without changes
|
data/examples/loop_example.rb
CHANGED
File without changes
|
data/examples/lua_loop.lua
CHANGED
File without changes
|
data/lib/luobo.rb
CHANGED
@@ -72,6 +72,12 @@ class Luobo
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
+
# convert inline processor
|
76
|
+
def conv_inline p, a, ln, line
|
77
|
+
# indent_level, processor_name, line_code, block_open
|
78
|
+
convert Token.new(ln, line, 0, p, a, false)
|
79
|
+
end
|
80
|
+
|
75
81
|
# processor converters and dump callbacks
|
76
82
|
def do_setup; "" end # call before all tokens
|
77
83
|
def do_cleanup; "" end # call after all tokens
|
@@ -147,6 +153,13 @@ class Luobo
|
|
147
153
|
# this function invokes after a loop expansion or if the line
|
148
154
|
# is not in any examples and loop templates.
|
149
155
|
def process_line ln, line
|
156
|
+
# convert inline processor
|
157
|
+
while /\#\#(?<p_>[A-Z][_A-Z0-9]*)(:\s*(?<a_>.+))?\#\#/ =~ line
|
158
|
+
rst = conv_inline(p_, a_, ln, line)
|
159
|
+
raise "do not use '##.*##' inside your inline processor converting result" if rst =~ /\#\#[A-Z][_A-Z0-9]*(:\s*.+)?\#\#/
|
160
|
+
line.sub!(/\#\#[A-Z][_A-Z0-9]*(:\s*.+)?\#\#/, rst)
|
161
|
+
end
|
162
|
+
|
150
163
|
# create a token, with processor name
|
151
164
|
token = self.tokenize(ln, line)
|
152
165
|
# based on the the token indent level, close token stack if any
|
data/lib/luobo/token.rb
CHANGED
@@ -8,6 +8,10 @@ class Token
|
|
8
8
|
@blocks = Array.new if block_open
|
9
9
|
end
|
10
10
|
|
11
|
+
def indent
|
12
|
+
" " * indent_level
|
13
|
+
end
|
14
|
+
|
11
15
|
# add a line to current block args, separate each line with "\n"
|
12
16
|
def add_block_code line
|
13
17
|
raise "block not opened in line #{:ln}" unless block_open?
|
data/lib/luobo/version.rb
CHANGED
data/spec/block_spec.rb
CHANGED
File without changes
|
data/spec/inline_spec.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
class InlineLuobo < Luobo
|
4
|
+
attr_accessor :token_stack, :dumps
|
5
|
+
|
6
|
+
def dump contents;
|
7
|
+
# p contents
|
8
|
+
@dumps = Array.new unless @dumps
|
9
|
+
@dumps << contents
|
10
|
+
end
|
11
|
+
|
12
|
+
def last_dump; @dumps[-1] if @dumps end
|
13
|
+
|
14
|
+
def stack_size; @token_stack.size end
|
15
|
+
|
16
|
+
def do_mark token
|
17
|
+
"small mark"
|
18
|
+
end
|
19
|
+
|
20
|
+
def do_double token
|
21
|
+
rslt = token.line_code.to_i * 2
|
22
|
+
rslt.to_s
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe InlineLuobo do
|
27
|
+
|
28
|
+
context "convert inline content" do
|
29
|
+
subject {InlineLuobo.new('-', STDOUT).process_line(1, 'upcase name ##MARK##')}
|
30
|
+
|
31
|
+
its(:stack_size) { should eq(0) }
|
32
|
+
its(:last_dump) { should eq("upcase name small mark") }
|
33
|
+
end
|
34
|
+
|
35
|
+
context "process inline argument" do
|
36
|
+
subject {InlineLuobo.new('-', STDOUT).process_line(1, 'calculate ##DOUBLE: 4##')}
|
37
|
+
|
38
|
+
its(:last_dump) { should eq("calculate 8") }
|
39
|
+
end
|
40
|
+
|
41
|
+
context "process tow inline processor" do
|
42
|
+
subject {InlineLuobo.new('-', STDOUT).process_line(1, '##MARK## ##DOUBLE: 4##')}
|
43
|
+
|
44
|
+
its(:last_dump) { should eq("small mark 8") }
|
45
|
+
end
|
46
|
+
end
|
data/spec/loop_spec.rb
CHANGED
File without changes
|
data/spec/lua_loop_spec.rb
CHANGED
File without changes
|
data/spec/token_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.1.
|
4
|
+
version: 0.1.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-
|
12
|
+
date: 2013-04-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- luobo.gemspec
|
70
70
|
- spec/block_spec.rb
|
71
71
|
- spec/command_spec.rb
|
72
|
+
- spec/inline_spec.rb
|
72
73
|
- spec/loop_spec.rb
|
73
74
|
- spec/lua_loop_spec.rb
|
74
75
|
- spec/spec_helper.rb
|
@@ -101,13 +102,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
102
|
version: '0'
|
102
103
|
requirements: []
|
103
104
|
rubyforge_project:
|
104
|
-
rubygems_version: 1.8.
|
105
|
+
rubygems_version: 1.8.25
|
105
106
|
signing_key:
|
106
107
|
specification_version: 3
|
107
108
|
summary: Easy to extend macroes inside you soure code
|
108
109
|
test_files:
|
109
110
|
- spec/block_spec.rb
|
110
111
|
- spec/command_spec.rb
|
112
|
+
- spec/inline_spec.rb
|
111
113
|
- spec/loop_spec.rb
|
112
114
|
- spec/lua_loop_spec.rb
|
113
115
|
- spec/spec_helper.rb
|