noratext 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/noratext.rb +1 -0
- data/lib/noratext/lexer.rb +1 -2
- data/lib/noratext/parser.rb +2 -1
- data/lib/noratext/processor.rb +19 -0
- data/noratext.gemspec +3 -2
- data/spec/noratext_lexer_spec.rb +4 -4
- data/spec/noratext_parser_spec.rb +3 -3
- metadata +5 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.1
|
data/lib/noratext.rb
CHANGED
data/lib/noratext/lexer.rb
CHANGED
@@ -11,7 +11,7 @@ module Noratext
|
|
11
11
|
lexer.instance_eval(&block) # for check only
|
12
12
|
end
|
13
13
|
|
14
|
-
def self.
|
14
|
+
def self.generate(name)
|
15
15
|
lexer = @instances_block[name][:lexer_class].new
|
16
16
|
lexer.instance_eval(&@instances_block[name][:block])
|
17
17
|
lexer
|
@@ -20,7 +20,6 @@ module Noratext
|
|
20
20
|
def initialize
|
21
21
|
@tags = {}
|
22
22
|
end
|
23
|
-
|
24
23
|
def process(io)
|
25
24
|
result = []
|
26
25
|
while line = io.gets
|
data/lib/noratext/parser.rb
CHANGED
@@ -7,7 +7,7 @@ module Noratext
|
|
7
7
|
parser.instance_eval(&block) # for check only
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.
|
10
|
+
def self.generate(name)
|
11
11
|
parser = Parser.new
|
12
12
|
parser.instance_eval(&@instances_block[name])
|
13
13
|
parser
|
@@ -28,6 +28,7 @@ module Noratext
|
|
28
28
|
def parse(sequence)
|
29
29
|
result = @start_element.process(sequence)
|
30
30
|
logger sequence[0][:line], "unexpected #{sequence[0][:data]}" if (sequence.size > 0)
|
31
|
+
result.set_attributes({ :log => log })
|
31
32
|
result
|
32
33
|
end
|
33
34
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Noratext
|
2
|
+
class Processor
|
3
|
+
def element(name, &block)
|
4
|
+
@processor[name] = block
|
5
|
+
end
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@processors = {}
|
9
|
+
@stack = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def process(parsedData)
|
13
|
+
@stack.push(parsedData)
|
14
|
+
@processors[parsedData.type].call(parsedData)
|
15
|
+
@stack.pop
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
data/noratext.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{noratext}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["KOJIMA Satoshi"]
|
12
|
-
s.date = %q{2010-07-
|
12
|
+
s.date = %q{2010-07-14}
|
13
13
|
s.description = %q{noratext is a simple (and rather stupid) lexer and parser generator for loosly markuped text. }
|
14
14
|
s.email = %q{skoji@mac.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
|
|
27
27
|
"lib/noratext/lexer.rb",
|
28
28
|
"lib/noratext/parser.rb",
|
29
29
|
"lib/noratext/parser_element.rb",
|
30
|
+
"lib/noratext/processor.rb",
|
30
31
|
"lib/noratext/xmly_lexer.rb",
|
31
32
|
"noratext.gemspec",
|
32
33
|
"spec/noratext_lexer_spec.rb",
|
data/spec/noratext_lexer_spec.rb
CHANGED
@@ -28,7 +28,7 @@ describe "Noratext::Lexer" do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should parse tag correctly" do
|
31
|
-
lexer = Noratext::Lexer
|
31
|
+
lexer = Noratext::Lexer.generate(:test)
|
32
32
|
opentag = lexer.factory('<center>')
|
33
33
|
closetag = lexer.factory('</center>')
|
34
34
|
|
@@ -40,7 +40,7 @@ describe "Noratext::Lexer" do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should create parse path" do
|
43
|
-
lexer = Noratext::Lexer
|
43
|
+
lexer = Noratext::Lexer.generate(:test)
|
44
44
|
tag = lexer.factory('<img src="../img/path.jpg">')
|
45
45
|
tag[:tag][:name].should == :image
|
46
46
|
tag[:tag][:kind].should == :opentag
|
@@ -49,7 +49,7 @@ describe "Noratext::Lexer" do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
it "should create parse path" do
|
52
|
-
lexer = Noratext::Lexer
|
52
|
+
lexer = Noratext::Lexer.generate(:test)
|
53
53
|
tag = lexer.factory('<img src="../img/path.jpg" scale="90%">')
|
54
54
|
tag[:tag][:name].should == :image
|
55
55
|
tag[:tag][:kind].should == :opentag
|
@@ -58,7 +58,7 @@ describe "Noratext::Lexer" do
|
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should parse rawtext tag" do
|
61
|
-
lexer = Noratext::Lexer
|
61
|
+
lexer = Noratext::Lexer.generate(:test)
|
62
62
|
text = "<quote>この部分は、<center>とかはいっていても、そのまま見えるはず。
|
63
63
|
<bold>改行</bold>しても、扱えるはず。</quote>このへんは、タグを<center>読む。"
|
64
64
|
io = StringIO.new(text)
|
@@ -45,7 +45,7 @@ end
|
|
45
45
|
describe Noratext::Parser do
|
46
46
|
it "should parse valid test" do
|
47
47
|
seq = [ { :type => :text, :data=>'これが中身', :line => 1} ]
|
48
|
-
result = Noratext::Parser
|
48
|
+
result = Noratext::Parser.generate(:ydml).parse(seq)
|
49
49
|
result.type.should == :document
|
50
50
|
result.is_leaf?.should_not be_true
|
51
51
|
result.children.size.should == 1
|
@@ -65,10 +65,10 @@ describe Noratext::Parser do
|
|
65
65
|
{ :type => :ruby,:tag => { :name => :ruby, :kind => :closetag }}
|
66
66
|
]
|
67
67
|
|
68
|
-
parser = Noratext::Parser
|
68
|
+
parser = Noratext::Parser.generate(:ydml)
|
69
69
|
result = parser.parse(seq)
|
70
70
|
result.type.should == :document
|
71
|
-
|
71
|
+
result.log.size.should == 0
|
72
72
|
result.children.size.should == 2
|
73
73
|
result.children[0].is_leaf?.should_not be_true
|
74
74
|
result.children[0].type.should == :center
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: noratext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- KOJIMA Satoshi
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-07-
|
18
|
+
date: 2010-07-14 00:00:00 +09:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -54,6 +54,7 @@ files:
|
|
54
54
|
- lib/noratext/lexer.rb
|
55
55
|
- lib/noratext/parser.rb
|
56
56
|
- lib/noratext/parser_element.rb
|
57
|
+
- lib/noratext/processor.rb
|
57
58
|
- lib/noratext/xmly_lexer.rb
|
58
59
|
- noratext.gemspec
|
59
60
|
- spec/noratext_lexer_spec.rb
|