Skip to content

Commit

Permalink
Fix function matching (#5)
Browse files Browse the repository at this point in the history
* Add additional hard tests, improve function matching

* Simplify grammar
  • Loading branch information
N-Wouda authored Feb 2, 2024
1 parent 2e1ee0e commit 4c92aa6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions docblock/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <nielswouda@gmail.com>"]
license = "MIT"
Expand All @@ -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",
Expand Down
18 changes: 16 additions & 2 deletions tests/test_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -39,6 +45,14 @@ def test_func_matches_complicated():
"""
)

assert FUNC.matches(
"""
timeWarp(Duration const maxDuration
= std::numeric_limits<Duration>::max(),
Duration const maxOvertime = 0) const;
"""
)


def test_operator_match():
assert OPERATOR.matches("operator~")
Expand Down

0 comments on commit 4c92aa6

Please sign in to comment.