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 +4 -4
- data/.travis.yml +2 -1
- data/README.md +1 -1
- data/lib/eqn.treetop +0 -4
- data/lib/eqn/expression.rb +31 -3
- data/lib/eqn/terminal.rb +20 -0
- data/lib/eqn/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7a78002efee6ad3b972ad83a8e6a465f1315116
|
4
|
+
data.tar.gz: ebbe4de996b80177d20d108940496aa924ae8e18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45338dbccc37d5d4cfb31f53423af3049063b29b54230a23ef1e0b737b85427b12b9bcadb74e767bcea25950576e3f0c2e02722d659e191093c9f691559a67fe
|
7
|
+
data.tar.gz: 7e311be733a590f3bb895f864afe546c4a95afd17840d6a9d837acd398dce36533bfb000af1cd32cc135b2f51f85db35e3d4b771c9f0dd116edfb1e11b6fbc55
|
data/.travis.yml
CHANGED
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
data/lib/eqn/expression.rb
CHANGED
@@ -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
|
-
|
11
|
-
|
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
|
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
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.
|
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-
|
11
|
+
date: 2015-06-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: treetop
|