Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codeblock Lexer pattern doesn't work if codeblock ends with close comment (end of input to the lexer) #52

Closed
thirtytwobits opened this issue May 17, 2023 · 2 comments

Comments

@thirtytwobits
Copy link

(Found in Sybil 4.0.1)

TLDR

Unescaped tokens in END_PATTERN_TEMPLATE = '(\n\\Z|\n[ \t]{{0,{len_prefix}}}(?=\\S))'

I think you meant: r'(\n\Z|\n[ \t]{{0,{len_prefix}}}(?=\S))'?

Details

if I have this:

    """
    My comment

    .. code-block:: python
        test_my_code("Hello World")
    """

the PythonCodeBlockParser fails. For example:

.tox/local/lib/python3.8/site-packages/sybil/integration/pytest.py:104: in collect
    self.document = self.sybil.parse(Path(self.fspath.strpath))
.tox/local/lib/python3.8/site-packages/sybil/sybil.py:144: in parse
    return type_.parse(str(path), *self.parsers, encoding=self.encoding)
.tox/local/lib/python3.8/site-packages/sybil/document.py:201: in parse
    for region in parser(docstring_document):
.tox/local/lib/python3.8/site-packages/sybil/parsers/abstract/codeblock.py:46: in __call__
    for lexed in chain(*(lexer(document) for lexer in self.lexers)):
.tox/local/lib/python3.8/site-packages/sybil/parsers/abstract/lexers.py:59: in __call__
    raise LexingException(
E   sybil.parsers.abstract.lexers.LexingException: Could not match '(\n\\Z|\n[ \t]{0,8}(?=\\S))' in my_python.py (truncated)

Neither does this work because my IDE always elides extra whitespace:

    """
    My comment

    .. code-block:: python
        test_my_code("Hello World")

    """

If I do this it will work:

    """
    My comment

    .. code-block:: python
        test_my_code("Hello World")
    \
    """

or this works too:

    """
    My comment

    .. code-block:: python
        test_my_code("Hello World")

    Any other rst comment text here.
    """
thirtytwobits added a commit to thirtytwobits/nunavut that referenced this issue May 17, 2023
@cjw296
Copy link
Member

cjw296 commented May 18, 2023

This is fixed in 90a385c, thanks for the report!

@cjw296 cjw296 closed this as completed May 18, 2023
@cjw296
Copy link
Member

cjw296 commented May 19, 2023

Released in 5.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants