summaryrefslogtreecommitdiff
path: root/lib/editor/Csyntaxhighlight.tcl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/editor/Csyntaxhighlight.tcl')
-rw-r--r--[-rwxr-xr-x]lib/editor/Csyntaxhighlight.tcl145
1 files changed, 87 insertions, 58 deletions
diff --git a/lib/editor/Csyntaxhighlight.tcl b/lib/editor/Csyntaxhighlight.tcl
index 8bdc913..c4ecd2a 100755..100644
--- a/lib/editor/Csyntaxhighlight.tcl
+++ b/lib/editor/Csyntaxhighlight.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 _CSYNTAXHIGHLIGHT_TCL ] } {
+set _CSYNTAXHIGHLIGHT_TCL _
+# <<< File inclusion guard
+
# --------------------------------------------------------------------------
# DESCRIPTION
# Implements syntax highlighting interface for ISO C language
@@ -40,18 +45,23 @@ namespace eval CsyntaxHighlight {
#if #ifdef #ifndef
#else #elif #endif
#line #pragma #undef
+ #warning
}
# List of data type specifiers
variable data_types {
void int float double char signed unsigned
long short uchar ushort uint ulong const
export extern static mutable volatile
+
+ __data __near __xdata __far __idata __pdata __code
+ __bit __sfr __sfr16 __sfr32 __sbit __at
}
# List of C keywords
variable keywords {
auto break case _endasm while union continue
default do else enum sizeof for namespace
if goto return struct switch typedef using
+ _asm __asm __endasm
}
# List of doxygen tags -- No argument
variable doxy_tags_type0 {
@@ -69,7 +79,8 @@ namespace eval CsyntaxHighlight {
# List of doxygen tags -- Name after tag
variable doxy_tags_type2 {
@brief @ingroup @name @mainpage
- @fn @var @typedef
+ @fn @var @typedef @author
+ @authors
}
# List of HTML tags (HTML 4.0 Strict)
variable html_tags {
@@ -99,11 +110,12 @@ namespace eval CsyntaxHighlight {
# {
# {tag_name ?foreground? ?overstrike? ?italic? ?bold?}
# }
- variable hightlight_tags {
+ variable highlight_tags {
{tag_c_keyword #0000DD 0 0 1}
{tag_c_data_type #00CC00 0 0 1}
{tag_c_dec #0000FF 0 0 0}
{tag_c_hex #8800FF 0 0 0}
+ {tag_c_bin #5555AA 0 0 0}
{tag_c_oct #883300 0 0 0}
{tag_c_char #DD00DD 0 0 0}
{tag_c_float #AA00AA 0 0 0}
@@ -127,26 +139,22 @@ namespace eval CsyntaxHighlight {
}
## 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]
@@ -159,13 +167,13 @@ namespace eval CsyntaxHighlight {
# 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
}
@@ -190,6 +198,7 @@ namespace eval CsyntaxHighlight {
tag_c_bracket tag_c_symbol tag_c_keyword
tag_c_data_type tag_c_char tag_c_dec
tag_c_oct tag_c_hex tag_c_float
+ tag_c_bin
} {
$text_widget tag raise $t tag_normal
}
@@ -245,7 +254,7 @@ namespace eval CsyntaxHighlight {
$editor tag add tag_c_preprocessor $line_start $line_end-1c
$editor tag add tag_c_symbol $line_end-1c $line_end
return 7
- } {
+ } else {
$editor tag add tag_c_preprocessor $line_start $line_end
return 1
}
@@ -274,7 +283,7 @@ namespace eval CsyntaxHighlight {
# Highlight directive argument
if {$directive == {#include}} {
set prep_tag {tag_c_prep_lib}
- } {
+ } else {
set prep_tag {tag_c_preprocessor}
}
@@ -284,7 +293,7 @@ namespace eval CsyntaxHighlight {
set cur_line_end $com_start
incr cur_line_end -1
set cur_line_end $line_number.$cur_line_end
- } {
+ } else {
set cur_line_end $line_end
}
@@ -308,14 +317,14 @@ namespace eval CsyntaxHighlight {
return $cur_status
# Inline assembler
- } elseif {[regexp {^\s*_asm\s*$} $line_content]} {
+ } elseif {[regexp {^\s*_?_asm\s*$} $line_content]} {
$editor tag add tag_c_keyword $line_start $line_end
return 5
}
}
# Split line into fields with different highlight status
- while 1 {
+ while {1} {
set incr_last_i 0
switch -- $status {
1 { ;# Normal
@@ -384,12 +393,12 @@ namespace eval CsyntaxHighlight {
}
4 { ;# String
set l_idx $last_idx_s
- while 1 {
+ while {1} {
set idx [string first "\"" $line_content $l_idx]
if {$idx < 1} {break}
if {[string index $line_content [expr {$idx - 1}]] == "\\"} {
incr l_idx
- } {
+ } else {
break
}
}
@@ -399,7 +408,7 @@ namespace eval CsyntaxHighlight {
set status 1
}
5 { ;# Inline assembler
- if {[regexp {^\s*_endasm[^\w]*} $line_content]} {
+ if {[regexp {^\s*_?_endasm[^\w]*} $line_content]} {
mode_normal 0 [string length $line_content]
return 1
}
@@ -409,10 +418,10 @@ namespace eval CsyntaxHighlight {
break
}
6 { ;# Inline assembler -- within asm block
- if {[regexp {^\s*_endasm[^\w]*} $line_content]} {
+ if {[regexp {^\s*_?_endasm[^\w]*} $line_content]} {
mode_normal 0 [string length $line_content]
return 1
- } {
+ } else {
break
}
}
@@ -437,14 +446,14 @@ namespace eval CsyntaxHighlight {
# Return final status
if {$this_line_only} {
return 1
- } {
+ } else {
return $status
}
}
## Auxiliary procedure for procedure highlight
# This procedure calls other procedures to perform syntax
- #+ highlight acording to the given highlight status
+ #+ highlight according to the given highlight status
# @parm Int status - Highlight status
# @parm Int idx0 - Start index
# @parm Int idx1 - End index
@@ -501,7 +510,7 @@ namespace eval CsyntaxHighlight {
set string [string range $line_content $idx0 [expr {$idx1 - 1}]]
# Highlight escaped characters and character between them
- while 1 {
+ while {1} {
# Search for backslash
set idx [string first "\\" $string $idx]
if {$idx == -1} {break}
@@ -545,18 +554,18 @@ namespace eval CsyntaxHighlight {
set words [split [regsub -all {>} [regsub -all {<} $string { &}] {& }]]
# Adjust HTML tags with argument(s) (they must be represented as a single word)
- set tag_opended 0
+ set tag_opened 0
set result_words {}
foreach word $words {
- if {!$tag_opended} {
+ if {!$tag_opened} {
append result_words { } ;# Insert a common space
- } {
+ } else {
append result_words "\xA0" ;# Insert NBSP
}
- if {!$tag_opended && [regexp {^<\w+$} $word]} {
- set tag_opended 1
- } elseif {$tag_opended && [string index $word end] == {>}} {
- set tag_opended 0
+ if {!$tag_opened && [regexp {^<\w+$} $word]} {
+ set tag_opened 1
+ } elseif {$tag_opened && [string index $word end] == {>}} {
+ set tag_opened 0
}
append result_words [regsub -all {[\{\}]} $word {\\&}]
}
@@ -670,7 +679,7 @@ namespace eval CsyntaxHighlight {
$editor tag add tag_c_dox_hargval \
$line_number.[expr {$idx0 + $idx + $sub_idx + $first_equ_mark}] \
$line_number.[expr {$idx0 + $idx + $sub_idx + $sub_len}]
- } {
+ } else {
set first_equ_mark $sub_len
}
@@ -727,7 +736,7 @@ namespace eval CsyntaxHighlight {
if {
$char == {(} || $char == {)} || $char == "\{" ||
$char == "\}" || $char == {[} || $char == {]}
- } {
+ } then {
$editor tag add tag_c_bracket $line_number.$j $line_number.$j+1c
# Other symbols
@@ -743,7 +752,7 @@ namespace eval CsyntaxHighlight {
{
set idx -1
foreach word $words {
- while 1 {
+ while {1} {
incr idx
set idx [string first $word $string $idx]
if {$idx == -1} {break}
@@ -765,7 +774,7 @@ namespace eval CsyntaxHighlight {
set idx -1
set len 0
set tags {}
- foreach word [split $string {   ;=,+-<>!|&*/?:%^\{\}[]()}] {
+ foreach word [split $string {   ;=,+-<>!|&*/?:%^{}[]()}] {
if {$word == {}} {continue}
incr idx
@@ -774,9 +783,11 @@ namespace eval CsyntaxHighlight {
# Char
if {![string is digit -strict [string index $word 0]]} {
- if {[regexp {^'[^']*'$} $word]} {
+ if {$word == {''}} {
+ set tags {tag_error}
+ } elseif {[regexp {^'[^']+'$} $word]} {
set tags {tag_c_char}
- } {
+ } else {
continue
}
@@ -787,10 +798,10 @@ namespace eval CsyntaxHighlight {
set tags {tag_c_dec}
} elseif {!$validation_L0 || [regexp {^0[0-7]+$} $word]} {
set tags {tag_c_oct}
- } {
+ } else {
set tags {tag_c_oct tag_error}
}
- } {
+ } else {
set tags {tag_c_dec}
}
@@ -801,12 +812,26 @@ namespace eval CsyntaxHighlight {
||
[string index $word 1] == {X}
)
- } {
- if {!$validation_L0 || [string is xdigit -strict [string range $word 2 end]]} {
- set tags {tag_c_hex}
- } {
- set tags {tag_c_hex tag_error}
- }
+ } then {
+ if {!$validation_L0 || [string is xdigit -strict [string range $word 2 end]]} {
+ set tags {tag_c_hex}
+ } else {
+ set tags {tag_c_hex tag_error}
+ }
+
+ # Bin
+ } elseif {
+ [string index $word 0] == {0} && (
+ [string index $word 1] == {b}
+ ||
+ [string index $word 1] == {B}
+ )
+ } then {
+ if {!$validation_L0 || [regexp {^[01]+$} [string range $word 2 end]]} {
+ set tags {tag_c_bin}
+ } else {
+ set tags {tag_c_bin tag_error}
+ }
# Float
} elseif {[regexp {^\d+\.\d+$} $word]} {
@@ -832,7 +857,7 @@ namespace eval CsyntaxHighlight {
# @return void
proc delete_tags {} {
variable editor ;# Widget: Editor text widget
- variable hightlight_tags ;# Highlight tags definition
+ variable highlight_tags ;# Highlight tags definition
variable line_start ;# Index of line start
variable line_end ;# Index of line end
@@ -842,12 +867,16 @@ namespace eval CsyntaxHighlight {
$editor tag remove c_lang_func $line_start $line_start+1l
$editor tag remove c_lang_var $line_start $line_start+1l
- # 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
}
- foreach tag $::ASMsyntaxHighlight::hightlight_tags {
+ foreach tag $::ASMsyntaxHighlight::highlight_tags {
$editor tag remove [lindex $tag 0] $line_start $line_end
}
}
}
+
+# >>> File inclusion guard
+}
+# <<< File inclusion guard