Procházet zdrojové kódy

Lex identifiers

master
Dylan Baker před 6 roky
rodič
revize
f2495f89f7
2 změnil soubory, kde provedl 9 přidání a 0 odebrání
  1. 3
    0
      lib/chervil/lexer.rb
  2. 6
    0
      spec/lexer_spec.rb

+ 3
- 0
lib/chervil/lexer.rb Zobrazit soubor

@@ -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 Zobrazit soubor

@@ -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

Načítá se…
Zrušit
Uložit