Text Editor: correct number highlighting #98971

Open
opened 2022-06-18 13:22:17 +02:00 by jon denning · 1 comment
Member

Blender's tokenizer does not match CPython's (source ) when it comes to tokenizing numbers.

This task is related to D14739 and #72964. This is a relatively easy issue to fix, but (...thinking out loud on topics WAY outside the scope of this task...) I wonder if it makes sense to take another look at Blender's tokenizer and parsing code. Right now, Blender only tokenizes and then marks up the text in order to offer some basic highlighting for Python only. Also, many of the text editor features (ex: Find) are extremely simple. Could Blender's community benefit from either 1) a more extensive built-in editor or 2) improved integration features for using an external editor? There are a few submissions on Right-Click Select that could be solved/added with an improved parser. Perhaps this would be a good GSoC project?

The following is some example code showing where the two tokenizers agree and where they disagree, and below that is a screenshot showing how the text editor renders the example code.

# https://github.com/python/cpython/blob/3.10/Parser/tokenizer.c

### the good ###

# valid syntax, correctly highlighted

1000    # standard int
1.000   # standard float
1_000   # using _ as separator
1_0_0
0x300   # hex
0x4aA
0o123   # octal
0O123   # (can use capital O)
0b000   # binary
1e400   # scientific notation (exponent)
1E400
1 + 2j  # imaginary numbers
1 - 2j
0x1e20  # hex with scientific notation

# invalid syntax, correctly highlighted

0oo0123  # double o
0bb01    # double b
0xx12    # double x
0x42AXY  # hex with non-hex digits
1e       # incomplete scientific notation (no exponent)
0x1e0x1  # exponent must be in decimal (not hex)


### the bad ###

# valid syntax, wrong highlighting
1e-40   # - is op
1e+42   # e, + is op
1.

# invalid syntax, wrong highlighting
1_     # end with _
1__00  # double _
2jj    # double j
1.0.0  # extra .
1e2e2  # extra e
0B1e2  # cannot have e with 0b
0o1e2  # cannot have e with 0o

image.png

Blender's tokenizer does not match CPython's ([source ](https://github.com/python/cpython/blob/3.10/Parser/tokenizer.c)) when it comes to tokenizing numbers. This task is related to [D14739](https://archive.blender.org/developer/D14739) and #72964. This is a relatively easy issue to fix, but (...thinking out loud on topics WAY outside the scope of this task...) I wonder if it makes sense to take another look at Blender's tokenizer and parsing code. Right now, Blender only tokenizes and then marks up the text in order to offer some basic highlighting for Python only. Also, many of the text editor features (ex: Find) are extremely simple. Could Blender's community benefit from either 1) a more extensive built-in editor or 2) improved integration features for using an external editor? There are a few submissions on [Right-Click Select ](https://blender.community/c/rightclickselect) that could be solved/added with an improved parser. Perhaps this would be a good GSoC project? The following is some example code showing where the two tokenizers agree and where they disagree, and below that is a screenshot showing how the text editor renders the example code. ``` # https://github.com/python/cpython/blob/3.10/Parser/tokenizer.c ### the good ### # valid syntax, correctly highlighted 1000 # standard int 1.000 # standard float 1_000 # using _ as separator 1_0_0 0x300 # hex 0x4aA 0o123 # octal 0O123 # (can use capital O) 0b000 # binary 1e400 # scientific notation (exponent) 1E400 1 + 2j # imaginary numbers 1 - 2j 0x1e20 # hex with scientific notation # invalid syntax, correctly highlighted 0oo0123 # double o 0bb01 # double b 0xx12 # double x 0x42AXY # hex with non-hex digits 1e # incomplete scientific notation (no exponent) 0x1e0x1 # exponent must be in decimal (not hex) ### the bad ### # valid syntax, wrong highlighting 1e-40 # - is op 1e+42 # e, + is op 1. # invalid syntax, wrong highlighting 1_ # end with _ 1__00 # double _ 2jj # double j 1.0.0 # extra . 1e2e2 # extra e 0B1e2 # cannot have e with 0b 0o1e2 # cannot have e with 0o ``` ![image.png](https://archive.blender.org/developer/F13188564/image.png)
Author
Member

Added subscriber: @gfxcoder

Added subscriber: @gfxcoder
Philipp Oeser removed the
Interest
Python API
label 2023-02-10 09:04:26 +01:00
Iliya Katushenock added
Interest
Python API
and removed
Module
Python API
labels 2023-08-24 17:37:59 +02:00
Iliya Katushenock removed the
Status
Needs Triage
label 2024-04-07 22:22:35 +02:00
Iliya Katushenock added this to the Python API project 2024-04-07 22:22:46 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#98971
No description provided.