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

Fix go number highlighting #3981

Merged
merged 5 commits into from
Feb 20, 2024

Conversation

lugray
Copy link
Contributor

@lugray lugray commented Jan 31, 2024

Go number literals are considerably more complex than previously expressed. Most notable, _ is allowed in several contexts to allow digit grouping, hex numbers can take p exponents, and a number with a radix (.) requires digits before or after but not both. The additional test cases were pulled from https://go.dev/ref/spec.

Changes

Add test cases from https://go.dev/ref/spec, and make the tests pass.

Checklist

  • Added markup tests, or they don't apply here because...
  • Updated the changelog at CHANGES.md

Sorry, something went wrong.

Go number literals are considerably more complex than previously
expressed. Most notable, `_` is allowed in several contexts to allow
digit grouping, hex numbers can take `p` exponents, and a number with a
radix (`.`) requires digits before or after but not both. The additional
test cases were pulled from https://go.dev/ref/spec.
Copy link

Build Size Report

Changes to minified artifacts in /build, after gzip compression.

3 files changed

Total change +187 B

View Changes
file base pr diff
es/languages/go.min.js 688 B 781 B +93 B
highlight.min.js 8.21 KB 8.21 KB -1 B
languages/go.min.js 694 B 789 B +95 B

These numbers get picked up by the decimal regex.
@lugray
Copy link
Contributor Author

lugray commented Feb 12, 2024

Also any reason we can't group the two octal rules together?

Defining the two together before defining decimals caused us to match the beginnings of what should be matched as decimal/complex floats such as 0., 0.15e+0_2, and 0.i, and excludes as a number the decimal component.

Defining the two together after defining decimals caused 0o... style octals to get matched as a 0 decimal number, leaving the o... unhighlighted.

But writing this out made me realize that we don't ever actually match an octal without the [oO] as an octal. To the regex, it looks like a decimal. So we can drop the second octal rule.

Copy link

Build Size Report

Changes to minified artifacts in /build, after gzip compression.

5 files changed

Total change +201 B

View Changes
file base pr diff
es/core.min.js 8.17 KB 8.17 KB +1 B
es/highlight.min.js 8.17 KB 8.17 KB +1 B
es/languages/go.min.js 688 B 786 B +98 B
highlight.min.js 8.21 KB 8.21 KB +1 B
languages/go.min.js 694 B 794 B +100 B

Copy link

Build Size Report

Changes to minified artifacts in /build, after gzip compression.

5 files changed

Total change +101 B

View Changes
file base pr diff
es/languages/go.min.js 688 B 793 B +105 B
es/languages/markdown.min.js 960 B 905 B -55 B
highlight.min.js 8.21 KB 8.21 KB -1 B
languages/go.min.js 694 B 800 B +106 B
languages/markdown.min.js 960 B 906 B -54 B

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Copy link

Build Size Report

Changes to minified artifacts in /build, after gzip compression.

5 files changed

Total change +208 B

View Changes
file base pr diff
es/core.min.js 8.17 KB 8.17 KB -1 B
es/highlight.min.js 8.17 KB 8.17 KB -1 B
es/languages/go.min.js 688 B 793 B +105 B
highlight.min.js 8.21 KB 8.21 KB -1 B
languages/go.min.js 694 B 800 B +106 B

@joshgoebel joshgoebel merged commit 1f1908d into highlightjs:main Feb 20, 2024
15 checks passed
@lugray lugray deleted the fix_go_number_higlighting branch February 20, 2024 16:13
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.

None yet

2 participants