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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2860b1b9f6d206dcfacf04fba88a5c64e9670c97d42423d5fac78615c3609d3a
4
- data.tar.gz: c2ab02c9febc928efa76fa47aea965c27a53099b56ff55e180304988f9eea062
3
+ metadata.gz: 23174f34d0abd8999a84dcbe74b96fb7042143b619d028c8cb96f2e5a07b1ef2
4
+ data.tar.gz: 85d495b784530ae42e435ccf9c47adb274ca3eb4d635fb64b41e1843bafc4687
5
5
  SHA512:
6
- metadata.gz: 8a008f3c549e69bfa839d6788449704afb5b2491084eacde00ce1809769d4c65fffc4f22b0843c5b7522908891146f4ad4f227ef1ae67f1f07d0a33f97bbba3a
7
- data.tar.gz: 68e14c34c40ea2b4715a20d9cac1f56c6860eeb6d9d3c8e2d31b6addf66fb529217e88b272ef1ccc252cb52645fb41dc3d77a8c6d0eb5af902b936af7b851e87
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
@@ -5,4 +5,9 @@ module Rbscmlex
5
5
  require_relative "rbscmlex/token"
6
6
  require_relative "rbscmlex/lexer"
7
7
  require_relative "rbscmlex/version"
8
+
9
+ def self.lexer(source)
10
+ Lexer.new(source)
11
+ end
12
+
8
13
  end
@@ -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.split(" ").map { |literal|
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
  #
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rbscmlex
4
- VERSION = "0.1.3"
5
- RELEASE = "2021-05-15"
4
+ VERSION = "0.1.4"
5
+ RELEASE = "2021-05-23"
6
6
  end
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.3
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-15 00:00:00.000000000 Z
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: