From 9232432c359c7afbb6250d76e445c205d991b711 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Thu, 25 Aug 2022 00:05:40 -0400 Subject: [PATCH] Implemented thos bad boys --- lexer/lexer.go | 23 +++++++++++++++++++++-- lexer/lexer_test.go | 6 +++--- tests/lexer/all.arf | 2 +- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/lexer/lexer.go b/lexer/lexer.go index cfa0543..b3a50ac 100644 --- a/lexer/lexer.go +++ b/lexer/lexer.go @@ -242,9 +242,15 @@ func (lexer *LexingOperation) tokenizeSymbolBeginning () (err error) { err = lexer.nextRune() case '!': token := lexer.newToken() - token.kind = TokenKindExclamation - lexer.addToken(token) err = lexer.nextRune() + if err != nil { return } + token.kind = TokenKindExclamation + if lexer.char == '=' { + token.kind = TokenKindNotEqualTo + err = lexer.nextRune() + token.location.SetWidth(2) + } + lexer.addToken(token) case '%': token := lexer.newToken() token.kind = TokenKindPercent @@ -255,6 +261,11 @@ func (lexer *LexingOperation) tokenizeSymbolBeginning () (err error) { token.kind = TokenKindTilde lexer.addToken(token) err = lexer.nextRune() + case '=': + token := lexer.newToken() + token.kind = TokenKindEqualTo + lexer.addToken(token) + err = lexer.nextRune() case '<': token := lexer.newToken() err = lexer.nextRune() @@ -264,6 +275,10 @@ func (lexer *LexingOperation) tokenizeSymbolBeginning () (err error) { token.kind = TokenKindLShift err = lexer.nextRune() token.location.SetWidth(2) + } else if lexer.char == '=' { + token.kind = TokenKindLessThanEqualTo + err = lexer.nextRune() + token.location.SetWidth(2) } lexer.addToken(token) case '>': @@ -275,6 +290,10 @@ func (lexer *LexingOperation) tokenizeSymbolBeginning () (err error) { token.kind = TokenKindRShift err = lexer.nextRune() token.location.SetWidth(2) + } else if lexer.char == '=' { + token.kind = TokenKindGreaterThanEqualTo + err = lexer.nextRune() + token.location.SetWidth(2) } lexer.addToken(token) case '|': diff --git a/lexer/lexer_test.go b/lexer/lexer_test.go index 6f2aec1..e77d9f5 100644 --- a/lexer/lexer_test.go +++ b/lexer/lexer_test.go @@ -154,12 +154,12 @@ func TestTokenizeAll (test *testing.T) { quickToken(1, TokenKindPercent, nil), quickToken(1, TokenKindTilde, nil), quickToken(1, TokenKindEqualTo, nil), - quickToken(1, TokenKindNotEqualTo, nil), + quickToken(2, TokenKindNotEqualTo, nil), quickToken(1, TokenKindLessThan, nil), - quickToken(1, TokenKindLessThanEqualTo, nil), + quickToken(2, TokenKindLessThanEqualTo, nil), quickToken(2, TokenKindLShift, nil), quickToken(1, TokenKindGreaterThan, nil), - quickToken(1, TokenKindGreaterThanEqualTo, nil), + quickToken(2, TokenKindGreaterThanEqualTo, nil), quickToken(2, TokenKindRShift, nil), quickToken(1, TokenKindBinaryOr, nil), quickToken(2, TokenKindLogicalOr, nil), diff --git a/tests/lexer/all.arf b/tests/lexer/all.arf index 07e0298..51ae12e 100644 --- a/tests/lexer/all.arf +++ b/tests/lexer/all.arf @@ -1,3 +1,3 @@ :arf --- rw -> -349820394 932748397 239485.37520 "hello world!\n" 'E' helloWorld:.,..[]{} -+ - ++ -- * / @ ! % ~ = != < <= << > => >> | || & && ++ - ++ -- * / @ ! % ~ = != < <= << > >= >> | || & &&