Keywords and identifiers
This commit is contained in:
parent
cdab15193a
commit
fd21194901
3 changed files with 46 additions and 0 deletions
|
|
@ -108,6 +108,10 @@ func (s *Scanner) scanToken() {
|
|||
s.scanNumber()
|
||||
return
|
||||
}
|
||||
if isIdentAlpha(c) {
|
||||
s.scanIdentifier()
|
||||
return
|
||||
}
|
||||
lerrors.EmitError(s.line, "Unexpected character.")
|
||||
}
|
||||
}
|
||||
|
|
@ -201,6 +205,18 @@ func (s *Scanner) scanNumber() {
|
|||
)
|
||||
}
|
||||
|
||||
func (s *Scanner) scanIdentifier() {
|
||||
for isIdentAlphaNumeric(s.peek()) {
|
||||
s.advance()
|
||||
}
|
||||
l := s.source[s.start:s.current]
|
||||
typ := IDENT
|
||||
if kTyp, ok := KeywordTypes[l]; ok {
|
||||
typ = kTyp
|
||||
}
|
||||
s.addToken(typ)
|
||||
}
|
||||
|
||||
// addToken produces a single token without a literal value.
|
||||
func (s *Scanner) addToken(typ TokenType) {
|
||||
s.addTokenWithLiteral(typ, nil)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue