Skip to content

Support for underscores in Python numbers #3038#3039

Merged
RunDevelopment merged 2 commits into
PrismJS:masterfrom
marvintensuan:issue-3038
Aug 16, 2021
Merged

Support for underscores in Python numbers #3038#3039
RunDevelopment merged 2 commits into
PrismJS:masterfrom
marvintensuan:issue-3038

Conversation

@marvintensuan

Copy link
Copy Markdown
Contributor

Modified the regex for number in prism-python.js from:

'number': /(?:\b(?=\d)|\B(?=\.))(?:0[bo])?(?:(?:\d|0x[\da-f])[\da-f]*(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?j?\b/i,

to:

/(?:\b(?=\d)|\B(?=\.))(?:0[bo](_)?)?(?:(?:\d|0x(_)?[\da-f])([\da-f]|[\da-f]_)*(?:\.\d*)?|\.\d+|((\d+_)*(\.)?(\d+)?)*)(?:e[+-]?\d+)?([^_]j)?\b/i

I have highlighted the rationale at #3038. Additional test cases were also added.


Test results:

> prismjs@1.24.1 test:languages (...)\prism
> mocha tests/run.js "--language=python"



  Testing language 'python'
    √ – should pass test case 'boolean_feature'
    √ – should pass test case 'builtin_feature'
    √ – should pass test case 'class-name_feature'
    √ – should pass test case 'comment_feature'
    √ – should pass test case 'decorator_feature'
    √ – should pass test case 'function_feature'
    √ – should pass test case 'issue1355'
    √ – should pass test case 'keyword_feature'
    √ – should pass test case 'number_feature'
    √ – should pass test case 'operator_feature'
    √ – should pass test case 'string-interpolation_feature'
    √ – should pass test case 'string_feature'
    √ – should pass test case 'triple-quoted-string_feature'


  13 passing (101ms)

@github-actions

github-actions Bot commented Aug 16, 2021

Copy link
Copy Markdown

JS File Size Changes (gzipped)

A total of 1 files have changed, with a combined diff of +13 B (+1.2%).

Details
file master pull size diff % diff
components/prism-python.min.js 1.05 KB 1.06 KB +13 B +1.2%

Generated by 🚫 dangerJS against c56db5a

@marvintensuan marvintensuan changed the title Support for underscores in Python numbers #3038 Support for underscores in Python numbers resolve #3038 Aug 16, 2021
@marvintensuan marvintensuan changed the title Support for underscores in Python numbers resolve #3038 Support for underscores in Python numbers #3038 Aug 16, 2021
@RunDevelopment RunDevelopment linked an issue Aug 16, 2021 that may be closed by this pull request

@RunDevelopment RunDevelopment left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for the PR @marvintensuan!

I have a suggestion. Also, please rebuild Prism by running npm run build and committing the changes to prism-python.min.js.

Comment thread components/prism-python.js Outdated
@RunDevelopment RunDevelopment merged commit 6f5d68f into PrismJS:master Aug 16, 2021
@RunDevelopment

Copy link
Copy Markdown
Member

Thank you for contributing @marvintensuan!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for Python underscores in numeric literals

2 participants