home *** CD-ROM | disk | FTP | other *** search
/ PC World 2002 May / PCWorld_2002-05_cd.bin / Software / TemaCD / activetcltk / ActiveTcl8.3.4.1-8.win32-ix86.exe / ActiveTcl8.3.4.1-win32-ix86 / lib / tclxml2.0 / sgml-8.0.tcl < prev    next >
Encoding:
Text File  |  2001-10-22  |  3.8 KB  |  162 lines

  1. # sgml-8.0.tcl --
  2. #
  3. #    This file provides generic parsing services for SGML-based
  4. #    languages, namely HTML and XML.
  5. #    This file supports Tcl 8.0 characters and regular expressions.
  6. #
  7. #    NB.  It is a misnomer.  There is no support for parsing
  8. #    arbitrary SGML as such.
  9. #
  10. # Copyright (c) 1998,1999 Zveno Pty Ltd
  11. # http://www.zveno.com/
  12. #
  13. # Zveno makes this software available free of charge for any purpose.
  14. # Copies may be made of this software but all of this notice must be included
  15. # on any copy.
  16. #
  17. # The software was developed for research purposes only and Zveno does not
  18. # warrant that it is error free or fit for any purpose.  Zveno disclaims any
  19. # liability for all claims, expenses, losses, damages and costs any user may
  20. # incur as a result of using, copying or modifying this software.
  21. #
  22. # Copyright (c) 1997 ANU and CSIRO on behalf of the
  23. # participants in the CRC for Advanced Computational Systems ('ACSys').
  24. # ACSys makes this software and all associated data and documentation 
  25. # ('Software') available free of charge for any purpose.  You may make copies 
  26. # of the Software but you must include all of this notice on any copy.
  27. # The Software was developed for research purposes and ACSys does not warrant
  28. # that it is error free or fit for any purpose.  ACSys disclaims any
  29. # liability for all claims, expenses, losses, damages and costs any user may
  30. # incur as a result of using, copying or modifying the Software.
  31. #
  32. # $Id: sgml-8.0.tcl,v 1.2 2000/03/09 06:52:16 steve Exp $
  33.  
  34. package require -exact Tcl 8.0
  35.  
  36. package provide sgml 1.8
  37.  
  38. namespace eval sgml {
  39.  
  40.     # Convenience routine
  41.     proc cl x {
  42.     return "\[$x\]"
  43.     }
  44.  
  45.     # Define various regular expressions
  46.  
  47.     # Character classes
  48.     variable Char \t\n\r\ -\xFF
  49.     variable BaseChar A-Za-z
  50.     variable Letter $BaseChar
  51.     variable Digit 0-9
  52.     variable CombiningChar {}
  53.     variable Extender {}
  54.     variable Ideographic {}
  55.  
  56.     # white space
  57.     variable Wsp " \t\r\n"
  58.     variable noWsp [cl ^$Wsp]
  59.  
  60.     # Various XML names
  61.     variable NameChar \[-$Letter$Digit._:$CombiningChar$Extender\]
  62.     variable Name \[_:$BaseChar$Ideographic\]$NameChar*
  63.     variable Names ${Name}(?:$Wsp$Name)*
  64.     variable Nmtoken $NameChar+
  65.     variable Nmtokens ${Nmtoken}(?:$Wsp$Nmtoken)*
  66.  
  67.     # table of predefined entities for XML
  68.  
  69.     variable EntityPredef
  70.     array set EntityPredef {
  71.     lt <   gt >   amp &   quot \"   apos '
  72.     }
  73.  
  74. }
  75.  
  76. # These regular expressions are defined here once for better performance
  77.  
  78. namespace eval sgml {
  79.     variable Wsp
  80.  
  81.     # Watch out for case-sensitivity
  82.  
  83.     set attlist_exp [cl $Wsp]*([cl ^$Wsp]+)[cl $Wsp]*([cl ^$Wsp]+)[cl $Wsp]*(#REQUIRED|#IMPLIED)
  84.     set attlist_enum_exp [cl $Wsp]*([cl ^$Wsp]+)[cl $Wsp]*\\(([cl ^)]*)\\)[cl $Wsp]*("([cl ^")])")? ;# "
  85.     set attlist_fixed_exp [cl $Wsp]*([cl ^$Wsp]+)[cl $Wsp]*([cl ^$Wsp]+)[cl $Wsp]*(#FIXED)[cl $Wsp]*([cl ^$Wsp]+)
  86.  
  87.     set param_entity_exp [cl $Wsp]*([cl ^$Wsp]+)[cl $Wsp]*([cl ^"$Wsp]*)[cl $Wsp]*"([cl ^"]*)"
  88.  
  89.     set notation_exp [cl $Wsp]*([cl ^$Wsp]+)[cl $Wsp]*(.*)
  90.  
  91. }
  92.  
  93. ### Utility procedures
  94.  
  95. # sgml::noop --
  96. #
  97. #    A do-nothing proc
  98. #
  99. # Arguments:
  100. #    args    arguments
  101. #
  102. # Results:
  103. #    Nothing.
  104.  
  105. proc sgml::noop args {
  106.     return 0
  107. }
  108.  
  109. # sgml::identity --
  110. #
  111. #    Identity function.
  112. #
  113. # Arguments:
  114. #    a    arbitrary argument
  115. #
  116. # Results:
  117. #    $a
  118.  
  119. proc sgml::identity a {
  120.     return $a
  121. }
  122.  
  123. # sgml::Error --
  124. #
  125. #    Throw an error
  126. #
  127. # Arguments:
  128. #    args    arguments
  129. #
  130. # Results:
  131. #    Error return condition.
  132.  
  133. proc sgml::Error args {
  134.     uplevel return -code error [list $args]
  135. }
  136.  
  137. ### Following procedures are based on html_library
  138.  
  139. # sgml::zapWhite --
  140. #
  141. #    Convert multiple white space into a single space.
  142. #
  143. # Arguments:
  144. #    data    plain text
  145. #
  146. # Results:
  147. #    As above
  148.  
  149. proc sgml::zapWhite data {
  150.     regsub -all "\[ \t\r\n\]+" $data { } data
  151.     return $data
  152. }
  153.  
  154. proc sgml::Boolean value {
  155.     regsub {1|true|yes|on} $value 1 value
  156.     regsub {0|false|no|off} $value 0 value
  157.     return $value
  158. }
  159.  
  160.