Added short form for variable definitions

This commit is contained in:
2024-06-14 18:03:54 +02:00
parent 6de8ac7b9f
commit 65791ea5a1
6 changed files with 76 additions and 33 deletions

View File

@ -2,6 +2,5 @@ package token
// Keywords defines the keywords used in the language.
var Keywords = map[string]bool{
"let": true,
"return": true,
}

View File

@ -13,7 +13,7 @@ func (list List) String() string {
var last Token
for _, t := range list {
if last.Kind == Keyword || last.Kind == Separator {
if last.Kind == Keyword || last.Kind == Separator || last.Kind == Operator || t.Kind == Operator {
builder.WriteByte(' ')
}

View File

@ -70,9 +70,6 @@ func Tokenize(buffer []byte) List {
case ']':
tokens = append(tokens, Token{ArrayEnd, i, arrayEndBytes})
case '=', ':', '+', '-', '*', '/', '<', '>', '!':
tokens = append(tokens, Token{Operator, i, buffer[i : i+1]})
// Separator
case ',':
tokens = append(tokens, Token{Separator, i, separatorBytes})
@ -122,6 +119,24 @@ func Tokenize(buffer []byte) List {
continue
}
// Operators
if isOperator(buffer[i]) {
position := i
i++
for i < len(buffer) && isOperator(buffer[i]) {
i++
}
tokens = append(tokens, Token{
Operator,
position,
buffer[position:i],
})
continue
}
}
i++