This is the mail archive of the insight@sourceware.org mailing list for the Insight project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC] syntax highlighting


Hi

I've ask Vineeth if the developing of the Patch already have started.
Since Vineeth told me that this is not the case.
So I'm sending here a patch, which should carefully reviewed.
The method isn't the fastest but it seems OK for the moment.

   cheers,
      Thomas

PS. 733 PATCH lines following
#####################################################################
--- srctextwin.ith.orig Mon Aug 1 18:56:18 2005
+++ srctextwin.ith Mon Aug 1 18:59:16 2005
@@ -134,6 +134,9 @@
method _initialize_srctextwin {}
method _clear_cache {}
method _highlightAsmLine {win addr pc_addr tagname filename funcname} {}
+ method scanAndTagTextWidget {win name} {}
+ method scanAndTagC {win} {}
+ method scanAndTagASM {win} {}


     proc makeBreakDot {size colorList {image {}}}
   }
--- srctextwin.itb.orig	Mon Aug  1 18:56:17 2005
+++ srctextwin.itb	Mon Aug  1 20:59:37 2005
@@ -1247,6 +1247,680 @@
   }
 }

+
+# ------------------------------------------------------------------
+# METHOD: scanAndTagTextWidget - for Syntax Highlight
+# ------------------------------------------------------------------
+itcl::body SrcTextWin::scanAndTagTextWidget {win name} {
+ if {[regexp {(.+)(\.)([chCH])([+pP])*$} $name ignore]} {
+ scanAndTagC $win
+ } elseif {[regexp {(.+)(\.)(([sS])|([aA][sS][mM]))$} $name ignore]} {
+ scanAndTagASM $win
+ }
+}
+
+# ------------------------------------------------------------------
+# METHOD: scanAndTagASM - for Syntax Highlight
+# ------------------------------------------------------------------
+itcl::body SrcTextWin::scanAndTagASM {win} {
+ set keyWords {(\.)([a-zA-Z0-9])+}
+
+ scan [$win index end] %d numLines
+ set multiLineComment 0
+ set multiLinePreProc 0
+ set multiLineString 0
+
+ for {set i 1} {$i < $numLines} {incr i} {
+ # skip first (' ' or '-') char, the TAB and the number
+ if {$Linenums} {
+ $win mark set last $i.2
+ set strLine [$win get last "last + 12 chars"]
+ if {[regexp -indices {([0-9])+} $strLine indices]} {
+ set idx_lo [lindex $indices 0]
+ set idx_hi [lindex $indices 1]
+ $win mark set first "last + $idx_lo chars"
+ $win mark set last "last + $idx_hi chars + 1 chars"
+ $win tag add hl_linenum first last
+ set k [expr [lindex $indices 1] + 3]
+ }
+ } else {
+ # skip first ' ' or '-' char
+ set k 1
+ }
+ # tag commends and strings
+ $win mark set last $i.$k
+ while { 1 } {
+ set strLine [$win get last "last lineend"]
+ if {$strLine == {}} break
+ if { ($multiLineComment == 0) && ($multiLineString == 0) } {
+ # searching /* or "
+ if {[regexp -indices {(/\*)|(//)|(\")} $strLine indices]} {
+ set idx_lo [lindex $indices 0]
+ set idx_hi [lindex $indices 1]
+ $win mark set first "last + $idx_lo chars"
+ # is it /*,// or "
+ if { [string index $strLine $idx_lo] != "/" } {
+ # it's quote " ;make sure it's not \"
+ if { $idx_lo == 0 || ($idx_lo > 0 && [string index $strLine [expr $idx_lo - 1]] != "\\") } {
+ $win mark set last "last + $idx_hi chars + 1 chars"
+ set strLine [$win get last "last lineend"]
+ # is there a closing " too
+ set found_quote_end 0
+ while {[regexp -indices {(\")} $strLine indices]} {
+ set idx_hi [lindex $indices 1]
+ # also without make sure it's not \"
+ if { $idx_hi == 0 || ($idx_hi > 0 && [string index $strLine [expr $idx_hi - 1]] != "\\") } {
+ $win mark set last "last + 1 chars + $idx_hi chars"
+ $win tag add hl_lineString first last
+ set found_quote_end 1
+ break
+ }
+ $win mark set last "last + 1 chars + $idx_hi chars"
+ set strLine [$win get last "last lineend"]
+ }
+ if {$found_quote_end == 0} {
+ # there is no quoting end in this line; seach for end of line
+ if {[regexp -indices {(.)$} $strLine indices]} {
+ set multiLineString 1
+ set idx_hi [lindex $indices 0]
+ $win mark set last "last + 1 chars + $idx_hi chars"
+ $win tag add hl_lineString first last
+ break
+ } else {
+ # something goes wrong
+ debug "missing lineend "
+ break
+ }
+ }
+ } else {
+ $win mark set last "last + $idx_hi chars + 1 chars"
+ }
+ } elseif { [string index $strLine [expr $idx_lo + 1]] == "/" } {
+ # it's line comment //
+ if {[regexp -indices {(.)$} $strLine indices]} {
+ set idx_hi [lindex $indices 0]
+ } else {
+ debug "missing lineend"
+ set idx_hi [lindex $indices 1]
+ }
+ $win mark set first "last + $idx_lo chars"
+ $win mark set last "last + 1 chars + $idx_hi chars"
+ $win tag add hl_comment first last
+ break
+ } else {
+ # it's a comment /*
+ $win mark set last "last + $idx_hi chars"
+ set strLine [$win get last "last lineend"]
+ # is there a closing */ too
+ if {[regexp -indices {(\*/)} $strLine indices]} {
+ set idx_hi [lindex $indices 1]
+ $win mark set last "last + 1 chars + $idx_hi chars"
+ $win tag add hl_comment first last
+ } elseif {[regexp -indices {(.)$} $strLine indices]} {
+ set multiLineComment 1
+ set idx_hi [lindex $indices 0]
+ $win mark set last "last + 1 chars + $idx_hi chars"
+ $win tag add hl_comment first last
+ break
+ } else {
+ # something goes wrong
+ debug "missing lineend "
+ break
+ }
+ }
+ } else {
+ # no more // or /*
+ break
+ }
+
+ } elseif { $multiLineComment == 0 } {
+ # multi line String
+ $win mark set first "last"
+ if {[regexp -indices {(\")} $strLine indices]} {
+ # it's quote " ;make sure it's not \"
+ set idx_hi [lindex $indices 1]
+ if { $idx_hi == 0 || ($idx_hi > 0 && [string index $strLine [expr $idx_hi - 1]] != "\\") } {
+ set multiLineString 0
+ $win mark set last "last + 1 chars + $idx_hi chars"
+ $win tag add hl_lineString first last
+ } else {
+ $win mark set last "last + 1 chars + $idx_hi chars"
+ }
+ } elseif {[regexp -indices {(.)$} $strLine indices]} {
+ set idx_hi [lindex $indices 0]
+ $win mark set last "last + 1 chars + $idx_hi chars"
+ $win tag add hl_lineString first last
+ break
+ } else {
+ # something goes wrong
+ debug "missing lineend "
+ break
+ }
+ } else {
+ # multi line comments
+ $win mark set first "last"
+ if {[regexp -indices {(\*/)} $strLine indices]} {
+ set multiLineComment 0
+ set idx_hi [lindex $indices 1]
+ $win mark set last "last + 1 chars + $idx_hi chars"
+ $win tag add hl_comment first last
+ } elseif {[regexp -indices {(.)$} $strLine indices]} {
+ set idx_hi [lindex $indices 0]
+ $win mark set last "last + 1 chars + $idx_hi chars"
+ $win tag add hl_comment first last
+ break
+ } else {
+ # something goes wrong
+ debug "missing lineend "
+ break
+ }
+ }
+ }
+ # tag prepocessor directives
+ $win mark set last $i.$k
+ while (1) {
+ set strLine [$win get last "last lineend"]
+ if { $multiLinePreProc == 0 } {
+ # search for a beginning #
+ if {[regexp -indices {(^([ \t])*#)} $strLine indices]} {
+ set idx_lo [lindex $indices 0]
+ set idx_hi [lindex $indices 1]
+ $win mark set first "last + $idx_lo chars"
+ $win mark set last "last + $idx_hi chars"
+ set strLine [$win get first "first lineend"]
+ set strEndPos [expr [string length $strLine] - 1]
+ # is there a reapet \
+ if {$strEndPos > 0} {
+ $win mark set last "last + 1 chars + $strEndPos chars"
+ $win tag add hl_preproc first last
+ if { [string index $strLine $strEndPos] == "\\" } {
+ set multiLinePreProc 1
+ } else {
+ # is there a <..> within this line
+ if {[regexp -indices {<([a-zA-Z0-9/\\\.]+)>} $strLine indices]} {
+ set idx_lo [lindex $indices 0]
+ set idx_hi [lindex $indices 1]
+ $win mark set last "first + 1 chars + $idx_hi chars"
+ $win mark set first "first + $idx_lo chars"
+ $win tag add hl_lineString first last
+ }
+ }
+ break
+ }
+ }
+ } else {
+ # multi line directives
+ $win mark set first "last"
+ set strLine [$win get first "first lineend"]
+ set strEndPos [expr [string length $strLine] - 1]
+ if {$strEndPos > 0} {
+ $win mark set last "last + 1 chars + $strEndPos chars"
+ $win tag add hl_preproc first last
+ if { [string index $strLine $strEndPos] != "\\" } {
+ set multiLinePreProc 0
+ }
+ break
+ }
+ }
+ break
+ }
+ # search for keywords and give those a tag
+ $win mark set last $i.$k
+ set strLine [$win get last "last lineend"]
+ while {[regexp -indices $keyWords $strLine indices]} {
+ set idx_lo [lindex $indices 0]
+ set idx_hi [lindex $indices 1]
+ $win mark set first "last + $idx_lo chars"
+ $win mark set last "last + 1 chars + $idx_hi chars"
+ set tag_names [$win tag names first]
+ if {[regexp {(hl_comment)|(hl_preproc)|(hl_lineString)} $tag_names] == 0} {
+ # only if it't not a comment
+ set cmpStr [string index $strLine [expr $idx_lo - 1]]
+ if { $idx_lo > 0 && [regexp {^[a-z]|^[A-Z]|^[#_\.>]} $cmpStr] } {
+ } else {
+ set cmpStr [string index $strLine [expr $idx_hi + 1]]
+ if {[regexp {^[0-9]|^[a-z]|^[A-Z]|^[_\-\.\:]} $cmpStr] == 0} {
+ $win tag add hl_keyword first last
+ }
+ }
+ }
+ set strLine [$win get last "last lineend"]
+ }
+ # search for labels and give those a tag
+ $win mark set last $i.$k
+ set strLine [$win get last "last lineend"]
+ if {[regexp -indices {^([ \t]*)([a-zA-Z0-9_\\\.])+:} $strLine indices]} {
+ # skip leading space chars
+ regexp -indices {([a-zA-Z0-9_\\\.])+:} $strLine indices
+ set idx_lo [lindex $indices 0]
+ set idx_hi [lindex $indices 1]
+ $win mark set first "last + $idx_lo chars"
+ $win mark set last "last + 1 chars + $idx_hi chars"
+ set tag_names [$win tag names first]
+ if {[regexp {(hl_comment)|(hl_lineString)|(hl_keyword)} $tag_names] == 0} {
+ $win tag add hl_label first last
+ }
+ }
+ #next line
+ }
+
+}
+
+# ------------------------------------------------------------------
+# METHOD: scanAndTagC - for Syntax Highlight
+# ------------------------------------------------------------------
+itcl::body SrcTextWin::scanAndTagC {win} {
+ # tagKeyword
+ #debug "tag Keyword $win $Linenums"
+ set keyWords [join {
+ (if) (then) (elif) (else) (do) (while) (for)
+ (break) (continue) (next) (goto)
+ (switch) (case) (default)
+ (return)
+ (sizeof)
+ (namespace) (using)
+ (try) (catch) (throw)
+ (new) (delete)
+ (template) (public:) (protected:) (private:)
+ (public) (protected) (private)
+ (operator) (friend) (this)
+ } | ]
+
+ set typeWords [join {
+ (__asm__) (__volatile__) (__attribute__)
+ (__inline__) (__label__)
+ (__complex__) (__real__) (__imag__)
+ (__typeof__) (__restrict__)
+ (inline) (virtual) (explicit)
+ (static) (extern) (auto) (register)
+ (typedef) (typeof) (typename)
+ (struct) (union) (enum) (class)
+ (const) (volatile) (restrict)
+ (void) (char) (short) (int) (long)
+ (signed) (unsigned)
+ (float) (double)
+ (asm)
+ (size_t) (ssize_t)
+ (wchar_t)
+ (clock_t) (time_t)
+ (va_list) (jmp_buf)
+ (FILE) (DIR)
+ (div_t) (ldiv_t)
+ (bool) (complex)
+ (int8_t) (int16_t) (int32_t) (int64_t)
+ (uint8_t) (uint16_t) (uint32_t) (uint64_t)
+ } | ]
+
+ set constWords [join {
+ (__GNUC__) (__FUNCTION__) (__PRETTY_FUNCTION__)
+ (__LINE__) (__FILE__) (__DATE__) (__TIME__) (__STDC__)
+ (__STDC_VERSION__) (__ELF__)
+ (UCHAR_MAX) (UINT_MAX) (ULONG_MAX) (USHRT_MAX)
+ (CHAR_MIN) (INT_MIN) (LONG_MIN) (SHRT_MIN)
+ (CHAR_MAX) (INT_MAX) (LONG_MAX) (SHRT_MAX)
+ (SCHAR_MIN) (SINT_MIN) (SLONG_MIN) (SSHRT_MIN)
+ (SCHAR_MAX) (SINT_MAX) (SLONG_MAX) (SSHRT_MAX)
+ (LLONG_MAX) (ULLONG_MAX)
+ (INT8_MIN) (INT16_MIN) (INT32_MIN) (INT64_MIN)
+ (INT8_MAX) (INT16_MAX) (INT32_MAX) (INT64_MAX)
+ (UINT8_MAX) (UINT16_MAX) (UINT32_MAX) (UINT64_MAX)
+ (SIZE_MAX) (WCHAR_MIN) (WCHAR_MAX) (WINT_MIN) (WINT_MAX)
+ (LC_ALL) (LC_COLLATE) (LC_CTYPE) (LC_MONETARY) (LC_NUMERIC) (LC_TIME)
+ (SIG_ATOMIC_MIN) (SIG_ATOMIC_MAX)
+ (SIG_DFL) (SIG_ERR) (SIG_IGN)
+ (SIGABRT) (SIGFPE) (SIGILL) (SIGHUP) (SIGINT) (SIGSEGV) (SIGTERM)
+ (SIGABRT) (SIGALRM) (SIGCHLD) (SIGCONT) (SIGFPE) (SIGHUP)
+ (SIGILL) (SIGINT) (SIGKILL) (SIGPIPE) (SIGQUIT) (SIGSEGV)
+ (SIGSTOP) (SIGTERM) (SIGTRAP) (SIGTSTP) (SIGTTIN) (SIGTTOU)
+ (SIGUSR1) (SIGUSR2)
+ (_IOFBF) (_IOLBF) (_IONBF) (BUFSIZ) (EOF) (WEOF)
+ (FOPEN_MAX) (FILENAME_MAX)
+ (SEEK_CUR) (SEEK_END) (SEEK_SET)
+ (stderr) (stdin) (stdout)
+ (E2BIG) (EACCES) (EAGAIN) (EBADF) (EBADMSG) (EBUSY)
+ (ECANCELED) (ECHILD) (EDEADLK) (EDOM) (EEXIST) (EFAULT)
+ (EFBIG) (EILSEQ) (EINPROGRESS) (EINTR) (EINVAL) (EIO) (EISDIR)
+ (EMFILE) (EMLINK) (EMSGSIZE) (ENAMETOOLONG) (ENFILE) (ENODEV)
+ (ENOENT) (ENOEXEC) (ENOLCK) (ENOMEM) (ENOSPC) (ENOSYS)
+ (ENOTDIR) (ENOTEMPTY) (ENOTSUP) (ENOTTY) (ENXIO) (EPERM)
+ (EPIPE) (ERANGE) (EROFS) (ESPIPE) (ESRCH) (ETIMEDOUT) (EXDEV)
+ (true) (false)
+ (TRUE) (FALSE)
+ } | ]
+
+ set charWords {(['`].['`])|(['`]\\[abfnrv\\\"\'\?]['`])}
+
+ scan [$win index end] %d numLines
+ set multiLineComment 0
+ set multiLinePreProc 0
+ set multiLineString 0
+ #
+ for {set i 1} {$i < $numLines} {incr i} {
+ # skip first (' ' or '-') char, the TAB and the number
+ if {$Linenums} {
+ $win mark set last $i.2
+ set strLine [$win get last "last + 12 chars"]
+ if {[regexp -indices {([0-9])+} $strLine indices]} {
+ set idx_lo [lindex $indices 0]
+ set idx_hi [lindex $indices 1]
+ $win mark set first "last + $idx_lo chars"
+ $win mark set last "last + $idx_hi chars + 1 chars"
+ $win tag add hl_linenum first last
+ set k [expr [lindex $indices 1] + 3]
+ }
+ } else {
+ # skip first ' ' or '-' char
+ set k 1
+ }
+ # tag commends and strings
+ $win mark set last $i.$k
+ while { 1 } {
+ set strLine [$win get last "last lineend"]
+ if {$strLine == {}} break
+ if { ($multiLineComment == 0) && ($multiLineString == 0) } {
+ # searching /* or "
+ if {[regexp -indices {(/\*)|(//)|(\")} $strLine indices]} {
+ set idx_lo [lindex $indices 0]
+ set idx_hi [lindex $indices 1]
+ $win mark set first "last + $idx_lo chars"
+ # is it /*,// or "
+ if { [string index $strLine $idx_lo] != "/" } {
+ # it's quote " ;make sure it's not \"
+ if { $idx_lo == 0 || ($idx_lo > 0 && [string index $strLine [expr $idx_lo - 1]] != "\\") } {
+ $win mark set last "last + $idx_hi chars + 1 chars"
+ set strLine [$win get last "last lineend"]
+ # is there a closing " too
+ set found_quote_end 0
+ while {[regexp -indices {(\")} $strLine indices]} {
+ set idx_hi [lindex $indices 1]
+ # also without make sure it's not \"
+ if { $idx_hi == 0 || ($idx_hi > 0 && [string index $strLine [expr $idx_hi - 1]] != "\\") } {
+ $win mark set last "last + 1 chars + $idx_hi chars"
+ $win tag add hl_lineString first last
+ set found_quote_end 1
+ break
+ }
+ $win mark set last "last + 1 chars + $idx_hi chars"
+ set strLine [$win get last "last lineend"]
+ }
+ if {$found_quote_end == 0} {
+ # there is no quoting end in this line; seach for end of line
+ if {[regexp -indices {(.)$} $strLine indices]} {
+ set multiLineString 1
+ set idx_hi [lindex $indices 0]
+ $win mark set last "last + 1 chars + $idx_hi chars"
+ $win tag add hl_lineString first last
+ break
+ } else {
+ # something goes wrong
+ debug "missing lineend "
+ break
+ }
+ }
+ } else {
+ $win mark set last "last + $idx_hi chars + 1 chars"
+ }
+ } elseif { [string index $strLine [expr $idx_lo + 1]] == "/" } {
+ # it's line comment //
+ if {[regexp -indices {(.)$} $strLine indices]} {
+ set idx_hi [lindex $indices 0]
+ } else {
+ debug "missing lineend"
+ set idx_hi [lindex $indices 1]
+ }
+ $win mark set first "last + $idx_lo chars"
+ $win mark set last "last + 1 chars + $idx_hi chars"
+ $win tag add hl_comment first last
+ break
+ } else {
+ # it's a comment /*
+ $win mark set last "last + $idx_hi chars"
+ set strLine [$win get last "last lineend"]
+ # is there a closing */ too
+ if {[regexp -indices {(\*/)} $strLine indices]} {
+ set idx_hi [lindex $indices 1]
+ $win mark set last "last + 1 chars + $idx_hi chars"
+ $win tag add hl_comment first last
+ } elseif {[regexp -indices {(.)$} $strLine indices]} {
+ set multiLineComment 1
+ set idx_hi [lindex $indices 0]
+ $win mark set last "last + 1 chars + $idx_hi chars"
+ $win tag add hl_comment first last
+ break
+ } else {
+ # something goes wrong
+ debug "missing lineend "
+ break
+ }
+ }
+ } else {
+ # no more // or /*
+ break
+ }
+
+ } elseif { $multiLineComment == 0 } {
+ # multi line String
+ $win mark set first "last"
+ if {[regexp -indices {(\")} $strLine indices]} {
+ # it's quote " ;make sure it's not \"
+ set idx_hi [lindex $indices 1]
+ if { $idx_hi == 0 || ($idx_hi > 0 && [string index $strLine [expr $idx_hi - 1]] != "\\") } {
+ set multiLineString 0
+ $win mark set last "last + 1 chars + $idx_hi chars"
+ $win tag add hl_lineString first last
+ } else {
+ $win mark set last "last + 1 chars + $idx_hi chars"
+ }
+ } elseif {[regexp -indices {(.)$} $strLine indices]} {
+ set idx_hi [lindex $indices 0]
+ $win mark set last "last + 1 chars + $idx_hi chars"
+ $win tag add hl_lineString first last
+ break
+ } else {
+ # something goes wrong
+ debug "missing lineend "
+ break
+ }
+ } else {
+ # multi line comments
+ $win mark set first "last"
+ if {[regexp -indices {(\*/)} $strLine indices]} {
+ set multiLineComment 0
+ set idx_hi [lindex $indices 1]
+ $win mark set last "last + 1 chars + $idx_hi chars"
+ $win tag add hl_comment first last
+ } elseif {[regexp -indices {(.)$} $strLine indices]} {
+ set idx_hi [lindex $indices 0]
+ $win mark set last "last + 1 chars + $idx_hi chars"
+ $win tag add hl_comment first last
+ break
+ } else {
+ # something goes wrong
+ debug "missing lineend "
+ break
+ }
+ }
+ }
+ # search for single chars and give those a tag
+ $win mark set last $i.$k
+ set strLine [$win get last "last lineend"]
+ while {[regexp -indices $charWords $strLine indices]} {
+ set idx_lo [lindex $indices 0]
+ set idx_hi [lindex $indices 1]
+ $win mark set first "last + $idx_lo chars"
+ $win mark set last "last + 1 chars + $idx_hi chars"
+ set tag_names [$win tag names first]]
+ if {[regexp {(hl_comment)|(hl_lineString)} $tag_names] == 0} {
+ # only if it't not a comment
+ set cmpStr [string index $strLine [expr $idx_lo - 1]]
+ if { $idx_lo > 0 && [regexp {^[a-z]|^[A-Z]|^[#_]} $cmpStr] } {
+ } else {
+ set cmpStr [string index $strLine [expr $idx_hi + 1]]
+ if [regexp {^[0-9]|^[a-z]|^[A-Z]|^(_)} $cmpStr] {
+ } else {
+ $win tag add hl_charword first last
+ }
+ }
+ }
+ set strLine [$win get last "last lineend"]
+ }
+ # tag prepocessor directives
+ $win mark set last $i.$k
+ while (1) {
+ set strLine [$win get last "last lineend"]
+ if { $multiLinePreProc == 0 } {
+ # search for a beginning #
+ if {[regexp -indices {(^([ \t])*#)} $strLine indices]} {
+ set idx_lo [lindex $indices 0]
+ set idx_hi [lindex $indices 1]
+ $win mark set first "last + $idx_lo chars"
+ $win mark set last "last + $idx_hi chars"
+ set strLine [$win get first "first lineend"]
+ set strEndPos [expr [string length $strLine] - 1]
+ # is there a reapet \
+ if {$strEndPos > 0} {
+ $win mark set last "last + 1 chars + $strEndPos chars"
+ $win tag add hl_preproc first last
+ if { [string index $strLine $strEndPos] == "\\" } {
+ set multiLinePreProc 1
+ } else {
+ # is there a <..> within this line
+ if {[regexp -indices {<([a-zA-Z0-9/\\\.]+)>} $strLine indices]} {
+ set idx_lo [lindex $indices 0]
+ set idx_hi [lindex $indices 1]
+ $win mark set last "first + 1 chars + $idx_hi chars"
+ $win mark set first "first + $idx_lo chars"
+ $win tag add hl_lineString first last
+ }
+ }
+ break
+ }
+ }
+ } else {
+ # multi line derictives
+ $win mark set first "last"
+ set strLine [$win get first "first lineend"]
+ set strEndPos [expr [string length $strLine] - 1]
+ if {$strEndPos > 0} {
+ $win mark set last "last + 1 chars + $strEndPos chars"
+ $win tag add hl_preproc first last
+ if { [string index $strLine $strEndPos] != "\\" } {
+ set multiLinePreProc 0
+ }
+ break
+ }
+ }
+ break
+ }
+ # search for keywords and give those a tag
+ $win mark set last $i.$k
+ set strLine [$win get last "last lineend"]
+ while {[regexp -indices $keyWords $strLine indices]} {
+ set idx_lo [lindex $indices 0]
+ set idx_hi [lindex $indices 1]
+ $win mark set first "last + $idx_lo chars"
+ $win mark set last "last + 1 chars + $idx_hi chars"
+ set tag_names [$win tag names first]
+ if {[regexp {(hl_comment)|(hl_preproc)|(hl_lineString)} $tag_names] == 0} {
+ # only if it't not a comment
+ set cmpStr [string index $strLine [expr $idx_lo - 1]]
+ if { $idx_lo > 0 && [regexp {^[a-z]|^[A-Z]|^[#_\.>]} $cmpStr] } {
+ } else {
+ set cmpStr [string index $strLine [expr $idx_hi + 1]]
+ if {[regexp {^[0-9]|^[a-z]|^[A-Z]|^[_\-\.]} $cmpStr] == 0} {
+ $win tag add hl_keyword first last
+ }
+ }
+ }
+ set strLine [$win get last "last lineend"]
+ }
+ # search for typewords and give those a tag
+ $win mark set last $i.$k
+ set strLine [$win get last "last lineend"]
+ while {[regexp -indices $typeWords $strLine indices]} {
+ set idx_lo [lindex $indices 0]
+ set idx_hi [lindex $indices 1]
+ $win mark set first "last + $idx_lo chars"
+ $win mark set last "last + 1 chars + $idx_hi chars"
+ set tag_names [$win tag names first]
+ if {[regexp {(hl_comment)|(hl_preproc)|(hl_lineString)} $tag_names] == 0} {
+ # only if it't not a comment
+ set cmpStr [string index $strLine [expr $idx_lo - 1]]
+ if { $idx_lo > 0 && [regexp {^[a-z]|^[A-Z]|^[#_\.>]} $cmpStr] } {
+ } else {
+ set cmpStr [string index $strLine [expr $idx_hi + 1]]
+ if {[regexp {^[0-9]|^[a-z]|^[A-Z]|^[_\-\.]} $cmpStr] == 0} {
+ $win tag add hl_varword first last
+ }
+ }
+ }
+ set strLine [$win get last "last lineend"]
+ }
+ # search for constWords and give those a tag
+ $win mark set last $i.$k
+ set strLine [$win get last "last lineend"]
+ while {[regexp -indices $constWords $strLine indices]} {
+ set idx_lo [lindex $indices 0]
+ set idx_hi [lindex $indices 1]
+ $win mark set first "last + $idx_lo chars"
+ $win mark set last "last + 1 chars + $idx_hi chars"
+ set tag_names [$win tag names first]
+ if {[regexp {(hl_comment)|(hl_lineString)} $tag_names] == 0} {
+ # only if it't not a comment
+ set cmpStr [string index $strLine [expr $idx_lo - 1]]
+ if { $idx_lo > 0 && [regexp {^[a-z]|^[A-Z]|^[#_\.>]} $cmpStr] == 0} {
+ set cmpStr [string index $strLine [expr $idx_hi + 1]]
+ if {[regexp {^[0-9]|^[a-z]|^[A-Z]|^[_\.]} $cmpStr] == 0} {
+ $win tag add hl_constword first last
+ }
+ }
+ }
+ set strLine [$win get last "last lineend"]
+ }
+ # search for labels and give those a tag
+ $win mark set last $i.$k
+ set strLine [$win get last "last lineend"]
+ if {[regexp -indices {^([ \t]*)([a-zA-Z_])([a-zA-Z0-9_])*:} $strLine indices]} {
+ # skip leading space chars
+ regexp -indices {([a-zA-Z_])([a-zA-Z0-9_])*:} $strLine indices
+ set idx_lo [lindex $indices 0]
+ set idx_hi [lindex $indices 1]
+ $win mark set first "last + $idx_lo chars"
+ $win mark set last "last + 1 chars + $idx_hi chars"
+ set tag_names [$win tag names first]
+ if {[regexp {(hl_comment)|(hl_lineString)|(hl_keyword)|(hl_varword)|(hl_constword)} $tag_names] == 0} {
+ # only if it't not a comment and not c++ :: stuff
+ set strEndPos [expr $idx_hi + 1]
+ if { [string index $strLine $strEndPos] != ":" } {
+ $win tag add hl_label first last
+ }
+ }
+ }
+ # search label branch
+ while {[regexp -indices {(goto)([ \t]+)([a-zA-Z_])([a-zA-Z0-9_])*} $strLine indices]} {
+ set idx_lo [lindex $indices 0]
+ set idx_hi [lindex $indices 1]
+ $win mark set first "last + 5 chars + $idx_lo chars"
+ $win mark set last "last + 1 chars + $idx_hi chars"
+ set tag_names [$win tag names first]
+ if {[regexp {(hl_comment)|(hl_lineString)} $tag_names] == 0} {
+ # only if it't not a comment
+ set cmpStr [string index $strLine [expr $idx_lo - 1]]
+ if { $idx_lo > 0 && [regexp {^[a-z]|^[A-Z]|^[#_\.>]} $cmpStr] == 0} {
+ set cmpStr [string index $strLine [expr $idx_hi + 1]]
+ if {[regexp {^[#:\-\.]} $cmpStr] == 0} {
+ $win tag add hl_label first last
+ }
+ }
+ }
+ set strLine [$win get last "last lineend"]
+ }
+ #next line
+ }
+
+}
+
+
# ------------------------------------------------------------------
# METHOD: LoadFile - loads in a new source file
# ------------------------------------------------------------------
@@ -1272,6 +1946,36 @@
UnLoadFromCache $w $oldpane $name "" $lib
return 0
}
+ scanAndTagTextWidget $win $name
+ }
+ # higlight taged Keywords
+ set tag_names [$win tag names]
+ if {[regexp hl_comment $tag_names]} {
+ $win tag configure hl_comment -foreground Blue
+ }
+ if {[regexp hl_preproc $tag_names]} {
+ $win tag configure hl_preproc -foreground purple
+ }
+ if {[regexp hl_keyword $tag_names]} {
+ $win tag configure hl_keyword -foreground Red
+ }
+ if {[regexp hl_varword $tag_names]} {
+ $win tag configure hl_varword -foreground DarkGreen
+ }
+ if {[regexp hl_linenum $tag_names]} {
+ $win tag configure hl_linenum -foreground DarkGray
+ }
+ if {[regexp hl_lineString $tag_names]} {
+ $win tag configure hl_lineString -foreground DarkOrange4
+ }
+ if {[regexp hl_constword $tag_names]} {
+ $win tag configure hl_constword -foreground "dark salmon"
+ }
+ if {[regexp hl_charword $tag_names]} {
+ $win tag configure hl_charword -foreground "dark cyan"
+ }
+ if {[regexp hl_label $tag_names]} {
+ $win tag configure hl_label -foreground "dark cyan"
}
set current(filename) $name
# Display all breaks/traces



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]