diff options
author | Andrej Shadura <andrewsh@debian.org> | 2018-05-08 15:59:31 +0200 |
---|---|---|
committer | Andrej Shadura <andrewsh@debian.org> | 2018-05-08 15:59:31 +0200 |
commit | 47aa8b00b2b11df13a100489e0f904a4947177ef (patch) | |
tree | b35c9acc778ea2f761f3c549f7bee2f4491b3144 /lib/editor/LSTsyntaxhighlight.tcl | |
parent | 5b8466f7fae0e071c0f4eda13051c93313910028 (diff) |
Import Upstream version 1.4.7
Diffstat (limited to 'lib/editor/LSTsyntaxhighlight.tcl')
-rw-r--r--[-rwxr-xr-x] | lib/editor/LSTsyntaxhighlight.tcl | 87 |
1 files changed, 48 insertions, 39 deletions
diff --git a/lib/editor/LSTsyntaxhighlight.tcl b/lib/editor/LSTsyntaxhighlight.tcl index c108de9..62f622f 100755..100644 --- a/lib/editor/LSTsyntaxhighlight.tcl +++ b/lib/editor/LSTsyntaxhighlight.tcl @@ -2,7 +2,7 @@ # Part of MCU 8051 IDE ( http://mcu8051ide.sf.net ) ############################################################################ -# Copyright (C) 2007-2009 by Martin Ošmera # +# Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 by Martin Ošmera # # martin.osmera@gmail.com # # # # This program is free software; you can redistribute it and#or modify # @@ -21,6 +21,11 @@ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ############################################################################ +# >>> File inclusion guard +if { ! [ info exists _LSTSYNTAXHIGHLIGHT_TCL ] } { +set _LSTSYNTAXHIGHLIGHT_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION # Implements syntax highlighting interface for code listing @@ -33,7 +38,7 @@ namespace eval LSTsyntaxHighlight { # { # {tag_name ?foreground? ?overstrike? ?italic? ?bold?} # } - variable hightlight_tags { + variable highlight_tags { {tag_lst_number #000000 0 0 1} {tag_lst_code #000000 0 0 1} {tag_lst_address #000000 0 0 1} @@ -74,26 +79,22 @@ namespace eval LSTsyntaxHighlight { ## Define highlighting text tags in the given text widget - # @parm Widget - ID of the target text widget - # @parm Int - font size - # @parm String - font family - # @parm List = default - Highlighting tags definition + # @parm Widget text_widget - ID of the target text widget + # @parm Int fontSize - font size + # @parm String fontFamily - font family + # @parm List highlight=default - Highlighting tags definition + # @parm Bool nobold=0 - Ignore bold flag # @return void - proc create_tags args { - variable hightlight_tags ;# Highlight tags definition + proc create_tags {text_widget fontSize fontFamily {highlight {}} {nobold 0}} { + variable highlight_tags ;# Highlight tags definition # Handle arguments - set text_widget [lindex $args 0] ;# text widget - set fontSize [lindex $args 1] ;# font size - set fontFamily [lindex $args 2] ;# font family - if {[llength $args] > 3} { ;# highlighting definition - set hightlight [lindex $args 3] - } { - set hightlight $hightlight_tags + if {$highlight == {}} { ;# highlighting definition + set highlight $highlight_tags } # Iterate over highlighting tags definition - foreach item $hightlight { + foreach item $highlight { # Create array of tag attributes for {set i 0} {$i < 5} {incr i} { set tag($i) [lindex $item $i] @@ -106,13 +107,13 @@ namespace eval LSTsyntaxHighlight { # Fonr slant if {$tag(3) == 1} { set tag(3) italic - } { + } else { set tag(3) roman } # Font weight - if {$tag(4) == 1} { + if {$tag(4) == 1 && !$nobold} { set tag(4) bold - } { + } else { set tag(4) normal } @@ -152,7 +153,7 @@ namespace eval LSTsyntaxHighlight { # Remove current highlighting tags if {[string length [string trim $line_content]]} { delete_tags - } { + } else { return 0 } @@ -169,7 +170,7 @@ namespace eval LSTsyntaxHighlight { return 1 } } - + # Search for error/warning messages if {[regexp {^(\s+@@@@@)|^(\*\*\*\*)|^(\s+\^)} $line_content]} { $editor tag add tag_lst_error $line_start $line_end @@ -194,7 +195,7 @@ namespace eval LSTsyntaxHighlight { if {${::ExternalCompiler::selected_assembler} == 3} { set asm_start_index 19 as31_highlight 19 -| + # ASEM-51 } elseif { [regexp {^\s*\d+(\:|\+)} $line_content] || @@ -205,7 +206,7 @@ namespace eval LSTsyntaxHighlight { set asm_start_index 33 set idx -1 set cor 0 - while 1 { + while {1} { set idx [string first "\t" $lineText [expr {$idx + 1}]] if {$idx == -1} {break} @@ -224,28 +225,32 @@ namespace eval LSTsyntaxHighlight { sdcc_highlight 32 ::R_ASMsyntaxHighlight::highlight $editor $line_number 1 32 return 1 - + # MCU 8051 IDE Assembler } else { set asm_start_index 31 mcu8051ide_highlight $asm_start_index } - # Highlight assembly code + # Highlight remaining assembly code ::ASMsyntaxHighlight::highlight $editor $line_number 1 $asm_start_index + + # Make sure there are no ASM error tags, they don't make sense here + $editor tag remove tag_error $line_number.$asm_start_index $line_end + return 1 } - ## Remove previously defined syntax highlighting tags + ## Remove previously put syntax highlighting tags # @return void proc delete_tags {} { - variable hightlight_tags ;# Highlight tags definition + variable highlight_tags ;# Highlight tags definition variable editor ;# Widget: Editor text widget variable line_start ;# Index of line start variable line_end ;# Index of line end - # Remove tags acording to pattern - foreach tag $hightlight_tags { + # Remove tags according to pattern + foreach tag $highlight_tags { $editor tag remove [lindex $tag 0] $line_start $line_end } } @@ -292,7 +297,7 @@ namespace eval LSTsyntaxHighlight { variable line_content ;# String: Line content variable line_start ;# Index of line start variable line_end ;# Index of line end - + set idx 0 ;# Regular expression match start index set foo 0 ;# Foo :) @@ -305,11 +310,11 @@ namespace eval LSTsyntaxHighlight { set idx [string first $substring $line_content $idx] $editor tag add tag_lst_line $line_number.$idx $line_number.[expr {$idx + $substr_len}] incr idx $substr_len - } { + } else { set idx 6 set foo 1 } - + # Highlight for inclusion level if {[regexp -start $idx -- {\A[ \d]\d} $line_content substring]} { set substr_len [string length $substring] @@ -345,7 +350,7 @@ namespace eval LSTsyntaxHighlight { $editor tag add tag_lst_number $line_number.$idx $line_number.[expr {$idx + $substr_len}] incr idx $substr_len } - + # Highlight processor code } elseif {[regexp -start $idx -- {\A\s+([[:xdigit:]]{2} )*[[:xdigit:]]{2}} $line_content substring]} { set substr_len [string length $substring] @@ -377,13 +382,13 @@ namespace eval LSTsyntaxHighlight { variable line_content ;# String: Line content variable line_start ;# Index of line start variable line_end ;# Index of line end - + set idx 0 ;# Regular expression match start index - + # Alter line set line_content [string range $line_content 0 [expr {$asm_start_index - 1}]] - - # Highlight processor code + + # Highlight processor code if {[regexp -start $idx -- {\A [[:xdigit:]]{2,}} $line_content substring]} { set substr_len [string length $substring] set idx [string first $substring $line_content $idx] @@ -400,7 +405,7 @@ namespace eval LSTsyntaxHighlight { set idx [string first $substring $line_content $idx] $editor tag add tag_lst_address $line_number.$idx $line_number.[expr {$idx + $substr_len}] incr idx $substr_len - + # Highlight processor code if {[regexp -start $idx -- {\A\s+[[:xdigit:]]{2,}} $line_content substring]} { set substr_len [string length $substring] @@ -417,7 +422,7 @@ namespace eval LSTsyntaxHighlight { $editor tag add tag_lst_number $line_number.$idx $line_number.[expr {$idx + $substr_len}] incr idx $substr_len } - + # Highlight inclusion level if {[regexp -start $idx -- {\A\s+\=\d+} $line_content substring]} { set substr_len [string length $substring] @@ -441,3 +446,7 @@ namespace eval LSTsyntaxHighlight { } } } + +# >>> File inclusion guard +} +# <<< File inclusion guard |