allow for single character identifiers
FossilOrigin-Name: 6f663cda900d2517ff10ddcf74b1e294e3f07cb415bf7d00157b36fe7c780b72
change qloyrxslwvmtsoxmxtzqprsumqnpkrwy
commit d5d0c91d6f489a476b21ce1fdaf701e987337ff8
author alpha <alpha@kejadlen.dev>
date
parent ytklozyy
diff --git a/ruby/lox.rb b/ruby/lox.rb
index 851d100..9ac7357 100755
--- a/ruby/lox.rb
+++ b/ruby/lox.rb
@@ -117,7 +117,7 @@ module Lox
           scan_str(state)
         when number = state.scan(/\d+(\.\d+)?/)
           state.add_token(:NUMBER, literal: number.to_f)
-        when identifier = state.scan(/[a-zA-Z_]\w+/)
+        when identifier = state.scan(/[a-zA-Z_]\w*/)
           type = KEYWORDS.fetch(identifier, :IDENTIFIER)
           state.add_token(type)
         else state.scan(/./) # keep scanning
diff --git a/ruby/test_lox.rb b/ruby/test_lox.rb
index a3ff067..6114659 100644
--- a/ruby/test_lox.rb
+++ b/ruby/test_lox.rb
@@ -111,8 +111,9 @@ class TestScanner < Minitest::Test
     assert_equal [
       Token.new(:OR, "or", nil, 1),
       Token.new(:IDENTIFIER, "orchid", nil, 1),
+      Token.new(:IDENTIFIER, "o", nil, 1),
       Token.new(:EOF, "", nil, 1),
-    ], @scanner.scan("or orchid")
+    ], @scanner.scan("or orchid o")
   end
 
   def test_block_comments