cheshirekow / cmake_format

Source code formatter for cmake listfiles.
GNU General Public License v3.0
949 stars 104 forks source link

additional_commands parsing create internal error with flag followed by variable #268

Open OlivierLDff opened 3 years ago

OlivierLDff commented 3 years ago

CMakeLists.txt :

my_custom_function(
  MY_FLAG
  ${VAR}
)

.cmake-format :

parse:
  additional_commands:
    my_custom_function:
      kwargs:
        MY_FLAG: 0

Produce:

WARNING __main__.py:522: While processing ./CMakeLists.txt
ERROR __main__.py:629: parsed an empty subtree at Token(type=DEREF, content='${VAR}', line=3, col=2):
  \u2514\u2500 ARGGROUP: 0:0

 pspec: (0, False, [], [], True, None, None)
Traceback (most recent call last):
  File "c:\python38\lib\site-packages\cmake_format\__main__.py", line 624, in main
    return inner_main()
  File "c:\python38\lib\site-packages\cmake_format\__main__.py", line 607, in inner_main
    onefile_main(infile_path, args, argparse_dict)
  File "c:\python38\lib\site-packages\cmake_format\__main__.py", line 518, in onefile_main
    outtext, reflow_valid = process_file(cfg, intext, args.dump)
  File "c:\python38\lib\site-packages\cmake_format\__main__.py", line 159, in process_file
    parse_tree = parse.parse(tokens, ctx)
  File "c:\python38\lib\site-packages\cmake_format\parse\__init__.py", line 68, in parse
    return BodyNode.consume(ctx, tokens)
  File "c:\python38\lib\site-packages\cmake_format\parse\body_nodes.py", line 67, in consume
    subtree = StatementNode.consume(ctx, tokens)
  File "c:\python38\lib\site-packages\cmake_format\parse\statement_node.py", line 89, in consume
    node.argtree = subtree = parse_fun(ctx, tokens, breakstack)
  File "c:\python38\lib\site-packages\cmake_format\parse\argument_nodes.py", line 266, in __call__
    return StandardArgTree.parse2(
  File "c:\python38\lib\site-packages\cmake_format\parse\argument_nodes.py", line 167, in parse2
    subtree = KeywordGroupNode.parse(
  File "c:\python38\lib\site-packages\cmake_format\parse\argument_nodes.py", line 316, in parse
    subtree = subparser(ctx, tokens, breakstack)
  File "c:\python38\lib\site-packages\cmake_format\parse\argument_nodes.py", line 266, in __call__
    return StandardArgTree.parse2(
  File "c:\python38\lib\site-packages\cmake_format\parse\argument_nodes.py", line 191, in parse2
    raise InternalError(
cmake_format.common.InternalError

Current workaround:

my_custom_function(
  ${VAR}
  MY_FLAG
)