diff --git a/src/lpython/parser/parser.yy b/src/lpython/parser/parser.yy index 9076e33cee..aa7ca09829 100644 --- a/src/lpython/parser/parser.yy +++ b/src/lpython/parser/parser.yy @@ -516,8 +516,8 @@ decorators_opt ; decorators - : decorators "@" expr TK_NEWLINE { $$ = $1; LIST_ADD($$, $3); } - | "@" expr TK_NEWLINE { LIST_NEW($$); LIST_ADD($$, $2); } + : decorators "@" expr sep { $$ = $1; LIST_ADD($$, $3); } + | "@" expr sep { LIST_NEW($$); LIST_ADD($$, $2); } ; parameter @@ -606,7 +606,7 @@ slice_item | expr ":" { $$ = SLICE_01( $1, nullptr, nullptr, @$); } | ":" expr { $$ = SLICE_01(nullptr, $2, nullptr, @$); } | expr ":" expr { $$ = SLICE_01( $1, $3, nullptr, @$); } - | ":" ":" { $$ = SLICE_01(nullptr, nullptr, nullptr, @$); } + | ":" ":" { $$ = SLICE_01(nullptr, nullptr, nullptr, @$); } | ":" ":" expr { $$ = SLICE_01(nullptr, nullptr, $3, @$); } | expr ":" ":" { $$ = SLICE_01( $1, nullptr, nullptr, @$); } | ":" expr ":" { $$ = SLICE_01(nullptr, $2, nullptr, @$); } diff --git a/tests/parser/function_def1.py b/tests/parser/function_def1.py index 063ef83683..c3f2b4726b 100644 --- a/tests/parser/function_def1.py +++ b/tests/parser/function_def1.py @@ -33,6 +33,11 @@ def tri_recursion(k): def test(a: i32) -> i32: return a + 10 +@overload +# Comment +def test(a: i64) -> i64: + return a + 10 + @overload def test(a: bool) -> i32: if a: diff --git a/tests/reference/ast_new-function_def1-1a872df.json b/tests/reference/ast_new-function_def1-1a872df.json index c484665423..013bebf758 100644 --- a/tests/reference/ast_new-function_def1-1a872df.json +++ b/tests/reference/ast_new-function_def1-1a872df.json @@ -2,11 +2,11 @@ "basename": "ast_new-function_def1-1a872df", "cmd": "lpython --show-ast --new-parser --no-color {infile} -o {outfile}", "infile": "tests/parser/function_def1.py", - "infile_hash": "4224c0bffeb39c449abfeba907eba690ee5ff15f9514c9a0c0922a92", + "infile_hash": "9dc3cbaa399b8013e99cf165c76d468cf48edde757daafc4069cda40", "outfile": null, "outfile_hash": null, "stdout": "ast_new-function_def1-1a872df.stdout", - "stdout_hash": "19677f67c936f188ba070291048c6dd20a815c5fe66c13570051b3e7", + "stdout_hash": "62bdf27fa9795b9cad94f2747ac48dfac223ef7401dc9af0b445c5a8", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/ast_new-function_def1-1a872df.stdout b/tests/reference/ast_new-function_def1-1a872df.stdout index d5823785ed..d383b67a1c 100644 --- a/tests/reference/ast_new-function_def1-1a872df.stdout +++ b/tests/reference/ast_new-function_def1-1a872df.stdout @@ -3,4 +3,4 @@ the person passed in as a parameter " ())) (Expr (Call (Name print Load) [(BinOp (BinOp (ConstantStr "Hello, " ()) Add (Name name Load)) Add (ConstantStr ". Good morning!" ()))] []))] [] () ()) (FunctionDef absolute_value ([] [(num () ())] [] [] [] [] []) [(Expr (ConstantStr "This function returns the absolute - value of the entered number" ())) (If (Compare (Name num Load) GtE [(ConstantInt 0 ())]) [(Return (Name num Load))] [(Return (UnaryOp USub (Name num Load)))])] [] () ()) (FunctionDef combine ([] [(fname () ()) (lname () ())] [] [] [] [] []) [(Expr (Call (Name print Load) [(BinOp (BinOp (Name fname Load) Add (ConstantStr " " ())) Add (Name lname Load))] []))] [] () ()) (FunctionDef tri_recursion ([] [(k () ())] [] [] [] [] []) [(If (Compare (Name k Load) Gt [(ConstantInt 0 ())]) [(Assign [(Name result Store)] (BinOp (Name k Load) Add (Call (Name tri_recursion Load) [(BinOp (Name k Load) Sub (ConstantInt 1 ()))] [])) ()) (Expr (Call (Name print Load) [(Name result Load)] []))] [(Assign [(Name result Store)] (ConstantInt 0 ()) ())]) (Return (Name result Load))] [] () ()) (FunctionDef test ([] [(a (Name i32 Load) ())] [] [] [] [] []) [(Return (BinOp (Name a Load) Add (ConstantInt 10 ())))] [(Name overload Load)] (Name i32 Load) ()) (FunctionDef test ([] [(a (Name bool Load) ())] [] [] [] [] []) [(If (Name a Load) [(Return (ConstantInt 10 ()))] []) (Return (UnaryOp USub (ConstantInt 10 ())))] [(Name overload Load)] (Name i32 Load) ()) (FunctionDef check ([] [] [] [] [] [] []) [(Expr (Call (Name greet Load) [(ConstantStr "Xyz" ())] [])) (Expr (Call (Name print Load) [(Call (Name absolute_value Load) [(ConstantInt 2 ())] [])] [])) (Expr (Call (Name combine Load) [(ConstantStr "LPython" ()) (ConstantStr "Compiler" ())] [])) (Expr (Call (Name print Load) [(ConstantStr "Recursion Example Results: " ())] [])) (Expr (Call (Name tri_recursion Load) [(ConstantInt 6 ())] [])) (Expr (Call (Name print Load) [(Call (Name test Load) [(ConstantInt 15 ())] [])] [])) (Expr (Call (Name print Load) [(Call (Name test Load) [(ConstantBool .true. ())] [])] []))] [] () ()) (Expr (Call (Name check Load) [] []))] []) + value of the entered number" ())) (If (Compare (Name num Load) GtE [(ConstantInt 0 ())]) [(Return (Name num Load))] [(Return (UnaryOp USub (Name num Load)))])] [] () ()) (FunctionDef combine ([] [(fname () ()) (lname () ())] [] [] [] [] []) [(Expr (Call (Name print Load) [(BinOp (BinOp (Name fname Load) Add (ConstantStr " " ())) Add (Name lname Load))] []))] [] () ()) (FunctionDef tri_recursion ([] [(k () ())] [] [] [] [] []) [(If (Compare (Name k Load) Gt [(ConstantInt 0 ())]) [(Assign [(Name result Store)] (BinOp (Name k Load) Add (Call (Name tri_recursion Load) [(BinOp (Name k Load) Sub (ConstantInt 1 ()))] [])) ()) (Expr (Call (Name print Load) [(Name result Load)] []))] [(Assign [(Name result Store)] (ConstantInt 0 ()) ())]) (Return (Name result Load))] [] () ()) (FunctionDef test ([] [(a (Name i32 Load) ())] [] [] [] [] []) [(Return (BinOp (Name a Load) Add (ConstantInt 10 ())))] [(Name overload Load)] (Name i32 Load) ()) (FunctionDef test ([] [(a (Name i64 Load) ())] [] [] [] [] []) [(Return (BinOp (Name a Load) Add (ConstantInt 10 ())))] [(Name overload Load)] (Name i64 Load) ()) (FunctionDef test ([] [(a (Name bool Load) ())] [] [] [] [] []) [(If (Name a Load) [(Return (ConstantInt 10 ()))] []) (Return (UnaryOp USub (ConstantInt 10 ())))] [(Name overload Load)] (Name i32 Load) ()) (FunctionDef check ([] [] [] [] [] [] []) [(Expr (Call (Name greet Load) [(ConstantStr "Xyz" ())] [])) (Expr (Call (Name print Load) [(Call (Name absolute_value Load) [(ConstantInt 2 ())] [])] [])) (Expr (Call (Name combine Load) [(ConstantStr "LPython" ()) (ConstantStr "Compiler" ())] [])) (Expr (Call (Name print Load) [(ConstantStr "Recursion Example Results: " ())] [])) (Expr (Call (Name tri_recursion Load) [(ConstantInt 6 ())] [])) (Expr (Call (Name print Load) [(Call (Name test Load) [(ConstantInt 15 ())] [])] [])) (Expr (Call (Name print Load) [(Call (Name test Load) [(ConstantBool .true. ())] [])] []))] [] () ()) (Expr (Call (Name check Load) [] []))] [])