parsecs 0.2.19 → 0.2.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/libnativemath/libnativemath.i +1 -1
- data/lib/parsec.rb +17 -9
- data/test/test_parsec.rb +18 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: baad050f7884ccde189b53870ea8b12919bf9814c389677794119e64590b0c37
|
4
|
+
data.tar.gz: f46692c9899acb7993f103a223dfd2c8c582defba944c23b19bae345bbeda45e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7b5293ef8325c2dffed4e73ec8957fcaf5e5f6ebe25ccfd9c3b2b44d1f0869c25324ca336da667fba9b4d0e82ba79ddb39d4a252371746b87d9e6bad69d19a4
|
7
|
+
data.tar.gz: 57759958a8205ca77b00f8ff62629e6023aaf81e14c9a3d4cbfaf14404c7473909839e474ba16168b332746e3d72188669fc4591def308c73b76b66e61534297
|
@@ -20,8 +20,8 @@ extern std::string native_direct_eval(std::string input);
|
|
20
20
|
switch (*$2) {
|
21
21
|
case 'i': rb_hash_aset($result, rb_str_new2("type"), rb_str_new2("int")); break;
|
22
22
|
case 'f': rb_hash_aset($result, rb_str_new2("type"), rb_str_new2("float")); break;
|
23
|
-
case 's': rb_hash_aset($result, rb_str_new2("type"), rb_str_new2("string")); break;
|
24
23
|
case 'b': rb_hash_aset($result, rb_str_new2("type"), rb_str_new2("boolean")); break;
|
24
|
+
case 's': rb_hash_aset($result, rb_str_new2("type"), rb_str_new2("string")); break;
|
25
25
|
case 'c': rb_hash_aset($result, rb_str_new2("type"), rb_str_new2("complex")); break;
|
26
26
|
case 'm': rb_hash_aset($result, rb_str_new2("type"), rb_str_new2("matrix")); break;
|
27
27
|
}
|
data/lib/parsec.rb
CHANGED
@@ -6,36 +6,43 @@ module Parsec
|
|
6
6
|
class Parsec
|
7
7
|
using StringToBooleanRefinements
|
8
8
|
|
9
|
-
VERSION = '0.2.
|
9
|
+
VERSION = '0.2.20'.freeze
|
10
10
|
|
11
11
|
# evaluates the equation
|
12
12
|
def self.eval_equation(equation)
|
13
|
-
|
13
|
+
remove(equation, true)
|
14
14
|
|
15
15
|
convert(Libnativemath.native_eval(equation))
|
16
16
|
end
|
17
17
|
|
18
18
|
# returns true or raise an error
|
19
|
-
def self.validate_syntax(equation)
|
19
|
+
def self.validate_syntax!(equation)
|
20
|
+
remove(equation)
|
21
|
+
|
20
22
|
validate(Libnativemath.native_eval(equation), true)
|
21
23
|
end
|
22
24
|
|
23
25
|
# returns true or an error string
|
24
|
-
def self.
|
26
|
+
def self.validate_syntax(equation)
|
27
|
+
remove(equation)
|
28
|
+
|
25
29
|
validate(Libnativemath.native_eval(equation), false)
|
26
30
|
end
|
27
31
|
|
28
32
|
private_class_method
|
29
33
|
|
30
|
-
def self.
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
+
def self.remove(equation, new_line = false)
|
35
|
+
equation.gsub!(/[\n\t\r]/, ' ')
|
36
|
+
|
37
|
+
# The following regex remove all spaces that are not between quot marks
|
38
|
+
# https://goo.gl/exJ66Y
|
39
|
+
equation.gsub!(/( |(".*?"))/, '\\2') if new_line == true
|
34
40
|
end
|
35
41
|
|
36
42
|
def self.convert(ans)
|
37
43
|
case ans['value']
|
38
44
|
when 'inf' then return 'Infinity'
|
45
|
+
when '-inf' then return '-Infinity'
|
39
46
|
when 'nan' then return ans['value']
|
40
47
|
end
|
41
48
|
|
@@ -44,7 +51,8 @@ module Parsec
|
|
44
51
|
when 'float' then return ans['value'].to_f
|
45
52
|
when 'boolean' then return ans['value'].to_bool
|
46
53
|
when 'string' then return error_check(ans['value'])
|
47
|
-
when '
|
54
|
+
when 'complex' then return 'complex number' # Maybe future implementation
|
55
|
+
when 'matrix' then return 'matrix value' # Maybe future implementation
|
48
56
|
end
|
49
57
|
end
|
50
58
|
|
data/test/test_parsec.rb
CHANGED
@@ -83,4 +83,22 @@ class TestParsec < Minitest::Test
|
|
83
83
|
assert_equal(5, parsec.eval_equation('round(4.62)'))
|
84
84
|
assert_equal(4.63, parsec.eval_equation('round_decimal(4.625, 2)'))
|
85
85
|
end
|
86
|
+
|
87
|
+
def test_newlines_remotion
|
88
|
+
parsec = Parsec::Parsec
|
89
|
+
assert_equal(true, parsec.validate_syntax("4 + \n 2"))
|
90
|
+
assert_equal(true, parsec.validate_syntax("\n4\n+ \n 2\n"))
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_validate_syntax
|
94
|
+
parsec = Parsec::Parsec
|
95
|
+
assert_equal(true, parsec.validate_syntax('((0.09/1.0)+2.58)-1.6+'))
|
96
|
+
assert_equal('Missing parenthesis.', parsec.validate_syntax('(0.09/1.0'))
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_validate_syntax!
|
100
|
+
parsec = Parsec::Parsec
|
101
|
+
assert_equal(true, parsec.validate_syntax!('((0.09/1.0)+2.58)-1.6+'))
|
102
|
+
assert_raises(parsec.validate_syntax!('(0.09/1.0'))
|
103
|
+
end
|
86
104
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parsecs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.20
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nilton Vasques
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2018-06-
|
13
|
+
date: 2018-06-19 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: minitest
|
@@ -82,7 +82,7 @@ requirements:
|
|
82
82
|
- swig
|
83
83
|
- cmake
|
84
84
|
rubyforge_project:
|
85
|
-
rubygems_version: 2.7.
|
85
|
+
rubygems_version: 2.7.3
|
86
86
|
signing_key:
|
87
87
|
specification_version: 4
|
88
88
|
summary: A gem to evaluate equations using muparserx C++ library
|