whittle 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -57,13 +57,3 @@ p calculator.parse("5 - -2").to_f
57
57
 
58
58
  p calculator.parse("5 * 2 - -2").to_f
59
59
  # => 12
60
-
61
-
62
- p calculator.parse(
63
- <<-END
64
- 5 * 2 - -2
65
- + 3 / 7 * 90
66
- / 45 * 8 * 8 * 8 - 6 * (1 - 2 - 3 ) (45 / 5)) / (7 * 3)
67
- - 6
68
- END
69
- ).to_f
@@ -39,7 +39,7 @@ module Whittle
39
39
  ERROR
40
40
 
41
41
  unless region.nil?
42
- region = "\n\nExact region marked...\n\n#{region}"
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}^ ... right here\n\n"
78
+ marker = "#{padding}^ ... occurred here\n\n"
79
79
 
80
80
  unless error_line =~ /[\r\n]\Z/
81
81
  marker = "\n#{marker}"
@@ -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
- return token
296
+ best = token if token[:value].length > best[:value].length
294
297
  end
295
298
  end
296
299
 
297
- nil
300
+ best
298
301
  end
299
302
  end
300
303
  end
@@ -3,5 +3,5 @@
3
3
  # Copyright (c) Chris Corbyn, 2011
4
4
 
5
5
  module Whittle
6
- VERSION = "0.0.7"
6
+ VERSION = "0.0.8"
7
7
  end
@@ -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.7
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: &70312516285540 !ruby/object:Gem::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: *70312516285540
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