-
Notifications
You must be signed in to change notification settings - Fork 22
/
atom.rb
33 lines (28 loc) · 813 Bytes
/
atom.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require 'sym'
module Tokens
class Atom
def self.expect(s)
tmp = ""
c = s.peek
return Sym.expect(s) if c == ?: # This is a hack. Shoud be handled separately
if c == ?@ || c == ?$
tmp << s.get
tmp << s.get if c == ?@ && s.peek == ?@
end
if (c = s.peek) && (c == ?_ || (?a .. ?z).member?(c) || (?A .. ?Z).member?(c))
tmp << s.get
while (c = s.peek) && (ALNUM.member?(c) || ?_ == c)
tmp << s.get
end
elsif tmp == "$"
tmp << s.get # FIXME: Need to check what characters are legal after $ (and not covered above)
return tmp.to_sym
end
if tmp.size > 0 && (s.peek == ?! || s.peek == ??)
tmp << s.get
end
return nil if tmp == ""
return tmp.to_sym
end
end
end