From 71b9df7c42f3ab4d6bdbc6c5c8b72ca187378f7d Mon Sep 17 00:00:00 2001 From: Tan Le Date: Sun, 7 Apr 2024 17:39:23 +1000 Subject: [PATCH] Fix comment highlight in TCL lexer (#2041) --- lib/rouge/lexers/tcl.rb | 9 +++++++-- spec/visual/samples/tcl | 13 +++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/rouge/lexers/tcl.rb b/lib/rouge/lexers/tcl.rb index e73730ae3f..1bc6c8645f 100644 --- a/lib/rouge/lexers/tcl.rb +++ b/lib/rouge/lexers/tcl.rb @@ -57,9 +57,9 @@ def self.detect?(text) def self.gen_command_state(name='') state(:"command#{name}") do - mixin :word + rule %r/#/, Comment, :comment - rule %r/##{NOT_CHARS[END_LINE]}+/, Comment::Single + mixin :word rule %r/(?=#{CHARS[END_WORD]})/ do push :"params#{name}" @@ -163,6 +163,11 @@ def self.gen_delimiter_states(name, close, opts={}) rule %r/\\./m, Str::Escape end + state :comment do + rule %r/.*[^\\]\n/, Comment, :pop! + rule %r/.*\\\n/, Comment + end + state :string do rule %r/"/, Str::Double, :pop! mixin :interp diff --git a/spec/visual/samples/tcl b/spec/visual/samples/tcl index 76b684f40f..eb3ec14d3d 100644 --- a/spec/visual/samples/tcl +++ b/spec/visual/samples/tcl @@ -323,3 +323,16 @@ test parse-1.63 "unquoted dollar sign" { } {x$} testreport + +# The braced form of variable substitution handles more complex variable names: +set greeting "Hello, ${first name}" + +# "set" can always be used instead of variable substitution, and can handle all +# variable names: +set greeting "Hello, [set {first name}]" + + +# To unpack a list into the command, use the expansion operator, "{*}". These +# two commands are equivalent: +set name Neo +set {*}{name Neo}