From 4c92aa6667f6ff5586fa8785b79dc4a0766bd4fa Mon Sep 17 00:00:00 2001 From: Niels Wouda Date: Fri, 2 Feb 2024 23:49:51 +0100 Subject: [PATCH] Fix function matching (#5) * Add additional hard tests, improve function matching * Simplify grammar --- .github/workflows/CI.yaml | 2 +- docblock/grammar.py | 5 +++-- pyproject.toml | 7 +------ tests/test_grammar.py | 18 ++++++++++++++++-- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index d92bb49..feb30c8 100644 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [ '3.8', '3.9', '3.10', '3.11' ] + python-version: [ '3.9', '3.10', '3.11', '3.12' ] steps: - uses: actions/checkout@v3 - name: Set up Python diff --git a/docblock/grammar.py b/docblock/grammar.py index 9277576..42d4622 100644 --- a/docblock/grammar.py +++ b/docblock/grammar.py @@ -23,8 +23,9 @@ _OP = pp.Word("<>!=&|*/+-~^", min=1, max=3) | "()" | "[]" OPERATOR = pp.Combine("operator" + _OP) FUNC_NAME = OPERATOR | QUALIFIED_ID -ARG_LIST = LPAR + ... + RPAR[1, ...] -FUNC = FUNC_NAME + (ARG_LIST + ID[...] + CLOSE_STMT).suppress() +FUNC_OPEN = FUNC_NAME + LPAR.suppress() +FUNC_CLOSE = RPAR + ... + CLOSE_STMT +FUNC = FUNC_OPEN + (... + FUNC_CLOSE).suppress() # Line comment and documentation blocks. LINE_COMMENT = pp.dbl_slash_comment diff --git a/pyproject.toml b/pyproject.toml index 8c7bdba..b15641a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "docblock" -version = "0.1.1" +version = "0.1.2" description = "Reads and parses documentation from header files in pure Python." authors = ["Niels Wouda "] license = "MIT" @@ -14,11 +14,6 @@ packages = [ ] classifiers = [ "License :: OSI Approved :: MIT License", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", "Intended Audience :: Developers", "Development Status :: 5 - Production/Stable", "Topic :: Software Development", diff --git a/tests/test_grammar.py b/tests/test_grammar.py index 2277724..d9a0319 100644 --- a/tests/test_grammar.py +++ b/tests/test_grammar.py @@ -24,12 +24,18 @@ def test_func_match(): assert FUNC.matches("count() const;") assert FUNC.matches("Matrix(size_t nRows, size_t nCols);") + assert FUNC.matches("bpd(Solution const &first, Solution const &second);") + # These are a bit harder, because the name is hard, or because there are - # multiple parens. + # multiple parentheses. assert FUNC.matches("operator()(size_t row, size_t col);") - assert FUNC.matches("operator|(DynamicBitset const &other) const;") + assert FUNC.matches("operator|(pyvrp::DynamicBitset const &other) const;") assert FUNC.matches("operator~() const;") + # Both orderings (const override, and override const) should be accepted. + assert FUNC.matches("apply(Node *U, Node *V) const override;") + assert FUNC.matches("apply(Node *U, Node *V) override const;") + def test_func_matches_complicated(): assert FUNC.matches( @@ -39,6 +45,14 @@ def test_func_matches_complicated(): """ ) + assert FUNC.matches( + """ + timeWarp(Duration const maxDuration + = std::numeric_limits::max(), + Duration const maxOvertime = 0) const; + """ + ) + def test_operator_match(): assert OPERATOR.matches("operator~")