terryyin / lizard

A simple code complexity analyser without caring about the C/C++ header files or Java imports, supports most of the popular languages.
Other
1.86k stars 253 forks source link

Regex for FORTRAN Throws an Error #398

Open alicebibaud opened 1 week ago

alicebibaud commented 1 week ago

When running lizard over a fortran file, I'm getting this error:

File ".../.venv/lib/python3.12/site-packages/lizard.py", line 567, in analyze_source_code
    for _ in reader(tokens, reader):
  File ".../.venv/lib/python3.12/site-packages/lizard_languages/code_reader.py", line 161, in __call__
    for token in tokens:
  File ".../.venv/lib/python3.12/site-packages/lizard.py", line 533, in condition_counter
    for token in tokens:
  File ".../.venv/lib/python3.12/site-packages/lizard.py", line 525, in token_counter
    for token in tokens:
  File ".../.venv/lib/python3.12/site-packages/lizard.py", line 511, in line_counter
    for token in tokens:
  File ".../.venv/lib/python3.12/site-packages/lizard.py", line 494, in comment_counter
    for token in tokens:
  File ".../.venv/lib/python3.12/site-packages/lizard_languages/fortran.py", line 54, in preprocess
    for token in tokens:
  File ".../.venv/lib/python3.12/site-packages/lizard_languages/code_reader.py", line 123, in _generate_tokens
    token_pattern = re.compile(
                    ^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/re/__init__.py", line 228, in compile
    return _compile(pattern, flags)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/re/__init__.py", line 307, in _compile
    p = _compiler.compile(pattern, flags)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/re/_compiler.py", line 745, in compile
    p = _parser.parse(p, flags)
        ^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/re/_parser.py", line 979, in parse
    p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/re/_parser.py", line 460, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/re/_parser.py", line 862, in _parse
    p = _parse_sub(source, state, sub_verbose, nested + 1)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/re/_parser.py", line 460, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/lib/python3.12/re/_parser.py", line 840, in _parse
    raise source.error('global flags not at the start '
re.error: global flags not at the start of the expression at position 14

It looks like this is an issue with the regex that's attempting to pull methods or functions out of this file. I'm interested in taking a stab at fixing this, but I wanted to put this here for completeness.

terryyin commented 6 days ago

Thanks for the report. It's fixed with the commit https://github.com/terryyin/lizard/commit/ff1928bd96607deb70396e268b6b54dbbe9967e7 please try again. Also I created a new release on pypi.