A Collection of Isabelle Programming Hacks
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

262 lines
9.9 KiB

  1. (***********************************************************************************
  2. * Copyright (c) 2021 Achim D. Brucker
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. *
  9. * * Redistributions of source code must retain the above copyright notice, this
  10. *
  11. * * Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. *
  26. * SPDX-License-Identifier: BSD-2-Clause
  27. * Repository: https://git.logicalhacking.com/adbrucker/isabelle-hacks/
  28. * Dependencies: None
  29. ***********************************************************************************)
  30. (***********************************************************************************
  31. # Changelog
  32. This comment documents all notable changes to this file in a format inspired by
  33. [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres
  34. to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
  35. ## [Unreleased]
  36. ## [1.0.0] - 2021-04-29
  37. - Initial release as part of "Isabelle Hacks".
  38. ***********************************************************************************)
  39. chapter\<open>The Functional XML Parser for Isabelle\<close>
  40. theory fxp
  41. imports Main
  42. begin
  43. (*
  44. The files in the directory "fxp" are part of fxp (The Functional XML Parser).
  45. It was modified to work with Isabelle/ML by Achim D. Brucker.
  46. It was downloaded from http://www2.cs.tum.edu/projects/Fxp/a
  47. fxp: A Functional XML Parser
  48. Version 2.0, 25.06.2004
  49. ------------------------------------------------
  50. COPYRIGHT NOTICE, LICENSE AND DISCLAIMER.
  51. Copyright 1999-2004 by Andreas Neumann and Alexandru Berlea, TU Munich
  52. Permission to use, copy, modify, and distribute this software and
  53. its documentation for any purpose and without fee is hereby granted,
  54. provided that the above copyright notice appear in all copies and that
  55. both the copyright notice and this permission notice and warranty
  56. disclaimer appear in supporting documentation.
  57. The TU Munich disclaims all warranties with regard to this
  58. software, including all implied warranties of merchantability and
  59. fitness. In no event shall the TU Munich be liable for any
  60. special, indirect or consequential damages or any damages whatsoever
  61. resulting from loss of use, data or profits, whether in an action of
  62. contract, negligence or other tortious action, arising out of or in
  63. connection with the use or performance of this software.
  64. ------------------------------------------------
  65. This software was produced with the help of software, tools, and code
  66. from SML of New Jersey. Therefore we repeat here the copyright notice
  67. SML of New Jersey:
  68. STANDARD ML OF NEW JERSEY COPYRIGHT NOTICE, LICENSE AND DISCLAIMER.
  69. Copyright (c) 1989-1998 by Lucent Technologies
  70. Permission to use, copy, modify, and distribute this software and its
  71. documentation for any purpose and without fee is hereby granted,
  72. provided that the above copyright notice appear in all copies and that
  73. both the copyright notice and this permission notice and warranty
  74. disclaimer appear in supporting documentation, and that the name of
  75. Lucent Technologies, Bell Labs or any Lucent entity not be used in
  76. advertising or publicity pertaining to distribution of the software
  77. without specific, written prior permission.
  78. Lucent disclaims all warranties with regard to this software,
  79. including all implied warranties of merchantability and fitness. In no
  80. event shall Lucent be liable for any special, indirect or
  81. consequential damages or any damages whatsoever resulting from loss of
  82. use, data or profits, whether in an action of contract, negligence or
  83. other tortious action, arising out of or in connection with the use
  84. or performance of this software.
  85. ------------------------------------------------
  86. *)
  87. ML\<open>
  88. structure HashString =
  89. struct
  90. fun hashString _ = ()
  91. end
  92. structure HashTable =
  93. struct
  94. datatype ('a, 'b) hash_table = HT of {
  95. eq_pred : ('a * 'a) -> bool,
  96. not_found : exn,
  97. table: (('a*'b) list) Unsynchronized.ref
  98. }
  99. fun mkTable (_, eq) (_, notFound) = HT{
  100. eq_pred = eq,
  101. not_found = notFound,
  102. table = Unsynchronized.ref ([])
  103. }
  104. fun find (HT{table,...}) key =
  105. Option.map (fn (_,b) => b) ((List.find (fn (x,_) => x =key) (!table)))
  106. fun insert (HT{table,...}) (k,v) = (table:=([(k,v)]@ (!(table))))
  107. end
  108. \<close>
  109. SML_import List.foldl
  110. SML_import List.foldr
  111. SML_import Option.valOf
  112. SML_import Option.isSome
  113. SML_import Char.ord
  114. SML_import Char.chr
  115. ML\<open>
  116. val ord = Char.ord;
  117. val chr = Char.chr;
  118. val print = writeln;
  119. val foldr=List.foldr;
  120. val foldl=List.foldl;
  121. val valOf = Option.valOf;
  122. val isSome = Option.isSome;
  123. val getOpt = Option.getOpt
  124. \<close>
  125. (* begin fxp imports *)
  126. ML_file "fxp/src/Util/utilString.sml"
  127. ML_file "fxp/src/Util/utilHash.sml"
  128. ML_file "fxp/src/Util/utilCompare.sml"
  129. ML_file "fxp/src/Unicode/Chars/uniChar.sml"
  130. ML_file "fxp/src/Util/SymDict/key.sml"
  131. ML_file "fxp/src/Util/utilError.sml"
  132. ML_file "fxp/src/Util/utilInt.sml"
  133. ML_file "fxp/src/Util/SymDict/dict.sml"
  134. ML_file "fxp/src/Util/SymDict/stringDict.sml"
  135. ML_file "fxp/src/Unicode/encoding.sml"
  136. ML_file "fxp/src/Unicode/Encode/encodeBasic.sml"
  137. ML_file "fxp/src/Unicode/Encode/encodeError.sml"
  138. ML_file "fxp/src/Unicode/Encode/encodeMisc.sml"
  139. ML_file "fxp/src/Unicode/Encode/encode.sml"
  140. ML_file "fxp/src/Unicode/Chars/charClasses.sml"
  141. ML_file "fxp/src/Unicode/Chars/uniRanges.sml"
  142. ML_file "fxp/src/Unicode/Chars/uniClasses.sml"
  143. ML_file "fxp/src/Unicode/Uri/uriDecode.sml"
  144. ML_file "fxp/src/Unicode/Uri/uriEncode.sml"
  145. ML_file "fxp/src/config.sml"
  146. ML_file "fxp/src/Unicode/Uri/uri.sml"
  147. ML_file "fxp/src/Unicode/Decode/decodeFile.sml"
  148. ML_file "fxp/src/genRandom.sml"
  149. ML_file "fxp/src/Util/utilTime.sml"
  150. ML_file "fxp/src/Util/utilList.sml"
  151. ML_file "fxp/src/Util/intLists.sml"
  152. ML_file "fxp/src/Util/SymDict/symbolTable.sml"
  153. ML_file "fxp/src/Util/SymDict/intListDict.sml"
  154. ML_file "fxp/src/Util/SymDict/intDict.sml"
  155. ML_file "fxp/src/Unicode/Chars/testClasses.sml"
  156. ML_file "fxp/src/Unicode/Chars/charVecDict.sml"
  157. ML_file "fxp/src/Parser/version.sml"
  158. ML_file "fxp/src/Unicode/Decode/decodeError.sml"
  159. ML_file "fxp/src/Unicode/Decode/decodeUtil.sml"
  160. ML_file "fxp/src/Unicode/Decode/decodeUtf8.sml"
  161. ML_file "fxp/src/Unicode/Decode/decodeUtf16.sml"
  162. ML_file "fxp/src/Unicode/Decode/decodeUcs4.sml"
  163. ML_file "fxp/src/Unicode/Decode/decodeUcs2.sml"
  164. ML_file "fxp/src/Unicode/Decode/decodeMisc.sml"
  165. ML_file "fxp/src/Unicode/Decode/decode.sml"
  166. ML_file "fxp/src/Parser/Error/errorData.sml"
  167. ML_file "fxp/src/Parser/Error/errorString.sml"
  168. ML_file "fxp/src/Parser/Error/errorMessage.sml"
  169. ML_file "fxp/src/Parser/Error/errorUtil.sml"
  170. ML_file "fxp/src/Parser/Error/expected.sml"
  171. ML_file "fxp/src/Parser/Error/errors.sml"
  172. ML_file "fxp/src/Parser/Dfa/dfaData.sml"
  173. ML_file "fxp/src/Parser/Base/baseData.sml"
  174. ML_file "fxp/src/Parser/Dfa/dfaString.sml"
  175. ML_file "fxp/src/Parser/Base/baseString.sml"
  176. ML_file "fxp/src/Parser/Base/base.sml"
  177. ML_file "fxp/src/Parser/Params/resolve.sml"
  178. ML_file "fxp/src/Catalog/catError.sml"
  179. ML_file "fxp/src/Catalog/catParams.sml"
  180. ML_file "fxp/src/Unicode/Uri/uriDict.sml"
  181. ML_file "fxp/src/Catalog/catData.sml"
  182. ML_file "fxp/src/Util/options.sml"
  183. ML_file "fxp/src/Parser/Dfa/dfaOptions.sml"
  184. ML_file "fxp/src/Parser/Params/parserOptions.sml"
  185. ML_file "fxp/src/Parser/Params/hookData.sml"
  186. ML_file "fxp/src/Parser/Params/hooks.sml"
  187. ML_file "fxp/src/Unicode/Chars/dataDict.sml"
  188. ML_file "fxp/src/Parser/Params/dtd.sml"
  189. ML_file "fxp/src/Parser/Dfa/dfaUtil.sml"
  190. ML_file "fxp/src/Util/intSets.sml"
  191. ML_file "fxp/src/Util/SymDict/intSetDict.sml"
  192. ML_file "fxp/src/Parser/Dfa/dfaPassThree.sml"
  193. ML_file "fxp/src/Parser/Dfa/dfaError.sml"
  194. ML_file "fxp/src/Parser/Dfa/dfaPassOne.sml"
  195. ML_file "fxp/src/Parser/Dfa/dfaPassTwo.sml"
  196. ML_file "fxp/src/Parser/Dfa/dfa.sml"
  197. ML_file "fxp/src/Parser/entities.sml"
  198. ML_file "fxp/src/Parser/Dtd/dtdDeclare.sml"
  199. ML_file "fxp/src/Parser/Dtd/dtdAttributes.sml"
  200. ML_file "fxp/src/Parser/Dtd/dtdManager.sml"
  201. ML_file "fxp/src/Parser/Parse/parseBase.sml"
  202. ML_file "fxp/src/Parser/Parse/parseNames.sml"
  203. ML_file "fxp/src/Parser/Parse/parseMisc.sml"
  204. ML_file "fxp/src/Parser/Parse/parseXml.sml"
  205. ML_file "fxp/src/Parser/Parse/parseRefs.sml"
  206. ML_file "fxp/src/Parser/Parse/parseLiterals.sml"
  207. ML_file "fxp/src/Parser/Parse/parseTags.sml"
  208. ML_file "fxp/src/Parser/Parse/parseDecl.sml"
  209. ML_file "fxp/src/Parser/Parse/parseDtd.sml"
  210. ML_file "fxp/src/Parser/Parse/parseContent.sml"
  211. ML_file "fxp/src/Parser/Parse/parseDocument.sml"
  212. ML_file "fxp/src/Catalog/catFile.sml"
  213. ML_file "fxp/src/Catalog/socatParse.sml"
  214. ML_file "fxp/src/Catalog/catDtd.sml"
  215. ML_file "fxp/src/Parser/Params/ignore.sml"
  216. ML_file "fxp/src/Catalog/catHooks.sml"
  217. ML_file "fxp/src/Catalog/catParse.sml"
  218. ML_file "fxp/src/Catalog/catalog.sml"
  219. ML_file "fxp/src/Catalog/catResolve.sml"
  220. ML_file "fxp/src/Catalog/catOptions.sml"
  221. (* end of fxp imports *)
  222. (*
  223. Todo: move configuration of the OS command for resolving URI
  224. from config.sml to a proper Isabelle/Isar configuration attribute:
  225. *)
  226. ML\<open>
  227. val timeout = Attrib.setup_config_string \<^binding>\<open>uri_cmd\<close> (K "wget -qO %2 %1")
  228. \<close>
  229. end