Packages: [Python] Integer and float highligting issue

Created on 5 Jun 2017  路  5Comments  路  Source: sublimehq/Packages

Summary

Syntax highlighting in Python, by default all the digits or any integer or float are blue but when we type number like 069 the last 9 changes to white. The problem seems to persist for the following pattern

  1. 0 [8-9][0-9]*
  2. [0-9]*.[0-9]*[0-9]
  3. 0[0-9]*[8-9]

Expected behavior

All digits should be blue

Actual behavior

The bold digits in regex shown above are white

Steps to reproduce

  1. Open sublime text
  2. Select Python as the file type from bottom right corner
  3. Type any of the regex as above - example 08234646 or 35345.2234 or 069

Environment

  • Operating system and version:

    • Linux Ubuntu 16.04
  • Sublime Text:

    • Build 3126

Most helpful comment

Oh, and please elaborate on the [0-9]*.[0-9]*[0-9] regex, that matches 35345.2234, as per your example, but is scoped correctly for me (as constant.numeric.float.python).

All 5 comments

numbers starting with 0 in Python are in the Octal base, and so it seems correct that 8 and 9 wouldn't be scoped as a number. https://stackoverflow.com/questions/11620151/what-do-numbers-starting-with-0-mean-in-python

>>> print(089)
  File "<string>", line 1
    print(089)
            ^
SyntaxError: invalid token

It might make sense to keep this issue open so we can discuss whether the unexpected digits should be scoped as invalid or not - I'd vote for yes as it's a syntax error.

CopyingMoving myself from the other issue (https://github.com/SublimeTextIssues/Core/issues/1747):

Not sure what you're expecting, but 069 is invalid syntax and that's why it's not colorized entirely. You could argue that the offending parts of a token should be highlighted, which I also considered doing, but instead continued highlighting it the way it has before.

fichte@pinaceae> python
Python 3.6.1 (default, Mar 27 2017, 00:27:06) 
[GCC 6.3.1 20170306] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 069
  File "<stdin>", line 1
    069
      ^
SyntaxError: invalid token
>>> exit()
fichte@pinaceae> python2
Python 2.7.13 (default, Feb 11 2017, 12:22:40) 
[GCC 6.3.1 20170109] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 069
  File "<stdin>", line 1
    069
      ^
SyntaxError: invalid token

I'm +1 for highlighting something as invalid, just not sure what. Should it be the entire number or just the offending and trailing part? The latter is probably less intrusive while typing. Might also be worth to take a look at other languages.

Oh, and please elaborate on the [0-9]*.[0-9]*[0-9] regex, that matches 35345.2234, as per your example, but is scoped correctly for me (as constant.numeric.float.python).

@FichteFoll Initially in the given example, last digit was coming out to be white. But I think that issue has been resolved when I updated my Sublime text styling packages from this repo.

Was this page helpful?
0 / 5 - 0 ratings