bitwisecook / vscode-tcl

Tcl for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=bitwisecook.tcl
MIT License
39 stars 20 forks source link

Syntax highlighting breaks on regexp and square brackets #4

Closed maciejmatczak closed 2 years ago

maciejmatczak commented 3 years ago

Example:


if { [regexp -nocase {pattern} [otherProc]] } {
}

# code below doesn't format well
# example: https://wiki.tcl-lang.org/page/nested+list
proc left {args} {
    # nl2 left ...
    ::set L [::list ""]
    ::set i 0
    ::foreach e $args {
        if {[::llength $e] != 1} {::set e [list $e]}
        ::lset L {*}$i [::list "" $e]
        ::lappend i 0
    }
    ::return {*}$L  
}

Incorrectly formats as (dark+): image

Seems to be correlated with regexp command itself and with nested evaluation in last argument. Also, when I delete last closing curly from if clause, the last section pick ups proper highlighting.

dylan-robins commented 3 years ago

Also have this issue, did you ever find a way around it?

SnirYehuda commented 2 years ago

Also happens for regsub not good: image

good: image

maciejmatczak commented 2 years ago

In some other tmlanguage end match for regex is defined as: https://github.com/bradrobertson/sublime-packages/blob/22811a99485215062b7fe31990976c3b66b71a58/TCL/Tcl.tmLanguage#L114

In this plugin end match for regex is defined as: https://github.com/bitwisecook/vscode-tcl/blob/5148b946adc5b3a4e1b63978735f9060b13c462e/syntaxes/tcl.tmlanguage.yaml#L2902

I am not sure if there is not too many slashes there ;)

ethantheb commented 2 years ago

Is there a way to fix this locally? I want to use this plugin but can't change hundreds of lines of code to remove all of the nested evals.

Update: coworker is a wizard, this seems to work. It seemed to be matching any end bracket? end: "(?=(?<!\\\\)(?:$|.*[\n;}\\]]))"

dylan-robins commented 2 years ago

Oh nice! I'm going to be using TCL again in a few days, I'll try your modified regex and see how I get on with it.

bitwisecook commented 2 years ago

thank you @ethantheb and your coworker, I'll merge this as it seems to fix your example for me @maciejmatczak

bitwisecook commented 2 years ago

Release 0.4.1 has this fix and I've pushed it out to the extension marketplace.