keisan 0.8.3 → 0.8.4

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: d96dbb0d0fa1401f10443f46ce6fd273c2a370155a25f8b248f8f387d20c039f
4
- data.tar.gz: a02847f4342e2dc70335a7489772a71f5d17dd70b1f6f9f0a845a9bb6e2be40a
3
+ metadata.gz: de85515fc642eede46d24bdb2347a7f8bbe32c4d317fd305404c08367e742ecf
4
+ data.tar.gz: 0ce75e5555ca880e690e1cae4b76820594899706aa5608944fa5c9eedd0be9c8
5
5
  SHA512:
6
- metadata.gz: fd68bfc3f9722a21419fc47c66a92abdfab529be641ea6e2c39385b8f3d014736a5ce9d7ad679554abae9d29c9ce03e1fb37ef0cd806b17f0fa6608aa82491f9
7
- data.tar.gz: 242f78fc02f1c45673d977b505ec7f933cb11b5d098f8895c741fa0b8821640badab1046190935996c850296014ab0685864ec2a92bdb951f096c961eadfb2cd
6
+ metadata.gz: cd6b7cee90edee2d0ba51eb6b4d0a223305eeaf75a85ec6c2c6dbd9c3310ecd035c00d4a86d16768303f28d61996291e6e4d3ac7e5323a3a4df0c22f6343ff58
7
+ data.tar.gz: '05873d8324f622a818f5cba2b9ef260e61f3500154db3ab0ecb9570bf308a686f4b32eddcbfb664afab76845fe71da7c82f47dd511f845f33498045011024a8a'
@@ -129,7 +129,7 @@ module Keisan
129
129
 
130
130
  while index < expression.size
131
131
  case expression[index]
132
- when STRING_CHARACTER_REGEX, OPEN_GROUP_REGEX, CLOSED_GROUP_REGEX
132
+ when STRING_CHARACTER_REGEX, OPEN_GROUP_REGEX, CLOSED_GROUP_REGEX, COMMENT_CHARACTER_REGEX
133
133
  break
134
134
  else
135
135
  index += 1
@@ -149,9 +149,40 @@ module Keisan
149
149
  end
150
150
  end
151
151
 
152
+ class CommentPortion < Portion
153
+ attr_reader :string
154
+
155
+ def initialize(expression, start_index)
156
+ super(start_index)
157
+
158
+ if expression[start_index] != '#'
159
+ raise Keisan::Exceptions::TokenizingError.new("Comment should start with '#'")
160
+ else
161
+ index = start_index + 1
162
+ end
163
+
164
+ while index < expression.size
165
+ break if expression[index] == "\n"
166
+ index += 1
167
+ end
168
+
169
+ @end_index = index
170
+ @string = expression[start_index...end_index]
171
+ end
172
+
173
+ def size
174
+ string.size
175
+ end
176
+
177
+ def to_s
178
+ string
179
+ end
180
+ end
181
+
152
182
  # An ordered array of "portions", which
153
183
  attr_reader :portions, :size
154
184
 
185
+ COMMENT_CHARACTER_REGEX = /[#]/
155
186
  STRING_CHARACTER_REGEX = /["']/
156
187
  OPEN_GROUP_REGEX = /[\(\{\[]/
157
188
  CLOSED_GROUP_REGEX = /[\)\}\]]/
@@ -176,6 +207,11 @@ module Keisan
176
207
  when CLOSED_GROUP_REGEX
177
208
  raise Keisan::Exceptions::TokenizingError.new("Tokenizing error, unexpected closing brace #{expression[start_index]}")
178
209
 
210
+ when COMMENT_CHARACTER_REGEX
211
+ portion = CommentPortion.new(expression, index)
212
+ index += portion.size
213
+ @portions << portion
214
+
179
215
  else
180
216
  portion = OtherPortion.new(expression, index)
181
217
  index += portion.size
@@ -24,9 +24,11 @@ module Keisan
24
24
  attr_reader :expression, :tokens
25
25
 
26
26
  def initialize(expression)
27
- @expression = self.class.normalize_expression(expression)
27
+ @expression = expression
28
28
 
29
- portions = StringAndGroupParser.new(@expression).portions
29
+ portions = StringAndGroupParser.new(expression).portions.reject do |portion|
30
+ portion.is_a? StringAndGroupParser::CommentPortion
31
+ end
30
32
 
31
33
  @tokens = portions.inject([]) do |tokens, portion|
32
34
  case portion
@@ -43,21 +45,8 @@ module Keisan
43
45
  end
44
46
  end
45
47
 
46
- def self.normalize_expression(expression)
47
- expression = normalize_line_delimiters(expression)
48
- expression = remove_comments(expression)
49
- end
50
-
51
48
  private
52
49
 
53
- def self.normalize_line_delimiters(expression)
54
- expression.gsub(/\n/, ";")
55
- end
56
-
57
- def self.remove_comments(expression)
58
- expression.gsub(/#[^;]*/, "")
59
- end
60
-
61
50
  def tokenize!(scan)
62
51
  scan.map do |scan_result|
63
52
  i = scan_result.find_index {|token| !token.nil?}
@@ -1,3 +1,3 @@
1
1
  module Keisan
2
- VERSION = "0.8.3"
2
+ VERSION = "0.8.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keisan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.3
4
+ version: 0.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Locke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-18 00:00:00.000000000 Z
11
+ date: 2020-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cmath