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 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__ "input.index(Regexp.new(#{single_quote(text_value)}), index) == index" do
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
@@ -79,7 +79,7 @@ module Treetop
79
79
  end
80
80
 
81
81
  def reset_index
82
- builder.assign 'self.index', start_index_var
82
+ builder.assign '@index', start_index_var
83
83
  end
84
84
 
85
85
  def epsilon_node
@@ -27,7 +27,7 @@ module Treetop
27
27
  builder.newline
28
28
  generate_cache_storage(builder, result_var)
29
29
  builder.newline
30
- builder << "return #{result_var}"
30
+ builder << result_var
31
31
  end
32
32
  end
33
33
 
@@ -5,7 +5,7 @@ module Treetop
5
5
  super
6
6
  string_length = eval(text_value).length
7
7
 
8
- builder.if__ "input.index(#{text_value}, index) == index" do
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}"
@@ -103,7 +103,7 @@ module Treetop
103
103
  address_space.reset_addresses
104
104
  end
105
105
 
106
- protected
106
+ private
107
107
 
108
108
  def indent
109
109
  " " * level
@@ -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
@@ -1,8 +1,8 @@
1
1
  module Treetop #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
- MINOR = 2
5
- TINY = 6
4
+ MINOR = 3
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
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.2.6
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-06-14 00:00:00 +10:00
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