Skip to content

[julia mode] Typing zero in front of numbers breaks code display and syntax highlighting #6064

@Firionus

Description

@Firionus

I noticed this issue in Julia-Jupyter Notebooks and already wrongly reported it as a bug in IJulia:
JuliaLang/IJulia.jl#887
I was swiftly pointed here.

Minimal Example

  • Open /demo/loadmode.html
  • type "julia" in the lower text box and hit "change mode"
    • second line will change to "Current mode: julia"
  • type 01 in the main editor text box
    • the 1 will not appear.
    • Further typing is almost impossible (except for writing one .)
    • The console (here Firefox) throws two errors:
Error: Mode julia failed to advance stream. codemirror.js:1174:11
    readToken file:///E:/ZickeZackeHühnerkacke/Codemirror Debugging/node_modules/codemirror/lib/codemirror.js:1174
    runMode file:///E:/ZickeZackeHühnerkacke/Codemirror Debugging/node_modules/codemirror/lib/codemirror.js:1228
    highlightLine file:///E:/ZickeZackeHühnerkacke/Codemirror Debugging/node_modules/codemirror/lib/codemirror.js:1074
    getLineStyles file:///E:/ZickeZackeHühnerkacke/Codemirror Debugging/node_modules/codemirror/lib/codemirror.js:1118
    buildLineContent file:///E:/ZickeZackeHühnerkacke/Codemirror Debugging/node_modules/codemirror/lib/codemirror.js:1751
    getLineContent file:///E:/ZickeZackeHühnerkacke/Codemirror Debugging/node_modules/codemirror/lib/codemirror.js:2141
    updateLineText file:///E:/ZickeZackeHühnerkacke/Codemirror Debugging/node_modules/codemirror/lib/codemirror.js:2149
    updateLineForChanges file:///E:/ZickeZackeHühnerkacke/Codemirror Debugging/node_modules/codemirror/lib/codemirror.js:2098
    patchDisplay file:///E:/ZickeZackeHühnerkacke/Codemirror Debugging/node_modules/codemirror/lib/codemirror.js:4218
    updateDisplayIfNeeded file:///E:/ZickeZackeHühnerkacke/Codemirror Debugging/node_modules/codemirror/lib/codemirror.js:4119
    endOperation_W1 file:///E:/ZickeZackeHühnerkacke/Codemirror Debugging/node_modules/codemirror/lib/codemirror.js:3827
    endOperations file:///E:/ZickeZackeHühnerkacke/Codemirror Debugging/node_modules/codemirror/lib/codemirror.js:3804
    endOperation file:///E:/ZickeZackeHühnerkacke/Codemirror Debugging/node_modules/codemirror/lib/codemirror.js:3793
    finishOperation file:///E:/ZickeZackeHühnerkacke/Codemirror Debugging/node_modules/codemirror/lib/codemirror.js:2053
    endOperation file:///E:/ZickeZackeHühnerkacke/Codemirror Debugging/node_modules/codemirror/lib/codemirror.js:3790
    runInOp file:///E:/ZickeZackeHühnerkacke/Codemirror Debugging/node_modules/codemirror/lib/codemirror.js:3919
    poll file:///E:/ZickeZackeHühnerkacke/Codemirror Debugging/node_modules/codemirror/lib/codemirror.js:9519
    init file:///E:/ZickeZackeHühnerkacke/Codemirror Debugging/node_modules/codemirror/lib/codemirror.js:9313
Error: Mode julia failed to advance stream. codemirror.js:1174:11
    readToken file:///E:/ZickeZackeHühnerkacke/Codemirror Debugging/node_modules/codemirror/lib/codemirror.js:1174
    runMode file:///E:/ZickeZackeHühnerkacke/Codemirror Debugging/node_modules/codemirror/lib/codemirror.js:1228
    highlightLine file:///E:/ZickeZackeHühnerkacke/Codemirror Debugging/node_modules/codemirror/lib/codemirror.js:1074
    highlightWorker file:///E:/ZickeZackeHühnerkacke/Codemirror Debugging/node_modules/codemirror/lib/codemirror.js:3968
    iterN file:///E:/ZickeZackeHühnerkacke/Codemirror Debugging/node_modules/codemirror/lib/codemirror.js:5624
    iterN file:///E:/ZickeZackeHühnerkacke/Codemirror Debugging/node_modules/codemirror/lib/codemirror.js:5736
    iter file:///E:/ZickeZackeHühnerkacke/Codemirror Debugging/node_modules/codemirror/lib/codemirror.js:6134
    highlightWorker file:///E:/ZickeZackeHühnerkacke/Codemirror Debugging/node_modules/codemirror/lib/codemirror.js:3964
    bind file:///E:/ZickeZackeHühnerkacke/Codemirror Debugging/node_modules/codemirror/lib/codemirror.js:148
    onTimeout file:///E:/ZickeZackeHühnerkacke/Codemirror Debugging/node_modules/codemirror/lib/codemirror.js:185
    bind file:///E:/ZickeZackeHühnerkacke/Codemirror Debugging/node_modules/codemirror/lib/codemirror.js:148

In the other issue I have detailed some breaking and non-breaking things to type:

Breaking Strings

  • 01
  • 02
  • 06
  • 00
  • -01
  • +01
  • .01
  • .02
  • \01
  • (01
  • ?01
  • =01
  • 0,01 (no 1)
  • 01. (one appears after hitting ".". Backspace needs to be hit two times to remove both dot and one)
  • 00.01 (analogous with dot)
  • 00a (only first zero appears)

Non-breaking Strings

  • a01
  • z04
  • _01
  • 0.2
  • 0.0
  • 0.01
  • '01
  • "01
  • 0"1
  • 0a
  • 0'

Testing environment

CodeMirror v5.49.2 from npm, manually added /demo and /doc from Github master (a9789c7)
Firefox 71.0b9 and Chrome 78.0.3904.97
Windows 10 1903 Build 18362.418

Bug found in current Jupyter

>jupyter --version
jupyter core     : 4.6.1
jupyter-notebook : 6.0.2
qtconsole        : 4.5.5
ipython          : 7.9.0
ipykernel        : 5.1.3
jupyter client   : 5.3.4
jupyter lab      : not installed
nbconvert        : 5.6.1
ipywidgets       : 7.5.1
nbformat         : 4.4.0
traitlets        : 4.3.3

Likely cause

Seems to be a regression in 65fab82.
It was the last change to the code in the julia mode and replacing the julia.js with the one from the commit before (ff978a0) fixes the zeros-issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions