checker_idx.tcl

Go to the documentation of this file.
00001 /*  -*- tcl -*-*/
00002 /*  checker_idx.tcl*/
00003 /* */
00004 /*  Code used inside of a checker interpreter to ensure correct usage of*/
00005 /*  docidx formatting commands.*/
00006 /* */
00007 /*  Copyright (c) 2003 Andreas Kupries <andreas_kupries@sourceforge.net>*/
00008 
00009 /*  L10N*/
00010 
00011 package require msgcat
00012 
00013 ret  ::msgcat::mcunknown (type locale , type code) {
00014     return "unknown error code \"$code\" (for locale $locale)"
00015 }
00016 
00017 if {0} {
00018     puts stderr "Locale [::msgcat::mcpreferences]"
00019     foreach path [dt_search] {
00020     puts stderr "Catalogs: [::msgcat::mc
00021     }
00022 } else {
00023     foreach path [dt_search] {
00024     ::msgcat::mc
00025     }
00026 }
00027 
00028 /*  State, and checker commands.*/
00029 /*  -------------------------------------------------------------*/
00030 /* */
00031 /*  Note that the code below assumes that a command XXX provided by the*/
00032 /*  formatter engine is accessible under the name 'fmt_XXX'.*/
00033 /* */
00034 /*  -------------------------------------------------------------*/
00035 
00036 global state
00037 
00038 /*  State machine ... State centered*/
00039 /*  --------------+-----------------------+----------------------*/
00040 /*  state       | allowed commands  | new state (if any)*/
00041 /*  --------------+-----------------------+----------------------*/
00042 /*  all except  | include vset      |*/
00043 /*  ==============+=======================+======================*/
00044 /*  idx_begin   | idx_begin     | -> contents*/
00045 /*  --------------+-----------------------+----------------------*/
00046 /*  contents    | key           | -> ref_series*/
00047 /*  --------------+-----------------------+----------------------*/
00048 /*  ref_series  | manpage       | -> refkey_series*/
00049 /*      | url           |*/
00050 /*  --------------+-----------------------+----------------------*/
00051 /*  refkey_series   | manpage       | -> refkey_series*/
00052 /*      | url           |*/
00053 /*      +-----------------------+-----------*/
00054 /*      | key           | -> ref_series*/
00055 /*      +-----------------------+-----------*/
00056 /*      | idx_end       | -> done*/
00057 /*  --------------+-----------------------+----------------------*/
00058 
00059 /*  State machine, as above ... Command centered*/
00060 /*  --------------+-----------------------+----------------------*/
00061 /*  state       | allowed commands  | new state (if any)*/
00062 /*  --------------+-----------------------+----------------------*/
00063 /*  all except  | include vset      |*/
00064 /*  ==============+=======================+======================*/
00065 /*  idx_begin   | idx_begin     | -> contents*/
00066 /*  --------------+-----------------------+----------------------*/
00067 /*  contents    | key           | -> ref_series*/
00068 /*  refkey_series   |           |*/
00069 /*  --------------+-----------------------+----------------------*/
00070 /*  ref_series  | manpage       | -> refkey_series*/
00071 /*  refkey_series   |           |*/
00072 /*  --------------+-----------------------+----------------------*/
00073 /*  ref_series  | url           | -> refkey_series*/
00074 /*  refkey_series   |           |*/
00075 /*  --------------+-----------------------+----------------------*/
00076 /*  refkey_series   | idx_end       | -> done*/
00077 /*  --------------+-----------------------+----------------------*/
00078 
00079 /*  -------------------------------------------------------------*/
00080 /*  Helpers*/
00081 ret  Error (type code , optional text ={)} {
00082     global state
00083 
00084     # Problematic command with all arguments (we strip the "ck_" prefix!)
00085     # -*- future -*- count lines of input, maintain history buffer, use
00086     # -*- future -*- that to provide some context here.
00087 
00088     set cmd  [lindex [info level 1] 0]
00089     set args [lrange [info level 1] 1 end]
00090     if {$args != {}} {append cmd " [join $args]"}
00091 
00092     /*  Use a message catalog to map the error code into a legible message.*/
00093      msg =  [::msgcat::mc $code]
00094 
00095     if {$text != {}} {
00096      msg =  [string map [list @ $text] $msg]
00097     }
00098 
00099     dt_error "IDX error ($code), \"$cmd\" : ${msg}."
00100     return
00101 }
00102 ret  Warn (type code , type text) {
00103     set msg [::msgcat::mc $code]
00104     dt_warning "IDX warning ($code): [join [split [format $msg $text] \n] "\nIDX warning ($code): "]"
00105     return
00106 }
00107 
00108 ret  Is    (type s) {global state ; return [string equal $state $s]}
00109 ret  IsNot (type s) {global state ; return [expr {![string equal $state $s]}]}
00110 ret  Go    (type s) {Log " >>\[$s\]" ; global state ; set state $s; return}
00111 ret  Push  (type s) {Log " //\[$s\]" ; global state stack ; lappend stack $state ; set state $s; return}
00112 ret  Pop   ()  {Log* " pop" ;  global state stack ; set state [lindex $stack end] ; set stack [lrange $stack 0 end-1] ; Log " \\\\\[$state\]" ; return}
00113 ret  State () {global state ; return $state}
00114 
00115 ret  Enter (type cmd) {Log* "\[[State]\] $cmd"}
00116 
00117 /* proc Log* {text} {puts -nonewline $text}*/
00118 /* proc Log  {text} {puts            $text}*/
00119 ret  Log* (type text) {}
00120 ret  Log  (type text) {}
00121 
00122 /*  -------------------------------------------------------------*/
00123 /*  Framing*/
00124 ret  ck_initialize () {
00125     global state   ; set state idx_begin
00126     global stack   ; set stack [list]
00127 }
00128 ret  ck_complete () {
00129     if {[Is done]} {
00130     return
00131     } else {
00132     Error end/open/idx
00133     }
00134     return
00135 }
00136 /*  -------------------------------------------------------------*/
00137 /*  Plain text*/
00138 ret  plain_text (type text) {
00139     # Ignore everything which is only whitespace ...
00140     # Beyond that plain text is not allowed.
00141 
00142     set redux [string map [list " " "" "\t" "" "\n" ""] $text]
00143     if {$redux == {}} {return [fmt_plain_text $text]}
00144     Error idx/plaintext
00145     return ""
00146 }
00147 
00148 /*  -------------------------------------------------------------*/
00149 /*  Variable handling ...*/
00150 
00151 ret  vset (type var , type args) {
00152     switch -exact -- [llength $args] {
00153     0 {
00154         # Retrieve contents of variable VAR
00155         upvar #0 __$var data
00156         return $data
00157     }
00158     1 {
00159         # Set contents of variable VAR
00160         global __$var
00161         set    __$var [lindex $args 0]
00162         return "" ; # Empty string ! Nothing for output.
00163     }
00164     default {
00165         return -code error "wrong#args: set var ?value?"
00166     }
00167     }
00168 }
00169 
00170 /*  -------------------------------------------------------------*/
00171 /*  Formatting commands*/
00172 ret  index_begin (type label , type title) {
00173     Enter index_begin
00174     if {[IsNot idx_begin]} {Error idx/begincmd}
00175     Go contents
00176     fmt_index_begin $label $title
00177 }
00178 ret  index_end () {
00179     Enter index_end
00180     if {[IsNot refkey_series]} {Error idx/endcmd}
00181     Go done
00182     fmt_index_end
00183 }
00184 ret  key (type text) {
00185     Enter key
00186     if {[IsNot contents] && [IsNot refkey_series]} {Error idx/keycmd}
00187     Go ref_series
00188     fmt_key $text
00189 }
00190 ret  manpage (type file , type label) {
00191     Enter manpage
00192     if {[IsNot ref_series] && [IsNot refkey_series]} {Error idx/manpagecmd}
00193     Go refkey_series
00194     fmt_manpage $file $label
00195 }
00196 ret  url (type url , type label) {
00197     Enter url
00198     if {[IsNot ref_series] && [IsNot refkey_series]} {Error idx/urlcmd}
00199     Go refkey_series
00200     fmt_url $url $label
00201 }
00202 ret  comment (type text) {
00203     if {[Is done]} {Error idx/nodonecmd}
00204     return ; #fmt_comment $text
00205 }
00206 
00207 /*  -------------------------------------------------------------*/
00208 

Generated on 21 Sep 2010 for Gui by  doxygen 1.6.1