Scony / godot-gdscript-toolkit

Independent set of GDScript tools - parser, linter, formatter, and more
MIT License
944 stars 65 forks source link

gdformat: The `breakpoint` keyword in a gdscript file generates a `KeyError: Token('RULE', 'breakpoint_stmt')`error #289

Closed LaurentOngaro closed 5 months ago

LaurentOngaro commented 5 months ago

The breakpoint keyword prevents a gdscript file script to be formatted. If I comment the keyword, formatting is OK.

For instance, this is the output of the gdformat.exe command :

 logger  gdformat.exe .\log-stream.gd
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "E:\Apps\Python\Scripts\gdformat.exe\__main__.py", line 7, in <module>
  File "E:\Apps\Python\Lib\site-packages\gdtoolkit\formatter\__main__.py", line 78, in main
    _format_files(files, line_length, spaces_for_indent, safety_checks)
  File "E:\Apps\Python\Lib\site-packages\gdtoolkit\formatter\__main__.py", line 167, in _format_files
    success, actually_formatted, formatted_code = _format_code(
                                                  ^^^^^^^^^^^^^
  File "E:\Apps\Python\Lib\site-packages\gdtoolkit\formatter\__main__.py", line 211, in _format_code
    formatted_code = format_code(
                     ^^^^^^^^^^^^
  File "E:\Apps\Python\Lib\site-packages\gdtoolkit\formatter\formatter.py", line 61, in format_code
    formatted_lines, _ = format_block(
                         ^^^^^^^^^^^^^
  File "E:\Apps\Python\Lib\site-packages\gdtoolkit\formatter\block.py", line 55, in format_block
    lines, previously_processed_line_number = statement_formatter(
                                              ^^^^^^^^^^^^^^^^^^^^
  File "E:\Apps\Python\Lib\site-packages\gdtoolkit\formatter\class_statement.py", line 46, in format_class_statement
    return handlers[statement.data](statement, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Apps\Python\Lib\site-packages\gdtoolkit\formatter\class_statement.py", line 172, in _format_func_statement
    func_lines, last_processed_line_no = format_block(
                                         ^^^^^^^^^^^^^
  File "E:\Apps\Python\Lib\site-packages\gdtoolkit\formatter\block.py", line 55, in format_block
    lines, previously_processed_line_number = statement_formatter(
                                              ^^^^^^^^^^^^^^^^^^^^
  File "E:\Apps\Python\Lib\site-packages\gdtoolkit\formatter\function_statement.py", line 35, in format_func_statement
    return handlers[statement.data](statement, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Apps\Python\Lib\site-packages\gdtoolkit\formatter\function_statement.py", line 98, in _format_match_statement
    return _format_branch(prefix, suffix, expr_position, statement, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Apps\Python\Lib\site-packages\gdtoolkit\formatter\function_statement.py", line 133, in _format_branch
    body_lines, last_processed_line_no = format_block(
                                         ^^^^^^^^^^^^^
  File "E:\Apps\Python\Lib\site-packages\gdtoolkit\formatter\block.py", line 55, in format_block
    lines, previously_processed_line_number = statement_formatter(
                                              ^^^^^^^^^^^^^^^^^^^^
  File "E:\Apps\Python\Lib\site-packages\gdtoolkit\formatter\function_statement.py", line 35, in format_func_statement
    return handlers[statement.data](statement, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Apps\Python\Lib\site-packages\gdtoolkit\formatter\function_statement.py", line 105, in _format_match_branch
    return _format_branch(prefix, suffix, expr_position, statement, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Apps\Python\Lib\site-packages\gdtoolkit\formatter\function_statement.py", line 133, in _format_branch
    body_lines, last_processed_line_no = format_block(
                                         ^^^^^^^^^^^^^
  File "E:\Apps\Python\Lib\site-packages\gdtoolkit\formatter\block.py", line 55, in format_block
    lines, previously_processed_line_number = statement_formatter(
                                              ^^^^^^^^^^^^^^^^^^^^
  File "E:\Apps\Python\Lib\site-packages\gdtoolkit\formatter\function_statement.py", line 35, in format_func_statement
    return handlers[statement.data](statement, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Apps\Python\Lib\site-packages\gdtoolkit\formatter\function_statement.py", line 73, in _format_if_statement
    lines, previously_processed_line_number = _format_branch(
                                              ^^^^^^^^^^^^^^^
  File "E:\Apps\Python\Lib\site-packages\gdtoolkit\formatter\function_statement.py", line 133, in _format_branch
    body_lines, last_processed_line_no = format_block(
                                         ^^^^^^^^^^^^^
  File "E:\Apps\Python\Lib\site-packages\gdtoolkit\formatter\block.py", line 55, in format_block
    lines, previously_processed_line_number = statement_formatter(
                                              ^^^^^^^^^^^^^^^^^^^^
  File "E:\Apps\Python\Lib\site-packages\gdtoolkit\formatter\function_statement.py", line 35, in format_func_statement
    return handlers[statement.data](statement, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Apps\Python\Lib\site-packages\gdtoolkit\formatter\function_statement.py", line 73, in _format_if_statement
    lines, previously_processed_line_number = _format_branch(
                                              ^^^^^^^^^^^^^^^
  File "E:\Apps\Python\Lib\site-packages\gdtoolkit\formatter\function_statement.py", line 133, in _format_branch
    body_lines, last_processed_line_no = format_block(
                                         ^^^^^^^^^^^^^
  File "E:\Apps\Python\Lib\site-packages\gdtoolkit\formatter\block.py", line 55, in format_block
    lines, previously_processed_line_number = statement_formatter(
                                              ^^^^^^^^^^^^^^^^^^^^
  File "E:\Apps\Python\Lib\site-packages\gdtoolkit\formatter\function_statement.py", line 35, in format_func_statement
    return handlers[statement.data](statement, context)
           ~~~~~~~~^^^^^^^^^^^^^^^^
KeyError: Token('RULE', 'breakpoint_stmt')

To test it, you can try to format the log-stream.gd file from the logger addon or the modified version I've joined to the post

I'm using the 4.2.2 version of gdtoolkit log-stream.zip

Scony commented 5 months ago

Looks like it was missed in https://github.com/Scony/godot-gdscript-toolkit/commit/4f74038da585797c4d9cb29dd7ce0f7b9ec078db

LaurentOngaro commented 5 months ago

Thanks, I can confirm it's fixed with the commit #32abc37 No more issue with the file given as example