Skip to content

Conversation

@darenc
Copy link
Contributor

@darenc darenc commented Mar 13, 2024

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
Copy link
Contributor

jeanas commented Mar 13, 2024

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

@darenc
Copy link
Contributor Author

darenc commented Mar 13, 2024

(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

@darenc darenc requested a review from Anteru March 25, 2024 13:17
(r'[a-zA-Z_/]\w*', Name),

# numbers
(r'(\d+((_\d+)+)?\.(?!\.)(\d+((_\d+)+)?)?|\.\d+((_\d+)+)?)([eEf][+-]?[0-9]+)?', Number.Float),
Copy link
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*.


# numbers
(r'(\d+((_\d+)+)?\.(?!\.)(\d+((_\d+)+)?)?|\.\d+((_\d+)+)?)([eEf][+-]?[0-9]+)?', Number.Float),
(r'\d+((_\d+)+)?[eEf][+-]?[0-9]+', Number.Float),
Copy link
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),

# 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
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),

(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
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),

(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
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),

(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
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),

(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
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
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
Copy link

Pi-Cla commented Apr 12, 2024

@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
Copy link
Contributor Author

darenc commented Apr 12, 2024

@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
Copy link
Collaborator

Anteru commented Oct 6, 2024

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

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
Copy link
Collaborator

Anteru commented Jan 6, 2025

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