parsecs 0.2.18 → 0.2.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/libnativemath/libnativemath.cpp +5 -11
- data/ext/libnativemath/libnativemath.h +1 -1
- data/ext/libnativemath/libnativemath.i +25 -1
- data/lib/parsec.rb +10 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e7b3b272aa00c84d85c8ed2e54564840f6cda8d34865125a7e2b47eb2313946
|
4
|
+
data.tar.gz: 9a0eca31231d8dbcd6d5006e0e0c3e1de8d008e4cf5d6891a50af7fd25924c01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e9a252ffde2b57982a3bd68491d144514af414ff7bc5235002b914ecae0a11eff42a95db1acc22b5acb4e81165d6cf80f5f04f1379733f221ae4955c54a5327
|
7
|
+
data.tar.gz: b1709ff79e5870d03c1579ec717d5ef9c932838fecbee26cb3e5c132b168e606a35c8a2cd6302ff6aef38062c3708a59abf605a13b3f305bc4ae890d962584f1
|
@@ -1,5 +1,4 @@
|
|
1
1
|
/* ext/libnativemath.cpp */
|
2
|
-
#include <string>
|
3
2
|
#include <iostream>
|
4
3
|
#include <cmath>
|
5
4
|
#include "mpParser.h"
|
@@ -34,21 +33,16 @@ Value Calc(string input) {
|
|
34
33
|
return ans;
|
35
34
|
}
|
36
35
|
|
37
|
-
|
36
|
+
string_type native_direct_eval(string_type input) {
|
38
37
|
Value ans = Calc(input);
|
39
38
|
return ans.AsString();
|
40
39
|
}
|
41
40
|
|
42
|
-
|
41
|
+
int native_eval(string input, char *value, char *value_type) {
|
43
42
|
Value ans = Calc(input);
|
44
|
-
stringstream_type ss;
|
45
43
|
|
46
|
-
|
47
|
-
ss << _T("{");
|
48
|
-
ss << _T("\"value\": \"") << ans.AsString() << _T("\"");
|
49
|
-
ss << _T(", ");
|
50
|
-
ss << _T("\"type\": \"") << ans.GetType() << _T("\"");
|
51
|
-
ss << _T("}");
|
44
|
+
value_type[0] = ans.GetType();
|
52
45
|
|
53
|
-
|
46
|
+
strcpy(value, ans.AsString().c_str());
|
47
|
+
return 0;
|
54
48
|
}
|
@@ -6,4 +6,28 @@
|
|
6
6
|
%}
|
7
7
|
|
8
8
|
extern std::string native_direct_eval(std::string input);
|
9
|
-
|
9
|
+
|
10
|
+
%typemap(in, numinputs=0) (char *value, char *value_type) {
|
11
|
+
char a[1000];
|
12
|
+
char b;
|
13
|
+
$1 = a;
|
14
|
+
$2 = &b;
|
15
|
+
};
|
16
|
+
%typemap(argout) (char *value, char *value_type) {
|
17
|
+
if(result == 0) {
|
18
|
+
$result = rb_hash_new();
|
19
|
+
rb_hash_aset($result, rb_str_new2("value"), rb_str_new2($1));
|
20
|
+
switch (*$2) {
|
21
|
+
case 'i': rb_hash_aset($result, rb_str_new2("type"), rb_str_new2("int")); break;
|
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
|
+
case 'b': rb_hash_aset($result, rb_str_new2("type"), rb_str_new2("boolean")); break;
|
25
|
+
case 'c': rb_hash_aset($result, rb_str_new2("type"), rb_str_new2("complex")); break;
|
26
|
+
case 'm': rb_hash_aset($result, rb_str_new2("type"), rb_str_new2("matrix")); break;
|
27
|
+
}
|
28
|
+
} else {
|
29
|
+
$result = Qfalse;
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
extern int native_eval(std::string input, char *value, char *value_type);
|
data/lib/parsec.rb
CHANGED
@@ -1,29 +1,28 @@
|
|
1
1
|
require 'string_to_boolean_refinements'
|
2
2
|
require 'libnativemath'
|
3
|
-
require 'json'
|
4
3
|
|
5
4
|
module Parsec
|
6
5
|
# This is the main class responsible to evaluate the equations
|
7
6
|
class Parsec
|
8
7
|
using StringToBooleanRefinements
|
9
8
|
|
10
|
-
VERSION = '0.2.
|
9
|
+
VERSION = '0.2.19'.freeze
|
11
10
|
|
12
11
|
# evaluates the equation
|
13
12
|
def self.eval_equation(equation)
|
14
13
|
remove_spaces(equation)
|
15
14
|
|
16
|
-
convert(
|
15
|
+
convert(Libnativemath.native_eval(equation))
|
17
16
|
end
|
18
17
|
|
19
18
|
# returns true or raise an error
|
20
19
|
def self.validate_syntax(equation)
|
21
|
-
validate(
|
20
|
+
validate(Libnativemath.native_eval(equation), true)
|
22
21
|
end
|
23
22
|
|
24
23
|
# returns true or an error string
|
25
24
|
def self.verify_syntax(equation)
|
26
|
-
validate(
|
25
|
+
validate(Libnativemath.native_eval(equation), false)
|
27
26
|
end
|
28
27
|
|
29
28
|
private_class_method
|
@@ -41,12 +40,11 @@ module Parsec
|
|
41
40
|
end
|
42
41
|
|
43
42
|
case ans['type']
|
44
|
-
when '
|
45
|
-
when '
|
46
|
-
when '
|
47
|
-
when '
|
48
|
-
when 'c'
|
49
|
-
when 'm' then return 'matrix value' # Maybe future implementation
|
43
|
+
when 'int' then return ans['value'].to_i
|
44
|
+
when 'float' then return ans['value'].to_f
|
45
|
+
when 'boolean' then return ans['value'].to_bool
|
46
|
+
when 'string' then return error_check(ans['value'])
|
47
|
+
when 'c' then return 'complex number'
|
50
48
|
end
|
51
49
|
end
|
52
50
|
|
@@ -56,7 +54,7 @@ module Parsec
|
|
56
54
|
end
|
57
55
|
|
58
56
|
def self.validate(ans, raise_error)
|
59
|
-
if (ans['type'] == '
|
57
|
+
if (ans['type'] == 'string') && ans['value'].include?('Error: ')
|
60
58
|
raise SyntaxError, ans['value'].sub('Error: ', '') if raise_error
|
61
59
|
return ans['value'].sub('Error: ', '')
|
62
60
|
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.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nilton Vasques
|
@@ -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.6
|
86
86
|
signing_key:
|
87
87
|
specification_version: 4
|
88
88
|
summary: A gem to evaluate equations using muparserx C++ library
|