diff --git a/lexer/lexer.go b/lexer/lexer.go index 5063bd93..b9509e5b 100644 --- a/lexer/lexer.go +++ b/lexer/lexer.go @@ -21,7 +21,7 @@ func NewLineMode(input string) *Lexer { return &Lexer{input: input, lineMode: true} } -func (l *Lexer) NextToken() token.Token { //nolint:funlen // many cases to lex. +func (l *Lexer) NextToken() token.Token { //nolint:funlen,gocyclo // many cases to lex. l.skipWhitespace() ch := l.readChar() @@ -87,6 +87,10 @@ func (l *Lexer) NextToken() token.Token { //nolint:funlen // many cases to lex. case ']': return newToken(token.RBRACKET, ch) case ':': + if l.peekChar() == '=' { // semi hacky treat := as = (without changing literal etc so tests work with either) + nextChar := l.readChar() + return newToken(token.ASSIGN, nextChar) + } return newToken(token.COLON, ch) case '"': return token.Token{Type: token.STRING, Literal: l.readString()} diff --git a/lexer/lexer_test.go b/lexer/lexer_test.go index efd7aa2d..4e173877 100644 --- a/lexer/lexer_test.go +++ b/lexer/lexer_test.go @@ -35,6 +35,7 @@ a2=3 {"foo": "bar"} return // nil return macro(x, y) { x + y } +a3:=5 ` tests := []struct { @@ -142,6 +143,9 @@ macro(x, y) { x + y } {token.PLUS, "+"}, {token.IDENT, "y"}, {token.RBRACE, "}"}, + {token.IDENT, "a3"}, + {token.ASSIGN, "="}, // `:=` changed to `=`. + {token.INT, "5"}, {token.EOF, ""}, } diff --git a/repl/repl_test.go b/repl/repl_test.go index a1d30bfa..b99ee3d1 100644 --- a/repl/repl_test.go +++ b/repl/repl_test.go @@ -30,7 +30,7 @@ Factorial of 5 is 120` + " \n120\n" // there is an extra space before \n that vs } func TestEvalStringParsingError(t *testing.T) { - s := `x:=3` + s := `.` expected := "" res, errs := repl.EvalString(s) if len(errs) == 0 {