Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strformat not highlighted correct in some cases #115

Open
ghost opened this issue Jan 17, 2019 · 3 comments
Open

strformat not highlighted correct in some cases #115

ghost opened this issue Jan 17, 2019 · 3 comments

Comments

@ghost
Copy link

ghost commented Jan 17, 2019

The syntax improvements introduced by #105 (comment) don't display correct in the following two cases with "incorrect coloring" :

import strformat

var a = fmt"{""}"          # incorrect code; correct coloring 
var b = fmt"{"a"}"         # incorrect code; incorrect coloring
var c = fmt"{'a'}"         # correct code; correct coloring
var d = fmt"""{"""a"""}""" # incorrect code; incorrect coloring

syntax

For me it seemed like I could use "..." inside the strformat because the coloring implied it also the compiler error wasn't clear, then I saw that the color highlight needs changes for this case.

@ghost
Copy link
Author

ghost commented Jan 19, 2019

Another one is:

echo fmt"{{}}"

And also with round brackets for the call it isnt highlighted correct (see tests in strformat.nim)

@izikeros
Copy link

izikeros commented May 6, 2020

I found, that fmt used with triple double quotes can break coloring in following lines.
Examples where fmt breaks coloring:

fmt_nok

when fmt is removed, coloring back to the norm:

fmt_ok

@timotheecour
Copy link

timotheecour commented Dec 29, 2020

hit this again:

  block: # nim --eval
    let opt = "--hints:off"
    check fmt"""{nim} {opt} --eval:"echo defined(nimscript)"""".execCmdEx == ("true\n", 0)
    check fmt"""{nim} r {opt} --eval:"echo defined(c)"""".execCmdEx == ("true\n", 0)
    check fmt"""{nim} r -b:js {opt} --eval:"echo defined(js)"""".execCmdEx == ("true\n", 0)

  block: # `hintProcessing` dots should not interfere with `static: echo` + friends
    let cmd = fmt"""{nim} r {defaultHintsOff} --hint:processing -f --eval:"static: echo 1+1""""
    let (outp, exitCode) = execCmdEx(cmd, options = {poStdErrToStdOut})
    template check3(cond) = doAssert cond, $(outp,)
    doAssert exitCode == 0
    let lines = outp.splitLines
    check3 lines.len == 3
    when not defined(windows): # xxx: on windows, dots not properly handled, gives: `....2\n\n`
      check3 lines[0].isDots
      check3 lines[1] == "2"
      check3 lines[2] == ""
    else:
      check3 "2" in outp

=>
https://files.gitter.im/5fb473f1d73408ce4ff44cee/mPUt/image.png

it works fine in sublime text (which uses https://github.com/Varriount/NimLime for syntax definitions, just like github via github linguist)

EDIT

looks like the culprit is that syntax definition doesn't understand when there are more than 3 consecutive " (which are allowed); the highliting is correct with:

    let cmd = fmt"""{nim} r {defaultHintsOff} --hint:processing -f --eval:"static: echo 1+1""""
=>
    let cmd = fmt"""{nim} r {defaultHintsOff} --hint:processing -f --eval:"static: echo 1+1" """

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants