Repository: goplus/gop
Pull request #1764 (2024-02-21 11:47:53)

binaryOp: -> <>


Patch:
diff --git a/parser/parser.go b/parser/parser.go
index 734bd439..3ba5006a 100644
--- a/parser/parser.go
+++ b/parser/parser.go
@@ -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, // *=
diff --git a/token/token.go b/token/token.go
index e10ce5f0..a0b31993 100644
--- a/token/token.go
+++ b/token/token.go
@@ -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


Test patch:
diff --git a/parser/_testdata/arrowop/arrowop.gop b/parser/_testdata/arrowop/arrowop.gop
new file mode 100644
index 00000000..6c73c969
--- /dev/null
+++ b/parser/_testdata/arrowop/arrowop.gop
@@ -0,0 +1,4 @@
+echo 1+a -> b
+echo a <> b+1
+echo a -> b
+echo a <> b, "Hi"
diff --git a/parser/_testdata/arrowop/parser.expect b/parser/_testdata/arrowop/parser.expect
new file mode 100644
index 00000000..e70f1308
--- /dev/null
+++ b/parser/_testdata/arrowop/parser.expect
@@ -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"