Something went wrong. Try again.
🌱 A minimal programming language and compiler. git.urbach.dev/cli/q
high-performance programming-language compiler
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273package token
// identifier handles all tokens that qualify as an identifier.func identifier(tokens List, buffer []byte, i Position) (List, Position) { position := i i++
for i < Position(len(buffer)) && isIdentifier(buffer[i]) { i++ }
identifier := buffer[position:i] kind := Identifier
switch string(identifier) { case "as": kind = Cast case "assert": kind = Assert case "cas": kind = Cas case "const": kind = Const case "delete": kind = Delete case "if": kind = If case "else": kind = Else case "extern": kind = Extern case "global": kind = Global case "go": kind = Go case "import": kind = Import case "local": kind = Local case "loop": kind = Loop case "new": kind = New case "return": kind = Return case "syscall": kind = Syscall case "switch": kind = Switch }
tokens = append(tokens, Token{Kind: kind, Position: position, Length: Length(len(identifier))}) return tokens, i}
// isIdentifier returns true if the character is a letter,// a digit or an underscore.func isIdentifier(c byte) bool { return isLetter(c) || isDigit(c) || c == '_'}
// isIdentifierStart returns true if the character is the// start of an identifier which is either a letter or an// underscore.func isIdentifierStart(c byte) bool { return isLetter(c) || c == '_'}
// isLetter returns true if the character is a lowercase// or uppercase letter in the English alphabet.func isLetter(c byte) bool { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')}