From e3c5a02d34c95c835a3cb7227a963f49097fabf4 Mon Sep 17 00:00:00 2001 From: Pawel Lampe Date: Thu, 12 Sep 2024 21:28:49 +0200 Subject: [PATCH] Add 'simple_multistatement_lambdas' tests, align formatter, and fix lexer --- gdtoolkit/formatter/expression.py | 1 + gdtoolkit/parser/gdscript_indenter.py | 4 +- .../long_unistatement_lambdas.in.gd | 15 + .../long_unistatement_lambdas.out.gd | 494 ++++++++++++++++++ .../simple_multistatement_lambdas.in.gd | 2 + .../simple_multistatement_lambdas.out.gd | 2 + 6 files changed, 517 insertions(+), 1 deletion(-) create mode 100644 tests/formatter/input-output-pairs/long_unistatement_lambdas.in.gd create mode 100644 tests/formatter/input-output-pairs/long_unistatement_lambdas.out.gd diff --git a/gdtoolkit/formatter/expression.py b/gdtoolkit/formatter/expression.py index e179eab1..abc502e0 100644 --- a/gdtoolkit/formatter/expression.py +++ b/gdtoolkit/formatter/expression.py @@ -151,6 +151,7 @@ def _format_foldable_to_multiple_lines( "c_dict_element": _format_kv_pair_to_multiple_lines, "eq_dict_element": _format_kv_pair_to_multiple_lines, "lambda": _format_lambda_to_multiple_lines, + "lambda_header": _format_lambda_header_to_multiple_lines, # fake expressions: "func_args": _format_args_to_multiple_lines, "func_arg_regular": _format_func_arg_to_multiple_lines, diff --git a/gdtoolkit/parser/gdscript_indenter.py b/gdtoolkit/parser/gdscript_indenter.py index 62605ca6..5ce8d416 100644 --- a/gdtoolkit/parser/gdscript_indenter.py +++ b/gdtoolkit/parser/gdscript_indenter.py @@ -40,7 +40,9 @@ def handle_NL(self, token: Token) -> Iterator[Token]: else: while indent < self.indent_level[-1]: self.indent_level.pop() - yield Token.new_borrow_pos(self.DEDENT_type, indent_str, token) + yield Token( + self.DEDENT_type, indent_str, None, token.line, None, token.line + ) # produce extra newline after dedent to simplify grammar: yield token diff --git a/tests/formatter/input-output-pairs/long_unistatement_lambdas.in.gd b/tests/formatter/input-output-pairs/long_unistatement_lambdas.in.gd new file mode 100644 index 00000000..821021d5 --- /dev/null +++ b/tests/formatter/input-output-pairs/long_unistatement_lambdas.in.gd @@ -0,0 +1,15 @@ +func xyz(x): + pass +func foo(): + var x1 = func(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16,p17,p18,p19,p20,p21,p22,p23): pass + var x2 = func(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16,p17,p18,p19,p20,p21,p22,p23) -> int: return 1 + var x3 = func bar(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16,p17,p18,p19,p20,p21,p22,p23): pass + var x4 = func baz(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16,p17,p18,p19,p20,p21,p22,p23) -> int: return 1 + + var x5 = func baz(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16,p17,p18,p19,p20,p21,p22,p23): return [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] + var x6 = func baz(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16,p17,p18,p19,p20,p21,p22,p23): xyz([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]) + var x8 = func baz(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16,p17,p18,p19,p20,p21,p22,p23): var xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + var x9 = func baz(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16,p17,p18,p19,p20,p21,p22,p23): var x=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] + var x10 = func baz(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16,p17,p18,p19,p20,p21,p22,p23): var xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx:int + var x11 = func baz(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16,p17,p18,p19,p20,p21,p22,p23): var x:Array=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] + var x12 = func baz(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16,p17,p18,p19,p20,p21,p22,p23): var x:=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] diff --git a/tests/formatter/input-output-pairs/long_unistatement_lambdas.out.gd b/tests/formatter/input-output-pairs/long_unistatement_lambdas.out.gd new file mode 100644 index 00000000..b5f920c8 --- /dev/null +++ b/tests/formatter/input-output-pairs/long_unistatement_lambdas.out.gd @@ -0,0 +1,494 @@ +func xyz(x): + pass + + +func foo(): + var x1 = func( + p1, + p2, + p3, + p4, + p5, + p6, + p7, + p8, + p9, + p10, + p11, + p12, + p13, + p14, + p15, + p16, + p17, + p18, + p19, + p20, + p21, + p22, + p23 + ): + pass + var x2 = func( + p1, + p2, + p3, + p4, + p5, + p6, + p7, + p8, + p9, + p10, + p11, + p12, + p13, + p14, + p15, + p16, + p17, + p18, + p19, + p20, + p21, + p22, + p23 + ) -> int: + return 1 + var x3 = func bar( + p1, + p2, + p3, + p4, + p5, + p6, + p7, + p8, + p9, + p10, + p11, + p12, + p13, + p14, + p15, + p16, + p17, + p18, + p19, + p20, + p21, + p22, + p23 + ): + pass + var x4 = func baz( + p1, + p2, + p3, + p4, + p5, + p6, + p7, + p8, + p9, + p10, + p11, + p12, + p13, + p14, + p15, + p16, + p17, + p18, + p19, + p20, + p21, + p22, + p23 + ) -> int: + return 1 + + var x5 = func baz( + p1, + p2, + p3, + p4, + p5, + p6, + p7, + p8, + p9, + p10, + p11, + p12, + p13, + p14, + p15, + p16, + p17, + p18, + p19, + p20, + p21, + p22, + p23 + ): + return [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ] + var x6 = func baz( + p1, + p2, + p3, + p4, + p5, + p6, + p7, + p8, + p9, + p10, + p11, + p12, + p13, + p14, + p15, + p16, + p17, + p18, + p19, + p20, + p21, + p22, + p23 + ): + xyz( + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ] + ) + var x8 = func baz( + p1, + p2, + p3, + p4, + p5, + p6, + p7, + p8, + p9, + p10, + p11, + p12, + p13, + p14, + p15, + p16, + p17, + p18, + p19, + p20, + p21, + p22, + p23 + ): + var xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + var x9 = func baz( + p1, + p2, + p3, + p4, + p5, + p6, + p7, + p8, + p9, + p10, + p11, + p12, + p13, + p14, + p15, + p16, + p17, + p18, + p19, + p20, + p21, + p22, + p23 + ): + var x = [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ] + var x10 = func baz( + p1, + p2, + p3, + p4, + p5, + p6, + p7, + p8, + p9, + p10, + p11, + p12, + p13, + p14, + p15, + p16, + p17, + p18, + p19, + p20, + p21, + p22, + p23 + ): + var xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: int + var x11 = func baz( + p1, + p2, + p3, + p4, + p5, + p6, + p7, + p8, + p9, + p10, + p11, + p12, + p13, + p14, + p15, + p16, + p17, + p18, + p19, + p20, + p21, + p22, + p23 + ): + var x: Array = [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ] + var x12 = func baz( + p1, + p2, + p3, + p4, + p5, + p6, + p7, + p8, + p9, + p10, + p11, + p12, + p13, + p14, + p15, + p16, + p17, + p18, + p19, + p20, + p21, + p22, + p23 + ): + var x := [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ] diff --git a/tests/formatter/input-output-pairs/simple_multistatement_lambdas.in.gd b/tests/formatter/input-output-pairs/simple_multistatement_lambdas.in.gd index 47f52a6d..604c3d94 100644 --- a/tests/formatter/input-output-pairs/simple_multistatement_lambdas.in.gd +++ b/tests/formatter/input-output-pairs/simple_multistatement_lambdas.in.gd @@ -16,3 +16,5 @@ func baz(): return 5 return 6 return 7 + + pass diff --git a/tests/formatter/input-output-pairs/simple_multistatement_lambdas.out.gd b/tests/formatter/input-output-pairs/simple_multistatement_lambdas.out.gd index 38cd2847..584018a6 100644 --- a/tests/formatter/input-output-pairs/simple_multistatement_lambdas.out.gd +++ b/tests/formatter/input-output-pairs/simple_multistatement_lambdas.out.gd @@ -23,3 +23,5 @@ func baz(): return 5 return 6 return 7 + + pass