summaryrefslogtreecommitdiff
path: root/lib/editor/R_ASMsyntaxhighlight.tcl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/editor/R_ASMsyntaxhighlight.tcl')
-rw-r--r--[-rwxr-xr-x]lib/editor/R_ASMsyntaxhighlight.tcl157
1 files changed, 78 insertions, 79 deletions
diff --git a/lib/editor/R_ASMsyntaxhighlight.tcl b/lib/editor/R_ASMsyntaxhighlight.tcl
index 2408bff..250da57 100755..100644
--- a/lib/editor/R_ASMsyntaxhighlight.tcl
+++ b/lib/editor/R_ASMsyntaxhighlight.tcl
@@ -2,7 +2,7 @@
# Part of MCU 8051 IDE ( http://mcu8051ide.sf.net )
############################################################################
-# Copyright (C) 2007-2008 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 _R_ASMSYNTAXHIGHLIGHT_TCL ] } {
+set _R_ASMSYNTAXHIGHLIGHT_TCL _
+# <<< File inclusion guard
+
# --------------------------------------------------------------------------
# DESCRIPTION
# Implements syntax highlighting interface for reallocable assembly
@@ -86,24 +91,20 @@ namespace eval R_ASMsyntaxHighlight {
variable validation_L1 1 ;# Bool: Advancet validation enabled
## 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 {
+ proc create_tags {text_widget fontSize fontFamily {highlight {}} {nobold 0}} {
# 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 $::ASMsyntaxHighlight::hightlight_tags
+ if {$highlight == {}} { ;# highlighting definition
+ set highlight $::ASMsyntaxHighlight::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]
@@ -116,13 +117,13 @@ namespace eval R_ASMsyntaxHighlight {
# 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
}
@@ -142,13 +143,13 @@ namespace eval R_ASMsyntaxHighlight {
}
## Perform syntax highlight on the given line in the given widget
- # @parm Widget Editor - Text widget
- # @parm Int LineNumber - Number of line to highlight
- # @parm Bool inline_asm - Inline assembler
- # @parm Int boundary_0 = 0 - Start index
- # @parm Int boundary_1 = end - End index
+ # @parm Widget p_editor - Text widget
+ # @parm Int linenumber - Number of line to highlight
+ # @parm Bool inlineasm=0 - Inline assembler
+ # @parm Int linestart=0 - Start index
+ # @parm Int lineend=end - End index
# @return Bool - result
- proc highlight args {
+ proc highlight {p_editor linenumber {inlineasm 0} {linestart {}} {lineend {}}} {
variable editor ;# ID of the text widget
variable lineNumber ;# Number of current line
variable lineStart ;# Index of line start
@@ -170,27 +171,22 @@ namespace eval R_ASMsyntaxHighlight {
variable validation_L0 ;# Bool: Basic validation enabled
# Parse input arguments
- set editor [lindex $args 0]
- set lineNumber [lindex $args 1]
- set inline_asm [lindex $args 2]
- set lineStart [lindex $args 3]
- set lineEnd [lindex $args 4]
- if {$inline_asm == {}} {
- set inline_asm 0
- }
- if {$lineStart == {}} {
+ set editor $p_editor
+ set lineNumber $linenumber
+ set inline_asm $inlineasm
+ if {$linestart == {}} {
set lineStart $lineNumber.0
- } {
- set lineStart $lineNumber.$lineStart
+ } else {
+ set lineStart $lineNumber.$linestart
}
- if {$lineEnd == {}} {
+ if {$lineend == {}} {
set lineEnd [$editor index "$lineStart lineend"]
- } {
+ } else {
set lineEnd $lineNumber.$lineEnd
}
- if {[lindex $args 3] != {}} {
- set start_offset [lindex $args 3]
- } {
+ if {$linestart != {}} {
+ set start_offset $linestart
+ } else {
set start_offset 0
}
@@ -227,7 +223,7 @@ namespace eval R_ASMsyntaxHighlight {
if {$comment_start == 0} {
set data {}
delete_tags
- } {
+ } else {
set data [string range $data 0 [expr {$comment_start - 1}]]
regsub {\s+$} $data {} data
}
@@ -295,7 +291,7 @@ namespace eval R_ASMsyntaxHighlight {
if {
$validation_L0 &&
([regexp {^\d} $seg_1] || ![regexp {^\w+$} $seg_1])
- } {
+ } then {
put_error_on_segment 1
}
determinate_segment_2
@@ -314,7 +310,7 @@ namespace eval R_ASMsyntaxHighlight {
determinate_segment_2
if {[string tolower $seg_0] == {.optsdcc}} {
$editor tag add tag_string $lineNumber.$seg_0_end $lineEnd
- } {
+ } else {
parse_expressions
}
}
@@ -376,8 +372,8 @@ namespace eval R_ASMsyntaxHighlight {
# Remove tag error
$editor tag remove tag_error $lineStart_truestart $lineEnd
- # Remove tags acording to pattern
- foreach tag $::ASMsyntaxHighlight::hightlight_tags {
+ # Remove tags according to pattern
+ foreach tag $::ASMsyntaxHighlight::highlight_tags {
$editor tag remove [lindex $tag 0] $lineStart_truestart $lineEnd
}
}
@@ -412,7 +408,7 @@ namespace eval R_ASMsyntaxHighlight {
set seg_1_start $last_index
# Line is not empty
- } {
+ } else {
set data_backup $data
set last_index_backup $last_index
@@ -508,7 +504,7 @@ namespace eval R_ASMsyntaxHighlight {
} elseif {$segment_data == {=} || $segment_data == {==}} {
$editor tag add tag_symbol $lineNumber.$start $lineNumber.$end
set seg_type {assignment}
- } {
+ } else {
set seg_type {unknown}
}
}
@@ -565,9 +561,9 @@ namespace eval R_ASMsyntaxHighlight {
if {[regexp {^\s*$} $seg_2]} {return 0}
- while 1 {
+ while {1} {
# Handle redutant commas
- while 1 {
+ while {1} {
if {![regexp {^\s*\,} $seg_2]} {break}
set space_len 0
@@ -639,9 +635,9 @@ namespace eval R_ASMsyntaxHighlight {
set original_data $seg_2
set data [hide_strings $seg_2]
- while 1 {
+ while {1} {
# Handle redutant commas
- while 1 {
+ while {1} {
if {![regexp {^\s*\,} $data]} {break}
set space_len 0
@@ -672,7 +668,7 @@ namespace eval R_ASMsyntaxHighlight {
set space_len [string length $space]
set opr_start [expr {$last_index + $space_len}]
set operand [string range $operand $space_len end]
- } {
+ } else {
set opr_start $last_index
}
@@ -681,7 +677,7 @@ namespace eval R_ASMsyntaxHighlight {
set space_len [string length $space]
set opr_end [expr {$operand_len - $space_len}]
set operand [string range $operand 0 $opr_end]
- } {
+ } else {
set opr_end $operand_len
}
incr opr_end $last_index
@@ -725,7 +721,7 @@ namespace eval R_ASMsyntaxHighlight {
default {
if {[lsearch -ascii -exact {R0 R1 R2 R3 R4 R5 R6 R7 DPTR A AB C} $opr] != -1} {
lappend ::ASMsyntaxHighlight::opr_types $opr
- } {
+ } else {
lappend ::ASMsyntaxHighlight::opr_types {D}
}
}
@@ -756,7 +752,7 @@ namespace eval R_ASMsyntaxHighlight {
if {$len > 3} {
put_tag_on_operand tag_string
- } {
+ } else {
put_tag_on_operand tag_imm_char
}
@@ -773,7 +769,7 @@ namespace eval R_ASMsyntaxHighlight {
} elseif {
$validation_L0 &&
([string length $operand] == 0 || ![regexp {^[\w\.\\]+$} $operand])
- } {
+ } then {
# put_tag_on_operand tag_error
# Operand value determinated successfully
@@ -804,12 +800,11 @@ namespace eval R_ASMsyntaxHighlight {
$lineNumber.$opr_start $lineNumber.$opr_start+1c
} elseif {
- $validation_L0 &&
- ([string length $operand] == 0 || ![regexp {^'?[\w\.]+'?$} $operand])
- } {
-
- # Operand has no value => incorrect operand
-# put_tag_on_operand tag_error
+ $validation_L0 &&
+ ([string length $operand] == 0 || ![regexp {^'?[\w\.]+'?$} $operand])
+ } then {
+ # Operand has no value => incorrect operand
+# put_tag_on_operand tag_error
} else {
parse_operand_auxiliary $::ASMsyntaxHighlight::spec_bits {
@@ -841,7 +836,7 @@ namespace eval R_ASMsyntaxHighlight {
put_tag_on_operand tag_sfr
# Something else than SFR
- } {
+ } else {
parse_operand_auxiliary2 $tag_list
}
}
@@ -897,8 +892,8 @@ namespace eval R_ASMsyntaxHighlight {
put_tag_on_operand [lindex $tag_list 0]
# Radix determinated correctly - continue normaly
- } {
- # highlight acording to numeric base
+ } else {
+ # highlight according to numeric base
switch -- $opr_base {
{hex} {put_tag_on_operand [lindex $tag_list 1]}
{dec} {put_tag_on_operand [lindex $tag_list 2]}
@@ -910,7 +905,7 @@ namespace eval R_ASMsyntaxHighlight {
}
# defined by a symbolic name
- } {
+ } else {
put_tag_on_operand [lindex $tag_list 6]
}
}
@@ -996,7 +991,7 @@ namespace eval R_ASMsyntaxHighlight {
if {[regexp {^[0-7]*$} $number]} {
if {$len != 3} {
set dec_val 0
- } {
+ } else {
if {[string index $number 0] <= 3} {
set dec_val 0
}
@@ -1014,7 +1009,7 @@ namespace eval R_ASMsyntaxHighlight {
if {[regexp {^[0-7]*$} $number]} {
if {$len != 3} {
set dec_val 0
- } {
+ } else {
if {[string index $number 0] <= 3} {
set dec_val 0
}
@@ -1037,7 +1032,7 @@ namespace eval R_ASMsyntaxHighlight {
}
# done ...
- return "$base $dec_val"
+ return [list $base $dec_val]
}
## Highlight expressions (eg. '( 10d - X MOD 55h)')
@@ -1062,7 +1057,7 @@ namespace eval R_ASMsyntaxHighlight {
# Remove strings
set e_idx 0
- while 1 {
+ while {1} {
if {![regexp -start $e_idx -- {'[^']*'} $data string_data]} {
break
}
@@ -1079,22 +1074,22 @@ namespace eval R_ASMsyntaxHighlight {
}
# remove and highlight '('
- set opended_par 0
- while 1 {
+ set opened_par 0
+ while {1} {
set symbol_idx [string first {(} $data]
if {$symbol_idx == -1} {break}
- incr opended_par
+ incr opened_par
set data [string replace $data $symbol_idx $symbol_idx { }]
incr symbol_idx $start_index
$editor tag add tag_symbol $lineNumber.$symbol_idx $lineNumber.[expr {$symbol_idx + 1}]
}
# remove and highlight ')'
- while 1 {
+ while {1} {
set symbol_idx [string first {)} $data]
if {$symbol_idx == -1} {break}
- incr opended_par -1
+ incr opened_par -1
set data [string replace $data $symbol_idx $symbol_idx { }]
incr symbol_idx $start_index
$editor tag add tag_symbol $lineNumber.$symbol_idx $lineNumber.[expr {$symbol_idx + 1}]
@@ -1105,7 +1100,7 @@ namespace eval R_ASMsyntaxHighlight {
regsub {\t} $adjusted_data { } adjusted_data
# highlight expr. symbols (1 char) and remove them from the string
foreach symbol $expr_symbols {
- while 1 {
+ while {1} {
set symbol_idx [string first $symbol $data]
if {$symbol_idx == -1} {break}
set original_symbol_idx $symbol_idx
@@ -1122,7 +1117,7 @@ namespace eval R_ASMsyntaxHighlight {
set last_index $start_index
set original_data $data
set data [hide_strings $data]
- while 1 {
+ while {1} {
if {![regexp {[^\s]+} $data value]} {break}
set value_S_idx [string first $value $data]
@@ -1175,13 +1170,13 @@ namespace eval R_ASMsyntaxHighlight {
set opr_base [lindex $opr_info 0]
set opr_in_dec [lindex $opr_info 1]
- # Highlight value acording to info
+ # Highlight value according to info
if {$opr_base == {}} {
$editor tag add tag_unknown_base $lineNumber.$start_index $lineNumber.$end_index
return
}
- # Highlight acording to numeric base
+ # Highlight according to numeric base
switch -- $opr_base {
{hex} { ;# Hexadecimal
$editor tag add tag_hex $lineNumber.$start_index $lineNumber.$end_index
@@ -1217,7 +1212,7 @@ namespace eval R_ASMsyntaxHighlight {
if {[string first {'} $data] == -1} {return $data}
# Perform replacement
- while 1 {
+ while {1} {
if {![regexp {'[^']*'} $data string]} {
break
}
@@ -1230,3 +1225,7 @@ namespace eval R_ASMsyntaxHighlight {
return $data
}
}
+
+# >>> File inclusion guard
+}
+# <<< File inclusion guard