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

improve number highlighting for c #1752

Merged
merged 5 commits into from
Jun 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions data/plugins/language_c.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
-- mod-version:3
local syntax = require "core.syntax"

-- integer suffix combinations as a regex
local isuf = [[(?:[lL][uU]|ll[uU]|LL[uU]|[uU][lL]\b|[uU]ll|[uU]LL|[uU]|[lL]\b|ll|LL)?]]
Copy link
Member

Choose a reason for hiding this comment

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

You can probably simplify this by enabling case insensitiveness with like (?i:this IS case INSENSITIVE).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for some odd reason, the two Ls in long long have to have the same case for the literal to be valid

Copy link
Member

Choose a reason for hiding this comment

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

if it can't be fixed easily, let's just keep this as is.

Copy link
Member

Choose a reason for hiding this comment

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

What about the \b? Why is it needed only in some cases?

Copy link
Member

Choose a reason for hiding this comment

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

@thacuber2a03 can you answer this question? I will merge if this conversation is resolved.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh, yeah, sorry
about the \b, I have it there to avoid having an l alongside another one with a different case be highlighted
which, honestly, I think it's overkill, but compilers actually don't compile programs with stuff like UlL or Ll

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in whatever case, I'm not sure whether I care that much anymore, so you can merge with or without that big ass regex

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@takase1121 almost forgot the mention

-- float suffix combinations as a Lua pattern / regex
local fsuf = "[fFlL]?"

syntax.add {
name = "C",
files = { "%.c$" },
Expand All @@ -11,9 +16,13 @@ syntax.add {
{ pattern = { "/%*", "%*/" }, type = "comment" },
{ pattern = { '"', '"', '\\' }, type = "string" },
{ pattern = { "'", "'", '\\' }, type = "string" },
{ pattern = "0x%x+", type = "number" },
{ pattern = "%d+[%d%.eE]*f?", type = "number" },
{ pattern = "%.?%d+f?", type = "number" },
{ regex = "0x[0-9a-fA-f]+"..isuf, type = "number" },
{ regex = "0()[0-7]+"..isuf, type = { "keyword", "number" } },
{ pattern = "%d+%.%d*[Ee]%d+"..fsuf, type = "number" },
{ pattern = "%d+[Ee]%d+"..fsuf, type = "number" },
{ pattern = "%d+%.%d*"..fsuf, type = "number" },
{ pattern = "%.%d+"..fsuf, type = "number" },
{ regex = "\\d+"..isuf, type = "number" },
{ pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" },
{ pattern = "##", type = "operator" },
{ pattern = "struct%s()[%a_][%w_]*", type = {"keyword", "keyword2"} },
Expand Down
Loading