trenni 1.7.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +7 -3
- data/Gemfile +4 -0
- data/README.md +72 -10
- data/Rakefile +85 -0
- data/benchmark/call_vs_yield.rb +51 -0
- data/benchmark/interpolation_vs_concat.rb +29 -0
- data/benchmark/io_vs_string.rb +14 -4
- data/entities.json +2233 -0
- data/ext/trenni/extconf.rb +13 -0
- data/ext/trenni/markup.c +1981 -0
- data/ext/trenni/markup.h +6 -0
- data/ext/trenni/markup.rl +223 -0
- data/ext/trenni/template.c +1113 -0
- data/ext/trenni/template.h +6 -0
- data/ext/trenni/template.rl +77 -0
- data/ext/trenni/trenni.c +64 -0
- data/ext/trenni/trenni.h +28 -0
- data/lib/trenni.rb +1 -0
- data/lib/trenni/buffer.rb +13 -2
- data/lib/trenni/builder.rb +54 -47
- data/lib/trenni/entities.rb +2154 -0
- data/lib/trenni/entities.trenni +34 -0
- data/lib/trenni/fallback/markup.rb +1648 -0
- data/lib/trenni/fallback/markup.rl +236 -0
- data/lib/trenni/fallback/template.rb +843 -0
- data/lib/trenni/fallback/template.rl +97 -0
- data/lib/trenni/markup.rb +76 -0
- data/lib/trenni/native.rb +28 -0
- data/lib/trenni/parse_delegate.rb +34 -0
- data/lib/trenni/{scanner.rb → parse_error.rb} +9 -54
- data/lib/trenni/parsers.rb +12 -0
- data/lib/trenni/substitutions.rb +45 -0
- data/lib/trenni/template.rb +52 -135
- data/lib/trenni/version.rb +1 -1
- data/parsers/trenni/entities.rl +11 -0
- data/parsers/trenni/markup.rl +43 -0
- data/parsers/trenni/template.rl +60 -0
- data/spec/trenni/builder_spec.rb +37 -62
- data/spec/trenni/corpus/large.rb +4605 -0
- data/spec/trenni/corpus/large.xhtml +726 -0
- data/spec/trenni/markup_parser_spec.rb +233 -0
- data/spec/trenni/markup_spec.rb +48 -0
- data/spec/trenni/parsers_performance_spec.rb +44 -0
- data/spec/trenni/template_error_spec.rb +36 -0
- data/spec/trenni/template_performance_spec.rb +102 -0
- data/spec/trenni/template_spec.rb +90 -64
- data/spec/trenni/template_spec/basic.trenni +1 -0
- data/spec/trenni/template_spec/capture.trenni +2 -2
- data/spec/trenni/template_spec/error.trenni +4 -0
- data/trenni.gemspec +9 -6
- metadata +57 -15
- data/lib/trenni/parser.rb +0 -153
- data/spec/trenni/parser_spec.rb +0 -144
data/spec/trenni/parser_spec.rb
DELETED
@@ -1,144 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the "Software"), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in
|
13
|
-
# all copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
# THE SOFTWARE.
|
22
|
-
|
23
|
-
require 'trenni/parser'
|
24
|
-
|
25
|
-
module Trenni::ParserSpec
|
26
|
-
class ParserDelegate
|
27
|
-
def initialize
|
28
|
-
@events = []
|
29
|
-
end
|
30
|
-
|
31
|
-
attr :events
|
32
|
-
|
33
|
-
def method_missing(*args)
|
34
|
-
@events << args
|
35
|
-
end
|
36
|
-
|
37
|
-
def begin_parse(scanner)
|
38
|
-
# ignore this event
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe Trenni::Parser do
|
43
|
-
def parse(input)
|
44
|
-
delegate = ParserDelegate.new
|
45
|
-
buffer = Trenni::Buffer.new(input)
|
46
|
-
Trenni::Parser.new(buffer, delegate).parse!
|
47
|
-
|
48
|
-
return delegate
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should parse self-closing tags correctly" do
|
52
|
-
delegate = parse("<br/>")
|
53
|
-
|
54
|
-
expect(delegate.events).to be == [
|
55
|
-
[:begin_tag, "br", :opened],
|
56
|
-
[:finish_tag, :opened, :closed],
|
57
|
-
]
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should parse doctype correctly" do
|
61
|
-
delegate = parse("<!DOCTYPE html>")
|
62
|
-
|
63
|
-
expect(delegate.events).to be == [
|
64
|
-
[:doctype, "html"]
|
65
|
-
]
|
66
|
-
end
|
67
|
-
|
68
|
-
it "Should parse instruction correctly" do
|
69
|
-
delegate = parse("<?foo=bar?>")
|
70
|
-
|
71
|
-
expect(delegate.events).to be == [
|
72
|
-
[:instruction, "foo=bar"]
|
73
|
-
]
|
74
|
-
end
|
75
|
-
|
76
|
-
it "should parse comment correctly" do
|
77
|
-
delegate = parse(%Q{<!--comment-->})
|
78
|
-
|
79
|
-
expect(delegate.events).to be == [
|
80
|
-
[:comment, "comment"]
|
81
|
-
]
|
82
|
-
end
|
83
|
-
|
84
|
-
it "should parse markup correctly" do
|
85
|
-
delegate = parse(%Q{<foo bar="20" baz>Hello World</foo>})
|
86
|
-
|
87
|
-
expected_events = [
|
88
|
-
[:begin_tag, "foo", :opened],
|
89
|
-
[:attribute, "bar", "20"],
|
90
|
-
[:attribute, "baz", true],
|
91
|
-
[:finish_tag, :opened, :opened],
|
92
|
-
[:text, "Hello World"],
|
93
|
-
[:begin_tag, "foo", :closed],
|
94
|
-
[:finish_tag, :closed, :opened],
|
95
|
-
]
|
96
|
-
|
97
|
-
expect(delegate.events).to be == expected_events
|
98
|
-
end
|
99
|
-
|
100
|
-
it "should parse CDATA correctly" do
|
101
|
-
delegate = parse(%Q{<test><![CDATA[Hello World]]></test>})
|
102
|
-
|
103
|
-
expected_events = [
|
104
|
-
[:begin_tag, "test", :opened],
|
105
|
-
[:finish_tag, :opened, :opened],
|
106
|
-
[:cdata, "Hello World"],
|
107
|
-
[:begin_tag, "test", :closed],
|
108
|
-
[:finish_tag, :closed, :opened],
|
109
|
-
]
|
110
|
-
|
111
|
-
expect(delegate.events).to be == expected_events
|
112
|
-
end
|
113
|
-
|
114
|
-
it "should generate errors on incorrect input" do
|
115
|
-
expect{parse(%Q{<foo})}.to raise_error Trenni::ParseError
|
116
|
-
|
117
|
-
expect{parse(%Q{<foo bar=>})}.to raise_error Trenni::ParseError
|
118
|
-
|
119
|
-
expect{parse(%Q{<foo bar="" baz>})}.to_not raise_error
|
120
|
-
end
|
121
|
-
|
122
|
-
it "should know about line numbers" do
|
123
|
-
data = %Q{Hello\nWorld\nFoo\nBar!}
|
124
|
-
|
125
|
-
location = Trenni::Location.new(data, 7)
|
126
|
-
|
127
|
-
expect(location.to_i).to be == 7
|
128
|
-
expect(location.to_s).to be == "[2]"
|
129
|
-
expect(location.line_text).to be == "World"
|
130
|
-
|
131
|
-
expect(location.line_number).to be == 2
|
132
|
-
expect(location.line_range.min).to be == 6
|
133
|
-
expect(location.line_offset).to be == 1
|
134
|
-
end
|
135
|
-
|
136
|
-
it "should know about line numbers when input contains multi-byte characters" do
|
137
|
-
data = %Q{<p>\nこんにちは\nWorld\n<p}
|
138
|
-
error = parse(data) rescue $!
|
139
|
-
|
140
|
-
expect(error).to be_kind_of Trenni::ParseError
|
141
|
-
expect(error.location.line_number).to be == 4
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|