-
Notifications
You must be signed in to change notification settings - Fork 0
/
tokenize-numeric.go
39 lines (38 loc) · 1.14 KB
/
tokenize-numeric.go
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
34
35
36
37
38
39
package lexer
func (lexer *Lexer) tokenizeNumeric() error {
if !lexer.reader.HasNext() {
lexer.currentToken.Kind = Literal
lexer.currentToken.DirectValue = Integer
return nil
}
nextChar := lexer.reader.Char()
lexer.reader.Next()
if lexer.currentToken.Contents[0] == '0' {
switch nextChar {
case 'x', 'X': // Hexadecimal
lexer.currentToken.append(nextChar)
return lexer.tokenizeHexadecimal()
case 'b', 'B': // Binary
lexer.currentToken.append(nextChar)
return lexer.tokenizeBinary()
case 'o', 'O': // Octal
lexer.currentToken.append(nextChar)
return lexer.tokenizeOctal()
}
}
switch nextChar {
case 'e', 'E': // Scientific float
lexer.currentToken.append(nextChar)
return lexer.tokenizeScientificFloat()
case '.': // Maybe a float
lexer.currentToken.append(nextChar)
return lexer.tokenizeFloat() // Integer, Float Or Scientific Float
case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '_':
lexer.currentToken.append(nextChar)
return lexer.tokenizeInteger() // Integer, Float or Scientific Float
}
lexer.reader.Redo()
lexer.currentToken.Kind = Literal
lexer.currentToken.DirectValue = Integer
return nil
}