eqn 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 08c722b548df16e9f686ca109df362c10592c8a0
4
- data.tar.gz: aedb663d5c308aaf018bab79028432e0538883be
3
+ metadata.gz: c7a78002efee6ad3b972ad83a8e6a465f1315116
4
+ data.tar.gz: ebbe4de996b80177d20d108940496aa924ae8e18
5
5
  SHA512:
6
- metadata.gz: f8c56e988905d9860e879241e9ce231db2d1ba82a68e38a317d09b575ecc9a53e228288b88e1b0a448ff4bb5cfeac1b4c6bc429e7e4b730d9600f5c564d2a90b
7
- data.tar.gz: 24b4da1f8663c8cbb6c12246ecbe82eb78a477ab093370c81a37605492b50a0b783fe13df6ca3a892de65fb016ae2ad56ca4a8eeeeb8b4ccaaee9861582f8a6d
6
+ metadata.gz: 45338dbccc37d5d4cfb31f53423af3049063b29b54230a23ef1e0b737b85427b12b9bcadb74e767bcea25950576e3f0c2e02722d659e191093c9f691559a67fe
7
+ data.tar.gz: 7e311be733a590f3bb895f864afe546c4a95afd17840d6a9d837acd398dce36533bfb000af1cd32cc135b2f51f85db35e3d4b771c9f0dd116edfb1e11b6fbc55
data/.travis.yml CHANGED
@@ -6,4 +6,5 @@ install:
6
6
  - gem install bundler --version '1.8.5'
7
7
  - bundle
8
8
  script:
9
- - bundle exec rspec
9
+ - bundle exec rspec
10
+ - bundle exec rubocop
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Build Status](https://travis-ci.org/schneidmaster/eqn.svg?branch=master)](https://travis-ci.org/schneidmaster/eqn)
1
+ [![Gem Version](https://badge.fury.io/rb/eqn.svg)](http://badge.fury.io/rb/eqn) [![Build Status](https://travis-ci.org/schneidmaster/eqn.svg?branch=master)](https://travis-ci.org/schneidmaster/eqn)
2
2
 
3
3
  # Eqn
4
4
 
data/lib/eqn.treetop CHANGED
@@ -103,10 +103,6 @@ grammar Eqn
103
103
  / '!=' <Eqn::Terminal::CompOp::Neq>
104
104
  end
105
105
 
106
- rule dot
107
- '.' <Eqn::Terminal::Dot>
108
- end
109
-
110
106
  rule exp
111
107
  'e' / 'E'
112
108
  end
@@ -2,19 +2,47 @@ module Eqn
2
2
  class Node < Treetop::Runtime::SyntaxNode; end
3
3
 
4
4
  class Expression < Node
5
+ def left_associative?
6
+ elements.any? && elements.last.left_associative?
7
+ end
8
+
9
+ def term?
10
+ elements.empty?
11
+ end
12
+
13
+ # rubocop:disable Metrics/AbcSize
5
14
  def value
6
15
  if elements.count == 1
7
16
  elements.shift.value
8
17
  else
9
18
  base = elements.shift.value
10
- op, num = elements.shift.value
11
- base.send(op, num)
19
+
20
+ # Aggressively consume left associative operators to maintain associativity.
21
+ while left_associative?
22
+ op, num_expr = elements.shift.value
23
+ num_expr_operand = num_expr.elements.shift
24
+ base = base.send(op, num_expr_operand.value)
25
+ elements.push num_expr.elements.shift unless num_expr.term?
26
+ end
27
+
28
+ # Apply next right-associative operator (if any) or return.
29
+ if term?
30
+ base
31
+ else
32
+ op, num_expr = elements.shift.value
33
+ base.send(op, num_expr.value)
34
+ end
12
35
  end
13
36
  end
37
+ # rubocop:enable Metrics/AbcSize
14
38
 
15
39
  class ExprGroup < Node
40
+ def left_associative?
41
+ elements.first.left_associative?
42
+ end
43
+
16
44
  def value
17
- [elements.shift.value, elements.shift.value]
45
+ [elements.shift.value, elements.shift]
18
46
  end
19
47
  end
20
48
  end
data/lib/eqn/terminal.rb CHANGED
@@ -20,30 +20,50 @@ module Eqn
20
20
 
21
21
  class Op < Node
22
22
  class Add < Node
23
+ def left_associative?
24
+ false
25
+ end
26
+
23
27
  def value
24
28
  '+'
25
29
  end
26
30
  end
27
31
 
28
32
  class Sub < Node
33
+ def left_associative?
34
+ true
35
+ end
36
+
29
37
  def value
30
38
  '-'
31
39
  end
32
40
  end
33
41
 
34
42
  class Mul < Node
43
+ def left_associative?
44
+ false
45
+ end
46
+
35
47
  def value
36
48
  '*'
37
49
  end
38
50
  end
39
51
 
40
52
  class Div < Node
53
+ def left_associative?
54
+ true
55
+ end
56
+
41
57
  def value
42
58
  '/'
43
59
  end
44
60
  end
45
61
 
46
62
  class Pow < Node
63
+ def left_associative?
64
+ false
65
+ end
66
+
47
67
  def value
48
68
  '**'
49
69
  end
data/lib/eqn/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eqn
2
- VERSION = '1.1.1'
2
+ VERSION = '1.1.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eqn
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Schneider
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-05-27 00:00:00.000000000 Z
11
+ date: 2015-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: treetop