keisan 0.8.3 → 0.8.4
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/lib/keisan/string_and_group_parser.rb +37 -1
- data/lib/keisan/tokenizer.rb +4 -15
- data/lib/keisan/version.rb +1 -1
- 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: de85515fc642eede46d24bdb2347a7f8bbe32c4d317fd305404c08367e742ecf
|
4
|
+
data.tar.gz: 0ce75e5555ca880e690e1cae4b76820594899706aa5608944fa5c9eedd0be9c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/keisan/tokenizer.rb
CHANGED
@@ -24,9 +24,11 @@ module Keisan
|
|
24
24
|
attr_reader :expression, :tokens
|
25
25
|
|
26
26
|
def initialize(expression)
|
27
|
-
@expression =
|
27
|
+
@expression = expression
|
28
28
|
|
29
|
-
portions = StringAndGroupParser.new(
|
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?}
|
data/lib/keisan/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2020-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cmath
|