Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

binaryOp: -> <> #1764

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions parser/_testdata/arrowop/arrowop.gop
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
echo 1+a -> b
echo a <> b+1
echo a -> b
echo a <> b, "Hi"
92 changes: 92 additions & 0 deletions parser/_testdata/arrowop/parser.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package main

file arrowop.gop
noEntrypoint
ast.FuncDecl:
Name:
ast.Ident:
Name: main
Type:
ast.FuncType:
Params:
ast.FieldList:
Body:
ast.BlockStmt:
List:
ast.ExprStmt:
X:
ast.CallExpr:
Fun:
ast.Ident:
Name: echo
Args:
ast.BinaryExpr:
X:
ast.BinaryExpr:
X:
ast.BasicLit:
Kind: INT
Value: 1
Op: +
Y:
ast.Ident:
Name: a
Op: ->
Y:
ast.Ident:
Name: b
ast.ExprStmt:
X:
ast.CallExpr:
Fun:
ast.Ident:
Name: echo
Args:
ast.BinaryExpr:
X:
ast.Ident:
Name: a
Op: <>
Y:
ast.BinaryExpr:
X:
ast.Ident:
Name: b
Op: +
Y:
ast.BasicLit:
Kind: INT
Value: 1
ast.ExprStmt:
X:
ast.CallExpr:
Fun:
ast.Ident:
Name: echo
Args:
ast.BinaryExpr:
X:
ast.Ident:
Name: a
Op: ->
Y:
ast.Ident:
Name: b
ast.ExprStmt:
X:
ast.CallExpr:
Fun:
ast.Ident:
Name: echo
Args:
ast.BinaryExpr:
X:
ast.Ident:
Name: a
Op: <>
Y:
ast.Ident:
Name: b
ast.BasicLit:
Kind: STRING
Value: "Hi"
3 changes: 3 additions & 0 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,9 @@ var overloadOps = [...]byte{
token.SHR: opBinary, // >>
token.AND_NOT: opBinary, // &^

token.SRARROW: opBinary, // ->
token.BIDIARROW: opBinary, // <>

token.ADD_ASSIGN: opAssignOp, // +=
token.SUB_ASSIGN: opAssignOp, // -=
token.MUL_ASSIGN: opAssignOp, // *=
Expand Down
2 changes: 1 addition & 1 deletion token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func (op Token) Precedence() int {
return 1
case LAND:
return 2
case EQL, NEQ, LSS, LEQ, GTR, GEQ:
case EQL, NEQ, LSS, LEQ, GTR, GEQ, SRARROW, BIDIARROW:
return 3
case ADD, SUB, OR, XOR:
return 4
Expand Down