[GHC] #14473: Implement Underscores in Numeric Literals Proposal (NumericUnderscores extension)
#14473: Implement Underscores in Numeric Literals Proposal (NumericUnderscores extension) -------------------------------------+------------------------------------- Reporter: takenobu | Owner: (none) Type: task | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.2.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: #13126 #9224 Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Implement Underscores in Numeric Literals Proposal. GHC supports various numeric literals such as decimal, octal, hexadecimal, binary, and floating point numbers. However, large numeric literals are hard to read. This proposal improves the readability, quality, expressiveness of numeric literals. This proposal allows underscores to numeric literals when the `NumericUnderscores` language extension is enabled. Underscores (`_`) in numeric literals are simply ignored. The specification of the feature is available here:\\ https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0009 -numeric-underscores.rst For a discussion:\\ https://github.com/ghc-proposals/ghc-proposals/pull/76 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14473> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14473: Implement Underscores in Numeric Literals Proposal (NumericUnderscores extension) -------------------------------------+------------------------------------- Reporter: takenobu | Owner: (none) Type: task | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #13126 #9224 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by takenobu): I am planning to submit a patch. This is the patch of the current version:\\ https://github.com/takenobu-hs/ghc/compare/master...takenobu-hs:wip /numeric-underscores About it, Iavor gave me good advice:\\ https://github.com/ghc-proposals/ghc- proposals/pull/76#issuecomment-344347463 That is, I unify the definition of Lexer and add a validation function. After investigating how to implement the function for validation, I will submit the patch. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14473#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14473: Implement Underscores in Numeric Literals Proposal (NumericUnderscores extension) -------------------------------------+------------------------------------- Reporter: takenobu | Owner: takenobu Type: task | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #13126 #9224 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by takenobu): * owner: (none) => takenobu -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14473#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14473: Implement Underscores in Numeric Literals Proposal (NumericUnderscores extension) -------------------------------------+------------------------------------- Reporter: takenobu | Owner: takenobu Type: task | Status: patch Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #13126 #9224 | Differential Rev(s): Phab:D4235 Wiki Page: | -------------------------------------+------------------------------------- Changes (by takenobu): * status: new => patch * differential: => Phab:D4235 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14473#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14473: Implement Underscores in Numeric Literals Proposal (NumericUnderscores extension) -------------------------------------+------------------------------------- Reporter: takenobu | Owner: takenobu Type: task | Status: patch Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #13126 #9224 | Differential Rev(s): Phab:D4235 Wiki Page: | -------------------------------------+------------------------------------- Comment (by takenobu): I submitted a patch Phab:D4235. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14473#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14473: Implement Underscores in Numeric Literals Proposal (NumericUnderscores extension) -------------------------------------+------------------------------------- Reporter: takenobu | Owner: takenobu Type: task | Status: patch Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #13126 #9224 | Differential Rev(s): Phab:D4235 Wiki Page: | -------------------------------------+------------------------------------- Comment (by takenobu): For the later people, I record about the correspondence status of the syntax highlight on editors and code browsers for `BinaryLiterals`, `HexFloatLiterals` and `NumericUnderscores` extensions. * Vim * It has already been officially implemented. Since patch 8.0.1401 * https://github.com/vim/vim/pull/2455 * Emacs * Lowercase literals are already almost correctly displayed. * `haskell-lexeme.el` and `haskell-font-lock.el` * Atom (language-haskell package) * It has already been officially implemented. Since 1.15.0 * https://github.com/atom-haskell/language-haskell/pull/112 * Visual Studio Code (language-haskell extension) * It has already been officially implemented. * https://github.com/JustusAdam/language-haskell/pull/49 * Linguist (which is used from github) * Linguis uses language-haskell submodule of atom. * Linguis will bump it at new year release. * Pygments (which is used from trac, readthedocs, pandoc, ...) * This is pending review. * https://bitbucket.org/birkenfeld/pygments-main/pull-requests/745 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14473#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14473: Implement Underscores in Numeric Literals Proposal (NumericUnderscores extension) -------------------------------------+------------------------------------- Reporter: takenobu | Owner: takenobu Type: task | Status: patch Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #13126 #9224 | Differential Rev(s): Phab:D4235 Wiki Page: | -------------------------------------+------------------------------------- Comment (by _recursion): I've submitted an issue for this for SublimeHaskell (Sublime Text Haskell plugin) which can be found here: https://github.com/SublimeHaskell/SublimeHaskell/issues/387 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14473#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14473: Implement Underscores in Numeric Literals Proposal (NumericUnderscores extension) -------------------------------------+------------------------------------- Reporter: takenobu | Owner: takenobu Type: task | Status: patch Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #13126 #9224 | Differential Rev(s): Phab:D4235 Wiki Page: | -------------------------------------+------------------------------------- Comment (by takenobu): _recursion,thank you so much! -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14473#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14473: Implement Underscores in Numeric Literals Proposal (NumericUnderscores extension) -------------------------------------+------------------------------------- Reporter: takenobu | Owner: takenobu Type: task | Status: patch Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #13126 #9224 | Differential Rev(s): Phab:D4235 Wiki Page: | -------------------------------------+------------------------------------- Comment (by Ben Gamari <ben@…>): In [changeset:"4a13c5b1f4beb53cbf1f3529acdf3ba37528e694/ghc" 4a13c5b1/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="4a13c5b1f4beb53cbf1f3529acdf3ba37528e694" Implement underscores in numeric literals (NumericUnderscores extension) Implement the proposal of underscores in numeric literals. Underscores in numeric literals are simply ignored. The specification of the feature is available here: https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/000 9-numeric-underscores.rst For a discussion of the various choices: https://github.com/ghc-proposals/ghc-proposals/pull/76 Implementation detail: * Added dynamic flag * `NumericUnderscores` extension flag is added for this feature. * Alex "Regular expression macros" in Lexer.x * Add `@numspc` (numeric spacer) macro to represent multiple underscores. * Modify `@decimal`, `@decimal`, `@binary`, `@octal`, `@hexadecimal`, `@exponent`, and `@bin_exponent` macros to include `@numspc`. * Alex "Rules" in Lexer.x * To be simpler, we have only the definitions with underscores. And then we have a separate function (`tok_integral` and `tok_frac`) that validates the literals. * Validation functions in Lexer.x * `tok_integral` and `tok_frac` functions validate whether contain underscores or not. If `NumericUnderscores` extensions are not enabled, check that there are no underscores. * `tok_frac` function is created by merging `strtoken` and `init_strtoken`. * `init_strtoken` is deleted. Because it is no longer used. * Remove underscores from target literal string * `parseUnsignedInteger`, `readRational__`, and `readHexRational} use the customized `span'` function to remove underscores. * Added Testcase * testcase for NumericUnderscores enabled. NumericUnderscores0.hs and NumericUnderscores1.hs * testcase for NumericUnderscores disabled. NoNumericUnderscores0.hs and NoNumericUnderscores1.hs * testcase to invalid pattern for NumericUnderscores enabled. NumericUnderscoresFail0.hs and NumericUnderscoresFail1.hs Test Plan: `validate` including the above testcase Reviewers: goldfire, bgamari Reviewed By: bgamari Subscribers: carter, rwbarton, thomie GHC Trac Issues: #14473 Differential Revision: https://phabricator.haskell.org/D4235 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14473#comment:8> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14473: Implement Underscores in Numeric Literals Proposal (NumericUnderscores extension) -------------------------------------+------------------------------------- Reporter: takenobu | Owner: takenobu Type: task | Status: closed Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.2.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #13126 #9224 | Differential Rev(s): Phab:D4235 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: patch => closed * resolution: => fixed Comment: Thanks for taking this on, takenobu! -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14473#comment:9> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14473: Implement Underscores in Numeric Literals Proposal (NumericUnderscores extension) -------------------------------------+------------------------------------- Reporter: takenobu | Owner: takenobu Type: task | Status: closed Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.2.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #13126 #9224 | Differential Rev(s): Phab:D4235 Wiki Page: | -------------------------------------+------------------------------------- Comment (by takenobu): It's my pleasure :) -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14473#comment:10> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14473: Implement Underscores in Numeric Literals Proposal (NumericUnderscores extension) -------------------------------------+------------------------------------- Reporter: takenobu | Owner: takenobu Type: task | Status: closed Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.2.1 Resolution: fixed | Keywords: GHCProposal Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #13126 #9224 | Differential Rev(s): Phab:D4235 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * keywords: => GHCProposal -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14473#comment:11> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#14473: Implement Underscores in Numeric Literals Proposal (NumericUnderscores extension) -------------------------------------+------------------------------------- Reporter: takenobu | Owner: takenobu Type: task | Status: closed Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.2.1 Resolution: fixed | Keywords: GHCProposal Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #13126 #9224 | Differential Rev(s): Phab:D4235 Wiki Page: | -------------------------------------+------------------------------------- Comment (by takenobu):
Pygments (which is used from trac, readthedocs, pandoc, ...) This is pending review. https://bitbucket.org/birkenfeld/pygments-main/pull-requests/745
The patch for Pygments has been merged. (Development of Pygments was restarted.) Syntax hightlight for NumericUnderscores, BinaryLiterals and HexFloatLiterals will be available on Pygments, Sphinx, readthedocs and pandoc. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14473#comment:12> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC