treetop 1.2.6 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +19 -0
- data/lib/treetop/compiler/node_classes/character_class.rb +6 -1
- data/lib/treetop/compiler/node_classes/parsing_expression.rb +1 -1
- data/lib/treetop/compiler/node_classes/parsing_rule.rb +1 -1
- data/lib/treetop/compiler/node_classes/terminal.rb +1 -1
- data/lib/treetop/compiler/ruby_builder.rb +1 -1
- data/lib/treetop/runtime/compiled_parser.rb +10 -0
- data/lib/treetop/version.rb +2 -2
- metadata +3 -2
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2007 Nathan Sobo.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
@@ -4,7 +4,7 @@ module Treetop
|
|
4
4
|
def compile(address, builder, parent_expression = nil)
|
5
5
|
super
|
6
6
|
|
7
|
-
builder.if__ "
|
7
|
+
builder.if__ "has_terminal?(#{grounded_regexp(text_value)}, true, index)" do
|
8
8
|
assign_result "instantiate_node(#{node_class_name},input, index...(index + 1))"
|
9
9
|
extend_result_with_inline_module
|
10
10
|
builder << "@index += 1"
|
@@ -14,6 +14,11 @@ module Treetop
|
|
14
14
|
assign_result 'nil'
|
15
15
|
end
|
16
16
|
end
|
17
|
+
|
18
|
+
def grounded_regexp(string)
|
19
|
+
# Double any backslashes, then backslash any single-quotes:
|
20
|
+
"'\\G#{string.gsub(/\\/) { '\\\\' }.gsub(/'/) { "\\'"}}'"
|
21
|
+
end
|
17
22
|
end
|
18
23
|
end
|
19
24
|
end
|
@@ -5,7 +5,7 @@ module Treetop
|
|
5
5
|
super
|
6
6
|
string_length = eval(text_value).length
|
7
7
|
|
8
|
-
builder.if__ "
|
8
|
+
builder.if__ "has_terminal?(#{text_value}, false, index)" do
|
9
9
|
assign_result "instantiate_node(#{node_class_name},input, index...(index + #{string_length}))"
|
10
10
|
extend_result_with_inline_module
|
11
11
|
builder << "@index += #{string_length}"
|
@@ -54,6 +54,7 @@ module Treetop
|
|
54
54
|
@input_length = input.length
|
55
55
|
reset_index
|
56
56
|
@node_cache = Hash.new {|hash, key| hash[key] = Hash.new}
|
57
|
+
@regexps = {}
|
57
58
|
@terminal_failures = []
|
58
59
|
@max_terminal_failure_index = 0
|
59
60
|
end
|
@@ -81,6 +82,15 @@ module Treetop
|
|
81
82
|
end
|
82
83
|
end
|
83
84
|
|
85
|
+
def has_terminal?(terminal, regex, index)
|
86
|
+
if regex
|
87
|
+
rx = @regexps[terminal] ||= Regexp.new(terminal)
|
88
|
+
input.index(rx, index) == index
|
89
|
+
else
|
90
|
+
input[index, terminal.size] == terminal
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
84
94
|
def terminal_parse_failure(expected_string)
|
85
95
|
return nil if index < max_terminal_failure_index
|
86
96
|
if index > max_terminal_failure_index
|
data/lib/treetop/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: treetop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Sobo
|
@@ -9,7 +9,7 @@ autorequire: treetop
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-07-22 00:00:00 +10:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -31,6 +31,7 @@ extensions: []
|
|
31
31
|
extra_rdoc_files: []
|
32
32
|
|
33
33
|
files:
|
34
|
+
- LICENSE
|
34
35
|
- README
|
35
36
|
- Rakefile
|
36
37
|
- lib/treetop/bootstrap_gen_1_metagrammar.rb
|