Skip to content

Commit

Permalink
Merge pull request #13 from JunNishimura/change_symbol_for_equation
Browse files Browse the repository at this point in the history
change equation symbol
  • Loading branch information
JunNishimura authored Sep 26, 2024
2 parents 9f0f292 + 6bec5ab commit 14db100
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion evaluator/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ var builtins = map[string]*object.Builtin{
return &object.Integer{Value: result}
},
},
"=": {
"==": {
Fn: func(args ...object.Object) object.Object {
if len(args) <= 1 {
return newError("number of arguments to '=' must be more than 1, got %d", len(args))
Expand Down
4 changes: 2 additions & 2 deletions evaluator/evaluator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func TestEvalBooleanExpression(t *testing.T) {
input: `
{
"command": {
"symbol": "=",
"symbol": "==",
"args": [true, true]
}
}`,
Expand All @@ -162,7 +162,7 @@ func TestEvalBooleanExpression(t *testing.T) {
input: `
{
"command": {
"symbol": "=",
"symbol": "==",
"args": [true, false]
}
}`,
Expand Down
9 changes: 8 additions & 1 deletion lexer/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,14 @@ func (l *Lexer) NextToken() token.Token {
case '/':
tok = newToken(token.SYMBOL, l.curChar)
case '=':
tok = newToken(token.SYMBOL, l.curChar)
if l.peekChar() == '=' {
ch := l.curChar
l.readChar()
literal := string(ch) + string(l.curChar)
tok = token.Token{Type: token.SYMBOL, Literal: literal}
} else {
tok = newToken(token.SYMBOL, l.curChar)
}
case '!':
if l.peekChar() == '=' {
ch := l.curChar
Expand Down
4 changes: 2 additions & 2 deletions lexer/lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func TestSingleProgram(t *testing.T) {
input: `
{
"command": {
"symbol": "=",
"symbol": "==",
"args": [1, 2]
}
}`,
Expand All @@ -235,7 +235,7 @@ func TestSingleProgram(t *testing.T) {
{Type: token.DOUBLE_QUOTE, Literal: "\""},
{Type: token.COLON, Literal: ":"},
{Type: token.DOUBLE_QUOTE, Literal: "\""},
{Type: token.SYMBOL, Literal: "="},
{Type: token.SYMBOL, Literal: "=="},
{Type: token.DOUBLE_QUOTE, Literal: "\""},
{Type: token.COMMA, Literal: ","},
{Type: token.DOUBLE_QUOTE, Literal: "\""},
Expand Down
12 changes: 6 additions & 6 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,15 @@ func TestCommand(t *testing.T) {
input: `
{
"command": {
"symbol": "=",
"symbol": "==",
"args": [1, 2]
}
}`,
expected: &ast.CommandObject{
Token: token.Token{Type: token.COMMAND, Literal: "command"},
Symbol: &ast.Symbol{
Token: token.Token{Type: token.SYMBOL, Literal: "="},
Value: "=",
Token: token.Token{Type: token.SYMBOL, Literal: "=="},
Value: "==",
},
Args: []ast.Expression{
&ast.IntegerLiteral{
Expand Down Expand Up @@ -434,7 +434,7 @@ func TestIfExpression(t *testing.T) {
"if": {
"cond": {
"command": {
"symbol": "=",
"symbol": "==",
"args": [1, 2]
}
},
Expand All @@ -457,8 +457,8 @@ func TestIfExpression(t *testing.T) {
Condition: &ast.CommandObject{
Token: token.Token{Type: token.COMMAND, Literal: "command"},
Symbol: &ast.Symbol{
Token: token.Token{Type: token.SYMBOL, Literal: "="},
Value: "=",
Token: token.Token{Type: token.SYMBOL, Literal: "=="},
Value: "==",
},
Args: []ast.Expression{
&ast.IntegerLiteral{
Expand Down

0 comments on commit 14db100

Please sign in to comment.