Selaa lähdekoodia

Lex identifiers

master
Dylan Baker 6 vuotta sitten
vanhempi
commit
f2495f89f7
2 muutettua tiedostoa jossa 9 lisäystä ja 0 poistoa
  1. 3
    0
      lib/chervil/lexer.rb
  2. 6
    0
      spec/lexer_spec.rb

+ 3
- 0
lib/chervil/lexer.rb Näytä tiedosto

31
         if match = source.match(/^[0-9]+(\.[0-9]+)?/)
31
         if match = source.match(/^[0-9]+(\.[0-9]+)?/)
32
           advance(match[0].size)
32
           advance(match[0].size)
33
           Token.new(:number, match[0])
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
         end
37
         end
35
       end
38
       end
36
     end
39
     end

+ 6
- 0
spec/lexer_spec.rb Näytä tiedosto

28
         ]
28
         ]
29
       )
29
       )
30
     end
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
   end
37
   end
32
 end
38
 end

Loading…
Peruuta
Tallenna