Implemented unary operator parsing

This commit is contained in:
2024-07-27 12:49:39 +02:00
parent d001e4e55f
commit 944bacf4e1
8 changed files with 142 additions and 16 deletions

View File

@ -26,8 +26,28 @@ func Tokenize(buffer []byte) List {
tokens = append(tokens, Token{Kind: ArrayEnd, Position: i, Length: 1})
case '\n':
tokens = append(tokens, Token{Kind: NewLine, Position: i, Length: 1})
case '-':
if len(tokens) == 0 || tokens[len(tokens)-1].IsOperator() || tokens[len(tokens)-1].IsExpressionStart() {
tokens = append(tokens, Token{Kind: Negate, Position: i, Length: 1})
} else {
if i+1 < Position(len(buffer)) && buffer[i+1] == '=' {
tokens = append(tokens, Token{Kind: SubAssign, Position: i, Length: 2})
i++
} else {
tokens = append(tokens, Token{Kind: Sub, Position: i, Length: 1})
}
}
case '/':
if i+1 >= Position(len(buffer)) || buffer[i+1] != '/' {
if i+1 < Position(len(buffer)) && buffer[i+1] == '/' {
position := i
for i < Position(len(buffer)) && buffer[i] != '\n' {
i++
}
tokens = append(tokens, Token{Kind: Comment, Position: position, Length: Length(i - position)})
} else {
position := i
i++
@ -45,14 +65,6 @@ func Tokenize(buffer []byte) List {
}
tokens = append(tokens, Token{Kind: kind, Position: position, Length: Length(i - position)})
} else {
position := i
for i < Position(len(buffer)) && buffer[i] != '\n' {
i++
}
tokens = append(tokens, Token{Kind: Comment, Position: position, Length: Length(i - position)})
}
continue