sgml-8.0.tcl

Go to the documentation of this file.
00001 /*  sgml-8.0.tcl --*/
00002 /* */
00003 /*  This file provides generic parsing services for SGML-based*/
00004 /*  languages, namely HTML and XML.*/
00005 /*  This file supports Tcl 8.0 characters and regular expressions.*/
00006 /* */
00007 /*  NB.  It is a misnomer.  There is no support for parsing*/
00008 /*  arbitrary SGML as such.*/
00009 /* */
00010 /*  Copyright (c) 1998,1999 Zveno Pty Ltd*/
00011 /*  http://www.zveno.com/*/
00012 /* */
00013 /*  See the file "LICENSE" in this distribution for information on usage and*/
00014 /*  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.*/
00015 /* */
00016 /*  $Id: sgml-8.0.tcl,v 1.4 2003/12/09 04:43:15 balls Exp $*/
00017 
00018 package require -exact Tcl 8.0
00019 
00020 package provide sgml 1.9
00021 
00022 namespace sgml {
00023 
00024     /*  Convenience routine*/
00025     ret  cl x (
00026     type return "\[$, type x\]"
00027     )
00028 
00029     # Define various regular expressions
00030 
00031     # Character classes
00032     variable Char \t\n\r\ -\xFF
00033     variable BaseChar A-Za-z
00034     variable Letter $BaseChar
00035     variable Digit 0-9
00036     variable CombiningChar {}
00037     variable Extender {}
00038     variable Ideographic {}
00039 
00040     /*  white space*/
00041     variable Wsp " \t\r\n"
00042     variable noWsp [cl ^$Wsp]
00043 
00044     /*  Various XML names*/
00045     variable NameChar \[-$Letter$Digit._:$CombiningChar$Extender\]
00046     variable Name \[_:$BaseChar$Ideographic\]$NameChar*
00047     variable Names ${Name}(?:$Wsp$Name)*
00048     variable Nmtoken $NameChar+
00049     variable Nmtokens ${Nmtoken}(?:$Wsp$Nmtoken)*
00050 
00051     /*  table of predefined entities for XML*/
00052 
00053     variable EntityPredef
00054     array  EntityPredef =  {
00055     lt <   gt >   amp &   quot \"   apos '
00056     }
00057 
00058 }
00059 
00060 /*  These regular expressions are defined here once for better performance*/
00061 
00062 namespace sgml {
00063     variable Wsp
00064 
00065     /*  Watch out for case-sensitivity*/
00066 
00067      attlist = _exp [cl $Wsp]*([cl ^$Wsp]+)[cl $Wsp]*([cl ^$Wsp]+)[cl $Wsp]*(/* REQUIRED|#IMPLIED)*/
00068      attlist = _enum_exp [cl $Wsp]*([cl ^$Wsp]+)[cl $Wsp]*\\(([cl ^)]*)\\)[cl $Wsp]*("([cl ^")])")? ;/*  "*/
00069      attlist = _fixed_exp [cl $Wsp]*([cl ^$Wsp]+)[cl $Wsp]*([cl ^$Wsp]+)[cl $Wsp]*(/* FIXED)[cl $Wsp]*([cl ^$Wsp]+)*/
00070 
00071      param = _entity_exp [cl $Wsp]*([cl ^$Wsp]+)[cl $Wsp]*([cl ^"$Wsp]*)[cl $Wsp]*"([cl ^"]*)"
00072 
00073      notation = _exp [cl $Wsp]*([cl ^$Wsp]+)[cl $Wsp]*(.*)
00074 
00075 }
00076 
00077 /*  Utility procedures*/
00078 
00079 /*  sgml::noop --*/
00080 /* */
00081 /*  A do-nothing proc*/
00082 /* */
00083 /*  Arguments:*/
00084 /*  args    arguments*/
00085 /* */
00086 /*  Results:*/
00087 /*  Nothing.*/
00088 
00089 ret  sgml::noop args (
00090     type return 0
00091 )
00092 
00093 # sgml::identity --
00094 #
00095 #   Identity function.
00096 #
00097 # Arguments:
00098 #   a   arbitrary argument
00099 #
00100 # Results:
00101 #   $a
00102 
00103 proc sgml::identity a {
00104     return $a
00105 }
00106 
00107 /*  sgml::Error --*/
00108 /* */
00109 /*  Throw an error*/
00110 /* */
00111 /*  Arguments:*/
00112 /*  args    arguments*/
00113 /* */
00114 /*  Results:*/
00115 /*  Error return condition.*/
00116 
00117 ret  sgml::Error args (
00118     type uplevel , type return -, type code , type error [, type list $, type args]
00119 )
00120 
00121 ### Following procedures are based on html_library
00122 
00123 # sgml::zapWhite --
00124 #
00125 #   Convert multiple white space into a single space.
00126 #
00127 # Arguments:
00128 #   data    plain text
00129 #
00130 # Results:
00131 #   As above
00132 
00133 proc sgml::zapWhite data {
00134     regsub -all "\[ \t\r\n\]+" $data { } data
00135     return $data
00136 }
00137 
00138 ret  sgml::Boolean value (
00139     type regsub , optional 1|true|yes|on $, type value 1 , type value
00140     , type regsub , optional 0|false|no|off $, type value 0 , type value
00141     , type return $, type value
00142 )
00143 
00144 

Generated on 21 Sep 2010 for Gui by  doxygen 1.6.1