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

Add lexer for colon-separated value config files like /etc/passwd, /etc/shadow and /etc/group #2112

Merged
merged 10 commits into from
Apr 16, 2022
Merged

Add lexer for colon-separated value config files like /etc/passwd, /etc/shadow and /etc/group #2112

merged 10 commits into from
Apr 16, 2022

Conversation

Leistungsabfall
Copy link
Contributor

@Leistungsabfall Leistungsabfall commented Apr 14, 2022

Hi,

I created two lexers (PasswdLexer, ShadowLexer) for lexing linux config files /etc/passwd and /etc/shadow.
I don't know if they are of much use for pygments though, so feel free to reject this PR if they are too specific.

/etc/passwd:
passwd

/etc/shadow:
shadow

Copy link
Contributor

@jeanas jeanas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if they are of much use for pygments though, so feel free to reject this PR if they are too specific.

They don't seem egregious to me, but I would prefer if they didn't match files named passwd and shadow.

pygments/lexers/configs.py Outdated Show resolved Hide resolved
pygments/lexers/configs.py Outdated Show resolved Hide resolved
pygments/lexers/configs.py Outdated Show resolved Hide resolved
pygments/lexers/configs.py Outdated Show resolved Hide resolved
pygments/lexers/configs.py Outdated Show resolved Hide resolved
pygments/lexers/configs.py Outdated Show resolved Hide resolved
@birkenfeld
Copy link
Member

It seems to me that they could be combined into a single lexer, with highlighting determined not by position but by content...

Leistungsabfall and others added 4 commits April 15, 2022 18:46
Co-authored-by: Jean Abou-Samra <jean@abou-samra.fr>
…rated values, typically used in Unix/Linux system config files.
@Leistungsabfall
Copy link
Contributor Author

Thank you both for your valuable feedback.
I applied the suggested changes and merged both lexers into a generic UnixConfigLexer that is able to parse any config file using colons (:) as value separators (e.g. /etc/shadow, /etc/passwd, /etc/group).

I'd appreciate if you could take another look at the changes :)

@Leistungsabfall Leistungsabfall changed the title Support lexing of /etc/passwd and /etc/shadow Add lexer for colon-separated value config files like /etc/passwd, /etc/shadow and /etc/group Apr 15, 2022
Copy link
Contributor

@jeanas jeanas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry that I forgot to say it the first time: this PR is missing some tests. Please add them as tests/snippets/unixconfig/test-name.txt and run pytest --update-goldens tests/snippets/unixconfig to generate golden test output.

pygments/lexers/configs.py Outdated Show resolved Hide resolved
tests/snippets/unixconfig/etc_group.txt Outdated Show resolved Hide resolved
pygments/lexers/configs.py Outdated Show resolved Hide resolved
Copy link
Contributor

@jeanas jeanas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks OK to me. Leaving this around in case @birkenfeld wants to take another look.

@birkenfeld birkenfeld merged commit 29392ea into pygments:master Apr 16, 2022
@birkenfeld
Copy link
Member

Thanks for the contribution!

@Anteru Anteru added the changelog-update Items which need to get mentioned in the changelog label Apr 16, 2022
@Anteru Anteru added this to the 2.12.0 milestone Apr 16, 2022
@Leistungsabfall Leistungsabfall deleted the feature/add-linux-config-lexers branch April 22, 2022 13:47
@Anteru Anteru removed the changelog-update Items which need to get mentioned in the changelog label Apr 24, 2022
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

Successfully merging this pull request may close these issues.

4 participants