Explorar el Código

Lex identifiers

master
Dylan Baker hace 5 años
padre
commit
f2495f89f7
Se han modificado 2 ficheros con 9 adiciones y 0 borrados
  1. 3
    0
      lib/chervil/lexer.rb
  2. 6
    0
      spec/lexer_spec.rb

+ 3
- 0
lib/chervil/lexer.rb Ver fichero

@@ -31,6 +31,9 @@ module Chervil
31 31
         if match = source.match(/^[0-9]+(\.[0-9]+)?/)
32 32
           advance(match[0].size)
33 33
           Token.new(:number, match[0])
34
+        elsif match = source.match(/^[a-z!$%&*\/:<=>?~_^][a-z0-9@!$%&*\/:<=>?~_^,+\-]*/)
35
+          advance(match[0].size)
36
+          Token.new(:identifier, match[0])
34 37
         end
35 38
       end
36 39
     end

+ 6
- 0
spec/lexer_spec.rb Ver fichero

@@ -28,5 +28,11 @@ module Chervil
28 28
         ]
29 29
       )
30 30
     end
31
+
32
+    it 'lexes identifiers' do
33
+      expect(Lexer.new('hello').get_next_token).to eq(
34
+        Token.new(:identifier, 'hello')
35
+      )
36
+    end
31 37
   end
32 38
 end

Loading…
Cancelar
Guardar