pygments icon indicating copy to clipboard operation
pygments copied to clipboard

Update SourcesListLexer, fix #2695

Open iBug opened this issue 1 year ago • 5 comments

For valid inputs, this new set of states is working as intended.

Input:

deb http://deb.debian.org/debian bookworm main contrib
deb [arch=amd64 trusted=yes] http://deb.debian.org/debian bookworm main contrib

Output:

# Line 1
Token.Keyword   'deb'
Token.Text.Whitespace   ' '
Token.Literal.String    'http://deb.debian.org/debian'
Token.Text.Whitespace   ' '
Token.Keyword   'bookworm'
Token.Text.Whitespace   ' '
Token.Keyword.Pseudo    'main'
Token.Text.Whitespace   ' '
Token.Keyword.Pseudo    'contrib'
Token.Text      ''
Token.Text.Whitespace   '\n'

# Line 2
Token.Keyword   'deb'
Token.Text.Whitespace   ' '
Token.Literal.String.Other      '[arch=amd64 trusted=yes]'
Token.Text.Whitespace   ' '
Token.Literal.String    'http://deb.debian.org/debian'
Token.Text.Whitespace   ' '
Token.Keyword   'bookworm'
Token.Text.Whitespace   ' '
Token.Keyword.Pseudo    'main'
Token.Text.Whitespace   ' '
Token.Keyword.Pseudo    'contrib'
Token.Text      ''
Token.Text.Whitespace   '\n'

iBug avatar Apr 24 '24 17:04 iBug

I tried this and I don't see the improvement from this PR. I'm closing this unless there's some motivation as to why we should be doing this.

Anteru avatar Aug 09 '24 19:08 Anteru

@Anteru Have you checked the linked issue?

iBug avatar Aug 09 '24 20:08 iBug

I looked at the linked issue and it doesn't make it clearer for me either. We are not a parser, but a syntax highlighter, so adding semantics is secondary for us. Is the highlighting going to be substantially better with the changes?

Anteru avatar Aug 10 '24 07:08 Anteru

@Anteru We're using Material for MkDocs for our documentation and there are quite some Debian sources.list examples.

Without this patch (i.e. latest version of pygments on PyPI):

image

With this patch:

image

At least the URL is highlighted correctly afterwards.

iBug avatar Aug 10 '24 15:08 iBug

@Anteru Tests are now passing locally. I cannot run tox with -W error because there are two other warnings unrelated to this PR that would be promoted to errors:

ERROR tests/examplefiles - pytest.PytestRemovedIn9Warning: The (path: py.path.local) argument is deprecated, please use (file_path: pathlib.Path)
ERROR tests/snippets - pytest.PytestRemovedIn9Warning: The (path: py.path.local) argument is deprecated, please use (file_path: pathlib.Path)

One extra fix is chmod a-x pygments/lexers/gsql.py which I hope won't hurt.

iBug avatar Aug 11 '24 12:08 iBug