Skip to content

Add Gleam lexer - #2662

Merged
Anteru merged 12 commits into
pygments:masterfrom
darenc:gleam-lexer
Oct 6, 2024
Merged

Anteru merged 12 commits into
pygments:masterfrom
darenc:gleam-lexer

Conversation

@darenc

@darenc darenc commented Mar 13, 2024

Copy link
Copy Markdown
Contributor

Hi, this PR adds a lexer for Gleam, which just released version 1.0.0.

I've run tests and things look good to me. However, I'm not a Python person and haven't tried writing a lexer before, particularly not one for Pygments, so I'm happy to take feedback and suggestions for improvements.

There is some example HTML at https://red-rose.com/gleam.html that I generated with pygmentize and then modified to add the lightbulb style (slightly modified for Name colours). This is the same large example file that's included with the PR.

Cheers,
Daren

@jeanas

jeanas commented Mar 13, 2024

Copy link
Copy Markdown
Contributor

(Pushed a commit to fix line endings, can you configure Git's core.autocrlf for the future? Thanks.)

@darenc

darenc commented Mar 13, 2024

Copy link
Copy Markdown
Contributor Author

(Pushed a commit to fix line endings, can you configure Git's core.autocrlf for the future? Thanks.)

Thank you, I thought I'd fixed them. Sorry for the inconvenience

Comment thread pygments/lexers/gleam.py Outdated
Comment thread pygments/lexers/gleam.py Outdated
@darenc
darenc requested a review from Anteru March 25, 2024 13:17
Comment thread pygments/lexers/gleam.py Outdated
(r'[a-zA-Z_/]\w*', Name),

# numbers
(r'(\d+((_\d+)+)?\.(?!\.)(\d+((_\d+)+)?)?|\.\d+((_\d+)+)?)([eEf][+-]?[0-9]+)?', Number.Float),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
(r'(\d+((_\d+)+)?\.(?!\.)(\d+((_\d+)+)?)?|\.\d+((_\d+)+)?)([eEf][+-]?[0-9]+)?', Number.Float),
(r'(\d+(_\d+)*\.(?!\.)(\d+(_\d+)*)?|\.\d+(_\d+)*)([eEf][+-]?[0-9]+)?', Number.Float),

(X+)? is just X*.

Comment thread pygments/lexers/gleam.py Outdated

# numbers
(r'(\d+((_\d+)+)?\.(?!\.)(\d+((_\d+)+)?)?|\.\d+((_\d+)+)?)([eEf][+-]?[0-9]+)?', Number.Float),
(r'\d+((_\d+)+)?[eEf][+-]?[0-9]+', Number.Float),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
(r'\d+((_\d+)+)?[eEf][+-]?[0-9]+', Number.Float),
(r'\d+(_\d+)*[eEf][+-]?[0-9]+', Number.Float),

Comment thread pygments/lexers/gleam.py Outdated
# numbers
(r'(\d+((_\d+)+)?\.(?!\.)(\d+((_\d+)+)?)?|\.\d+((_\d+)+)?)([eEf][+-]?[0-9]+)?', Number.Float),
(r'\d+((_\d+)+)?[eEf][+-]?[0-9]+', Number.Float),
(r'0[xX][a-fA-F0-9]+((_[a-fA-F0-9]+)+)?(\.([a-fA-F0-9]+((_[a-fA-F0-9]+)+)?)?)?p[+-]?\d+', Number.Float),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
(r'0[xX][a-fA-F0-9]+((_[a-fA-F0-9]+)+)?(\.([a-fA-F0-9]+((_[a-fA-F0-9]+)+)?)?)?p[+-]?\d+', Number.Float),
(r'0[xX][a-fA-F0-9]+(_[a-fA-F0-9]+)*(\.([a-fA-F0-9]+(_[a-fA-F0-9]+)*)?)?p[+-]?\d+', Number.Float),

Comment thread pygments/lexers/gleam.py Outdated
(r'(\d+((_\d+)+)?\.(?!\.)(\d+((_\d+)+)?)?|\.\d+((_\d+)+)?)([eEf][+-]?[0-9]+)?', Number.Float),
(r'\d+((_\d+)+)?[eEf][+-]?[0-9]+', Number.Float),
(r'0[xX][a-fA-F0-9]+((_[a-fA-F0-9]+)+)?(\.([a-fA-F0-9]+((_[a-fA-F0-9]+)+)?)?)?p[+-]?\d+', Number.Float),
(r'0[bB][01]+((_[01]+)+)?', Number.Bin),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
(r'0[bB][01]+((_[01]+)+)?', Number.Bin),
(r'0[bB][01]+(_[01]+)*', Number.Bin),

Comment thread pygments/lexers/gleam.py Outdated
(r'\d+((_\d+)+)?[eEf][+-]?[0-9]+', Number.Float),
(r'0[xX][a-fA-F0-9]+((_[a-fA-F0-9]+)+)?(\.([a-fA-F0-9]+((_[a-fA-F0-9]+)+)?)?)?p[+-]?\d+', Number.Float),
(r'0[bB][01]+((_[01]+)+)?', Number.Bin),
(r'0[oO][0-7]+((_[0-7]+)+)?', Number.Oct),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
(r'0[oO][0-7]+((_[0-7]+)+)?', Number.Oct),
(r'0[oO][0-7]+(_[0-7]+)*', Number.Oct),

Comment thread pygments/lexers/gleam.py Outdated
(r'0[xX][a-fA-F0-9]+((_[a-fA-F0-9]+)+)?(\.([a-fA-F0-9]+((_[a-fA-F0-9]+)+)?)?)?p[+-]?\d+', Number.Float),
(r'0[bB][01]+((_[01]+)+)?', Number.Bin),
(r'0[oO][0-7]+((_[0-7]+)+)?', Number.Oct),
(r'0[xX][a-fA-F0-9]+((_[a-fA-F0-9]+)+)?', Number.Hex),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
(r'0[xX][a-fA-F0-9]+((_[a-fA-F0-9]+)+)?', Number.Hex),
(r'0[xX][a-fA-F0-9]+(_[a-fA-F0-9]+)*', Number.Hex),

Comment thread pygments/lexers/gleam.py Outdated
(r'0[bB][01]+((_[01]+)+)?', Number.Bin),
(r'0[oO][0-7]+((_[0-7]+)+)?', Number.Oct),
(r'0[xX][a-fA-F0-9]+((_[a-fA-F0-9]+)+)?', Number.Hex),
(r'\d+((_\d+)+)?', Number.Integer),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
(r'\d+((_\d+)+)?', Number.Integer),
(r'\d+(_\d+)*', Number.Integer),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This and other suggestions have been implemented, thanks for the input

@Pi-Cla

Pi-Cla commented Apr 12, 2024

Copy link
Copy Markdown

@darenc Hi, are you still working on this?
I have been able to add a lexer to Chroma so I was wondering whether I should let you finish this or if I should try to translate the lexer I made in Chroma into Pygments and make a new PR.

What do you think?

@darenc

darenc commented Apr 12, 2024

Copy link
Copy Markdown
Contributor Author

@darenc Hi, are you still working on this?

Yep, I'll pick up the requested changes in the next few days. Just been busy with other things.

@Anteru
Anteru merged commit eaa22a2 into pygments:master Oct 6, 2024
@Anteru

Anteru commented Oct 6, 2024

Copy link
Copy Markdown
Collaborator

Merged, thanks!

@Anteru Anteru added this to the 2.19.0 milestone Oct 6, 2024
@Anteru Anteru added the A-lexing area: changes to individual lexers label Oct 6, 2024
@logan-connolly

Copy link
Copy Markdown

Just wanted to give you guys a heads up that the documentation on your website states that Gleam support was added in 2.18, but it appears here that it is planned for 2.19. Thanks a lot for all your hard work and looking forward to the next release :)

@Anteru

Anteru commented Jan 6, 2025

Copy link
Copy Markdown
Collaborator

That's fixed as well now, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-lexing area: changes to individual lexers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants