rbscmlex 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/rbscmlex.rb +5 -0
- data/lib/rbscmlex/lexer.rb +40 -6
- data/lib/rbscmlex/version.rb +2 -2
- 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: 23174f34d0abd8999a84dcbe74b96fb7042143b619d028c8cb96f2e5a07b1ef2
|
4
|
+
data.tar.gz: 85d495b784530ae42e435ccf9c47adb274ca3eb4d635fb64b41e1843bafc4687
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 984827b5d264e2b8f51b3582b3cb46ff595f1a50e965ecc67e16fd9650932107f1c7a570040faf105d2d9aed0d9463ac7c3b4f46dc7ee3b8a4f56bc99ada9589
|
7
|
+
data.tar.gz: a98522d875d75c8136fc4507a54ed737d461183c59e263b2a0dc5fa4034078da042e5ef70d0f9c1672fbd1c6322f938455921d42957d3085fa9df506d6580494
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
|
|
7
7
|
## [Unreleased]
|
8
8
|
- (nothing to record here)
|
9
9
|
|
10
|
+
## [0.1.4] - 2021-05-23
|
11
|
+
### Fixed
|
12
|
+
- Fix issue #7: cannot tokenize a string contains any spaces.
|
13
|
+
|
10
14
|
## [0.1.3] - 2021-05-15
|
11
15
|
### Added
|
12
16
|
- Add `Lexer#skip_token(offset)`
|
data/lib/rbscmlex.rb
CHANGED
data/lib/rbscmlex/lexer.rb
CHANGED
@@ -169,8 +169,6 @@ module Rbscmlex
|
|
169
169
|
raise StopIteration if (@next_pos + offset) >= size
|
170
170
|
end
|
171
171
|
|
172
|
-
# :stopdoc:
|
173
|
-
|
174
172
|
S2R_MAP = { "(" => "( ", ")" => " ) ", "'" => " ' " }
|
175
173
|
|
176
174
|
BOOLEAN = /\A#(f(alse)?|t(rue)?)\Z/
|
@@ -197,12 +195,10 @@ module Rbscmlex
|
|
197
195
|
CHAR_PAT = "(#{SINGLE_CHAR_PAT}|#{SPACE_PAT}|#{NEWLINE_PAT})"
|
198
196
|
CHAR = Regexp.new("\\A#{CHAR_PREFIX}#{CHAR_PAT}\\Z")
|
199
197
|
|
200
|
-
# :startdoc:
|
201
|
-
|
202
198
|
def tokenize(src)
|
203
|
-
cooked = src.gsub(/[()']/, S2R_MAP)
|
199
|
+
cooked = src.gsub(/[()']/, S2R_MAP).strip
|
204
200
|
|
205
|
-
cooked
|
201
|
+
split_at_space(cooked).map { |literal|
|
206
202
|
case literal
|
207
203
|
when "("
|
208
204
|
Rbscmlex.new_token(:lparen, literal)
|
@@ -234,6 +230,44 @@ module Rbscmlex
|
|
234
230
|
}
|
235
231
|
end
|
236
232
|
|
233
|
+
def split_at_space(source)
|
234
|
+
escaped = false
|
235
|
+
in_string = false
|
236
|
+
after_space = false
|
237
|
+
slice = String.new # an empty string
|
238
|
+
results = []
|
239
|
+
source.each_char { |rune|
|
240
|
+
case rune
|
241
|
+
when "\\"
|
242
|
+
slice << rune
|
243
|
+
escaped = !escaped if in_string
|
244
|
+
after_space = false
|
245
|
+
when '"'
|
246
|
+
if !in_string or !escaped
|
247
|
+
in_string = !in_string
|
248
|
+
end
|
249
|
+
slice << rune
|
250
|
+
escaped = false
|
251
|
+
after_space = false
|
252
|
+
when /[\s]/
|
253
|
+
if in_string
|
254
|
+
slice << rune
|
255
|
+
elsif !after_space
|
256
|
+
results << slice.dup
|
257
|
+
slice.clear
|
258
|
+
end
|
259
|
+
escaped = false
|
260
|
+
after_space = true
|
261
|
+
else
|
262
|
+
slice << rune
|
263
|
+
escaped = false
|
264
|
+
after_space = false
|
265
|
+
end
|
266
|
+
}
|
267
|
+
results << slice unless slice.empty?
|
268
|
+
results
|
269
|
+
end
|
270
|
+
|
237
271
|
# Holds functions to check a literal is valid as an identifier
|
238
272
|
# defined in R7RS.
|
239
273
|
#
|
data/lib/rbscmlex/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbscmlex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mnbi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-05-
|
11
|
+
date: 2021-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A simple lexical analyzer for Scheme
|
14
14
|
email:
|