eqn 1.0.7 → 1.1.0

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
  SHA1:
3
- metadata.gz: 72aa39e625ff099ac7869c8674ebfee16778bf68
4
- data.tar.gz: 12ab353c122b7d5666460817f1aa27ee70cf9ac5
3
+ metadata.gz: 66e4ae8e6dc085c3b899b571fce70d14c5cf7b75
4
+ data.tar.gz: c42d2d4fd3d8f705e8f22b25cee68cf8ef57f472
5
5
  SHA512:
6
- metadata.gz: f21e1917137c223fa4d35a3ead85aa4f36d11729d4e844702953461d6b5dffff83eb361bf4d5046e73e2a93191385af959ccedfd4f496bceb14a740f6251cd23
7
- data.tar.gz: 986aa3bee41487e0e451049225482424236a20549a5d315d049cbdfc20db7b211d635fb78e9087de44293ade39ca30ac363c81123a0994c187c67f7097c1a2a6
6
+ metadata.gz: 94d074d217a93397af2d48c0beec74f4b24db070a730100e47fad5c3470449bd441a0294a51f4ee26d7766c4b991b37c95cd0fae6b01a56564729dd51f936c46
7
+ data.tar.gz: f70fc70d36c8dbf3706c664122d24483a21f8e3c04bd4be5ce1cca39740f359cf1c33c2a989df6e12cfc1a18cfd10d2d3bbcf81d829329c125af9b27a457156e
@@ -8,7 +8,7 @@ grammar Eqn
8
8
  end
9
9
 
10
10
  rule expression
11
- multitive addsub_group? <Eqn::Expression>
11
+ space? multitive space? addsub_group? space? <Eqn::Expression>
12
12
  end
13
13
 
14
14
  rule addsub_group
@@ -16,19 +16,19 @@ grammar Eqn
16
16
  end
17
17
 
18
18
  rule multitive
19
- exponentiative muldiv_group? <Eqn::Expression>
19
+ exponentiative space? muldiv_group? <Eqn::Expression>
20
20
  end
21
21
 
22
22
  rule muldiv_group
23
- muldiv_op multitive <Eqn::Expression::ExprGroup>
23
+ muldiv_op space? multitive <Eqn::Expression::ExprGroup>
24
24
  end
25
25
 
26
26
  rule exponentiative
27
- operand pow_group? <Eqn::Expression>
27
+ operand space? pow_group? <Eqn::Expression>
28
28
  end
29
29
 
30
30
  rule pow_group
31
- pow_op exponentiative <Eqn::Expression::ExprGroup>
31
+ pow_op space? exponentiative <Eqn::Expression::ExprGroup>
32
32
  end
33
33
 
34
34
  rule operand
@@ -40,19 +40,19 @@ grammar Eqn
40
40
  end
41
41
 
42
42
  rule if_func
43
- 'if' '(' comparation ',' expression ',' expression ')' <Eqn::Function::If>
43
+ 'if' space? '(' comparation ',' expression ',' expression ')' <Eqn::Function::If>
44
44
  end
45
45
 
46
46
  rule round_func
47
- 'round' group <Eqn::Function::Round>
47
+ 'round' space? group <Eqn::Function::Round>
48
48
  end
49
49
 
50
50
  rule roundup_func
51
- 'roundup' group <Eqn::Function::RoundUp>
51
+ 'roundup' space? group <Eqn::Function::RoundUp>
52
52
  end
53
53
 
54
54
  rule rounddown_func
55
- 'rounddown' group <Eqn::Function::RoundDown>
55
+ 'rounddown' space? group <Eqn::Function::RoundDown>
56
56
  end
57
57
 
58
58
  rule group
@@ -60,11 +60,11 @@ grammar Eqn
60
60
  end
61
61
 
62
62
  rule number
63
- signed_float exponent? <Eqn::Number>
63
+ signed_float space? exponent? <Eqn::Number>
64
64
  end
65
65
 
66
66
  rule signed_float
67
- sign? digits? decimal? <Eqn::Number::SignedNumber>
67
+ sign? space? digits? decimal? <Eqn::Number::SignedNumber>
68
68
  end
69
69
 
70
70
  rule decimal
@@ -72,7 +72,7 @@ grammar Eqn
72
72
  end
73
73
 
74
74
  rule exponent
75
- exp signed_float <Eqn::Number::Exponent>
75
+ exp space? signed_float <Eqn::Number::Exponent>
76
76
  end
77
77
 
78
78
  rule pow_op
@@ -110,4 +110,8 @@ grammar Eqn
110
110
  rule digits
111
111
  [0-9]+ <Eqn::Terminal::Digits>
112
112
  end
113
+
114
+ rule space
115
+ ("\s" / "\t")*
116
+ end
113
117
  end
@@ -10,7 +10,7 @@ module Eqn
10
10
  def valid?(data)
11
11
  calc(data)
12
12
  true
13
- rescue Exception
13
+ rescue ParseError, ZeroDivisionError
14
14
  false
15
15
  end
16
16
  end
@@ -9,6 +9,7 @@ module Eqn
9
9
  base
10
10
  end
11
11
 
12
+ # rubocop:disable Metrics/AbcSize
12
13
  class SignedNumber < Node
13
14
  def value
14
15
  # Store sign if any.
@@ -0,0 +1 @@
1
+ class ParseError < StandardError; end
@@ -2,32 +2,23 @@ require 'eqn/function'
2
2
  require 'eqn/comparation'
3
3
  require 'eqn/expression'
4
4
  require 'eqn/number'
5
+ require 'eqn/parse_error'
5
6
  require 'eqn/terminal'
6
7
 
7
8
  module Eqn
8
- WHITESPACE_REGEX = /([^0-9]( )+[^0-9|.])|([^0-9]( )+[0-9|.])|([0-9]( )+[^0-9|.])/
9
-
10
9
  class Parser
11
10
  # Load the Treetop grammar from the grammar.
12
11
  Treetop.load(File.join(File.dirname(__dir__), 'eqn.treetop'))
13
12
  @@parser = EqnParser.new
14
13
 
15
14
  def self.parse(data)
16
- # Remove any whitespace and pass the data over to the parser instance.
17
- data.downcase!
18
- while data =~ Eqn::WHITESPACE_REGEX
19
- data = data.downcase.gsub(Eqn::WHITESPACE_REGEX) do
20
- Regexp.last_match.to_s.delete(' ')
21
- end
22
- end
23
- tree = @@parser.parse(data)
15
+ # Pass the data over to the parser instance.
16
+ tree = @@parser.parse(data.downcase)
24
17
 
25
18
  # Raise any errors.
26
- if tree.nil?
27
- fail Exception, "Parse error at offset: #{@@parser.index}" + @@parser.failure_reason
28
- end
19
+ fail ParseError, "Parse error at offset: #{@@parser.index}" + @@parser.failure_reason if tree.nil?
29
20
 
30
- # Remove extraneous nodes and return the tree.
21
+ # Remove extraneous nodes and return tree.
31
22
  clean_tree(tree)
32
23
  end
33
24
 
@@ -1,3 +1,3 @@
1
1
  module Eqn
2
- VERSION = '1.0.7'
2
+ VERSION = '1.1.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eqn
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Schneider
@@ -106,6 +106,7 @@ files:
106
106
  - lib/eqn/expression.rb
107
107
  - lib/eqn/function.rb
108
108
  - lib/eqn/number.rb
109
+ - lib/eqn/parse_error.rb
109
110
  - lib/eqn/parser.rb
110
111
  - lib/eqn/terminal.rb
111
112
  - lib/eqn/version.rb