math_engine 0.6.4 → 0.7.0
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 +7 -0
- data/lib/lexer.rb +14 -14
- data/lib/parser.rb +5 -5
- metadata +20 -29
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9e98431e721fc6a9e9e76074de4666dc634b1bc5
|
4
|
+
data.tar.gz: 336c1a08937a4a453589fc728181c5cd55ee5f35
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 328cfd23de9da48f972a5efdc6c3e65007274c592fe9ad4863c358633ffc2ea927d6c54885e0255414b3635cf78ae605d830a518ad6d08fbed573a8d1cbbac18
|
7
|
+
data.tar.gz: af33ab3cc14f3819249c6c579686cc8282a25c3689a81ef8ce2a44056abb5d692611acb5b7f71a506a4c68e14b604b60b837ab5d9008344bc2af7bd1c62d6b4e
|
data/lib/lexer.rb
CHANGED
@@ -2,26 +2,26 @@ require "lexr"
|
|
2
2
|
class MathEngine
|
3
3
|
Lexer = Lexr.that {
|
4
4
|
ignores /\s/ => :whitespace
|
5
|
-
|
6
|
-
legal_place_for_binary_operator = lambda { |prev| [:addition,
|
7
|
-
:subtraction,
|
8
|
-
:multiplication,
|
5
|
+
|
6
|
+
legal_place_for_binary_operator = lambda { |prev| [:addition,
|
7
|
+
:subtraction,
|
8
|
+
:multiplication,
|
9
9
|
:division,
|
10
10
|
:open_parenthesis,
|
11
11
|
:start].include? prev.type }
|
12
|
-
|
12
|
+
|
13
13
|
matches ',' => :comma
|
14
14
|
matches '=' => :assignment
|
15
|
-
matches '+' => :addition, :
|
16
|
-
matches '-' => :subtraction, :
|
17
|
-
matches '*' => :multiplication, :
|
18
|
-
matches '/' => :division, :
|
19
|
-
matches '^' => :exponent, :
|
20
|
-
matches '%' => :modulus, :
|
15
|
+
matches '+' => :addition, unless: legal_place_for_binary_operator
|
16
|
+
matches '-' => :subtraction, unless: legal_place_for_binary_operator
|
17
|
+
matches '*' => :multiplication, unless: legal_place_for_binary_operator
|
18
|
+
matches '/' => :division, unless: legal_place_for_binary_operator
|
19
|
+
matches '^' => :exponent, unless: legal_place_for_binary_operator
|
20
|
+
matches '%' => :modulus, unless: legal_place_for_binary_operator
|
21
21
|
matches '(' => :open_parenthesis
|
22
22
|
matches ')' => :close_parenthesis
|
23
|
-
|
24
|
-
matches /
|
25
|
-
matches /[
|
23
|
+
|
24
|
+
matches /[a-z][a-z0-9_]*/i => :identifier, convert_with: lambda { |v| v.to_sym }
|
25
|
+
matches /([-+]?(\d+\.?\d*|\d*\.?\d+)([Ee][-+]?[0-2]?\d{1,2})?[r]?|[-+]?((\d+\.?\d*|\d*\.?\d+)([Ee][-+]?[0-2]?\d{1,2})?)?[i]|[-+]?(\d+\.?\d*|\d*\.?\d+)([Ee][-+]?[0-2]?\d{1,2})?[r]?[-+]((\d+\.?\d*|\d*\.?\d+)([Ee][-+]?[0-2]?\d{1,2})?)?[i])/ => :number, convert_with: lambda { |v| BigDecimal(v) }
|
26
26
|
}
|
27
27
|
end
|
data/lib/parser.rb
CHANGED
@@ -68,7 +68,7 @@ class MathEngine
|
|
68
68
|
end
|
69
69
|
result || left
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
def factor
|
73
73
|
if current.type == :number
|
74
74
|
result = MathEngine::LiteralNumberNode.new(current.value)
|
@@ -79,7 +79,7 @@ class MathEngine
|
|
79
79
|
next!
|
80
80
|
return result
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
expect_current :open_parenthesis, "number, variable or open_parenthesis"
|
84
84
|
next!
|
85
85
|
result = MathEngine::ParenthesisedExpressionNode.new(expression)
|
@@ -98,7 +98,7 @@ class MathEngine
|
|
98
98
|
expect_current :close_parenthesis
|
99
99
|
result
|
100
100
|
end
|
101
|
-
|
101
|
+
|
102
102
|
def call_parameter
|
103
103
|
left = expression
|
104
104
|
right = nil
|
@@ -112,7 +112,7 @@ class MathEngine
|
|
112
112
|
def current
|
113
113
|
@lexer.current
|
114
114
|
end
|
115
|
-
|
115
|
+
|
116
116
|
def peek
|
117
117
|
@lexer.peek
|
118
118
|
end
|
@@ -125,4 +125,4 @@ class MathEngine
|
|
125
125
|
raise MathEngine::ParseError.new("Unexpected #{current}, expected: #{friendly ? friendly : type}") unless current.type == type
|
126
126
|
end
|
127
127
|
end
|
128
|
-
end
|
128
|
+
end
|
metadata
CHANGED
@@ -1,91 +1,82 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: math_engine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.7.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Michael Baldry
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2017-02-24 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: lexr
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.
|
19
|
+
version: 0.4.0
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.
|
26
|
+
version: 0.4.0
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rspec
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
description: Lightweight matematical expression parser that is easy to extend
|
47
|
-
email:
|
42
|
+
email: mikeyb@buyapowa.com
|
48
43
|
executables: []
|
49
44
|
extensions: []
|
50
45
|
extra_rdoc_files:
|
51
46
|
- README.md
|
52
47
|
files:
|
53
48
|
- README.md
|
54
|
-
- lib/nodes.rb
|
55
|
-
- lib/lexer.rb
|
56
49
|
- lib/context.rb
|
57
50
|
- lib/errors.rb
|
58
|
-
- lib/math_engine.rb
|
59
|
-
- lib/evaluators/finders.rb
|
60
51
|
- lib/evaluators/calculate.rb
|
52
|
+
- lib/evaluators/finders.rb
|
53
|
+
- lib/lexer.rb
|
54
|
+
- lib/math_engine.rb
|
55
|
+
- lib/nodes.rb
|
61
56
|
- lib/parser.rb
|
62
|
-
homepage: http://
|
57
|
+
homepage: http://tech.buyapowa.com
|
63
58
|
licenses: []
|
59
|
+
metadata: {}
|
64
60
|
post_install_message:
|
65
61
|
rdoc_options:
|
66
|
-
- --main
|
62
|
+
- "--main"
|
67
63
|
- README.md
|
68
64
|
require_paths:
|
69
65
|
- lib
|
70
66
|
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
-
none: false
|
72
67
|
requirements:
|
73
|
-
- -
|
68
|
+
- - ">="
|
74
69
|
- !ruby/object:Gem::Version
|
75
70
|
version: '0'
|
76
|
-
segments:
|
77
|
-
- 0
|
78
|
-
hash: -1839538838728425454
|
79
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
-
none: false
|
81
72
|
requirements:
|
82
|
-
- -
|
73
|
+
- - ">="
|
83
74
|
- !ruby/object:Gem::Version
|
84
75
|
version: '0'
|
85
76
|
requirements: []
|
86
77
|
rubyforge_project:
|
87
|
-
rubygems_version:
|
78
|
+
rubygems_version: 2.5.2
|
88
79
|
signing_key:
|
89
|
-
specification_version:
|
80
|
+
specification_version: 4
|
90
81
|
summary: Lightweight mathematical expression parser
|
91
82
|
test_files: []
|