Repository: goplus/gop
Pull request #1112 (2022-01-21 12:56:29)

parser: fix funlit  command style single line
fix https://github.com/goplus/gop/issues/1110


Patch:
diff --git a/parser/parser.go b/parser/parser.go
index fab81edf..304387a6 100644
--- a/parser/parser.go
+++ b/parser/parser.go
@@ -1588,6 +1588,9 @@ func (p *parser) parseCallOrConversion(fun ast.Expr, isCmd bool) *ast.CallExpr {
 				break
 			}
 		}
+		if isCmd && p.tok == token.RBRACE {
+			break
+		}
 		if !p.atComma("argument list", endTok) {
 			break
 		}


Test patch:
diff --git a/parser/_testdata/cmdlinestyle4/cmd4.gop b/parser/_testdata/cmdlinestyle4/cmd4.gop
new file mode 100644
index 00000000..b1d457c4
--- /dev/null
+++ b/parser/_testdata/cmdlinestyle4/cmd4.gop
@@ -0,0 +1,5 @@
+func call(fn func(x int)) { fn(100) }
+
+call(func(x int) { println })
+call(func(x int) { println x })
+call(func(x int) { println {"x": 100, "y": 200}, x })
diff --git a/parser/_testdata/cmdlinestyle4/parser.expect b/parser/_testdata/cmdlinestyle4/parser.expect
new file mode 100644
index 00000000..faec429d
--- /dev/null
+++ b/parser/_testdata/cmdlinestyle4/parser.expect
@@ -0,0 +1,164 @@
+package main
+
+file cmd4.gop
+noEntrypoint
+ast.FuncDecl:
+  Name:
+    ast.Ident:
+      Name: call
+  Type:
+    ast.FuncType:
+      Params:
+        ast.FieldList:
+          List:
+            ast.Field:
+              Names:
+                ast.Ident:
+                  Name: fn
+              Type:
+                ast.FuncType:
+                  Params:
+                    ast.FieldList:
+                      List:
+                        ast.Field:
+                          Names:
+                            ast.Ident:
+                              Name: x
+                          Type:
+                            ast.Ident:
+                              Name: int
+  Body:
+    ast.BlockStmt:
+      List:
+        ast.ExprStmt:
+          X:
+            ast.CallExpr:
+              Fun:
+                ast.Ident:
+                  Name: fn
+              Args:
+                ast.BasicLit:
+                  Kind: INT
+                  Value: 100
+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: call
+              Args:
+                ast.FuncLit:
+                  Type:
+                    ast.FuncType:
+                      Params:
+                        ast.FieldList:
+                          List:
+                            ast.Field:
+                              Names:
+                                ast.Ident:
+                                  Name: x
+                              Type:
+                                ast.Ident:
+                                  Name: int
+                  Body:
+                    ast.BlockStmt:
+                      List:
+                        ast.ExprStmt:
+                          X:
+                            ast.Ident:
+                              Name: println
+        ast.ExprStmt:
+          X:
+            ast.CallExpr:
+              Fun:
+                ast.Ident:
+                  Name: call
+              Args:
+                ast.FuncLit:
+                  Type:
+                    ast.FuncType:
+                      Params:
+                        ast.FieldList:
+                          List:
+                            ast.Field:
+                              Names:
+                                ast.Ident:
+                                  Name: x
+                              Type:
+                                ast.Ident:
+                                  Name: int
+                  Body:
+                    ast.BlockStmt:
+                      List:
+                        ast.ExprStmt:
+                          X:
+                            ast.CallExpr:
+                              Fun:
+                                ast.Ident:
+                                  Name: println
+                              Args:
+                                ast.Ident:
+                                  Name: x
+        ast.ExprStmt:
+          X:
+            ast.CallExpr:
+              Fun:
+                ast.Ident:
+                  Name: call
+              Args:
+                ast.FuncLit:
+                  Type:
+                    ast.FuncType:
+                      Params:
+                        ast.FieldList:
+                          List:
+                            ast.Field:
+                              Names:
+                                ast.Ident:
+                                  Name: x
+                              Type:
+                                ast.Ident:
+                                  Name: int
+                  Body:
+                    ast.BlockStmt:
+                      List:
+                        ast.ExprStmt:
+                          X:
+                            ast.CallExpr:
+                              Fun:
+                                ast.Ident:
+                                  Name: println
+                              Args:
+                                ast.CompositeLit:
+                                  Elts:
+                                    ast.KeyValueExpr:
+                                      Key:
+                                        ast.BasicLit:
+                                          Kind: STRING
+                                          Value: "x"
+                                      Value:
+                                        ast.BasicLit:
+                                          Kind: INT
+                                          Value: 100
+                                    ast.KeyValueExpr:
+                                      Key:
+                                        ast.BasicLit:
+                                          Kind: STRING
+                                          Value: "y"
+                                      Value:
+                                        ast.BasicLit:
+                                          Kind: INT
+                                          Value: 200
+                                ast.Ident:
+                                  Name: x