From ee8df5f757ae5fdd1f6e69934122c7d1d4fe0628 Mon Sep 17 00:00:00 2001 From: Andrej Lajovic Date: Wed, 2 Jul 2025 19:12:27 +0200 Subject: [PATCH 1/3] Fix end positions of comments and pragmas (#109) --- blark/util.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/blark/util.py b/blark/util.py index b4e6cca..f586bf4 100644 --- a/blark/util.py +++ b/blark/util.py @@ -363,7 +363,7 @@ def get_token( end_line: int, end_col: int, ) -> lark.Token: - block = text[start_pos:end_pos + 1] + block = text[start_pos:end_pos] if block.startswith("//"): type_ = "SINGLE_LINE_COMMENT" @@ -424,7 +424,7 @@ def get_token( start_pos, start_line, start_col, - pos, + pos + 1, lineno, colno + 1, ) @@ -452,9 +452,9 @@ def get_token( start_pos, start_line, start_col, - pos + 1, # two character ending + pos + 2, # two character ending lineno, - colno + 1, # two character ending + colno + 2, # two character ending ) ) skip = 1 @@ -466,7 +466,7 @@ def get_token( pos, lineno, colno, - pos + (len(lines[lineno]) - colno - 1), + pos + (len(lines[lineno]) - colno), lineno, len(lines[lineno]), ) From 94fe9adb4075fc1b7c28e576d778bb69af02c3b4 Mon Sep 17 00:00:00 2001 From: Ken Lauer <5139267+klauer@users.noreply.github.com> Date: Wed, 9 Jul 2025 17:43:33 -0700 Subject: [PATCH 2/3] TST: add test case from issue 109 --- blark/tests/test_parsing.py | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/blark/tests/test_parsing.py b/blark/tests/test_parsing.py index 1d94a80..ef93009 100644 --- a/blark/tests/test_parsing.py +++ b/blark/tests/test_parsing.py @@ -2,9 +2,8 @@ import pytest -from blark.util import SourceType - from ..parse import parse, parse_source_code, summarize +from ..util import SourceType from . import conftest TEST_PATH = pathlib.Path(__file__).parent @@ -97,3 +96,37 @@ def test_parsing_source(source_filename: str): def test_rule_smoke(grammar, name, value): result = conftest.get_grammar(start=name).parse(value) print(f"rule {name} value {value!r} into {result}") + + +@pytest.mark.parametrize( + ("code", "expected_snippets"), + [ + pytest.param( + """\ +(* +123456789012345678 +*) +// comment +{pragma} +VAR_GLOBAL + dummy : BOOL; +END_VAR +""", + [ + "(*\n123456789012345678\n*)", + "// comment", + "{pragma}", + ], + id="issue_109", + ), + ], +) +def test_comment_parsing(code: str, expected_snippets: list[str]): + result = parse_source_code(code) + + print(result.comments) + + snippets = [ + result.source_code[token.start_pos: token.end_pos] for token in result.comments + ] + assert snippets == expected_snippets From d7e3d6af61d9a14d3e9511bcf87927f0dc6b06d3 Mon Sep 17 00:00:00 2001 From: Ken Lauer <5139267+klauer@users.noreply.github.com> Date: Wed, 9 Jul 2025 17:47:42 -0700 Subject: [PATCH 3/3] CI: bump download-artifact as well --- .github/workflows/docs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 051c3f4..d21a29d 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -137,7 +137,7 @@ jobs: pip install docs-versions-menu - name: Download documentation artifact - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: Documentation