highlightjs / highlight.js

JavaScript syntax highlighter with language auto-detection and zero dependencies.
https://highlightjs.org/
BSD 3-Clause "New" or "Revised" License
23.31k stars 3.52k forks source link

Fix go number highlighting #3981

Closed lugray closed 4 months ago

lugray commented 5 months ago

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

github-actions[bot] commented 4 months ago

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 |
lugray commented 4 months ago

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.

github-actions[bot] commented 4 months ago

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 |
github-actions[bot] commented 4 months ago

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 |
github-actions[bot] commented 4 months ago

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 |