kalculator 0.5.0 → 0.5.1

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
  SHA256:
3
- metadata.gz: 9d38e426af60ed279a79b3764e035b3564623f702590337f28958aff8ea5ef1c
4
- data.tar.gz: 6409234b6be3c95af8c79071f49363d277b15a7a707e6ea1bcf7056d15b0fcda
3
+ metadata.gz: 5026dd4c73a2ebf6f64a18d11d6ef1c8838f902a4fb9fdee31bba43c0819d998
4
+ data.tar.gz: dacfcdd98e1bc4c08048052b1f4ce4fa94449ac05d7217842c9fbfbce8c0efc6
5
5
  SHA512:
6
- metadata.gz: 676a268b7e66af2752dde9ea44de1c3e56074399220cfe696d89fec1ae85d790723682e4a9a11a2ba56f4013da79d6dd106903b185578e2d76df4ead8166d624
7
- data.tar.gz: ecdd4b0f06b52a320c7d80fbbfd56c778d2ad9c498a71028a3a45cc78040b66fa8e82d426d14f3a2ddcb379804f924b9af9964173d1b78ad7f93f083a3ff3d2e
6
+ metadata.gz: 35c4bab92d9ed7b895f7f60231a8cfbd01a4ecefec46f0eebdff27a465543fe3ab6f14b6a2876df636ebb9fc20a02ebfbb1695a04d50197c80b7678cc513222b
7
+ data.tar.gz: 243833c66d4dc6a3eb952a53610226cf28c5f8d94b49c77b95d71737d33ec35ef32bafd3ebda38511b96be36fda8cc9ac59cc71ff47ae958940bd5401f6af2a5
@@ -44,6 +44,10 @@ class Kalculator
44
44
  evaluate(left) == evaluate(right)
45
45
  end
46
46
 
47
+ def !=(_, left, right)
48
+ evaluate(left) != evaluate(right)
49
+ end
50
+
47
51
  def and(_, left, right)
48
52
  evaluate(left) && evaluate(right)
49
53
  end
@@ -80,6 +84,12 @@ class Kalculator
80
84
  expressions.map{|expression| evaluate(expression) }
81
85
  end
82
86
 
87
+ def not(_, expression)
88
+ bool = evaluate(expression)
89
+ raise TypeError, "! only works with booleans, got #{bool.inspect}" unless bool === true || bool === false
90
+ !bool
91
+ end
92
+
83
93
  def number(_, number)
84
94
  number
85
95
  end
@@ -15,8 +15,10 @@ class Kalculator
15
15
  rule(/</) { :LT }
16
16
  rule(/<=/) { :LTE }
17
17
  rule(/==/) { :EQ }
18
+ rule(/!=/) { :NEQ }
18
19
  rule(/AND/) { :AND }
19
20
  rule(/OR/) { :OR }
21
+ rule(/!/) { :BANG }
20
22
  rule(/\-?\d+/) { |t| [:NUMBER, t.to_i] }
21
23
  rule(/\-?\.\d+/) { |t| [:NUMBER, t.to_f] }
22
24
  rule(/\-?\d+\.\d+/) { |t| [:NUMBER, t.to_f] }
@@ -30,6 +30,7 @@ class Kalculator
30
30
  clause('expression LT expression') { |e0, _, e1| [:<, e0, e1] }
31
31
  clause('expression LTE expression') { |e0, _, e1| [:<=, e0, e1] }
32
32
  clause('expression EQ expression') { |e0, _, e1| [:==, e0, e1] }
33
+ clause('expression NEQ expression') { |e0, _, e1| [:!=, e0, e1] }
33
34
 
34
35
  clause('expression AND expression') { |e0, _, e1| [:and, e0, e1] }
35
36
  clause('expression OR expression') { |e0, _, e1| [:or, e0, e1] }
@@ -38,6 +39,8 @@ class Kalculator
38
39
  clause('expression SUB expression') { |e0, _, e1| [:-, e0, e1] }
39
40
  clause('expression MUL expression') { |e0, _, e1| [:*, e0, e1] }
40
41
  clause('expression DIV expression') { |e0, _, e1| [:/, e0, e1] }
42
+
43
+ clause('BANG expression') { |_, e0| [:not, e0] }
41
44
  end
42
45
 
43
46
  production(:expressions) do
@@ -1,3 +1,3 @@
1
1
  class Kalculator
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kalculator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Ries
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-30 00:00:00.000000000 Z
11
+ date: 2018-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rltk