whittle 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/examples/calculator.rb +0 -10
- data/lib/whittle/parse_error_builder.rb +2 -2
- data/lib/whittle/parser.rb +5 -2
- data/lib/whittle/version.rb +1 -1
- data/spec/unit/parser/multiple_match_spec.rb +23 -0
- metadata +5 -3
data/examples/calculator.rb
CHANGED
@@ -39,7 +39,7 @@ module Whittle
|
|
39
39
|
ERROR
|
40
40
|
|
41
41
|
unless region.nil?
|
42
|
-
region = "\n\
|
42
|
+
region = "\n\n#{region}"
|
43
43
|
end
|
44
44
|
|
45
45
|
ParseError.new(message + region.to_s, token[:line], expected, token[:name])
|
@@ -75,7 +75,7 @@ module Whittle
|
|
75
75
|
" " * region_before.length
|
76
76
|
end
|
77
77
|
|
78
|
-
marker = "#{padding}^ ...
|
78
|
+
marker = "#{padding}^ ... occurred here\n\n"
|
79
79
|
|
80
80
|
unless error_line =~ /[\r\n]\Z/
|
81
81
|
marker = "\n#{marker}"
|
data/lib/whittle/parser.rb
CHANGED
@@ -285,16 +285,19 @@ module Whittle
|
|
285
285
|
private
|
286
286
|
|
287
287
|
def next_token(source, offset, line)
|
288
|
+
best = nil
|
289
|
+
|
288
290
|
rules.each do |name, rule|
|
289
291
|
next unless rule.terminal?
|
290
292
|
|
291
293
|
if token = rule.scan(source, offset, line)
|
294
|
+
best ||= token
|
292
295
|
token[:name] = name
|
293
|
-
|
296
|
+
best = token if token[:value].length > best[:value].length
|
294
297
|
end
|
295
298
|
end
|
296
299
|
|
297
|
-
|
300
|
+
best
|
298
301
|
end
|
299
302
|
end
|
300
303
|
end
|
data/lib/whittle/version.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "a parser with two terminal rules which overlap" do
|
4
|
+
let(:parser) do
|
5
|
+
Class.new(Whittle::Parser) do
|
6
|
+
rule("def")
|
7
|
+
rule("define")
|
8
|
+
rule(:id => /[a-z_]+/)
|
9
|
+
|
10
|
+
rule(:prog) do |r|
|
11
|
+
r["def"]
|
12
|
+
r["define"]
|
13
|
+
r[:id]
|
14
|
+
end
|
15
|
+
|
16
|
+
start(:prog)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it "uses the longest match" do
|
21
|
+
parser.new.parse("define_method").should == "define_method"
|
22
|
+
end
|
23
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whittle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-12-03 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70139412511200 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '2.6'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70139412511200
|
25
25
|
description: ! "Write powerful parsers by defining a series of very simple rules\n
|
26
26
|
\ and operations to perform as those rules are matched. Whittle\n
|
27
27
|
\ parsers are written in pure ruby and as such are extremely
|
@@ -59,6 +59,7 @@ files:
|
|
59
59
|
- spec/unit/parser/empty_string_spec.rb
|
60
60
|
- spec/unit/parser/error_reporting_spec.rb
|
61
61
|
- spec/unit/parser/grouped_expr_spec.rb
|
62
|
+
- spec/unit/parser/multiple_match_spec.rb
|
62
63
|
- spec/unit/parser/multiple_precedence_spec.rb
|
63
64
|
- spec/unit/parser/non_terminal_ambiguity_spec.rb
|
64
65
|
- spec/unit/parser/noop_spec.rb
|
@@ -104,6 +105,7 @@ test_files:
|
|
104
105
|
- spec/unit/parser/empty_string_spec.rb
|
105
106
|
- spec/unit/parser/error_reporting_spec.rb
|
106
107
|
- spec/unit/parser/grouped_expr_spec.rb
|
108
|
+
- spec/unit/parser/multiple_match_spec.rb
|
107
109
|
- spec/unit/parser/multiple_precedence_spec.rb
|
108
110
|
- spec/unit/parser/non_terminal_ambiguity_spec.rb
|
109
111
|
- spec/unit/parser/noop_spec.rb
|