Skip to content

Commit

Permalink
Merge pull request #1764 from xushiwei/q
Browse files Browse the repository at this point in the history
binaryOp: -> <>
  • Loading branch information
xushiwei committed Feb 21, 2024
2 parents 8bb1dc7 + cfc47fe commit 98e689b
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 1 deletion.
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

0 comments on commit 98e689b

Please sign in to comment.