From 1d840722d6b7d12bf2f7fef035145fbe108a0c4f Mon Sep 17 00:00:00 2001 From: "Achim D. Brucker" Date: Wed, 28 Apr 2021 09:24:59 +0100 Subject: [PATCH] Import of fxp sources, as used in su4sml . --- fxp/CHANGES | 339 +++++++ fxp/COPYRIGHT | 55 ++ fxp/Makefile | 146 +++ fxp/README | 133 +++ fxp/doc/CHANGES | 339 +++++++ fxp/doc/COPYRIGHT | 55 ++ fxp/doc/Examples/exa-1.ext | 2 + fxp/doc/Examples/exa-1.xml | 22 + fxp/doc/Examples/exa-2.xml | 15 + fxp/doc/Examples/exa-3.xml | 15 + fxp/doc/Examples/exa-4.xml | 21 + fxp/doc/Examples/exa-5.esis-7 | 28 + fxp/doc/Examples/exa-5.esis-8 | 33 + fxp/doc/Examples/exa-5.xml | 35 + fxp/doc/Examples/exa-6.ext | 2 + fxp/doc/Examples/exa-6.xml | 8 + fxp/doc/Examples/exa-exp.xml | 12 + fxp/doc/Examples/ext-6.decl | 1 + fxp/doc/Examples/ext.decl | 1 + fxp/doc/Examples/ext.elem | 1 + fxp/doc/Examples/ext.ent | 1 + fxp/doc/Examples/xmlcat.dtd | 24 + fxp/doc/Images/ball-shadow.jpg | Bin 0 -> 494 bytes fxp/doc/Images/email.png | Bin 0 -> 411 bytes fxp/doc/Images/exa-vcg-1.gif | Bin 0 -> 7196 bytes fxp/doc/Images/exa-vcg-2.gif | Bin 0 -> 5908 bytes fxp/doc/Images/exa-vcg-3.gif | Bin 0 -> 2241 bytes fxp/doc/Images/exa-vcg-4.gif | Bin 0 -> 4910 bytes fxp/doc/Images/exa-vcg-5.gif | Bin 0 -> 4503 bytes fxp/doc/Images/exa-vcg-6.gif | Bin 0 -> 5696 bytes fxp/doc/Images/fxp-shadow.jpg | Bin 0 -> 2246 bytes fxp/doc/Images/index.html | 238 +++++ fxp/doc/Images/shadow.jpg | Bin 0 -> 1767 bytes fxp/doc/README | 133 +++ fxp/doc/api.ps | 1092 +++++++++++++++++++++ fxp/doc/ball-shadow.jpg | Bin 0 -> 494 bytes fxp/doc/doc.ps | 821 ++++++++++++++++ fxp/doc/exa-vcg-1.gif | Bin 0 -> 7196 bytes fxp/doc/exa-vcg-2.gif | Bin 0 -> 5908 bytes fxp/doc/exa-vcg-3.gif | Bin 0 -> 2241 bytes fxp/doc/exa-vcg-4.gif | Bin 0 -> 4910 bytes fxp/doc/exa-vcg-5.gif | Bin 0 -> 4503 bytes fxp/doc/exa-vcg-6.gif | Bin 0 -> 5696 bytes fxp/doc/features.html | 387 ++++++++ fxp/doc/fxcanon.html | 40 + fxp/doc/fxcopy.html | 485 ++++++++++ fxp/doc/fxesis.html | 334 +++++++ fxp/doc/fxp-shadow.jpg | Bin 0 -> 2246 bytes fxp/doc/fxp-xsa.xml | 22 + fxp/doc/fxp.html | 793 ++++++++++++++++ fxp/doc/fxviz.html | 246 +++++ fxp/doc/index.html | 239 +++++ fxp/doc/shadow.jpg | Bin 0 -> 1767 bytes fxp/doc/windows.html | 97 ++ fxp/doc/working.diff | 339 +++++++ fxp/doc/working.html | 299 ++++++ fxp/fxp.sh.in | 13 + fxp/src/Apps/Canon/canon.cm | 8 + fxp/src/Apps/Canon/canon.mlb | 15 + fxp/src/Apps/Canon/canon.sml | 81 ++ fxp/src/Apps/Canon/canonEncode.sml | 70 ++ fxp/src/Apps/Canon/canonHooks.sml | 79 ++ fxp/src/Apps/Canon/canonOptions.sml | 106 +++ fxp/src/Apps/Canon/canonOutput.sml | 75 ++ fxp/src/Apps/Copy/copy.cm | 8 + fxp/src/Apps/Copy/copy.mlb | 15 + fxp/src/Apps/Copy/copy.sml | 81 ++ fxp/src/Apps/Copy/copyEncode.sml | 135 +++ fxp/src/Apps/Copy/copyHooks.sml | 153 +++ fxp/src/Apps/Copy/copyOptions.sml | 270 ++++++ fxp/src/Apps/Copy/copyOutput.sml | 330 +++++++ fxp/src/Apps/Esis/esis.cm | 8 + fxp/src/Apps/Esis/esis.mlb | 15 + fxp/src/Apps/Esis/esis.sml | 88 ++ fxp/src/Apps/Esis/esisData.sml | 16 + fxp/src/Apps/Esis/esisHooks.sml | 39 + fxp/src/Apps/Esis/esisOptions.sml | 116 +++ fxp/src/Apps/Esis/esisOutput.sml | 204 ++++ fxp/src/Apps/Null/null.cm | 7 + fxp/src/Apps/Null/null.mlb | 14 + fxp/src/Apps/Null/null.sml | 82 ++ fxp/src/Apps/Null/nullHard.sml | 88 ++ fxp/src/Apps/Null/nullHooks.sml | 20 + fxp/src/Apps/Null/nullOptions.sml | 93 ++ fxp/src/Apps/Viz/viz.cm | 6 + fxp/src/Apps/Viz/viz.mlb | 13 + fxp/src/Apps/Viz/viz.sml | 87 ++ fxp/src/Apps/Viz/vizHooks.sml | 381 ++++++++ fxp/src/Apps/Viz/vizOptions.sml | 106 +++ fxp/src/Catalog/catData.sml | 13 + fxp/src/Catalog/catDtd.sml | 54 ++ fxp/src/Catalog/catError.sml | 117 +++ fxp/src/Catalog/catFile.sml | 74 ++ fxp/src/Catalog/catHooks.sml | 89 ++ fxp/src/Catalog/catOptions.sml | 136 +++ fxp/src/Catalog/catParams.sml | 17 + fxp/src/Catalog/catParse.sml | 69 ++ fxp/src/Catalog/catResolve.sml | 25 + fxp/src/Catalog/catalog.sml | 139 +++ fxp/src/Catalog/socatParse.sml | 293 ++++++ fxp/src/Parser/Base/base.sml | 9 + fxp/src/Parser/Base/baseData.sml | 110 +++ fxp/src/Parser/Base/baseString.sml | 165 ++++ fxp/src/Parser/Dfa/dfa.sml | 112 +++ fxp/src/Parser/Dfa/dfaData.sml | 73 ++ fxp/src/Parser/Dfa/dfaError.sml | 58 ++ fxp/src/Parser/Dfa/dfaOptions.sml | 97 ++ fxp/src/Parser/Dfa/dfaPassOne.sml | 85 ++ fxp/src/Parser/Dfa/dfaPassThree.sml | 101 ++ fxp/src/Parser/Dfa/dfaPassTwo.sml | 77 ++ fxp/src/Parser/Dfa/dfaString.sml | 78 ++ fxp/src/Parser/Dfa/dfaUtil.sml | 130 +++ fxp/src/Parser/Dtd/dtdAttributes.sml | 538 +++++++++++ fxp/src/Parser/Dtd/dtdDeclare.sml | 466 +++++++++ fxp/src/Parser/Dtd/dtdManager.sml | 71 ++ fxp/src/Parser/Error/errorData.sml | 176 ++++ fxp/src/Parser/Error/errorMessage.sml | 209 ++++ fxp/src/Parser/Error/errorString.sml | 179 ++++ fxp/src/Parser/Error/errorUtil.sml | 85 ++ fxp/src/Parser/Error/errors.sml | 6 + fxp/src/Parser/Error/expected.sml | 70 ++ fxp/src/Parser/Params/dtd.sml | 339 +++++++ fxp/src/Parser/Params/hookData.sml | 60 ++ fxp/src/Parser/Params/hooks.sml | 34 + fxp/src/Parser/Params/ignore.sml | 31 + fxp/src/Parser/Params/parserOptions.sml | 294 ++++++ fxp/src/Parser/Params/resolve.sml | 18 + fxp/src/Parser/Parse/parseBase.sml | 160 ++++ fxp/src/Parser/Parse/parseContent.sml | 919 ++++++++++++++++++ fxp/src/Parser/Parse/parseDecl.sml | 1157 +++++++++++++++++++++++ fxp/src/Parser/Parse/parseDocument.sml | 262 +++++ fxp/src/Parser/Parse/parseDtd.sml | 541 +++++++++++ fxp/src/Parser/Parse/parseLiterals.sml | 458 +++++++++ fxp/src/Parser/Parse/parseMisc.sml | 299 ++++++ fxp/src/Parser/Parse/parseNames.sml | 108 +++ fxp/src/Parser/Parse/parseRefs.sml | 720 ++++++++++++++ fxp/src/Parser/Parse/parseTags.sml | 329 +++++++ fxp/src/Parser/Parse/parseXml.sml | 679 +++++++++++++ fxp/src/Parser/entities.sml | 570 +++++++++++ fxp/src/Parser/version.sml | 4 + fxp/src/ROOT.ML | 95 ++ fxp/src/Unicode/Chars/charClasses.sml | 158 ++++ fxp/src/Unicode/Chars/charVecDict.sml | 11 + fxp/src/Unicode/Chars/dataDict.sml | 22 + fxp/src/Unicode/Chars/testClasses.sml | 46 + fxp/src/Unicode/Chars/uniChar.sml | 129 +++ fxp/src/Unicode/Chars/uniClasses.sml | 222 +++++ fxp/src/Unicode/Chars/uniRanges.sml | 431 +++++++++ fxp/src/Unicode/Decode/decode.sml | 295 ++++++ fxp/src/Unicode/Decode/decodeError.sml | 118 +++ fxp/src/Unicode/Decode/decodeFile.sml | 151 +++ fxp/src/Unicode/Decode/decodeMisc.sml | 76 ++ fxp/src/Unicode/Decode/decodeUcs2.sml | 37 + fxp/src/Unicode/Decode/decodeUcs4.sml | 91 ++ fxp/src/Unicode/Decode/decodeUtf16.sml | 61 ++ fxp/src/Unicode/Decode/decodeUtf8.sml | 176 ++++ fxp/src/Unicode/Decode/decodeUtil.sml | 41 + fxp/src/Unicode/Encode/encode.sml | 86 ++ fxp/src/Unicode/Encode/encodeBasic.sml | 48 + fxp/src/Unicode/Encode/encodeError.sml | 32 + fxp/src/Unicode/Encode/encodeMisc.sml | 205 ++++ fxp/src/Unicode/Uri/uri.sml | 197 ++++ fxp/src/Unicode/Uri/uriDecode.sml | 135 +++ fxp/src/Unicode/Uri/uriDict.sml | 18 + fxp/src/Unicode/Uri/uriEncode.sml | 98 ++ fxp/src/Unicode/encoding.sml | 89 ++ fxp/src/Util/SymDict/dict.sml | 323 +++++++ fxp/src/Util/SymDict/intDict.sml | 21 + fxp/src/Util/SymDict/intListDict.sml | 20 + fxp/src/Util/SymDict/intSetDict.sml | 23 + fxp/src/Util/SymDict/key.sml | 16 + fxp/src/Util/SymDict/stringDict.sml | 20 + fxp/src/Util/SymDict/symbolTable.sml | 314 ++++++ fxp/src/Util/intLists.sml | 49 + fxp/src/Util/intSets.sml | 173 ++++ fxp/src/Util/options.sml | 105 ++ fxp/src/Util/utilCompare.sml | 89 ++ fxp/src/Util/utilError.sml | 49 + fxp/src/Util/utilHash.sml | 80 ++ fxp/src/Util/utilInt.sml | 86 ++ fxp/src/Util/utilList.sml | 198 ++++ fxp/src/Util/utilString.sml | 238 +++++ fxp/src/Util/utilTime.sml | 37 + fxp/src/config.sml | 19 + fxp/src/fxlib.cm | 106 +++ fxp/src/fxlib.mlb | 105 ++ fxp/src/genRandom.sml | 49 + 187 files changed, 25766 insertions(+) create mode 100644 fxp/CHANGES create mode 100644 fxp/COPYRIGHT create mode 100644 fxp/Makefile create mode 100644 fxp/README create mode 100644 fxp/doc/CHANGES create mode 100644 fxp/doc/COPYRIGHT create mode 100644 fxp/doc/Examples/exa-1.ext create mode 100644 fxp/doc/Examples/exa-1.xml create mode 100644 fxp/doc/Examples/exa-2.xml create mode 100644 fxp/doc/Examples/exa-3.xml create mode 100644 fxp/doc/Examples/exa-4.xml create mode 100644 fxp/doc/Examples/exa-5.esis-7 create mode 100644 fxp/doc/Examples/exa-5.esis-8 create mode 100644 fxp/doc/Examples/exa-5.xml create mode 100644 fxp/doc/Examples/exa-6.ext create mode 100644 fxp/doc/Examples/exa-6.xml create mode 100644 fxp/doc/Examples/exa-exp.xml create mode 100644 fxp/doc/Examples/ext-6.decl create mode 100644 fxp/doc/Examples/ext.decl create mode 100644 fxp/doc/Examples/ext.elem create mode 100644 fxp/doc/Examples/ext.ent create mode 100644 fxp/doc/Examples/xmlcat.dtd create mode 100644 fxp/doc/Images/ball-shadow.jpg create mode 100644 fxp/doc/Images/email.png create mode 100644 fxp/doc/Images/exa-vcg-1.gif create mode 100644 fxp/doc/Images/exa-vcg-2.gif create mode 100644 fxp/doc/Images/exa-vcg-3.gif create mode 100644 fxp/doc/Images/exa-vcg-4.gif create mode 100644 fxp/doc/Images/exa-vcg-5.gif create mode 100644 fxp/doc/Images/exa-vcg-6.gif create mode 100644 fxp/doc/Images/fxp-shadow.jpg create mode 100644 fxp/doc/Images/index.html create mode 100644 fxp/doc/Images/shadow.jpg create mode 100644 fxp/doc/README create mode 100644 fxp/doc/api.ps create mode 100644 fxp/doc/ball-shadow.jpg create mode 100644 fxp/doc/doc.ps create mode 100644 fxp/doc/exa-vcg-1.gif create mode 100644 fxp/doc/exa-vcg-2.gif create mode 100644 fxp/doc/exa-vcg-3.gif create mode 100644 fxp/doc/exa-vcg-4.gif create mode 100644 fxp/doc/exa-vcg-5.gif create mode 100644 fxp/doc/exa-vcg-6.gif create mode 100644 fxp/doc/features.html create mode 100644 fxp/doc/fxcanon.html create mode 100644 fxp/doc/fxcopy.html create mode 100644 fxp/doc/fxesis.html create mode 100644 fxp/doc/fxp-shadow.jpg create mode 100644 fxp/doc/fxp-xsa.xml create mode 100644 fxp/doc/fxp.html create mode 100644 fxp/doc/fxviz.html create mode 100644 fxp/doc/index.html create mode 100644 fxp/doc/shadow.jpg create mode 100644 fxp/doc/windows.html create mode 100644 fxp/doc/working.diff create mode 100644 fxp/doc/working.html create mode 100755 fxp/fxp.sh.in create mode 100644 fxp/src/Apps/Canon/canon.cm create mode 100644 fxp/src/Apps/Canon/canon.mlb create mode 100644 fxp/src/Apps/Canon/canon.sml create mode 100644 fxp/src/Apps/Canon/canonEncode.sml create mode 100644 fxp/src/Apps/Canon/canonHooks.sml create mode 100644 fxp/src/Apps/Canon/canonOptions.sml create mode 100644 fxp/src/Apps/Canon/canonOutput.sml create mode 100644 fxp/src/Apps/Copy/copy.cm create mode 100644 fxp/src/Apps/Copy/copy.mlb create mode 100644 fxp/src/Apps/Copy/copy.sml create mode 100644 fxp/src/Apps/Copy/copyEncode.sml create mode 100644 fxp/src/Apps/Copy/copyHooks.sml create mode 100644 fxp/src/Apps/Copy/copyOptions.sml create mode 100644 fxp/src/Apps/Copy/copyOutput.sml create mode 100644 fxp/src/Apps/Esis/esis.cm create mode 100644 fxp/src/Apps/Esis/esis.mlb create mode 100644 fxp/src/Apps/Esis/esis.sml create mode 100644 fxp/src/Apps/Esis/esisData.sml create mode 100644 fxp/src/Apps/Esis/esisHooks.sml create mode 100644 fxp/src/Apps/Esis/esisOptions.sml create mode 100644 fxp/src/Apps/Esis/esisOutput.sml create mode 100644 fxp/src/Apps/Null/null.cm create mode 100644 fxp/src/Apps/Null/null.mlb create mode 100644 fxp/src/Apps/Null/null.sml create mode 100644 fxp/src/Apps/Null/nullHard.sml create mode 100644 fxp/src/Apps/Null/nullHooks.sml create mode 100644 fxp/src/Apps/Null/nullOptions.sml create mode 100644 fxp/src/Apps/Viz/viz.cm create mode 100644 fxp/src/Apps/Viz/viz.mlb create mode 100644 fxp/src/Apps/Viz/viz.sml create mode 100644 fxp/src/Apps/Viz/vizHooks.sml create mode 100644 fxp/src/Apps/Viz/vizOptions.sml create mode 100644 fxp/src/Catalog/catData.sml create mode 100644 fxp/src/Catalog/catDtd.sml create mode 100644 fxp/src/Catalog/catError.sml create mode 100644 fxp/src/Catalog/catFile.sml create mode 100644 fxp/src/Catalog/catHooks.sml create mode 100644 fxp/src/Catalog/catOptions.sml create mode 100644 fxp/src/Catalog/catParams.sml create mode 100644 fxp/src/Catalog/catParse.sml create mode 100644 fxp/src/Catalog/catResolve.sml create mode 100644 fxp/src/Catalog/catalog.sml create mode 100644 fxp/src/Catalog/socatParse.sml create mode 100644 fxp/src/Parser/Base/base.sml create mode 100644 fxp/src/Parser/Base/baseData.sml create mode 100644 fxp/src/Parser/Base/baseString.sml create mode 100644 fxp/src/Parser/Dfa/dfa.sml create mode 100644 fxp/src/Parser/Dfa/dfaData.sml create mode 100644 fxp/src/Parser/Dfa/dfaError.sml create mode 100644 fxp/src/Parser/Dfa/dfaOptions.sml create mode 100644 fxp/src/Parser/Dfa/dfaPassOne.sml create mode 100644 fxp/src/Parser/Dfa/dfaPassThree.sml create mode 100644 fxp/src/Parser/Dfa/dfaPassTwo.sml create mode 100644 fxp/src/Parser/Dfa/dfaString.sml create mode 100644 fxp/src/Parser/Dfa/dfaUtil.sml create mode 100644 fxp/src/Parser/Dtd/dtdAttributes.sml create mode 100644 fxp/src/Parser/Dtd/dtdDeclare.sml create mode 100644 fxp/src/Parser/Dtd/dtdManager.sml create mode 100644 fxp/src/Parser/Error/errorData.sml create mode 100644 fxp/src/Parser/Error/errorMessage.sml create mode 100644 fxp/src/Parser/Error/errorString.sml create mode 100644 fxp/src/Parser/Error/errorUtil.sml create mode 100644 fxp/src/Parser/Error/errors.sml create mode 100644 fxp/src/Parser/Error/expected.sml create mode 100644 fxp/src/Parser/Params/dtd.sml create mode 100644 fxp/src/Parser/Params/hookData.sml create mode 100644 fxp/src/Parser/Params/hooks.sml create mode 100644 fxp/src/Parser/Params/ignore.sml create mode 100644 fxp/src/Parser/Params/parserOptions.sml create mode 100644 fxp/src/Parser/Params/resolve.sml create mode 100644 fxp/src/Parser/Parse/parseBase.sml create mode 100644 fxp/src/Parser/Parse/parseContent.sml create mode 100644 fxp/src/Parser/Parse/parseDecl.sml create mode 100644 fxp/src/Parser/Parse/parseDocument.sml create mode 100644 fxp/src/Parser/Parse/parseDtd.sml create mode 100644 fxp/src/Parser/Parse/parseLiterals.sml create mode 100644 fxp/src/Parser/Parse/parseMisc.sml create mode 100644 fxp/src/Parser/Parse/parseNames.sml create mode 100644 fxp/src/Parser/Parse/parseRefs.sml create mode 100644 fxp/src/Parser/Parse/parseTags.sml create mode 100644 fxp/src/Parser/Parse/parseXml.sml create mode 100644 fxp/src/Parser/entities.sml create mode 100644 fxp/src/Parser/version.sml create mode 100644 fxp/src/ROOT.ML create mode 100644 fxp/src/Unicode/Chars/charClasses.sml create mode 100644 fxp/src/Unicode/Chars/charVecDict.sml create mode 100644 fxp/src/Unicode/Chars/dataDict.sml create mode 100644 fxp/src/Unicode/Chars/testClasses.sml create mode 100644 fxp/src/Unicode/Chars/uniChar.sml create mode 100644 fxp/src/Unicode/Chars/uniClasses.sml create mode 100644 fxp/src/Unicode/Chars/uniRanges.sml create mode 100644 fxp/src/Unicode/Decode/decode.sml create mode 100644 fxp/src/Unicode/Decode/decodeError.sml create mode 100644 fxp/src/Unicode/Decode/decodeFile.sml create mode 100644 fxp/src/Unicode/Decode/decodeMisc.sml create mode 100644 fxp/src/Unicode/Decode/decodeUcs2.sml create mode 100644 fxp/src/Unicode/Decode/decodeUcs4.sml create mode 100644 fxp/src/Unicode/Decode/decodeUtf16.sml create mode 100644 fxp/src/Unicode/Decode/decodeUtf8.sml create mode 100644 fxp/src/Unicode/Decode/decodeUtil.sml create mode 100644 fxp/src/Unicode/Encode/encode.sml create mode 100644 fxp/src/Unicode/Encode/encodeBasic.sml create mode 100644 fxp/src/Unicode/Encode/encodeError.sml create mode 100644 fxp/src/Unicode/Encode/encodeMisc.sml create mode 100644 fxp/src/Unicode/Uri/uri.sml create mode 100644 fxp/src/Unicode/Uri/uriDecode.sml create mode 100644 fxp/src/Unicode/Uri/uriDict.sml create mode 100644 fxp/src/Unicode/Uri/uriEncode.sml create mode 100644 fxp/src/Unicode/encoding.sml create mode 100644 fxp/src/Util/SymDict/dict.sml create mode 100644 fxp/src/Util/SymDict/intDict.sml create mode 100644 fxp/src/Util/SymDict/intListDict.sml create mode 100644 fxp/src/Util/SymDict/intSetDict.sml create mode 100644 fxp/src/Util/SymDict/key.sml create mode 100644 fxp/src/Util/SymDict/stringDict.sml create mode 100644 fxp/src/Util/SymDict/symbolTable.sml create mode 100644 fxp/src/Util/intLists.sml create mode 100644 fxp/src/Util/intSets.sml create mode 100644 fxp/src/Util/options.sml create mode 100644 fxp/src/Util/utilCompare.sml create mode 100644 fxp/src/Util/utilError.sml create mode 100644 fxp/src/Util/utilHash.sml create mode 100644 fxp/src/Util/utilInt.sml create mode 100644 fxp/src/Util/utilList.sml create mode 100644 fxp/src/Util/utilString.sml create mode 100644 fxp/src/Util/utilTime.sml create mode 100644 fxp/src/config.sml create mode 100644 fxp/src/fxlib.cm create mode 100644 fxp/src/fxlib.mlb create mode 100644 fxp/src/genRandom.sml diff --git a/fxp/CHANGES b/fxp/CHANGES new file mode 100644 index 0000000..12721cc --- /dev/null +++ b/fxp/CHANGES @@ -0,0 +1,339 @@ +From 1.4.6 to 2.0 +--------------------------- +(25.06.2004) + +Added support for XML 1.1 (Entities.getChar, UniClasses.isNms/isName/isXml +have now an 11 (for 1.1) counterpart which are to be called when the XML +declaration declares version 1.1. + +Changed Makefile to better support Windows installation. + +(13.02.2004) +Updated fxp to handle the new specification of the xml:space attribute + +From 1.4.5 to 1.4.6 +--------------------------- +(09.10.2003) +Modified documentation to fit in the fxgrep gui framework + +From 1.4.4 to 1.4.5 +--------------------------- +(20.02.2002) +Modified the Makefiles to avoid unnecessary recompilations +2001-09-17 + - added hasElement, hasAttribute, etc. functions in Dtd + +Changes from 1.4.3 to 1.4.4 +--------------------------- +2000-10-30 + - fixed a bug : parser reported an error if more than one definition + was provided for the same ID attribute, instead of ignoring + delarations later than the first one + +Changes from 1.4.2 to 1.4.3 +--------------------------- +2000-08-29: + - modified the autodetection of character encodings as stated in the + XML 1.0 Specification Errata from 2000-08-10 under E 44; among + others, UTF-8 with BOM is now recognized. + +Changes from 1.4.1 to 1.4.2: +-------------------------- +2000-07-28: + - fixed a Solaris bug in the Makefile + +Changes from 1.4 to 1.4.1: +-------------------------- +2000-06-08: + - fixed a bug in surrogate composition + - fixed a bug: parser complained about undeclared entities in + non-validating mode, even if the DTD has paramter references. + - fixed another bug: parser never complained about undeclared + parameter entities that constitute a validity error. + - slightly restructured ParseRefs; resulting in some minor + changes in other modules. + - modified sample applications to report fatal errors as fatal. + +Changes from 1.3 to 1.4: +------------------------ +2000-02-18: + - fixed a bug in UtilCompare.compareVector + - eliminated UnsafeOps structure. Unsafe operations yield only + insignificant speedup, but extremely impair reliability. + +2000-02-10: + - parseElementContent reports only a single error for each piece + of character data in element content. Before this change, it did + report an error after each sequence of white space characters + followed by non-white space. Similarly for parseDocument. + +1999-10-22: + - Added the start position of the PI text to HookData.ProcInstInfo. + +1999-10-18: + - Fixed a small bug in UtilHash.hashTriple + +1999-08-27: + - Removed the this/next components from the Entities.State type. + It is sufficient to compare the entity's indices in the DTD. + Added a type EntId, indicating whether an entity is a parameter + or general entity, and holding its index. isOpen, pushIntern and + pushExtern now have an additional parameter isParam:bool. Changed + all parser functions accordingly. + +Changes from 1.2 to 1.3: +------------------------ +1999-08-24: + - Removed options --table-size/width. + - added new encoding UCS2B/L, which is UTF16 without surrogate pairs. + - unrolled the getBytes loop in getCharUtf8. UTF-8 does not recognize + surrogates pairs any more (cf. Rfc 2279, lines 201-206). The same + for UCS-4. + - changed implementation getCharUtf16/getCharUcs4: they are not higher + order any more. Efficiency increased. + +1999-08-13: + - Changed ParseDecl.parseGenEntDecl not to check for declaredness of + unparsed entities' notations. + - Added maxUsedGen to Dtd: returns the number of general entities defined. + - Added checkUnparsed to DtdDeclare. It checks whether all notations of + unparsed entities have been declared. Added a call to checkUnparsed + at the end of parseDtd. + +1999-08-12: + - Made DecodeUtf8.byte1switch a vector. + - Changed type CharClasses.CharClass to a vector. Arrays are now only + used for initializing the char classes; for lookup, they must be + finalized to a vector. + +1999-08-03: + - Restructered the Dtd[Elements|Attributes|Notations|Entities] modules. + There are now two modules: DtdDeclare for operations concerning + declarations, and DtdAttributes for generating attribute values. + - Renamed AuxDtd to DtdManager. + - Renamed some functions from Entities to shorter names. + - Changed ParseDocument.parseDoc not to set O_VALIDATE to false if there + is no DTD. Instead those functions that would produce too many errors + without a DTD call hasDtd in order to find out whether there is one. + - Changed the error message for ERR_NO_DTD. + +1999-07-29: + - Fixed a bug in the ParseContent.parseElementContent: character + references were passed to the application instead of reporting + an error. + - Removed ERR_DATA_IN_ELEM and ERR_CDATA_IN_ELEM; added ERR_ELEM_CONTENT + instead, which does the job for data, CDATA sections and charrefs. + - Added a boolean flag to HookData.DataInfo,indicating whether the + data is whitespace in element content. This information was available + only implicitly by the content spec of the parent element. + +1999-07-26: + - Fixed a bug in the decoder and encoder, concerning surrogates: the + offset added/subtracted in combine/splitSurrogates was 0wx10000 + instead of 0wx100000. + - DecodeUtil.isSurrogate ignored the high surrogates: fixed that. + +1999-07-22: + - Renamed DecodeBasic to DecodeFile. Changes getByte such that it + closes the file (and removes it if temporary) before raising EndOfFile. + +1999-07-20: + - Reimplemented the Uri structure to use strings for uris. (They may + only contain ASCII characters). Changed the result type of uriSuffix + to string. + - Moved the URI encoding functions to a new structure UriEncode. + A character "%" is only encoded if not followed by two hex digits. + Removed URI decoding, since that is superfluous. + - Added parser option O_WARN_NON_ASCII_URI. Changed + ParseLiterals.parseSystemLiteral to issue a warning if a non-ASCII + character occurs. Added a corresponding command line option + --warn-uri. + - Removed types CharInterval and CharRange from structure UniChar. + Added them to CharClasses, used only in Naming and NameClasses. + - Renamed type UniChar.CharVector to Vector for brevity. + - Renamed structures NameRanges and Naming to UniRanges and UniClasses. + +1999-07-19: + - Renamed structure Chars to UniChar. Changed definitions such that + UniChar provides a structure Chars : WORD such that type Char = + Chars.word; + - Moved type Byte to DecodeBasic such that DecodeBasic provides a + structure Bytes : WORD such that type Byte = Chars.word; + - Changed other structures to use UniChar.Char and DecodeBasic.Bytes + instead of hardwired Word and Word8. + +1999-07-14: + - Changed the DTD structure. The DTD is not a bunch of global variables + anymore; it is now a single data structure handed as argument to all + DTD functions. It must therefore be passed around through all DTD- + dependent parts of the parser and of all applications. + + Removed O_INIT_DTD option. Instead, the parser expects an optional + DTD as argument. If that is NONE, a new DTD data structure is + initialized, otherwise tghe provided one is used. + + Changed all applications to pass the DTD around. + - Changed functions ParseMisc.skipS and ParseRefs.skipPS. Instead of + raising NotFound on error, they call the hookError function themselves. + +Changes from 1.1 to 1.2: +------------------------ +1999-06-07: + - Replaced the --error-minimize option by --few-errors[=(yes|no)]. + The old option was buggy and could only turn on an feature that + was on by default. + +1999-06-04: + - Removed option --no-output/-n from fxesis and fxcopy. + - Modified the main functions of all applications: in case of + option errors, they raise now raise exception Exit instead + of calling OS.Process.exit. + - Added support for remote URIs. + + In structure Config, value retrieveCommand defines a command + to be executed for URI retrieval. + + Uri.retrieveUri calls this command for storing the entity + in a local file. It returns the name of the file and a flag + indicating whether a temporary file has actually been created + or the URI was local. + + DecodeBasic.FILE has this boolean as additional parameter. + Function decClose removes the temp. file if the flag is true. + +1999-05-10: + - Added new type AppFinal to HookData signature. hookFinish now + returns a value of type AppFinal. This is also the new type of + ParseDocument.parseDocument's result. + +1999-05-03: + - Added support for XML syntax of XML Catalogs. + + new function Uri.uriSuffix. Depending on the suffix of a URI, + catalogs are parsed in Socat syntax (.soc, .SOC) or XML syntax. + +1999-04-23: + - Fixed bug: Dict.getByKey raised NoSuchEntry for unknown keys. + That made fxp fail with an uncaught exception if, e.g., an + unknown output encoding was given. + +1999-04-15: + - Added functions Dict.clearDict and SymTable.clearSymTable. + - Removed references from the tables in Dtd. The Tables are now + initialized with clearDict/SymTable. + +1999-04-14: + - Moved Hooks, HookData, Dtd, DtdOptions, Resolve and ParserOptions + to directory Params. Deleted directory Hooks. + - Added the start and end position to the arguments of most of the Hooks. + Made the appropriate changes in the parser modules and the apps. + - The parser is now reentrant, i.e., multiple instances are possible + at the same time. + - Made Dfa a functor, expecting the Dfa-relevant options in a + structure DfaOptions. Added a new functor for creating such a + structure. + - Made ParserOptions a functor in order to have multiple instances + of it. ParserOptions creates DfaOptions as a substructure. + +1999-04-13: + - Made Dtd a functor, expecting a structure DtdOptions holding all options + concerning the DTD. Removed these options from ParseOptions. + - Removed O_SILENT, O_ERROR_DEVICE and O_ERROR_LINEWIDTH from ParseOptions. + These options now belong to the application. + - Fixed some bugs in the option parsers of applications. + - Fixed a bug in Dfa: exception DfaTooLarge was not visible through the + signature. + - Added an integer parameter to exceptions DfaToLarge and to + WARN_DFA_TOO_LARGE. It is the maximal allowed number of states. + - ErrorMessage no longer depends on ParseOptions. + +Changes from 1.0 to 1.1: +------------------------ +1999-03-29: + - Fixed ErrorMessage.errorMessage to complain about standalone 'yes' instead + of 'no'. + - Avoid multiple EndOfFile events for the same entity by adding a boolean + flag to DecodeError/Bytes exceptions. + +1999-03-25: + - Improved error reporting; the position handed to hookError/Warning is now + - whenever possible - the first character of the concerned item. + Exceptions are checks done at the end of the DTD or of the document. + - Improved handling of wrong end-tags. The strategy is: + + if the end-tag is for the current element, consume it and finish the + element; + + otherwise, if it is for an open element, assume the end-tag for the + current element was forgotten, i.e., finish the current element but + retain the end-tag; + + otherwise, if the current element requires further content in order + to satisfy its content model, ignore the end-tag; + + otherwise consumne the end-tag and finish the current element. + In order to implement this, the following were necessary: + + an extra argument openElems to ParseContent.parseElement. It is a list + of the indices of the types of the enclosing elements; + + an extra component optEtag in the return vale of parseElement. It is an + option and holds information about an end-tag that was not consumed when + finishing the element; + + appropriate changes to the code of parse[Mixed|Element]Content. + +1999-03-24: + - fixed some bugs: + + comparison of fixed attribute values is now correct. + + Naming.isUnicode: 0x10000..0xFFFFF was not unicode. + + ParseContent.parseMixedContent complained about character '>' even if + it was not part of the sequence ']]>'. + + whitespace normalization in attribute values also affected characters + that were escaped by a char reference. + + end-of-line normalization was done for the replacement text of internal + entities, but may only be done for the literal entitiy values. + + default values in attlist declarations were checked not only for lexical + validity but also for declaredness of notation/entity names. This is now + done when the default value is used. + +1999-03-22: + - Added support for the Socat syntax of XCatalog: + + new subdir Catalog with a main functor Catalog + + the parser functor now expects an additional structure argument Resolve + providing a function resolveExtId. That does not exist in BaseData any + more. + +1999-03-16: + - Extracted Unicode-specific code from the Parser: + + made a new directory Unicode. + + moved Parser/Front/front.sml to Parser/entities.sml; renamed Front to + Entities. + + moved Parser/Front to Unicode/Decode; renamed everything to Decode<...>, + frontEncoding to Encode. + + moved Parser/Back to Unicode/Encode; renamed everything to Encode<...>, + backEncoding to Encode; moved back.sml to Apps/Copy/copyEncode.sml + + moved Parser/Chars to Unicode/Chars. + - Changed the implementation of Decode and Encode: + + UTF-7 is no longer supported. + + new structure Encoding providing types and functions for handling + encoding names. + + both Encode and Decode now raise exceptions instead of printing errors. + + made the appropriate changes to Entities and CopyEncode. + +1999-03-08: + - Moved fillArray for Front to FrontEncoding, renamed it to encGetArray. + - Hid implem. of type FrontEncoding.Encoding through the signature. + +1999-03-05: + - Changed Front.fillArray to use a function parameter instead of a reference. + +1999-03-02: + - Changed all parser functors: + + expect only a structure Params containing former Hooks, Front, Dtd, + AuxParse and AuxRecover. + + No other parser structures are arguments to functors. + - Removed the functions from DtdTables from the Dtd signature. + - Renamed Dtd to AuxDtd and DtdTables to Dtd. + +1999-03-01: + - Added function hookWhite to signature Hooks. + - Added calls to hookWhite in ParseDtd.parseSubset and ParseDocument.parseDoc. + - Changed CopyHooks and CopyOutput to account for this: + + removed third bool arg from CopyOutput.outComment/ProcInstr; they never + print a newline now; + + removed printing of newlines from declaration hooks in CopyHooks; + + removed function CopyHooks.inContent; + + added hookWhite to CopyHooks; + - Added hookWhite to NullHooks and EsisHooks; + - Added LOC_SUBSET to datatype Location in ErrorData and ErrorString. + - Fixed ErrorMessage.errorMessage to print "Could not open file..." instead of + "Could open file..." for ERR_NO_SUCH_FILE. + diff --git a/fxp/COPYRIGHT b/fxp/COPYRIGHT new file mode 100644 index 0000000..13a0fdc --- /dev/null +++ b/fxp/COPYRIGHT @@ -0,0 +1,55 @@ + fxp: A Functional XML Parser + Version 2.0, 25.06.2004 + + ------------------------------------------------ + +COPYRIGHT NOTICE, LICENSE AND DISCLAIMER. + +Copyright 1999-2004 by Andreas Neumann and Alexandru Berlea, TU Munich + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both the copyright notice and this permission notice and warranty +disclaimer appear in supporting documentation. + +The TU Munich disclaims all warranties with regard to this +software, including all implied warranties of merchantability and +fitness. In no event shall the TU Munich be liable for any +special, indirect or consequential damages or any damages whatsoever +resulting from loss of use, data or profits, whether in an action of +contract, negligence or other tortious action, arising out of or in +connection with the use or performance of this software. + + ------------------------------------------------ + +This software was produced with the help of software, tools, and code +from SML of New Jersey. Therefore we repeat here the copyright notice +SML of New Jersey: + +STANDARD ML OF NEW JERSEY COPYRIGHT NOTICE, LICENSE AND DISCLAIMER. + +Copyright (c) 1989-1998 by Lucent Technologies + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both the copyright notice and this permission notice and warranty +disclaimer appear in supporting documentation, and that the name of +Lucent Technologies, Bell Labs or any Lucent entity not be used in +advertising or publicity pertaining to distribution of the software +without specific, written prior permission. + +Lucent disclaims all warranties with regard to this software, +including all implied warranties of merchantability and fitness. In no +event shall Lucent be liable for any special, indirect or +consequential damages or any damages whatsoever resulting from loss of +use, data or profits, whether in an action of contract, negligence or +other tortious action, arising out of or in connection with the use +or performance of this software. + + ------------------------------------------------ + + + + diff --git a/fxp/Makefile b/fxp/Makefile new file mode 100644 index 0000000..b5c1e5e --- /dev/null +++ b/fxp/Makefile @@ -0,0 +1,146 @@ +############################################################################## +# These are the programs to be installed (fxlib is the library). +############################################################################## +INSTALL_PROGS = fxp fxcanon fxcopy fxesis fxviz fxlib + +############################################################################## +# These are the locations for executables, heap images and library files +############################################################################## +PREFIX = /cygdrive/d/xml +FXP_BINDIR = ${PREFIX}/bin +FXP_LIBDIR = ${PREFIX}/fxp + +############################################################################## +# The path where the SML-NJ binaries are located, and the name of the +# SML-NJ executable with the Compilation manager built-in. If sml is in +# your PATH at execution time, you fon't need the full path here. +############################################################################## +SML_BINDIR = /cygdrive/d/smlnj-110.43/bin +SML_EXEC = ${SML_BINDIR}/sml +############################################################################## +# No need to change this for SML-NJ 110.0.6. For earlier or working versions +# 110.19 you might have to use the second or third line. This is the +# compilation manager function for making with a named description file. +############################################################################## +#SML_MAKEDEF= val make = CM.make' +SML_MAKEDEF= val make = CM.make +#SML_MAKEDEF= fun make x = CM.make'{force_relink=true, group=x} + +############################################################################## +# These should be fine on most unix machines +############################################################################## +SED = sed +RM = rm -f +RMDIR = rmdir +COPY = cp -f +CHMOD = chmod +FIND = find +#buggy in cygwin +#MKDIRHIER = mkdirhier +MKDIRHIER = mkdir -p + +############################################################################## +# nothing to change below this line +############################################################################## +SRC = src +DOC = doc +FXLIB_PRUNE = \( -name CM -o -name CVS -o -name Apps \) + +all: fxp.sh images + +arch.os: + if test -s ${SML_BINDIR}/.arch-n-opsys; then\ + ${SML_BINDIR}/.arch-n-opsys | \ + ${SED} -e 's/^.*HEAP_SUFFIX=\(.*\)$$/\1/' > .arch-opsys;\ + else \ + echo "ARCH=x86; OPSYS=win32; HEAP_SUFFIX=x86-win32" | \ + ${SED} -e 's/^.*HEAP_SUFFIX=\(.*\)$$/\1/' > .arch-opsys;\ + fi + +fxp.sh: Makefile arch.os + ${RM} fxp.sh + echo "#!/bin/sh -f" > fxp.sh + echo >> fxp.sh + echo "SML_BINDIR=${SML_BINDIR}" >> fxp.sh + echo "FXP_LIBDIR=${FXP_LIBDIR}" >> fxp.sh + cat fxp.sh.in >> fxp.sh + +image.prog: + @echo "Creating the ${PROG_NAME} heap image..." + echo "${SML_MAKEDEF}; make \"${SRC}/${PROG_CM}\"; \ + SMLofNJ.exportFn(\"${SRC}/_${PROG_NAME}\",${PROG_FUN})" | ${SML_EXEC} + +image.fxlib: +image.fxp: + @make image.prog PROG_NAME=fxp PROG_CM=Apps/Null/null.cm PROG_FUN=Null.null +image.fxcanon: + @make image.prog PROG_NAME=fxcanon PROG_CM=Apps/Canon/canon.cm PROG_FUN=Canon.canon +image.fxcopy: + @make image.prog PROG_NAME=fxcopy PROG_CM=Apps/Copy/copy.cm PROG_FUN=Copy.copy +image.fxesis: + @make image.prog PROG_NAME=fxesis PROG_CM=Apps/Esis/esis.cm PROG_FUN=Esis.esis +image.fxviz: + @make image.prog PROG_NAME=fxviz PROG_CM=Apps/Viz/viz.cm PROG_FUN=Viz.viz + +images: + for prog in ${INSTALL_PROGS}; do \ + make image.$${prog}; \ + done + +inst.dirs: + test -d ${FXP_BINDIR} || ${MKDIRHIER} ${FXP_BINDIR} + test -d ${FXP_LIBDIR} || ${MKDIRHIER} ${FXP_LIBDIR} + +inst.prog: inst.dirs fxp.sh arch.os + ${RM} ${FXP_BINDIR}/${PROG_NAME} ${FXP_BINDIR}/fxp.sh \ + ${FXP_LIBDIR}/_${PROG_NAME}.`cat .arch-opsys` + ${COPY} fxp.sh ${FXP_BINDIR} + ${CHMOD} 755 ${FXP_BINDIR}/fxp.sh + ln -s fxp.sh ${FXP_BINDIR}/${PROG_NAME} + ${COPY} ${SRC}/_${PROG_NAME}.`cat .arch-opsys` ${FXP_LIBDIR} + ${CHMOD} 644 ${FXP_LIBDIR}/_${PROG_NAME}.`cat .arch-opsys` + +inst.fxp: + @make inst.prog PROG_NAME=fxp PROG_CM=Apps/Null/null.cm PROG_FUN=Null.null +inst.fxcanon: + @make inst.prog PROG_NAME=fxcanon PROG_CM=Apps/Canon/canon.cm PROG_FUN=Canon.canon +inst.fxcopy: + @make inst.prog PROG_NAME=fxcopy PROG_CM=Apps/Copy/copy.cm PROG_FUN=Copy.copy +inst.fxesis: + @make inst.prog PROG_NAME=fxesis PROG_CM=Apps/Esis/esis.cm PROG_FUN=Esis.esis +inst.fxviz: + @make inst.prog PROG_NAME=fxviz PROG_CM=Apps/Viz/viz.cm PROG_FUN=Viz.viz + +inst.fxlib: + for dir in `${FIND} ${SRC} ${FXLIB_PRUNE} -prune -o -type d -print`; do \ + ${MKDIRHIER} ${FXP_LIBDIR}/$${dir}; \ + done + for file in `${FIND} ${SRC} ${FXLIB_PRUNE} -prune -o -name '*.sml' -print`; do \ + ${COPY} $${file} ${FXP_LIBDIR}/$${file}; \ + done + ${COPY} ${SRC}/fxlib.cm ${FXP_LIBDIR}/${SRC}/fxlib.cm + rm -f ${FXP_LIBDIR}/fxlib.cm + echo Group is > ${FXP_LIBDIR}/fxlib.cm + echo " "${SRC}/fxlib.cm >> ${FXP_LIBDIR}/fxlib.cm + ${COPY} -r ${DOC} ${FXP_LIBDIR} + +install: + for prog in ${INSTALL_PROGS}; do \ + make inst.$${prog}; \ + done + +uninstall: arch.os + -for prog in ${INSTALL_PROGRAMS}; do \ + if [ "$${prog}" == "fxlib" ]; then \ + ${RM} -r ${FXP_LIBDIR/src}; \ + else \ + ${RM} ${FXP_BINDIR}/$${prog}; \ + ${RM} ${FXP_LIBDIR}/_$${prog}.`cat .arch-opsys`; \ + fi; \ + done + -${RM} ${FXP_BINDIR}/fxp.sh + -${RMDIR} ${FXP_BINDIR} ${FXP_LIBDIR} + +clean: + -${RM} -f ${SRC}/_fx.* fxp.sh .arch-opsys + -find ${SRC} -type d -name CM -print | xargs ${RM} -r diff --git a/fxp/README b/fxp/README new file mode 100644 index 0000000..8fb61a9 --- /dev/null +++ b/fxp/README @@ -0,0 +1,133 @@ +fxp - The Functional XML Parser +Version 2.0, 25.06.2004 + +by + Andreas Neumann, University of Trier + neumann (AT) psi.uni-trier.de + Alexandru Berlea, TU Munich + berlea (AT) in.tum.de + +What is fxp? +------------ +fxp is a validating XML parser, written completely in the functional +programming language SML. It has a programming interface +allowing for production of XML applications based on fxp. It comes with +some example applications: + + fxp The pure parser. It parses a document and finds well-formedness + errors, validity errors and other problems; + + fxcanon Produces an equivalent canonical XML document. Canonical XML was + invented by James Clark for testing XML parsers. It contains only + the information a processor is required to pass to the application; + + fxcopy Reproduces the document parsed by fxp. The copy can be generated + in a different encoding than the input, and can be normalized in + different ways concerning, e.g., expansion of entity references; + + fxesis Produces an output similar to nsgmls's ESIS (Element Structure + Information Set) output; + + fxviz An XML tree visualizer. It produces a graph description suitable as + input to Georg Sander's vcg. + +Homepage +-------- + http://www.informatik.uni-trier.de/~berlea/Fxp + + +Installation +------------ + +In order to install fxp, you need an SML compiler. It has been tested with +version 110.0.7 of SML of New Jersey, but it might also run with other +versions. The compiler must have the compilation manager (CM) built in, which +is the default when installing SML-NJ. We successfully compiled fxp on +Linux. For other unices we expect no problems. An installation using the +Windows version of SML-NJ is documented on fxp's homepage. + + +These are the steps for installing fxp under Unix: + + 1. Download the latest version of fxp; + 2. Unpack the sources, and change to the fxp directory, e.g.: + + gunzip -c fxp-2.0.tar.gz | tar xf - + cd fxp-2.0 + + 3. Read the COPYRIGHT; + 4. Edit the Makefile according to your needs. Probably you will only have + to change the following: + + INSTALL_PROGS is the list of programs to be installed. fxlib is only + required if you want to develop applications with fxp. + + FXP_BINDIR is where the executables are installed; + + FXP_LIBDIR is where other files needed by fxp - the heap images + and the library - are installed; + + SML_BINDIR is the directory where the SML executables are found. + It must contain the .arch-n-opsys script from the + SML-NJ distribution, so make sure that this is where + SML-NJ is physically installed; + + SML_EXEC is the name of the SML executable. This is the program + that is called for generating the heap image and at + execution of fxp. If sml is in your PATH at + installation time, you don't need the full path here. + + SML_MAKEDEF is for defining the make command in SML. After version + 110.0.3, SML-NJ changed the type of CM.make'. + For earlier or working versions of SML-NJ, use the + second or third variant of this definition. + + 5. Edit the file src/config.sml according to your needs. Currently only a + single value can be configured here: + + val retrieveCommand : string + + is the command to be used by fxp for retrieving a remote URI from + the internet and storing it in a temporary file on the local file + system. It is a string value and should contain the strings %1 + and %2, where: + + - %1 is replaced by the URI; + - %2 is replaced by the local filename. + + It is recommended that the command exits with failure in case the + URI cannot be retrieved. If the command generates an HTML error + message instead (like, e.g., "lynx -source %1 > %2"), this HTML + file is considered to be XML and will probably cause a mess of + parsing errors. If you don't need URI retrieval, use "exit 1" + which always fails on Unix. Sensible values are, e.g: + + - "wget -qO %2 %1" + (ftp://gnjilux.cc.fer.hr/pub/unix/util/wget/) + - "got_it -o %2 %1" + (ftp://sunsite.unc.edu/pub/Linux/apps/www/ + mirroring/got_it-0.34.tar.gz) + - "urlget -s -o %2 %1" + (ftp://sunsite.unc.edu/pub/Linux/apps/www/ + mirroring/urlget-3.12.tar.gz) + + 6. Compile fxp by typing make; + 7. Install fxp by typing make install. + 8. If you want to use fxviz, you should also install vcg + (ftp://ftp.cs.uni-sb.de/pub/graphics/vcg/). + +If you experience problems installing fxp, send me mail at berlea (AT) +in.tum.de Check out for new versions at +http://www.informatik.tu-muenchen.de/~berlea/Fxp. + +Running the Parser +------------------ +Sample applications like fxp (a validating XML parser), fxcanon, fxcopy, +fxesis, and fxviz are described on fxp's homepage. + +Programming Interface +--------------------- +fxt's API is described in api.ps. + + +Alexandru Berlea \ No newline at end of file diff --git a/fxp/doc/CHANGES b/fxp/doc/CHANGES new file mode 100644 index 0000000..12721cc --- /dev/null +++ b/fxp/doc/CHANGES @@ -0,0 +1,339 @@ +From 1.4.6 to 2.0 +--------------------------- +(25.06.2004) + +Added support for XML 1.1 (Entities.getChar, UniClasses.isNms/isName/isXml +have now an 11 (for 1.1) counterpart which are to be called when the XML +declaration declares version 1.1. + +Changed Makefile to better support Windows installation. + +(13.02.2004) +Updated fxp to handle the new specification of the xml:space attribute + +From 1.4.5 to 1.4.6 +--------------------------- +(09.10.2003) +Modified documentation to fit in the fxgrep gui framework + +From 1.4.4 to 1.4.5 +--------------------------- +(20.02.2002) +Modified the Makefiles to avoid unnecessary recompilations +2001-09-17 + - added hasElement, hasAttribute, etc. functions in Dtd + +Changes from 1.4.3 to 1.4.4 +--------------------------- +2000-10-30 + - fixed a bug : parser reported an error if more than one definition + was provided for the same ID attribute, instead of ignoring + delarations later than the first one + +Changes from 1.4.2 to 1.4.3 +--------------------------- +2000-08-29: + - modified the autodetection of character encodings as stated in the + XML 1.0 Specification Errata from 2000-08-10 under E 44; among + others, UTF-8 with BOM is now recognized. + +Changes from 1.4.1 to 1.4.2: +-------------------------- +2000-07-28: + - fixed a Solaris bug in the Makefile + +Changes from 1.4 to 1.4.1: +-------------------------- +2000-06-08: + - fixed a bug in surrogate composition + - fixed a bug: parser complained about undeclared entities in + non-validating mode, even if the DTD has paramter references. + - fixed another bug: parser never complained about undeclared + parameter entities that constitute a validity error. + - slightly restructured ParseRefs; resulting in some minor + changes in other modules. + - modified sample applications to report fatal errors as fatal. + +Changes from 1.3 to 1.4: +------------------------ +2000-02-18: + - fixed a bug in UtilCompare.compareVector + - eliminated UnsafeOps structure. Unsafe operations yield only + insignificant speedup, but extremely impair reliability. + +2000-02-10: + - parseElementContent reports only a single error for each piece + of character data in element content. Before this change, it did + report an error after each sequence of white space characters + followed by non-white space. Similarly for parseDocument. + +1999-10-22: + - Added the start position of the PI text to HookData.ProcInstInfo. + +1999-10-18: + - Fixed a small bug in UtilHash.hashTriple + +1999-08-27: + - Removed the this/next components from the Entities.State type. + It is sufficient to compare the entity's indices in the DTD. + Added a type EntId, indicating whether an entity is a parameter + or general entity, and holding its index. isOpen, pushIntern and + pushExtern now have an additional parameter isParam:bool. Changed + all parser functions accordingly. + +Changes from 1.2 to 1.3: +------------------------ +1999-08-24: + - Removed options --table-size/width. + - added new encoding UCS2B/L, which is UTF16 without surrogate pairs. + - unrolled the getBytes loop in getCharUtf8. UTF-8 does not recognize + surrogates pairs any more (cf. Rfc 2279, lines 201-206). The same + for UCS-4. + - changed implementation getCharUtf16/getCharUcs4: they are not higher + order any more. Efficiency increased. + +1999-08-13: + - Changed ParseDecl.parseGenEntDecl not to check for declaredness of + unparsed entities' notations. + - Added maxUsedGen to Dtd: returns the number of general entities defined. + - Added checkUnparsed to DtdDeclare. It checks whether all notations of + unparsed entities have been declared. Added a call to checkUnparsed + at the end of parseDtd. + +1999-08-12: + - Made DecodeUtf8.byte1switch a vector. + - Changed type CharClasses.CharClass to a vector. Arrays are now only + used for initializing the char classes; for lookup, they must be + finalized to a vector. + +1999-08-03: + - Restructered the Dtd[Elements|Attributes|Notations|Entities] modules. + There are now two modules: DtdDeclare for operations concerning + declarations, and DtdAttributes for generating attribute values. + - Renamed AuxDtd to DtdManager. + - Renamed some functions from Entities to shorter names. + - Changed ParseDocument.parseDoc not to set O_VALIDATE to false if there + is no DTD. Instead those functions that would produce too many errors + without a DTD call hasDtd in order to find out whether there is one. + - Changed the error message for ERR_NO_DTD. + +1999-07-29: + - Fixed a bug in the ParseContent.parseElementContent: character + references were passed to the application instead of reporting + an error. + - Removed ERR_DATA_IN_ELEM and ERR_CDATA_IN_ELEM; added ERR_ELEM_CONTENT + instead, which does the job for data, CDATA sections and charrefs. + - Added a boolean flag to HookData.DataInfo,indicating whether the + data is whitespace in element content. This information was available + only implicitly by the content spec of the parent element. + +1999-07-26: + - Fixed a bug in the decoder and encoder, concerning surrogates: the + offset added/subtracted in combine/splitSurrogates was 0wx10000 + instead of 0wx100000. + - DecodeUtil.isSurrogate ignored the high surrogates: fixed that. + +1999-07-22: + - Renamed DecodeBasic to DecodeFile. Changes getByte such that it + closes the file (and removes it if temporary) before raising EndOfFile. + +1999-07-20: + - Reimplemented the Uri structure to use strings for uris. (They may + only contain ASCII characters). Changed the result type of uriSuffix + to string. + - Moved the URI encoding functions to a new structure UriEncode. + A character "%" is only encoded if not followed by two hex digits. + Removed URI decoding, since that is superfluous. + - Added parser option O_WARN_NON_ASCII_URI. Changed + ParseLiterals.parseSystemLiteral to issue a warning if a non-ASCII + character occurs. Added a corresponding command line option + --warn-uri. + - Removed types CharInterval and CharRange from structure UniChar. + Added them to CharClasses, used only in Naming and NameClasses. + - Renamed type UniChar.CharVector to Vector for brevity. + - Renamed structures NameRanges and Naming to UniRanges and UniClasses. + +1999-07-19: + - Renamed structure Chars to UniChar. Changed definitions such that + UniChar provides a structure Chars : WORD such that type Char = + Chars.word; + - Moved type Byte to DecodeBasic such that DecodeBasic provides a + structure Bytes : WORD such that type Byte = Chars.word; + - Changed other structures to use UniChar.Char and DecodeBasic.Bytes + instead of hardwired Word and Word8. + +1999-07-14: + - Changed the DTD structure. The DTD is not a bunch of global variables + anymore; it is now a single data structure handed as argument to all + DTD functions. It must therefore be passed around through all DTD- + dependent parts of the parser and of all applications. + + Removed O_INIT_DTD option. Instead, the parser expects an optional + DTD as argument. If that is NONE, a new DTD data structure is + initialized, otherwise tghe provided one is used. + + Changed all applications to pass the DTD around. + - Changed functions ParseMisc.skipS and ParseRefs.skipPS. Instead of + raising NotFound on error, they call the hookError function themselves. + +Changes from 1.1 to 1.2: +------------------------ +1999-06-07: + - Replaced the --error-minimize option by --few-errors[=(yes|no)]. + The old option was buggy and could only turn on an feature that + was on by default. + +1999-06-04: + - Removed option --no-output/-n from fxesis and fxcopy. + - Modified the main functions of all applications: in case of + option errors, they raise now raise exception Exit instead + of calling OS.Process.exit. + - Added support for remote URIs. + + In structure Config, value retrieveCommand defines a command + to be executed for URI retrieval. + + Uri.retrieveUri calls this command for storing the entity + in a local file. It returns the name of the file and a flag + indicating whether a temporary file has actually been created + or the URI was local. + + DecodeBasic.FILE has this boolean as additional parameter. + Function decClose removes the temp. file if the flag is true. + +1999-05-10: + - Added new type AppFinal to HookData signature. hookFinish now + returns a value of type AppFinal. This is also the new type of + ParseDocument.parseDocument's result. + +1999-05-03: + - Added support for XML syntax of XML Catalogs. + + new function Uri.uriSuffix. Depending on the suffix of a URI, + catalogs are parsed in Socat syntax (.soc, .SOC) or XML syntax. + +1999-04-23: + - Fixed bug: Dict.getByKey raised NoSuchEntry for unknown keys. + That made fxp fail with an uncaught exception if, e.g., an + unknown output encoding was given. + +1999-04-15: + - Added functions Dict.clearDict and SymTable.clearSymTable. + - Removed references from the tables in Dtd. The Tables are now + initialized with clearDict/SymTable. + +1999-04-14: + - Moved Hooks, HookData, Dtd, DtdOptions, Resolve and ParserOptions + to directory Params. Deleted directory Hooks. + - Added the start and end position to the arguments of most of the Hooks. + Made the appropriate changes in the parser modules and the apps. + - The parser is now reentrant, i.e., multiple instances are possible + at the same time. + - Made Dfa a functor, expecting the Dfa-relevant options in a + structure DfaOptions. Added a new functor for creating such a + structure. + - Made ParserOptions a functor in order to have multiple instances + of it. ParserOptions creates DfaOptions as a substructure. + +1999-04-13: + - Made Dtd a functor, expecting a structure DtdOptions holding all options + concerning the DTD. Removed these options from ParseOptions. + - Removed O_SILENT, O_ERROR_DEVICE and O_ERROR_LINEWIDTH from ParseOptions. + These options now belong to the application. + - Fixed some bugs in the option parsers of applications. + - Fixed a bug in Dfa: exception DfaTooLarge was not visible through the + signature. + - Added an integer parameter to exceptions DfaToLarge and to + WARN_DFA_TOO_LARGE. It is the maximal allowed number of states. + - ErrorMessage no longer depends on ParseOptions. + +Changes from 1.0 to 1.1: +------------------------ +1999-03-29: + - Fixed ErrorMessage.errorMessage to complain about standalone 'yes' instead + of 'no'. + - Avoid multiple EndOfFile events for the same entity by adding a boolean + flag to DecodeError/Bytes exceptions. + +1999-03-25: + - Improved error reporting; the position handed to hookError/Warning is now + - whenever possible - the first character of the concerned item. + Exceptions are checks done at the end of the DTD or of the document. + - Improved handling of wrong end-tags. The strategy is: + + if the end-tag is for the current element, consume it and finish the + element; + + otherwise, if it is for an open element, assume the end-tag for the + current element was forgotten, i.e., finish the current element but + retain the end-tag; + + otherwise, if the current element requires further content in order + to satisfy its content model, ignore the end-tag; + + otherwise consumne the end-tag and finish the current element. + In order to implement this, the following were necessary: + + an extra argument openElems to ParseContent.parseElement. It is a list + of the indices of the types of the enclosing elements; + + an extra component optEtag in the return vale of parseElement. It is an + option and holds information about an end-tag that was not consumed when + finishing the element; + + appropriate changes to the code of parse[Mixed|Element]Content. + +1999-03-24: + - fixed some bugs: + + comparison of fixed attribute values is now correct. + + Naming.isUnicode: 0x10000..0xFFFFF was not unicode. + + ParseContent.parseMixedContent complained about character '>' even if + it was not part of the sequence ']]>'. + + whitespace normalization in attribute values also affected characters + that were escaped by a char reference. + + end-of-line normalization was done for the replacement text of internal + entities, but may only be done for the literal entitiy values. + + default values in attlist declarations were checked not only for lexical + validity but also for declaredness of notation/entity names. This is now + done when the default value is used. + +1999-03-22: + - Added support for the Socat syntax of XCatalog: + + new subdir Catalog with a main functor Catalog + + the parser functor now expects an additional structure argument Resolve + providing a function resolveExtId. That does not exist in BaseData any + more. + +1999-03-16: + - Extracted Unicode-specific code from the Parser: + + made a new directory Unicode. + + moved Parser/Front/front.sml to Parser/entities.sml; renamed Front to + Entities. + + moved Parser/Front to Unicode/Decode; renamed everything to Decode<...>, + frontEncoding to Encode. + + moved Parser/Back to Unicode/Encode; renamed everything to Encode<...>, + backEncoding to Encode; moved back.sml to Apps/Copy/copyEncode.sml + + moved Parser/Chars to Unicode/Chars. + - Changed the implementation of Decode and Encode: + + UTF-7 is no longer supported. + + new structure Encoding providing types and functions for handling + encoding names. + + both Encode and Decode now raise exceptions instead of printing errors. + + made the appropriate changes to Entities and CopyEncode. + +1999-03-08: + - Moved fillArray for Front to FrontEncoding, renamed it to encGetArray. + - Hid implem. of type FrontEncoding.Encoding through the signature. + +1999-03-05: + - Changed Front.fillArray to use a function parameter instead of a reference. + +1999-03-02: + - Changed all parser functors: + + expect only a structure Params containing former Hooks, Front, Dtd, + AuxParse and AuxRecover. + + No other parser structures are arguments to functors. + - Removed the functions from DtdTables from the Dtd signature. + - Renamed Dtd to AuxDtd and DtdTables to Dtd. + +1999-03-01: + - Added function hookWhite to signature Hooks. + - Added calls to hookWhite in ParseDtd.parseSubset and ParseDocument.parseDoc. + - Changed CopyHooks and CopyOutput to account for this: + + removed third bool arg from CopyOutput.outComment/ProcInstr; they never + print a newline now; + + removed printing of newlines from declaration hooks in CopyHooks; + + removed function CopyHooks.inContent; + + added hookWhite to CopyHooks; + - Added hookWhite to NullHooks and EsisHooks; + - Added LOC_SUBSET to datatype Location in ErrorData and ErrorString. + - Fixed ErrorMessage.errorMessage to print "Could not open file..." instead of + "Could open file..." for ERR_NO_SUCH_FILE. + diff --git a/fxp/doc/COPYRIGHT b/fxp/doc/COPYRIGHT new file mode 100644 index 0000000..13a0fdc --- /dev/null +++ b/fxp/doc/COPYRIGHT @@ -0,0 +1,55 @@ + fxp: A Functional XML Parser + Version 2.0, 25.06.2004 + + ------------------------------------------------ + +COPYRIGHT NOTICE, LICENSE AND DISCLAIMER. + +Copyright 1999-2004 by Andreas Neumann and Alexandru Berlea, TU Munich + +Permission to use, copy, modify, and distribute this software and +its documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both the copyright notice and this permission notice and warranty +disclaimer appear in supporting documentation. + +The TU Munich disclaims all warranties with regard to this +software, including all implied warranties of merchantability and +fitness. In no event shall the TU Munich be liable for any +special, indirect or consequential damages or any damages whatsoever +resulting from loss of use, data or profits, whether in an action of +contract, negligence or other tortious action, arising out of or in +connection with the use or performance of this software. + + ------------------------------------------------ + +This software was produced with the help of software, tools, and code +from SML of New Jersey. Therefore we repeat here the copyright notice +SML of New Jersey: + +STANDARD ML OF NEW JERSEY COPYRIGHT NOTICE, LICENSE AND DISCLAIMER. + +Copyright (c) 1989-1998 by Lucent Technologies + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both the copyright notice and this permission notice and warranty +disclaimer appear in supporting documentation, and that the name of +Lucent Technologies, Bell Labs or any Lucent entity not be used in +advertising or publicity pertaining to distribution of the software +without specific, written prior permission. + +Lucent disclaims all warranties with regard to this software, +including all implied warranties of merchantability and fitness. In no +event shall Lucent be liable for any special, indirect or +consequential damages or any damages whatsoever resulting from loss of +use, data or profits, whether in an action of contract, negligence or +other tortious action, arising out of or in connection with the use +or performance of this software. + + ------------------------------------------------ + + + + diff --git a/fxp/doc/Examples/exa-1.ext b/fxp/doc/Examples/exa-1.ext new file mode 100644 index 0000000..5ff96b1 --- /dev/null +++ b/fxp/doc/Examples/exa-1.ext @@ -0,0 +1,2 @@ + + diff --git a/fxp/doc/Examples/exa-1.xml b/fxp/doc/Examples/exa-1.xml new file mode 100644 index 0000000..db3b0f1 --- /dev/null +++ b/fxp/doc/Examples/exa-1.xml @@ -0,0 +1,22 @@ + + + + + + + +%ext; + + + +]> + + + + +&ext; + + + diff --git a/fxp/doc/Examples/exa-2.xml b/fxp/doc/Examples/exa-2.xml new file mode 100644 index 0000000..2a82819 --- /dev/null +++ b/fxp/doc/Examples/exa-2.xml @@ -0,0 +1,15 @@ + + + + +]> + + + + + +this element contains a "]]>" sequence + + diff --git a/fxp/doc/Examples/exa-3.xml b/fxp/doc/Examples/exa-3.xml new file mode 100644 index 0000000..ea3a48a --- /dev/null +++ b/fxp/doc/Examples/exa-3.xml @@ -0,0 +1,15 @@ + + + + + + +]> + + + + + diff --git a/fxp/doc/Examples/exa-4.xml b/fxp/doc/Examples/exa-4.xml new file mode 100644 index 0000000..533f238 --- /dev/null +++ b/fxp/doc/Examples/exa-4.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + +]> + + + + diff --git a/fxp/doc/Examples/exa-5.esis-7 b/fxp/doc/Examples/exa-5.esis-7 new file mode 100644 index 0000000..074f05e --- /dev/null +++ b/fxp/doc/Examples/exa-5.esis-7 @@ -0,0 +1,28 @@ + +(exa +-\n +pBSD//A Program for viewing text//EN +s/bin/cat +Ntext +Anot NOTATION text +Abold TOKEN no +Aid TOKEN first-a +s/usr/bin/nroff +Nman +s/usr/man/man1/fxp.1 +f/usr/man/man1/fxp.1 +Efxp.manpage NDATA man +Aent ENTITY fxp.manpage +Aref CDATA www.fxp.org +(a +-\nThere is a comment in this line.\nThis line has a character reference and \nthis one has a "quoted general entity reference". \n\nthis is a cdata section!\n +?see this pi? +-\n +)a +-\n +Abold TOKEN no +Anot NOTATION man +(a +-\nEr wohnt in K\U+f6;ln, in der M\U+fc;llerstra\U+df;e 13.\n +)a +)exa diff --git a/fxp/doc/Examples/exa-5.esis-8 b/fxp/doc/Examples/exa-5.esis-8 new file mode 100644 index 0000000..7374ee3 --- /dev/null +++ b/fxp/doc/Examples/exa-5.esis-8 @@ -0,0 +1,33 @@ + +(exa +-\n +Aref CDATA www.fxp.org +Anum IMPLIED +s/usr/bin/nroff +Nman +s/usr/man/man1/fxp.1 +f/usr/man/man1/fxp.1 +Efxp.manpage NDATA man +Aent ENTITY fxp.manpage +pBSD//A Program for viewing text//EN +s/bin/cat +Ntext +Anot NOTATION text +Aid TOKEN first-a +Abold TOKEN no +(a +-\nThere is a comment in this line.\nThis line has a character reference and \nthis one has a "quoted general entity reference". \n\nthis is a cdata section!\n +?see this pi? +-\n +)a +-\n +Aref IMPLIED +Anum IMPLIED +Aent IMPLIED +Anot NOTATION man +Aid IMPLIED +Abold TOKEN no +(a +-\nEr wohnt in Köln, in der Müllerstraße 13.\n +)a +)exa diff --git a/fxp/doc/Examples/exa-5.xml b/fxp/doc/Examples/exa-5.xml new file mode 100644 index 0000000..b8a55bb --- /dev/null +++ b/fxp/doc/Examples/exa-5.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + +]> + + + +There is a comment in this line. +This line has a character reference and +this one has a "quoted general entity reference". + + + + + +Er wohnt in Köln, in der Müllerstraße 13. + diff --git a/fxp/doc/Examples/exa-6.ext b/fxp/doc/Examples/exa-6.ext new file mode 100644 index 0000000..96c3cac --- /dev/null +++ b/fxp/doc/Examples/exa-6.ext @@ -0,0 +1,2 @@ + + diff --git a/fxp/doc/Examples/exa-6.xml b/fxp/doc/Examples/exa-6.xml new file mode 100644 index 0000000..e5db0b5 --- /dev/null +++ b/fxp/doc/Examples/exa-6.xml @@ -0,0 +1,8 @@ + +"> + +%int; +%ext; +]> + diff --git a/fxp/doc/Examples/exa-exp.xml b/fxp/doc/Examples/exa-exp.xml new file mode 100644 index 0000000..6f3919e --- /dev/null +++ b/fxp/doc/Examples/exa-exp.xml @@ -0,0 +1,12 @@ + + + + +]> + +here is a character reference: @ +here is an ∫ +here is an &ext; + diff --git a/fxp/doc/Examples/ext-6.decl b/fxp/doc/Examples/ext-6.decl new file mode 100644 index 0000000..e22e08a --- /dev/null +++ b/fxp/doc/Examples/ext-6.decl @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/fxp/doc/Examples/ext.decl b/fxp/doc/Examples/ext.decl new file mode 100644 index 0000000..506117c --- /dev/null +++ b/fxp/doc/Examples/ext.decl @@ -0,0 +1 @@ + diff --git a/fxp/doc/Examples/ext.elem b/fxp/doc/Examples/ext.elem new file mode 100644 index 0000000..4cb11fb --- /dev/null +++ b/fxp/doc/Examples/ext.elem @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/fxp/doc/Examples/ext.ent b/fxp/doc/Examples/ext.ent new file mode 100644 index 0000000..5251779 --- /dev/null +++ b/fxp/doc/Examples/ext.ent @@ -0,0 +1 @@ +external entity diff --git a/fxp/doc/Examples/xmlcat.dtd b/fxp/doc/Examples/xmlcat.dtd new file mode 100644 index 0000000..8732672 --- /dev/null +++ b/fxp/doc/Examples/xmlcat.dtd @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + diff --git a/fxp/doc/Images/ball-shadow.jpg b/fxp/doc/Images/ball-shadow.jpg new file mode 100644 index 0000000000000000000000000000000000000000..54e3c7941fd7923a1fe51562b3be1b9a3b989e56 GIT binary patch literal 494 zcmex=^(PF6}rMnOeST|r4lSw=>~TvNxu(8R<bIbPXRz2H8$!it$JbX0%Gbr@6%B~FVQc<;3W=OX!Jh75jdrhv? zu`4sbZI|IVcXi7rGhOx%?(V-hWj`NWReWle)rY->1v^&$T)8oprPO9d?%KPjauuyZ zT7FA=HBB-6Ch?ZFdc40Q???fqnSfDeV7m0ssrHgjWCn literal 0 HcmV?d00001 diff --git a/fxp/doc/Images/email.png b/fxp/doc/Images/email.png new file mode 100644 index 0000000000000000000000000000000000000000..6965ff1c81b1ebd2381f4e3711b3d86cee0b2321 GIT binary patch literal 411 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 +qjR#xQ-jS6eqcq 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 etHCl|lrtCKyyiI9${{R30EC2ui0NVl{ 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 literal 0 HcmV?d00001 diff --git a/fxp/doc/Images/exa-vcg-3.gif b/fxp/doc/Images/exa-vcg-3.gif new file mode 100644 index 0000000000000000000000000000000000000000..34627a20fd3abdd823a4a368965cea2d6dfeeb4c GIT binary patch literal 2241 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 literal 0 HcmV?d00001 diff --git a/fxp/doc/Images/exa-vcg-5.gif b/fxp/doc/Images/exa-vcg-5.gif new file mode 100644 index 0000000000000000000000000000000000000000..63b4a42309d9c0734d09bff1a6a7218acb6195a1 GIT binary patch literal 4503 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 z gE37vzCLP z8J@r;bR0^Y#ujqtS(@G%mJKSHoOzuUs-F^PKK_Y%%(ci-CYH2mq+#lwBU+VY%An2ZB!ww*JF1~6lx7RrrNpL&=gX{eA|s(Nv%i*%N0#;B|MsL0``N!F>=kg6fMsPf2<2EiG|2ap3P zkjz(_z#6Re_>aIDkYeDhVE9bo7_HJ8kJS2~)_SehG_BftOx)V7!}P7-`b*+EuDevO z=6Xx$ny$07uIw61?)t8-6tD8SO7vQs>GYGRl{+n4dJG3&p3r5SbMVqvp#IsCG zT+Q&bqU5wvdsjmlBM73mV6J~q14Ux8LTMlg7w%+iz za9dbWJGU>WwRX#YU7NSbHMV>UwKws%i6pmz`;I16xH!AFh#OFfySU8MxQ^>ckQ=#r zt$D#F3Z+ZA!5r*q?%TXJ+`#rr5eAII^=rZq48ADr zrhAE>}*y*TU5jQ?O5a%5?qXqt&^>%MR-Yci|ecy{D`@BhD=2uLg%d%~o0 z`Jyq8(9#Z2s9LYstai)odcWYXcuX#v6-27@>ucnWA#_rO#pNJ;CcS;1pG(P&A>PM$SEA6>>Ro@u(aT_XX{-)dKBAD1jGKo z%7ZE$FKtZNVw*vO3*eaKc92d>f+>M9I2niJ!kgwC2C&Ic6UL0PEP{jw)Y3*w>*^`> zh*V;_WHo8B8R+k2!K(sgN-b9N>CLYt8|vKYHA%#aKZ{O^Cv@UbwfAzxo13=4+cWUW zzG``p>Q=0P0c!PwP^Dh5h}DSI$#Vogw{X{9u{bhQNRSIKQ-PKF?Bxa?Gk+1S`K&~= zLs8qcOz-fFzAg(Rj5(FIoCYYZ&ZaukW$$pde-qBl+jeY~vlA=-kdy4yapieDTRx-+WG`=pA(zG6&m(0Mg`NR0ATIRgnQQD4>x{D#@gSL_#Q`a?KfH zVTAikcjI+BT1V8E>A5%}jv|s-;$x?YlxCPQzQ`qZHgXgvm}br?S!?($DO-@k4XNjk zM>bhtRZ%K9B%wt@xu=v z>X@Te8zX%*!l8zUu1Kiqst7=%Vwq8Oap0Q!Y%a>u>2-lTy?2hZ_Zv5TGabLk{ z>~TL7&x>EN$_$%wPx)#~iFGN8d2PZ2!y<5GJomif%Z>#$E@1GoBoojo3p*Bc`1%aZ z&Q3?|Gq5WO-7!p9CmIT{No(`mIaF^b^(0V_Z8lJ0TMa8#MIT)?C|q}a?AObLeRf62 z-mN!9X{+69L2dh;F4A&4vou*v?~O^>iZ>2T--1UjIoyQ)7rxKob~|nfBU5GFl`G~sC7iGB`pl`nJ^JjU$6Y#xbTbpX*sr@2#qYoee*%8O7jL`~x2Lj# zI>$G!z!c6$FZ~h3PjCJ86(oO(6Ukr?`~ljBFaG%Cmv8?0si3dE2;i^p{`>I9FaP|# z&~JYG_UEtv{`~h(um8!z9{>kPzyca@f2lj*F$Ac<20HM85S&*6Bgg~>Qt*Np%%BDb zu|cp{u!A5Bp$H2&!4b0HgC>n3L=*2La z@r>{rqX^50#x}Zfd}<6K8{bIBI(99NAe^He_sGY@;IV^x?4uwDd5k}9Fpz{yq$17o zMMN(0k&qlhBO^)4N-koOmdvCkOM=NwdUBJ7)Sx3jNlG+^GJ~Tmr7FL8N(`oQm9Ugz zD=+xUSlaT4v!q}xZ^_FZ<}!l2?4>Yi_)7=|bC}3nVKEca1m?%g)YSD+DG^F-J>HB2rKALXNr9-soD^&VYmIBbEIfZFPN4ipv;#7z_ zt)EblO4Oeo)t5_^Us7Ax)RI1xhg0QXRIyrBF3c&LOWBz#+I+fO|4@Cdt4R@H(1x56me%rTia%L zO5e5NVJ+KMpB`;mwJHPNQ$G%h=?|RGI-u}M#zi-{|eEkbY z6co3K2CnaRW!T->CYZt8eQ;hEjNIs&PXPqTu!c9x;SLkPcI#v?06a`$4}>t5yEwxqK4^qr{Nfk~H^s_aad2BqV-nj~zt-h(k30Nh?BZC34eqUwhrHn;t2f9@ zHZf;`%HP$taLG~rFn(_;;w*F6$>2S53X^!ov3HDyFF`J$(R$zqhp%sO;@_p+iSI}Ck^XGuQ}AC&h^i1ZRT2II@N!U z@T^}gQw0p$(h)86t#_yEW;=}6UiP)}fW7LB%6iz+#?P^7o$OB!8Q0DZ_jRD1)IZE5N2|(i&XT9)C^8 z=RNU|Ye`y;E4lv3UA6C;UwBw7zc_*|O>}OP&)Bpsy1e7;?H+^sL?S6zm#(83s)r^b zJBnD2P?R?meJ)(d0Qt|+v4DTOT(aw2 z6*jS#uU-{r8o={R-B(@ifdk%tQSn)es*Ed_doZENJ%a7yvNef*UpU)^Uw{V#9wCmnoORb7ALmr{^+dr+f#9cJC)>GdF!8Sbg^H8Vt!U&kBEdh_!@~;iA6AePSvl z0eFYjNR5MKVIep?;wTIQHutyquz$O+vDLf_br0?A0g zc#iQnkO+A!|42p4n2_~IWdr7p4mpvMRFL{8krbJcYOs(S6p$K8kq}vpa`llU8IlIM zk0d#eCV7$Nn35pLk=E3ZE?G@0xm)NslL%Rp2ZoY3xsE!?T{78|$@G&Dc9TN>$&W-? zVF!7X*_f0nW|T}Rj!v0lP#KlaIF(2ilva65SUF}|xs|chl_unoV7ZH8d5d3Jma24? z%2<_ZNs};{L1g)saA}b?xs-J2Ol;|mX_=Rx6qj$-mwuT^dkK(&Ihd7Hm<;Kbh$&2p z*^!6Yn2_|CG0B*c$(4Y4L34STyhNFD8JV1!NS+y(mKmC>G@6^EE$o)nViN+RjL)7 zq6wYTIg-HXoYk2G%88w}d7RlvNW*!ZzX@O>DW29Dp7>~B*k)DWC;PpF+@`<;k3Psi1rGo(MXi5(=IM z8lV+=oBo-Vkwl@?`Jmc)o`VFUBf6d;I-lFwpdAWFEjpHzWTGURpc@L5A9|oEN~1X% zp&81e1X`RwilGcz0}hI!%Xy;tS)w?Kq!wDELb{?v`l4|rrELkIK6;_jiKS0zrBNEB zS?Z)p`A9OVq9Qt@JUXN@P^3C~q-MIHP@1Mx+F5aGm^Z4SJIbM6x}{>eq-_eMTKb=R zYNt$!r+@09TneXodU|uZn3y)3=%l7i3ZZV=r+eY3=LD&Q`u?3^3Z@BXYM%P3pc<-c zhN*t4sd~z(&LFC)x~i-ys-)UmstHce^?|KgtG0TpCHAUcDycS_s2_)`z#6Qzs;l>j zm%Uo3`yi~!x~!i{tcqHin|i0h!mQLu;AM*0dQJ`oiqPbVdtt5OI<6gttu~~s z=gO_~XaPtDt~yAr@H(#MdS56Yjg4|=4i<>sD2E9cuJQV>%sQ`BVrTZctyeZxvUhB> z$aMPpt^oV6!78wRM6h4>OABzY`8tU0+OVApu^v0DV@9!OcCQP&4+zVzRCtRhdx8b` zu`bK15(|yHgJlGFu|IdR9NUpAt8pmzvOepnF-tFs{?GtEVhRgTu<6Pi!&MgI@Bl^o z6kd@I4xn91J1HgWH92cdJDZ3<+qFX$v|nMfRXes(t85xpvqKBD8#!EKOSM$1wr-0% zWP7z`sIeiNwaMzWdYffnixWm`L~~2C7Mr$8OSo;jwr?A^hcUE8o3VAcv35(Vdpo%= z*0=V^w1DfjM_aKZtF}_B7(T+bZTq>HD@mVgwK(g3&d0NmOM|YvRkepTe_oL zv`9;@o~vC=yOB|wxohhRM9aIHOSf~gfc*-PZKt|iJG+!?xe6h+af`T!ySXE4u!-Bd z+AF$>JH6f;ywz*GVG(_EIF_yVy09y`&bz+;&>M@k+r6lpy8{ci+Y7#j`@5hEyj9z~ zsOz{ixPInagEe@H>+7}cI}XxIz0?b}X3J;T8@~37zqjkV5-hrDo4P~?z$#0=$=k6H z8;wL}z_qKta2vmz`@jsWz!ki}ntQm#+qg;wbE})a8_c{NoT|6_05E2Io(jU%dceHM zz+&40xMRJihQdn=ym~>zEUXwrEWruPcrskRHT=2^NWh`GWIimcTYR=(JHpH(zZ0ud zQA~$ZD899|wLP1|U-q(Hyu&>P#EnWkVl1;58^Z{A!&-~CbHl|IYs5yZWeqH4S{%sI z*uV_n#fqHBJS@k`GqZIpv}BCN43Yl92Zx&+7r8APtXkY;ZLG*}Tw|UL%Cq>%a4ck~ z9CrlZ$gu{=C!Dl5>%TLcvfs+bSjfqy{9(Ba!l_(myS&J`>|?78#@!RiVN1y{d}X%m znre*2pxVi#tjlLM$ih6$wO7cD%w{1h%B*~Du6(_)oQ|^WZkVit%ghjdJj$WG&cR&G zCZ@{j{K?SV$hB(%#_YH1s?3^P%lquFz&g*;Ov=41$^s3~E!N8eEzRCGV%_X%NU*Ku z)UB#m&+HnzwhGVyEy%Kn%^Qu%)|=2;R$~oa4(O`85xuV2L(wU%z6C71BfXm3i>klc z($4$RF#Wxh>aa9DyEc8(<^CMK2>ix7Ew48%V~gq|L(S7gomR8D$w@uAJq^=8Jt0B; z)X%%rKqk{BYpLZF)vGzx2prU0-PKs_SH4O~UTvCSZ92k~)}gu9_tZ;n&6#kWK5|{w zPo~w8G}o6|*IdR+d@Y%Noo0ZI*DZC_gA~|}IoP#$*M@CYXT8^t4cW*l*^}*Dld4LJ zjhKwRQH6cku_~*M4cf+fthTh-gW1^-(bl95tLS+H9KBnH1Z3Iop?1 z+qPY%xNS+gO_#jwkG}oeYdWZ&G~91l+ywdA$PL_Ns@c))oq7#P%&nHrU0Kjw-H|G- zo0Q#Ux!p?D-QHcQ{@49T;tiJMJp-(L-rud<;SJyM9o&_)-dow;pLI+4ZI${hR>w`> z+=$qM)ZbD0->Ajk0*>C`tw{#XlnAbn0lwfOdD;_B_n}y=@E#-tp;T5dUDuE0n>=Cy_8 zxsB#&&gFFE|PaJAAH@e*WHgE7>Yf&R@ftWMOo?$Eie>H()$)V!>&{!FvZjJm$KRPEVC-0R|c z?0R{@)Lz8Y{s&Wwx@EiUInLIN{p@kLs)n4azYgp%UBdXw?A;=}U^j_{H{k~0{?j*kN@!n@g4#m>T#M3*x+P?7p zF7Ibs?0-zN8_#A8ZScfH!fZ?NBroy#o6NLs<_f>R_^!n8i|@N`0|O0rAf3=7cF^^X zObPz{zNfpw|GvO6kMinX!uD(N3IFimUhD77!_jQ>3Z3)AwDT@s^k!c5nJe(Y4(0it z?M{sFEAPGA4(%RK^9``eWsmb9&paZ}@-58pO?>eV59Piq_bp%dJ|FfNAJ8<<^z8if zY2Q6-U%g~&^e>O~w1@D-3%?c2^DjT~LGKvqy!TBX&o>WaQ16)6{yF%LjL)ZnDLcwdxp%>r+oRng!=RA??~_Lz3mvpF4WEX_XUSgvVU77(QUbJ z>%3p7Ss(WbDg0vp!^Lm>hfn(({)x*^t+3yjSNr>S^!N-h{J!4&qj>x&--+BG?IYe# miPxj*mN@+ZTmGYX{-d5~r7k?x&y}hE{)iU;!E*o!0029*5x?*N literal 0 HcmV?d00001 diff --git a/fxp/doc/Images/fxp-shadow.jpg b/fxp/doc/Images/fxp-shadow.jpg new file mode 100644 index 0000000000000000000000000000000000000000..580879caa8e470cf8e819f0cc84d7d42d464580c GIT binary patch literal 2246 zcmb7_dpOe#8^?d!Y%_*tJXwx2n$u{gd3v+u6t-HZyc#OuaafZ%Hiw*5QgW&nEkNChb=1w*V7*6{zwfZ$33_U06`#N2viIKhW|SN0zoxJJA0H10XOIBDQ1cpa94Y7%T>b{^#m1E{Z6N zg`&;u4c*wUmeg?t&0n_P0!RpGr!52pP=F{$rhGPpJ{xq!^HE3Lh$;=`UU;va-xP&! zmCN|~WJt+2FTmY8!&$AxqYeRi6uMMY8Vk;hizX)fF`Z|jywQLNf^loSp-?PKO|`o4 zR&-<&`e(t^i4m-4IipsC$6i}wsf>kWqgnCTnDAsGF4y$E4Cni{| zl|w~1If@_m>K9YhsrAm!NzAwUHg)Bmw-~Xv&K6R+HtmxVYKf?Y`I)1oUG`i|t%qV9 ztP3iff)$qV((~FM*X+qFo~YVi9P`2y$qIWVcNW7kzAY4%N?RdE|uB((<7bLtOW z>^Coq^Y?>Kj`6EAKlu4O#V25o+4O9!%h9NA^+ZzSX`? zwV2z8*pVwrXZPu2A5t??lt4o*)lcmoWOEfa)l=VEXW++ceZIA9lDjhGdG8 zwLQ>!mtSD;y)Hj~QuDDi+)Q+9{5ig-E~U3*pL}`o1XJ0H^)oYhD^ag3ygHJuktkA8 z%PqRJyq+E6YCM|nKiH!U&m_Q}wK5*xF`Jeob1lNI+28LRT_tT9Ji&i3Pq*wfy`CKC zC(ej+-#Srw)JisoIx;rqvVwm5iKNmqozcH=S6fn{_veYY!@k3T`WKqNb0@9sGy^g! z=KK#RlR7K)`KpTtb1{aSyYg)CqO0v`5GQE6$#T;&0NO0$ZyBb%neBccBylEv34J26=t=QQ`cD9#;qb;fVs8K5mV|- z3c+&zGUCj~Io=x0rGt5G|7wR_WV_}uo^{sYaXe0ALX~^edsLAnT>H(-bz0|RkQ)f8 z-9lqGEgdGGHX&o)Nc1NZH%%D7UI>fW288#<+~?^&r@R-WM>yJux^C0z)OA}$+!8_J+;AWvhy@yG@zSXRZ@DMJg?wIk*E~0j9i1@ zoch3{RyCQ)sO$|3sr*l=C!rzZZmc(l3IM(``;_>%*_w^`noM`&0X0;tPG%);9{kry z@0q26M=RkLDa$Lk5(5L`i@X@V<*K7-VHIw|hp}j6nQ&fA#fJgphdRo|E?%V17keU8a|CXj + + + + + fxp - a Functional XML Parser + + + +

+fxp The Functional +XML Parser

+---------------- +

+Contents

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
oAbout fxp
ofxp Versions and Changes
oWhere to get fxp
oHow to install fxp
oExample Applications: fxp, fxcanon, +fxcopy, fxesis, +and fxviz
+ +

---------------- +

+fxp is a validating XML +parser written completely in the functional programming language SML. It +has a programming interface allowing for production +of XML applications based on fxp. It comes with four example applications: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ofxp, the pure parser. It parses a document +and finds well-formedness errors, validity errors and other problems;
ofxcanon produces an equivalent canonical +XML document. Canonical +XML was invented by James Clark +for testing XML parsers. It contains only the information a processor is +required to pass to the application; 
ofxcopy reproduces the document parsed +by fxp. The copy can be generated in a different encoding than the +input, and can be normalized in different ways concerning, e.g., expansion +of entity references; 
ofxesis adds a backend to fxp, +producing an output similar to nsgmls's +ESIS (Element Structure Information Set) output;
ofxviz is an XML tree visualizer. It +produces a graph description suitable as input to Georg Sander's vcg
+More features of fxp are here. +

---------------- + +

fxp Versions and Changes

+ +

The current version of fxp is 1.4.5. Changes from the +previous versions are described here.

+ +

---------------- + +

+Downloading fxp

+The source code for fxp can be downloaded by http. The Copyright note is here. +

---------------- +

+Installation instructions

+In order to install fxp, you need an SML compiler. It has been tested +with version 110.0.6 of SML +of New Jersey, but it might also run with other versions. The compiler +must have the compilation manager (CM) built in, which is the default when +installing SML-NJ. We successfully compiled fxp on Linux with libc5, +Digital Unix 4.0 and Solaris 2.4/6. For other unices we expect no problems; +compiling with the Windows version of SML-NJ has not been tried. +

These are the steps for installing fxp under Unix: +

    +
  1. +Download the latest version of fxp;
  2. + +
  3. +Unpack the sources, and change to the fxp directory, e.g.:
  4. + +
        gunzip -c fxp-1.4.tar.gz | tar xf -
    +    cd fxp-1.4
    + +
  5. +Read the COPYRIGHT;
  6. + +
  7. +Edit the Makefile according to your needs. Probably you will only +have to change the following:
  8. + +
      +
    • +INSTALL_PROGS is the list of programs to be installed. fxlib is +required if you want to develop applications with fxp. The fxgrep XML query language and the fxt XML transformation language also need fxlib being installed.
    • + +
    • +FXP_BINDIR is where the executables are installed;
    • + +
    • +FXP_LIBDIR is where other files needed by fxp - the heap +images and the library -- are installed;
    • + +
    • +SML_BINDIR is the directory where the SML executables are found. +It must contain the .arch-n-opsys script from the SML-NJ distribution, +so make sure that this is where SML-NJ is physically installed;
    • + +
    • +SML_EXEC is the name of the SML executable. This is the program +that is called for generating the heap image and at execution of fxp. +If sml will be in your PATH at execution time, you don't +need the full path here.
    • + +
    • +SML_MAKEDEF is for defining the make command in SML. +After version 110.0.3, SML-NJ changed the type of CM.make'. Therefore +it is wrapped into the make defined by this variable. For working +versions of SML-NJ, use the second variant of this definition.
    • +
    + +
  9. +Edit the file src/config.sml according to your needs. Currently +only a single value can be configured here:
  10. + +
      +
    • +retrieveCommand is the command to be used by fxp for retrieving +a remote URI from the internet and storing it in a temporary file on the +local file system. It is a string value and should contain the strings +%1 and %2, where
    • + +
        +
      • +%1 is replaced by the URI;
      • + +
      • +%2 is replaced by the local filename.
      • +
      +It is recommended that the command exits with failure in case the URI cannot +be retrieved. If the command generates a HTML error message instead (like, +e.g., "lynx -source %1 > %2"), this HTML file is considered to +be XML and will probably cause a mess of parsing errors. If you don't need +URI retrieval, use "exit 1" which always fails on Unix. Sensible +values are, e.g: + +
    + +
  11. +Compile fxp by typing make;
  12. + +
  13. +Install fxp by typing make install.
  14. + +
  15. +If you want to use fxviz, you should also install vcg.
  16. +
+---------------- + +

fxp's Programming Interface

+Here is a document describinng the programming interface +

---------------- + +

fxp's feedback address

+Any feedback related to fxp is welcome to: fxp@psi.uni-trier.de

---------------- + + +

Credits:

The author of fxp is Andreas Neumann. fxp is +maintained and updated by Alexandru Berlea. + + + + diff --git a/fxp/doc/Images/shadow.jpg b/fxp/doc/Images/shadow.jpg new file mode 100644 index 0000000000000000000000000000000000000000..41e6f590436c52ec08889de22ee4681208a85f86 GIT binary patch literal 1767 zcmex=^(PF6}rMnOeST|r4lSw=>~TvNxu(8R<nz|P9V0+dk`U|?isVP;@r zVundGu})+Z3=9zy4`yazOJo-kHU_E_LDda12qY>9(*!s9|1Aa{pixYM%z_N|3_Jfm z*I#q@<9~+w4ZGClZ`RvCV@u8=fB9!?;!|J0{Le7|dT4O`Mbq^kC-42w@Ma~`>NB&< z0+nZ)^kF@@+QuE&dH-gmEQnxQJ8JM~P>iOE;h#Y^{uTevu;}rpdjIC9 zUaNntTv?R+BmCiihRW&h>X+a6skN%^l>Jxcg;@y %2"), this HTML + file is considered to be XML and will probably cause a mess of + parsing errors. If you don't need URI retrieval, use "exit 1" + which always fails on Unix. Sensible values are, e.g: + + - "wget -qO %2 %1" + (ftp://gnjilux.cc.fer.hr/pub/unix/util/wget/) + - "got_it -o %2 %1" + (ftp://sunsite.unc.edu/pub/Linux/apps/www/ + mirroring/got_it-0.34.tar.gz) + - "urlget -s -o %2 %1" + (ftp://sunsite.unc.edu/pub/Linux/apps/www/ + mirroring/urlget-3.12.tar.gz) + + 6. Compile fxp by typing make; + 7. Install fxp by typing make install. + 8. If you want to use fxviz, you should also install vcg + (ftp://ftp.cs.uni-sb.de/pub/graphics/vcg/). + +If you experience problems installing fxp, send me mail at berlea (AT) +in.tum.de Check out for new versions at +http://www.informatik.tu-muenchen.de/~berlea/Fxp. + +Running the Parser +------------------ +Sample applications like fxp (a validating XML parser), fxcanon, fxcopy, +fxesis, and fxviz are described on fxp's homepage. + +Programming Interface +--------------------- +fxt's API is described in api.ps. + + +Alexandru Berlea \ No newline at end of file diff --git a/fxp/doc/api.ps b/fxp/doc/api.ps new file mode 100644 index 0000000..d393691 --- /dev/null +++ b/fxp/doc/api.ps @@ -0,0 +1,1092 @@ +%!PS-Adobe-2.0 +%%Creator: dvips(k) 5.92b Copyright 2002 Radical Eye Software +%%Title: doc.dvi +%%Pages: 7 +%%PageOrder: Ascend +%%BoundingBox: 0 0 596 842 +%%DocumentFonts: Palatino-Roman Palatino-Italic Helvetica Helvetica-Bold +%%+ EURM10 CMR10 CMSY10 Palatino-Bold Symbol Courier Palatino-BoldItalic +%%+ CMMI10 +%%DocumentPaperSizes: a4 +%%EndComments +%DVIPSWebPage: (www.radicaleye.com) +%DVIPSCommandLine: dvips -o api.ps doc.dvi +%DVIPSParameters: dpi=600, compressed +%DVIPSSource: TeX output 2004.06.25:1715 +%%BeginProcSet: texc.pro +%! +/TeXDict 300 dict def TeXDict begin/N{def}def/B{bind def}N/S{exch}N/X{S +N}B/A{dup}B/TR{translate}N/isls false N/vsize 11 72 mul N/hsize 8.5 72 +mul N/landplus90{false}def/@rigin{isls{[0 landplus90{1 -1}{-1 1}ifelse 0 +0 0]concat}if 72 Resolution div 72 VResolution div neg scale isls{ +landplus90{VResolution 72 div vsize mul 0 exch}{Resolution -72 div hsize +mul 0}ifelse TR}if Resolution VResolution vsize -72 div 1 add mul TR[ +matrix currentmatrix{A A round sub abs 0.00001 lt{round}if}forall round +exch round exch]setmatrix}N/@landscape{/isls true N}B/@manualfeed{ +statusdict/manualfeed true put}B/@copies{/#copies X}B/FMat[1 0 0 -1 0 0] +N/FBB[0 0 0 0]N/nn 0 N/IEn 0 N/ctr 0 N/df-tail{/nn 8 dict N nn begin +/FontType 3 N/FontMatrix fntrx N/FontBBox FBB N string/base X array +/BitMaps X/BuildChar{CharBuilder}N/Encoding IEn N end A{/foo setfont}2 +array copy cvx N load 0 nn put/ctr 0 N[}B/sf 0 N/df{/sf 1 N/fntrx FMat N +df-tail}B/dfs{div/sf X/fntrx[sf 0 0 sf neg 0 0]N df-tail}B/E{pop nn A +definefont setfont}B/Cw{Cd A length 5 sub get}B/Ch{Cd A length 4 sub get +}B/Cx{128 Cd A length 3 sub get sub}B/Cy{Cd A length 2 sub get 127 sub} +B/Cdx{Cd A length 1 sub get}B/Ci{Cd A type/stringtype ne{ctr get/ctr ctr +1 add N}if}B/id 0 N/rw 0 N/rc 0 N/gp 0 N/cp 0 N/G 0 N/CharBuilder{save 3 +1 roll S A/base get 2 index get S/BitMaps get S get/Cd X pop/ctr 0 N Cdx +0 Cx Cy Ch sub Cx Cw add Cy setcachedevice Cw Ch true[1 0 0 -1 -.1 Cx +sub Cy .1 sub]/id Ci N/rw Cw 7 add 8 idiv string N/rc 0 N/gp 0 N/cp 0 N{ +rc 0 ne{rc 1 sub/rc X rw}{G}ifelse}imagemask restore}B/G{{id gp get/gp +gp 1 add N A 18 mod S 18 idiv pl S get exec}loop}B/adv{cp add/cp X}B +/chg{rw cp id gp 4 index getinterval putinterval A gp add/gp X adv}B/nd{ +/cp 0 N rw exit}B/lsh{rw cp 2 copy get A 0 eq{pop 1}{A 255 eq{pop 254}{ +A A add 255 and S 1 and or}ifelse}ifelse put 1 adv}B/rsh{rw cp 2 copy +get A 0 eq{pop 128}{A 255 eq{pop 127}{A 2 idiv S 128 and or}ifelse} +ifelse put 1 adv}B/clr{rw cp 2 index string putinterval adv}B/set{rw cp +fillstr 0 4 index getinterval putinterval adv}B/fillstr 18 string 0 1 17 +{2 copy 255 put pop}for N/pl[{adv 1 chg}{adv 1 chg nd}{1 add chg}{1 add +chg nd}{adv lsh}{adv lsh nd}{adv rsh}{adv rsh nd}{1 add adv}{/rc X nd}{ +1 add set}{1 add clr}{adv 2 chg}{adv 2 chg nd}{pop nd}]A{bind pop} +forall N/D{/cc X A type/stringtype ne{]}if nn/base get cc ctr put nn +/BitMaps get S ctr S sf 1 ne{A A length 1 sub A 2 index S get sf div put +}if put/ctr ctr 1 add N}B/I{cc 1 add D}B/bop{userdict/bop-hook known{ +bop-hook}if/SI save N @rigin 0 0 moveto/V matrix currentmatrix A 1 get A +mul exch 0 get A mul add .99 lt{/QV}{/RV}ifelse load def pop pop}N/eop{ +SI restore userdict/eop-hook known{eop-hook}if showpage}N/@start{ +userdict/start-hook known{start-hook}if pop/VResolution X/Resolution X +1000 div/DVImag X/IEn 256 array N 2 string 0 1 255{IEn S A 360 add 36 4 +index cvrs cvn put}for pop 65781.76 div/vsize X 65781.76 div/hsize X}N +/p{show}N/RMat[1 0 0 -1 0 0]N/BDot 260 string N/Rx 0 N/Ry 0 N/V{}B/RV/v{ +/Ry X/Rx X V}B statusdict begin/product where{pop false[(Display)(NeXT) +(LaserWriter 16/600)]{A length product length le{A length product exch 0 +exch getinterval eq{pop true exit}if}{pop}ifelse}forall}{false}ifelse +end{{gsave TR -.1 .1 TR 1 1 scale Rx Ry false RMat{BDot}imagemask +grestore}}{{gsave TR -.1 .1 TR Rx Ry scale 1 1 false RMat{BDot} +imagemask grestore}}ifelse B/QV{gsave newpath transform round exch round +exch itransform moveto Rx 0 rlineto 0 Ry neg rlineto Rx neg 0 rlineto +fill grestore}B/a{moveto}B/delta 0 N/tail{A/delta X 0 rmoveto}B/M{S p +delta add tail}B/b{S p tail}B/c{-4 M}B/d{-3 M}B/e{-2 M}B/f{-1 M}B/g{0 M} +B/h{1 M}B/i{2 M}B/j{3 M}B/k{4 M}B/w{0 rmoveto}B/l{p -4 w}B/m{p -3 w}B/n{ +p -2 w}B/o{p -1 w}B/q{p 1 w}B/r{p 2 w}B/s{p 3 w}B/t{p 4 w}B/x{0 S +rmoveto}B/y{3 2 roll p a}B/bos{/SS save N}B/eos{SS restore}B end + +%%EndProcSet +%%BeginProcSet: 8r.enc +% File 8r.enc as of 2002-03-12 for PSNFSS 9 +% +% This is the encoding vector for Type1 and TrueType fonts to be used +% with TeX. This file is part of the PSNFSS bundle, version 9 +% +% Authors: S. Rahtz, P. MacKay, Alan Jeffrey, B. Horn, K. Berry, W. Schmidt +% +% Idea is to have all the characters normally included in Type 1 fonts +% available for typesetting. This is effectively the characters in Adobe +% Standard Encoding + ISO Latin 1 + extra characters from Lucida + Euro. +% +% Character code assignments were made as follows: +% +% (1) the Windows ANSI characters are almost all in their Windows ANSI +% positions, because some Windows users cannot easily reencode the +% fonts, and it makes no difference on other systems. The only Windows +% ANSI characters not available are those that make no sense for +% typesetting -- rubout (127 decimal), nobreakspace (160), softhyphen +% (173). quotesingle and grave are moved just because it's such an +% irritation not having them in TeX positions. +% +% (2) Remaining characters are assigned arbitrarily to the lower part +% of the range, avoiding 0, 10 and 13 in case we meet dumb software. +% +% (3) Y&Y Lucida Bright includes some extra text characters; in the +% hopes that other PostScript fonts, perhaps created for public +% consumption, will include them, they are included starting at 0x12. +% +% (4) Remaining positions left undefined are for use in (hopefully) +% upward-compatible revisions, if someday more characters are generally +% available. +% +% (5) hyphen appears twice for compatibility with both ASCII and Windows. +% +% (6) /Euro is assigned to 128, as in Windows ANSI +% +/TeXBase1Encoding [ +% 0x00 (encoded characters from Adobe Standard not in Windows 3.1) + /.notdef /dotaccent /fi /fl + /fraction /hungarumlaut /Lslash /lslash + /ogonek /ring /.notdef + /breve /minus /.notdef +% These are the only two remaining unencoded characters, so may as +% well include them. + /Zcaron /zcaron +% 0x10 + /caron /dotlessi +% (unusual TeX characters available in, e.g., Lucida Bright) + /dotlessj /ff /ffi /ffl + /.notdef /.notdef /.notdef /.notdef + /.notdef /.notdef /.notdef /.notdef + % very contentious; it's so painful not having quoteleft and quoteright + % at 96 and 145 that we move the things normally found there down to here. + /grave /quotesingle +% 0x20 (ASCII begins) + /space /exclam /quotedbl /numbersign + /dollar /percent /ampersand /quoteright + /parenleft /parenright /asterisk /plus /comma /hyphen /period /slash +% 0x30 + /zero /one /two /three /four /five /six /seven + /eight /nine /colon /semicolon /less /equal /greater /question +% 0x40 + /at /A /B /C /D /E /F /G /H /I /J /K /L /M /N /O +% 0x50 + /P /Q /R /S /T /U /V /W + /X /Y /Z /bracketleft /backslash /bracketright /asciicircum /underscore +% 0x60 + /quoteleft /a /b /c /d /e /f /g /h /i /j /k /l /m /n /o +% 0x70 + /p /q /r /s /t /u /v /w + /x /y /z /braceleft /bar /braceright /asciitilde + /.notdef % rubout; ASCII ends +% 0x80 + /Euro /.notdef /quotesinglbase /florin + /quotedblbase /ellipsis /dagger /daggerdbl + /circumflex /perthousand /Scaron /guilsinglleft + /OE /.notdef /.notdef /.notdef +% 0x90 + /.notdef /.notdef /.notdef /quotedblleft + /quotedblright /bullet /endash /emdash + /tilde /trademark /scaron /guilsinglright + /oe /.notdef /.notdef /Ydieresis +% 0xA0 + /.notdef % nobreakspace + /exclamdown /cent /sterling + /currency /yen /brokenbar /section + /dieresis /copyright /ordfeminine /guillemotleft + /logicalnot + /hyphen % Y&Y (also at 45); Windows' softhyphen + /registered + /macron +% 0xD0 + /degree /plusminus /twosuperior /threesuperior + /acute /mu /paragraph /periodcentered + /cedilla /onesuperior /ordmasculine /guillemotright + /onequarter /onehalf /threequarters /questiondown +% 0xC0 + /Agrave /Aacute /Acircumflex /Atilde /Adieresis /Aring /AE /Ccedilla + /Egrave /Eacute /Ecircumflex /Edieresis + /Igrave /Iacute /Icircumflex /Idieresis +% 0xD0 + /Eth /Ntilde /Ograve /Oacute + /Ocircumflex /Otilde /Odieresis /multiply + /Oslash /Ugrave /Uacute /Ucircumflex + /Udieresis /Yacute /Thorn /germandbls +% 0xE0 + /agrave /aacute /acircumflex /atilde + /adieresis /aring /ae /ccedilla + /egrave /eacute /ecircumflex /edieresis + /igrave /iacute /icircumflex /idieresis +% 0xF0 + /eth /ntilde /ograve /oacute + /ocircumflex /otilde /odieresis /divide + /oslash /ugrave /uacute /ucircumflex + /udieresis /yacute /thorn /ydieresis +] def + +%%EndProcSet +%%BeginProcSet: f7b6d320.enc +% Thomas Esser, Dec 2002. public domain +% +% Encoding for: +% cmb10 cmbx10 cmbx12 cmbx5 cmbx6 cmbx7 cmbx8 cmbx9 cmbxsl10 +% cmdunh10 cmr10 cmr12 cmr17cmr6 cmr7 cmr8 cmr9 cmsl10 cmsl12 cmsl8 +% cmsl9 cmss10cmss12 cmss17 cmss8 cmss9 cmssbx10 cmssdc10 cmssi10 +% cmssi12 cmssi17 cmssi8cmssi9 cmssq8 cmssqi8 cmvtt10 +% +/TeXf7b6d320Encoding [ +/Gamma /Delta /Theta /Lambda /Xi /Pi /Sigma /Upsilon /Phi /Psi /Omega +/ff /fi /fl /ffi /ffl /dotlessi /dotlessj /grave /acute /caron /breve +/macron /ring /cedilla /germandbls /ae /oe /oslash /AE /OE /Oslash +/suppress /exclam /quotedblright /numbersign /dollar /percent /ampersand +/quoteright /parenleft /parenright /asterisk /plus /comma /hyphen +/period /slash /zero /one /two /three /four /five /six /seven /eight +/nine /colon /semicolon /exclamdown /equal /questiondown /question /at +/A /B /C /D /E /F /G /H /I /J /K /L /M /N /O /P /Q /R /S /T /U /V /W /X +/Y /Z /bracketleft /quotedblleft /bracketright /circumflex /dotaccent +/quoteleft /a /b /c /d /e /f /g /h /i /j /k /l /m /n /o /p /q /r /s /t /u +/v /w /x /y /z /endash /emdash /hungarumlaut /tilde /dieresis /suppress +/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef +/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef +/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef +/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /space +/Gamma /Delta /Theta /Lambda /Xi /Pi /Sigma /Upsilon /Phi /Psi /.notdef +/.notdef /Omega /ff /fi /fl /ffi /ffl /dotlessi /dotlessj /grave /acute +/caron /breve /macron /ring /cedilla /germandbls /ae /oe /oslash /AE +/OE /Oslash /suppress /dieresis /.notdef /.notdef /.notdef /.notdef +/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef +/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef +/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef +/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef +/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef +/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef +/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef +] def + +%%EndProcSet +%%BeginProcSet: bbad153f.enc +% Thomas Esser, Dec 2002. public domain +% +% Encoding for: +% cmsy10 cmsy5 cmsy6 cmsy7 cmsy8 cmsy9 +% +/TeXbbad153fEncoding [ +/minus /periodcentered /multiply /asteriskmath /divide /diamondmath +/plusminus /minusplus /circleplus /circleminus /circlemultiply +/circledivide /circledot /circlecopyrt /openbullet /bullet +/equivasymptotic /equivalence /reflexsubset /reflexsuperset /lessequal +/greaterequal /precedesequal /followsequal /similar /approxequal +/propersubset /propersuperset /lessmuch /greatermuch /precedes /follows +/arrowleft /arrowright /arrowup /arrowdown /arrowboth /arrownortheast +/arrowsoutheast /similarequal /arrowdblleft /arrowdblright /arrowdblup +/arrowdbldown /arrowdblboth /arrownorthwest /arrowsouthwest /proportional +/prime /infinity /element /owner /triangle /triangleinv /negationslash +/mapsto /universal /existential /logicalnot /emptyset /Rfractur /Ifractur +/latticetop /perpendicular /aleph /A /B /C /D /E /F /G /H /I /J /K +/L /M /N /O /P /Q /R /S /T /U /V /W /X /Y /Z /union /intersection +/unionmulti /logicaland /logicalor /turnstileleft /turnstileright +/floorleft /floorright /ceilingleft /ceilingright /braceleft /braceright +/angbracketleft /angbracketright /bar /bardbl /arrowbothv /arrowdblbothv +/backslash /wreathproduct /radical /coproduct /nabla /integral +/unionsq /intersectionsq /subsetsqequal /supersetsqequal /section +/dagger /daggerdbl /paragraph /club /diamond /heart /spade /arrowleft +/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef +/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef +/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef +/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef +/minus /periodcentered /multiply /asteriskmath /divide /diamondmath +/plusminus /minusplus /circleplus /circleminus /.notdef /.notdef +/circlemultiply /circledivide /circledot /circlecopyrt /openbullet +/bullet /equivasymptotic /equivalence /reflexsubset /reflexsuperset +/lessequal /greaterequal /precedesequal /followsequal /similar +/approxequal /propersubset /propersuperset /lessmuch /greatermuch +/precedes /follows /arrowleft /spade /.notdef /.notdef /.notdef /.notdef +/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef +/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef +/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef +/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef +/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef +/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef +/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef +] def + +%%EndProcSet +%%BeginProcSet: aae443f0.enc +% Thomas Esser, Dec 2002. public domain +% +% Encoding for: +% cmmi10 cmmi12 cmmi5 cmmi6 cmmi7 cmmi8 cmmi9 cmmib10 +% +/TeXaae443f0Encoding [ +/Gamma /Delta /Theta /Lambda /Xi /Pi /Sigma /Upsilon /Phi /Psi /Omega +/alpha /beta /gamma /delta /epsilon1 /zeta /eta /theta /iota /kappa +/lambda /mu /nu /xi /pi /rho /sigma /tau /upsilon /phi /chi /psi +/omega /epsilon /theta1 /pi1 /rho1 /sigma1 /phi1 /arrowlefttophalf +/arrowleftbothalf /arrowrighttophalf /arrowrightbothalf /arrowhookleft +/arrowhookright /triangleright /triangleleft /zerooldstyle /oneoldstyle +/twooldstyle /threeoldstyle /fouroldstyle /fiveoldstyle /sixoldstyle +/sevenoldstyle /eightoldstyle /nineoldstyle /period /comma /less /slash +/greater /star /partialdiff /A /B /C /D /E /F /G /H /I /J /K /L /M /N +/O /P /Q /R /S /T /U /V /W /X /Y /Z /flat /natural /sharp /slurbelow +/slurabove /lscript /a /b /c /d /e /f /g /h /i /j /k /l /m /n /o /p +/q /r /s /t /u /v /w /x /y /z /dotlessi /dotlessj /weierstrass /vector +/tie /psi /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef +/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef +/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef +/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef +/space /Gamma /Delta /Theta /Lambda /Xi /Pi /Sigma /Upsilon /Phi /Psi +/.notdef /.notdef /Omega /alpha /beta /gamma /delta /epsilon1 /zeta /eta +/theta /iota /kappa /lambda /mu /nu /xi /pi /rho /sigma /tau /upsilon +/phi /chi /psi /tie /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef +/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef +/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef +/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef +/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef +/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef +/.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef +/.notdef /.notdef /.notdef /.notdef /.notdef +] def + +%%EndProcSet +%%BeginProcSet: texps.pro +%! +TeXDict begin/rf{findfont dup length 1 add dict begin{1 index/FID ne 2 +index/UniqueID ne and{def}{pop pop}ifelse}forall[1 index 0 6 -1 roll +exec 0 exch 5 -1 roll VResolution Resolution div mul neg 0 0]FontType 0 +ne{/Metrics exch def dict begin Encoding{exch dup type/integertype ne{ +pop pop 1 sub dup 0 le{pop}{[}ifelse}{FontMatrix 0 get div Metrics 0 get +div def}ifelse}forall Metrics/Metrics currentdict end def}{{1 index type +/nametype eq{exit}if exch pop}loop}ifelse[2 index currentdict end +definefont 3 -1 roll makefont/setfont cvx]cvx def}def/ObliqueSlant{dup +sin S cos div neg}B/SlantFont{4 index mul add}def/ExtendFont{3 -1 roll +mul exch}def/ReEncodeFont{CharStrings rcheck{/Encoding false def dup[ +exch{dup CharStrings exch known not{pop/.notdef/Encoding true def}if} +forall Encoding{]exch pop}{cleartomark}ifelse}if/Encoding exch def}def +end + +%%EndProcSet +%%BeginFont: CMMI10 +%!PS-AdobeFont-1.1: CMMI10 1.100 +%%CreationDate: 1996 Jul 23 07:53:57 +% Copyright (C) 1997 American Mathematical Society. All Rights Reserved. +11 dict begin +/FontInfo 7 dict dup begin +/version (1.100) readonly def +/Notice (Copyright (C) 1997 American Mathematical Society. All Rights Reserved) readonly def +/FullName (CMMI10) readonly def +/FamilyName (Computer Modern) readonly def +/Weight (Medium) readonly def +/ItalicAngle -14.04 def +/isFixedPitch false def +end readonly def +/FontName /CMMI10 def +/PaintType 0 def +/FontType 1 def +/FontMatrix [0.001 0 0 0.001 0 0] readonly def +/Encoding 256 array +0 1 255 {1 index exch /.notdef put} for +dup 0 /.notdef put +readonly def +/FontBBox{-32 -250 1048 750}readonly def +/UniqueID 5087385 def +currentdict end +currentfile eexec +D9D66F633B846A97B686A97E45A3D0AA0529731C99A784CCBE85B4993B2EEBDE +3B12D472B7CF54651EF21185116A69AB1096ED4BAD2F646635E019B6417CC77B +532F85D811C70D1429A19A5307EF63EB5C5E02C89FC6C20F6D9D89E7D91FE470 +B72BEFDA23F5DF76BE05AF4CE93137A219ED8A04A9D7D6FDF37E6B7FCDE0D90B +986423E5960A5D9FBB4C956556E8DF90CBFAEC476FA36FD9A5C8175C9AF513FE +D919C2DDD26BDC0D99398B9F4D03D5993DFC0930297866E1CD0A319B6B1FD958 +9E394A533A081C36D456A09920001A3D2199583EB9B84B4DEE08E3D12939E321 +990CD249827D9648574955F61BAAA11263A91B6C3D47A5190165B0C25ABF6D3E +6EC187E4B05182126BB0D0323D943170B795255260F9FD25F2248D04F45DFBFB +DEF7FF8B19BFEF637B210018AE02572B389B3F76282BEB29CC301905D388C721 +59616893E774413F48DE0B408BC66DCE3FE17CB9F84D205839D58014D6A88823 +D9320AE93AF96D97A02C4D5A2BB2B8C7925C4578003959C46E3CE1A2F0EAC4BF +8B9B325E46435BDE60BC54D72BC8ACB5C0A34413AC87045DC7B84646A324B808 +6FD8E34217213E131C3B1510415CE45420688ED9C1D27890EC68BD7C1235FAF9 +1DAB3A369DD2FC3BE5CF9655C7B7EDA7361D7E05E5831B6B8E2EEC542A7B38EE +03BE4BAC6079D038ACB3C7C916279764547C2D51976BABA94BA9866D79F13909 +95AA39B0F03103A07CBDF441B8C5669F729020AF284B7FF52A29C6255FCAACF1 +74109050FBA2602E72593FBCBFC26E726EE4AEF97B7632BC4F5F353B5C67FED2 +3EA752A4A57B8F7FEFF1D7341D895F0A3A0BE1D8E3391970457A967EFF84F6D8 +47750B1145B8CC5BD96EE7AA99DDC9E06939E383BDA41175233D58AD263EBF19 +AFC0E2F840512D321166547B306C592B8A01E1FA2564B9A26DAC14256414E4C8 +42616728D918C74D13C349F4186EC7B9708B86467425A6FDB3A396562F7EE4D8 +40B43621744CF8A23A6E532649B66C2A0002DD04F8F39618E4F572819DD34837 +B5A08E643FDCA1505AF6A1FA3DDFD1FA758013CAED8ACDDBBB334D664DFF5B53 +95601766777978D01677B8D19E1B10A078432D2884BB4F7B8C3293B68BB78100 +16724E495064BA0168CC86D413CB48560D6D318357397832F7A858CD82030C7D +8A4A1919716E8B26AFF8789AAF489EE4E0A88DC477551A87C7DF2856189E4596 +FE015956AFE5CC019F5CA6323A12B763B7B08B92C1A2940D3C566C43729E5482 +63C6DC5E834AEB4DAFB5AE8F0B8931A4687C94D11587B9071C8D81DA14F12776 +53A1985A3EBE37827656BD4635E03F09C3231F906874645E7DB3E59045A59D67 +E745D8487CF73FC50F64060544F624F357BC998A87FBE468DEBB38A09449EBCA +D041D7C29225ACD16CB8A59E87924D15A9125F064710A6CCCA3AD3103D8FCC94 +CC3571C6F9192774FCFE5BB42A14B27960903144D28BF047BF4C77646EA7BF6F +440D4EDEB712C63F2E8080419E42D1D58EED685EB5CDD49F80DB6E5553B519FA +C6A39A093155802F3EC607721F390307E91ECB597ABA60A537E3F8C045BF5DD3 +D88CF6518D37FCD95D2F295D902D617440D23516D962F47750A682A319ACE1 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +cleartomark +%%EndFont +%%BeginFont: CMSY10 +%!PS-AdobeFont-1.1: CMSY10 1.0 +%%CreationDate: 1991 Aug 15 07:20:57 +% Copyright (C) 1997 American Mathematical Society. All Rights Reserved. +11 dict begin +/FontInfo 7 dict dup begin +/version (1.0) readonly def +/Notice (Copyright (C) 1997 American Mathematical Society. All Rights Reserved) readonly def +/FullName (CMSY10) readonly def +/FamilyName (Computer Modern) readonly def +/Weight (Medium) readonly def +/ItalicAngle -14.035 def +/isFixedPitch false def +end readonly def +/FontName /CMSY10 def +/PaintType 0 def +/FontType 1 def +/FontMatrix [0.001 0 0 0.001 0 0] readonly def +/Encoding 256 array +0 1 255 {1 index exch /.notdef put} for +dup 0 /.notdef put +readonly def +/FontBBox{-29 -960 1116 775}readonly def +/UniqueID 5000820 def +currentdict end +currentfile eexec +D9D66F633B846A97B686A97E45A3D0AA052F09F9C8ADE9D907C058B87E9B6964 +7D53359E51216774A4EAA1E2B58EC3176BD1184A633B951372B4198D4E8C5EF4 +A213ACB58AA0A658908035BF2ED8531779838A960DFE2B27EA49C37156989C85 +E21B3ABF72E39A89232CD9F4237FC80C9E64E8425AA3BEF7DED60B122A52922A +221A37D9A807DD01161779DDE7D31FF2B87F97C73D63EECDDA4C49501773468A +27D1663E0B62F461F6E40A5D6676D1D12B51E641C1D4E8E2771864FC104F8CBF +5B78EC1D88228725F1C453A678F58A7E1B7BD7CA700717D288EB8DA1F57C4F09 +0ABF1D42C5DDD0C384C7E22F8F8047BE1D4C1CC8E33368FB1AC82B4E96146730 +DE3302B2E6B819CB6AE455B1AF3187FFE8071AA57EF8A6616B9CB7941D44EC7A +71A7BB3DF755178D7D2E4BB69859EFA4BBC30BD6BB1531133FD4D9438FF99F09 +4ECC068A324D75B5F696B8688EEB2F17E5ED34CCD6D047A4E3806D000C199D7C +515DB70A8D4F6146FE068DC1E5DE8BC57033D79919697C81395D5B94C3AAAB11 +52D7393B7810FB3A048DB26F99398B6402C264B13FEFEE92BA387801BC9699A2 +E43D69AAA3CB2DD7C81617501B0618651E0850CB5C173082CDC1D1372741FC2E +7AB2116FB69984ECBCE8EC5515E9F234C273AEB8F9C222E448AF3CCDC35A428F +9A267F67CAD67819A64BB630671647A63A11636808CB93ADF3D6833ABBA85CD1 +B9C0C37370FCEC157D06072F9E783EEBFA8F2322912210FA9669F870FEA1DEE3 +0E5A8A230609D077AF8FF69E4915D3918778846363DD98E76B0A64AA884D759A +18068F08DFCDAC51EC16C3557D73FBFEFE893F2CEE353183BC8767C4FB5B259D +8E8052ECB97B25570A07136013C072DE083CFFF01DBE2C4D4DC3506AE677B87D +22047CF66F24DC46EA5787F850233595CE10A4085D40498064D5309D7DCBCF43 +BDB7B1CCFF0D4D1635F8234545E9C12062CE60D235F44328A4C56804977793CF +5FB9BB31EB1721A6B6039FEB7A13225B1B2D3924E61365F3EF20BBFB79D75B84 +E0F5AC513CC4CB459DA29AAC0467116822CDD97D23F22D229C7F622CF5775779 +51C2F1070743D9DA737FCCB558F47F674A594AEF6DE05C496239B397B15D3130 +38328DB1D00C1575271024486754845AA7CEC9179F4F7DB3C74C276008DF0569 +DA697985B569658784366E7D18D1E7ADEECF2C2E90E138C38D5D4FA2B2076517 +6031A5D9BC8EF30525C255D6A0304097E0F9F686FEE3E0A6C6B62EEB4DC6E25F +C5C224555C057CA7DA3F16B0371EE30C195219436E860AA98BB2B08218C73BD4 +5C6653C74AF1951632E4B7E67902E55B197DB76AB75140754AEFA49F15BFA3C2 +A99485EA437AA7F091172928345616D01C54B8FCCC861491304040FE12F453EF +CD69E1DA51AD05C811F4E82485866674413C4CF288C31EB281E0F102A41069CC +C2729313A7C3B61F89E41298E97126E42E927B727E48F8BEDAE7E268F8124431 +A5B9CB2226614ABB613E766030F01115B9A4D58FAA6C6D2A59F44AB2555E595A +D2B9DA418E0E8104E52F50ECC65A244B6D042654870AC34E76D2450E5D3167E2 +92E9A1C799F462705617181FD29326C6AC2F5F062C409D2359F239CBE402C1CD +2A74D9FA86079D9FE49EEADBD5EEB4941A68A808B433F372CC9ED578FC8676B7 +6B91848E2D93E7E9B7367C63783F5D4BDF0F746AB838745EF04425F8E8611C50 +BAD150C9B9 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +cleartomark +%%EndFont +%%BeginFont: CMR10 +%!PS-AdobeFont-1.1: CMR10 1.00B +%%CreationDate: 1992 Feb 19 19:54:52 +% Copyright (C) 1997 American Mathematical Society. All Rights Reserved. +11 dict begin +/FontInfo 7 dict dup begin +/version (1.00B) readonly def +/Notice (Copyright (C) 1997 American Mathematical Society. All Rights Reserved) readonly def +/FullName (CMR10) readonly def +/FamilyName (Computer Modern) readonly def +/Weight (Medium) readonly def +/ItalicAngle 0 def +/isFixedPitch false def +end readonly def +/FontName /CMR10 def +/PaintType 0 def +/FontType 1 def +/FontMatrix [0.001 0 0 0.001 0 0] readonly def +/Encoding 256 array +0 1 255 {1 index exch /.notdef put} for +dup 0 /.notdef put +readonly def +/FontBBox{-251 -250 1009 969}readonly def +/UniqueID 5000793 def +currentdict end +currentfile eexec +D9D66F633B846A97B686A97E45A3D0AA052A014267B7904EB3C0D3BD0B83D891 +016CA6CA4B712ADEB258FAAB9A130EE605E61F77FC1B738ABC7C51CD46EF8171 +9098D5FEE67660E69A7AB91B58F29A4D79E57022F783EB0FBBB6D4F4EC35014F +D2DECBA99459A4C59DF0C6EBA150284454E707DC2100C15B76B4C19B84363758 +469A6C558785B226332152109871A9883487DD7710949204DDCF837E6A8708B8 +2BDBF16FBC7512FAA308A093FE5CF7158F1163BC1F3352E22A1452E73FECA8A4 +87100FB1FFC4C8AF409B2067537220E605DA0852CA49839E1386AF9D7A1A455F +D1F017CE45884D76EF2CB9BC5821FD25365DDEA6E45F332B5F68A44AD8A530F0 +92A36FAC8D27F9087AFEEA2096F839A2BC4B937F24E080EF7C0F9374A18D565C +295A05210DB96A23175AC59A9BD0147A310EF49C551A417E0A22703F94FF7B75 +409A5D417DA6730A69E310FA6A4229FC7E4F620B0FC4C63C50E99E179EB51E4C +4BC45217722F1E8E40F1E1428E792EAFE05C5A50D38C52114DFCD24D54027CBF +2512DD116F0463DE4052A7AD53B641A27E81E481947884CE35661B49153FA19E +0A2A860C7B61558671303DE6AE06A80E4E450E17067676E6BBB42A9A24ACBC3E +B0CA7B7A3BFEA84FED39CCFB6D545BB2BCC49E5E16976407AB9D94556CD4F008 +24EF579B6800B6DC3AAF840B3FC6822872368E3B4274DD06CA36AF8F6346C11B +43C772CC242F3B212C4BD7018D71A1A74C9A94ED0093A5FB6557F4E0751047AF +D72098ECA301B8AE68110F983796E581F106144951DF5B750432A230FDA3B575 +5A38B5E7972AABC12306A01A99FCF8189D71B8DBF49550BAEA9CF1B97CBFC7CC +96498ECC938B1A1710B670657DE923A659DB8757147B140A48067328E7E3F9C3 +7D1888B284904301450CE0BC15EEEA00E48CCD6388F3FC3C8578EF9A20A0E06E +4F7ADDAF0E7D1E182D115BF1AD931977325AD391E72E2B13CC108E3726C11099 +E2000623188AAAC9F3E233EB253BDD8B0A4759A66A113E066238B0086AC1B634 +5ABFF90E4B5ED3FA69C22541981B2BFC9710AEF6B50A8BB53431C7B4D380D721 +639E005D6B4688EE16BFF48443E7C9E5FB5BC5883E271CB0342893C0BBC0A879 +B7220832FB50103F72F8B5D986B7619683B3BE2BBEFDBCE02277C601A977C3CC +A643D219A9074AFFAEACE5CF1E007DF84E7B0634F5FF6824D3ABC3CE1259C2F8 +0D023DBDD4DD06EF96751AA97695823E5E8FEA5C526B78059E57293164FF5B4E +452ABA970DE4680E0170CBD232901F175DD37779D63BC85BA1450F2A6C3E62D4 +6636A59DBA0BE8DECA24B77DB2A60676CF6146666094BA9F805E7BE295BCC02C +7422EC734C49DC0529F6829881A0855596C8F17F089A9D8EF68BD3FBE9BBC987 +674637AA811D0E4653E7E044EF655B9CC90912236F4B78C01ECA4EBE3E0AF090 +688571B045A62D267FF554E63D810B2491CB +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +0000000000000000000000000000000000000000000000000000000000000000 +cleartomark +%%EndFont +TeXDict begin 39158280 55380996 1000 600 600 (doc.dvi) +@start /Fa 193[61 1[61 60[{ TeXaae443f0Encoding ReEncodeFont }2 +77.8574 /CMMI10 rf /Fc 161[35 94[{ TeXbbad153fEncoding ReEncodeFont }1 +51.905 /CMSY10 rf /Fd 135[60 7[66 9[40 102[{ + TeXBase1Encoding ReEncodeFont }3 119.552 /Palatino-BoldItalic +rf /Fe 103[42 29[42 2[42 1[42 42 42 42 1[42 42 42 42 +1[42 1[42 42 42 42 42 42 42 1[42 16[42 14[42 6[42 10[42 +42 42 45[{ .85 ExtendFont TeXBase1Encoding ReEncodeFont }26 +83.022 /Courier rf /Fg 133[60 1[60 100 1[73 40 53 47 +1[73 66 73 106 40 2[40 73 66 47 60 73 53 1[60 12[80 1[86 +1[73 100 5[47 2[66 3[80 93 12[60 60 60 60 3[40 45[{ + TeXBase1Encoding ReEncodeFont }33 119.552 /Palatino-Bold +rf /Fh 138[51 2[32 5[28 2[28 1[46 1[42 2[51 42 12[55 +13[46 11[21 6[42 42 42 49[{ TeXBase1Encoding ReEncodeFont }14 +83.022 /Palatino-Bold rf /Fi 149[22 64[78 7[78 29[39 +3[{ TeXbbad153fEncoding ReEncodeFont }4 77.8574 /CMSY10 +rf /Fj 194[61 61[{ TeXf7b6d320Encoding ReEncodeFont }1 +77.8574 /CMR10 rf /Fl 134[42 42 58 42 46 25 42 29 1[46 +46 46 1[21 2[21 46 46 25 42 46 42 1[42 14[54 2[58 10[54 +68[{ TeXBase1Encoding ReEncodeFont }23 74.7198 /Helvetica-Bold +rf /Fm 107[25 26[37 37 54 37 42 21 37 25 1[42 42 42 62 +17 37 1[17 42 42 21 42 42 37 42 42 3[21 1[21 2[50 71 +50 54 46 50 54 1[50 58 54 62 42 2[21 54 58 46 50 54 54 +50 50 6[21 1[42 42 42 42 2[42 1[42 1[21 1[21 2[25 25 +17 36[37 2[{ TeXBase1Encoding ReEncodeFont }60 74.7198 +/Helvetica rf /Fn 171[41 6[63 41 3[55 72[{ + TeXBase1Encoding ReEncodeFont }4 66.4176 /Palatino-Roman +rf /Fo 133[37 1[42 2[46 28 32 32 1[42 37 46 1[23 37 1[23 +42 1[23 32 42 34 1[37 51[28 42[44 2[{ TeXBase1Encoding ReEncodeFont }20 +83.022 /Palatino-Italic rf /Fp 105[42 27[42 46 43 69 +47 50 27 35 33 46 50 45 48 73 24 46 1[24 48 46 28 40 +51 37 46 42 3[28 1[28 2[55 83 1[65 51 44 55 65 50 65 +69 79 51 2[28 69 1[46 51 64 59 1[65 5[21 21 1[42 42 42 +42 42 42 42 42 42 1[21 28 21 4[23 35[50 50 2[{ + TeXBase1Encoding ReEncodeFont }64 83.022 /Palatino-Roman +rf /Fq 135[72 7[72 9[40 102[{ TeXBase1Encoding ReEncodeFont }3 +143.462 /Palatino-Italic rf /Fr 139[47 1[57 1[86 78 83 +127 42 2[42 1[80 48 69 1[64 1[72 16[87 6[48 7[112 65[{ + TeXBase1Encoding ReEncodeFont }16 143.462 /Palatino-Roman +rf end +%%EndProlog +%%BeginSetup +%%Feature: *Resolution 600dpi +TeXDict begin +%%BeginPaperSize: a4 +a4 +%%EndPaperSize + end +%%EndSetup +%%Page: 1 1 +TeXDict begin 1 0 bop 528 880 a Fr(Application)35 b(Pr)m(ogramming)g +(Interface)g(for)g Fq(fxp)573 1483 y Fp(The)22 b(following)h(is)g +(basically)e(an)h(excerpt)f(fr)o(om)h(Andr)o(eas)e(Neumann's)j(Ph.D.)f +(The-)448 1583 y(sis)g([1)o(],)e(Chapter)g(2,)g(Section8.)573 +1758 y(The)k Fo(fxp)p Fp('s)f(application)h(interface)f(is)h(a)g +(functional)g(variant)f(of)h(an)g(event-based)e(in-)448 +1858 y(terface)d(that)i(vitally)g(r)o(elies)f(on)k(S)t +Fn(M)t(L)r Fp('s)c(parametrized)e(modules)k(for)e(customization.)573 +1958 y(The)d(application)h(de\002nes)f(a)g(data)g(type)g +Fm(AppData)e Fp(r)o(epr)o(esenting)i(the)h(part)e(of)i(its)g(state)448 +2057 y(af)o(fected)28 b(by)j(the)g(event)f(handlers.)55 +b(W)-8 b(e)30 b(call)h(this)g(information)g(the)g Fo(application)e +(data)p Fp(.)448 2157 y(During)21 b(parsing,)g(a)f(value)f(of)i(this)g +(type)f(is)h(maintained)f(by)g(the)h(parser)-6 b(.)24 +b(Upon)d(trigger)o(-)448 2256 y(ing)26 b(an)f(event,)h(the)g(event)f +(handler)f(r)o(eceives)g(the)i(application)f(data)f(as)h(an)g +(additional)448 2356 y(parameter)30 b(and)g(r)o(eturns)h(it)g(\226)g +(possibly)h(modi\002ed)g(\226)e(to)i(the)f(parser)-6 +b(.)55 b(The)31 b(modi\002ed)448 2456 y(application)24 +b(data)g(is)g(then)h(an)f(ar)o(gument)g(to)h(the)f(next)g(event,)h(and) +f(so)h(forth.)36 b(In)25 b(or)o(der)448 2555 y(to)g(distinguish)g(this) +g(kind)g(of)f(event)f(handlers)h(fr)o(om)g(the)g(imperative)g(variant)f +(we)h(call)448 2655 y(them)18 b Fo(hooks)p Fp(.)24 b(The)18 +b(ef)o(fects)e(of)i(all)f(hooks)i(ar)o(e)d(thus)j(accumulated)d(into)j +(one)f(value)f(of)h(type)448 2755 y Fm(AppData)n Fp(.)573 +2854 y(In)25 b(or)o(der)g(to)g(implement)i(hooks)f(in)g +Fo(fxp)p Fp(,)f(the)h(parser)e(must)i(be)f(pr)o(ovided)f(with)i(the)448 +2954 y(type)h(of)g(the)g(application)g(data)f(and)h(with)h(the)f +(functions)h(implementing)g(the)f(hooks.)448 3053 y(The)35 +b(easiest)f(way)g(of)h(doing)g(so)g(is)g(to)g(pack)f(them)h(into)g(a)f +(str)o(uctur)o(e)g Fm(Hooks)p Fp(,)k(ful\002ll-)448 3153 +y(ing)28 b(the)f(signatur)o(e)g(in)h(Figur)o(e)54 b(1.)44 +b(The)27 b(purposes)g(of)g(the)h(single)g(hooks)g(ar)o(e)e(listed)h(in) +448 3253 y(T)-8 b(able1.)30 b(A)22 b(hook)i(expects)e(as)g(ar)o(gument) +g(the)h(curr)o(ent)f(application)g(data)f(and)h(\226)g(except)448 +3352 y(for)28 b Fm(hookFinish)d Fp(\226)j(the)g(information)h +(belonging)g(to)f(the)g(signaled)g(event,)i(and)d(r)o(eturns)448 +3452 y(the)21 b(modi\002ed)g(application)g(data.)573 +3552 y(The)27 b(data)e(types)i(pr)o(oviding)g(the)g(event-speci\002c)f +(information)i(passed)e(to)h(a)f(hook)448 3651 y(ar)o(e)c(de\002ned)g +(by)h(str)o(uctur)o(e)f Fm(HookData)n Fp(.)32 b(Each)22 +b(information)i(item)f(contains)h(at)e(least)g(the)448 +3751 y(position)i(in)e(the)g(document)g(wher)o(e)g(the)g(event)f +(occurr)o(ed;)g(for)h(some)g(events)g(even)g(two)448 +3850 y(positions)h(ar)o(e)d(speci\002ed:)26 b(a)20 b(start)h(position)i +(and)e(an)g(end)g(position.)28 b(E.g.,)20 b(type)h Fm(ErrorInf)n(o)448 +3950 y Fp(describes)26 b(an)g(err)o(or)g(by)g(means)h(of)f(its)h +(position)h(and)e(an)g(err)o(or)g(description.)42 b(A)26 +b(start-)448 4050 y(tag)e(is)g(described)f(by)h(the)g(positions)h(of)f +(its)g(\002rst)g(and)g(last)f(character)-6 b(,)23 b(the)h(index)g(of)f +(the)448 4149 y(element,)32 b(the)f(list)f(of)g(attribute)f +(speci\002cations)i(the)f(eventual)g(spaces)f(following)i(the)448 +4249 y(element)d(name)f(and)h(a)f(boolean)h(\003ag,)h(indicating)f +(whether)g(it)f(is)h(an)g(empty-element)448 4349 y(tag:)656 +4482 y Fl(type)19 b Fm(ErrorInf)n(o)28 b Fj(=)h Fm(Errors)o(.P)l +(osition)e Fi(\003)j Fm(Errors)o(.Error)656 4574 y Fl(type)19 +b Fm(Star)s(tT)-9 b(agInf)n(o)26 b Fj(=)k Fm(Star)s(tEnd)d +Fi(\003)j Fm(int)f Fi(\003)h Fm(AttSpecList)e Fi(\003)i +Fm(UniChar)l(.Data)d Fi(\003)i Fm(bool)573 4716 y Fp(The)24 +b(information)i(set)f(pr)o(ovided)e(thr)o(ough)i Fo(fxp)p +Fp('s)f(hooks)i(is)f(suf)o(\002cient)f(for)h(pr)o(oduc-)448 +4815 y(ing)j(a)e(character)o(-by-character)d(identical)k(copy)g(of)g +(the)g(document)g(instance.)44 b(Except)448 4915 y(for)18 +b(white)g(space)f(and)g(parameter)g(entity)h(r)o(efer)o(ences)d(within) +k(declarations,)f(this)g(is)g(also)448 5015 y(possible)k(for)e(the)h +(DTD.)573 5114 y(In)j(addition)g(to)g(type)g Fm(AppData)n +Fp(,)g(a)g Fm(Hooks)f Fp(str)o(uctur)o(e)h(must)g(de\002ne)g(a)f(type)h +Fm(AppFinal)m Fp(.)448 5214 y(This)18 b(type)f(is)h(the)f(r)o(esult)g +(type)g(of)h(the)f(parser:)23 b(At)17 b(the)g(end)g(of)h(the)f +(document,)h(the)g(parser)448 5313 y(calls)e Fm(hookFinish)e +Fp(in)i(or)o(der)g(to)g Fo(\002nalize)g Fp(the)h(accumulated)e +(application)h(data.)23 b(This)16 b(is)h(use-)448 5413 +y(ful)23 b(because)e(values)h(of)g(type)g Fm(AppData)e +Fp(often)j(contain)g(auxiliary)e(information:)30 b(E.g.,)22 +b(if)1860 5662 y(1)p eop end +%%Page: 2 2 +TeXDict begin 2 1 bop 448 452 2865 4 v 448 3141 4 2690 +v 515 582 a Fl(signature)18 b Fm(Hooks)30 b Fj(=)622 +673 y Fl(sig)729 765 y(type)20 b Fm(AppData)729 856 y +Fl(type)g Fm(AppFinal)729 986 y Fl(v)o(al)f Fm(hookError)177 +b(:)25 b(AppData)j Fi(\003)i Fm(HookData.ErrorInf)n(o)183 +b Fi(!)30 b Fm(AppData)729 1078 y Fl(v)o(al)19 b Fm(hookW)m(ar)r(ning) +64 b(:)25 b(AppData)j Fi(\003)i Fm(HookData.W)m(ar)r(ningInf)n(o)70 +b Fi(!)30 b Fm(AppData)729 1208 y Fl(v)o(al)19 b Fm(hookStar)s(tT)-9 +b(ag)61 b(:)25 b(AppData)j Fi(\003)i Fm(HookData.Star)s(tT)-9 +b(agInf)n(o)67 b Fi(!)30 b Fm(AppData)729 1299 y Fl(v)o(al)19 +b Fm(hookEndT)-9 b(ag)89 b(:)25 b(AppData)j Fi(\003)i +Fm(HookData.EndT)-9 b(agInf)n(o)95 b Fi(!)30 b Fm(AppData)729 +1430 y Fl(v)o(al)19 b Fm(hookData)185 b(:)25 b(AppData)j +Fi(\003)i Fm(HookData.DataInf)n(o)191 b Fi(!)30 b Fm(AppData)729 +1521 y Fl(v)o(al)19 b Fm(hookCData)131 b(:)25 b(AppData)j +Fi(\003)i Fm(HookData.CDataInf)n(o)137 b Fi(!)30 b Fm(AppData)729 +1612 y Fl(v)o(al)19 b Fm(hookCharRef)64 b(:)25 b(AppData)j +Fi(\003)i Fm(HookData.CharRefInf)n(o)70 b Fi(!)30 b Fm(AppData)729 +1743 y Fl(v)o(al)19 b Fm(hookProcInst)69 b(:)25 b(AppData)j +Fi(\003)i Fm(HookData.ProcInstInf)n(o)75 b Fi(!)30 b +Fm(AppData)729 1834 y Fl(v)o(al)19 b Fm(hookComment)g(:)25 +b(AppData)j Fi(\003)i Fm(HookData.CommentInf)n(o)25 b +Fi(!)30 b Fm(AppData)729 1926 y Fl(v)o(al)19 b Fm(hookWhite)151 +b(:)25 b(AppData)j Fi(\003)i Fm(HookData.WhiteInf)n(o)157 +b Fi(!)30 b Fm(AppData)729 2017 y Fl(v)o(al)19 b Fm(hookDecl)194 +b(:)25 b(AppData)j Fi(\003)i Fm(HookData.DeclInf)n(o)200 +b Fi(!)30 b Fm(AppData)729 2147 y Fl(v)o(al)19 b Fm(hookDocT)-9 +b(ype)53 b(:)25 b(AppData)j Fi(\003)i Fm(HookData.DtdInf)n(o)233 +b Fi(!)30 b Fm(AppData)729 2239 y Fl(v)o(al)19 b Fm(hookSubset)110 +b(:)25 b(AppData)j Fi(\003)i Fm(HookData.SubsetInf)n(o)116 +b Fi(!)30 b Fm(AppData)729 2330 y Fl(v)o(al)19 b Fm(hookExtSubset)t(:)k +(AppData)28 b Fi(\003)i Fm(HookData.ExtSubsetInf)n(o)13 +b Fi(!)25 b Fm(AppData)729 2421 y Fl(v)o(al)19 b Fm(hookEndDtd)93 +b(:)25 b(AppData)j Fi(\003)i Fm(HookData.EndDtdInf)n(o)99 +b Fi(!)30 b Fm(AppData)729 2552 y Fl(v)o(al)19 b Fm(hookGenRef)85 +b(:)25 b(AppData)j Fi(\003)i Fm(HookData.GenRefInf)n(o)91 +b Fi(!)30 b Fm(AppData)729 2643 y Fl(v)o(al)19 b Fm(hookP)m(arRef)113 +b(:)25 b(AppData)j Fi(\003)i Fm(HookData.P)m(arRefInf)n(o)119 +b Fi(!)30 b Fm(AppData)729 2734 y Fl(v)o(al)19 b Fm(hookEntEnd)97 +b(:)25 b(AppData)j Fi(\003)i Fm(HookData.EntEndInf)n(o)103 +b Fi(!)30 b Fm(AppData)729 2865 y Fl(v)o(al)19 b Fm(hookXml)215 +b(:)25 b(AppData)j Fi(\003)i Fm(HookData.XmlInf)n(o)221 +b Fi(!)30 b Fm(AppData)729 2956 y Fl(v)o(al)19 b Fm(hookFinish)143 +b(:)25 b(AppData)926 b Fi(!)30 b Fm(AppFinal)622 3047 +y Fl(end)p 3309 3141 V 448 3144 2865 4 v 1315 3246 a +Fh(Figure)20 b(1:)g Fp(The)h Fm(Hooks)g Fp(signatur)o(e.)p +448 3290 V 448 3456 a(an)28 b(application)h(collects)f(information)i +(fr)o(om)d(the)i(document)g(entity,)h(it)f(must)g(ignor)o(e)448 +3555 y(all)20 b(events)h(occurring)g(within)g(entity)g(r)o(eplacement)e +(texts.)25 b(For)c(this)g(r)o(eason,)f(the)g(hooks)448 +3655 y(might)27 b(maintain)g(a)f(counter)g(indicating)g(the)h(nesting)g +(depth)f(of)g(included)g(entity)g(r)o(ef-)448 3755 y(er)o(ences.)j +Fm(hookFinish)19 b Fp(then)k(r)o(emoves)e(this)i(counter)f(because)g +(it)g(is)g(of)g(no)h(inter)o(est)f(to)g(the)448 3854 +y(application.)39 b(Another)26 b(example)e(for)h(the)h(bene\002ts)f(of) +h(\002nalization)f(is)h(the)f(following:)448 3954 y(An)j(application)g +(might)h(collect)f(section)g(titles)g(in)h(or)o(der)d(to)j(compile)f(a) +f(table)h(of)f(con-)448 4054 y(tents.)k(Since)23 b(the)f(application)h +(data)e(is)i(an)f(accumulating)g(parameter,)g(these)g(titles)h(ar)o(e) +448 4153 y(collected)i(in)g(r)o(everse)e(or)o(der)-6 +b(.)37 b Fm(AppFinal)21 b Fp(can)k(be)f(used)h(for)f(r)o(eestablishing) +h(the)g(original)448 4253 y(or)o(der)-6 b(.)448 4539 +y Fg(1)120 b(Functorizing)30 b(the)f(Parser)448 4728 +y Fp(The)i(parser)e(is)i(ther)o(efor)o(e)e(implemented)i(as)f(an)j(S)t +Fn(M)t(L)f Fo(functor)p Fp(,)h(expecting)d(the)h Fm(Hooks)448 +4827 y Fp(str)o(uctur)o(e)24 b(as)g(ar)o(gument.)35 b(The)24 +b(application)g(can)g(then)h(generate)e(several)g(instances)i(of)448 +4927 y(the)g(parser)e(for)h(dif)o(fer)o(ent)f(purposes.)36 +b(In)25 b(addition)f(to)h(the)f(hooks,)j(the)d(parser)g(functor)448 +5027 y(is)d(parametrized)e(with)j(thr)o(ee)e(other)h(str)o(uctur)o(es:) +448 5193 y Fl(Options)o Fh(:)41 b Fp(This)19 b(str)o(uctur)o(e)g +(supplies)g(the)h(parser)e(with)h(its)h(options.)26 b(It)19 +b(is)h(useful)f(to)g(have)656 5292 y(each)30 b(instance)h(of)g(the)g +(parser)f(r)o(un)h(with)h(its)f(own)h(set)f(of)g(options:)47 +b(E.g.,)34 b(X)t Fn(M)t(L)656 5392 y Fp(catalogs)25 b(fr)o(equently)h +(have)f(no)i(DTD.)40 b(Ther)o(efor)o(e)24 b(a)i(catalog)f(is)h(parsed)f +(in)h(non-)1860 5662 y(2)p eop end +%%Page: 3 3 +TeXDict begin 3 2 bop 452 452 2857 4 v 450 551 4 100 +v 1086 551 V 3305 551 V 450 573 V 519 543 a Fp(Hook)p +1086 573 V 432 w(X)t Fn(M)t(L)23 b Fp(Event)p 3305 573 +V 452 576 2857 4 v 450 676 4 100 v 1086 676 V 3305 676 +V 452 596 2857 4 v 450 696 4 100 v 1086 696 V 3305 696 +V 450 718 V 519 688 a Fm(hookError)p 1086 718 V 305 w +Fp(err)o(or)p 3305 718 V 450 817 V 519 787 a Fm(hookW)m(ar)r(ning)p +1086 817 V 192 w Fp(warning)p 3305 817 V 452 821 2857 +4 v 450 920 4 100 v 1086 920 V 3305 920 V 450 942 V 519 +912 a Fm(hookStar)s(tT)-9 b(ag)p 1086 942 V 189 w Fp(start-tag)p +3305 942 V 450 1042 V 519 1012 a Fm(hookEndT)g(ag)p 1086 +1042 V 217 w Fp(end-tag)p 3305 1042 V 452 1045 2857 4 +v 450 1145 4 100 v 1086 1145 V 3305 1145 V 450 1166 V +519 1136 a Fm(hookData)p 1086 1166 V 313 w Fp(segment)21 +b(of)g(character)e(data)p 3305 1166 V 450 1266 V 519 +1236 a Fm(hookCData)p 1086 1266 V 259 w Fp(CDA)-6 b(T)g(A)20 +b(section)p 3305 1266 V 450 1366 V 519 1336 a Fm(hookCharRef)p +1086 1366 V 192 w Fp(character)f(r)o(efer)o(ence)p 3305 +1366 V 452 1369 2857 4 v 450 1468 4 100 v 1086 1468 V +3305 1468 V 450 1490 V 519 1460 a Fm(hookProcInst)p 1086 +1490 V 197 w Fp(pr)o(ocessing)i(instr)o(uction)p 3305 +1490 V 450 1590 V 519 1560 a Fm(hookComment)p 1086 1590 +V 147 w Fp(comment)p 3305 1590 V 450 1690 V 519 1660 +a Fm(hookDecl)p 1086 1690 V 322 w Fp(element,)g(attribute,)f(notation)h +(or)g(entity)h(declaration)p 3305 1690 V 452 1693 2857 +4 v 450 1792 4 100 v 1086 1792 V 3305 1792 V 450 1814 +V 519 1784 a Fm(hookDocT)-9 b(ype)p 1086 1814 V 181 w +Fp(start)20 b(of)h(the)g(DTD)p 3305 1814 V 450 1914 V +519 1884 a Fm(hookSubset)p 1086 1914 V 238 w Fp(start)f(of)h(the)g +(internal)g(subset)p 3305 1914 V 450 2013 V 519 1984 +a Fm(hookExtSubset)p 1086 2013 V 130 w Fp(start)f(of)h(the)g(external)f +(subset)p 3305 2013 V 450 2113 V 519 2083 a Fm(hookEndDtd)p +1086 2113 V 221 w Fp(end)h(of)f(the)h(DTD)p 3305 2113 +V 452 2116 2857 4 v 450 2216 4 100 v 1086 2216 V 3305 +2216 V 450 2238 V 519 2208 a Fm(hookGenRef)p 1086 2238 +V 213 w Fp(general)f(entity)i(r)o(efer)o(ence)p 3305 +2238 V 450 2337 V 519 2308 a Fm(hookP)m(arRef)p 1086 +2337 V 241 w Fp(parameter)d(entity)i(r)o(efer)o(ence)p +3305 2337 V 450 2437 V 519 2407 a Fm(hookEntEnd)p 1086 +2437 V 225 w Fp(end)g(of)f(an)h(included)f(entity)p 3305 +2437 V 452 2440 2857 4 v 450 2540 4 100 v 1086 2540 V +3305 2540 V 450 2562 V 519 2532 a Fm(hookXml)p 1086 2562 +V 343 w Fp(start)g(of)h(the)g(document)g(entity)p 3305 +2562 V 450 2661 V 519 2631 a Fm(hookFinish)p 1086 2661 +V 271 w Fp(end)g(of)f(the)h(document)p 3305 2661 V 452 +2665 2857 4 v 1058 2767 a Fh(T)-9 b(able)19 b(1:)h Fp(The)h(hooks)h(in) +f Fo(fxp)f Fp(and)g(their)h(purposes.)p 448 2810 2865 +4 v 448 2913 V 448 3777 4 864 v 515 3044 a Fl(funsig)e +Fm(P)m(arse)h(\()g Fl(structure)f Fm(Dtd)172 b(:)25 b(Dtd)1018 +3135 y Fl(structure)19 b Fm(Hooks)77 b(:)25 b(Hooks)1018 +3226 y Fl(structure)19 b Fm(Resolv)n(e)h(:)25 b(Resolv)n(e)1018 +3318 y Fl(structure)19 b Fm(Options)30 b(:)25 b(Options)19 +b(\))30 b Fj(=)622 3409 y Fl(sig)729 3500 y(v)o(al)19 +b Fm(parseDocument)f(:)26 b(Ur)q(i.Ur)q(i)20 b(option)27 +b Fi(!)j Fm(Dtd.Dtd)19 b(option)1456 3592 y Fi(!)30 b +Fm(Hooks)o(.AppData)d Fi(!)j Fm(Hooks)o(.AppFinal)622 +3683 y Fl(end)p 3309 3777 V 448 3780 2865 4 v 1353 3882 +a Fh(Figure)21 b(2:)f Fp(The)g Fm(P)m(arser)g Fp(functor)-6 +b(.)p 448 3924 V 656 4090 a(validating)20 b(mode,)h(even)f(if)h(the)g +(main)g(document)g(is)g(validated.)448 4256 y Fl(Resolve)n +Fh(:)41 b Fp(This)34 b(str)o(uctur)o(e)g(pr)o(ovides)f(a)g(single)i +(function)f(for)g(r)o(esolving)g(an)f(external)656 4356 +y(identi\002er)21 b(to)g(a)f(URI:)839 4514 y Fl(v)o(al)f +Fm(resolv)n(eExtId)g(:)25 b(Base)o(.Exter)r(nalId)h Fi(!)k +Fm(Ur)q(i.Ur)q(i)656 4680 y Fp(In)20 b(the)f(simplest)h(case)f(this)h +(function)g(r)o(eturns)f(the)h(system)g(identi\002er)f(that)h(is)f +(part)656 4779 y(of)25 b(the)g(external)g(identi\002er)-6 +b(.)38 b(If)25 b(the)g(parser)f(supports)k(X)t Fn(M)t(L)f +Fp(catalogs,)f(however)-6 b(,)656 4879 y(this)21 b(is)g(the)g(function) +h(that)f(sear)o(ches)e(the)i(catalog.)448 5045 y Fl(Dtd)p +Fh(:)41 b Fp(The)29 b(implementation)h(of)f(the)g(DTD)g(tables)f(can)h +(be)f(pr)o(ovided)g(by)h(the)g(applica-)656 5145 y(tion.)d(In)19 +b(most)i(cases)e(this)h(is)f(the)h Fm(Dtd)e Fp(str)o(uctur)o(e)h(pr)o +(ovided)g(by)g Fo(fxp)p Fp(,)f(but)i(the)f(appli-)656 +5244 y(cation)25 b(can)f(also)h(pr)o(ovide)e(a)h(mor)o(e)g(ef)o +(\002cient)g(implementation,)i(or)f(enhance)f(the)656 +5344 y(functionality)e(of)g(the)g(DTD)g(tables.)28 b(For)21 +b(instance,)h(the)g(operations)g(on)g(the)g(DTD)1860 +5662 y(3)p eop end +%%Page: 4 4 +TeXDict begin 4 3 bop 656 531 a Fp(tables)21 b(might)h(be)e(wrapped)g +(into)i(functions)g(pr)o(oducing)f(debugging)g(or)h(statisti-)656 +631 y(cal)c(information.)26 b(On)19 b(the)g(other)f(hand,)h(the)g +(application)f(can)h Fo(hard-code)d Fp(element)656 731 +y(types)j(or)g(attributes)g(to)h(\002xed)e(indices.)25 +b(E.g.,)19 b(in)h(or)o(der)e(to)h(collect)g Fe(href)i +Fp(attributes)656 830 y(in)h(an)i(X)t Fn(H)t(T)t(M)t(L)h +Fp(document,)d(one)h(might)g(use)f(the)g(following)h(implementation)h +(of)656 930 y(the)d Fm(Dtd)f Fp(ar)o(gument)g(str)o(uctur)o(e:)839 +1088 y Fl(structure)e Fm(HrefDtd)29 b Fj(=)946 1179 y +Fl(struct)1053 1270 y(open)19 b Fm(Dtd)1053 1401 y Fl(v)o(al)g +Fm(hrefData)28 b Fj(=)h Fm(UniChar)l(.Str)q(ing2Data)16 +b(\224href\224)1053 1531 y Fl(fun)k Fm(initDtdT)-9 b(ab)o(les)16 +b(\(\))30 b Fj(=)1160 1622 y Fl(let)20 b(v)o(al)f Fm(dtd)29 +b Fj(=)h Fm(Dtd.initDtdT)-9 b(ab)o(les\(\))1268 1714 +y Fl(v)o(al)p 1391 1726 40 3 v 88 w Fj(=)30 b Fm(AttNot2Inde)n(x)17 +b(dtd)j(hrefData)1160 1805 y Fl(in)g Fm(dtd)1160 1896 +y Fl(end)1053 2027 y(v)o(al)f Fm(hrefIdx)29 b Fj(=)g +Fm(AttNot2Inde)n(x)17 b(\(initDtdT)-9 b(ab)o(les\(\)\))16 +b(hrefData)946 2118 y Fl(end)656 2284 y Fp(A)21 b Fe(href)i +Fp(attribute)e(will)h(then)g(always)g(have)f(index)g +Fm(hrefIdx)n Fp(;)h(sear)o(ching)f(and)g(com-)656 2384 +y(paring)37 b(can)h(be)f(done)h(with)h(this)f(constant)g(rather)f(than) +h(the)g(list)g(of)g(charac-)656 2483 y(ters)23 b Fm +([0wx68,0wx72,0wx65,)c(0wx66])p Fp(.)32 b(This)23 b(is)h(r)o(easonable) +e(also)h(because)f(element)656 2583 y(types)i(ar)o(e)g(passed)f(to)i +(the)g(hooks)h(by)e(means)h(of)f(their)h(indices)g(in)g(the)f(DTD,)h +(not)656 2683 y(by)c(their)g(names.)448 2849 y(The)32 +b(signatur)o(e)g(of)g(the)h(parser)e(functor)h(is)h(given)f(in)h(Figur) +o(e)e(2.)60 b(It)32 b(de\002nes)g(a)g(single)448 2948 +y(function)e Fm(parseDocument)c Fp(which,)31 b(given)e(an)f(optional)h +(URI)g(of)g(a)f(document)h(and)f(an)448 3048 y(optional)21 +b(DTD,)f(parses)f(that)h(document)h(\226)e(if)h(no)g(URI)g(is)g(given,) +h(the)f(document)g(is)g(r)o(ead)448 3148 y(fr)o(om)k(the)h(standar)o(d) +e(input.)37 b(It)24 b(r)o(eturns)g(the)h(\002nalized)f(value)f(of)i +(the)f(application)h(data)448 3247 y(r)o(eceived)19 b(in)j(its)f(thir)o +(d)f(ar)o(gument,)g(modi\002ed)h(by)g(the)g(hooks)h(during)f(parsing.) +573 3347 y(If)16 b(the)h(optional)g Fm(Dtd)f Fp(ar)o(gument)g(is)h +(given)f(as)h Fm(NONE)p Fp(,)g(the)f(parser)g(initializes)g(the)h(DTD) +448 3446 y(tables)25 b(with)i(the)e Fm(initDtdT)-9 b(ab)o(les)21 +b Fp(function.)40 b(In)26 b(this)g(case)f(hooks)i(have)e(no)h(access)f +(to)g(the)448 3546 y(DTD)19 b(because)d(it)i(is)h(not)f(pr)o(ovided)f +(as)g(an)h(ar)o(gument)f(to)h(them.)25 b(For)18 b(many)h(applications) +448 3646 y(this)24 b(is)f(not)g(necessary)f(indeed.)31 +b(If)22 b(the)h(hooks)h(need)e(to)h(access)f(the)h(DTD,)g(the)g +(applica-)448 3745 y(tion)g(must)g(initialize)f(the)g(tables)f(itself,) +h(incorporate)g(them)g(into)h(the)f(application)g(data)448 +3845 y(and)f(pass)f(them)h(to)h(the)e(parser)g(in)h(its)h +Fm(Dtd)e Fp(ar)o(gument.)448 4131 y Fg(2)120 b(Building)29 +b(Applications)h(with)f Fd(fxp)448 4320 y Fo(fxp)22 b +Fp(pr)o(ovides)g(a)g(rich)h(information)h(set)f(thr)o(ough)g(its)g +(hooks)h(interface.)31 b(Many)22 b(applica-)448 4419 +y(tions,)g(however)-6 b(,)20 b(ar)o(e)f(only)j(inter)o(ested)e(in)h(a)f +(subset)h(of)f(that)h(information:)26 b(A)20 b(formatter)448 +4519 y(is)27 b(pr)o(obably)f(not)i(inter)o(ested)e(in)h(comments,)i +(and)d(a)g(querying)i(tool)g(will)f(only)h(sear)o(ch)448 +4619 y(the)33 b(document)g(instance)f(and)g(ignor)o(e)h(the)g(DTD.)61 +b(Ther)o(efor)o(e)30 b(we)j(pr)o(ovide)e(a)h(set)h(of)448 +4718 y(hooks)22 b(that)f(simply)h(r)o(eturn)e(the)h(application)f(data) +g(unchanged:)1860 5662 y(4)p eop end +%%Page: 5 5 +TeXDict begin 5 4 bop 656 531 a Fl(structure)18 b Fm(IgnoreHooks)28 +b Fj(=)763 623 y Fl(struct)870 714 y(fun)20 b Fm(hookError\(a,)p +1425 726 40 3 v 37 w(\))30 b Fj(=)8 b Fm(a)870 805 y +Fl(fun)20 b Fm(hookW)m(ar)r(ning\(a,)p 1538 817 V 35 +w(\))30 b Fj(=)8 b Fm(a)870 897 y Fl(fun)20 b Fm(hookStar)s(tT)-9 +b(ag\(a,)p 1541 909 V 35 w(\))30 b Fj(=)9 b Fm(a)870 +988 y(...)870 1079 y Fl(fun)20 b Fm(hookXml\(a,)p 1387 +1091 V 37 w(\))30 b Fj(=)9 b Fm(a)870 1171 y Fl(fun)20 +b Fm(hookFinish)e(a)30 b Fj(=)9 b Fm(a)763 1262 y Fl(end)448 +1418 y Fp(These)26 b(functions)g(ar)o(e)e(polymorphic:)35 +b(They)26 b(do)f(not)h(depend)e(on)i(the)g(type)f(of)g(the)h(ap-)448 +1517 y(plication)g(data)f(and)g(can)h(thus)g(be)f(used)h(with)g +(arbitrary)f(types.)40 b(The)26 b(only)h(exception)448 +1617 y(is)k Fm(hookFinish)c Fp(which)j(r)o(equir)o(es)f(types)h +Fm(AppData)e Fp(and)h Fm(AppFinal)e Fp(to)j(be)g(equal.)53 +b(An)30 b(ap-)448 1717 y(plication)24 b(must)g(now)g(only)h(de\002ne)e +(the)g(hooks)i(that)e(have)g(a)g(dif)o(fer)o(ent)f(behavior)-6 +b(.)32 b(E.g.,)448 1816 y(the)20 b(hooks)i(for)e(a)f(validator)g(ar)o +(e)g(implemented)h(in)g(a)g(few)f(lines,)i(because)e(it)h(only)h +(prints)448 1916 y(err)o(ors)f(and)h(warnings)g(but)g(ignor)o(es)g(all) +f(other)h(events:)656 2063 y Fl(structure)d Fm(Chec)o(kHooks)30 +b Fj(=)763 2155 y Fl(struct)870 2246 y(open)20 b Fm(T)-9 +b(e)n(xtIO)19 b(Errors)i(IgnoreHooks)870 2376 y Fl(type)f +Fm(AppData)28 b Fj(=)8 b Fm(OS)o(.Process)o(.status)870 +2507 y Fl(fun)20 b Fm(message\(pos,msg\))29 b Fj(=)8 +b Fm(output\(stdErr,P)l(osition2Str)q(in)o(g)14 b(pos)2845 +2480 y Fc(^)2880 2507 y Fm(\224:)25 b(\224)2985 2480 +y Fc(^)3020 2507 y Fm(msg\))870 2637 y Fl(fun)20 b Fm(hookError)f(\()p +1381 2649 V 39 w(,\(pos,err\)\))28 b Fj(=)978 2728 y +Fm(OS)o(.Process)o(.f)n(ailure)16 b(bef)n(ore)j +(message\(pos,errorMessage)e(err\))870 2820 y Fl(fun)j +Fm(hookW)m(ar)r(ning)d(\(status,\(pos,w)o(ar)r(n\)\))27 +b Fj(=)978 2911 y Fm(status)20 b(bef)n(ore)e(message\(pos,w)o(ar)r +(ningMessage)e(w)o(ar)r(n\))763 3002 y Fl(end)448 3158 +y Fp(Except)25 b(for)h Fm(hookError)e Fp(and)h Fm(hookW)m(ar)r(ning)l +Fp(,)i(all)f(hooks)h(ar)o(e)d(taken)i(over)g(fr)o(om)f(str)o(uctur)o(e) +448 3258 y Fm(IgnoreHooks)n Fp(.)g(Another)c(example)f(is)h(the)f +(application)h(alr)o(eady)d(mentioned)j(on)g(page)f(4:)448 +3357 y(It)27 b(collects)g(all)f(attributes)g(named)g +Fe(href)p Fp(.)44 b(For)27 b(this)g(purpose)g(we)f(de\002ned)g(a)g(str) +o(uctur)o(e)448 3457 y Fm(HrefDtd)o Fp(,)17 b(har)o(d-coding)f(this)h +(attribute)g(name)f(to)h(a)g(constant)g(index)g Fm(hrefIdx)n +Fp(.)24 b(This)18 b(is)f(used)448 3557 y(in)22 b(the)e(de\002nition)i +(of)f(the)g(hooks:)656 3704 y Fl(structure)d Fm(HrefHooks)29 +b Fj(=)763 3796 y Fl(struct)870 3887 y(open)20 b Fm(Base)g(HrefDtd)f +(IgnoreHooks)870 4017 y Fl(type)h Fm(AppData)28 b Fj(=)h +Fm(UniChar)l(.V)-6 b(ector)18 b(list)870 4109 y Fl(type)i +Fm(AppFinal)27 b Fj(=)i Fm(AppData)870 4239 y Fl(fun)20 +b Fm(\002ndHref)g(nil)28 b Fj(=)i Fm(NONE)948 4330 y +Fi(j)37 b Fm(\002ndHref)20 b(\(\(idx,attPres\))8 b(::)g(rest\))27 +b Fj(=)1085 4422 y Fl(if)20 b Fm(idx)9 b Fa(<)-11 b(>)8 +b Fm(hrefIdx)20 b Fl(then)f Fm(\002ndHref)g(rest)1085 +4513 y Fl(else)g(case)g Fm(attPres)1338 4604 y Fl(of)29 +b Fm(AP)p 1542 4604 23 4 v 27 w(PRESENT\(v)n(ec,)p 2079 +4616 40 3 v 38 w(\))g Fi(\))h Fm(SOME)21 b(v)n(ec)1378 +4696 y Fi(j)38 b Fm(AP)p 1542 4696 23 4 v 27 w(DEF)-6 +b(A)l(UL)e(T\(v)n(ec,)p 2049 4708 40 3 v 37 w(\))30 b +Fi(\))g Fm(SOME)21 b(v)n(ec)1378 4787 y Fi(j)p 1438 4799 +V 107 w(\))30 b Fm(\002ndHref)19 b(rest)870 4917 y Fl(fun)h +Fm(hookStar)s(tT)-9 b(ag)18 b(\(a,\()p 1584 4929 V 38 +w(,)p 1643 4929 V 39 w(,attSpecs,)p 2016 4929 V 37 w(,)p +2074 4929 V 39 w(\)\))30 b Fj(=)978 5009 y Fl(case)19 +b Fm(\002ndHref)g(attSpecs)1065 5100 y Fl(of)29 b Fm(NONE)g +Fi(\))h Fm(a)1105 5191 y Fi(j)38 b Fm(SOME)20 b(x)31 +b Fi(\))f Fm(x)8 b(::)g(a)870 5322 y Fl(v)o(al)19 b Fm(hookFinish)28 +b Fj(=)h Fm(re)n(v)763 5413 y Fl(end)1860 5662 y Fp(5)p +eop end +%%Page: 6 6 +TeXDict begin 6 5 bop 448 531 a Fp(In)31 b(or)o(der)e(to)h(identify)h +(a)e Fe(href)j Fp(attribute,)f(function)g Fm(\002ndHref)e +Fp(need)h(only)h(compar)o(e)e(its)448 631 y(index)h(with)g +Fm(hrefIdx)o Fp(.)52 b(Note)29 b(that)h(due)f(to)h(the)g(accumulative)f +(natur)o(e)f(of)i(the)g Fm(AppData)448 731 y Fp(ar)o(gument,)e(the)e +(attribute)g(values)g(ar)o(e)f(collected)i(in)g(r)o(everse)e(or)o(der) +-6 b(.)41 b(Ther)o(efor)o(e)25 b(func-)448 830 y(tion)e +Fm(hookFinish)c Fp(is)j(de\002ned)f(to)h(be)g(the)f(list)i(r)o +(eversing)e(function)h(and)f(r)o(eestablishes)g(the)448 +930 y(original)h(or)o(der)-6 b(.)448 1216 y Fg(3)120 +b(Implementing)29 b(a)h(T)-13 b(ree-Based)27 b(Interface)448 +1405 y Fp(The)f(hooks)i(interface)d(of)h Fo(fxp)f Fp(its)h +(event-based;)h(nevertheless)f(a)g(tr)o(ee-based)e(interface)448 +1504 y(can)h(easily)g(be)g(implemented)h(on)g(top)f(of)g(the)h(hooks.) +40 b(W)-8 b(e)25 b(pr)o(esent)g(bellow)h(an)f(imple-)448 +1604 y(mentation)30 b(of)f(such)h(an)f(interface.)49 +b(For)30 b(br)o(evity)-9 b(,)30 b(it)f(has)g(only)h(a)f(r)o(estricted)f +(informa-)448 1704 y(tion)c(set:)30 b(It)24 b(ignor)o(es)f(the)g(DTD,)g +(comments,)i(pr)o(ocessing)e(instr)o(uctions)i(and)e(the)g(entity)448 +1803 y(str)o(uctur)o(e)i(of)h(the)g(document.)40 b(It)25 +b(is,)i(however)-6 b(,)27 b(easy)e(to)h(extend)f(the)g(implementation) +448 1903 y(to)c(supply)h(all)e(this)i(information.)573 +2003 y(The)k Fm(T)-9 b(ree)25 b Fp(data)g(type)h(is)h(simple:)37 +b(A)26 b(tr)o(ee)f(is)h(either)g(a)g(piece)g(of)g(text)g(or)g(an)g +(element)448 2102 y(consisting)35 b(of)d(a)g(start-tag)g(and)g(a)g +(list)h(of)f(tr)o(ees)g(as)g(content.)62 b(The)32 b(application)h(data) +448 2202 y(r)o(epr)o(esents)23 b(the)h(partial)f(document)i(tr)o(ee)e +(constr)o(ucted)i(so)f(far)-6 b(.)35 b(It)24 b(contains)h(in)f(its)h +Fm(stac)o(k)448 2301 y Fp(component)30 b(for)e(each)f(ancestor)h +(element)h(of)f(the)g(curr)o(ent)f(position,)32 b(its)c(start-tag)g +(to-)448 2401 y(gether)23 b(with)h(the)f(list)h(of)f(its)g(\226)g(alr)o +(eady)e(complete)i(\226)f(left)h(siblings;)i(component)g +Fm(content)448 2501 y Fp(holds)g(the)f(childr)o(en)f(of)h(the)g(curr)o +(ent)f(element)h(that)g(ar)o(e)f(known)i(so)f(far)-6 +b(.)34 b(At)24 b(the)g(begin-)448 2600 y(ning)i(of)e(the)g(parse)g +(both)h(components)g(ar)o(e)e(empty)-9 b(.)36 b(After)23 +b(the)i(whole)g(document)g(has)448 2700 y(been)18 b(parsed,)e(the)i +(stack)f(must)h(be)f(empty)h(and)f(a)g(single)h(element)g(tr)o(ee)e +(must)i(have)f(been)448 2800 y(constr)o(ucted.)34 b(In)24 +b(this)g(case)f(function)h Fm(hookFinish)d Fp(r)o(eturns)i(that)h +(element;)g(otherwise)g(it)448 2899 y(raises)d(an)f(exception.)573 +2999 y(The)25 b(thr)o(ee)g(functions)h Fm(hookData)n +Fp(,)g Fm(hookCData)d Fp(and)i Fm(hookCharRef)e Fp(add)h(the)i(piece)f +(of)448 3098 y(text)31 b(r)o(eported)e(to)i(them)f(to)h(the)g(content)g +(of)g(the)f(curr)o(ent)g(element.)55 b(The)30 b(hook)i(for)e(a)448 +3198 y(start-tag)21 b(pushes)i(that)f(tag)g(together)g(with)h(the)g +(content)g(of)f(the)g(curr)o(ent)f(element)i(onto)448 +3298 y(the)k(stack.)42 b(The)26 b(element)h(started)e(by)i(that)f(tag)g +(now)h(becomes)g(the)f(curr)o(ent)g(element.)448 3397 +y(Function)33 b Fm(hookEndT)-9 b(ag)28 b Fp(r)o(everses)i(the)h +(content)h(of)f(the)h(curr)o(ent)e(element)h(in)h(or)o(der)e(to)448 +3497 y(compensate)19 b(for)f(the)h(r)o(eversing)f(ef)o(fect)f(of)h +(accumulation.)25 b(Its)19 b(tag)f(is)h(popped)f(fr)o(om)g(the)448 +3597 y(stack)26 b(and)f(combined)g(with)i(its)f(content.)40 +b(The)25 b(constr)o(ucted)h(tr)o(ee)f(is)g(then)h(pr)o(epended)448 +3696 y(to)21 b(the)g(content)h(of)f(the)f(par)o(ent)g(element)h(which)h +(now)f(becomes)g(the)g(curr)o(ent)f(element.)448 3982 +y Fg(4)120 b(Other)28 b(examples)448 4171 y Fo(fxp)d +Fp(comes)h(with)h(a)e(few)h(application)f(examples)h(which)g(r)o +(esides)f(in)i(the)f Fe(src/Apps)i Fp(di-)448 4271 y(r)o(ectory)-9 +b(.)24 b(The)19 b(inter)o(ested)f(r)o(eader)f(can)h(\002nd)h(ther)o(e)f +(further)g(examples)h(of)g(using)g(the)g Fo(fxp)p Fp('s)448 +4370 y(pr)o(ogramming)i(interface.)448 4656 y Fg(References)490 +4845 y Fp([1])40 b(Andr)o(eas)132 b(Neumann.)i(Parsing)g(and)f +(Querying)h(XML)f(Docu-)628 4945 y(ments)116 b(in)g(SML.)d(University)j +(of)f(T)-7 b(rier)h(,)137 b(2000.)113 b(A)-8 b(vailable)114 +b(at)628 5044 y Fe(http://www.informat)q(ik.)q(uni)q(-tr)q(ier)q(.de)q +(/\230n)q(eum)q(ann)q(/Pa)q(pe)q(rs/)q(the)q(sis)q(.ps)q(.gz)1860 +5662 y Fp(6)p eop end +%%Page: 7 7 +TeXDict begin 7 6 bop 448 698 2865 4 v 448 5018 4 4321 +v 515 828 a Fl(structure)18 b Fm(T)-9 b(reeData)28 b +Fj(=)622 920 y Fl(struct)729 1011 y(e)o(xception)18 b +Fm(IllF)n(or)r(med)729 1141 y Fl(type)i Fm(T)-9 b(ag)28 +b Fj(=)i Fm(int)f Fi(\003)h Fm(HookData.AttSpecList)729 +1233 y Fl(datatype)18 b Fm(T)-9 b(ree)29 b Fj(=)g Fm(TEXT)20 +b Fl(of)g Fm(UniChar)l(.V)-6 b(ector)1263 1324 y Fi(j)37 +b Fm(ELEM)21 b Fl(of)f Fm(T)-9 b(ag)29 b Fi(\003)g Fm(Content)729 +1415 y Fl(withtype)19 b Fm(Content)28 b Fj(=)h Fm(T)-9 +b(ree)20 b(list)622 1507 y Fl(end)515 1728 y(structure)e +Fm(T)-9 b(reeHooks)29 b Fj(=)622 1820 y Fl(struct)729 +1911 y(open)19 b Fm(IgnoreHooks)g(T)-9 b(reeData)18 b(UniChar)729 +2041 y Fl(type)i Fm(AppData)27 b Fj(=)j Fm(Content)d +Fi(\003)j Fm(\(T)-9 b(ag)29 b Fi(\003)h Fm(Content\))18 +b(list)729 2133 y Fl(type)i Fm(AppFinal)27 b Fj(=)i Fm(T)-9 +b(ree)729 2263 y Fl(v)o(al)19 b Fm(appStar)s(t)28 b Fj(=)h +Fm(\(nil,nil\))729 2394 y Fl(fun)20 b Fm(hookStar)s(tT)-9 +b(ag)17 b(\(\(content,stac)o(k\),)h(\()p 1909 2406 40 +3 v 39 w(,elem,atts,)p 2295 2406 V 37 w(,empty\)\))29 +b Fj(=)836 2485 y Fl(if)21 b Fm(empty)f Fl(then)g Fm(\(ELEM)g +(\(\(elem,atts\),nil\))8 b(::)g(content,stac)n(k\))836 +2576 y Fl(else)20 b Fm(\(nil,\(\(elem,atts\),content\))7 +b(::)h(stac)o(k\))729 2707 y Fl(fun)20 b Fm(hookEndT)-9 +b(ag)18 b(\(\()p 1352 2719 V 38 w(,nil\),)p 1533 2719 +V 38 w(\))30 b Fj(=)f Fl(raise)19 b Fm(IllF)n(or)r(med)806 +2798 y Fi(j)38 b Fm(hookEndT)-9 b(ag)18 b(\(\(content,\(tag,content')o +(\))8 b(::)g(stac)o(k\),)p 2336 2810 V 33 w(\))30 b Fj(=)836 +2889 y Fm(\(ELEM)21 b(\(tag,re)n(v)d(content\))8 b(::)g(content',stac)o +(k\))729 3020 y Fl(fun)20 b Fm(hookData)f(\(\(content,stac)o(k\),\()p +1769 3032 V 36 w(,v)n(ec,)p 1961 3032 V 39 w(\)\))30 +b Fj(=)866 3111 y Fm(\(TEXT)20 b(v)n(ec)8 b(::)g(content,stac)o(k\))729 +3202 y Fl(fun)20 b Fm(hookCData)f(\(\(content,stac)o(k\),\()p +1823 3214 V 36 w(,v)n(ec\)\))30 b Fj(=)866 3294 y Fm(\(TEXT)20 +b(v)n(ec)8 b(::)g(content,stac)o(k\))729 3385 y Fl(fun)20 +b Fm(hookCharRef)e(\(\(content,stac)o(k\),\()p 1889 3397 +V 36 w(,c,)p 2004 3397 V 39 w(\)\))30 b Fj(=)866 3476 +y Fm(\(TEXT\(Data2V)-6 b(ector)17 b([c]\))8 b(::)g(content,stac)o(k\)) +729 3607 y Fl(fun)20 b Fm(hookFinish)e(\([elem],nil\))27 +b Fj(=)i Fm(elem)806 3698 y Fi(j)38 b Fm(hookFinish)p +1248 3710 V 87 w Fj(=)30 b Fl(raise)19 b Fm(IllF)n(or)r(med)622 +3789 y Fl(end)515 4011 y(structure)f Fm(P)m(arseT)-9 +b(ree)19 b(:)622 4102 y Fl(sig)729 4194 y(v)o(al)g Fm(parseT)-9 +b(ree)19 b(:)25 b(Ur)q(i.Ur)q(i)20 b(option)27 b Fi(!)j +Fm(Dtd.Dtd)19 b(option)28 b Fi(!)h Fm(T)-9 b(reeData.T)g(ree)622 +4285 y Fl(end)523 4376 y Fj(=)38 b Fl(struct)729 4468 +y(structure)19 b Fm(P)m(arser)29 b Fj(=)g Fm(P)m(arse)20 +b(\()h Fl(structure)d Fm(Dtd)182 b Fj(=)29 b Fm(Dtd)1670 +4559 y Fl(structure)18 b Fm(Hooks)87 b Fj(=)29 b Fm(T)-9 +b(reeHooks)1670 4650 y Fl(structure)18 b Fm(P)m(arserOptions)28 +b Fj(=)h Fm(P)m(arserOptions)19 b(\(\))1670 4742 y Fl(structure)f +Fm(Resolv)n(e)30 b Fj(=)f Fm(Resolv)n(eNull\))729 4833 +y Fl(fun)20 b Fm(parseT)-9 b(ree)18 b(ur)q(i)i(dtd)29 +b Fj(=)h Fm(P)m(arser)l(.parseDocument)17 b(ur)q(i)j(dtd)f(T)-9 +b(reeHooks)o(.appStar)s(t)622 4924 y Fl(end)p 3309 5018 +4 4321 v 448 5021 2865 4 v 852 5123 a Fh(Figure)20 b(3:)g +Fp(A)h(simple)g(tr)o(ee-based)d(interface)i(on)h(top)g(of)g(hooks.)p +448 5167 V 1860 5662 a(7)p eop end +%%Trailer + +userdict /end-hook known{end-hook}if +%%EOF diff --git a/fxp/doc/ball-shadow.jpg b/fxp/doc/ball-shadow.jpg new file mode 100644 index 0000000000000000000000000000000000000000..54e3c7941fd7923a1fe51562b3be1b9a3b989e56 GIT binary patch literal 494 zcmex=^(PF6}rMnOeST|r4lSw=>~TvNxu(8R<bIbPXRz2H8$!it$JbX0%Gbr@6%B~FVQc<;3W=OX!Jh75jdrhv? zu`4sbZI|IVcXi7rGhOx%?(V-hWj`NWReWle)rY->1v^&$T)8oprPO9d?%KPjauuyZ zT7FA=HBB-6Ch?ZFdc40Q???fqnSfDeV7m0ssrHgjWCn literal 0 HcmV?d00001 diff --git a/fxp/doc/doc.ps b/fxp/doc/doc.ps new file mode 100644 index 0000000..5624579 --- /dev/null +++ b/fxp/doc/doc.ps @@ -0,0 +1,821 @@ +%!PS-Adobe-2.0 +%%Creator: dvips(k) 5.86 Copyright 1999 Radical Eye Software +%%Title: doc.dvi +%%Pages: 7 +%%PageOrder: Ascend +%%BoundingBox: 0 0 596 842 +%%DocumentFonts: Palatino-Roman Palatino-Italic Helvetica Helvetica-Bold +%%+ Palatino-Bold Symbol Courier Palatino-BoldItalic EURM10 +%%DocumentPaperSizes: a4 +%%EndComments +%DVIPSWebPage: (www.radicaleye.com) +%DVIPSCommandLine: dvips doc.dvi +%DVIPSParameters: dpi=1200, compressed +%DVIPSSource: TeX output 2001.02.26:1647 +%%BeginProcSet: texc.pro +%! +/TeXDict 300 dict def TeXDict begin/N{def}def/B{bind def}N/S{exch}N/X{S +N}B/A{dup}B/TR{translate}N/isls false N/vsize 11 72 mul N/hsize 8.5 72 +mul N/landplus90{false}def/@rigin{isls{[0 landplus90{1 -1}{-1 1}ifelse 0 +0 0]concat}if 72 Resolution div 72 VResolution div neg scale isls{ +landplus90{VResolution 72 div vsize mul 0 exch}{Resolution -72 div hsize +mul 0}ifelse TR}if Resolution VResolution vsize -72 div 1 add mul TR[ +matrix currentmatrix{A A round sub abs 0.00001 lt{round}if}forall round +exch round exch]setmatrix}N/@landscape{/isls true N}B/@manualfeed{ +statusdict/manualfeed true put}B/@copies{/#copies X}B/FMat[1 0 0 -1 0 0] +N/FBB[0 0 0 0]N/nn 0 N/IEn 0 N/ctr 0 N/df-tail{/nn 8 dict N nn begin +/FontType 3 N/FontMatrix fntrx N/FontBBox FBB N string/base X array +/BitMaps X/BuildChar{CharBuilder}N/Encoding IEn N end A{/foo setfont}2 +array copy cvx N load 0 nn put/ctr 0 N[}B/sf 0 N/df{/sf 1 N/fntrx FMat N +df-tail}B/dfs{div/sf X/fntrx[sf 0 0 sf neg 0 0]N df-tail}B/E{pop nn A +definefont setfont}B/Cw{Cd A length 5 sub get}B/Ch{Cd A length 4 sub get +}B/Cx{128 Cd A length 3 sub get sub}B/Cy{Cd A length 2 sub get 127 sub} +B/Cdx{Cd A length 1 sub get}B/Ci{Cd A type/stringtype ne{ctr get/ctr ctr +1 add N}if}B/id 0 N/rw 0 N/rc 0 N/gp 0 N/cp 0 N/G 0 N/CharBuilder{save 3 +1 roll S A/base get 2 index get S/BitMaps get S get/Cd X pop/ctr 0 N Cdx +0 Cx Cy Ch sub Cx Cw add Cy setcachedevice Cw Ch true[1 0 0 -1 -.1 Cx +sub Cy .1 sub]/id Ci N/rw Cw 7 add 8 idiv string N/rc 0 N/gp 0 N/cp 0 N{ +rc 0 ne{rc 1 sub/rc X rw}{G}ifelse}imagemask restore}B/G{{id gp get/gp +gp 1 add N A 18 mod S 18 idiv pl S get exec}loop}B/adv{cp add/cp X}B +/chg{rw cp id gp 4 index getinterval putinterval A gp add/gp X adv}B/nd{ +/cp 0 N rw exit}B/lsh{rw cp 2 copy get A 0 eq{pop 1}{A 255 eq{pop 254}{ +A A add 255 and S 1 and or}ifelse}ifelse put 1 adv}B/rsh{rw cp 2 copy +get A 0 eq{pop 128}{A 255 eq{pop 127}{A 2 idiv S 128 and or}ifelse} +ifelse put 1 adv}B/clr{rw cp 2 index string putinterval adv}B/set{rw cp +fillstr 0 4 index getinterval putinterval adv}B/fillstr 18 string 0 1 17 +{2 copy 255 put pop}for N/pl[{adv 1 chg}{adv 1 chg nd}{1 add chg}{1 add +chg nd}{adv lsh}{adv lsh nd}{adv rsh}{adv rsh nd}{1 add adv}{/rc X nd}{ +1 add set}{1 add clr}{adv 2 chg}{adv 2 chg nd}{pop nd}]A{bind pop} +forall N/D{/cc X A type/stringtype ne{]}if nn/base get cc ctr put nn +/BitMaps get S ctr S sf 1 ne{A A length 1 sub A 2 index S get sf div put +}if put/ctr ctr 1 add N}B/I{cc 1 add D}B/bop{userdict/bop-hook known{ +bop-hook}if/SI save N @rigin 0 0 moveto/V matrix currentmatrix A 1 get A +mul exch 0 get A mul add .99 lt{/QV}{/RV}ifelse load def pop pop}N/eop{ +SI restore userdict/eop-hook known{eop-hook}if showpage}N/@start{ +userdict/start-hook known{start-hook}if pop/VResolution X/Resolution X +1000 div/DVImag X/IEn 256 array N 2 string 0 1 255{IEn S A 360 add 36 4 +index cvrs cvn put}for pop 65781.76 div/vsize X 65781.76 div/hsize X}N +/p{show}N/RMat[1 0 0 -1 0 0]N/BDot 260 string N/Rx 0 N/Ry 0 N/V{}B/RV/v{ +/Ry X/Rx X V}B statusdict begin/product where{pop false[(Display)(NeXT) +(LaserWriter 16/600)]{A length product length le{A length product exch 0 +exch getinterval eq{pop true exit}if}{pop}ifelse}forall}{false}ifelse +end{{gsave TR -.1 .1 TR 1 1 scale Rx Ry false RMat{BDot}imagemask +grestore}}{{gsave TR -.1 .1 TR Rx Ry scale 1 1 false RMat{BDot} +imagemask grestore}}ifelse B/QV{gsave newpath transform round exch round +exch itransform moveto Rx 0 rlineto 0 Ry neg rlineto Rx neg 0 rlineto +fill grestore}B/a{moveto}B/delta 0 N/tail{A/delta X 0 rmoveto}B/M{S p +delta add tail}B/b{S p tail}B/c{-4 M}B/d{-3 M}B/e{-2 M}B/f{-1 M}B/g{0 M} +B/h{1 M}B/i{2 M}B/j{3 M}B/k{4 M}B/w{0 rmoveto}B/l{p -4 w}B/m{p -3 w}B/n{ +p -2 w}B/o{p -1 w}B/q{p 1 w}B/r{p 2 w}B/s{p 3 w}B/t{p 4 w}B/x{0 S +rmoveto}B/y{3 2 roll p a}B/bos{/SS save N}B/eos{SS restore}B end + +%%EndProcSet +%%BeginProcSet: 8r.enc +% @@psencodingfile@{ +% author = "S. Rahtz, P. MacKay, Alan Jeffrey, B. Horn, K. Berry", +% version = "0.6", +% date = "1 July 1998", +% filename = "8r.enc", +% email = "tex-fonts@@tug.org", +% docstring = "Encoding for TrueType or Type 1 fonts +% to be used with TeX." +% @} +% +% Idea is to have all the characters normally included in Type 1 fonts +% available for typesetting. This is effectively the characters in Adobe +% Standard Encoding + ISO Latin 1 + extra characters from Lucida. +% +% Character code assignments were made as follows: +% +% (1) the Windows ANSI characters are almost all in their Windows ANSI +% positions, because some Windows users cannot easily reencode the +% fonts, and it makes no difference on other systems. The only Windows +% ANSI characters not available are those that make no sense for +% typesetting -- rubout (127 decimal), nobreakspace (160), softhyphen +% (173). quotesingle and grave are moved just because it's such an +% irritation not having them in TeX positions. +% +% (2) Remaining characters are assigned arbitrarily to the lower part +% of the range, avoiding 0, 10 and 13 in case we meet dumb software. +% +% (3) Y&Y Lucida Bright includes some extra text characters; in the +% hopes that other PostScript fonts, perhaps created for public +% consumption, will include them, they are included starting at 0x12. +% +% (4) Remaining positions left undefined are for use in (hopefully) +% upward-compatible revisions, if someday more characters are generally +% available. +% +% (5) hyphen appears twice for compatibility with both +% ASCII and Windows. +% +/TeXBase1Encoding [ +% 0x00 (encoded characters from Adobe Standard not in Windows 3.1) + /.notdef /dotaccent /fi /fl + /fraction /hungarumlaut /Lslash /lslash + /ogonek /ring /.notdef + /breve /minus /.notdef +% These are the only two remaining unencoded characters, so may as +% well include them. + /Zcaron /zcaron +% 0x10 + /caron /dotlessi +% (unusual TeX characters available in, e.g., Lucida Bright) + /dotlessj /ff /ffi /ffl + /.notdef /.notdef /.notdef /.notdef + /.notdef /.notdef /.notdef /.notdef + % very contentious; it's so painful not having quoteleft and quoteright + % at 96 and 145 that we move the things normally found there to here. + /grave /quotesingle +% 0x20 (ASCII begins) + /space /exclam /quotedbl /numbersign + /dollar /percent /ampersand /quoteright + /parenleft /parenright /asterisk /plus /comma /hyphen /period /slash +% 0x30 + /zero /one /two /three /four /five /six /seven + /eight /nine /colon /semicolon /less /equal /greater /question +% 0x40 + /at /A /B /C /D /E /F /G /H /I /J /K /L /M /N /O +% 0x50 + /P /Q /R /S /T /U /V /W + /X /Y /Z /bracketleft /backslash /bracketright /asciicircum /underscore +% 0x60 + /quoteleft /a /b /c /d /e /f /g /h /i /j /k /l /m /n /o +% 0x70 + /p /q /r /s /t /u /v /w + /x /y /z /braceleft /bar /braceright /asciitilde + /.notdef % rubout; ASCII ends +% 0x80 + /.notdef /.notdef /quotesinglbase /florin + /quotedblbase /ellipsis /dagger /daggerdbl + /circumflex /perthousand /Scaron /guilsinglleft + /OE /.notdef /.notdef /.notdef +% 0x90 + /.notdef /.notdef /.notdef /quotedblleft + /quotedblright /bullet /endash /emdash + /tilde /trademark /scaron /guilsinglright + /oe /.notdef /.notdef /Ydieresis +% 0xA0 + /.notdef % nobreakspace + /exclamdown /cent /sterling + /currency /yen /brokenbar /section + /dieresis /copyright /ordfeminine /guillemotleft + /logicalnot + /hyphen % Y&Y (also at 45); Windows' softhyphen + /registered + /macron +% 0xD0 + /degree /plusminus /twosuperior /threesuperior + /acute /mu /paragraph /periodcentered + /cedilla /onesuperior /ordmasculine /guillemotright + /onequarter /onehalf /threequarters /questiondown +% 0xC0 + /Agrave /Aacute /Acircumflex /Atilde /Adieresis /Aring /AE /Ccedilla + /Egrave /Eacute /Ecircumflex /Edieresis + /Igrave /Iacute /Icircumflex /Idieresis +% 0xD0 + /Eth /Ntilde /Ograve /Oacute + /Ocircumflex /Otilde /Odieresis /multiply + /Oslash /Ugrave /Uacute /Ucircumflex + /Udieresis /Yacute /Thorn /germandbls +% 0xE0 + /agrave /aacute /acircumflex /atilde + /adieresis /aring /ae /ccedilla + /egrave /eacute /ecircumflex /edieresis + /igrave /iacute /icircumflex /idieresis +% 0xF0 + /eth /ntilde /ograve /oacute + /ocircumflex /otilde /odieresis /divide + /oslash /ugrave /uacute /ucircumflex + /udieresis /yacute /thorn /ydieresis +] def + +%%EndProcSet +%%BeginProcSet: texps.pro +%! +TeXDict begin/rf{findfont dup length 1 add dict begin{1 index/FID ne 2 +index/UniqueID ne and{def}{pop pop}ifelse}forall[1 index 0 6 -1 roll +exec 0 exch 5 -1 roll VResolution Resolution div mul neg 0 0]/Metrics +exch def dict begin Encoding{exch dup type/integertype ne{pop pop 1 sub +dup 0 le{pop}{[}ifelse}{FontMatrix 0 get div Metrics 0 get div def} +ifelse}forall Metrics/Metrics currentdict end def[2 index currentdict +end definefont 3 -1 roll makefont/setfont cvx]cvx def}def/ObliqueSlant{ +dup sin S cos div neg}B/SlantFont{4 index mul add}def/ExtendFont{3 -1 +roll mul exch}def/ReEncodeFont{CharStrings rcheck{/Encoding false def +dup[exch{dup CharStrings exch known not{pop/.notdef/Encoding true def} +if}forall Encoding{]exch pop}{cleartomark}ifelse}if/Encoding exch def} +def end + +%%EndProcSet +TeXDict begin 39158280 55380996 1000 1200 1200 (doc.dvi) +@start +%DVIPSBitmapFont: Fa cmmi10 9.37793 2 +/Fa 2 63 df<1D70F401F8F407FC1C1F1C7F983801FFF8090713F0093F13C098B5120008 +0313FC080F13F0083F13C097B5C7FC070313FC070F13E0073F1380DFFFFEC8FC060313F8 +060F13E0063F1380DEFFFEC9FC050713F8051F13E0057F13804C4848CAFC040713F8041F +13E0047F1380922601FFFCCBFC030713F0031F13C0037F90CCFC913801FFFC020713F002 +1F13C091B5CDFC010313FC010F13F0013F13C090B5CEFC000313FC000F13F0003F138048 +48CFFCEAFFF813E013F8EA7FFE6C6C7E000F13F0000313FCC613FF013F13C0010F13F001 +0313FC010013FF021F13C0020713F0020113FC6E6CB4FC031F13C0030713F0030113FC6F +6CB47E041F13E0040713F8040113FE706C6C7E051F13E0050713F8050013FE95383FFF80 +060F13E0060313F8060013FE96383FFF80070F13E0070313FC070013FF083F13C0080F13 +F0080313FC080013FF093F13C0090713F0090113F89838007FFC1C1F1C07F401F8F40070 +5E5B73D379>60 D<1238127EB47E13E013F8EA7FFE6C6C7E000F13F0000313FCC613FF01 +3F13C0010F13F0010313FC010013FF021F13C0020713F0020113FC6E6CB4FC031F13C003 +0713F0030113FC6F6CB47E041F13E0040713F8040113FE706C6C7E051F13E0050713F805 +0013FE95383FFF80060F13E0060313F8060013FE96383FFF80070F13E0070313FC070013 +FF083F13C0080F13F0080313FC080013FF093F13C0090713F0090113F89838007FFC1C1F +1C7F983801FFF8090713F0093F13C098B51200080313FC080F13F0083F13C097B5C7FC07 +0313FC070F13E0073F1380DFFFFEC8FC060313F8060F13E0063F1380DEFFFEC9FC050713 +F8051F13E0057F13804C4848CAFC040713F8041F13E0047F1380922601FFFCCBFC030713 +F0031F13C0037F90CCFC913801FFFC020713F0021F13C091B5CDFC010313FC010F13F001 +3F13C090B5CEFC000313FC000F13F0003F13804848CFFCEAFFF813E01380007ED0FC1238 +5E5B73D379>62 D E +%EndDVIPSBitmapFont +%DVIPSBitmapFont: Fc cmsy10 6.25195 1 +/Fc 1 95 df<153CA2157EA215FFA34A7FA24A7F15E702077F15C3A2020F7F1581021F7F +15004A7F023E137CA2027E137E027C133E02FC133F4A7FA20101814A130F0103814A1307 +0107814A1303A2010F814A1301011F8191C8FC4981013E157CA2017E157E017C153E01FC +153F49810001178049150FA2000317C0491507000717E0491503000F17F0491501A2001F +17F890CAFC4817FC003E177C007E177E007C173EA200FC173F48171FA20070170E38417A +BE45>94 D E +%EndDVIPSBitmapFont +/Fd 135[120 7[133 9[80 102[{TeXBase1Encoding ReEncodeFont}3 +239.103 /Palatino-BoldItalic rf /Fe 140[85 85 1[85 7[85 +1[85 85 1[85 33[85 17[85 47[{ +.85 ExtendFont TeXBase1Encoding ReEncodeFont}9 166.044 +/Courier rf /Fg 133[120 1[120 199 1[146 80 106 93 1[146 +133 146 213 80 2[80 146 133 93 120 146 106 1[120 12[159 +1[173 1[146 199 5[93 2[133 3[159 186 12[120 120 120 120 +3[80 45[{TeXBase1Encoding ReEncodeFont}33 239.103 /Palatino-Bold +rf /Fh 138[101 2[65 5[55 2[55 1[92 1[83 2[101 83 12[111 +13[92 11[42 6[83 83 83 49[{TeXBase1Encoding ReEncodeFont}14 +166.044 /Palatino-Bold rf +%DVIPSBitmapFont: Fi cmsy10 9.37793 4 +/Fi 4 107 df<153E157F4B7EA86FC9FCA400081708003E173ED87F8016FF486C4B1380 +6D5D01F8150F6D5D6C6C4B1300273FFF803EEBFFFE6C01C0495B000701F0010713F0C601 +F8491380D93FFC4948C7FCD90FFFEB7FF801039038BEFFE0010090B51280023F49C8FC02 +0F13F8020313E002001380020313E0020F13F8023F13FE91B67E010301BE13E0010F9038 +3E7FF8D93FFCEB1FFED9FFF86D6C7E000701F06D13F0001F01C0010113FC4801806D7F27 +7FFE007FEB3FFF48486F1380498101E0150349816C486F1300003EC7153E00081708C892 +C7FCA44B7EA86FC9FC153E394376C74E>3 D<1E3F8BA48B1E1FA38B1E0F8BA21E078B1E +038B1E018B787EA2797E797EA2797E797E8C797E797E797E797FF87FE07A7E7A7EF80FFE +7A7E7A13C0003FC212F04821FEC41280A36CF9FE006C21F0D3000313C05690C7FC565AF8 +1FF8565A565AF8FF805590C8FC555A555A555A68555A555AA2555A55C9FCA2545A671E03 +671E07671E0FA2671E1F67A31E3F67A49CCAFC895177CE9C>33 D<1C7E1CFF88891C3F89 +1C1F891C0F89767E1C0389767E1C0089777E777E777EA2777E777E777E777E003FBFFC48 +8AC012E08B8B6C8A6C1EFFD100017F7813E0F73FF0F71FFC79B4FC0D0313C07913F09C38 +007FFC7AB47E0E0F13E00E0313FC0E00EBFF80213F9EB5FC0E03EBFC000E0F13E00E3F13 +80E67FFCC7FC9C3801FFF05513C00D0F90C8FCF71FFCF73FF0F7FFE0541380003FC0C9FC +481EFCC05A67676C1E806C9BCAFCD0EA01FE535A535A535A535AA2535A535A53CBFC651C +01525A651C07525A651C1F651C3F651C7F9ACCFC641C7E895777D19C>41 +D<1238127C12FEB3B3B3B3B3B3B3B3A8127C1238079C6EF42B>106 +D E +%EndDVIPSBitmapFont +%DVIPSBitmapFont: Fj cmr10 9.37793 1 +/Fj 1 62 df<003FBE12F0481DF8BF12FCA36C1DF86C1DF0D2FCB3A7003FBE12F0481DF8 +BF12FCA36C1DF86C1DF0662777B979>61 D E +%EndDVIPSBitmapFont +/Fl 134[83 83 116 83 91 50 83 58 1[91 91 91 1[42 2[42 +91 91 50 83 91 83 1[83 14[108 2[116 10[108 68[{ +TeXBase1Encoding ReEncodeFont}23 149.44 /Helvetica-Bold +rf /Fm 107[50 26[75 75 108 75 83 42 75 50 1[83 83 83 +124 33 75 1[33 83 83 42 83 83 75 83 83 3[42 1[42 2[100 +141 100 108 91 100 108 1[100 116 108 124 83 2[42 108 +116 91 100 108 108 100 100 6[42 1[83 83 83 83 2[83 1[83 +1[42 1[42 2[50 50 33 36[75 2[{TeXBase1Encoding ReEncodeFont}60 +149.44 /Helvetica rf /Fn 171[81 6[126 81 3[111 72[{ +TeXBase1Encoding ReEncodeFont}4 132.835 /Palatino-Roman +rf /Fo 133[74 1[83 2[92 55 65 65 1[83 74 92 1[46 74 1[46 +83 1[46 65 83 68 1[74 51[55 42[88 2[{TeXBase1Encoding ReEncodeFont}20 +166.044 /Palatino-Italic rf /Fp 105[83 27[83 92 86 138 +94 100 54 70 66 93 100 91 97 147 48 92 1[48 97 92 55 +80 101 74 92 83 3[55 1[55 2[111 166 1[129 102 87 111 +2[131 138 157 101 1[55 56 138 1[92 101 129 118 1[129 +5[42 42 83 83 83 83 83 83 83 83 83 83 101 42 55 42 4[46 +35[101 100 2[{TeXBase1Encoding ReEncodeFont}65 166.044 +/Palatino-Roman rf /Fq 135[103 166 1[120 65 84 79 1[120 +109 116 176 58 2[58 116 111 66 95 122 88 1[100 12[122 +105 2[120 1[166 9[154 141 1[155 6[50 1[100 5[100 1[100 +1[50 6[55 39[{TeXBase1Encoding ReEncodeFont}32 199.253 +/Palatino-Roman rf /Fr 135[143 7[143 9[80 102[{ +TeXBase1Encoding ReEncodeFont}3 286.924 /Palatino-Italic +rf /Fs 139[94 122 113 1[172 157 167 253 83 2[83 167 160 +96 137 1[127 1[143 12[176 3[173 6[97 7[223 25[80 39[{ +TeXBase1Encoding ReEncodeFont}20 286.924 /Palatino-Roman +rf end +%%EndProlog +%%BeginSetup +%%Feature: *Resolution 1200dpi +TeXDict begin +%%BeginPaperSize: a4 +a4 +%%EndPaperSize + +%%EndSetup +%%Page: 1 1 +1 0 bop 1314 1760 a Fs(The)72 b Fr(fxp)p Fs('s)f(Application)k(Pr)-5 +b(ogramming)73 b(Interface)3624 2744 y Fq(August)50 b(2000)1561 +3310 y(Note:)61 b(The)50 b(following)f(is)g(an)g(excerpt)h(fr)l(om)f +(the)h(Chapter)e(2)h(Section)h(8)1312 3528 y(of)g(the)g(Andr)l(eas)g +(Neumann's)g(Ph.D.)g(Thesis.)1561 3926 y Fp(The)d Fo(fxp)p +Fp('s)h(application)g(interface)f(is)h(a)g(functional)g(variant)f(of)h +(an)g(event-based)f(in-)1312 4126 y(terface)60 b(that)h(vitally)h(r)m +(elies)f(on)k(S)8 b Fn(M)g(L)t Fp('s)62 b(parametrized)e(modules)h(for) +g(customization.)1312 4325 y(Its)52 b(information)e(set)h(includes)h +(all)g(r)m(equir)m(ed)f(and)g(most)g(optional)g(information)f(items) +1312 4524 y(of)41 b(the)k(X)8 b Fn(M)g(L)46 b Fp(information)40 +b(set)i([1].)1561 4723 y(The)34 b(application)h(de\002nes)g(a)g(data)h +(type)e Fm(AppData)h Fp(r)m(epr)m(esenting)e(the)h(part)h(of)g(its)h +(state)1312 4923 y(af)m(fected)61 b(by)g(the)f(event)g(handlers.)109 +b(W)-15 b(e)61 b(call)g(this)h(information)e(the)g Fo(application)h +(data)p Fp(.)1312 5122 y(During)40 b(parsing,)g(a)h(value)g(of)f(this)i +(type)e(is)i(maintained)e(by)h(the)f(parser)-12 b(.)49 +b(Upon)40 b(trigger)m(-)1312 5321 y(ing)50 b(an)h(event,)f(the)g(event) +f(handler)h(r)m(eceives)f(the)h(application)g(data)h(as)g(an)f +(additional)1312 5520 y(parameter)60 b(and)i(r)m(eturns)f(it)i(\226)f +(possibly)h(modi\002ed)g(\226)f(to)g(the)g(parser)-12 +b(.)112 b(The)61 b(modi\002ed)1312 5720 y(application)48 +b(data)h(is)h(then)d(an)h(ar)m(gument)g(to)g(the)g(next)g(event,)g(and) +h(so)g(forth.)71 b(In)48 b(or)m(der)1312 5919 y(to)g(distinguish)i +(this)e(kind)h(of)f(event)f(handlers)h(fr)m(om)f(the)g(imperative)g +(variant)h(we)g(call)1312 6118 y(them)34 b Fo(hooks)p +Fp(.)48 b(The)34 b(ef)m(fects)h(of)h(all)g(hooks)f(ar)m(e)f(thus)i +(accumulated)f(into)g(one)f(value)h(of)g(type)1312 6317 +y Fm(AppData)o Fp(.)1561 6517 y(In)50 b(or)m(der)g(to)g(implement)f +(hooks)i(in)f Fo(fxp)p Fp(,)j(the)d(parser)f(must)i(be)f(pr)m(ovided)h +(with)g(the)1312 6716 y(type)j(of)g(the)f(application)h(data)h(and)f +(with)g(the)g(functions)g(implementing)f(the)g(hooks.)1312 +6915 y(The)68 b(easiest)h(way)h(of)f(doing)g(so)g(is)h(to)f(pack)g +(them)e(into)i(a)g(str)o(uctur)m(e)f Fm(Hooks)p Fp(,)75 +b(ful\002ll-)1312 7114 y(ing)54 b(the)g(signatur)m(e)g(in)h(Figur)m(e) +108 b(1.)90 b(The)53 b(purposes)h(of)g(the)g(single)g(hooks)g(ar)m(e)g +(listed)h(in)1312 7314 y(T)-15 b(able1.)61 b(A)45 b(hook)f(expects)g +(as)h(ar)m(gument)f(the)h(curr)m(ent)e(application)i(data)h(and)f(\226) +g(except)1312 7513 y(for)55 b Fm(hookFinish)i Fp(\226)e(the)h +(information)e(belonging)i(to)g(the)f(signaled)i(event,)g(and)f(r)m +(eturns)1312 7712 y(the)41 b(modi\002ed)h(application)f(data.)1561 +7911 y(The)52 b(data)j(types)e(pr)m(oviding)h(the)f(event-speci\002c)f +(information)h(passed)h(to)f(a)h(hook)1312 8111 y(ar)m(e)44 +b(de\002ned)i(by)g(str)o(uctur)m(e)e Fm(HookData)p Fp(.)63 +b(Each)45 b(information)g(item)g(contains)g(at)h(least)g(the)1312 +8310 y(position)d(in)h(the)f(document)g(wher)m(e)f(the)h(event)g +(occurr)m(ed;)g(for)g(some)g(events)g(even)f(two)1312 +8509 y(positions)g(ar)m(e)g(speci\002ed:)53 b(a)42 b(start)h(position)f +(and)g(an)g(end)g(position.)54 b(E.g.,)41 b(type)h Fm(ErrorInf)l(o)1312 +8708 y Fp(describes)52 b(an)h(err)m(or)e(by)i(means)f(of)g(its)i +(position)f(and)g(an)f(err)m(or)f(description.)85 b(A)53 +b(start-)1312 8908 y(tag)48 b(is)g(described)g(by)f(the)g(positions)h +(of)g(its)g(\002rst)h(and)e(last)i(character)-12 b(,)46 +b(the)h(index)g(of)h(the)1312 9107 y(element,)62 b(the)d(list)i(of)f +(attribute)g(speci\002cations)g(the)f(eventual)g(spaces)h(following)h +(the)1312 9306 y(element)53 b(name)h(and)h(a)g(boolean)f(\003ag,)59 +b(indicating)c(whether)f(it)i(is)g(an)e(empty-element)1312 +9505 y(tag:)1727 9767 y Fl(type)42 b Fm(ErrorInf)l(o)58 +b Fj(=)h Fm(Errors)n(.P)-7 b(osition)58 b Fi(\003)h Fm(Errors)n(.Error) +1727 9950 y Fl(type)42 b Fm(Star)6 b(tT)-18 b(agInf)l(o)58 +b Fj(=)h Fm(Star)6 b(tEnd)59 b Fi(\003)h Fm(int)f Fi(\003)h +Fm(AttSpecList)e Fi(\003)i Fm(UniChar)-7 b(.Data)58 b +Fi(\003)i Fm(bool)1561 10228 y Fp(The)48 b(information)g(set)h(pr)m +(ovided)g(thr)m(ough)f Fo(fxp)p Fp('s)i(hooks)f(is)h(suf)m(\002cient)g +(for)f(pr)m(oduc-)1312 10428 y(ing)54 b(a)g(character)m(-by-character)c +(identical)55 b(copy)e(of)h(the)f(document)g(instance.)87 +b(Except)1312 10627 y(for)35 b(white)g(space)g(and)h(parameter)d +(entity)j(r)m(efer)m(ences)d(within)j(declarations,)g(this)g(is)g(also) +1312 10826 y(possible)42 b(for)f(the)f(DTD.)4134 11324 +y(1)p eop +%%Page: 2 2 +2 1 bop 465 903 5729 7 v 465 6282 7 5379 v 598 1164 a +Fl(signature)42 b Fm(Hooks)60 b Fj(=)812 1347 y Fl(sig)1027 +1529 y(type)41 b Fm(AppData)1027 1712 y Fl(type)g Fm(AppFinal)1027 +1973 y Fl(v)m(al)g Fm(hookError)356 b(:)51 b(AppData)60 +b Fi(\003)f Fm(HookData.ErrorInf)l(o)373 b Fi(!)59 b +Fm(AppData)1027 2155 y Fl(v)m(al)41 b Fm(hookW)-6 b(ar)t(ning)135 +b(:)51 b(AppData)60 b Fi(\003)f Fm(HookData.W)-6 b(ar)t(ningInf)l(o)152 +b Fi(!)59 b Fm(AppData)1027 2416 y Fl(v)m(al)41 b Fm(hookStar)6 +b(tT)-18 b(ag)127 b(:)51 b(AppData)60 b Fi(\003)f Fm(HookData.Star)6 +b(tT)-18 b(agInf)l(o)144 b Fi(!)59 b Fm(AppData)1027 +2599 y Fl(v)m(al)41 b Fm(hookEndT)-18 b(ag)184 b(:)51 +b(AppData)60 b Fi(\003)f Fm(HookData.EndT)-18 b(agInf)l(o)201 +b Fi(!)59 b Fm(AppData)1027 2860 y Fl(v)m(al)41 b Fm(hookData)373 +b(:)51 b(AppData)60 b Fi(\003)f Fm(HookData.DataInf)l(o)390 +b Fi(!)59 b Fm(AppData)1027 3042 y Fl(v)m(al)41 b Fm(hookCData)265 +b(:)51 b(AppData)60 b Fi(\003)f Fm(HookData.CDataInf)l(o)282 +b Fi(!)59 b Fm(AppData)1027 3225 y Fl(v)m(al)41 b Fm(hookCharRef)132 +b(:)51 b(AppData)60 b Fi(\003)f Fm(HookData.CharRefInf)l(o)149 +b Fi(!)59 b Fm(AppData)1027 3486 y Fl(v)m(al)41 b Fm(hookProcInst)139 +b(:)51 b(AppData)60 b Fi(\003)f Fm(HookData.ProcInstInf)l(o)156 +b Fi(!)59 b Fm(AppData)1027 3668 y Fl(v)m(al)41 b Fm(hookComment)h(:)51 +b(AppData)60 b Fi(\003)f Fm(HookData.CommentInf)l(o)g +Fi(!)g Fm(AppData)1027 3851 y Fl(v)m(al)41 b Fm(hookWhite)307 +b(:)51 b(AppData)60 b Fi(\003)f Fm(HookData.WhiteInf)l(o)324 +b Fi(!)59 b Fm(AppData)1027 4034 y Fl(v)m(al)41 b Fm(hookDecl)390 +b(:)51 b(AppData)60 b Fi(\003)f Fm(HookData.DeclInf)l(o)407 +b Fi(!)59 b Fm(AppData)1027 4294 y Fl(v)m(al)41 b Fm(hookDocT)-18 +b(ype)109 b(:)51 b(AppData)60 b Fi(\003)f Fm(HookData.DtdInf)l(o)473 +b Fi(!)59 b Fm(AppData)1027 4477 y Fl(v)m(al)41 b Fm(hookSubset)223 +b(:)51 b(AppData)60 b Fi(\003)f Fm(HookData.SubsetInf)l(o)240 +b Fi(!)59 b Fm(AppData)1027 4660 y Fl(v)m(al)41 b Fm(hookExtSubset)8 +b(:)49 b(AppData)60 b Fi(\003)f Fm(HookData.ExtSubsetInf)l(o)27 +b Fi(!)55 b Fm(AppData)1027 4842 y Fl(v)m(al)41 b Fm(hookEndDtd)190 +b(:)51 b(AppData)60 b Fi(\003)f Fm(HookData.EndDtdInf)l(o)207 +b Fi(!)59 b Fm(AppData)1027 5103 y Fl(v)m(al)41 b Fm(hookGenRef)174 +b(:)51 b(AppData)60 b Fi(\003)f Fm(HookData.GenRefInf)l(o)191 +b Fi(!)59 b Fm(AppData)1027 5286 y Fl(v)m(al)41 b Fm(hookP)-6 +b(arRef)229 b(:)51 b(AppData)60 b Fi(\003)f Fm(HookData.P)-6 +b(arRefInf)l(o)246 b Fi(!)59 b Fm(AppData)1027 5469 y +Fl(v)m(al)41 b Fm(hookEntEnd)198 b(:)51 b(AppData)60 +b Fi(\003)f Fm(HookData.EntEndInf)l(o)215 b Fi(!)59 b +Fm(AppData)1027 5729 y Fl(v)m(al)41 b Fm(hookXml)432 +b(:)51 b(AppData)60 b Fi(\003)f Fm(HookData.XmlInf)l(o)449 +b Fi(!)59 b Fm(AppData)1027 5912 y Fl(v)m(al)41 b Fm(hookFinish)291 +b(:)51 b(AppData)1856 b Fi(!)59 b Fm(AppFinal)812 6095 +y Fl(end)p 6187 6282 V 465 6289 5729 7 v 2199 6493 a +Fh(Figure)42 b(1:)f Fp(The)g Fm(Hooks)g Fp(signatur)m(e.)p +465 6580 V 714 6912 a(In)47 b(addition)i(to)f(type)f +Fm(AppData)p Fp(,)i(a)e Fm(Hooks)h Fp(str)o(uctur)m(e)e(must)j +(de\002ne)e(a)h(type)f Fm(AppFinal)q Fp(.)465 7111 y(This)35 +b(type)f(is)h(the)f(r)m(esult)h(type)f(of)h(the)f(parser:)46 +b(At)35 b(the)f(end)g(of)g(the)g(document,)h(the)f(parser)465 +7310 y(calls)f Fm(hookFinish)g Fp(in)f(or)m(der)f(to)i +Fo(\002nalize)e Fp(the)h(accumulated)g(application)g(data.)49 +b(This)32 b(is)h(use-)465 7509 y(ful)45 b(because)f(values)h(of)g(type) +f Fm(AppData)g Fp(often)g(contain)g(auxiliary)h(information:)56 +b(E.g.,)45 b(if)465 7709 y(an)56 b(application)h(collects)f +(information)f(fr)m(om)h(the)g(document)g(entity,)j(it)f(must)e(ignor)m +(e)465 7908 y(all)41 b(events)f(occurring)f(within)j(entity)e(r)m +(eplacement)f(texts.)50 b(For)40 b(this)i(r)m(eason,)d(the)h(hooks)465 +8107 y(might)52 b(maintain)g(a)g(counter)f(indicating)i(the)f(nesting)g +(depth)f(of)i(included)f(entity)h(r)m(ef-)465 8306 y(er)m(ences.)k +Fm(hookFinish)45 b Fp(then)e(r)m(emoves)f(this)j(counter)d(because)i +(it)g(is)h(of)f(no)g(inter)m(est)f(to)h(the)465 8506 +y(application.)78 b(Another)49 b(example)g(for)h(the)g(bene\002ts)g(of) +h(\002nalization)g(is)g(the)f(following:)465 8705 y(An)55 +b(application)h(might)f(collect)h(section)f(titles)h(in)g(or)m(der)e +(to)i(compile)e(a)i(table)g(of)f(con-)465 8904 y(tents.)61 +b(Since)44 b(the)h(application)f(data)i(is)g(an)e(accumulating)h +(parameter,)e(these)i(titles)g(ar)m(e)465 9103 y(collected)k(in)g(r)m +(everse)f(or)m(der)-12 b(.)74 b Fm(AppFinal)50 b Fp(can)f(be)g(used)h +(for)f(r)m(eestablishing)g(the)g(original)465 9303 y(or)m(der)-12 +b(.)465 9874 y Fg(1)239 b(Functorizing)58 b(the)h(Parser)465 +10252 y Fp(The)h(parser)g(is)i(ther)m(efor)m(e)d(implemented)h(as)h(an) +k(S)8 b Fn(M)g(L)66 b Fo(functor)p Fp(,)g(expecting)59 +b(the)i Fm(Hooks)465 10452 y Fp(str)o(uctur)m(e)47 b(as)i(ar)m(gument.) +70 b(The)47 b(application)h(can)g(then)f(generate)g(several)g +(instances)h(of)465 10651 y(the)g(parser)g(for)g(dif)m(fer)m(ent)g +(purposes.)72 b(In)49 b(addition)g(to)g(the)f(hooks,)i(the)e(parser)f +(functor)3288 11324 y(2)p eop +%%Page: 3 3 +3 2 bop 1320 903 5713 7 v 1317 1103 7 200 v 2587 1103 +V 7026 1103 V 1317 1146 V 1452 1086 a Fp(Hook)p 2587 +1146 V 863 w(X)8 b Fn(M)g(L)46 b Fp(Event)p 7026 1146 +V 1320 1153 5713 7 v 1317 1352 7 200 v 2587 1352 V 7026 +1352 V 1320 1193 5713 7 v 1317 1392 7 200 v 2587 1392 +V 7026 1392 V 1317 1435 V 1452 1376 a Fm(hookError)p +2587 1435 V 614 w Fp(err)m(or)p 7026 1435 V 1317 1635 +V 1452 1575 a Fm(hookW)-6 b(ar)t(ning)p 2587 1635 V 393 +w Fp(warning)p 7026 1635 V 1320 1641 5713 7 v 1317 1840 +7 200 v 2587 1840 V 7026 1840 V 1317 1884 V 1452 1824 +a Fm(hookStar)6 b(tT)-18 b(ag)p 2587 1884 V 385 w Fp(start-tag)p +7026 1884 V 1317 2083 V 1452 2023 a Fm(hookEndT)g(ag)p +2587 2083 V 442 w Fp(end-tag)p 7026 2083 V 1320 2090 +5713 7 v 1317 2289 7 200 v 2587 2289 V 7026 2289 V 1317 +2333 V 1452 2273 a Fm(hookData)p 2587 2333 V 631 w Fp(segment)41 +b(of)g(character)f(data)p 7026 2333 V 1317 2532 V 1452 +2472 a Fm(hookCData)p 2587 2532 V 523 w Fp(CDA)-12 b(T)g(A)40 +b(section)p 7026 2532 V 1317 2731 V 1452 2671 a Fm(hookCharRef)p +2587 2731 V 390 w Fp(character)g(r)m(efer)m(ence)p 7026 +2731 V 1320 2738 5713 7 v 1317 2937 7 200 v 2587 2937 +V 7026 2937 V 1317 2980 V 1452 2921 a Fm(hookProcInst)p +2587 2980 V 397 w Fp(pr)m(ocessing)h(instr)o(uction)p +7026 2980 V 1317 3180 V 1452 3120 a Fm(hookComment)p +2587 3180 V 300 w Fp(comment)p 7026 3180 V 1317 3379 +V 1452 3319 a Fm(hookDecl)p 2587 3379 V 648 w Fp(element,)e(attribute,) +i(notation)g(or)g(entity)g(declaration)p 7026 3379 V +1320 3386 5713 7 v 1317 3585 7 200 v 2587 3585 V 7026 +3585 V 1317 3628 V 1452 3569 a Fm(hookDocT)-18 b(ype)p +2587 3628 V 367 w Fp(start)42 b(of)f(the)g(DTD)p 7026 +3628 V 1317 3828 V 1452 3768 a Fm(hookSubset)p 2587 3828 +V 481 w Fp(start)h(of)f(the)g(internal)g(subset)p 7026 +3828 V 1317 4027 V 1452 3967 a Fm(hookExtSubset)p 2587 +4027 V 264 w Fp(start)h(of)f(the)g(external)f(subset)p +7026 4027 V 1317 4226 V 1452 4166 a Fm(hookEndDtd)p 2587 +4226 V 448 w Fp(end)h(of)h(the)f(DTD)p 7026 4226 V 1320 +4233 5713 7 v 1317 4432 7 200 v 2587 4432 V 7026 4432 +V 1317 4476 V 1452 4416 a Fm(hookGenRef)p 2587 4476 V +432 w Fp(general)g(entity)g(r)m(efer)m(ence)p 7026 4476 +V 1317 4675 V 1452 4615 a Fm(hookP)-6 b(arRef)p 2587 +4675 V 487 w Fp(parameter)40 b(entity)h(r)m(efer)m(ence)p +7026 4675 V 1317 4874 V 1452 4814 a Fm(hookEntEnd)p 2587 +4874 V 456 w Fp(end)g(of)h(an)f(included)h(entity)p 7026 +4874 V 1320 4881 5713 7 v 1317 5080 7 200 v 2587 5080 +V 7026 5080 V 1317 5123 V 1452 5064 a Fm(hookXml)p 2587 +5123 V 690 w Fp(start)g(of)f(the)g(document)g(entity)p +7026 5123 V 1317 5323 V 1452 5263 a Fm(hookFinish)p 2587 +5323 V 549 w Fp(end)g(of)h(the)f(document)p 7026 5323 +V 1320 5329 5713 7 v 2531 5534 a Fh(T)-18 b(able)41 b(1:)g +Fp(The)g(hooks)g(in)g Fo(fxp)h Fp(and)g(their)f(purposes.)p +1312 5621 5729 7 v 1312 5827 V 1312 7554 7 1727 v 1445 +6087 a Fl(funsig)g Fm(P)-6 b(arse)41 b(\()h Fl(structure)g +Fm(Dtd)344 b(:)51 b(Dtd)2452 6270 y Fl(structure)42 b +Fm(Hooks)153 b(:)51 b(Hooks)2452 6453 y Fl(structure)42 +b Fm(Resolv)l(e)f(:)51 b(Resolv)l(e)2452 6635 y Fl(structure)42 +b Fm(Options)62 b(:)51 b(Options)42 b(\))60 b Fj(=)1659 +6818 y Fl(sig)1874 7001 y(v)m(al)41 b Fm(parseDocument)g(:)51 +b(Ur)r(i.Ur)r(i)41 b(option)60 b Fi(!)g Fm(Dtd.Dtd)40 +b(option)3328 7183 y Fi(!)59 b Fm(Hooks)n(.AppData)f +Fi(!)i Fm(Hooks)n(.AppFinal)1659 7366 y Fl(end)p 7034 +7554 V 1312 7561 5729 7 v 3122 7764 a Fh(Figure)42 b(2:)f +Fp(The)g Fm(P)-6 b(arser)40 b Fp(functor)-12 b(.)p 1312 +7848 V 1312 8180 a(is)42 b(parametrized)e(with)i(thr)m(ee)e(other)g +(str)o(uctur)m(es:)1312 8512 y Fl(Options)p Fh(:)83 b +Fp(This)38 b(str)o(uctur)m(e)f(supplies)i(the)e(parser)g(with)i(its)g +(options.)49 b(It)39 b(is)f(useful)h(to)f(have)1727 8712 +y(each)61 b(instance)g(of)g(the)g(parser)g(r)o(un)g(with)h(its)h(own)e +(set)h(of)g(options:)91 b(E.g.,)70 b(X)8 b Fn(M)g(L)1727 +8911 y Fp(catalogs)52 b(fr)m(equently)f(have)f(no)h(DTD.)80 +b(Ther)m(efor)m(e)49 b(a)i(catalog)h(is)g(parsed)g(in)f(non-)1727 +9110 y(validating)43 b(mode,)d(even)g(if)i(the)f(main)g(document)f(is)j +(validated.)1312 9442 y Fl(Resolve)p Fh(:)82 b Fp(This)68 +b(str)o(uctur)m(e)f(pr)m(ovides)g(a)g(single)h(function)f(for)g(r)m +(esolving)h(an)f(external)1727 9641 y(identi\002er)41 +b(to)h(a)f(URI:)2092 9957 y Fl(v)m(al)g Fm(resolv)l(eExtId)f(:)51 +b(Base)n(.Exter)t(nalId)58 b Fi(!)h Fm(Ur)r(i.Ur)r(i)1727 +10289 y Fp(In)38 b(the)g(simplest)i(case)e(this)h(function)g(r)m +(eturns)e(the)i(system)g(identi\002er)g(that)f(is)i(part)1727 +10488 y(of)50 b(the)g(external)e(identi\002er)-12 b(.)77 +b(If)51 b(the)e(parser)h(supports)k(X)8 b Fn(M)g(L)54 +b Fp(catalogs,)f(however)-12 b(,)1727 10688 y(this)42 +b(is)g(the)f(function)g(that)g(sear)m(ches)g(the)g(catalog.)4134 +11324 y(3)p eop +%%Page: 4 4 +4 3 bop 465 1063 a Fl(Dtd)p Fh(:)82 b Fp(The)57 b(implementation)f(of)i +(the)f(DTD)f(tables)i(can)f(be)g(pr)m(ovided)g(by)h(the)f(applica-)880 +1262 y(tion.)50 b(In)38 b(most)h(cases)f(this)i(is)f(the)f +Fm(Dtd)g Fp(str)o(uctur)m(e)g(pr)m(ovided)g(by)h Fo(fxp)p +Fp(,)g(but)g(the)f(appli-)880 1461 y(cation)49 b(can)f(also)h(pr)m +(ovide)f(a)h(mor)m(e)f(ef)m(\002cient)h(implementation,)f(or)g(enhance) +f(the)880 1660 y(functionality)d(of)f(the)g(DTD)f(tables.)56 +b(For)43 b(instance,)g(the)f(operations)g(on)h(the)g(DTD)880 +1860 y(tables)f(might)g(be)g(wrapped)g(into)f(functions)h(pr)m(oducing) +g(debugging)h(or)e(statisti-)880 2059 y(cal)c(information.)49 +b(On)36 b(the)g(other)g(hand,)h(the)g(application)g(can)f +Fo(hard-code)g Fp(element)880 2258 y(types)i(or)g(attributes)g(to)g +(\002xed)h(indices.)50 b(E.g.,)38 b(in)g(or)m(der)g(to)g(collect)f +Fe(href)g Fp(attributes)880 2457 y(in)44 b(an)k(X)8 b +Fn(H)g(T)g(M)g(L)48 b Fp(document,)c(one)e(might)j(use)f(the)f +(following)i(implementation)d(of)880 2657 y(the)f Fm(Dtd)g +Fp(ar)m(gument)f(str)o(uctur)m(e:)1245 2972 y Fl(structure)j +Fm(HrefDtd)58 b Fj(=)1460 3155 y Fl(struct)1674 3337 +y(open)43 b Fm(Dtd)1674 3598 y Fl(v)m(al)f Fm(hrefData)59 +b Fj(=)g Fm(UniChar)-7 b(.Str)r(ing2Data)40 b(\224href\224)1674 +3859 y Fl(fun)i Fm(initDtdT)-18 b(ab)m(les)42 b(\(\))59 +b Fj(=)1889 4042 y Fl(let)41 b(v)m(al)g Fm(dtd)60 b Fj(=)f +Fm(Dtd.initDtdT)-18 b(ab)m(les\(\))2105 4224 y Fl(v)m(al)p +2351 4248 79 6 v 179 w Fj(=)60 b Fm(AttNot2Inde)l(x)39 +b(dtd)i(hrefData)1889 4407 y Fl(in)g Fm(dtd)1889 4590 +y Fl(end)1674 4850 y(v)m(al)h Fm(hrefIdx)59 b Fj(=)g +Fm(AttNot2Inde)l(x)39 b(\(initDtdT)-18 b(ab)m(les\(\)\))41 +b(hrefData)1460 5033 y Fl(end)880 5365 y Fp(A)i Fe(href)f +Fp(attribute)h(will)i(then)d(always)i(have)f(index)f +Fm(hrefIdx)o Fp(;)i(sear)m(ching)e(and)h(com-)880 5564 +y(paring)75 b(can)g(be)g(done)f(with)i(this)g(constant)f(rather)f(than) +h(the)f(list)j(of)e(charac-)880 5764 y(ters)46 b Fm +([0wx68,0wx72,0wx65,)f(0wx66])p Fp(.)65 b(This)46 b(is)h(r)m(easonable) +e(also)i(because)e(element)880 5963 y(types)k(ar)m(e)f(passed)i(to)f +(the)f(hooks)h(by)g(means)f(of)h(their)f(indices)h(in)g(the)g(DTD,)e +(not)880 6162 y(by)42 b(their)e(names.)465 6494 y(The)63 +b(signatur)m(e)i(of)f(the)g(parser)f(functor)g(is)i(given)f(in)h(Figur) +m(e)f(2.)120 b(It)64 b(de\002nes)h(a)f(single)465 6694 +y(function)57 b Fm(parseDocument)f Fp(which,)61 b(given)c(an)f +(optional)h(URI)g(of)g(a)h(document)e(and)h(an)465 6893 +y(optional)39 b(DTD,)f(parses)i(that)g(document)e(\226)i(if)h(no)e(URI) +h(is)g(given,)f(the)h(document)e(is)j(r)m(ead)465 7092 +y(fr)m(om)48 b(the)g(standar)m(d)i(input.)73 b(It)49 +b(r)m(eturns)f(the)g(\002nalized)i(value)e(of)h(the)f(application)h +(data)465 7291 y(r)m(eceived)40 b(in)h(its)i(thir)m(d)e(ar)m(gument,)f +(modi\002ed)i(by)g(the)f(hooks)g(during)h(parsing.)714 +7491 y(If)33 b(the)g(optional)f Fm(Dtd)h Fp(ar)m(gument)f(is)i(given)e +(as)i Fm(NONE)o Fp(,)h(the)d(parser)g(initializes)i(the)f(DTD)465 +7690 y(tables)51 b(with)g(the)g Fm(initDtdT)-18 b(ab)m(les)50 +b Fp(function.)79 b(In)50 b(this)i(case)e(hooks)h(have)f(no)g(access)h +(to)f(the)465 7889 y(DTD)34 b(because)h(it)h(is)g(not)g(pr)m(ovided)f +(as)h(an)f(ar)m(gument)g(to)g(them.)48 b(For)35 b(many)g(applications) +465 8088 y(this)46 b(is)g(not)f(necessary)f(indeed.)62 +b(If)46 b(the)f(hooks)g(need)f(to)h(access)g(the)g(DTD,)f(the)g +(applica-)465 8288 y(tion)f(must)i(initialize)f(the)f(tables)h(itself,) +h(incorporate)d(them)h(into)g(the)g(application)h(data)465 +8487 y(and)e(pass)g(them)e(to)h(the)g(parser)g(in)g(its)h +Fm(Dtd)f Fp(ar)m(gument.)465 9058 y Fg(2)239 b(Building)59 +b(Applications)f(with)i Fd(fxp)465 9437 y Fo(fxp)46 b +Fp(pr)m(ovides)f(a)g(rich)g(information)f(set)i(thr)m(ough)e(its)j +(hooks)e(interface.)62 b(Many)45 b(applica-)465 9636 +y(tions,)c(however)-12 b(,)39 b(ar)m(e)h(only)h(inter)m(ested)g(in)g(a) +g(subset)h(of)f(that)g(information:)50 b(A)41 b(formatter)465 +9835 y(is)54 b(pr)m(obably)f(not)g(inter)m(ested)f(in)i(comments,)g +(and)f(a)h(querying)f(tool)g(will)i(only)f(sear)m(ch)465 +10034 y(the)64 b(document)g(instance)g(and)h(ignor)m(e)f(the)g(DTD.)120 +b(Ther)m(efor)m(e)63 b(we)h(pr)m(ovide)h(a)g(set)f(of)465 +10234 y(hooks)41 b(that)h(simply)g(r)m(eturn)e(the)h(application)g +(data)h(unchanged:)3288 11324 y(4)p eop +%%Page: 5 5 +5 4 bop 1727 1063 a Fl(structure)42 b Fm(IgnoreHooks)59 +b Fj(=)1941 1245 y Fl(struct)2156 1428 y(fun)42 b Fm(hookError\(a,)p +3262 1452 79 6 v 76 w(\))60 b Fj(=)18 b Fm(a)2156 1611 +y Fl(fun)42 b Fm(hookW)-6 b(ar)t(ning\(a,)p 3483 1635 +V 77 w(\))60 b Fj(=)18 b Fm(a)2156 1793 y Fl(fun)42 b +Fm(hookStar)6 b(tT)-18 b(ag\(a,)p 3491 1817 V 76 w(\))60 +b Fj(=)18 b Fm(a)2156 1976 y(...)2156 2159 y Fl(fun)42 +b Fm(hookXml\(a,)p 3186 2183 V 78 w(\))59 b Fj(=)19 b +Fm(a)2156 2341 y Fl(fun)42 b Fm(hookFinish)g(a)60 b Fj(=)18 +b Fm(a)1941 2524 y Fl(end)1312 2835 y Fp(These)49 b(functions)i(ar)m(e) +e(polymorphic:)68 b(They)49 b(do)i(not)f(depend)g(on)g(the)g(type)g(of) +g(the)g(ap-)1312 3035 y(plication)h(data)h(and)g(can)e(thus)i(be)f +(used)h(with)g(arbitrary)f(types.)81 b(The)50 b(only)h(exception)1312 +3234 y(is)60 b Fm(hookFinish)g Fp(which)g(r)m(equir)m(es)f(types)h +Fm(AppData)f Fp(and)h Fm(AppFinal)g Fp(to)g(be)f(equal.)106 +b(An)59 b(ap-)1312 3433 y(plication)46 b(must)h(now)g(only)g(de\002ne)f +(the)g(hooks)g(that)h(have)f(a)h(dif)m(fer)m(ent)f(behavior)-12 +b(.)65 b(E.g.,)1312 3632 y(the)39 b(hooks)h(for)f(a)h(validator)g(ar)m +(e)f(implemented)g(in)h(a)g(few)g(lines,)g(because)f(it)i(only)e +(prints)1312 3832 y(err)m(ors)h(and)h(warnings)h(but)g(ignor)m(es)f +(all)h(other)e(events:)1727 4127 y Fl(structure)i Fm(Chec)m(kHooks)59 +b Fj(=)1941 4309 y Fl(struct)2156 4492 y(open)42 b Fm(T)-18 +b(e)l(xtIO)41 b(Errors)f(IgnoreHooks)2156 4753 y Fl(type)i +Fm(AppData)59 b Fj(=)18 b Fm(OS)m(.Process)n(.status)2156 +5014 y Fl(fun)42 b Fm(message\(pos,msg\))59 b Fj(=)18 +b Fm(output\(stdErr,P)-7 b(osition2Str)r(ing)38 b(pos)6105 +4959 y Fc(^)6175 5014 y Fm(\224:)51 b(\224)6386 4959 +y Fc(^)6455 5014 y Fm(msg\))2156 5274 y Fl(fun)42 b Fm(hookError)e(\()p +3177 5298 V 78 w(,\(pos,err\)\))58 b Fj(=)2370 5457 y +Fm(OS)m(.Process)n(.f)l(ailure)39 b(bef)l(ore)i +(message\(pos,errorMessage)f(err\))2156 5640 y Fl(fun)i +Fm(hookW)-6 b(ar)t(ning)41 b(\(status,\(pos,w)n(ar)t(n\)\))57 +b Fj(=)2370 5822 y Fm(status)41 b(bef)l(ore)f(message\(pos,w)n(ar)t +(ningMessage)h(w)n(ar)t(n\))1941 6005 y Fl(end)1312 6316 +y Fp(Except)51 b(for)g Fm(hookError)g Fp(and)g Fm(hookW)-6 +b(ar)t(ning)q Fp(,)53 b(all)g(hooks)e(ar)m(e)g(taken)g(over)f(fr)m(om)h +(str)o(uctur)m(e)1312 6516 y Fm(IgnoreHooks)o Fp(.)g(Another)39 +b(example)g(is)j(the)e(application)h(alr)m(eady)g(mentioned)f(on)g +(page)h(4:)1312 6715 y(It)53 b(collects)g(all)g(attributes)g(named)f +Fe(href)p Fp(.)85 b(For)52 b(this)h(purpose)f(we)h(de\002ned)g(a)g(str) +o(uctur)m(e)1312 6914 y Fm(HrefDtd)o Fp(,)34 b(har)m(d-coding)g(this)g +(attribute)f(name)g(to)g(a)h(constant)e(index)i Fm(hrefIdx)n +Fp(.)49 b(This)33 b(is)i(used)1312 7113 y(in)41 b(the)g(de\002nition)h +(of)f(the)g(hooks:)1727 7408 y Fl(structure)h Fm(HrefHooks)59 +b Fj(=)1941 7591 y Fl(struct)2156 7774 y(open)42 b Fm(Base)f(HrefDtd)g +(IgnoreHooks)2156 8035 y Fl(type)h Fm(AppData)59 b Fj(=)h +Fm(UniChar)-7 b(.V)-12 b(ector)39 b(list)2156 8217 y +Fl(type)j Fm(AppFinal)60 b Fj(=)g Fm(AppData)2156 8478 +y Fl(fun)42 b Fm(\002ndHref)e(nil)61 b Fj(=)f Fm(NONE)2310 +8661 y Fi(j)77 b Fm(\002ndHref)40 b(\(\(idx,attPres\))17 +b(::)g(rest\))55 b Fj(=)2585 8843 y Fl(if)41 b Fm(idx)19 +b Fa(<)-22 b(>)18 b Fm(hrefIdx)40 b Fl(then)i Fm(\002ndHref)f(rest)2585 +9026 y Fl(else)g(case)h Fm(attPres)3092 9209 y Fl(of)58 +b Fm(AP)p 3500 9209 45 7 v 53 w(PRESENT\(v)l(ec,)p 4572 +9233 79 6 v 76 w(\))i Fi(\))g Fm(SOME)41 b(v)l(ec)3172 +9391 y Fi(j)76 b Fm(AP)p 3500 9391 45 7 v 53 w(DEF)-12 +b(A)-7 b(UL)-16 b(T\(v)l(ec,)p 4511 9415 79 6 v 76 w(\))60 +b Fi(\))g Fm(SOME)41 b(v)l(ec)3172 9574 y Fi(j)p 3291 +9598 V 214 w(\))60 b Fm(\002ndHref)40 b(rest)2156 9835 +y Fl(fun)i Fm(hookStar)6 b(tT)-18 b(ag)40 b(\(a,\()p +3581 9859 V 78 w(,)p 3701 9859 V 77 w(,attSpecs,)p 4445 +9859 V 76 w(,)p 4563 9859 V 78 w(\)\))59 b Fj(=)2370 +10017 y Fl(case)42 b Fm(\002ndHref)f(attSpecs)2545 10200 +y Fl(of)58 b Fm(NONE)i Fi(\))f Fm(a)2625 10383 y Fi(j)76 +b Fm(SOME)42 b(x)60 b Fi(\))f Fm(x)17 b(::)g(a)2156 10643 +y Fl(v)m(al)41 b Fm(hookFinish)61 b Fj(=)e Fm(re)l(v)1941 +10826 y Fl(end)4134 11324 y Fp(5)p eop +%%Page: 6 6 +6 5 bop 465 1063 a Fp(In)60 b(or)m(der)f(to)h(identify)h(a)g +Fe(href)e Fp(attribute,)64 b(function)c Fm(\002ndHref)g +Fp(need)f(only)h(compar)m(e)f(its)465 1262 y(index)g(with)h +Fm(hrefIdx)n Fp(.)105 b(Note)58 b(that)h(due)h(to)f(the)f(accumulative) +h(natur)m(e)f(of)h(the)g Fm(AppData)465 1461 y Fp(ar)m(gument,)54 +b(the)f(attribute)g(values)g(ar)m(e)f(collected)h(in)g(r)m(everse)e(or) +m(der)-12 b(.)84 b(Ther)m(efor)m(e)50 b(func-)465 1660 +y(tion)43 b Fm(hookFinish)h Fp(is)g(de\002ned)f(to)h(be)e(the)h(list)i +(r)m(eversing)d(function)h(and)g(r)m(eestablishes)g(the)465 +1860 y(original)f(or)m(der)-12 b(.)465 2431 y Fg(3)239 +b(Implementing)57 b(a)i(T)-27 b(ree-Based)59 b(Interface)465 +2809 y Fp(The)51 b(hooks)h(interface)f(of)h Fo(fxp)g +Fp(its)h(event-based;)j(nevertheless)50 b(a)i(tr)m(ee-based)g +(interface)465 3009 y(can)e(easily)h(be)f(implemented)f(on)h(top)g(of)g +(the)g(hooks.)77 b(W)-15 b(e)50 b(pr)m(esent)f(bellow)h(an)h(imple-)465 +3208 y(mentation)57 b(of)h(such)g(an)g(interface.)100 +b(For)58 b(br)m(evity)-18 b(,)61 b(it)e(has)f(only)g(a)g(r)m(estricted) +g(informa-)465 3407 y(tion)46 b(set:)60 b(It)46 b(ignor)m(es)g(the)g +(DTD,)e(comments,)h(pr)m(ocessing)h(instr)o(uctions)g(and)g(the)f +(entity)465 3607 y(str)o(uctur)m(e)50 b(of)h(the)f(document.)79 +b(It)51 b(is,)j(however)-12 b(,)51 b(easy)g(to)g(extend)f(the)g +(implementation)465 3806 y(to)41 b(supply)h(all)h(this)f(information.) +714 4005 y(The)51 b Fm(T)-18 b(ree)53 b Fp(data)g(type)g(is)g(simple:) +73 b(A)52 b(tr)m(ee)g(is)h(either)e(a)i(piece)e(of)h(text)g(or)g(an)g +(element)465 4204 y(consisting)66 b(of)f(a)g(start-tag)h(and)f(a)g +(list)h(of)f(tr)m(ees)f(as)i(content.)120 b(The)64 b(application)h +(data)465 4404 y(r)m(epr)m(esents)46 b(the)i(partial)g(document)f(tr)m +(ee)g(constr)o(ucted)g(so)i(far)-12 b(.)70 b(It)49 b(contains)e(in)i +(its)g Fm(stac)m(k)465 4603 y Fp(component)54 b(for)i(each)f(ancestor)g +(element)g(of)h(the)g(curr)m(ent)e(position,)60 b(its)d(start-tag)g +(to-)465 4802 y(gether)45 b(with)h(the)g(list)h(of)f(its)h(\226)f(alr)m +(eady)g(complete)e(\226)i(left)h(siblings;)i(component)43 +b Fm(content)465 5001 y Fp(holds)48 b(the)f(childr)m(en)g(of)h(the)f +(curr)m(ent)f(element)g(that)i(ar)m(e)f(known)g(so)h(far)-12 +b(.)69 b(At)48 b(the)g(begin-)465 5201 y(ning)g(of)h(the)f(parse)g +(both)f(components)g(ar)m(e)h(empty)-18 b(.)71 b(After)48 +b(the)g(whole)g(document)f(has)465 5400 y(been)33 b(parsed,)j(the)e +(stack)h(must)g(be)g(empty)f(and)h(a)g(single)g(element)e(tr)m(ee)h +(must)h(have)f(been)465 5599 y(constr)o(ucted.)66 b(In)47 +b(this)g(case)g(function)f Fm(hookFinish)h Fp(r)m(eturns)f(that)h +(element;)h(otherwise)e(it)465 5798 y(raises)c(an)f(exception.)714 +5998 y(The)50 b(thr)m(ee)f(functions)i Fm(hookData)o +Fp(,)i Fm(hookCData)d Fp(and)h Fm(hookCharRef)f Fp(add)i(the)e(piece)f +(of)465 6197 y(text)60 b(r)m(eported)g(to)g(them)g(to)h(the)f(content)g +(of)h(the)f(curr)m(ent)f(element.)108 b(The)60 b(hook)g(for)g(a)465 +6396 y(start-tag)45 b(pushes)f(that)h(tag)f(together)f(with)i(the)f +(content)e(of)j(the)e(curr)m(ent)g(element)f(onto)465 +6595 y(the)52 b(stack.)85 b(The)52 b(element)f(started)i(by)f(that)h +(tag)g(now)g(becomes)e(the)h(curr)m(ent)f(element.)465 +6795 y(Function)62 b Fm(hookEndT)-18 b(ag)63 b Fp(r)m(everses)e(the)g +(content)g(of)i(the)e(curr)m(ent)g(element)g(in)h(or)m(der)g(to)465 +6994 y(compensate)35 b(for)i(the)f(r)m(eversing)g(ef)m(fect)h(of)g +(accumulation.)49 b(Its)37 b(tag)h(is)g(popped)e(fr)m(om)g(the)465 +7193 y(stack)51 b(and)h(combined)d(with)j(its)g(content.)77 +b(The)50 b(constr)o(ucted)g(tr)m(ee)g(is)h(then)f(pr)m(epended)465 +7392 y(to)41 b(the)g(content)f(of)h(the)g(par)m(ent)f(element)g(which)i +(now)f(becomes)f(the)g(curr)m(ent)g(element.)465 7964 +y Fg(4)239 b(Other)59 b(examples)465 8342 y Fo(fxp)52 +b Fp(comes)e(with)i(a)g(few)g(application)f(examples)g(which)g(r)m +(esides)h(in)f(the)g Fe(src/Apps)e Fp(di-)465 8541 y(r)m(ectory)-18 +b(.)48 b(The)36 b(inter)m(ested)h(r)m(eader)g(can)g(\002nd)h(ther)m(e)e +(further)g(examples)h(of)g(using)i(the)e Fo(fxp)p Fp('s)465 +8741 y(pr)m(ogramming)j(interface.)465 9312 y Fg(References)548 +9690 y Fp([1])84 b(John)57 b(Cowan)g(and)h(David)g(Megginson,)k +(editors.)c(XML)g(Information)e(Set.W3C)825 9890 y(W)-15 +b(orking)73 b(Draft,)82 b(W)-15 b(orld)74 b(W)-9 b(ide)74 +b(W)-15 b(eb)73 b(Consortium,)81 b(May)74 b(1999.)g(A)-15 +b(vailable)74 b(at)825 10089 y(http://www)-15 b(.w3.or)m +(g/TR/1998/WD-xml-infoset-19990517)3288 11324 y(6)p eop +%%Page: 7 7 +7 6 bop 1312 1396 5729 7 v 1312 10036 7 8641 v 1445 1657 +a Fl(structure)42 b Fm(T)-18 b(reeData)60 b Fj(=)1659 +1839 y Fl(struct)1874 2022 y(e)n(xception)41 b Fm(IllF)l(or)t(med)1874 +2283 y Fl(type)g Fm(T)-18 b(ag)61 b Fj(=)f Fm(int)g Fi(\003)f +Fm(HookData.AttSpecList)1874 2465 y Fl(datatype)42 b +Fm(T)-18 b(ree)60 b Fj(=)g Fm(TEXT)41 b Fl(of)h Fm(UniChar)-7 +b(.V)-12 b(ector)2940 2648 y Fi(j)77 b Fm(ELEM)41 b Fl(of)h +Fm(T)-18 b(ag)60 b Fi(\003)g Fm(Content)1874 2831 y Fl(withtype)41 +b Fm(Content)60 b Fj(=)f Fm(T)-18 b(ree)42 b(list)1659 +3013 y Fl(end)1445 3457 y(structure)g Fm(T)-18 b(reeHooks)60 +b Fj(=)1659 3639 y Fl(struct)1874 3822 y(open)42 b Fm(IgnoreHooks)f(T) +-18 b(reeData)41 b(UniChar)1874 4083 y Fl(type)g Fm(AppData)60 +b Fj(=)g Fm(Content)f Fi(\003)h Fm(\(T)-18 b(ag)60 b +Fi(\003)g Fm(Content\))40 b(list)1874 4265 y Fl(type)h +Fm(AppFinal)61 b Fj(=)f Fm(T)-18 b(ree)1874 4526 y Fl(v)m(al)41 +b Fm(appStar)6 b(t)59 b Fj(=)g Fm(\(nil,nil\))1874 4787 +y Fl(fun)41 b Fm(hookStar)6 b(tT)-18 b(ag)41 b(\(\(content,stac)m(k\),) +d(\()p 4234 4811 79 6 v 78 w(,elem,atts,)p 5003 4811 +V 76 w(,empty\)\))60 b Fj(=)2088 4970 y Fl(if)41 b Fm(empty)g +Fl(then)h Fm(\(ELEM)g(\(\(elem,atts\),nil\))17 b(::)g(content,stac)m +(k\))2088 5152 y Fl(else)41 b Fm(\(nil,\(\(elem,atts\),content\))17 +b(::)g(stac)m(k\))1874 5413 y Fl(fun)41 b Fm(hookEndT)-18 +b(ag)42 b(\(\()p 3118 5437 V 78 w(,nil\),)p 3479 5437 +V 77 w(\))60 b Fj(=)g Fl(raise)42 b Fm(IllF)l(or)t(med)2028 +5596 y Fi(j)76 b Fm(hookEndT)-18 b(ag)42 b +(\(\(content,\(tag,content'\))17 b(::)g(stac)m(k\),)p +5082 5620 V 71 w(\))60 b Fj(=)2088 5778 y Fm(\(ELEM)41 +b(\(tag,re)l(v)f(content\))17 b(::)g(content',stac)m(k\))1874 +6039 y Fl(fun)41 b Fm(hookData)h(\(\(content,stac)m(k\),\()p +3951 6063 V 74 w(,v)l(ec,)p 4338 6063 V 77 w(\)\))60 +b Fj(=)2147 6222 y Fm(\(TEXT)42 b(v)l(ec)17 b(::)g(content,stac)m(k\)) +1874 6405 y Fl(fun)41 b Fm(hookCData)g(\(\(content,stac)m(k\),\()p +4058 6429 V 75 w(,v)l(ec\)\))59 b Fj(=)2147 6587 y Fm(\(TEXT)42 +b(v)l(ec)17 b(::)g(content,stac)m(k\))1874 6770 y Fl(fun)41 +b Fm(hookCharRef)g(\(\(content,stac)m(k\),\()p 4191 6794 +V 75 w(,c,)p 4425 6794 V 77 w(\)\))59 b Fj(=)2147 6953 +y Fm(\(TEXT\(Data2V)-12 b(ector)40 b([c]\))17 b(::)g(content,stac)m +(k\))1874 7213 y Fl(fun)41 b Fm(hookFinish)i(\([elem],nil\))59 +b Fj(=)h Fm(elem)2028 7396 y Fi(j)76 b Fm(hookFinish)p +2912 7420 V 181 w Fj(=)59 b Fl(raise)42 b Fm(IllF)l(or)t(med)1659 +7579 y Fl(end)1445 8022 y(structure)g Fm(P)-6 b(arseT)-18 +b(ree)41 b(:)1659 8205 y Fl(sig)1874 8387 y(v)m(al)g +Fm(parseT)-18 b(ree)41 b(:)51 b(Ur)r(i.Ur)r(i)42 b(option)60 +b Fi(!)f Fm(Dtd.Dtd)40 b(option)61 b Fi(!)e Fm(T)-18 +b(reeData.T)g(ree)1659 8570 y Fl(end)1462 8753 y Fj(=)76 +b Fl(struct)1874 8935 y(structure)42 b Fm(P)-6 b(arser)59 +b Fj(=)h Fm(P)-6 b(arse)41 b(\()g Fl(structure)h Fm(Dtd)363 +b Fj(=)60 b Fm(Dtd)3755 9118 y Fl(structure)42 b Fm(Hooks)172 +b Fj(=)60 b Fm(T)-18 b(reeHooks)3755 9301 y Fl(structure)42 +b Fm(P)-6 b(arserOptions)59 b Fj(=)h Fm(P)-6 b(arserOptions)41 +b(\(\))3755 9483 y Fl(structure)h Fm(Resolv)l(e)60 b +Fj(=)g Fm(Resolv)l(eNull\))1874 9666 y Fl(fun)41 b Fm(parseT)-18 +b(ree)42 b(ur)r(i)g(dtd)60 b Fj(=)f Fm(P)-6 b(arser)f(.parseDocument)40 +b(ur)r(i)i(dtd)f(T)-18 b(reeHooks)n(.appStar)6 b(t)1659 +9849 y Fl(end)p 7034 10036 7 8641 v 1312 10043 5729 7 +v 2119 10247 a Fh(Figure)43 b(3:)e Fp(A)g(simple)h(tr)m(ee-based)f +(interface)f(on)h(top)g(of)g(hooks.)p 1312 10333 V 4134 +11324 a(7)p eop +%%Trailer +end +userdict /end-hook known{end-hook}if +%%EOF diff --git a/fxp/doc/exa-vcg-1.gif b/fxp/doc/exa-vcg-1.gif new file mode 100644 index 0000000000000000000000000000000000000000..f1cbf8b2bef6b5f84a2e9dc2470bbf7677a67613 GIT binary patch literal 7196 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 +qjR#xQ-jS6eqcq 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 etHCl|lrtCKyyiI9${{R30EC2ui0NVl{ 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 literal 0 HcmV?d00001 diff --git a/fxp/doc/exa-vcg-3.gif b/fxp/doc/exa-vcg-3.gif new file mode 100644 index 0000000000000000000000000000000000000000..34627a20fd3abdd823a4a368965cea2d6dfeeb4c GIT binary patch literal 2241 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 literal 0 HcmV?d00001 diff --git a/fxp/doc/exa-vcg-5.gif b/fxp/doc/exa-vcg-5.gif new file mode 100644 index 0000000000000000000000000000000000000000..63b4a42309d9c0734d09bff1a6a7218acb6195a1 GIT binary patch literal 4503 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 z gE37vzCLP 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 literal 0 HcmV?d00001 diff --git a/fxp/doc/features.html b/fxp/doc/features.html new file mode 100644 index 0000000..830a213 --- /dev/null +++ b/fxp/doc/features.html @@ -0,0 +1,387 @@ + + + + + + fxp - Features + + + + +

+fxp +Features

+---------------- + + + + + + + + + + + + +
oUnicode Support
oCatalog Support
+ +

---------------- +

+Unicode Support

+fxp has full support for Unicode and auto-detection of encoding +of external XML entities. The supported encodings +are currently: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Encoding Other recognized names 
ASCIIANSI_X3.4-1968, ANSI_X3.4-1986, US-ASCII, +US, ISO646-US, ISO-IR-6, ISO_646.IRV:1991, +IBM367 and CP367
EBCDIC
LATIN1ISO_8859-1:1987, ISO-8859-1, ISO_8859-1, +ISO-IR-100, CP819, IBM819, L1
UCS-4ISO-10646-UCS-4
UCS-2ISO-10646-UCS-2
UTF-16
UTF-8
+ +

---------------- +

+Catalog Support

+ + + + + + + + + + + + + + + + + + + +
oCatalogs
oOptions by Example
oSummary of Options
+ +

---------------- +

+Catalogs

+fxp supports the Socat syntax of XML +Catalog. Catalogs are used for generating system identifiers from public +identifiers (mapping), or for substituting system identifiers by other +system identifiers (remapping). Catalogs come in two syntaxes: the Socat +syntax is a subset of a catalog syntax used for SGML; the XML syntax is +an XML document instance. +

+Syntax

+There are five kinds of entries in a catalog: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Type Socat/XML syntax Meaning 
base BASE uri +
<Base HRef="uri">
Specifies a URI to be used as a base for succeeding relative URIs. 
extend CATALOG uri +
<Extend HRef="uri">
Indicates an alternative catalog to be searched if the actual catalog +does not contain a matching entry. 
delegate DELEGATE prefix uri +
<Delegate PublicId="prefix" HRef="uri">
Specifies an alternative catalog, but only for public identifiers beginning +with prefix
map PUBLIC pubid uri +
<Map PublicId="pubid" HRef="uri">
Maps a public identifier to a URI. 
remap SYSTEM src dst +
<Remap SystemId="src" HRef="dst">
Indicates that URI dst shall be used in the place of the source +URI src
+ +

If the XML syntax is used, the catalog is parsed in non-validating mode +and everything except for the start-tags of the above five elements is +ignored. It is recommended, however, that the catalog be a valid XML document +with a document type similar to this. +

Relative URIs are treated as relative to the catalog in which they appear, +or if there was a preceding base entry, relative to the URI of that entry. +The only exception is that the src URI in a remap entry must be +mapped exactly, ignoring any specified base. +

+Example in Socat Syntax

+If a catalog's file name ends in .SOC or .soc, fxp +assumes it is in Socat syntax, e.g.: +
+
BASE     "/pub/dtd/w3c/"
+PUBLIC   "-//W3C//DTD Specification::19980910//EN" "spec.dtd"
+SYSTEM   "spec.dtd" "xmlspec.dtd"
+DELEGATE "ISO" "/pub/dtd/iso/iso.soc"
+CATALOG  "/pub/entities/ent.soc"
+PUBLIC   "ISO 8879:1986//ENTITIES Added Latin 1//EN" "/pub/iso/lat1.ent"
+SYSTEM   "isolat1.ent" "latin1.ent"
+
+ +

+Example in XML Syntax

+For XML syntax, the catalog must be a well-formed, but not necessarily +valid XML document. I.e., if the catalog has more than one entry, there +must be at least one root element containing all the entries. All textual +data and elements other than the five catalog entries are ignored. +
+
<Catalog>
+  <Base HRef="/pub/dtd/w3c/"/>
+  <Map  PublicId="-//W3C//DTD Specification::19980910//EN" HRef="spec.dtd"/>
+  <Remap SystemId="spec.dtd" HRef="xmlspec.dtd"/>
+  <Delegate PublicId="ISO" HRef="/pub/dtd/iso/iso.soc"/>
+  <Extend HRef="/pub/entities/ent.soc"/>
+  <Map PublicId="ISO 8879:1986//ENTITIES Added Latin 1//EN" HRef="/pub/iso/lat1.ent"/>
+  <Remap SystemId="isolat1.ent" HRef="latin1.ent"/>
+</Catalog>
+
+ +

+Search Order

+The search order is breadth-first, i.e., a matching map or remap entry +is always preferred to a matching entry in an alternative catalog specified +by a preceding delegate or extend entry. E.g., in the example above the +public identifier "ISO 8879:1986//ENTITIES Added Latin 1//EN" +is mapped to /pub/iso/lat1.ent even if the catalog /pub/entities/ent.soc +contains a matching entry for it. +

---------------- +

+Catalog Options by Example

+ +

+Catalog Search Path

+A catalog to be used for resolving can be specified with the --catalog +option. Repeating this option several times is equivalent to concatenating +all specified catalogs into one. Note that, e.g, a matching entry in the +second catalog overrides a match in a catalog specified in a delegate or +extend entry in the first one: suppose that iso.soc contains the +line +
+
DELEGATE "ISO 8879:1986//ENTITIES" "8879.soc"
+
+8879.soc contains +
+
PUBLIC   "ISO 8879:1986//ENTITIES Added Latin 1//EN" "/pub/iso/lat1.ent"
+
+and ents.soc contains +
+
PUBLIC   "ISO 8879:1986//ENTITIES Added Latin 1//EN" "isolat1.ent"
+
+Specifying --catalog=iso.soc --catalog=ents.soc makes "ISO +8879:1986//ENTITIES Added Latin 1//EN" resolve to isolat1.ent, +and not to /pub/iso/lat1.ent. +

+Resolving Strategy

+A catalog may be used for several reasons: as a fall-back, i.e., for generating +system identifiers if the information in the XML document itself is not +sufficient; or as the default, overriding the system identifiers specified +in the DTD. By default, fxp tries to resolve an external identifier +as follows: +
    +
  1. +if a public identifier is present, then it is tried to be mapped to a system +identifier using the catalog; if this fails or no public identifier was +given, the declared system identifier is used;
  2. + +
  3. +the system identifier obtained by step 1 is tried to be remapped by a matching +catalog entry.
  4. +
+This can be affected by the --catalog-priority option. This option +takes one of the following arguments: + + + + + + + + + + + + + + + + + + +
mapthe default behaviour; for succeeding relative URIs. 
remapfirst try to remap the declared system identifier; only if that fails +proceed with step 1. 
sysif a system identifier is given, don't consider the catalog at all; +if there is no system identifier, proceed to steps 1 and 2. Note that in +well-formed documents an external identifier must always contain a system +identifier. Therefore this applies only to external identifiers declared +for notations. 
+ +

E.g., suppose you have the following declarations in the DTD: +

+
<ENTITY % isolat1 PUBLIC "ISO 8879:1986//ENTITIES Added Latin 1//EN" "isolat1.ent">
+<NOTATION ps PUBLIC "PostScript Level 3">
+
+By default, the external identifier for isolat1 is mapped to /pub/iso/lat1.ent. +With --catalog-priority=remap remapping of the declared system +identifier comes first and yields latin1.ent (which is modified +to /pub/dtd/w3c/latin1.ent due to the base entry in the catalog's +first line). Giving option --catalog-priority=sys totally disables +the catalog for this external identifier because it has a system identifier. +For notation ps, however, the catalog is still consulted because +its declaration lacks a system identifier. +

Since remapping should be used with caution in publicly available catalogs +it can be disabled with --catalog-remap=no. E.g., resolving public +identifier "-//W3C//DTD Specification::19980910//EN" first results +in the URI spec.dtd. By default, this is remapped to xmlspec.dtd, +but with --catalog-remap=no it is returned as is. +

+Catalog syntax and encoding

+A catalog is used for resolving system identifiers in XML documents. A +system identifier is a URI and may, according to RFC 2396, only contain +ASCII characters. Due to an inaccuracy in the XML recommendation, however, +arbitrary Unicode characters may occur in system identifiers. Since system +identifiers in catalogs are matched literally, it is desirable to specify +them identically both in the catalog and in the XML document. Therefore +catalogs are Unicode documents and can be written in all encodings supported +for XML documents. Though XML recommends encoding non-ASCII characters +in system identifiers in UTF-8 and escaping the resulting bytes in the +URI, matching of system identifiers in catalogs is performed on the Unicode +representation. Therefore, system identifier "entité" does +not match "entit%C3%A9", though both decode to the same URI. +

Catalogs in Socat syntax, however, have no encoding declaration. Therefore +fxp only checks for a byte-order mark at the beginning of a catalog +in order to auto-detect a UTF-16 encoding. If it doesn't find one it assumes +a default encoding. Because catalogs are usually written by hand, this +is by default LATIN1. The --catalog-encoding option tells fxp +to use another default encoding. +

fxp tries to guess the syntax of catalog by means of the suffix +of its file name. A suffix of .soc or .SOC suggests to +use Socat syntax, whereas for suffixes .xml and .XML +the XML syntax is chosen. For files having none of these suffices, fxp +assumes XML syntax. This can be changed with --catalog-syntax=soc. +

---------------- +

+Summary of Catalog Options

+ +
+
+-C uri
+ +
+--catalog=uri
+ +
+Use uri as a catalog. Several catalogs can be specified by repeating +this option.
+ +
+--catalog-syntax=(soc|xml)
+ +
+For catalogs with unknown suffix, specifies whether to assume Socat syntax +or XML syntax. Defaults to xml.
+ +
+--catalog-encoding=enc
+ +
+Use encoding enc for reading a catalog unless it starts with a +byte order mark. enc must be a supported encoding. +Defaults to LATIN1.
+ +
+--catalog-remap=[(yes|no)]
+ +
+Turn on or off support for remapping system identifiers. Defaults to yes.
+ +
+--catalog-priority=(map|remap|sys)
+ +
+Controls the resolving strategy in catalogs. map means that mapping +the public identifier has highest priority; remap means that remapping +the system identifier comes first; sys means that the catalog +is used only if no system identifier is present. Defaults to map.
+
+---------------- +
+fxp's feedback address fxp@PSI.Uni-Trier.DE
+ + + diff --git a/fxp/doc/fxcanon.html b/fxp/doc/fxcanon.html new file mode 100644 index 0000000..72e6619 --- /dev/null +++ b/fxp/doc/fxcanon.html @@ -0,0 +1,40 @@ + + + + + + fxp - The Program fxcanon + + + +

+fxp +The Program fxcanon

+---------------- +

+Description

+fxcanon is a validating XML processor. It reads an XML document +and produces an equivalent canonical document. Canonical +XML was invented by James Clark +for testing XML parsers. It contains only the information a processor is +required to pass to the application. fxcanon understands all options +documented for fxp; additionally, the +following options are available: +
+
+-o fname
+ +
+--output=fname
+ +
+Write all output, except for errors and warnings, to the file named fname. +If fname is -, the standard output is used. Defaults +is -.
+
+---------------- +
+fxp's feedback address fxp@PSI.Uni-Trier.DE
+ + + diff --git a/fxp/doc/fxcopy.html b/fxp/doc/fxcopy.html new file mode 100644 index 0000000..9741eeb --- /dev/null +++ b/fxp/doc/fxcopy.html @@ -0,0 +1,485 @@ + + + + + + fxp - The Program fxcopy + + + +

+fxp +The Program fxcopy

+---------------- + + + + + + + + + + + + + + + + + + +
oDescription
oOptions by Example
oSummary of Options
+ +

---------------- +

+Description

+fxcopy is a validating XML processor. It reads an XML document and +produces a copy of it. This copy can be in a different encoding, and can +be normalized in several ways by, e.g., expanding entity references. +

The typical invocation of fxcopy is +

+
fxcopy [option ...] [infile]
+
+If infile is given, fxcopy reads its input document from +that file, otherwise fxcopy reads from standard input. +

---------------- +

+Options by Example

+In addition to the options of fxp, fxcopy +accepts arguments in the following two areas:  + + + + + + + + + + + + +
oControlling Output
oExpansion of References in the Document +Instance and in the Declaration Subset
+ +

+Controlling Output

+By default, fxcopy writes to standard output, in the same encoding +as the input document. This can be changed by the following options: +
    +
  • +The output can be redirected to a file named outfile via the option +--output=outfile or, for short, -o outfile.
  • + +
  • +If an output encoding different from the input encoding is desired, use +the --output-encoding=enc option, where enc is one of +fxcopy's supported encodings.
  • +
+For instance, +
+
fxcopy -o output.utf8 --output-encoding=UTF-8 input.ascii
+
+recodes the file input.ascii to UTF-8 and writes it to the file +input.utf8. +

+Expansion of References

+By default fxcopy produces a document that is for the most parts +identical to the input, i.e., +
    +
  • +all character references and general entity references in the document +instance are preserved as far as the output encoding admits;
  • + +
  • +attribute values are reproduced literally, i.e., without being normalized +and without replacing entity references;
  • + +
  • +the internal subset of the DTD is reproduced in an equivalent form; it +is not reproduced literally in that white space is not preserved but normalized +to a canonical form;
  • + +
  • +entity values in entity declarations are reproduced literally, i.e., without +replacing entities references;
  • + +
  • +the external subset is not copied to the output, but the external identifier +of the document type declaration is preserved.
  • +
+This behavior can be affected by options. +
+Reference Expansion in the Document Instance
+Expansion of references in content can be controlled by the --expand-ref-content +option. Its takes as argument a list of keywords each specifying a class +of references to expand, where +
  + + + + + + + + + + + + + + + + + + +
charmeans that a character reference shall be replaced by the described +character unless that character cannot be represented directly in the output +encoding. 
intmeans that references to internal general entities shall be substituted +with their replacement text, unless the entity is undeclared (which may +only happen in non-validating mode). 
extmeans references to external parsed entities shall be substituted by +the content of the file they point to, unless the entity is undeclared +(which may only happen in non-validating mode). 
+
+Alternatively, we can use --expand-ref-content for specifying +all of the above. +

The second place within the document instance where references can occur +is attribute values. Furthermore, attribute values are normalized according +to their attribute type after replacement of references. By default, fxcopy +reproduces attribute values literally. Given the --expand-att-vals +option, it outputs the normalized value instead. +

As an example for expansion in the document instance assume the following +declarations in the DTD: +

+
<!ENTITY q "quote sign">
+<!ENTITY int "internal entity">
+<!ENTITY ext SYSTEM "ext.ent">
+<!ATTLIST a x NMTOKENS #IMPLIED
+            y CDATA    #IMPLIED>
+
+and the content of the file ext.ent is the string "external +entity". Let us consider the following document fragment: +
+
<a x=" a   b " y="two &q;s: &#x27; and &#x22;">    
+here is a character reference: &#64;
+here is an &int;           
+here is an &ext;
+</a>
+
+Running fxcopy --expand-refs-content=char,int produces this: +
+
<a x=" a   b " y="two &q;s: &#x27; and &#x22;">    
+here is a character reference: @
+here is an internal entity           
+here is an &ext;
+</a>
+
+whereas fxcopy --expand-refs-content=ext --expand-att-vals yields +
+
<a x="a b" y="two quote signs: ' and &#x22;">
+here is a character reference: &#64;
+here is an &int;           
+here is an external entity
+</a>
+
+Note that the &#x22; in the attribute value is not replaced +by the " sign because then it would be recognized as the end of +the attribute value literal. +
+Reference Expansion in the Declaration Subset
+Normally fxcopy reproduces only the internal subset of the document +type, preserving all references to parameter entities. This behavior can +be changed with the --expand-ents-subset option. Its argument +indicates which references shall be substitutes by their replacement text: +
  + + + + + + + + + + + + + + + + + + + + + + + + +
intExpand all references to internal parameter entities. 
extReplace all references to external parameter entities with the content +of file they point to. Note that this option implies --expand-ent-vals +in order to ensure well-formedness. 
yesExpand references to internal and external parameter entities. --expand-ents-subset +is equivalent --expand-ents-subset=yes
noExpand no parameter entity references at all. 
+
+This applies to references occurring where a declaration could occur. It +does not affect references within declarations which are expanded regardless +of options. +

The external subset can be viewed as a special reference. The --expand-ext-subset +option makes fxcopy drop the external identifier from the document +type declaration, and copy the content of the file it denotes to the end +of the internal subset. As --expand-ents-subset=ext, this option +implies --expand-ent-vals. +

Usually, entity values in entity declarations +are reproduced literally, i.e., without replacement of references. However, +if a declaration is copied from an external entity to the internal subset, +parameter entity references become invalid in the entity value. Therefore, +given the --expand-ent-vals option, fxcopy substitutes +the derived entity replacement text for the entity value. This does not +contain parameter entity references (only if the %-sign was escaped with +a character reference, but then it wasn't even recognized as a reference +by the parser); it uses character references only for characters that can +not be represented directly. +

For instance, consider the document exa-6.xml: +

+
<?xml version="1.0"?>
+<!DOCTYPE exa SYSTEM "exa-6.ext" [
+<!ENTITY % int "<!ELEMENT exa ANY>">
+<!ENTITY % ext SYSTEM "ext-6.decl">
+%int;
+%ext;
+]>
+<exa/>
+
+where the content of the file exa-6.ext is +
+
<!ENTITY % vnum "1.0">
+<!ENTITY % version "xml version %vnum;">
+
+and ext-6.decl contains +
+
<!NOTATION text SYSTEM "/bin/cat">
+
+Running fxcopy --expand-refs-subset=int exa-6.xml produces: +
+
<?xml version="1.0"?>
+<!DOCTYPE exa SYSTEM "exa-6.ext" [
+<!ENTITY % int "<!ELEMENT exa ANY>">
+<!ENTITY % ext SYSTEM "ext-6.decl">
+<!ELEMENT exa ANY>
+%ext;
+]>
+<exa/>
+
+Note that only the internal reference %int; was expanded. On the +other hand, if we run fxcopy --expand-refs-subset=ext exa-6.xml +we get: +
+
<?xml version="1.0"?>
+<!DOCTYPE exa SYSTEM "exa-6.ext" [
+<!ENTITY % int "<!ELEMENT exa ANY>">
+<!ENTITY % ext SYSTEM "ext-6.decl">
+%int;
+<!NOTATION text SYSTEM "/bin/cat">
+]>
+<exa/>
+
+Finally, using fxcopy --expand-ext-subset exa-6.xml yields +
+
<?xml version="1.0"?>
+<!DOCTYPE exa [
+<!ENTITY % int "<!ELEMENT exa ANY>">
+<!ENTITY % ext SYSTEM "ext-6.decl">
+%int;
+%ext;
+<!ENTITY % vnum "1.0">
+<!ENTITY % version "xml version 1.0">
+]>
+<exa/>
+
+Note that the entity value in the last entity declaration has been expanded, +because the --expand-ent-vals option was implied by --expand-ext-subset. +If we supersede this with --expand-ext-subset=no, we get +
+
<!ENTITY % version "xml version %vnum;">
+
+but this is not well-formed: +
+
> fxcopy --expand-ext-subset --expand-ent-vals=no exa-6.xml | fxp
+[<stdin>:8.33] Error: a parameter entity reference is not allowed in a 
+    declaration in the internal subset.
+
+---------------- +

+Summary of Command Line Options

+Each option can be one of: +
    +
  • +A file name specifying the input document. Only one input document may +be specified.
  • + +
  • +A long option of the form --key[=arg]
  • + +
  • +A short option of the form -k, where k consists of single +character. If k consists of more than one character, each character +is assumed to be a short option itself (e.g., -vic equals -v +-i -c).
  • + +
  • +A short option with argument of the form -k arg, where k +consists of a single character.
  • + +
  • +A negative short option of the form -nk, where k consists +of single character. If k consists of more than one character, +each character is assumed to be a negative short option itself (e.g., -nvic +equals -nv -ni -nc). If k is empty, then we have the +(non-negative) short option -n.
  • + +
  • +The string --. This option is ignored, except that all remaining +options are interpreted as file names, whether they start with - +or not.
  • +
+fxcopy understands all options documented for fxp; +additionally, the following options are available: +
+
+-o fname
+ +
+--output=fname
+ +
+Write all output, except for errors and warnings, to the file named fname. +If fname is -, the standard output is used. Defaults +is -.
+ +
+--output-encoding=enc
+ +
+Use encoding enc for generating the output. enc must +be a supported encoding. Default is the +encoding of the input document.
+ +
+--expand-refs-content[=key]
+ +
+Controls whether entity references in content are expanded, i.e., included +or preserved as references in the output. key is either a comma-separated +list of
+ +
    +
  • +char for character references,
  • + +
  • +ext for references to external parsed entities, and
  • + +
  • +int for references to internal general entities;
  • +
+or it is yes for all or no for none of the above. If +no key is given, yes is assumed. Default is no. +
+--expand-refs-subset[=key]
+ +
+Controls whether parameter entity references in the internal or external +subset are expanded, i.e., included or preserved as references in the output. +key is one out of
+ +
    +
  • +yes for all references,
  • + +
  • +int for references to internal entities,
  • + +
  • +ext for references to external entities; implies --expand-ent-vals; +or
  • + +
  • +no for no references at all
  • +
+to be expanded. If key is omitted, yes is assumed. Default +is no. +
+--expand-ext-subset[=(yes|no)]
+ +
+Controls whether the external subset shall be expanded, i.e., appended +to the internal subset of the output while dropping its external identifier +from the document type declaration. yes implies --expand-ent-vals. +If no argument is given, yes is assumed. Default is no.
+ +
+--expand-att-vals[=(yes|no)]
+ +
+Controls whether attribute values are reproduced literally or in expanded +form, i.e., with all references expanded and white space normalized according +to the attribute type. If no argument is given, yes is assumed. +Default is no.
+ +
+--expand-ent-vals[=(yes|no)]
+ +
+Controls whether entity values are reproduced literally or in expanded +form, i.e., with all references expanded. If no argument is given, yes +is assumed. Default is no.
+ +
+--expand=key
+ +
+Depending on key, equivalent to:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
yes:--expand-refs-content --expand-refs-subset --expand-ext-subset +--expand-att-vals --expand-ent-vals
no:--expand-refs-content=no --expand-refs-subset=no --expand-ext-subset=no +--expand-att-vals=no --expand-ent-vals=no
int:--expand-refs-content=char,int --expand-refs-subset=int --expand-ext-subset=no +--expand-att-vals --expand-ent-vals=no
ext:--expand-refs-content=ext --expand-refs-subset=yes --expand-ext-subset +--expand-att-vals=no --expand-ent-vals
+
+---------------- +
+fxp's feedback address fxp@PSI.Uni-Trier.DE
+ + + diff --git a/fxp/doc/fxesis.html b/fxp/doc/fxesis.html new file mode 100644 index 0000000..a82e217 --- /dev/null +++ b/fxp/doc/fxesis.html @@ -0,0 +1,334 @@ + + + + + + fxp - The Program fxesis + + + +

+fxp +The Program fxesis

+---------------- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
oDescription
oOutput Format
oOutput Example
oOptions by Example
oSummary of Options
+ +

---------------- +

+Description

+fxesis is a validating XML processor. It reads an XML document and +produces a textual description of its Element Structure Information Set +(ESIS). This contains only little information about the DTD, and no information +about the document's entity structure, but provides all information about +the document's logical (element) structure. +

The typical invocation of fxesis is +

+
fxesis [option ...] [infile]
+
+If infile is given, fxesis reads its input document from +that file, otherwise from standard input. By default, it prints its output +to the standard output. +

---------------- +

+The Output Format

+The fxesis output is a series of plain text lines. The meaning of +each line is determined by its first character. Some lines, e.g. attribute +specifications, define arguments for a following line. All lines contain +only LATIN1 characters, or, if the --ascii +option was given, ASCII characters. In order to print other characters +fxesis uses escape sequences with the following meaning: +
  + + + + + + + + + + + + + + + + + + + + + + + + +
\\the character '\'; 
\na newline character; 
\ta tab character; 
\U+hex;the Unicode character whose hexadecimal code is hex
+
+The following output lines can appear: +
  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
-dataA sequence of data characters, including newlines. The data need not +have been contiguous in the input document, but may have consisted of a +series of data characters, CDATA sections and character references, interspersed +with comments. 
(elemThe start of an element of type elem. Preceded by an A +line for each of its attributes. 
)elemThe end of an element of type elem
Aatt valueA specification of attribute att for a following ( +(element-start) line. value is one out of:  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
IMPLIEDThe attribute value was implied. This is used only in validating mode +only. 
CDATA dataThe attribute was declared CDATA; its value is data
NOTATION nameA notation attribute with value name; that notation was defined +in a previous N (notation definition) line. 
ENTITY name ...An attribute with declared type ENTITY or ENTITIES. +Each name is the name of an unparsed general entity that was defined +in a preceding E (entity definition) line. 
TOKEN token ...An attribute with declared type NMTOKEN, NMTOKENS, +ID, IDREF, IDREFS, or enumeration. Each token +is a name token complying with the attribute type. 
+
?target textA processing instruction with target target and text text
Eent NDATA ntDefines an unparsed external entity named ent whose notation +is nt and has been defined by a preceding N (notation definition) +line. This line is immediately preceded by an optional p (public +identifier) line, an s (system identifier) line and, if a filename +could be generated, an f (filename) line for the external identifier +declared for ent. An entity is defined by an E line only +once per document. 
NntDefines the notation named nt. This line is immediately preceded +by an optional p (public identifier) line and an optional s +(system identifier) line for the external identifier declared for nt. +A notation is defined by an N line only once per document. 
ppubidpubid is the public identifier belonging to the external identifier +of a following N (notation definition) or E (entity definition). 
ssysidsysid is the system identifier belonging to the external identifier +of a following N (notation definition) or E (entity definition). 
f<OSFILE>filenamefilename is the system file name generated for the external +identifier of a following E (entity definition). 
+
+---------------- +

+An Output Example

+Consider the example document exa-5.xml. +The fxesis output, if called without options, for this document +is exa-5.esis-8. Note that +all the adjacent data segments of the first a element are merged +into one; note also that there is an A line for each implied attribute. +Furthermore, notation man is not redefined at its second occurrence. +

Opposed to that, fxesis -7 -nv exa-5.xml produces the output +in exa-5.esis-7. Note the +difference: on the one hand, no A lines are printed for implied +attribute, because validation was turned off. On the other hand, characters +ö, ü and ß are represented by +escape sequences, because they are not ASCII-characters. +

---------------- +

+Options by Example

+fxesis understands all options documented for fxp; +the additional options control how output is generated. +

By default, fxesis writes its output to the standard output. +It can be redirected to a file named outfile via the option --output=outfile +or, for short, -o outfile. +

+Output Encoding

+By default, fxesis produces its output in the LATIN1 character set, +i.e., using 8-bit characters. It can be restricted to using only 7-bit +characters with the --ascii or, for short, -7 option. +For instance, consider the element +
+
<addr city="Köln">Müllerstraße 13</addr>
+
+Called with fxesis -8 ..., the output for this element is +
+
Acity CDATA Köln
+(addr
+-Müllerstraße 13
+)addr
+
+whereas fxesis -7 ... outputs the following: +
+
Acity CDATA K\U+f6;ln
+(addr
+-M\U+fc;llerstra\U+df;e 13
+)addr
+
+---------------- +

+Summary of Command Line Options

+Each option can be one of: +
    +
  • +A file name specifying the input document. Only one input document may +be specified.
  • + +
  • +A long option of the form --key[=arg]
  • + +
  • +A short option of the form -k, where k consists of single +character. If k consists of more than one character, each character +is assumed to be a short option itself (e.g., -vic equals -v +-i -c).
  • + +
  • +A short option with argument of the form -k arg, where k +consists of a single character.
  • + +
  • +A negative short option of the form -nk, where k consists +of single character. If k consists of more than one character, +each character is assumed to be a negative short option itself (e.g., -nvic +equals -nv -ni -nc). If k is empty, then we have the +(non-negative) short option -n.
  • + +
  • +The string --. This option is ignored, except that all remaining +options are interpreted as file names, whether they start with - +or not.
  • +
+fxesis understands all options documented for fxp; +additionally, the following options are available: +
+
+-o fname
+ +
+--output=fname
+ +
+Write all output, except for errors and warnings, to the file named fname. +If fname is -, the standard output is used. Defaults +to -.
+ +
+-7
+ +
+--ascii
+ +
+Produce the output in ASCII encoding, i.e., using 7-bit characters only.
+ +
+-8
+ +
+--latin1
+ +
+Produce output in Latin1 encoding, i.e., using 8-bit characters also. This +is the default.
+
+---------------- +
+fxp's feedback address fxp@PSI.Uni-Trier.DE
+ + + diff --git a/fxp/doc/fxp-shadow.jpg b/fxp/doc/fxp-shadow.jpg new file mode 100644 index 0000000000000000000000000000000000000000..580879caa8e470cf8e819f0cc84d7d42d464580c GIT binary patch literal 2246 zcmb7_dpOe#8^?d!Y%_*tJXwx2n$u{gd3v+u6t-HZyc#OuaafZ%Hiw*5QgW&nEkNChb=1w*V7*6{zwfZ$33_U06`#N2viIKhW|SN0zoxJJA0H10XOIBDQ1cpa94Y7%T>b{^#m1E{Z6N zg`&;u4c*wUmeg?t&0n_P0!RpGr!52pP=F{$rhGPpJ{xq!^HE3Lh$;=`UU;va-xP&! zmCN|~WJt+2FTmY8!&$AxqYeRi6uMMY8Vk;hizX)fF`Z|jywQLNf^loSp-?PKO|`o4 zR&-<&`e(t^i4m-4IipsC$6i}wsf>kWqgnCTnDAsGF4y$E4Cni{| zl|w~1If@_m>K9YhsrAm!NzAwUHg)Bmw-~Xv&K6R+HtmxVYKf?Y`I)1oUG`i|t%qV9 ztP3iff)$qV((~FM*X+qFo~YVi9P`2y$qIWVcNW7kzAY4%N?RdE|uB((<7bLtOW z>^Coq^Y?>Kj`6EAKlu4O#V25o+4O9!%h9NA^+ZzSX`? zwV2z8*pVwrXZPu2A5t??lt4o*)lcmoWOEfa)l=VEXW++ceZIA9lDjhGdG8 zwLQ>!mtSD;y)Hj~QuDDi+)Q+9{5ig-E~U3*pL}`o1XJ0H^)oYhD^ag3ygHJuktkA8 z%PqRJyq+E6YCM|nKiH!U&m_Q}wK5*xF`Jeob1lNI+28LRT_tT9Ji&i3Pq*wfy`CKC zC(ej+-#Srw)JisoIx;rqvVwm5iKNmqozcH=S6fn{_veYY!@k3T`WKqNb0@9sGy^g! z=KK#RlR7K)`KpTtb1{aSyYg)CqO0v`5GQE6$#T;&0NO0$ZyBb%neBccBylEv34J26=t=QQ`cD9#;qb;fVs8K5mV|- z3c+&zGUCj~Io=x0rGt5G|7wR_WV_}uo^{sYaXe0ALX~^edsLAnT>H(-bz0|RkQ)f8 z-9lqGEgdGGHX&o)Nc1NZH%%D7UI>fW288#<+~?^&r@R-WM>yJux^C0z)OA}$+!8_J+;AWvhy@yG@zSXRZ@DMJg?wIk*E~0j9i1@ zoch3{RyCQ)sO$|3sr*l=C!rzZZmc(l3IM(``;_>%*_w^`noM`&0X0;tPG%);9{kry z@0q26M=RkLDa$Lk5(5L`i@X@V<*K7-VHIw|hp}j6nQ&fA#fJgphdRo|E?%V17keU8a|CXj + + + + + + Alexandru Berlea + aberlea@PSI.Uni-Trier.DE + http://www.informatik.uni-trier.de/~aberlea/ + + + + fxp + 1.4.1 + 20003010 + http://www.informatik.uni-trier.de/~aberlea/Fxp/ + + - Bug Fixes + + + diff --git a/fxp/doc/fxp.html b/fxp/doc/fxp.html new file mode 100644 index 0000000..468ca71 --- /dev/null +++ b/fxp/doc/fxp.html @@ -0,0 +1,793 @@ + + + + + + fxp - The Program fxp + + + +

+fxp +The Program fxp

+---------------- + + + + + + + + + + + + + + + + + + +
oDescription
oOptions by Example
oSummary of Options
+ +

---------------- +

+Description

+fxp is a validating XML parser. It reads an XML document and reports +all well-formedness errors, validity errors and other errors in that document. +It can also warn about interoperability features and other issues mentioned +in the XML recommendation. +

The typical invocation of fxp is +

+
fxp [option ...] [infile]
+
+If infile is given, fxp reads its input document from that +file, otherwise from standard input. +

---------------- +

+Options by Example

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
oControlling Error Printing
oValidating and Non-Validating Mode
oCompatibility Modes
oInteroperability Modes
oOther Errors and Warnings
oCatalog Support
+ +

+Controlling Error Printing

+By default fxp reports all errors and warnings to the standard error. +This can be controlled by options: +
    +
  • +All messages can be redirected to a file named errfile via the +option --error-output=errfile or, for short, -e errfile.
  • + +
  • +All messages can be suppressed by supplying the --silent option, +or -s for short.
  • + +
  • +By default, the parser tries avoid printing an error that has already been +printed earlier. E.g., if an attribute is misspelled in the attribute list +declaration, there will be an undeclared-attribute error ech time this +attribute is actually specified for an element. Printing of all but the +first of these errors is suppressed. In order to make fxp print +this kind of duplicate error messages, use the --few-errors=no +option.
  • +
+ +

+Validating and Non-Validating Mode

+By default fxp is a validating parser, but it can be run in non-validating +mode with the --validate=no or, for short, -nv option. +This has the following effects: +
    +
  • +only the internal subset of the DTD is parsed and checked for well-formedness;
  • + +
  • +the external subset and all references to external parameter entities are +ignored;
  • + +
  • +declarations in the internal subset are processed only upto the first reference +to an external parameter entity;
  • + +
  • +validity constraints are not verified;
  • + +
  • +no referenced parameter entities are included;
  • + +
  • +by default, no external parsed general entities are included; this can +be changed with the --include-external option;
  • + +
  • +all attributes for which no declaration has been processed are assumed +to be declared CDATA with default value #IMPLIED;
  • +
+For instance, consider an example document exa-1.xml, +referencing files exa-1.ext, +ext.elem and ext.decl. +Running +
+
fxp exa-1.xml
+
+reports the following errors: +
+
[exa-1.xml:17.11] Error: Attribute 'num' has the value 'a' but was declared with
+    a fixed default value of '0'.
+[exa-1.xml:18.12] Error: ID name 'id1' already occurred as an attribute value.
+[exa-1.xml:19.0] Error: Element type 'a' not allowed at this point in the 
+    content of element 'a'.
+[ext.elem:1.11] Error: Attribute 'num' has the value '1' but was declared with a
+    fixed default value of '0'.
+[ext.elem:1.15] Error: Element 'a' was ended by an end-tag for 'b'.
+[exa-1.xml:20.7] Error: Attribute 'nmu' was not declared for element type 'b'.
+[exa-1.xml:20.12] Error: No value was specified for required attribute 'num'.
+[exa-1.xml:20.12] Error: The end-tag for element 'b' with declared EMPTY content
+    must follow immediately after its start-tag.
+
+whereas the non-validating mode +
+
fxp -nv exa-1.xml
+
+does not find any errors. Note that the error at [ext.elem:1.15] +is a well-formedness error but is not reported since the external entity +reference &ext; in not included. But if we make the parser +include external parsed entities: +
+
fxp -nv --include-external exa-1.xml
+
+then the error is reported: +
+
[ext.elem:1.15] Error: Element 'a' was ended by an end-tag for 'b'.
+
+ +

+Compatibility Modes

+Some features in XML have only been included for compatibility with SGML. +These include: +
    +
  • +the string (]]>) may not appear literally in content;
  • + +
  • +a comment may not contain a double-hyphen (--);
  • + +
  • +content models must be unambiguous.
  • +
+By default fxp checks for compatibility and prints errors in case +it is not obeyed. This can be changed with the --compatibility=no +or, for short, -nc option. +

In non-compatibility mode, however, the parser must handle ambiguous +content models. This implies generation of a deterministic finite state +machine (DFA), which may in the worst case have size exponential in the +size of the content model. In order to avoid too high space usage, fxp +imposes a limit on the size of the generated DFA. If this limit is exceeded, +a warning is printed and the content model is approximated by (e1|...|en)*, +where e1, ..., en are all element +types occurring in the original model. The new content model is less restrictive +but allows for a small DFA. The limit defaults to 256 and can be set by +the --dfa-max-size option, and the warning can be suppressed with +the --dfa-warn-size=no option. +

For instance, consider the document exa-2.xml. +Note that the content model for element a is ambiguous, and its +DFA needs at least 257 states. Running fxp in compatibility mode +produces the following errors: +

+
[exa-2.xml:4.65] Error: Content model is ambiguous: conflict between the 1st and
+    the 2nd occurrence of element 'b'. Using an approximation instead.
+[exa-2.xml:10.26] Error: '--' is not allowed in a comment.
+[exa-2.xml:13.26] Error: Character '>' must be escaped for compatibility.
+
+Note that the empty element tag for a is not an error since a's +content model was approximated. Running in non-compatibility mode: +
+
fxp -nc exa-1.xml
+
+suppressed these errors, but reports the following instead: +
+
[exa-2.xml:4.65] Warning: The finite state machine for the content model of 
+    element type 'a' would have more than the maximal allowed number of 256 
+    states. Using an approximation instead.
+
+This warning can be suppressed by invoking fxp like this: +
+
fxp -nc --dfa-warn-size=no exa-1.xml
+
+But still the invalidity of the empty-element tag for a is not +detected. In order to achieve this, we can raise the limit for the DFA's +size: +
+
fxp -nc --dfa-max-size=257 exa-1.xml
+
+Now element a's content can be validated and the error is reported: +
+
[exa-2.xml:12.0] Error: Empty-element tag for element type 'a' whose content 
+    model requires non-empty content.
+
+ +

+Interoperability Modes

+XML also includes some interoperability recommendations in to allow existing +SGML software to process XML documents. These recommendations are non-binding +and therefore not checked for by default. The --interoperability +or, for short, -i option makes fxp run in interoperability-mode, +which enables checking for these features. Some of these features can additionally +be controlled by individual options. The following table lists the features +supported by fxp, together with the option (if any) that enables +or disables them, and whether they are enabled by default if --interoperability +is supplied: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Controlling option  Default Interoperability Feature
(none) yesThe empty element tag must be used and may only be used for elements +declared EMPTY
--warn-mult-decl=attlistnoThere should be at most one attribute list declaration for each element +type. 
--warn-mult-decl=attnoNo attribute should be declared twice for the same element type. 
(none) yesThe same name token should not occur more than once in the enumerated +attribute types of a single element type. 
--warn-predefined=noyesValid documents should declare the entities amp, lt, +gt, apos and quot
+Note that all arguments to the --warn-mult-decl option must be +specified in a list; see a detailed description here. +

As example consider the document exa-3.xml. +Running fxp -i exa-3.xml reports the following: +

+
[exa-3.xml:10.2] Warning: The following name tokens occur more than once in the 
+    enumerated attribute types of element 'a': 'yes', 'no'.
+[exa-3.xml:10.2] Warning: The predefined entities 'lt', 'gt', 'apos', 'quot' and
+    'amp' should have been declared.
+[exa-3.xml:13.4] Error: An empty-element tag must be used for element type 'a' 
+    with EMPTY declared content.
+[exa-3.xml:15.0] Error: Empty-element tag for element 'b' with non-EMPTY 
+    declared content.
+
+Now we add some options: +
+
fxp -i --warn-mult-decl=att,attlist --warn-predefined=no exa-3.xml
+
+The result is that the predefined entities are not checked, but multiple +declarations are detected now: +
+
[exa-3.xml:9.12] Warning: Repeated attribute-list declaration for element type 
+    'a'.
+[exa-3.xml:9.28] Warning: Repeated definition of attribute 'x' for element type 
+    'a'.
+[exa-3.xml:10.2] Warning: The following name tokens occur more than once in the 
+    enumerated attribute types of element 'a': 'yes', 'no'.
+[exa-3.xml:13.4] Error: An empty-element tag must be used for element type 'a' 
+    with EMPTY declared content.
+[exa-3.xml:15.0] Error: Empty-element tag for element 'b' with non-EMPTY 
+    declared content.
+
+ +

+Other Errors and Warnings

+The following table lists some features from the XML recommendation which +can be enabled or disabled by command line options: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Controlling option  Default Feature
--warn-att-elemnoThere should be attribute list declarations for declared element types +only. 
--check-predefined=noyesIf the predefined entities are declared, this must be according to +section "4.6 Predefined Entities". 
--check-lang-idnoThe values of the attribute xml:lang must be language identifiers +as defined by IETF RFC 1766, "Tags for the Identification of Languages". 
--check-iso639noAn ISO-639 Code in a value of the attribute xml:lang must +be a two-letter language code as defined by ISO 639, "Codes for the representation +of names of languages" 
--warn-uri=noyesSystem identifiers are URI's and may only contain ASCII characters, +according to IETF RFC 2396, "Uniform Resource Identifiers (URI): Generic +Syntax" 
--check-xml-version=noyesProcessors may signal an error if they receive documents labeled with +versions they do not support. 
--warn-xml-declnoXML documents should, begin with an XML declaration which specifies +the version of XML being used. 
--warn-mult-decl=entnoAn XML processor may issue a warning if entities are declared multiple +times. 
--warn-mult-decl=notnoDitto for notations. This is not mentioned in the XML recommendation +but sensible. 
+Note that all arguments to the --warn-mult-decl option must be +specified in a list; see a detailed description here. +

For instance, consider the example document exa-4.xml. +Running fxp without options produces the following: +

+
[exa-4.xml:1.20] Error: XML version '1.1' is not supported.
+[exa-4.xml:12.21] Error: General entity 'amp' must be declared as internal 
+    entity with replacement text '&'.
+
+We can suppress these messages while making the parser check for the other +features listed above by typing: +
+
fxp --warn-att-elem --check-predefined=no --check-lang-id --check-iso639 
+    --check-xml-version=no --warn-mult-decl=ent,not exa-4.xml
+
+The result is: +
+
[exa-4.xml:9.32] Error: 'i-' is not a language identifier.
+[exa-4.xml:10.12] Warning: Attribute-list declaration for undeclared element 
+    type 'c'.
+[exa-4.xml:13.25] Warning: Repeated declaration for general entity 'amp'.
+[exa-4.xml:16.45] Warning: Repeated declaration for notation 'text'.
+[exa-4.xml:20.17] Error: 'yy' is not a language identifier.
+
+---------------- +

+Summary of Command Line Options

+Each option can be one of: +
    +
  • +A file name specifying the input document. Only one input document may +be specified.
  • + +
  • +A long option of the form --key[=arg]
  • + +
  • +A short option of the form -k, where k consists of single +character. If k consists of more than one character, each character +is assumed to be a short option itself (e.g., -vic equals -v +-i -c).
  • + +
  • +A short option with argument of the form -k arg, where k +consists of a single character.
  • + +
  • +A negative short option of the form -nk, where k consists +of single character. If k consists of more than one character, +each character is assumed to be a negative short option itself (e.g., -nvic +equals -nv -ni -nc). If k is empty, then we have the +(non-negative) short option -n.
  • + +
  • +The string --. This option is ignored, except that all remaining +options are interpreted as file names, whether they start with - +or not.
  • +
+The following options are available (see also the catalog +options): +
+
+-s
+ +
+--silent
+ +
+Do not print any errors or warnings.
+ +
+--few-errors=[(yes|no)]
+ +
+If yes, the parser tries to avoid printing errors caused by something +that already caused an error earlier. E.g., an attribute specification +for an attribute not declared for some element will cause an error only +at the first instance of that element with the attribute. If no argument +is given, yes is assumed. Default is yes.
+ +
+-e fname
+ +
+--error-output=fname
+ +
+Write all errors and warnings to the file named fname. If fname +is -, standard error is used. Default is -.
+ +
+--validate[=(yes|no)]
+ +
+Turns on or off validation. If no argument is given, yes is assumed. +Default is yes.
+ +
+-v
+ +
+Same as --validate=yes.
+ +
+-nv
+ +
+Same as --validate=no.
+ +
+--compatibility[=(yes|no)]
+ +
+If yes, the parser checks for features that were included into +XML solely for compatibility with SGML. If no argument is given, yes +is assumed. Default is yes.
+ +
+--compat[=(yes|no)]
+ +
+Same as --compatibility.
+ +
+-c
+ +
+Same as --compatibility=yes.
+ +
+-nc
+ +
+Same as --compatibility=no.
+ +
+--interoperability[=(yes|no)]
+ +
+If yes, the parser checks whether the (non-binding) recommendations +XML makes for enhancing interoperability with existing SGML software are +followed. If no argument is given, yes is assumed. Default is +no.
+ +
+--interop[=(yes|no)]
+ +
+Same as --interoperability.
+ +
+-i
+ +
+Same as --interoperability=yes.
+ +
+-ni
+ +
+Same as --interoperability=no.
+ +
  +

 

+ +
+
+--check-reserved[=(yes|no)]
+ +
+If yes, the parser checks whether element names, attribute names +and PI targets are reserved for standardization and thus invalid. If no +argument is given, yes is assumed. Default is no.
+ +
+--check-predefined[=(yes|no)]
+ +
+If yes, the parser checks whether declarations for the predefined +entities (amp, lt, gt, apos and quot) +are in accordance to section 4.6 in the XML recommendation. If no argument +is given, yes is assumed. Default is yes.
+ +
+--check-predef[=(yes|no)]
+ +
+Same as --check-predefined.
+ +
+--check-lang-id[=(yes|no)]
+ +
+If yes, the parser checks whether values of the 'xml:lang' attribute +are language identifiers as defined in RFC 1776. If no argument is given, +yes is assumed. Default is no.
+ +
+--check-iso639[=(yes|no)]
+ +
+If yes, the parser checks whether an ISO language code in a language +identifier is in accordance to ISO 639. Has no effect unless --check-lang-id=yes +was specified. If no argument is given, yes is assumed. Default +is no.
+ +
+--check-xml-version[=(yes|no)]
+ +
+If yes, the parser checks whether the version number in a XML +or text declaration is supported. If no argument is given, yes +is assumed. Default is yes.
+ +
+--warn-uri[=(yes|no)]
+ +
+If yes, the parser prints a warning for each non-ASCII character +occurring in a system literal (URI). If no argument is given, yes +is assumed. Default is yes.
+ +
+--warn-xml-decl[=(yes|no)]
+ +
+Turns on or off a warning if there is no XML declaration. If no argument +is given, yes is assumed. Default is no.
+ +
+--warn-att-elem[=(yes|no)]
+ +
+Turns on or off warnings about attribute list declarations for undeclared +elements. If no argument is given, yes is assumed. Default is +no.
+ +
+--warn-predefined[=(yes|no)]
+ +
+Turns on or off a warning if at least one of the predefined entities (amp, +lt, gt, apos and quot) are not declared. +Has no effect in non-validating mode or if --interoperability=yes +was not specified. If no argument is given, yes is assumed. Default +is no.
+ +
+--warn-mult-decl[=arg]
+ +
+Turns on or off a warning if something is declared multiple times. arg +specifies which declarations this applies to, and must be one of the following:
+ +
    +
  • +A comma-separated list key1[,key2 ...], +where each key is one out of:
  • + +
      +
    • +att for multiple definitions of an attribute for the same element;
    • + +
    • +attlist for multiple attribute list declaration for an element;
    • + +
    • +ent for multiple declarations of an entity;
    • + +
    • +not for multiple declarations of a notation.
    • +
    + +
  • +all for all of the keys above;
  • + +
  • +none for all of the keys above.
  • +
+att and attlist have no effect unless --interoperability=yes +was specified. If no argument is given, all is assumed. Default +is none. +
+--warn[=(yes|no)]
+ +
+If yes or without argument, equivalent to --warn-xml-decl +--warn-att-elem --warn-predefined --warn-mult-decl=all.
+ +
If no, equivalent to --warn-xml-decl=no --warn-att-elem=no +--warn-predefined=no --warn-mult-decl=none. +
+--include-external[=(yes|no)]
+ +
+Specifies whether external parsed entity references are included in content +or not. Has no effect in validating mode (then all references are included). +If no argument is given, yes is assumed. Default is no.
+ +
+--include-ext[=(yes|no)]
+ +
+Same as --include-external.
+ +
+--dfa-initial-size=n
+ +
+The transition table of a finite state machine grows dynamically during +its creation, i.e., if the table's size is exceeded, it is recreated with +double size. This option sets the initial size of the transition table +to the next power of 2 larger or equal to n. Default is 16.
+ +
+--dfa-initial-width=n
+ +
+Same as --dfa-initial-size=2n.
+ +
+--dfa-max-size=n
+ +
+For ambiguous content models the parser generates a deterministic finite +state machine (DFA), which may in the worst case have size exponential +in the size of the content model. This option specifies a threshold for +the number of admissible states of the DFA. If it is exceeded, the content +model is approximated by the content model (e1|...|en)*, +where e1, ..., en are all element +types occurring in the original model. Default is 256.
+ +
+--dfa-warn-size[=(yes|no)]
+ +
+Turns on or off a warning if the maximal number of states specified by +--dfa-max-size is exceeded by the DFA construction for a content +model. If no argument is given, yes is assumed. Default is yes.
+ +
+-?
+ +
+--help
+ +
+Print a summary of the command line options and exit.
+
+---------------- +
+fxp's feedback address fxp@PSI.Uni-Trier.DE
+ + + diff --git a/fxp/doc/fxviz.html b/fxp/doc/fxviz.html new file mode 100644 index 0000000..fc52506 --- /dev/null +++ b/fxp/doc/fxviz.html @@ -0,0 +1,246 @@ + + + + + + fxp - The Program fxviz + + + +

+fxp +The Program fxviz

+---------------- + + + + + + + + + + + + + + + + + + + + + + + + +
oDescription
oAn Example
oSummary of Options
oTributes
+ +

---------------- +

+Description

+fxviz is an XML tree visualizer. It reads an XML document and produces +a graph description file suitable as input to vcg. +The document tree can then be viewed or printed with the help of xvcg. +The typical invocation is +
+
fxviz [option ...] [infile]
+
+If infile is given, fxviz reads its input document from +that file, otherwise from standard input. By default, it prints its output +to the standard output. The generated tree contains the following kinds +of nodes: +
  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
node type color information unfolds into 
comment yellow file position 
processing instruction orange file position 
element light blue file position attributes 
text beige file position data segments 
attribute light green 
attribute value beige attribute type 
+
+Most of the nodes are annotated with their starting position in the XML +source; attribute value nodes provide the attribute type instead. +

A text node is usually the result of merging several adjacent text fragments +into a single one. It is, however, possible to unfold a text node into +the sequence of fragments it consists of. +

Simimlarly, an element node can be unfolded such that each of its attributes +is represented by its own attribute node as a child of the element. +

---------------- +

+An Example

+Consider the follwing XML document test.xml: +
+
<!DOCTYPE a [
+<!ELEMENT a ANY>
+<!ELEMENT b ANY>
+<!-- comment in DTD -->
+<!ATTLIST a x NMTOKEN "foo"
+            y ID      #IMPLIED>
+<!ATTLIST b x (yes|no) #REQUIRED        
+            y IDREFS   #IMPLIED>
+]>
+
+<?foo pi in prolog ?>
+<a x="yup" y="i-1">
+  <!-- comment in a -->
+  <b x="yes" y="i-1">
+    This is text with another <a>a element with an empty <b/> </a>, 
+    a character reference &#x3C; and a <![CDATA[CDATA section]]>
+  </b> 
+  <?foo pi in a ?>
+</a>
+<!-- comment in epilog -->
+
+The graph description produced by fxviz will display the document +tree as follows: +

graph output example +

Each node in the tree is connected to each of its children by an edge. +Additionally, the nodes are annotated this their starting postions in the +XML source. These positions can be viewed by selecting Node Information +=> Source Position in the vcg menu: +

graph output example +

Text nodes are merged such that no text node has another text node as +a direct sibling. If you wish to see how a merged text node is composed +of text fragments, apply vcg's Unfold Subgraph function +to that node. For the second text-node in the b-element this results +in: +

graph output example +

Additional information about attributes of elements is also available +by applying vcg's Unfold Subgraph function to the element +node: the attributes are removed from the element node's label, and for +each attribute a new attribute node is inserted before the element's content. +Each attribute node is labeled with the attribute name and has as a single +child the attribute value: +

graph output example +

The values of defaulted attributed are marked, and unspecified attributes +are either marked as implied or missing: +

graph output example +

Finally, if you are interested in the attribute type of some specified +attribute, use the Node Information => Attribute Type function: +

graph output example +

---------------- +

+Summary of Command Line Options

+Each option can be one of: +
    +
  • +A file name specifying the input document. Only one input document may +be specified.
  • + +
  • +A long option of the form --key[=arg]
  • + +
  • +A short option of the form -k, where k consists of single +character. If k consists of more than one character, each character +is assumed to be a short option itself (e.g., -vic equals -v +-i -c).
  • + +
  • +A short option with argument of the form -k arg, where k +consists of a single character.
  • + +
  • +A negative short option of the form -nk, where k consists +of single character. If k consists of more than one character, +each character is assumed to be a negative short option itself (e.g., -nvic +equals -nv -ni -nc). If k is empty, then we have the +(non-negative) short option -n.
  • + +
  • +The string --. This option is ignored, except that all remaining +options are interpreted as file names, whether they start with - +or not.
  • +
+fxviz understands all options documented for fxp; +additionally, the following options are available: +
+
+-o fname
+ +
+--output=fname
+ +
+Write all output, except for errors and warnings, to the file named fname. +If fname is -, the standard output is used. Defaults +to -.
+
+---------------- +

+Tributes

+fxviz generates output for vcg +which is an excellent graph layout program written by Georg Sander at the +University of Saarbrücken. +

---------------- +

+fxp's feedback address fxp@PSI.Uni-Trier.DE
+ + + diff --git a/fxp/doc/index.html b/fxp/doc/index.html new file mode 100644 index 0000000..09d48c1 --- /dev/null +++ b/fxp/doc/index.html @@ -0,0 +1,239 @@ + + + + + + fxp - a Functional XML Parser + + + +

+fxp The Functional +XML Parser

+---------------- +

+Contents

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
oAbout fxp
ofxp Versions and Changes
oWhere to get fxp
oHow to install fxp
oExample Applications: fxp, fxcanon, +fxcopy, fxesis, +and fxviz
+ +

---------------- +

+What is fxp?

+fxp is a validating XML +parser written completely in the functional programming language SML. fxp can +validate both XML 1.0 and XML 1.1 documents. It has a programming interface allowing for production of XML +applications based on fxp. It comes with four example applications: + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ofxp, the pure parser. It parses a document +and finds well-formedness errors, validity errors and other problems;
ofxcanon produces an equivalent canonical +XML document. Canonical +XML was invented by James Clark +for testing XML parsers. It contains only the information a processor is +required to pass to the application; 
ofxcopy reproduces the document parsed +by fxp. The copy can be generated in a different encoding than the +input, and can be normalized in different ways concerning, e.g., expansion +of entity references; 
ofxesis adds a backend to fxp, +producing an output similar to nsgmls's +ESIS (Element Structure Information Set) output;
ofxviz is an XML tree visualizer. It +produces a graph description suitable as input to Georg Sander's vcg
+More features of fxp are here. +

---------------- + +

fxp Versions and Changes

+ +

The current version of fxp is 2.0. Changes from the +previous versions are described here.

+ +

---------------- + +

+Downloading fxp

+The source code for fxp can be downloaded by http. The Copyright note is here. +

---------------- +

+Installation instructions

In order to +install fxp, you need an SML compiler. It has been tested with +the stable versions 110.0.7 and 110.0.6 of SML of New +Jersey. (If you need to use a working version of the SML compiler +look here.) The compiler must have the +compilation manager (CM) built in, which is the default when +installing SML-NJ. We successfully compiled fxp on Linux. For other unices we expect +no problems. An installation using the Windows version of SML-NJ is +documented here. + +

These are the steps for installing fxp under Unix: +

    +
  1. +Download the latest version of fxp;
  2. + +
  3. +Unpack the sources, and change to the fxp directory, e.g.:
  4. + +
        gunzip -c fxp-2.0.tar.gz | tar xf -
    +    cd fxp-2.0
    + +
  5. +Read the COPYRIGHT;
  6. + +
  7. +Edit the Makefile according to your needs. Probably you will only +have to change the following:
  8. + +
      +
    • +INSTALL_PROGS is the list of programs to be installed. fxlib is +required if you want to develop applications with fxp. The fxgrep XML query language and the fxt XML transformation language also need fxlib being installed.
    • + +
    • +FXP_BINDIR is where the executables are installed;
    • + +
    • +FXP_LIBDIR is where other files needed by fxp - the heap +images and the library -- are installed;
    • + +
    • +SML_BINDIR is the directory where the SML executables are found. +It must contain the .arch-n-opsys script from the SML-NJ distribution, +so make sure that this is where SML-NJ is physically installed;
    • + +
    • +SML_EXEC is the name of the SML executable. This is the program +that is called for generating the heap image and at execution of fxp. +If sml will be in your PATH at execution time, you don't +need the full path here.
    • + +
    • +SML_MAKEDEF is for defining the make command in SML. +After version 110.0.3, SML-NJ changed the type of CM.make'. Therefore +it is wrapped into the make defined by this variable. For working +versions of SML-NJ, use the second variant of this definition.
    • +
    + +
  9. +Edit the file src/config.sml according to your needs. Currently +only a single value can be configured here:
  10. + +
      +
    • +retrieveCommand is the command to be used by fxp for retrieving +a remote URI from the internet and storing it in a temporary file on the +local file system. It is a string value and should contain the strings +%1 and %2, where
    • + +
        +
      • +%1 is replaced by the URI;
      • + +
      • +%2 is replaced by the local filename.
      • +
      +It is recommended that the command exits with failure in case the URI cannot +be retrieved. If the command generates a HTML error message instead (like, +e.g., "lynx -source %1 > %2"), this HTML file is considered to +be XML and will probably cause a mess of parsing errors. If you don't need +URI retrieval, use "exit 1" which always fails on Unix. Sensible +values are, e.g: + +
    + +
  11. +Compile fxp by typing make;
  12. + +
  13. +Install fxp by typing make install.
  14. + +
  15. +If you want to use fxviz, you should also install vcg.
  16. +
+---------------- + +

fxp's Programming Interface

+Here is a document describinng the programming interface +

---------------- + +

fxp's feedback address

+Any feedback related to fxp is welcome to:

---------------- + + +

Credits:

The author of fxp is Andreas Neumann. fxp is +maintained and updated by Alexandru Berlea. + + + + diff --git a/fxp/doc/shadow.jpg b/fxp/doc/shadow.jpg new file mode 100644 index 0000000000000000000000000000000000000000..41e6f590436c52ec08889de22ee4681208a85f86 GIT binary patch literal 1767 zcmex=^(PF6}rMnOeST|r4lSw=>~TvNxu(8R<nz|P9V0+dk`U|?isVP;@r zVundGu})+Z3=9zy4`yazOJo-kHU_E_LDda12qY>9(*!s9|1Aa{pixYM%z_N|3_Jfm z*I#q@<9~+w4ZGClZ`RvCV@u8=fB9!?;!|J0{Le7|dT4O`Mbq^kC-42w@Ma~`>NB&< z0+nZ)^kF@@+QuE&dH-gmEQnxQJ8JM~P>iOE;h#Y^{uTevu;}rpdjIC9 zUaNntTv?R+BmCiihRW&h>X+a6skN%^l>Jxcg;@y + + + Installation steps for Windows + + + +

Installation steps for Windows

+ + This is a contribution by Kevin S. Millikin: + +
    +
  1. + Download the fxp sources. Save the file where you would like the fxp + source directory to reside. For instance, I just installed mine in + /cygdrive/d/xml. +
  2. +
  3. + In the Cygwin bash shell, cd to the directory containing the source + tarball, and unzip and detar it. Then, cd to the directory containing + the fxp sources +
    +cd /cygdrive/d/xml
    +tar -zxvf fxp.tar.gz
    +cd fxp-1.4.6
    +
    +
  4. +
  5. Read the COPYRIGHT.
  6. + +
  7. + Edit the Makefile to reflect the situation at your site. + Change the line specifying where to install the fxp binaries and + libraries from +
    +PREFIX     = /home/berlea/xmlsoft
    +
    + to something like +
    +PREFIX     = /cygdrive/d/xml
    +
    + Change the line specifying the path to the SML/NJ executable to the + correct path to the executable, from +
    +SML_BINDIR = /usr/share/smlnj/bin
    +
    + to something like +
    +SML_BINDIR = /cygdrive/d/smlnj-110.43/bin
    +
    + Finally, the Cygwin version of mkdirhier is buggy. Replace + the line +
    +MKDIRHIER = mkdirhier
    +
    + with +
    +MKDIRHIER = mkdir -p
    +      
    +
  8. +
  9. + Unix versions of SML/NJ come equipped with a shell script called + .arch-n-opsys that reports the processor architecture and + operating system. The Win32 versions do not include this shell script. + fxp's build process relies on the presence of this script. + The easiest thing to do is place a script in the same directory as your + sml binary. +
    +#!/bin/sh
    +#
    +# .arch-n-opsys  -- get architecture and system info
    +# This file is hacked to run with the Windows version
    +
    +echo "ARCH=x86; OPSYS=win32; HEAP_SUFFIX=x86-win32"
    +
    + Call this file .arch-n-opsys. Notice that it's really a + big cheat. Make sure that it is executable +
    +chmod a+x .arch-n-opsys
    +
    +
  10. +
  11. + Now, you can make all +
    +make
    +
    +
  12. +
  13. + If that succeeded, you can install the binaries and libraries +
    +make install
    +
    +
  14. +
+ +
+ + diff --git a/fxp/doc/working.diff b/fxp/doc/working.diff new file mode 100644 index 0000000..a4fdd0e --- /dev/null +++ b/fxp/doc/working.diff @@ -0,0 +1,339 @@ +diff -Naur fxp-1.4.6/Makefile fxp-win32-1.4.6/Makefile +--- fxp-1.4.6/Makefile 2003-10-09 09:48:03.000000000 -0500 ++++ fxp-win32-1.4.6/Makefile 2003-10-17 13:22:17.000000000 -0500 +@@ -6,7 +6,7 @@ + ############################################################################## + # These are the locations for executables, heap images and library files + ############################################################################## +-PREFIX = /home/berlea/xmlsoft ++PREFIX = /cygdrive/d/xml + FXP_BINDIR = ${PREFIX}/bin + FXP_LIBDIR = ${PREFIX}/fxp + +@@ -15,15 +15,15 @@ + # SML-NJ executable with the Compilation manager built-in. If sml is in + # your PATH at execution time, you fon't need the full path here. + ############################################################################## +-SML_BINDIR = /usr/share/smlnj/bin ++SML_BINDIR = /cygdrive/d/smlnj-110.43/bin + SML_EXEC = ${SML_BINDIR}/sml + ############################################################################## + # No need to change this for SML-NJ 110.0.6. For earlier or working versions + # 110.19 you might have to use the second or third line. This is the + # compilation manager function for making with a named description file. + ############################################################################## +-SML_MAKEDEF= val make = CM.make' +-#SML_MAKEDEF= val make = CM.make ++#SML_MAKEDEF= val make = CM.make' ++SML_MAKEDEF= val make = CM.make + #SML_MAKEDEF= fun make x = CM.make'{force_relink=true, group=x} + + ############################################################################## +@@ -35,7 +35,7 @@ + COPY = cp -f + CHMOD = chmod + FIND = find +-MKDIRHIER = mkdirhier ++MKDIRHIER = mkdir -p + + ############################################################################## + # nothing to change below this line +diff -Naur fxp-1.4.6/src/Apps/Canon/canon.cm fxp-win32-1.4.6/src/Apps/Canon/canon.cm +--- fxp-1.4.6/src/Apps/Canon/canon.cm 2003-10-09 09:48:00.000000000 -0500 ++++ fxp-win32-1.4.6/src/Apps/Canon/canon.cm 2003-10-17 16:16:42.000000000 -0500 +@@ -5,3 +5,4 @@ + canonHooks.sml + canon.sml + ../../fxlib.cm ++ $/basis.cm +diff -Naur fxp-1.4.6/src/Apps/Copy/copy.cm fxp-win32-1.4.6/src/Apps/Copy/copy.cm +--- fxp-1.4.6/src/Apps/Copy/copy.cm 2003-10-09 09:48:00.000000000 -0500 ++++ fxp-win32-1.4.6/src/Apps/Copy/copy.cm 2003-10-17 16:16:51.000000000 -0500 +@@ -5,3 +5,4 @@ + copyHooks.sml + copy.sml + ../../fxlib.cm ++ $/basis.cm +diff -Naur fxp-1.4.6/src/Apps/Copy/copyEncode.sml fxp-win32-1.4.6/src/Apps/Copy/copyEncode.sml +--- fxp-1.4.6/src/Apps/Copy/copyEncode.sml 2003-10-09 09:48:00.000000000 -0500 ++++ fxp-win32-1.4.6/src/Apps/Copy/copyEncode.sml 2003-10-17 14:30:01.000000000 -0500 +@@ -126,7 +126,7 @@ + | _ => if c<>q andalso validChar(f,c) then putChar(f,c) else putCharRef(f,c) + + val f1 = putChar(f,q) +- val f2 = Vector.foldli putOne f1 (cv,0,NONE) ++ val f2 = Vector.foldli putOne f1 cv + val f3 = putChar(f2,q) + in f3 + end +diff -Naur fxp-1.4.6/src/Apps/Esis/esis.cm fxp-win32-1.4.6/src/Apps/Esis/esis.cm +--- fxp-1.4.6/src/Apps/Esis/esis.cm 2003-10-09 09:48:01.000000000 -0500 ++++ fxp-win32-1.4.6/src/Apps/Esis/esis.cm 2003-10-17 16:17:04.000000000 -0500 +@@ -5,3 +5,4 @@ + esisHooks.sml + esisData.sml + ../../fxlib.cm ++ $/basis.cm +diff -Naur fxp-1.4.6/src/Apps/Null/null.cm fxp-win32-1.4.6/src/Apps/Null/null.cm +--- fxp-1.4.6/src/Apps/Null/null.cm 2003-10-09 09:47:59.000000000 -0500 ++++ fxp-win32-1.4.6/src/Apps/Null/null.cm 2003-10-17 16:16:57.000000000 -0500 +@@ -4,3 +4,4 @@ + null.sml + nullHard.sml + ../../fxlib.cm ++ $/basis.cm +diff -Naur fxp-1.4.6/src/Apps/Viz/viz.cm fxp-win32-1.4.6/src/Apps/Viz/viz.cm +--- fxp-1.4.6/src/Apps/Viz/viz.cm 2003-10-09 09:48:01.000000000 -0500 ++++ fxp-win32-1.4.6/src/Apps/Viz/viz.cm 2003-10-17 16:17:32.000000000 -0500 +@@ -3,3 +3,4 @@ + viz.sml + vizHooks.sml + ../../fxlib.cm ++ $/basis.cm +diff -Naur fxp-1.4.6/src/Parser/Dfa/dfaPassTwo.sml fxp-win32-1.4.6/src/Parser/Dfa/dfaPassTwo.sml +--- fxp-1.4.6/src/Parser/Dfa/dfaPassTwo.sml 2003-10-09 09:47:55.000000000 -0500 ++++ fxp-win32-1.4.6/src/Parser/Dfa/dfaPassTwo.sml 2003-10-17 14:24:41.000000000 -0500 +@@ -72,6 +72,6 @@ + + val _ = do_cm (nil,true) cmi + +- in Array.extract (table,0,NONE) ++ in Array.vector table + end + end +diff -Naur fxp-1.4.6/src/Parser/Dfa/dfaString.sml fxp-win32-1.4.6/src/Parser/Dfa/dfaString.sml +--- fxp-1.4.6/src/Parser/Dfa/dfaString.sml 2003-10-09 09:47:55.000000000 -0500 ++++ fxp-win32-1.4.6/src/Parser/Dfa/dfaString.sml 2003-10-17 14:07:50.000000000 -0500 +@@ -68,11 +68,11 @@ + (fn (i,q,yet) => if q<0 then yet + else " "::Elem2String (i+lo)::"->"::State2String q::yet) + (if fin then [" [Final]"] else nil) +- (tab,0,NONE)) ++ tab) + + fun Dfa2String Elem2String tab = + String.concat + (Vector.foldri + (fn (q,row,yet) => State2String q::":"::Row2String Elem2String row::yet) +- nil (tab,0,NONE)) ++ nil tab) + end +diff -Naur fxp-1.4.6/src/Parser/Dfa/dfaUtil.sml fxp-win32-1.4.6/src/Parser/Dfa/dfaUtil.sml +--- fxp-1.4.6/src/Parser/Dfa/dfaUtil.sml 2003-10-09 09:47:54.000000000 -0500 ++++ fxp-win32-1.4.6/src/Parser/Dfa/dfaUtil.sml 2003-10-17 14:22:35.000000000 -0500 +@@ -124,7 +124,7 @@ + val tab = Array.array(hi-lo+1,dfaError) + val _ = app (fn (q,a) => Array.update (tab,a-lo,q)) flw + in +- (lo,hi,Array.extract (tab,0,NONE),fin) ++ (lo,hi,Array.vector tab,fin) + end + + end +diff -Naur fxp-1.4.6/src/Parser/Dtd/dtdAttributes.sml fxp-win32-1.4.6/src/Parser/Dtd/dtdAttributes.sml +--- fxp-1.4.6/src/Parser/Dtd/dtdAttributes.sml 2003-10-09 09:47:55.000000000 -0500 ++++ fxp-win32-1.4.6/src/Parser/Dtd/dtdAttributes.sml 2003-10-17 14:12:28.000000000 -0500 +@@ -65,7 +65,7 @@ + ord(String.sub(s,1))-65, + true)) + iso639codes +- in Vector.tabulate(26,fn i => Array.extract (Array.sub(arr,i),0,NONE)) ++ in Vector.tabulate(26,fn i => Array.vector (Array.sub(arr,i))) + end + + (*--------------------------------------------------------------------*) +diff -Naur fxp-1.4.6/src/Parser/Params/dtd.sml fxp-win32-1.4.6/src/Parser/Params/dtd.sml +--- fxp-1.4.6/src/Parser/Params/dtd.sml 2003-10-09 09:47:56.000000000 -0500 ++++ fxp-win32-1.4.6/src/Parser/Params/dtd.sml 2003-10-17 14:09:57.000000000 -0500 +@@ -290,10 +290,10 @@ + val _ = map (fn i => Array.update(preRedef,i,false)) [1,2,3,4,5] + val _ = GenEnt2Index dtd [0wx2D] (* "-" *) + val _ = ParEnt2Index dtd [0wx2D] (* "-" *) +- val _ = Vector.appi +- (fn (_,(name,lit,cs)) +- => (setGenEnt dtd (GenEnt2Index dtd name,(GE_INTERN(lit,cs),false)))) +- (predefined,1,NONE) ++ val _ = VectorSlice.appi ++ (fn (_,(name,lit,cs)) ++ => (setGenEnt dtd (GenEnt2Index dtd name,(GE_INTERN(lit,cs),false)))) ++ (VectorSlice.slice (predefined,1,NONE)) + in () + end + +diff -Naur fxp-1.4.6/src/Parser/Parse/parseContent.sml fxp-win32-1.4.6/src/Parser/Parse/parseContent.sml +--- fxp-1.4.6/src/Parser/Parse/parseContent.sml 2003-10-09 09:47:56.000000000 -0500 ++++ fxp-win32-1.4.6/src/Parser/Parse/parseContent.sml 2003-10-17 14:26:30.000000000 -0500 +@@ -587,7 +587,9 @@ + val _ = Array.update(dataBuffer,0,c0) + + fun data_hook (i,(a,q)) = +- hookData(a,((!pos0,getPos q),Array.extract(dataBuffer,0,SOME i),false)) ++ hookData(a,((!pos0,getPos q), ++ ArraySlice.vector(ArraySlice.slice(dataBuffer,0,SOME i)), ++ false)) + fun takeOne (c,qE,i,aq as (a,q)) = + if i c::cs) nil (vec,0,SOME (maxlen div 2)) +- val cs2 = Vector.foldri +- (fn (_,c,cs) => c::cs) nil (vec,len-3-maxlen div 2,NONE) ++ val cs1 = VectorSlice.foldri ++ (fn (_,c,cs) => c::cs) ++ nil ++ (VectorSlice.slice (vec,0,SOME (maxlen div 2))) ++ val cs2 = VectorSlice.foldri ++ (fn (_,c,cs) => c::cs) ++ nil ++ (VectorSlice.slice (vec,len-3-maxlen div 2,NONE)) + in Data2String cs1^"..."^Data2String cs2 + end + end +diff -Naur fxp-1.4.6/src/Unicode/Uri/uriEncode.sml fxp-win32-1.4.6/src/Unicode/Uri/uriEncode.sml +--- fxp-1.4.6/src/Unicode/Uri/uriEncode.sml 2003-10-09 09:47:57.000000000 -0500 ++++ fxp-win32-1.4.6/src/Unicode/Uri/uriEncode.sml 2003-10-17 13:52:57.000000000 -0500 +@@ -73,7 +73,7 @@ + in c2::c1:: #"%"::s + end) + s (encodeCharUtf8 c)) +- nil (cv,0,NONE) ++ nil cv + in String.implode (rev revd) + end + +@@ -85,7 +85,7 @@ + else let val (c1,c2) = Byte2Cc (Char2Byte c) + in c2::c1:: #"%"::s + end)) +- nil (cv,0,NONE) ++ nil cv + in String.implode (rev revd) + end + +diff -Naur fxp-1.4.6/src/Util/SymDict/dict.sml fxp-win32-1.4.6/src/Util/SymDict/dict.sml +--- fxp-1.4.6/src/Util/SymDict/dict.sml 2003-10-09 09:47:59.000000000 -0500 ++++ fxp-win32-1.4.6/src/Util/SymDict/dict.sml 2003-10-17 13:57:44.000000000 -0500 +@@ -230,7 +230,7 @@ + in () + end + in +- Array.appi addTo (oldTab,0,NONE) ++ Array.appi addTo oldTab + end + + (*--------------------------------------------------------------------*) +@@ -316,8 +316,8 @@ + (*--------------------------------------------------------------------*) + fun printDict X2String ({desc,tab,count,...}:'a Dict) = + (print (desc^" dictionary:\n"); +- Array.appi ++ ArraySlice.appi + (fn (n,(key,value)) => + print (" "^Int.toString n^": "^Key.toString key^" = "^X2String value^"\n")) +- (!tab,0,SOME (!count))) ++ (ArraySlice.slice(!tab,0,SOME (!count)))) + end +diff -Naur fxp-1.4.6/src/Util/SymDict/symbolTable.sml fxp-win32-1.4.6/src/Util/SymDict/symbolTable.sml +--- fxp-1.4.6/src/Util/SymDict/symbolTable.sml 2003-10-09 09:47:59.000000000 -0500 ++++ fxp-win32-1.4.6/src/Util/SymDict/symbolTable.sml 2003-10-17 14:03:39.000000000 -0500 +@@ -219,7 +219,7 @@ + val _ = Array.update(newTab,i,key) + in () + end +- val _ = Array.appi addToNew (!tab,0,NONE) ++ val _ = Array.appi addToNew (!tab) + + val _ = tab := newTab + val _ = hash := newHash +@@ -300,15 +300,15 @@ + (* extract the contents of a symbol table to a vector. *) + (*--------------------------------------------------------------------*) + fun extractSymTable({count,tab,...}:SymTable) = +- Array.extract(!tab,0,SOME(!count)) ++ ArraySlice.vector(ArraySlice.slice(!tab,0,SOME(!count))) + + (*--------------------------------------------------------------------*) + (* print the contents of the symbol table. *) + (*--------------------------------------------------------------------*) + fun printSymTable ({desc,tab,count,...}:SymTable) = + (print (desc^" table:\n"); +- Array.appi ++ ArraySlice.appi + (fn (n,key) => + print (" "^Int.toString n^": "^Key.toString key^"\n")) +- (!tab,0,SOME (!count))) ++ (ArraySlice.slice(!tab,0,SOME (!count)))) + end +diff -Naur fxp-1.4.6/src/Util/intSets.sml fxp-win32-1.4.6/src/Util/intSets.sml +--- fxp-1.4.6/src/Util/intSets.sml 2003-10-09 09:47:58.000000000 -0500 ++++ fxp-win32-1.4.6/src/Util/intSets.sml 2003-10-17 14:20:11.000000000 -0500 +@@ -49,8 +49,8 @@ + + fun normalize (vec:IntSet) = + let val max = Vector.foldli +- (fn (i,w,max) => if w=0wx0 then i else max) 0 (vec,0,NONE) +- in Vector.extract (vec,0,SOME max) ++ (fn (i,w,max) => if w=0wx0 then i else max) 0 vec ++ in VectorSlice.vector(VectorSlice.slice (vec,0,SOME max)) + end + + val emptyIntSet = Vector.fromList nil : IntSet +@@ -88,7 +88,7 @@ + val size = Vector.length vec + in + if size>idx +- then Vector.mapi (fn (i,x) => if i=idx then x||mask else x) (vec,0,NONE) ++ then Vector.mapi (fn (i,x) => if i=idx then x||mask else x) vec + else Vector.tabulate + (idx+1,fn i => if i if i=idx then x && mask else x) (vec,0,NONE) ++ (fn (i,x) => if i=idx then x && mask else x) vec + end + in normalize vec1 + end +diff -Naur fxp-1.4.6/src/Util/utilString.sml fxp-win32-1.4.6/src/Util/utilString.sml +--- fxp-1.4.6/src/Util/utilString.sml 2003-10-09 09:47:58.000000000 -0500 ++++ fxp-win32-1.4.6/src/Util/utilString.sml 2003-10-17 13:38:53.000000000 -0500 +@@ -230,6 +230,9 @@ + if Vector.length vec=0 then pre^post + else String.concat + (pre::X2String(Vector.sub(vec,0)):: +- Vector.foldri (fn (_,x,yet) => sep::X2String x::yet) [post] (vec,1,NONE)) ++ VectorSlice.foldri ++ (fn (_,x,yet) => sep::X2String x::yet) ++ [post] ++ (VectorSlice.slice (vec,1,NONE))) + fun Vector2String X2String vec = Vector2xString ("#[",",","]") X2String vec + end +diff -Naur fxp-1.4.6/src/fxlib.cm fxp-win32-1.4.6/src/fxlib.cm +--- fxp-1.4.6/src/fxlib.cm 2003-10-09 09:47:59.000000000 -0500 ++++ fxp-win32-1.4.6/src/fxlib.cm 2003-10-17 16:16:27.000000000 -0500 +@@ -92,3 +92,4 @@ + Util/SymDict/intDict.sml + Util/utilCompare.sml + config.sml ++ $/basis.cm diff --git a/fxp/doc/working.html b/fxp/doc/working.html new file mode 100644 index 0000000..a913e54 --- /dev/null +++ b/fxp/doc/working.html @@ -0,0 +1,299 @@ + + + + Installing fxp with SML working versions + + + +

Installing fxp with SML working versions

+ + Kevin S. Millikin has documented the changes needed in fxp's sources + in order to use it with the SML working version 110.43. +
    +
  1. +Download fxp-1.4.6;
  2. + +
  3. +Unpack the sources, and change to the fxp directory:
  4. + +
        gunzip -c fxp-1.4.6.tar.gz | tar xf -
    +    cd fxp-1.4.6
    + +
  5. You need to do some modifications in the fxp's sources in order to +account for the changes in the SML working version. + +For fxp 1.4.6 put the following patch working.diff in the fxp-1.4.6 +directory and type:
    +
    +    patch -p1 < working.diff
    +    
    + +Alternatively you can perform them by hand as it follows: +
      +
    1. + Since the SML/NJ compilation manager (CM) is changed in the + working version, it is necessary to specifically note the + dependency on the SML Basis library (which is SML's standard + libarary). Add the following line +
      +    $/basis.cm
      +
      + to the end of all the necessary CM files. Those files are +
      +src/fxlib.cm
      +src/Apps/Canon/canon.cm
      +src/Apps/Copy/copy.cm
      +src/Apps/Esis/esis.cm
      +src/Apps/Null/null.cm
      +src/Apps/Viz/viz.cm
      +
      +
    2. +
    3. + The signatures for Arrays and Vectors in the Basis library have changed, + as of version 110.43. Functions in the Vector and + Array structure which previously operated over + slices now use the VectorSlice or + ArraySlice structures. This necessitates a whole host of + changes. + +
        +
      1. + In file src/Util/utilString.sml, line 233, change +
        +            Vector.foldri (fn (_,x,yet) => sep::X2String x::yet) [post] (vec,1,NONE))
        +
        + to +
        +             VectorSlice.foldri
        +                 (fn (_,x,yet) => sep::X2String x::yet)
        +                 [post]
        +                 (VectorSlice.slice (vec,1,NONE)))
        +
        +
      2. +
      3. + In file src/Unicode/Chars/uniChar.sml, line 111, change +
        +                    val cs1 = Vector.foldri 
        +                       (fn (_,c,cs) => c::cs) nil (vec,0,SOME (maxlen div 2))
        +                    val cs2 = Vector.foldri 
        +                       (fn (_,c,cs) => c::cs) nil (vec,len-3-maxlen div 2,NONE)
        +
        + to +
        +                    val cs1 = VectorSlice.foldri
        +                       (fn (_,c,cs) => c::cs)
        +                       nil
        +                       (VectorSlice.slice (vec,0,SOME (maxlen div 2)))
        +                    val cs2 = VectorSlice.foldri 
        +                       (fn (_,c,cs) => c::cs)
        +                       nil
        +                       (VectorSlice.slice (vec,len-3-maxlen div 2,NONE))
        +
        +
      4. +
      5. + In file src/Unicode/Chars/charClasses.sml, line 94, change +
        +      fun finalize arr = Array.extract(arr,0,NONE)
        +
        + to +
        +      fun finalize arr = Array.vector arr
        +
        +
      6. +
      7. + In file src\Unicode\Uri\uriEncode.sml, line 76, change +
        +            nil (cv,0,NONE)
        +
        + to +
        +            nil cv
        +
        + and on line 88, make the same change. +
      8. +
      9. + In file src\Util\SymDict\dict.sml, line 233, change +
        +            Array.appi addTo (oldTab,0,NONE)
        +
        + to +
        +            Array.appi addTo oldTab
        +
        + and on line 319, change +
        +          Array.appi 
        +          (fn (n,(key,value)) =>
        +           print ("  "^Int.toString n^": "^Key.toString key^" = "^X2String value^"\n")) 
        +          (!tab,0,SOME (!count))) 
        +
        + to +
        +          ArraySlice.appi 
        +          (fn (n,(key,value)) =>
        +           print ("  "^Int.toString n^": "^Key.toString key^" = "^X2String value^"\n")) 
        +          (ArraySlice.slice(!tab,0,SOME (!count))))
        +
        +
      10. +
      11. + In file src\Util\SymDict\symbolTable.sml, line 222, change +
        +            val _ = Array.appi addToNew (!tab,0,NONE)
        +
        + to +
        +            val _ = Array.appi addToNew (!tab)
        +
        + and on line 303, change +
        +         Array.extract(!tab,0,SOME(!count))
        +
        + to +
        +         ArraySlice.vector(ArraySlice.slice(!tab,0,SOME(!count)))
        +
        + an on line 310, change +
        +          Array.appi 
        +          (fn (n,key) =>
        +           print ("  "^Int.toString n^": "^Key.toString key^"\n")) 
        +          (!tab,0,SOME (!count))) 
        +
        + to +
        +          ArraySlice.appi 
        +          (fn (n,key) =>
        +           print ("  "^Int.toString n^": "^Key.toString key^"\n")) 
        +          (ArraySlice.slice(!tab,0,SOME (!count))))
        +
        +
      12. +
      13. + In file src\Parser\Dfa\dfaString.sml, line 71, change +
        +                (tab,0,NONE))
        +
        + to +
        +                tab)
        +
        + and on line 77, change +
        +            nil (tab,0,NONE))
        +
        + to +
        +            nil tab)
        +
        +
      14. +
      15. + In file src\Parser\Params\dtd.sml, line 293, change +
        +            val _ = Vector.appi 
        +               (fn (_,(name,lit,cs)) 
        +                => (setGenEnt dtd (GenEnt2Index dtd name,(GE_INTERN(lit,cs),false)))) 
        +               (predefined,1,NONE)
        +
        + to +
        +            val _ = VectorSlice.appi 
        +               (fn (_,(name,lit,cs)) 
        +                => (setGenEnt dtd (GenEnt2Index dtd name,(GE_INTERN(lit,cs),false)))) 
        +               (VectorSlice.slice (predefined,1,NONE))
        +
        +
      16. +
      17. + In file src\Parser\Dtd\dtdAttributes.sml, line 68, change +
        +         in Vector.tabulate(26,fn i => Array.extract (Array.sub(arr,i),0,NONE))
        +
        + to +
        +         in Vector.tabulate(26,fn i => Array.vector (Array.sub(arr,i)))
        +
        +
      18. +
      19. + In file src\Util\intSets.sml, line 53, change +
        +         in Vector.extract (vec,0,SOME max)
        +
        + to +
        +         in VectorSlice.vector(VectorSlice.slice (vec,0,SOME max))
        +
        + and line 52 from +
        +            (fn (i,w,max) => if w=0wx0 then i else max) 0 (vec,0,NONE)
        +
        + to +
        +            (fn (i,w,max) => if w=0wx0 then i else max) 0 vec
        +
        + and line 91 from +
        +               then Vector.mapi (fn (i,x) => if i=idx then x||mask else x) (vec,0,NONE)
        +
        + to +
        +               then Vector.mapi (fn (i,x) => if i=idx then x||mask else x) vec
        +
        + and line 104 from +
        +                               (fn (i,x) => if i=idx then x && mask else x) (vec,0,NONE)
        +
        + to +
        +                               (fn (i,x) => if i=idx then x && mask else x) vec
        +
        +
      20. +
      21. + In file src\Parser\Dfa\dfaUtil.sml, change line 127 from +
        +            (lo,hi,Array.extract (tab,0,NONE),fin)
        +
        + to +
        +            (lo,hi,Array.vector tab,fin)
        +
        +
      22. +
      23. + In file src\Parser\Dfa\dfaPassTwo.sml, change line 75 from +
        +         in Array.extract (table,0,NONE)
        +
        + to +
        +         in Array.vector table
        +
        +
      24. +
      25. + In file src\Parser\Parse\parseContent.sml, line 590, change +
        +                  hookData(a,((!pos0,getPos q),Array.extract(dataBuffer,0,SOME i),false))
        +
        + to +
        +                  hookData(a,((!pos0,getPos q),
        +                              ArraySlice.vector(ArraySlice.slice(dataBuffer,0,SOME i)),
        +                              false))
        +
        +
      26. +
      27. + In file src\Apps\Copy\copyEncode.sml, line 129, change +
        +            val f2 = Vector.foldli putOne f1 (cv,0,NONE)
        +
        + to +
        +            val f2 = Vector.foldli putOne f1 cv
        +
        +
      +
    4. +
    +
  6. +
  7. Follow the installation +instructions for fxp starting with step 3. +
  8. +
+
+ diff --git a/fxp/fxp.sh.in b/fxp/fxp.sh.in new file mode 100755 index 0000000..b50cda4 --- /dev/null +++ b/fxp/fxp.sh.in @@ -0,0 +1,13 @@ + +ARCH_N_OPSYS=`${SML_BINDIR}/.arch-n-opsys` +if [ "$?" != "0" ]; then + echo "$CMD: unable to determine architecture/operating system" + exit 1 +fi +eval ${ARCH_N_OPSYS} + +PROG=`basename $0` +HEAP=${FXP_LIBDIR}/_${PROG} +RUN=${SML_BINDIR}/.run/run.${ARCH}-${OPSYS} + +exec ${RUN} @SMLcmdname=$0 @SMLdebug=/dev/null @SMLload=${HEAP} "$@" diff --git a/fxp/src/Apps/Canon/canon.cm b/fxp/src/Apps/Canon/canon.cm new file mode 100644 index 0000000..7db7efa --- /dev/null +++ b/fxp/src/Apps/Canon/canon.cm @@ -0,0 +1,8 @@ +Group is + canonOptions.sml + canonEncode.sml + canonOutput.sml + canonHooks.sml + canon.sml + ../../fxlib.cm + $/basis.cm diff --git a/fxp/src/Apps/Canon/canon.mlb b/fxp/src/Apps/Canon/canon.mlb new file mode 100644 index 0000000..a185ee1 --- /dev/null +++ b/fxp/src/Apps/Canon/canon.mlb @@ -0,0 +1,15 @@ +ann + "warnMatch true" + "sequenceUnit true" +in + local + $(MLTON_ROOT)/basis/basis.mlb + ../../fxlib.mlb + in + canonOptions.sml + canonEncode.sml + canonOutput.sml + canonHooks.sml + canon.sml + end +end diff --git a/fxp/src/Apps/Canon/canon.sml b/fxp/src/Apps/Canon/canon.sml new file mode 100644 index 0000000..d42bf42 --- /dev/null +++ b/fxp/src/Apps/Canon/canon.sml @@ -0,0 +1,81 @@ +structure Canon = + struct + structure ParserOptions = ParserOptions () + structure CatOptions = CatOptions () + structure CatParams = + struct + open CatError CatOptions CanonOptions Uri UtilError + + fun catError(pos,err) = if !O_SILENT then () else TextIO.output + (!O_ERROR_DEVICE,formatMessage (4,!O_ERROR_LINEWIDTH) + (Position2String pos^" Error in catalog:"::catMessage err)) + end + structure Resolve = ResolveCatalog (structure Params = CatParams) + structure CanonHooks = CanonHooks (structure ParserOptions = ParserOptions) + structure ParseCanon = Parse (structure Dtd = Dtd + structure Hooks = CanonHooks + structure Resolve = Resolve + structure ParserOptions = ParserOptions) + open + CatOptions CanonOptions CanonHooks Options ParserOptions Uri + + val usage = List.concat [parserUsage,[U_SEP],catalogUsage,[U_SEP],canonUsage] + + exception Exit of OS.Process.status + + fun canon(prog,args) = + let + val prog = "fxcanon" + val hadError = ref false + + fun optError msg = + let val _ = TextIO.output(TextIO.stdErr,msg^".\n") + in hadError := true + end + fun exitError msg = + let val _ = TextIO.output(TextIO.stdErr,msg^".\n") + in raise Exit OS.Process.failure + end + fun exitHelp prog = + let val _ = printUsage TextIO.stdOut prog usage + in raise Exit OS.Process.success + end + fun exitVersion prog = + let val _ = app print [prog," version ",Version.FXP_VERSION,"\n"] + in raise Exit OS.Process.success + end + + fun summOpt prog = "For a summary of options type "^prog^" --help" + fun noFile(f,cause) = "can't open file '"^f^"': "^exnMessage cause + + val opts = parseOptions args + val _ = setParserDefaults() + val opts1 = setParserOptions (opts,optError) + val _ = setCatalogDefaults() + val opts2 = setCatalogOptions (opts1,optError) + val _ = setCanonDefaults() + val (vers,help,err,file) = setCanonOptions (opts2,optError) + val _ = if !hadError then exitError (summOpt prog) else () + val _ = if vers then exitVersion prog else () + val _ = if help then exitHelp prog else () + val _ = case err + of SOME "-" => O_ERROR_DEVICE := TextIO.stdErr + | SOME f => (O_ERROR_DEVICE := TextIO.openOut f + handle IO.Io {cause,...} => exitError(noFile(f,cause))) + | NONE => () + val f = valOf file handle Option => "-" + val uri = if f="-" then NONE else SOME(String2Uri f) + val dtd = initDtdTables() + val status = ParseCanon.parseDocument uri (SOME dtd) (canonStart dtd) + val _ = if isSome err then TextIO.closeOut (!O_ERROR_DEVICE) else () + in status + end + handle Exit status => status + | exn => + let val _ = TextIO.output + (TextIO.stdErr,prog^": Unexpected exception: "^exnMessage exn^".\n") + in OS.Process.failure + end + end + +val _ = Canon.canon(CommandLine.name (), CommandLine.arguments ()) diff --git a/fxp/src/Apps/Canon/canonEncode.sml b/fxp/src/Apps/Canon/canonEncode.sml new file mode 100644 index 0000000..e876388 --- /dev/null +++ b/fxp/src/Apps/Canon/canonEncode.sml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + +signature CanonEncode = + sig + type File + + val noFile : File + val openFile : unit -> File + val closeFile : File -> unit + + val putBlank : File -> File + val putChar : File * UniChar.Char -> File + val putData : File * UniChar.Data -> File + val putVector : File * UniChar.Vector -> File + val putDataChar : File * UniChar.Char -> File + val putDataVector : File * UniChar.Vector -> File + end + +structure CanonEncode : CanonEncode = + struct + open + CanonOptions Encode UniChar UniClasses UtilError + + fun decodeError err = if !O_SILENT then () else + TextIO.output(!O_ERROR_DEVICE,formatMessage (4,!O_ERROR_LINEWIDTH) + ("Encoding error:"::encodeMessage err)) + + type File = EncFile + val noFile = encNoFile + fun openFile() = encOpenFile (!O_OUTPUT_FILE,Encoding.UTF8,"UTF-8") + handle NoSuchFile (f,msg) => noFile before + TextIO.output(!O_ERROR_DEVICE,formatMessage (4,!O_ERROR_LINEWIDTH) + ["Cannot open file '"^f^"' for writing. ("^msg^")"]) + val closeFile = encCloseFile + val validChar = encValidChar + + fun putChar(enc,c) = encPutChar(enc,c) + handle EncodeError(f,msg) => encAdapt(enc,f) before decodeError msg + + fun putData(enc,cs) = foldl (fn (c,enc) => putChar(enc,c)) enc cs + fun putVector(enc,cv) = Vector.foldl (fn (c,enc) => putChar(enc,c)) enc cv + + fun putBlank f = putChar(f,0wx20) + fun putDataChar (f,c) = + case c + of 0wx09 => putData(f,[0wx26,0wx23,0wx39,0wx3b]) (* " " *) + | 0wx0A => putData(f,[0wx26,0wx23,0wx31,0wx30,0wx3b]) (* " " *) + | 0wx0D => putData(f,[0wx26,0wx23,0wx31,0wx33,0wx3b]) (* " " *) + | 0wx22 => putData(f,[0wx26,0wx71,0wx75,0wx6f,0wx74,0wx3b]) (* """ *) + | 0wx26 => putData(f,[0wx26,0wx61,0wx6d,0wx70,0wx3b]) (* "&" *) + | 0wx3C => putData(f,[0wx26,0wx6c,0wx74,0wx3b]) (* "<" *) + | 0wx3E => putData(f,[0wx26,0wx67,0wx74,0wx3b]) (* ">" *) + | _ => putChar(f,c) + + fun putDataVector (f,cv) = + Vector.foldl (fn (c,f) => putDataChar(f,c)) f cv + end diff --git a/fxp/src/Apps/Canon/canonHooks.sml b/fxp/src/Apps/Canon/canonHooks.sml new file mode 100644 index 0000000..af6e74d --- /dev/null +++ b/fxp/src/Apps/Canon/canonHooks.sml @@ -0,0 +1,79 @@ +functor CanonHooks (structure ParserOptions : ParserOptions) = + struct + structure CanonOutput = CanonOutput (structure ParserOptions = ParserOptions) + open + Base Dtd + CanonEncode CanonOptions CanonOutput + + datatype Where = SOMEWHERE | SUBSET | CONTENT of int | REFERENCE of Where + + type AppData = Dtd * OS.Process.status * CanonEncode.File * Where + type AppFinal = OS.Process.status + + fun canonStart dtd = (dtd,OS.Process.success,CanonEncode.noFile,SOMEWHERE) + + fun hookXml ((dtd,status,_,wher),_) = (dtd,status,openFile(),wher) + fun hookFinish (a as (_,status,f,_)) = status before closeFile f + + fun hookError ((dtd,status,f,wher),err) = (dtd,OS.Process.failure,f,wher) + before printError err + fun hookWarning (a,warn) = a before printWarning warn + + fun hookProcInst (a as (dtd,status,f,wher),pi) = + case wher + of REFERENCE _ => a + | _ => (dtd,status,putProcInst(f,pi),wher) + fun hookWhite (a as (dtd,status,f,wher),ws) = + case wher + of CONTENT _ => (dtd,status,putDataVector(f,ws),wher) + | _ => a + + fun hookDecl (a,_) = a + fun hookComment (a,_) = a + + fun hookStartTag (a as (dtd,status,f,wher),stag) = + case wher + of CONTENT level => (dtd,status,putStartTag dtd (f,stag), + CONTENT(if #5 stag then level else level+1)) + | SOMEWHERE => (dtd,status,putStartTag dtd (f,stag), + if #5 stag then wher else CONTENT 1) + | _ => a + fun hookEndTag (a as (dtd,status,f,wher),etag) = + case wher + of CONTENT level => (dtd,status,putEndTag dtd (f,etag), + if level>1 then CONTENT(level-1) else SOMEWHERE) + | _ => a + + fun hookCData (a as (dtd,status,f,wher),(_,text)) = + case wher + of CONTENT _ => (dtd,status,putDataVector(f,text),wher) + | _ => a + fun hookData (a,(pp,text,ignore)) = hookCData(a,(pp,text)) + fun hookCharRef (a,(pp,ch,_)) = hookCData(a,(pp,Vector.fromList [ch])) + + fun hookGenRef (a as (dtd,status,f,wher),(_,_,_,included)) = + case wher + of REFERENCE _ => if included then (dtd,status,f,REFERENCE wher) else a + | _ => a + fun hookParRef (a as (dtd,status,f,wher),(_,_,_,included)) = + if included then (dtd,status,f,REFERENCE wher) else a + fun hookEntEnd (a as (dtd,status,f,wher),_) = + case wher + of REFERENCE wher1 => (dtd,status,f,wher1) + | _ => a + + fun hookDocType (a,_) = a + fun hookSubset (a as (dtd,status,f,wher),_) = + case wher + of SOMEWHERE => (dtd,status,f,SUBSET) + | _ => a + fun hookExtSubset (a as (dtd,status,f,wher),_) = + case wher + of SOMEWHERE => (dtd,status,f,SUBSET) + | _ => a + fun hookEndDtd(a as (dtd,status,f,wher),_) = + case wher + of SUBSET => (dtd,status,f,SOMEWHERE) + | REFERENCE wher => (dtd,status,f,wher) + | _ => a + end diff --git a/fxp/src/Apps/Canon/canonOptions.sml b/fxp/src/Apps/Canon/canonOptions.sml new file mode 100644 index 0000000..6f5970a --- /dev/null +++ b/fxp/src/Apps/Canon/canonOptions.sml @@ -0,0 +1,106 @@ +signature CanonOptions = + sig + val O_SILENT : bool ref + val O_ERROR_DEVICE : TextIO.outstream ref + val O_ERROR_LINEWIDTH : int ref + val O_OUTPUT_FILE : string ref + + val setCanonDefaults : unit -> unit + val setCanonOptions : Options.Option list * (string -> unit) + -> bool * bool * string option * string option + + val canonUsage : Options.Usage + end + +structure CanonOptions : CanonOptions = + struct + open Options UtilList + + val O_SILENT = ref false + val O_ERROR_DEVICE = ref TextIO.stdErr + val O_ERROR_LINEWIDTH = ref 80 + val O_OUTPUT_FILE = ref "-" + + fun setCanonDefaults () = + let + val _ = O_SILENT := false + val _ = O_ERROR_DEVICE := TextIO.stdErr + val _ = O_OUTPUT_FILE := "-" + in () + end + + val canonUsage = + [U_ITEM(["-o ","--output="],"Write output to file (stdout)"), + U_ITEM(["-s","--silent"],"Suppress reporting of errors and warnings"), + U_ITEM(["-e ","--error-output="],"Redirect errors to file (stderr)"), + U_SEP, + U_ITEM(["--version"],"Print the version number and exit"), + U_ITEM(["-?","--help"],"Print this text and exit"), + U_ITEM(["--"],"Do not recognize remaining arguments as options") + ] + + fun setCanonOptions (opts,optError) = + let + fun onlyOne what = "at most one "^what^" may be specified" + fun unknown pre opt = String.concat ["unknown option ",pre,opt] + fun hasNoArg pre key = String.concat ["option ",pre,key," expects no argument"] + fun mustHave pre key = String.concat ["option ",pre,key," must have an argument"] + + fun check_noarg(key,valOpt) = + if isSome valOpt then optError (hasNoArg "--" key) else () + + fun do_long (pars as (v,h,e,f)) (key,valOpt) = + case key + of "help" => (v,true,e,f) before check_noarg(key,valOpt) + | "version" => (true,h,e,f) before check_noarg(key,valOpt) + | "silent" => pars before O_SILENT := true before check_noarg(key,valOpt) + | "output" => + (case valOpt + of NONE => pars before optError (mustHave "--" key) + | SOME s => pars before O_OUTPUT_FILE := s) + | "error-output" => + (case valOpt + of NONE => pars before optError (mustHave "--" key) + | SOME s => (v,h,SOME s,f)) + | _ => pars before optError(unknown "--" key) + + fun do_short (pars as (v,h,e,f)) (cs,opts) = + case cs + of nil => doit pars opts + | [#"o"] => (case opts + of OPT_STRING s::opts1 => (O_OUTPUT_FILE := s; + doit pars opts1) + | _ => (optError (mustHave "-" "o"); doit pars opts)) + | [#"e"] => (case opts + of OPT_STRING s::opts1 => doit (v,h,SOME s,f) opts1 + | _ => (optError (mustHave "-" "e"); doit pars opts)) + | cs => doit (foldr + (fn (c,pars) + => case c + of #"s" => pars before O_SILENT := true + | #"o" => pars before optError (mustHave "-" "o") + | #"e" => pars before optError (mustHave "-" "e") + | #"?" => (v,true,e,f) + | c => pars before + optError(unknown "-" (String.implode [c]))) + pars cs) opts + + and doit pars nil = pars + | doit (pars as (v,h,e,f)) (opt::opts) = + case opt + of OPT_LONG(key,valOpt) => doit (do_long pars (key,valOpt)) opts + | OPT_SHORT cs => do_short pars (cs,opts) + | OPT_STRING s => if isSome f + then let val _ = optError(onlyOne "input file") + in doit pars opts + end + else doit (v,h,e,SOME s) opts + | OPT_NOOPT => doit pars opts + | OPT_NEG cs => let val _ = if null cs then () + else app (fn c => optError + (unknown "-n" (String.implode[c]))) cs + in doit pars opts + end + in doit (false,false,NONE,NONE) opts + end + end diff --git a/fxp/src/Apps/Canon/canonOutput.sml b/fxp/src/Apps/Canon/canonOutput.sml new file mode 100644 index 0000000..3378eaa --- /dev/null +++ b/fxp/src/Apps/Canon/canonOutput.sml @@ -0,0 +1,75 @@ +signature CanonOutput = + sig + type Dtd + + val printError : Errors.Position * Errors.Error -> unit + val printWarning : Errors.Position * Errors.Warning -> unit + + val putProcInst : CanonEncode.File * HookData.ProcInstInfo -> CanonEncode.File + val putStartTag : Dtd -> CanonEncode.File * HookData.StartTagInfo -> CanonEncode.File + val putEndTag : Dtd -> CanonEncode.File * HookData.EndTagInfo -> CanonEncode.File + end + +functor CanonOutput (structure ParserOptions : ParserOptions) : CanonOutput = + struct + open + Base UniChar DfaData Dtd Errors ParserOptions + CanonEncode CanonOptions HookData + + fun printError(pos,err) = if !O_SILENT then () else TextIO.output + (!O_ERROR_DEVICE,formatMessage (4,!O_ERROR_LINEWIDTH) + (Position2String pos + ::(if isFatalError err then "Fatal error:" else "Error:") + ::errorMessage err)) + fun printWarning(pos,warn) = if !O_SILENT then () else TextIO.output + (!O_ERROR_DEVICE,formatMessage (4,!O_ERROR_LINEWIDTH) + (Position2String pos^" Warning:"::warningMessage warn)) + + fun putAttValue (f,cv) = + let + val f1 = putChar(f,0wx22) + val f2 = putDataVector(f1,cv) + val f3 = putChar(f2,0wx22) + in f3 + end + + fun putAttSpec(f,(att,cv)) = + let + val f1 = putBlank f + val f2 = putData(f1,att) + val f3 = putChar(f2,0wx3D) + val f4 = putAttValue(f3,cv) + in f4 + end + + fun putEndTag dtd (f,(_,eidx,_)) = + let + val f1 = putData(f,[0wx3C,0wx2F]) (* "" *) + end + fun putStartTag dtd (f,(pp,eidx,atts,_,mt)) = + let + val f1 = putChar(f,0wx3C) (* #"<" *) + val f2 = putData(f1,Index2Element dtd eidx) + val atts1 = List.mapPartial + (fn (aidx,ap,_) => + case ap + of AP_PRESENT(_,cv,_) => SOME(Index2AttNot dtd aidx,cv) + | AP_DEFAULT(_,cv,_) => SOME(Index2AttNot dtd aidx,cv) + | _ => NONE) atts + val atts2 = UtilList.sort (fn ((a1,_),(a2,_)) => compareData (a1,a2)) atts1 + val f3 = foldl (fn (spec,f) => putAttSpec (f,spec)) f2 atts2 + val f4 = putChar(f3,0wx3E) (* #">" *) + in if mt then putEndTag dtd (f4,(pp,eidx,NONE)) else f4 + end + + fun putProcInst(f,(_,target,_,text)) = + let + val f1 = putData(f,[0wx3c,0wx3f]) + val f2 = putData(f1,target) + val f3 = putBlank f2 + val f4 = putVector(f3 ,text) + in putData(f3,[0wx3f,0wx3e]) + end + end diff --git a/fxp/src/Apps/Copy/copy.cm b/fxp/src/Apps/Copy/copy.cm new file mode 100644 index 0000000..c406998 --- /dev/null +++ b/fxp/src/Apps/Copy/copy.cm @@ -0,0 +1,8 @@ +Group is + copyEncode.sml + copyOptions.sml + copyOutput.sml + copyHooks.sml + copy.sml + ../../fxlib.cm + $/basis.cm diff --git a/fxp/src/Apps/Copy/copy.mlb b/fxp/src/Apps/Copy/copy.mlb new file mode 100644 index 0000000..8a4fb85 --- /dev/null +++ b/fxp/src/Apps/Copy/copy.mlb @@ -0,0 +1,15 @@ +ann + "warnMatch true" + "sequenceUnit true" +in + local + $(MLTON_ROOT)/basis/basis.mlb + ../../fxlib.mlb + in + copyOptions.sml + copyEncode.sml + copyOutput.sml + copyHooks.sml + copy.sml + end +end diff --git a/fxp/src/Apps/Copy/copy.sml b/fxp/src/Apps/Copy/copy.sml new file mode 100644 index 0000000..3bc1819 --- /dev/null +++ b/fxp/src/Apps/Copy/copy.sml @@ -0,0 +1,81 @@ +structure Copy = + struct + structure ParserOptions = ParserOptions () + structure CatOptions = CatOptions () + structure CatParams = + struct + open CatError CatOptions CopyOptions Uri UtilError + + fun catError(pos,err) = if !O_SILENT then () else TextIO.output + (!O_ERROR_DEVICE,formatMessage (4,!O_ERROR_LINEWIDTH) + (Position2String pos^" Error in catalog:"::catMessage err)) + end + structure Resolve = ResolveCatalog (structure Params = CatParams) + structure CopyHooks = CopyHooks (structure ParserOptions = ParserOptions) + structure ParseCopy = Parse (structure Dtd = Dtd + structure Hooks = CopyHooks + structure Resolve = Resolve + structure ParserOptions = ParserOptions) + open + CatOptions CopyOptions Options ParserOptions Uri + + val usage = List.concat [parserUsage,[U_SEP],catalogUsage,[U_SEP],copyUsage] + + exception Exit of OS.Process.status + + fun copy(prog,args) = + let + val prog = "fxcopy" + val hadError = ref false + + fun optError msg = + let val _ = TextIO.output(TextIO.stdErr,msg^".\n") + in hadError := true + end + fun exitError msg = + let val _ = TextIO.output(TextIO.stdErr,msg^".\n") + in raise Exit OS.Process.failure + end + fun exitHelp prog = + let val _ = printUsage TextIO.stdOut prog usage + in raise Exit OS.Process.success + end + fun exitVersion prog = + let val _ = app print [prog," version ",Version.FXP_VERSION,"\n"] + in raise Exit OS.Process.success + end + + fun summOpt prog = "For a summary of options type "^prog^" --help" + fun noFile(f,cause) = "can't open file '"^f^"': "^exnMessage cause + + val opts = parseOptions args + val _ = setParserDefaults() + val opts1 = setParserOptions (opts,optError) + val _ = setCatalogDefaults() + val opts2 = setCatalogOptions (opts1,optError) + val _ = setCopyDefaults() + val (vers,help,err,file) = setCopyOptions (opts2,optError) + val _ = if !hadError then exitError (summOpt prog) else () + val _ = if vers then exitVersion prog else () + val _ = if help then exitHelp prog else () + val _ = case err + of SOME "-" => O_ERROR_DEVICE := TextIO.stdErr + | SOME f => (O_ERROR_DEVICE := TextIO.openOut f + handle IO.Io {cause,...} => exitError(noFile(f,cause))) + | NONE => () + val f = valOf file handle Option => "-" + val uri = if f="-" then NONE else SOME(String2Uri f) + val dtd = Dtd.initDtdTables() + val status = ParseCopy.parseDocument uri (SOME dtd) (CopyHooks.copyStart dtd) + val _ = if isSome err then TextIO.closeOut (!O_ERROR_DEVICE) else () + in status + end + handle Exit status => status + | exn => + let val _ = TextIO.output + (TextIO.stdErr,prog^": Unexpected exception: "^exnMessage exn^".\n") + in OS.Process.failure + end + end + +val _ = Copy.copy(CommandLine.name (), CommandLine.arguments ()) diff --git a/fxp/src/Apps/Copy/copyEncode.sml b/fxp/src/Apps/Copy/copyEncode.sml new file mode 100644 index 0000000..0e6683b --- /dev/null +++ b/fxp/src/Apps/Copy/copyEncode.sml @@ -0,0 +1,135 @@ +signature CopyEncode = + sig + type File + + val noFile : File + val openFile : string * Encoding.Encoding * string -> File + val closeFile : File -> unit + + val putBlank : File -> File + val putNl : File -> File + + val putChar : File * UniChar.Char -> File + val putAttChar : File * UniChar.Char -> File + val putDataChar : File * UniChar.Char -> File + + val putData : File * UniChar.Data -> File + val putAttData : File * UniChar.Data -> File + val putDataData : File * UniChar.Data -> File + + val putVector : File * UniChar.Vector -> File + val putAttVector : File * UniChar.Vector -> File + val putDataVector : File * UniChar.Vector -> File + val putEntVector : File * UniChar.Vector -> File + + val putAttValue : File * UniChar.Vector * UniChar.Char -> File + val putEntValue : bool -> File * UniChar.Vector * UniChar.Char -> File + val putString : File * string -> File + + val putCharRef : File * UniChar.Char -> File + val putGenRef : File * UniChar.Data -> File + val putParRef : File * UniChar.Data -> File + end + +functor CopyEncode (structure ParserOptions : ParserOptions) : CopyEncode = + struct + open + CopyOptions Encode ParserOptions UniChar UniClasses UtilError + + fun encodeError err = if !O_SILENT then () else + TextIO.output(!O_ERROR_DEVICE,formatMessage (4,!O_ERROR_LINEWIDTH) + ("Encoding error:"::encodeMessage err)) + + type File = EncFile + val noFile = encNoFile + fun openFile fe = encOpenFile fe + handle NoSuchFile (f,msg) => noFile before + TextIO.output(!O_ERROR_DEVICE,formatMessage (4,!O_ERROR_LINEWIDTH) + ["Cannot open file '"^f^"' for writing. ("^msg^")"]) + val closeFile = encCloseFile + val validChar = encValidChar + + fun putChar(enc,c) = encPutChar(enc,c) + handle EncodeError(f,msg) => encAdapt(enc,f) before encodeError msg + + fun putData(enc,cs) = foldl (fn (c,enc) => putChar(enc,c)) enc cs + fun putVector(enc,cv) = Vector.foldl (fn (c,enc) => putChar(enc,c)) enc cv + + fun putNl f = putChar(f,0wx0A) + fun putBlank f = putChar(f,0wx20) + + val hexDigits = Vector.tabulate(16,fn i => Chars.fromInt((if i<10 then 48 else 55)+i)) + fun hexDigit n = Vector.sub(hexDigits,Chars.toInt n) + fun charRefSeq c = + if c=0wx00 then [0wx26,0wx23,0wx78,0wx30,0wx3b] (* "�" *) + else let fun mk_hex yet n = if n=(0w0:Char) then yet + else mk_hex (hexDigit(n mod 0w16)::yet) (n div 0w16) + in 0wx26::0wx23::0wx78::mk_hex [0wx3b] c + end + fun putCharRef(f,c) = putData(f,charRefSeq c) + fun putGenRef(f,ent) = let val f1 = putChar(f,0wx26) + val f2 = putData(f1,ent) + val f3 = putChar(f2,0wx3b) + in f3 + end + fun putParRef(f,ent) = let val f1 = putChar(f,0wx25) + val f2 = putData(f1,ent) + val f3 = putChar(f2,0wx3b) + in f3 + end + + fun putAttChar(f,c) = + case c + of 0wx26 => putData(f,[0wx26,0wx61,0wx6d,0wx70,0wx3b]) (* "&" *) + | 0wx3C => putData(f,[0wx26,0wx6c,0wx74,0wx3b]) (* "<" *) + | _ => if validChar(f,c) then putChar(f,c) else putCharRef(f,c) + fun putDataChar(f,c) = + case c + of 0wx26 => putData(f,[0wx26,0wx61,0wx6d,0wx70,0wx3b]) (* "&" *) + | 0wx3C => putData(f,[0wx26,0wx6c,0wx74,0wx3b]) (* "<" *) + | 0wx3E => if !O_COMPATIBILITY + then putData(f,[0wx26,0wx67,0wx74,0wx3b]) (* ">" *) + else putChar(f,c) + | _ => if validChar(f,c) then putChar(f,c) else putCharRef(f,c) + + fun putAttData(f,cs) = + foldl (fn (c,f) => putAttChar(f,c)) f cs + fun putDataData(f,cs) = + foldl (fn (c,f) => putDataChar(f,c)) f cs + + fun putAttVector(f,cv) = + Vector.foldl (fn (c,f) => if validChar(f,c) then putChar(f,c) else putCharRef(f,c)) f cv + fun putDataVector(f,cv) = + Vector.foldl (fn (c,f) => putDataChar(f,c)) f cv + fun putEntVector (f,cv) = + Vector.foldl (fn (c,f) => if validChar(f,c) then putChar(f,c) else putCharRef(f,c)) f cv + + fun putAttValue (f,cv,q) = + let + fun putOne(c,f) = + case c + of 0wx26 => putData(f,[0wx26,0wx61,0wx6d,0wx70,0wx3b]) (* "&" *) + | 0wx3C => putData(f,[0wx26,0wx6c,0wx74,0wx3b]) (* "<" *) + | _ => if c<>q andalso validChar(f,c) then putChar(f,c) else putCharRef(f,c) + val f1 = putChar(f,q) + val f2 = Vector.foldl putOne f1 cv + val f3 = putChar(f2,q) + in f3 + end + fun putEntValue escapeParRef (f,cv,q) = + let + fun putOne(i,c,f) = + case c + of 0wx25 => if escapeParRef then putCharRef(f,c) else putChar(f,c) + | 0wx26 => if i+1 if c<>q andalso validChar(f,c) then putChar(f,c) else putCharRef(f,c) + + val f1 = putChar(f,q) + val f2 = Vector.foldli putOne f1 cv + val f3 = putChar(f2,q) + in f3 + end + + fun putString(f,str) = putData(f,String2Data str) + end diff --git a/fxp/src/Apps/Copy/copyHooks.sml b/fxp/src/Apps/Copy/copyHooks.sml new file mode 100644 index 0000000..15ca08c --- /dev/null +++ b/fxp/src/Apps/Copy/copyHooks.sml @@ -0,0 +1,153 @@ + + + + + + + + + + + +functor CopyHooks (structure ParserOptions : ParserOptions) = + struct + structure CopyOutput = CopyOutput (structure ParserOptions = ParserOptions) + + open + Base Dtd Encoding + CopyOptions CopyOutput + + datatype Where = SOMEWHERE | SUBSET | CONTENT of int | REFERENCE of Where + + type AppData = OS.Process.status * File * Dtd * Where + type AppFinal = OS.Process.status + + fun copyStart dtd = (OS.Process.success,noFile,dtd,SOMEWHERE) + + fun hookXml ((status,_,dtd,wher),(fname,enc,xmlDecl)) = + let val (vers,_,stand) = case xmlDecl + of SOME ves => ves + | NONE => (NONE,NONE,NONE) + val (outEnc,outEncName) = case !O_OUTPUT_ENCODING + of NONE => (enc,encodingName enc) + | SOME x => (NOENC,x) + val f = openFile(!O_OUTPUT_FILE,outEnc,outEncName) + in (status,putXmlDecl(f,(vers,SOME outEncName,stand)),dtd,wher) + end + + fun hookFinish (a as (status,f,_,_)) = status before closeFile f + + fun hookError ((status,f,dtd,wher),err) = (OS.Process.failure,f,dtd,wher) + before printError err + fun hookWarning (a,warn) = a before printWarning warn + + fun hookProcInst (a as (status,f,dtd,wher),pi) = + case wher + of REFERENCE _ => a + | _ => (status,putProcInst(f,pi),dtd,wher) + fun hookComment (a as (status,f,dtd,wher),com) = + case wher + of REFERENCE _ => a + | _ => (status,putComment(f,com),dtd,wher) + fun hookWhite (a as (status,f,dtd,wher),ws) = + case wher + of REFERENCE _ => a + | _ => (status,putVector(f,ws),dtd,wher) + + fun hookDecl (a as (status,f,dtd,wher),decl) = + case wher + of SUBSET => (status,putDecl(f,dtd,decl),dtd,wher) + | _ => a + + fun hookStartTag (a as (status,f,dtd,wher),stag) = + case wher + of CONTENT level => let val f1 = putStartTag(f,dtd,stag) + val level1 = if #5 stag then level else level+1 + in (status,f1,dtd,CONTENT level1) + end + | SOMEWHERE => let val f1 = putStartTag(f,dtd,stag) + in if #5 stag then (status,putNl f1,dtd,wher) + else (status,f1,dtd,CONTENT 1) + end + | _ => a + fun hookEndTag (a as (status,f,dtd,wher),etag) = + case wher + of CONTENT level => let val f1 = putEndTag(f,dtd,etag) + val (f2,wher1) = if level>1 then (f1,CONTENT(level-1)) + else (f1,SOMEWHERE) + in (status,f2,dtd,wher1) + end + | _ => a + + fun hookData (a as (status,f,dtd,wher),(_,text,_)) = + case wher + of CONTENT _ => (status,putDataVector(f,text),dtd,wher) + | _ => a + fun hookCData (a as (status,f,dtd,wher),(_,text)) = + case wher + of CONTENT _ => (status,putCData(f,text),dtd,wher) + | _ => a + + fun hookCharRef (a as (status,f,dtd,wher),(_,ch,cv)) = + case wher + of CONTENT _ => + let val f1 = if !O_EXPAND_CONT_CHAR + then putDataChar(f,ch) else putVector(f,cv) + in (status,f1,dtd,wher) + end + | _ => a + fun hookGenRef (a as (status,f,dtd,wher),(_,idx,ent,included)) = + case wher + of CONTENT l => + if not included then (status,putGenRef(f,Index2GenEnt dtd idx),dtd,wher) + else if (if isExtGen ent then !O_EXPAND_CONT_EXT else !O_EXPAND_CONT_INT) then a + else (status,putGenRef(f,Index2GenEnt dtd idx),dtd,REFERENCE wher) + | REFERENCE _ => if included then (status,f,dtd,REFERENCE wher) else a + | _ => a + fun hookParRef (a as (status,f,dtd,wher),(_,idx,ent,included)) = + case wher + of SUBSET => + if not included then (status,putNl(putParRef(f,Index2ParEnt dtd idx)),dtd,wher) + else if (if isExtPar ent then !O_EXPAND_SUBSET_EXT else !O_EXPAND_SUBSET_INT) then a + else (status,putNl(putParRef(f,Index2ParEnt dtd idx)),dtd,REFERENCE wher) + | REFERENCE _ => if included then (status,f,dtd,REFERENCE wher) else a + | _ => if included then (status,f,dtd,REFERENCE wher) else a + fun hookEntEnd (a as (status,f,dtd,wher),_) = + case wher + of REFERENCE wher1 => (status,f,dtd,wher1) + | _ => a + + fun hookDocType (a as (status,f,dtd,wher),(didx,extId)) = + case wher + of SOMEWHERE => + let + val f1 = putData(f,startDtd) + val f2 = putData(f1,Index2Element dtd didx) + val f3 = if !O_INCLUDE_EXT_SUBSET then f2 + else case extId + of NONE => f2 + | SOME x => putExtId(putBlank f2,x) + in (status,f1,dtd,wher) + end + | _ => a + fun hookSubset (a as (status,f,dtd,wher),_) = + case wher + of SOMEWHERE => (status,putData(f,[0wx20,0wx5B]),dtd,SUBSET) (* " [" *) + | _ => a + fun hookExtSubset (a as (status,f,dtd,wher),_) = + if !O_INCLUDE_EXT_SUBSET + then case wher + of SOMEWHERE => (status,putData(f,[0wx20,0wx5B,0wx0A]),dtd,SUBSET) (* " [\n" *) + | SUBSET => (status,putChar(f,0wx0A),dtd,SUBSET) + | _ => a + else case wher + of SOMEWHERE => (status,f,dtd,REFERENCE wher) + | SUBSET => (status,putChar(f,0wx5D),dtd,REFERENCE SOMEWHERE) (* #"]" *) + | _ => a + fun hookEndDtd(a as (status,f,dtd,wher),_) = + case wher + of SOMEWHERE => (status,putData(f,endDecl),dtd,wher) + | SUBSET => (status,putData(putChar(f,0wx5D),endDecl),dtd,SOMEWHERE) + | REFERENCE wher => (status,putData(f,endDecl),dtd,wher) + | _ => a + end diff --git a/fxp/src/Apps/Copy/copyOptions.sml b/fxp/src/Apps/Copy/copyOptions.sml new file mode 100644 index 0000000..8ad4eda --- /dev/null +++ b/fxp/src/Apps/Copy/copyOptions.sml @@ -0,0 +1,270 @@ +signature CopyOptions = + sig + val O_SILENT : bool ref + val O_ERROR_DEVICE : TextIO.outstream ref + val O_ERROR_LINEWIDTH : int ref + + val O_EXPAND_CONT_CHAR : bool ref + val O_EXPAND_CONT_EXT : bool ref + val O_EXPAND_CONT_INT : bool ref + + val O_EXPAND_SUBSET_EXT : bool ref + val O_EXPAND_SUBSET_INT : bool ref + val O_INCLUDE_EXT_SUBSET : bool ref + + val O_EXPAND_ENT_VAL : bool ref + val O_EXPAND_ATT_VAL : bool ref + + val O_OUTPUT_ENCODING : string option ref + val O_OUTPUT_FILE : string ref + + val setCopyDefaults : unit -> unit + val setCopyOptions : Options.Option list * (string -> unit) + -> bool * bool * string option * string option + + val copyUsage : Options.Usage + end + +structure CopyOptions : CopyOptions = + struct + open Options UtilList + + val O_SILENT = ref false + val O_ERROR_DEVICE = ref TextIO.stdErr + val O_ERROR_LINEWIDTH = ref 80 + + val O_EXPAND_CONT_CHAR = ref false + val O_EXPAND_CONT_EXT = ref false + val O_EXPAND_CONT_INT = ref false + + val O_EXPAND_SUBSET_EXT = ref false + val O_EXPAND_SUBSET_INT = ref false + val O_INCLUDE_EXT_SUBSET = ref false + + val O_EXPAND_ENT_VAL = ref false + val O_EXPAND_ATT_VAL = ref false + + val O_OUTPUT_ENCODING = ref NONE : string option ref + val O_OUTPUT_FILE = ref "-" + + fun setCopyDefaults () = + let + val _ = O_SILENT := false + val _ = O_ERROR_DEVICE := TextIO.stdErr + + val _ = O_EXPAND_CONT_CHAR := false + val _ = O_EXPAND_CONT_EXT := false + val _ = O_EXPAND_CONT_INT := false + + val _ = O_EXPAND_SUBSET_EXT := false + val _ = O_EXPAND_SUBSET_INT := false + val _ = O_INCLUDE_EXT_SUBSET := false + + val _ = O_EXPAND_ENT_VAL := false + val _ = O_EXPAND_ATT_VAL := false + + val _ = O_OUTPUT_ENCODING := NONE + val _ = O_OUTPUT_FILE := "-" + in () + end + + val copyUsage = + [U_ITEM(["-o ","--output="],"Write output to file (stdout)"), + U_ITEM(["-s","--silent"],"Suppress reporting of errors and warnings"), + U_ITEM(["-e ","--error-output="],"Redirect errors to file (stderr)"), + U_SEP, + U_ITEM(["--expand-refs-content[=(yes,no,]"], + "Controls expansion of entity references in content (no)"), + U_ITEM(["--expand-refs-subset[=(no|yes|int|ext)]"], + "Controls expansion of entity references in the DTD (no)"), + U_ITEM(["--expand-ext-subset[=(yes|no)]"],"Expand external subset (no)"), + U_ITEM(["--expand-att-vals[=(yes|no)]"],"Expand and normalize attribute values (no)"), + U_ITEM(["--expand-ent-vals[=(yes|no)]"],"Expand entity values (no)"), + U_SEP, + U_ITEM(["--expand=yes"],"Expand everything"), + U_ITEM(["--expand=no"],"Expand nothing"), + U_ITEM(["--expand=int"],"Expand internal and character entities"), + U_ITEM(["--expand=ext"],"Expand external entities and subset"), + U_SEP, + U_ITEM(["--version"],"Print the version number and exit"), + U_ITEM(["-?","--help"],"Print this text and exit"), + U_ITEM(["--"],"Do not recognize remaining arguments as options") + ] + + fun setCopyOptions (opts,optError) = + let + exception Failed + + val yesNoList= "'yes', 'no' or a list of 'char', 'ext' and 'int'" + val yesNoExtInt = "'yes', 'no', 'ext' or 'int'" + val yesNo = "'yes' or 'no'" + + fun onlyOne what = "at most one "^what^" may be specified" + fun unknown pre opt = String.concat ["unknown option ",pre,opt] + fun hasNoArg pre key = String.concat ["option ",pre,key," expects no argument"] + fun mustHave pre key = String.concat ["option ",pre,key," must have an argument"] + fun errorMustBe(key,what) = String.concat ["the argument to --",key," must be ",what] + + fun check_noarg(key,valOpt) = + if isSome valOpt then optError (hasNoArg "--" key) else () + + fun do_long (pars as (v,h,e,f)) (key,valOpt) = + case key + of "help" => (v,true,e,f) before check_noarg(key,valOpt) + | "version" => (true,h,e,f) before check_noarg(key,valOpt) + | "silent" => pars before O_SILENT := true before check_noarg(key,valOpt) + | "output" => + (case valOpt + of NONE => pars before optError (mustHave "--" key) + | SOME s => pars before O_OUTPUT_FILE := s) + | "output-encoding" => + (case valOpt + of NONE => pars before optError (mustHave "--" key) + | SOME s => pars before O_OUTPUT_ENCODING := SOME s) + | "error-output" => + (case valOpt + of NONE => pars before optError (mustHave "--" key) + | SOME s => (v,h,SOME s,f)) + | "expand-refs-content" => + let + datatype what = CHAR | EXT | INT + fun setFlags whats = + let + val _ = O_EXPAND_CONT_CHAR := member CHAR whats + val _ = O_EXPAND_CONT_EXT := member EXT whats + val _ = O_EXPAND_CONT_INT := member INT whats + in () + end + val _ = case valOpt + of NONE => setFlags [CHAR,EXT,INT] + | SOME "yes" => setFlags [CHAR,EXT,INT] + | SOME "no" => setFlags nil + | SOME s => let val fields = String.fields (fn c => #","=c) s + val whats = foldr + (fn(f,yet)=> + case f + of "char" => CHAR::yet + | "ext" => EXT::yet + | "int" => INT::yet + | _ => yet before optError + (errorMustBe(key,yesNoList))) + nil fields + in setFlags whats + end + in pars + end + | "expand-refs-subset" => + (let val (ext,int) = case valOpt + of NONE => (true,true) + | SOME "yes" => (true,true) + | SOME "no" => (false,false) + | SOME "ext" => (true,false) + | SOME "int" => (false,true) + | SOME _ => raise Failed + val _ = O_EXPAND_SUBSET_EXT := ext + val _ = O_EXPAND_SUBSET_INT := int + val _ = if ext then (O_EXPAND_ENT_VAL := true) else () + in pars + end + handle Failed => pars before optError (errorMustBe(key,yesNoExtInt)) ) + | "expand-ent-vals" => + (let val exp = case valOpt + of NONE => true + | SOME "yes" => true + | SOME "no" => false + | SOME _ => raise Failed + val _ = O_EXPAND_ENT_VAL := exp + in pars + end + handle Failed => pars before optError (errorMustBe(key,yesNo)) ) + | "expand-att-vals" => + (let val exp = case valOpt + of NONE => true + | SOME "yes" => true + | SOME "no" => false + | SOME _ => raise Failed + val _ = O_EXPAND_ATT_VAL := exp + in pars + end + handle Failed => pars before optError (errorMustBe(key,yesNo)) ) + | "expand-ext-subset" => + (let val exp = case valOpt + of NONE => true + | SOME "yes" => true + | SOME "no" => false + | SOME _ => raise Failed + val _ = O_INCLUDE_EXT_SUBSET := exp + val _ = if exp then (O_EXPAND_ENT_VAL := true) else () + in pars + end + handle Failed => pars before optError (errorMustBe(key,yesNo)) ) + | "expand" => + let + datatype what = ALL | NO | EXT | INT + val ext = [O_EXPAND_CONT_EXT,O_EXPAND_SUBSET_EXT, + O_INCLUDE_EXT_SUBSET,O_EXPAND_ENT_VAL] + val int = [O_EXPAND_CONT_CHAR,O_EXPAND_CONT_INT, + O_EXPAND_SUBSET_INT,O_EXPAND_ATT_VAL] + val all = ext@int + fun setFlags what = + let val (yes,no) = + case what + of ALL => (all,nil) + | NO => (nil,all) + | EXT => (ext,int) + | INT => (int,ext) + val _ = app (fn x => x := true) yes + val _ = app (fn x => x := false) no + in () + end + val _ = case valOpt + of NONE => setFlags ALL + | SOME "yes" => setFlags ALL + | SOME "no" => setFlags NO + | SOME "ext" => setFlags EXT + | SOME "int" => setFlags INT + | SOME _ => optError (errorMustBe(key,yesNoExtInt)) + in pars + end + | _ => pars before optError(unknown "--" key) + + fun do_short (pars as (v,h,e,f)) (cs,opts) = + case cs + of nil => doit pars opts + | [#"o"] => (case opts + of OPT_STRING s::opts1 => (O_OUTPUT_FILE := s; + doit pars opts1) + | _ => (optError (mustHave "-" "o"); doit pars opts)) + | [#"e"] => (case opts + of OPT_STRING s::opts1 => doit (v,h,SOME s,f) opts1 + | _ => (optError (mustHave "-" "e"); doit pars opts)) + | cs => doit (foldr + (fn (c,pars) + => case c + of #"s" => pars before O_SILENT := true + | #"o" => pars before optError (mustHave "-" "o") + | #"e" => pars before optError (mustHave "-" "e") + | #"?" => (v,true,e,f) + | c => pars before + optError(unknown "-" (String.implode [c]))) + pars cs) opts + + and doit pars nil = pars + | doit (pars as (v,h,e,f)) (opt::opts) = + case opt + of OPT_LONG(key,valOpt) => doit (do_long pars (key,valOpt)) opts + | OPT_SHORT cs => do_short pars (cs,opts) + | OPT_STRING s => if isSome f + then let val _ = optError(onlyOne "input file") + in doit pars opts + end + else doit (v,h,e,SOME s) opts + | OPT_NOOPT => doit pars opts + | OPT_NEG cs => let val _ = if null cs then () + else app (fn c => optError + (unknown "-n" (String.implode[c]))) cs + in doit pars opts + end + in doit (false,false,NONE,NONE) opts + end + end diff --git a/fxp/src/Apps/Copy/copyOutput.sml b/fxp/src/Apps/Copy/copyOutput.sml new file mode 100644 index 0000000..11fde30 --- /dev/null +++ b/fxp/src/Apps/Copy/copyOutput.sml @@ -0,0 +1,330 @@ +signature CopyOutput = + sig + type Dtd + + include CopyEncode + + val startDtd : UniChar.Data + val endDecl : UniChar.Data + + val printError : Errors.Position * Errors.Error -> unit + val printWarning : Errors.Position * Errors.Warning -> unit + + val putDecl : File * Dtd * HookData.DeclInfo -> File + val putXmlDecl : File * HookData.XmlDecl -> File + val putProcInst : File * HookData.ProcInstInfo -> File + val putComment : File * HookData.CommentInfo -> File + val putStartTag : File * Dtd * HookData.StartTagInfo -> File + val putEndTag : File * Dtd * HookData.EndTagInfo -> File + val putCData : File * UniChar.Vector -> File + val putExtId : File * Base.ExternalId -> File + end + +functor CopyOutput (structure ParserOptions : ParserOptions) : CopyOutput = + struct + structure CopyEncode = CopyEncode (structure ParserOptions = ParserOptions) + + open + Base DfaData Dtd Errors ParserOptions UniChar Uri + CopyEncode CopyOptions HookData + + fun printError(pos,err) = if !O_SILENT then () else TextIO.output + (!O_ERROR_DEVICE,formatMessage (4,!O_ERROR_LINEWIDTH) + (Position2String pos + ::(if isFatalError err then "Fatal error:" else "Error:") + ::errorMessage err)) + fun printWarning(pos,warn) = if !O_SILENT then () else TextIO.output + (!O_ERROR_DEVICE,formatMessage (4,!O_ERROR_LINEWIDTH) + (Position2String pos^" Warning:"::warningMessage warn)) + + val ANY = String2Data "ANY" + val ATTLIST = String2Data "" + val endCom = String2Data "-->" + val endPi = String2Data "?>" + val endSection= String2Data "]]>" + val preAttDef = String2Data "\n " + val startCom = String2Data "\"", + " color: "^comColor, + " info1: \""^Position2String pos^"\"", + " horizontal_order: "^Int.toString i, + " }" + ]) + in f1 + end + + fun outDataNode (f,path,(i,item)) = + let + val title = path^i + val (pos,label,text) = + case item + of DATA((pos,_),cv,_) => let val str = Vector2String cv + in (pos,str,str) + end + | CDATA((pos,_),cv) => let val str = Vector2String cv + in (pos,"",str) + end + | CREF((pos,_),c,cv) => (pos,Vector2String cv,Char2String c) + val f1 = outLines + (f,[" node: {", + " title: \""^title^"\"", + " label: \""^label^"\"", + " color: "^txtColor, + " info1: \""^Position2String pos^"\"", + " horizontal_order: "^i, + " }" + ]) + in (f1,pos,title,text) + end + + fun outDataGraph (f,i,path,items) = + if null items then NONE + else let val i1 = i+1 + val iS = Int.toString i1 + val title = path^iS + val f1 = outLines + (f,["", + " graph: {", + " title : \""^title^"\"", + " color : "^txtColor, + " folding: 1", + " horizontal_order: "^iS + ]) + val (f2,pos,titles,texts) = + foldl (fn (item,(f,_,titles,texts)) + => let val (f1,pos,title,text) = outDataNode (f,path,item) + in (f1,pos,title::titles,text::texts) + end) (f1,nullPosition,nil,nil) items + val label = String.concat texts + val (firstTitle,f3) = foldr + (fn (title,(next,f)) => + case next + of NONE => (SOME title,f) + | SOME nextTitle => + (SOME title,outLines + (f,["", + " nearedge: {", + " sourcename: \""^title^"\"", + " targetname:\""^nextTitle^"\"", + " }"]))) + (NONE,f2) titles + val f4 = outLines + (f3,[" label: \""^label^"\"", + " info1: \""^Position2String pos^"\"", + " }" + ]) + in SOME (f4,i1,valOf firstTitle) + end + + fun outData (a as (dtd,f,(i,path,titles,data),stack)) = + case outDataGraph (f,i,path,data) + of NONE => a + | SOME(f1,i1,title) => (dtd,f1,(i1,path,title::titles,nil),stack) + + fun attValType dtd avOpt = + case avOpt + of NONE => NONE + | SOME av => SOME + (case av + of AV_CDATA _ => "CDATA" + | AV_NMTOKEN _ => "NMTOKEN" + | AV_NMTOKENS _ => "NMTOKENS" + | AV_ENTITY _ => "ENTITY" + | AV_ENTITIES _ => "ENTITIES" + | AV_ID _ => "ID" + | AV_IDREF _=> "IDREF" + | AV_IDREFS _=> "IDREFS" + | AV_GROUP(is,_) => List2xString + ("(","|",")") (Data2String o (Index2AttNot dtd)) is + | AV_NOTATION(is,_) => List2xString + ("NOTATION(","|",")") (Data2String o (Index2AttNot dtd)) is) + + fun outAttNode dtd (f,path,(i,ap,_)) = + let + val iS = Int.toString i + val attTitle = path^iS + val attLabel = Data2String(Index2AttNot dtd i) + val valTitle = attTitle^".0" + val (valLabel,specText,typInfo) = + case ap + of AP_IMPLIED => ("\f"^typColor^"#IMPLIED","",NONE) + | AP_MISSING => ("\f"^misColor^"MISSING","",NONE) + | AP_DEFAULT(_,cv,av) => + let val str = Vector2String cv + in ("\f"^typColor^"#DEFAULT:\f31"^str,"",attValType dtd av) + end + | AP_PRESENT(_,cv,av) => + let val str = Vector2String cv + in (str," "^attLabel^"=\\\""^str^"\\\"",attValType dtd av) + end + val f1 = outLines + (f,["", + " node: {", + " title: \""^attTitle^"\"", + " label: \""^attLabel^"\"", + " color: "^attColor, + " horizontal_order: 0", + " }", + " node: {", + " title: \""^valTitle^"\"", + " label: \""^valLabel^"\"" + ]) + val f2 = case typInfo + of NONE => f1 + | SOME info => outLine(f1," info2: \""^info^"\"") + val f3 = outLines + (f2,[" color: "^valColor, + " }", + " edge: {", + " sourcename: \""^attTitle^"\"", + " targetname: \""^valTitle^"\"", + " }" + ]) + in (f3,attTitle,specText) + end + + fun outElemGraph dtd (f,i,path,children,((pos,_),el,atts,_,_)) = + let + val iS = Int.toString i + val title = path^iS + val nodeTitle = title^".0" + val nodeLabel = Data2String (Index2Element dtd el) + val attPath = nodeTitle^"." + val f1 = outLines(f,[" graph: {", + " title : \""^title^"\"", + " color : "^elColor, + " folding: 1", + " horizontal_order: "^iS, + "", + " node: {", + " title: \""^nodeTitle^"\"", + " color: "^elColor, + " horizontal_order: "^iS, + " label: \""^nodeLabel^"\"", + " info1: \""^Position2String pos^"\"", + " }" + ]) + val (f2,attTitles,attTexts) = foldl + (fn (att,(f,titles,texts)) + => let val (f1,title,text) = outAttNode dtd (f,attPath,att) + in (f1,title::titles,text::texts) + end) + (f1,nil,nil) atts + + val f3 = foldr + (fn (attTitle,f) => outLines(f,["", + " edge: {", + " sourcename: \""^nodeTitle^"\"", + " targetname:\""^attTitle^"\"", + " }"])) + f2 attTitles + + val attsText = String.concat attTexts + val label = nodeLabel^attsText + + val f4 = outLines(f3,[" label: \""^label^"\"", + " info1: \""^Position2String pos^"\"", + " }"]) + val f5 = foldr + (fn (child,f) => outLines(f,["", + " edge: {", + " sourcename: \""^title^"\"", + " targetname:\""^child^"\"", + " }"])) + f4 children + in (f5,title) + end + + fun outRoot (f,titles) = + let val f1 = outLines + (f,["", + " node: {", + " title : \"root\"", + " label : \"\"", + " width : 0", + " height: 0", + " }"]) + val f2 = + foldr (fn (title,f) => + outLines (f,["", + " edge: {", + " sourcename: \"root\"", + " targetname: \""^title^"\"", + " linestyle : invisible", + " }"])) f1 titles + in f2 + end + + fun hookProcInst (a,pi) = + let + val (dtd,f,(i,path,titles,_),stack) = outData a + val i1 = i+1 + val title = path^Int.toString i1 + val f1 = outPiNode(f,i1,title,pi) + in + (dtd,f1,(i1,path,title::titles,nil),stack) + end + + fun hookComment (a,com) = + let + val (dtd,f,(i,path,titles,_),stack) = outData a + val i1 = i+1 + val title = path^Int.toString i1 + val f1 = outComNode(f,i1,title,com) + in + (dtd,f1,(i1,path,title::titles,nil),stack) + end + + fun hookEndTag (a,_) = + let val (dtd,f,(_,_,titles,data),stack) = outData a + in case stack + of nil => a + | (stag,i,path,titles')::rest => + let + val (f1,title) = outElemGraph dtd (f,i,path,titles,stag) + in + (dtd,f1,(i,path,title::titles',nil),rest) + end + end + + fun hookStartTag (a,stag as (_,_,_,_,mt)) = + let + val (dtd,f,(i,path,titles,data),stack) = outData a + val i1 = i+1 + val title = path^Int.toString i1 + val a1 = (dtd,f,(0,title^".",nil,nil),(stag,i1,path,titles)::stack) + in + if mt then hookEndTag (a1,()) else a1 + end + + fun hookData0 ((dtd,f,(i,path,titles,data),stack),item) = + let + val i1 = i+1 + val iS = Int.toString i1 + in + (dtd,f,(i1,path,titles,(iS,item)::data),stack) + end + + fun hookData (a,x) = hookData0(a,DATA x) + fun hookCData (a,x) = hookData0(a,CDATA x) + fun hookCharRef (a,x) = hookData0(a,CREF x) + + fun hookError (a,pe) = a before printError pe + fun hookWarning (a,pw) = a before printWarning pw + + fun hookXml((dtd,_,_,_),_) = + let val f = if !O_OUTPUT_FILE="-" then TextIO.stdOut + else TextIO.openOut (!O_OUTPUT_FILE) + val f1 = outLines(f,["graph: {", + " layoutalgorithm: tree", + " smanhattanedges: yes", + " spreadlevel : 1000", + "", + " colorentry "^piColor^": "^piRgb, + " colorentry "^comColor^": "^comRgb, + " colorentry "^txtColor^": "^txtRgb, + " colorentry "^elColor^": "^elRgb, + " colorentry "^valColor^": "^valRgb, + " colorentry "^attColor^": "^attRgb, + " colorentry "^misColor^": "^misRgb, + " colorentry "^typColor^": "^typRgb, + "", + " infoname 1: \"Source Position\"", + " infoname 2: \"Attribute Type\"", + " infoname 3: \"\"", + "", + " edge.arrowstyle : none", + " foldedge.thickness: 1" + ]) + in + (dtd,f1,(0,"",nil,nil),nil) + end + + fun hookFinish (_,f,(_,_,titles,_),_) = + let + val f1 = outRoot(f,titles) + val f2 = outLine(f1,"}") + in + if !O_OUTPUT_FILE="-" then () else TextIO.closeOut f2 + end + end + +functor VizHooks_ ( structure Dtd : Dtd ) = VizHooks ( structure Dtd = Dtd ) : Hooks diff --git a/fxp/src/Apps/Viz/vizOptions.sml b/fxp/src/Apps/Viz/vizOptions.sml new file mode 100644 index 0000000..05e6a47 --- /dev/null +++ b/fxp/src/Apps/Viz/vizOptions.sml @@ -0,0 +1,106 @@ +signature VizOptions = + sig + val O_SILENT : bool ref + val O_ERROR_DEVICE : TextIO.outstream ref + val O_ERROR_LINEWIDTH : int ref + val O_OUTPUT_FILE : string ref + + val setVizDefaults : unit -> unit + val setVizOptions : Options.Option list * (string -> unit) + -> bool * bool * string option * string option + + val vizUsage : Options.Usage + end + +structure VizOptions : VizOptions = + struct + open Options + + val O_SILENT = ref false + val O_ERROR_DEVICE = ref TextIO.stdErr + val O_ERROR_LINEWIDTH = ref 80 + val O_OUTPUT_FILE = ref "-" + + fun setVizDefaults () = + let + val _ = O_SILENT := false + val _ = O_ERROR_DEVICE := TextIO.stdErr + val _ = O_OUTPUT_FILE := "-" + in () + end + + val vizUsage = + [U_ITEM(["-o ","--output="],"Write output to file (stdout)"), + U_ITEM(["-s","--silent"],"Suppress reporting of errors and warnings"), + U_ITEM(["-e ","--error-output="],"Redirect errors to file (stderr)"), + U_SEP, + U_ITEM(["--version"],"Print the version number and exit"), + U_ITEM(["-?","--help"],"Print this text and exit"), + U_ITEM(["--"],"Do not recognize remaining arguments as options") + ] + + fun setVizOptions (opts,optError) = + let + fun onlyOne what = "at most one "^what^" may be specified" + fun unknown pre opt = String.concat ["unknown option ",pre,opt] + fun hasNoArg pre key = String.concat ["option ",pre,key," expects no argument"] + fun mustHave pre key = String.concat ["option ",pre,key," must have an argument"] + + fun check_noarg(key,valOpt) = + if isSome valOpt then optError (hasNoArg "--" key) else () + + fun do_long (pars as (v,h,e,f)) (key,valOpt) = + case key + of "help" => (v,true,e,f) before check_noarg(key,valOpt) + | "version" => (true,h,e,f) before check_noarg(key,valOpt) + | "silent" => pars before O_SILENT := true before check_noarg(key,valOpt) + | "output" => + (case valOpt + of NONE => pars before optError (mustHave "--" key) + | SOME s => pars before O_OUTPUT_FILE := s) + | "error-output" => + (case valOpt + of NONE => pars before optError (mustHave "--" key) + | SOME s => (v,h,SOME s,f)) + | _ => pars before optError(unknown "--" key) + + fun do_short (pars as (v,h,e,f)) (cs,opts) = + case cs + of nil => doit pars opts + | [#"o"] => (case opts + of OPT_STRING s::opts1 => (O_OUTPUT_FILE := s; + doit pars opts1) + | _ => (optError (mustHave "-" "o"); doit pars opts)) + | [#"e"] => (case opts + of OPT_STRING s::opts1 => doit (v,h,SOME s,f) opts1 + | _ => (optError (mustHave "-" "e"); doit pars opts)) + | cs => doit (foldr + (fn (c,pars) + => case c + of #"s" => pars before O_SILENT := true + | #"o" => pars before optError (mustHave "-" "o") + | #"e" => pars before optError (mustHave "-" "e") + | #"?" => (v,true,e,f) + | c => pars before + optError(unknown "-" (String.implode [c]))) + pars cs) opts + + and doit pars nil = pars + | doit (pars as (v,h,e,f)) (opt::opts) = + case opt + of OPT_LONG(key,valOpt) => doit (do_long pars (key,valOpt)) opts + | OPT_SHORT cs => do_short pars (cs,opts) + | OPT_STRING s => if isSome f + then let val _ = optError(onlyOne "input file") + in doit pars opts + end + else doit (v,h,e,SOME s) opts + | OPT_NOOPT => doit pars opts + | OPT_NEG cs => let val _ = if null cs then () + else app (fn c => optError + (unknown "-n" (String.implode[c]))) cs + in doit pars opts + end + in doit (false,false,NONE,NONE) opts + end + end diff --git a/fxp/src/Catalog/catData.sml b/fxp/src/Catalog/catData.sml new file mode 100644 index 0000000..65ce091 --- /dev/null +++ b/fxp/src/Catalog/catData.sml @@ -0,0 +1,13 @@ + + +structure CatData = + struct + datatype CatEntry = + E_BASE of Uri.Uri + | E_DELEGATE of string * Uri.Uri + | E_EXTEND of Uri.Uri + | E_MAP of string * Uri.Uri + | E_REMAP of Uri.Uri * Uri.Uri + + type Catalog = Uri.Uri * CatEntry list + end diff --git a/fxp/src/Catalog/catDtd.sml b/fxp/src/Catalog/catDtd.sml new file mode 100644 index 0000000..49e48c2 --- /dev/null +++ b/fxp/src/Catalog/catDtd.sml @@ -0,0 +1,54 @@ +signature CatDtd = + sig + type Dtd + + val baseIdx : int + val delegateIdx : int + val extendIdx : int + val mapIdx : int + val remapIdx : int + + val hrefIdx : int + val pubidIdx : int + val sysidIdx : int + + val Index2AttNot : Dtd -> int -> UniChar.Data + val Index2Element : Dtd -> int -> UniChar.Data + end + +structure CatDtd = + struct + open Dtd + + val baseGi = UniChar.String2Data "Base" + val delegateGi = UniChar.String2Data "Delegate" + val extendGi = UniChar.String2Data "Extend" + val mapGi = UniChar.String2Data "Map" + val remapGi = UniChar.String2Data "Remap" + + val hrefAtt = UniChar.String2Data "HRef" + val pubidAtt = UniChar.String2Data "PublicId" + val sysidAtt = UniChar.String2Data "SystemId" + + fun initDtdTables () = + let + val dtd = Dtd.initDtdTables() + val _ = app (ignore o (Element2Index dtd)) [baseGi,delegateGi,extendGi,mapGi,remapGi] + val _ = app (ignore o (AttNot2Index dtd)) [hrefAtt,pubidAtt,sysidAtt] + in dtd + end + + local + val dtd = initDtdTables() + in + val baseIdx = Element2Index dtd baseGi + val delegateIdx = Element2Index dtd delegateGi + val extendIdx = Element2Index dtd extendGi + val mapIdx = Element2Index dtd mapGi + val remapIdx = Element2Index dtd remapGi + + val hrefIdx = AttNot2Index dtd hrefAtt + val pubidIdx = AttNot2Index dtd pubidAtt + val sysidIdx = AttNot2Index dtd sysidAtt + end + end diff --git a/fxp/src/Catalog/catError.sml b/fxp/src/Catalog/catError.sml new file mode 100644 index 0000000..538dee5 --- /dev/null +++ b/fxp/src/Catalog/catError.sml @@ -0,0 +1,117 @@ + + + + + + + + + + +signature CatError = + sig + type Position + val nullPosition : Position + val Position2String : Position -> string + + datatype Location = + LOC_CATALOG + | LOC_COMMENT + | LOC_NOCOMMENT + | LOC_PUBID + | LOC_SYSID + + datatype Expected = + EXP_NAME + | EXP_LITERAL + + datatype CatError = + ERR_DECODE_ERROR of Decode.Error.DecodeError + | ERR_NO_SUCH_FILE of string * string + | ERR_ILLEGAL_HERE of UniChar.Char * Location + | ERR_MISSING_WHITE + | ERR_EOF of Location + | ERR_EXPECTED of Expected * UniChar.Char + | ERR_XML of Errors.Error + | ERR_MISSING_ATT of UniChar.Data * UniChar.Data + | ERR_NON_PUBID of UniChar.Data * UniChar.Data + + val catMessage : CatError -> string list + end + +structure CatError : CatError = + struct + open Errors UtilError UtilString + + type Position = string * int * int + val nullPosition = ("",0,0) + + fun Position2String (fname,l,c) = + if fname="" then "" + else String.concat ["[",fname,":",Int2String l,".",Int2String c,"]"] + + datatype Location = + LOC_CATALOG + | LOC_COMMENT + | LOC_NOCOMMENT + | LOC_PUBID + | LOC_SYSID + + fun Location2String loc = + case loc + of LOC_CATALOG => "catalog file" + | LOC_COMMENT => "comment" + | LOC_NOCOMMENT => "something other than a comment" + | LOC_PUBID => "public identifier" + | LOC_SYSID => "system identifier" + + fun InLocation2String loc = + case loc + of LOC_CATALOG => "in a catalog file" + | LOC_COMMENT => "in a comment" + | LOC_NOCOMMENT => "outside of comments" + | LOC_PUBID => "in a public identifier" + | LOC_SYSID => "in a system identifier" + + datatype Expected = + EXP_NAME + | EXP_LITERAL + + fun Expected2String exp = + case exp + of EXP_NAME => "a name" + | EXP_LITERAL => "a literal" + + datatype CatError = + ERR_DECODE_ERROR of Decode.Error.DecodeError + | ERR_NO_SUCH_FILE of string * string + | ERR_ILLEGAL_HERE of UniChar.Char * Location + | ERR_MISSING_WHITE + | ERR_EOF of Location + | ERR_EXPECTED of Expected * UniChar.Char + | ERR_XML of Error + | ERR_MISSING_ATT of UniChar.Data * UniChar.Data + | ERR_NON_PUBID of UniChar.Data * UniChar.Data + + fun catMessage err = + case err + of ERR_DECODE_ERROR err => Decode.Error.decodeMessage err + | ERR_NO_SUCH_FILE(f,msg) => ["Could not open file",quoteErrorString f,"("^msg^")"] + + | ERR_ILLEGAL_HERE (c,loc) => + ["Character",quoteErrorChar c,"is not allowed",InLocation2String loc] + + | ERR_MISSING_WHITE => ["Missing white space"] + | ERR_EOF loc => [toUpperFirst (Location2String loc),"ended by end of file"] + | ERR_EXPECTED (exp,c) => + ["Expected",Expected2String exp,"but found",quoteErrorChar c] + + | ERR_XML err => errorMessage err + | ERR_MISSING_ATT(elem,att) => + ["Element",quoteErrorData elem,"has no",quoteErrorData att,"attribute"] + | ERR_NON_PUBID(att,cs) => + ["Value specified for attribute",quoteErrorData att,"contains non-PublicId", + case cs + of [c] => "character"^quoteErrorChar c + | cs => List2xString ("characters ",", ","") quoteErrorChar cs] + end diff --git a/fxp/src/Catalog/catFile.sml b/fxp/src/Catalog/catFile.sml new file mode 100644 index 0000000..d7c7c76 --- /dev/null +++ b/fxp/src/Catalog/catFile.sml @@ -0,0 +1,74 @@ + + + + + + + + + +signature CatFile = + sig + type CatFile + type Position + + val catOpenFile : Uri.Uri -> CatFile + val catCloseFile : CatFile -> unit + val catGetChar : CatFile -> UniChar.Char * CatFile + val catPos : CatFile -> CatError.Position + end + +functor CatFile ( structure Params : CatParams ) : CatFile = + struct + open UniChar CatError Decode Params Uri UtilError + + (* column, line, break *) + type PosInfo = int * int * bool + val startPos = (0,1,false) + + datatype CatFile = + NOFILE of string * PosInfo + | DIRECT of DecFile * PosInfo + + fun catPos cf = + case cf + of NOFILE (uri,(col,line,_)) => (uri,line,col) + | DIRECT (dec,(col,line,_)) => (decName dec,line,col) + + fun catOpenFile uri = + let val dec = decOpenUni(SOME uri,!O_CATALOG_ENC) + in DIRECT(dec,startPos) + end + handle NoSuchFile fmsg => let val _ = catError(nullPosition,ERR_NO_SUCH_FILE fmsg) + in NOFILE(Uri2String uri,startPos) + end + + fun catCloseFile cf = + case cf + of NOFILE _ => () + | DIRECT(dec,_) => ignore (decClose dec) + + fun catGetChar cf = + case cf + of NOFILE _ => (0wx00,cf) + | DIRECT(dec,(col,line,brk)) => + (let val (c,dec1) = decGetChar dec + in case c + of 0wx09 => (c,DIRECT(dec1,(col+1,line,false))) + | 0wx0A => if brk then catGetChar(DIRECT(dec1,(col,line,false))) + else (c,DIRECT(dec1,(0,line+1,false))) + | 0wx0D => (0wx0A,DIRECT(dec1,(0,line+1,true))) + | _ => if c>=0wx20 then (c,DIRECT(dec1,(col+1,line,false))) + else let val err = ERR_ILLEGAL_HERE(c,LOC_CATALOG) + val _ = catError(catPos cf,err) + in catGetChar(DIRECT(dec1,(col+1,line,false))) + end + end + handle DecEof dec => (0wx00,NOFILE(decName dec,(col,line,brk))) + | DecError(dec,_,err) => + let val _ = catError(catPos cf,ERR_DECODE_ERROR err) + in catGetChar(DIRECT(dec,(col,line,false))) + end + ) + end + diff --git a/fxp/src/Catalog/catHooks.sml b/fxp/src/Catalog/catHooks.sml new file mode 100644 index 0000000..771f393 --- /dev/null +++ b/fxp/src/Catalog/catHooks.sml @@ -0,0 +1,89 @@ +signature CatHooks = + sig + type AppData = CatData.CatEntry list + + val initCatHooks : unit -> AppData + end + +functor CatHooks (structure Params : CatParams + structure Dtd : CatDtd ) = + struct + open + Dtd HookData IgnoreHooks Params UniChar UniClasses Uri UtilList + CatData CatError + + type AppData = Dtd * CatEntry list + type AppFinal = CatEntry list + + fun initCatHooks dtd = (dtd,nil) + + fun hookError (a,(pos,err)) = a before catError (pos,ERR_XML err) + + fun getAtt dtd (pos,elem,att,trans) atts = + let + val cvOpt = findAndMap + (fn (i,ap,_) => if i<>att then NONE + else case ap + of AP_DEFAULT(_,cv,_) => SOME cv + | AP_PRESENT(_,cv,_) => SOME cv + | _ => NONE) + atts + in case cvOpt + of SOME cv => trans (pos,att) cv + | NONE => NONE before catError + (pos,ERR_MISSING_ATT(Index2Element dtd elem,Index2AttNot dtd att)) + end + + fun makePubid dtd (pos,att) cv = + let val (cs,bad) = + Vector.foldr + (fn (c,(cs,bad)) => if isPubid c then (Char2char c::cs,bad) + else (cs,c::bad)) + (nil,nil) cv + in if null bad then SOME(String.implode cs) + else NONE before catError(pos,ERR_NON_PUBID(Index2AttNot dtd att,bad)) + end + + fun makeUri (pos,att) cv = SOME cv + + fun hookStartTag (a as (dtd,items),((_,pos),elem,atts,_,_)) = + if elem=baseIdx + then let val hrefOpt = getAtt dtd (pos,elem,hrefIdx,makeUri) atts + in case hrefOpt + of NONE => a + | SOME href => (dtd,E_BASE (Vector2Uri href)::items) + end + else if elem=delegateIdx + then let val hrefOpt = getAtt dtd (pos,elem,hrefIdx,makeUri) atts + val pubidOpt = getAtt dtd (pos,elem,pubidIdx,makePubid dtd) atts + in case (hrefOpt,pubidOpt) + of (SOME href,SOME pubid) => + (dtd,E_DELEGATE(pubid,Vector2Uri href)::items) + | _ => a + end + else if elem=extendIdx + then let val hrefOpt = getAtt dtd (pos,elem,hrefIdx,makeUri) atts + in case hrefOpt + of NONE => a + | SOME href => (dtd,E_EXTEND (Vector2Uri href)::items) + end + else if elem=mapIdx + then let val hrefOpt = getAtt dtd (pos,elem,hrefIdx,makeUri) atts + val pubidOpt = getAtt dtd (pos,elem,pubidIdx,makePubid dtd) atts + in case (hrefOpt,pubidOpt) + of (SOME href,SOME pubid) => + (dtd,E_MAP(pubid,Vector2Uri href)::items) + | _ => a + end + else if elem=remapIdx + then let val hrefOpt = getAtt dtd (pos,elem,hrefIdx,makeUri) atts + val sysidOpt = getAtt dtd (pos,elem,sysidIdx,makeUri) atts + in case (hrefOpt,sysidOpt) + of (SOME href,SOME sysid) => + (dtd,E_REMAP(Vector2Uri sysid,Vector2Uri href)::items) + | _ => a + end + else a + + fun hookFinish (_,items) = rev items + end diff --git a/fxp/src/Catalog/catOptions.sml b/fxp/src/Catalog/catOptions.sml new file mode 100644 index 0000000..d28f714 --- /dev/null +++ b/fxp/src/Catalog/catOptions.sml @@ -0,0 +1,136 @@ +signature CatOptions = + sig + val O_CATALOG_FILES : Uri.Uri list ref + val O_PREFER_SOCAT : bool ref + val O_PREFER_SYSID : bool ref + val O_PREFER_CATALOG : bool ref + val O_SUPPORT_REMAP : bool ref + val O_CATALOG_ENC : Encoding.Encoding ref + + val setCatalogDefaults : unit -> unit + val setCatalogOptions : Options.Option list * (string -> unit) -> Options.Option list + + val catalogUsage : Options.Usage + end + +functor CatOptions () : CatOptions = + struct + open Encoding Options Uri + + val O_CATALOG_FILES = ref nil: Uri list ref + val O_PREFER_SOCAT = ref false + val O_PREFER_SYSID = ref false + val O_PREFER_CATALOG = ref true + val O_SUPPORT_REMAP = ref true + val O_CATALOG_ENC = ref LATIN1 + + fun setCatalogDefaults() = + let + val _ = O_CATALOG_FILES := nil + val _ = O_PREFER_SOCAT := false + val _ = O_PREFER_SYSID := false + val _ = O_PREFER_CATALOG := true + val _ = O_SUPPORT_REMAP := true + val _ = O_CATALOG_ENC := LATIN1 + in () + end + + val catalogUsage = + [U_ITEM(["-C ","--catalog="],"Use catalog "), + U_ITEM(["--catalog-syntax=(soc|xml)"],"Default syntax for catalogs (xml)"), + U_ITEM(["--catalog-encoding="],"Default encoding for Socat catalogs (LATIN1)"), + U_ITEM(["--catalog-remap=[(yes|no)]"],"Support remapping of system identifiers (yes)"), + U_ITEM(["--catalog-priority=(map|remap|sys)"],"Resolving strategy in catalogs (map)") + ] + + fun setCatalogOptions (opts,doError) = + let + val catalogs = ref nil:string list ref + + fun hasNoArg key = "option "^key^" has no argument" + fun mustHave key = String.concat ["option ",key," must have an argument"] + fun mustBe(key,what) = String.concat ["the argument to --",key," must be ",what] + + val yesNo = "'yes' or 'no'" + val mapRemapSys = "'map', 'remap' or 'sys'" + val encName = "'ascii', 'latin1', 'utf8' or 'utf16'" + val syntaxName = "'soc' or 'xml'" + + fun do_catalog valOpt = + case valOpt + of NONE => doError(mustHave "--catalog") + | SOME s => catalogs := s::(!catalogs) + + fun do_prio valOpt = + let fun set(cat,sys) = (O_PREFER_CATALOG := cat; O_PREFER_SYSID := sys) + in case valOpt + of NONE => doError(mustHave "--catalog-priority") + | SOME "map" => set(true,false) + | SOME "remap" => set(true,true) + | SOME "sys" => set(false,true) + | SOME s => doError(mustBe("catalog-priority",mapRemapSys)) + end + + fun do_enc valOpt = + case valOpt + of NONE => doError(mustHave "--catalog-encoding") + | SOME s => case isEncoding s + of NOENC => doError("unsupported encoding "^s) + | enc => O_CATALOG_ENC := enc + + fun do_remap valOpt = + case valOpt + of NONE => doError(mustHave "--catalog-remap") + | SOME "no" => O_SUPPORT_REMAP := false + | SOME "yes" => O_SUPPORT_REMAP := true + | SOME s => doError(mustBe("catalog-remap",yesNo)) + + fun do_syntax valOpt = + case valOpt + of NONE => doError(mustHave "--catalog-syntax") + | SOME "soc" => O_PREFER_SOCAT := true + | SOME "xml" => O_PREFER_SOCAT := false + | SOME s => doError(mustBe("catalog-remap",syntaxName)) + + fun do_long(key,valOpt) = + case key + of "catalog" => true before do_catalog valOpt + | "catalog-remap" => true before do_remap valOpt + | "catalog-syntax" => true before do_syntax valOpt + | "catalog-encoding" => true before do_enc valOpt + | "catalog-priority" => true before do_prio valOpt + | _ => false + + fun do_short cs opts = + case cs + of nil => doit opts + | [#"C"] => + (case opts + of OPT_STRING s::opts1 => (catalogs := s::(!catalogs); + doit opts1) + | _ => let val _ = doError (mustHave "-C") + in doit opts + end) + | cs => + let val cs1 = List.filter + (fn c => if #"C"<>c then true + else false before doError (mustHave "-C")) cs + in if null cs1 then doit opts else (OPT_SHORT cs1)::doit opts + end + + and doit nil = nil + | doit (opt::opts) = + case opt + of OPT_NOOPT => opts + | OPT_LONG(key,value) => if do_long(key,value) then doit opts + else opt::doit opts + | OPT_SHORT cs => do_short cs opts + | OPT_NEG cs => opt::doit opts + | OPT_STRING s => opt::doit opts + + val opts1 = doit opts + val uris = map String2Uri (!catalogs) + val _ = O_CATALOG_FILES := uris + in opts1 + end + end diff --git a/fxp/src/Catalog/catParams.sml b/fxp/src/Catalog/catParams.sml new file mode 100644 index 0000000..056eb31 --- /dev/null +++ b/fxp/src/Catalog/catParams.sml @@ -0,0 +1,17 @@ + + + + + +signature CatParams = + sig + val O_CATALOG_FILES : Uri.Uri list ref + val O_PREFER_SOCAT : bool ref + val O_PREFER_SYSID : bool ref + val O_PREFER_CATALOG : bool ref + val O_SUPPORT_REMAP : bool ref + val O_CATALOG_ENC : Encoding.Encoding ref + + val catError : CatError.Position * CatError.CatError -> unit + end + diff --git a/fxp/src/Catalog/catParse.sml b/fxp/src/Catalog/catParse.sml new file mode 100644 index 0000000..64f781a --- /dev/null +++ b/fxp/src/Catalog/catParse.sml @@ -0,0 +1,69 @@ +signature CatParse = + sig + val parseCatalog : Uri.Uri -> CatData.Catalog + end + +functor CatParse (structure Params : CatParams) : CatParse = + struct + structure SocatParse = SocatParse (structure Params = Params) + + structure ParserOptions = + struct + structure Options = ParserOptions() + open Options + + local + fun setDefaults() = + let + val _ = setParserDefaults() + + val _ = O_WARN_MULT_ENUM := false + val _ = O_WARN_XML_DECL := false + val _ = O_WARN_ATT_NO_ELEM := false + val _ = O_WARN_MULT_ENT_DECL := false + val _ = O_WARN_MULT_NOT_DECL := false + val _ = O_WARN_MULT_ATT_DEF := false + val _ = O_WARN_MULT_ATT_DECL := false + val _ = O_WARN_SHOULD_DECLARE := false + + val _ = O_VALIDATE := false + val _ = O_COMPATIBILITY := false + val _ = O_INTEROPERABILITY := false + + val _ = O_INCLUDE_EXT_PARSED := true + in () + end + in + val setParserDefaults = setDefaults + end + + end + structure CatHooks = CatHooks (structure Params = Params + structure Dtd = CatDtd) + structure Parse = Parse (structure Dtd = CatDtd + structure Hooks = CatHooks + structure Resolve = ResolveNull + structure ParserOptions = ParserOptions) + + open CatHooks CatDtd Parse ParserOptions SocatParse Uri + + fun parseXmlCat uri = + let + val _ = setParserDefaults() + val dtd = initDtdTables() + val items = parseDocument (SOME uri) (SOME dtd) (initCatHooks dtd) + in + (uri,items) + end + + fun isSocatSuffix x = x="soc" orelse x="SOC" + fun isXmlSuffix x = x="xml" orelse x="XML" + + fun parseCatalog uri = + let val suffix = uriSuffix uri + in if isSocatSuffix suffix then parseSoCat uri + else (if isXmlSuffix suffix then parseXmlCat uri + else (if !O_PREFER_SOCAT then parseSoCat uri + else parseXmlCat uri)) + end + end diff --git a/fxp/src/Catalog/catResolve.sml b/fxp/src/Catalog/catResolve.sml new file mode 100644 index 0000000..516bede --- /dev/null +++ b/fxp/src/Catalog/catResolve.sml @@ -0,0 +1,25 @@ + + + + + + + +functor ResolveCatalog ( structure Params : CatParams ) : Resolve = + struct + structure Catalog = Catalog ( structure Params = Params ) + + open Base Errors + + fun resolveExtId (id as EXTID(pub,sys)) = + let val pub1 = case pub + of NONE => NONE + | SOME (str,_) => SOME str + val sys1 = case sys + of NONE => NONE + | SOME (base,file,_) => SOME(base,file) + in case Catalog.resolveExtId (pub1,sys1) + of NONE => raise NoSuchFile ("","Could not generate system identifier") + | SOME uri => uri + end + end diff --git a/fxp/src/Catalog/catalog.sml b/fxp/src/Catalog/catalog.sml new file mode 100644 index 0000000..6916617 --- /dev/null +++ b/fxp/src/Catalog/catalog.sml @@ -0,0 +1,139 @@ + + + + + + + + + +signature Catalog = + sig + val resolveExtId : string option * (Uri.Uri * Uri.Uri) option -> Uri.Uri option + end + +functor Catalog ( structure Params : CatParams ) : Catalog = + struct + structure CatParse = CatParse ( structure Params = Params ) + + open CatData CatParse Params Uri UriDict + + val catDict = makeDict("catalog",6,NONE:Catalog option) + + fun getCatalog uri = + let val idx = getIndex(catDict,uri) + in case getByIndex(catDict,idx) + of SOME cat => cat + | NONE => let val cat = parseCatalog uri + val _ = setByIndex(catDict,idx,SOME cat) + in cat + end + end + + datatype SearchType = + SYS of Uri + | PUB of string + datatype SearchResult = + FOUND of Uri * Uri + | NOTFOUND of Uri list + + fun searchId id = + let + fun searchOne (base,other) nil = NOTFOUND other + | searchOne (base,other) (entry::entries) = + case entry + of E_BASE path => + let val newBase = uriJoin(base,path) + in searchOne (newBase,other) entries + end + | E_EXTEND path => + let val fullPath = uriJoin(base,path) + in searchOne (base,fullPath::other) entries + end + | E_DELEGATE(prefix,path) => + (case id + of PUB pid => if String.isPrefix prefix pid + then let val fullPath = uriJoin(base,path) + in searchOne (base,fullPath::other) entries + end + else searchOne (base,other) entries + | SYS _ => searchOne (base,other) entries) + | E_MAP(pubid,path) => + (case id + of PUB pid => if pubid=pid then FOUND (base,path) + else searchOne (base,other) entries + | _ => searchOne (base,other) entries) + | E_REMAP(sysid,path) => + (case id + of SYS sid => if sysid=sid then FOUND(base,path) + else searchOne (base,other) entries + | _ => searchOne (base,other) entries) + + fun searchLevel other nil = NOTFOUND(rev other) + | searchLevel other (fname::fnames) = + let + val (base,entries) = getCatalog fname + in + case searchOne (base,other) entries + of FOUND bp => FOUND bp + | NOTFOUND other' => searchLevel other' fnames + end + + fun searchAll fnames = + if null fnames then NONE + else case searchLevel nil fnames + of FOUND bp => SOME bp + | NOTFOUND other => searchAll other + + val fnames = !O_CATALOG_FILES + in + case id + of PUB _ => searchAll fnames + | SYS _ => if !O_SUPPORT_REMAP then searchAll fnames else NONE + end + + fun resolveExtId (pub,sys) = + let + fun resolvePubCat () = + case pub + of NONE => NONE + | SOME id => case searchId (PUB id) + of NONE => NONE + | SOME(base,sysid) => case searchId (SYS sysid) + of NONE => SOME(base,sysid) + | new => new + + fun resolveSysCat () = + case sys + of NONE => NONE + | SOME(base,id) => searchId (SYS id) + + fun resolveCat () = + if !O_PREFER_SYSID + then case resolveSysCat () + of NONE => resolvePubCat () + | found => found + else case resolvePubCat () + of NONE => resolveSysCat () + | found => found + + fun resolve () = + if !O_PREFER_CATALOG + then case resolveCat () + of NONE => (case sys + of NONE => NONE + | SOME(base,id) => SOME(base,id)) + | found => found + else case sys + of NONE => resolvePubCat () + | SOME(base,id) => SOME(base,id) + in + if null (!O_CATALOG_FILES) + then case sys + of NONE => NONE + | SOME(base,id) => SOME (uriJoin (base,id)) + else case resolve () + of NONE => NONE + | SOME bp => SOME (uriJoin bp) + end + end diff --git a/fxp/src/Catalog/socatParse.sml b/fxp/src/Catalog/socatParse.sml new file mode 100644 index 0000000..c2352fa --- /dev/null +++ b/fxp/src/Catalog/socatParse.sml @@ -0,0 +1,293 @@ + + + + + + + + + +signature SocatParse = + sig + val parseSoCat : Uri.Uri -> CatData.Catalog + end + +functor SocatParse ( structure Params : CatParams ) : SocatParse = + struct + structure CatFile = CatFile ( structure Params = Params ) + + open CatData CatError CatFile Params UniChar UniClasses Uri + + exception SyntaxError of UniChar.Char * CatFile.CatFile + exception NotFound of UniChar.Char * CatFile.CatFile + + val getChar = catGetChar + + fun parseName' (c,f) = + if isName c then let val (cs,cf1) = parseName' (getChar f) + in (c::cs,cf1) + end + else (nil,(c,f)) + fun parseName (c,f) = + if isNms c then let val (cs,cf1) = parseName' (getChar f) + in (c::cs,cf1) + end + else raise NotFound (c,f) + + datatype Keyword = + KW_BASE + | KW_CATALOG + | KW_DELEGATE + | KW_PUBLIC + | KW_SYSTEM + | KW_OTHER of UniChar.Data + + fun parseKeyword cf = + let + val (name,cf1) = parseName cf + val kw = case name + of [0wx42,0wx41,0wx53,0wx45] => KW_BASE + | [0wx43,0wx41,0wx54,0wx41,0wx4c,0wx4f,0wx47] => KW_CATALOG + | [0wx44,0wx45,0wx4c,0wx45,0wx47,0wx41,0wx54,0wx45] => KW_DELEGATE + | [0wx50,0wx55,0wx42,0wx4c,0wx49,0wx43] => KW_PUBLIC + | [0wx53,0wx59,0wx53,0wx54,0wx45,0wx4d] => KW_SYSTEM + | _ => KW_OTHER name + in (kw,cf1) + end + + fun parseSysLit' quote f = + let + fun doit text (c,f) = + if c=quote then (text,getChar f) + else if c<>0wx0 then doit (c::text) (getChar f) + else let val _ = catError(catPos f,ERR_EOF LOC_SYSID) + in (text,(c,f)) + end + val (text,cf1) = doit nil (getChar f) + in (Data2Uri(rev text),cf1) + end + fun parseSysLit req (c,f) = + if c=0wx22 orelse c=0wx27 then parseSysLit' c f + else if req then let val _ = catError(catPos f,ERR_EXPECTED(EXP_LITERAL,c)) + in raise SyntaxError (c,f) + end + else raise NotFound (c,f) + + fun parsePubLit' quote f = + let + fun doit (hadSpace,atStart,text) (c,f) = + case c + of 0wx0 => let val _ = catError(catPos f,ERR_EOF LOC_PUBID) + in (text,(c,f)) + end + | 0wx0A => doit (true,atStart,text) (getChar f) + | 0wx20 => doit (true,atStart,text) (getChar f) + | _ => + if c=quote then (text,getChar f) + else if isPubid c + then if hadSpace andalso not atStart + then doit (false,false,c::0wx20::text) (getChar f) + else doit (false,false,c::text) (getChar f) + else let val _ = catError(catPos f,ERR_ILLEGAL_HERE(c,LOC_PUBID)) + in doit (hadSpace,atStart,text) (getChar f) + end + val (text,cf1) = doit (false,true,nil) (getChar f) + in (Latin2String(rev text),cf1) + end + fun parsePubLit (c,f) = + if c=0wx22 orelse c=0wx27 then parsePubLit' c f + else let val _ = catError(catPos f,ERR_EXPECTED(EXP_LITERAL,c)) + in raise SyntaxError (c,f) + end + + fun skipComment (c,f) = + case c + of 0wx00 => let val _ = catError(catPos f,ERR_EOF LOC_COMMENT) + in (c,f) + end + | 0wx2D => let val (c1,f1) = getChar f + in if c1 = 0wx2D then (getChar f1) else skipComment (c1,f1) + end + | _ => skipComment (getChar f) + fun skipCopt (c,f) = + case c + of 0wx00 => (c,f) + | 0wx2D => let val (c1,f1) = getChar f + in if c1=0wx2D then skipComment (getChar f1) + else let val _ = catError(catPos f,ERR_ILLEGAL_HERE(c,LOC_NOCOMMENT)) + in (c1,f1) + end + end + | _ => (c,f) + + fun skipScomm req0 cf = + let + fun endit req (c,f) = + if req andalso c<>0wx00 + then let val _ = catError(catPos f,ERR_MISSING_WHITE) + in (c,f) + end + else (c,f) + fun doit req (c,f) = + case c + of 0wx00 => endit req (c,f) + | 0wx09 => doit false (getChar f) + | 0wx0A => doit false (getChar f) + | 0wx20 => doit false (getChar f) + | 0wx22 => endit req (c,f) + | 0wx27 => endit req (c,f) + | 0wx2D => + let val (c1,f1) = getChar f + in if c1=0wx2D + then let val _ = if not req then () + else catError(catPos f1,ERR_MISSING_WHITE) + val cf1 = skipComment (getChar f1) + in doit true cf1 + end + else let val _ = catError(catPos f,ERR_ILLEGAL_HERE(c,LOC_NOCOMMENT)) + in doit req (c1,f1) + end + end + | _ => if isNms c then endit req (c,f) + else let val _ = catError(catPos f,ERR_ILLEGAL_HERE(c,LOC_NOCOMMENT)) + in doit req (getChar f) + end + in doit req0 cf + end + + val skipWS = skipScomm true + val skipCommWS = (skipScomm false) o skipCopt + val skipWSComm = skipScomm false + + fun skipOther cf = + let + val cf1 = skipWS cf + val cf2 = let val (_,cf') = parseName cf1 + in skipWS cf' + end + handle NotFound cf => cf + + fun doit cf = + let val (_,cf1) = parseSysLit false cf + in doit (skipWS cf1) + end + handle NotFound(c,f) => (c,f) + in + (NONE,doit cf2) + end + + fun parseBase cf = + let + val cf1 = skipWS cf + val (lit,cf2) = parseSysLit true cf1 + val cf3 = skipWS cf2 + in + (SOME(E_BASE lit),cf3) + end + + fun parseExtend cf = + let + val cf1 = skipWS cf + val (lit,cf2) = parseSysLit true cf1 + val cf3 = skipWS cf2 + in + (SOME(E_EXTEND lit),cf3) + end + + fun parseDelegate cf = + let + val cf1 = skipWS cf + val (pub,cf2) = parsePubLit cf1 + val cf3 = skipWS cf2 + val (sys,cf4) = parseSysLit true cf3 + val cf5 = skipWS cf4 + in + (SOME(E_DELEGATE(pub,sys)),cf5) + end + + fun parseRemap cf = + let + val cf1 = skipWS cf + val (sys0,cf2) = parseSysLit true cf1 + val cf3 = skipWS cf2 + val (sys,cf4) = parseSysLit true cf3 + val cf5 = skipWS cf4 + in + (SOME(E_REMAP(sys0,sys)),cf5) + end + + fun parseMap cf = + let + val cf1 = skipWS cf + val (pub,cf2) = parsePubLit cf1 + val cf3 = skipWS cf2 + val (sys,cf4) = parseSysLit true cf3 + val cf5 = skipWS cf4 + in + (SOME(E_MAP(pub,sys)),cf5) + end + + fun recover cf = + let + fun do_lit q (c,f) = + if c=0wx00 then (c,f) + else if c=q then getChar f + else do_lit q (getChar f) + fun do_com (c,f) = + case c + of 0wx00 => (c,f) + | 0wx2D => let val (c1,f1) = getChar f + in if c1=0wx2D then getChar f1 + else do_com (c1,f1) + end + | _ => do_com (getChar f) + fun doit (c,f) = + case c + of 0wx00 => (c,f) + | 0wx22 => doit (do_lit c (getChar f)) + | 0wx27 => doit (do_lit c (getChar f)) + | 0wx2D => let val (c1,f1) = getChar f + in if c1=0wx2D then doit (do_com (getChar f1)) + else doit (c1,f1) + end + | _ => if isNms c then (c,f) + else doit (getChar f) + in doit cf + end + + fun parseEntry (cf as (c,f)) = + let val (kw,cf1) = parseKeyword cf handle NotFound cf => raise SyntaxError cf + in case kw + of KW_BASE => parseBase cf1 + | KW_CATALOG => parseExtend cf1 + | KW_DELEGATE => parseDelegate cf1 + | KW_SYSTEM => parseRemap cf1 + | KW_PUBLIC => parseMap cf1 + | KW_OTHER _ => skipOther cf1 + end + handle SyntaxError cf => (NONE,recover cf) + + fun parseDocument cf = + let + fun doit (c,f) = + if c=0wx0 then nil before catCloseFile f + else let val (opt,cf1) = parseEntry (c,f) + val entries = doit cf1 + in case opt + of NONE => entries + | SOME entry => entry::entries + end + + val cf1 = skipCommWS cf + in + doit cf1 + end + + fun parseSoCat uri = + let + val f = catOpenFile uri + val cf1 = getChar f + in + (uri,parseDocument cf1) + end + end diff --git a/fxp/src/Parser/Base/base.sml b/fxp/src/Parser/Base/base.sml new file mode 100644 index 0000000..5291857 --- /dev/null +++ b/fxp/src/Parser/Base/base.sml @@ -0,0 +1,9 @@ + + + +structure Base = + struct + open + BaseData + BaseString + end diff --git a/fxp/src/Parser/Base/baseData.sml b/fxp/src/Parser/Base/baseData.sml new file mode 100644 index 0000000..e97f4bd --- /dev/null +++ b/fxp/src/Parser/Base/baseData.sml @@ -0,0 +1,110 @@ +(*--------------------------------------------------------------------------*) +(* Structure: BaseData *) +(*--------------------------------------------------------------------------*) + +structure BaseData = + struct + open DfaData + + (*--- external ids may have a public id and must have a system id ---*) + (*--- for notations, however, also the system id can be optional ----*) + datatype ExternalId = + EXTID of (string * UniChar.Char) option * (Uri.Uri * Uri.Uri * UniChar.Char) option + + (*--- external ids may have a public id and must have a system id ---*) + type NotationInfo = ExternalId option + + (*--- replacement of a general entity ---*) + datatype GenEntity = + GE_NULL + | GE_INTERN of UniChar.Vector * UniChar.Vector + | GE_EXTERN of ExternalId + | GE_UNPARSED of ExternalId * int * Errors.Position + type GenEntInfo = GenEntity * bool + + fun isExtGen (GE_EXTERN _) = true + | isExtGen _ = false + + (*--- replacement of a parameter entity ---*) + datatype ParEntity = + PE_NULL + | PE_INTERN of UniChar.Vector * UniChar.Vector + | PE_EXTERN of ExternalId + type ParEntInfo = ParEntity * bool + + fun isExtPar (PE_EXTERN _) = true + | isExtPar _ = false + + (*--- declared type of an attribute ---*) + datatype AttType = + AT_CDATA + | AT_NMTOKEN + | AT_NMTOKENS + | AT_ID + | AT_IDREF + | AT_IDREFS + | AT_ENTITY + | AT_ENTITIES + | AT_GROUP of int list + | AT_NOTATION of int list + + (*--- typed attribute value ---*) + datatype AttValue = + AV_CDATA of UniChar.Vector + | AV_NMTOKEN of UniChar.Data + | AV_NMTOKENS of UniChar.Data list + | AV_ID of int + | AV_IDREF of int + | AV_IDREFS of int list + | AV_ENTITY of int + | AV_ENTITIES of int list + | AV_GROUP of int list * int + | AV_NOTATION of int list * int + + fun isIdType at = at=AT_ID + + (*--- default values of attributes ---*) + datatype AttDefault = + AD_IMPLIED + | AD_REQUIRED + | AD_DEFAULT of (UniChar.Vector * UniChar.Vector * AttValue option) + * (Errors.Position * bool ref) + | AD_FIXED of (UniChar.Vector * UniChar.Vector * AttValue option) + * (Errors.Position * bool ref) + + (*--- attribute definition (list) ---*) + (*--- the boolean says whether it was externally declared ---*) + type AttDef = int * AttType * AttDefault * bool + type AttDefList = AttDef list + + (*--- content specification ---*) + fun defaultAttDef idx = (idx,AT_CDATA,AD_IMPLIED,false) + + (*--- content specification ---*) + datatype ContentSpec = + CT_ANY + | CT_EMPTY + | CT_MIXED of int list + | CT_ELEMENT of DfaData.ContentModel * DfaData.Dfa + + fun isMixed ct = + case ct + of CT_ANY => true + | CT_MIXED _ => true + | _ => false + + type ElemInfo = {decl : (ContentSpec * bool) option, + atts : (AttDefList * bool) option, + errAtts : int list} + + val nullElemInfo : ElemInfo = {decl=NONE, + atts=NONE, + errAtts=nil} + + (*--------------------------------------------------------------------*) + (* the id info tells whether an id value has occurred for a name and *) + (* the list of all positions where it occurred as an idref value. *) + (*--------------------------------------------------------------------*) + type IdInfo = bool * Errors.Position list + val nullIdInfo : IdInfo = (false,nil) + end diff --git a/fxp/src/Parser/Base/baseString.sml b/fxp/src/Parser/Base/baseString.sml new file mode 100644 index 0000000..bbc9794 --- /dev/null +++ b/fxp/src/Parser/Base/baseString.sml @@ -0,0 +1,165 @@ + + + + + + + + + + + + +(*--------------------------------------------------------------------------*) +(* Structure: BaseString *) +(* *) +(* Depends on: *) +(* UniChar *) +(* Dfa *) +(* BaseData *) +(* UtilString *) +(* *) +(* Exceptions raised by functions in this structure: *) +(* ElemInfo2xString : InternalError *) +(* ExternalId2String : none *) +(* GenEntity2xString : none *) +(* Notation2String : none *) +(* IdInfo2String : none *) +(* ParEntity2String : none *) +(*--------------------------------------------------------------------------*) +signature BaseString = + sig + val ExternalId2String : BaseData.ExternalId -> string + val NotationInfo2String : BaseData.NotationInfo -> string + + val GenEntity2xString : (int -> string) -> BaseData.GenEntity -> string + val ParEntity2String : BaseData.ParEntity -> string + + val ElemInfo2xString : (int -> string) * (int -> string) * (int -> string) + * (int -> string) * (int -> string) -> BaseData.ElemInfo -> string + + val IdInfo2String : BaseData.IdInfo -> string + end + +structure BaseString : BaseString = + struct + open + UtilString Uri + Errors UniChar DfaString + BaseData + + val THIS_MODULE = "BaseString" + + fun ExternalId2String (EXTID id) = + case id + of (SOME(p,pq),SOME(rel,s,sq)) => String.concat + ["PUBLIC ",quoteUni pq p, + " ",quoteUni sq (Uri2String rel), + " @ ",quoteUni sq (Uri2String s)] + | (SOME(p,pq),NONE) => String.concat + ["PUBLIC ",quoteUni pq p] + | (NONE,SOME(rel,s,sq)) => String.concat + ["SYSTEM ",quoteUni sq (Uri2String rel), + " @ ",quoteUni sq (Uri2String s)] + | (NONE,NONE) => "" + fun NotationInfo2String not = + case not + of NONE => "undeclared" + | SOME extId => ExternalId2String extId + + fun GenEntity2xString NotIdx2String ge = + case ge + of GE_NULL => "NULL" + | GE_INTERN(lit,cv) => let val quote = Vector.sub(lit,0) + in String.concat ["INTERN ",Vector2String lit, + " - ",quoteVector quote cv] + end + | GE_EXTERN id => "EXTERN "^ExternalId2String id + | GE_UNPARSED(id,not,_) => "UNPARSED "^ExternalId2String id^" "^NotIdx2String not + + fun ParEntity2String pe = + case pe + of PE_NULL => "NULL" + | PE_INTERN(lit,cv) => let val quote = Vector.sub(lit,0) + in String.concat ["INTERN ",Vector2String lit, + " - ",quoteVector quote cv] + end + | PE_EXTERN id => "EXTERN "^ExternalId2String id + + fun ContentSpec2String Elem2String cs = + case cs + of CT_ANY => "ANY" + | CT_EMPTY => "EMPTY" + | CT_MIXED is => List2xString ("MIXED (","|",")") Elem2String is + | CT_ELEMENT(cm,_) => "ELEMENT "^ContentModel2String Elem2String cm + + fun AttValue2xString (Att2String,Ent2String,Id2String,Not2String) quote av = + quoteUni quote (case av + of AV_CDATA buf => Vector2String buf + | AV_NMTOKEN cs => Data2String cs + | AV_NMTOKENS css => List2xString (""," ","") Data2String css + | AV_ID idx => Id2String idx + | AV_IDREF idx => Id2String idx + | AV_IDREFS idxs => List2xString (""," ","") Id2String idxs + | AV_ENTITY idx => Ent2String idx + | AV_ENTITIES idxs => List2xString (""," ","") Ent2String idxs + | AV_GROUP(_,idx) => Att2String idx + | AV_NOTATION(_,idx) => Not2String idx) + + fun AttDefault2xString funs ad = + case ad + of AD_DEFAULT ((lit,cv,av),_) => + let val quote = Vector.sub(lit,0) + in String.concat [quoteVector quote cv," ", + Option2String0 (AttValue2xString funs quote) av] + end + | AD_FIXED ((lit,cv,av),_) => + let val quote = Vector.sub(lit,0) + in String.concat ["#FIXED ",quoteVector quote cv," ", + Option2String0 (AttValue2xString funs quote) av] + end + | AD_IMPLIED => "#IMPLIED" + | AD_REQUIRED => "#REQUIRED" + + fun AttType2xString (Att2String,Not2String) at = + case at + of AT_CDATA => "CDATA" + | AT_NMTOKEN => "NMTOKEN" + | AT_NMTOKENS => "NMTOKENS" + | AT_ID => "ID" + | AT_IDREF => "IDREF" + | AT_IDREFS => "IDREFS" + | AT_ENTITY => "ENTITY" + | AT_ENTITIES => "ENTITIES" + | AT_GROUP idxs => List2xString ("(","|",")") Att2String idxs + | AT_NOTATION idxs => List2xString ("NOTATION(","|",")") Not2String idxs + + fun AttDef2xString (funs as (Att2String,_,_,Not2String)) (idx,attType,default,ext) = + String.concat [Att2String idx," ", + AttType2xString (Att2String,Not2String) attType," ", + AttDefault2xString funs default, + Bool2xString ("[external]","") ext] + + fun AttDefList2xString funs adl = List2xString ("",",","") (AttDef2xString funs) adl + + fun ElemInfo2xString (Att2String,Elem2String,Ent2String,Id2String,Not2String) + ({decl,atts,...}:ElemInfo) = + let val dec = case decl + of NONE => "elem undeclared" + | SOME(cont,ext) => String.concat + ["elem declared ",if ext then "ex" else "in","ternally: ", + ContentSpec2String Elem2String cont] + val att = case atts + of NONE => "no atts declared" + | SOME(defs,hadId) => String.concat + ["atts were declared",if hadId then "(has id attribute): " else ": ", + AttDefList2xString (Att2String,Ent2String,Id2String,Not2String) defs] + in dec^att + end + + fun IdInfo2String (decl,refs) = + Bool2xString ("declared","undeclared") decl^"/"^ + (if null refs then "no references" + else List2xString ("references: ",", ","") Position2String refs) + end + diff --git a/fxp/src/Parser/Dfa/dfa.sml b/fxp/src/Parser/Dfa/dfa.sml new file mode 100644 index 0000000..550dcaa --- /dev/null +++ b/fxp/src/Parser/Dfa/dfa.sml @@ -0,0 +1,112 @@ + + + + + + + + + + +(*--------------------------------------------------------------------------*) +(* Structure: Dfa *) +(* *) +(* Depends on: *) +(* DfaData *) +(* DfaError *) +(* DfaPassOne *) +(* DfaPassTwo *) +(* DfaString *) +(* DfaUtil *) +(* *) +(* Exceptions raised by functions in this structure: *) +(* ContentModel2String : none *) +(* dfaFinal : none *) +(* dfaTrans : none *) +(* makeAmbiguous : DfaTooLarge *) +(* makeChoiceDfa : none *) +(* makeDfa : Ambiguous *) +(* Dfa2String : none *) +(*--------------------------------------------------------------------------*) +signature Dfa = + sig + eqtype DfaState + + val dfaError : DfaState + val dfaInitial : DfaState + + exception DfaTooLarge of int + exception Ambiguous of int * int * int + + val emptyDfa : DfaData.Dfa + + val makeDfa : DfaData.ContentModel -> DfaData.Dfa + val makeAmbiguous : DfaData.ContentModel -> DfaData.Dfa + val makeChoiceDfa : DfaData.ContentModel -> DfaData.Dfa + + val dfaFinal : DfaData.Dfa * DfaState -> bool + val dfaTrans : DfaData.Dfa * DfaState * int -> DfaState + end + +functor Dfa (structure DfaOptions : DfaOptions) : Dfa = + struct + structure DfaPassThree = DfaPassThree (structure DfaOptions = DfaOptions) + + open + DfaBase DfaError DfaPassOne DfaPassTwo DfaString DfaUtil + + type DfaState = State + + (*--------------------------------------------------------------------*) + (* Create a dfa for the content model (a1|...|aN)*, where a1,...,aN *) + (* are the symbols occurring in the input dfa. *) + (*--------------------------------------------------------------------*) + fun makeChoiceDfa cm = + let + val syms = cmSymbols cm + val flw = map (fn a => (dfaInitial,a)) syms + in + Vector.fromList [makeRow(flw,true)] + end + + (*--------------------------------------------------------------------*) + (* create a dfa for an ambiguous content model. Raise DfaTooLarge if *) + (* the subset construction yields too many states. *) + (*--------------------------------------------------------------------*) + fun makeAmbiguous cm = + let + val cmi = DfaPassOne.passOne true cm + val tab = DfaPassTwo.passTwo true cmi + val dfa = DfaPassThree.passThree true tab + in dfa + end + + (*--------------------------------------------------------------------*) + (* generate a dfa for a content model. Raise Ambiguous if the content *) + (* model is ambiguous. *) + (*--------------------------------------------------------------------*) + fun makeDfa cm = + let + val cmi = DfaPassOne.passOne false cm + val tab = DfaPassTwo.passTwo false cmi + val dfa = DfaPassThree.passThree false tab + in dfa + end + handle ConflictFirst aqq => raise Ambiguous (countOccs aqq cm) + | ConflictFollow aqq => raise Ambiguous (countOccs aqq cm) + + (*--------------------------------------------------------------------*) + (* make one transitions in the dfa. *) + (*--------------------------------------------------------------------*) + fun dfaTrans(tab,q,a) = + if q<0 then dfaDontCare + else let val (lo,hi,tab,_) = Vector.sub(tab,q) + in if a>=lo andalso a<=hi then Vector.sub(tab,a-lo) else dfaError + end + + (*--------------------------------------------------------------------*) + (* check whether a dfa's state is an accepting state. *) + (*--------------------------------------------------------------------*) + fun dfaFinal (tab,q) = + q<0 orelse #4(Vector.sub(tab,q):Row) + end diff --git a/fxp/src/Parser/Dfa/dfaData.sml b/fxp/src/Parser/Dfa/dfaData.sml new file mode 100644 index 0000000..8061cab --- /dev/null +++ b/fxp/src/Parser/Dfa/dfaData.sml @@ -0,0 +1,73 @@ + + + +(*--------------------------------------------------------------------------*) +(* Structure: DfaData *) +(* *) +(* Depends on: *) +(* *) +(* Exceptions raised by functions in this structure: *) +(* boundsFollow : none *) +(* mergeFirst : ConflictFirst *) +(* mergeFollow : ConflictFollow *) +(*--------------------------------------------------------------------------*) +signature DfaData = + sig + type Dfa + + datatype ContentModel = + CM_ELEM of int + | CM_OPT of ContentModel + | CM_REP of ContentModel + | CM_PLUS of ContentModel + | CM_ALT of ContentModel list + | CM_SEQ of ContentModel list + end + +structure DfaBase = + struct + (*--- visible to the parser ---*) + datatype ContentModel = + CM_ELEM of int + | CM_OPT of ContentModel + | CM_REP of ContentModel + | CM_PLUS of ContentModel + | CM_ALT of ContentModel list + | CM_SEQ of ContentModel list + + type Sigma = int + type State = int + + val dfaDontCare = ~2 + val dfaError = ~1 + val dfaInitial = 0 + + exception DfaTooLarge of int + exception Ambiguous of Sigma * int * int + exception ConflictFirst of Sigma * State * State + exception ConflictFollow of Sigma * State * State + + type Empty = bool + type First = (State * Sigma) list + type Follow = First + + type Info = State * Empty * First + + datatype CM' = + ELEM of Sigma + | OPT of CM + | REP of CM + | PLUS of CM + | ALT of CM list + | SEQ of CM list + withtype CM = CM' * Info + + type Row = Sigma * Sigma * State vector * bool + val nullRow : Row = (1,0,Vector.fromList nil,false) + + type Dfa = Row vector + + val emptyDfa : Dfa = Vector.fromList [(1,0,Vector.fromList nil,true)] + end + +structure DfaData = DfaBase (* : DfaData *) diff --git a/fxp/src/Parser/Dfa/dfaError.sml b/fxp/src/Parser/Dfa/dfaError.sml new file mode 100644 index 0000000..92ec81c --- /dev/null +++ b/fxp/src/Parser/Dfa/dfaError.sml @@ -0,0 +1,58 @@ + + +(*--------------------------------------------------------------------------*) +(* Structure: DfaError *) +(* *) +(* Note: *) +(* The function in this structure is for producing good error messages *) +(* for ambiguous content models. It numbers the nodes of a cm exactly *) +(* like passOne does, but counts the occurrences of symbol a in order to *) +(* indicate which are in conflict. It is only executed in case of error. *) +(* *) +(* Depends on: *) +(* DfaData *) +(* *) +(* Exceptions raised by functions in this structure: *) +(* countOccs : none *) +(*--------------------------------------------------------------------------*) +signature DfaError = + sig + val countOccs : DfaBase.Sigma * DfaBase.State * DfaBase.State + -> DfaBase.ContentModel -> DfaBase.Sigma * int * int + end + +structure DfaError : DfaError = + struct + open DfaBase + + fun countOccs (a,q1,q2) cm = + let + val (q1,q2) = if q1>q2 then (q2,q1) else (q1,q2) + + fun next a nil = (1,[(a,2)]) + | next a ((b,n)::rest) = + if a=b then (n,(b,n+1)::rest) + else if a insert a yet + | CM_OPT cmi => doit (cmi,yet) + | CM_REP cmi => doit (cmi,yet) + | CM_PLUS cmi => doit (cmi,yet) + | CM_ALT cmis => foldl doit yet cmis + | CM_SEQ cmis => foldl doit yet cmis + + val (_,_,n1,n2) = doit (cm,(1,nil,0,0)) + in + (a,n1,n2) + end + end diff --git a/fxp/src/Parser/Dfa/dfaOptions.sml b/fxp/src/Parser/Dfa/dfaOptions.sml new file mode 100644 index 0000000..4156eaa --- /dev/null +++ b/fxp/src/Parser/Dfa/dfaOptions.sml @@ -0,0 +1,97 @@ +signature DfaOptions = + sig + val O_DFA_INITIAL_WIDTH : int ref + val O_DFA_MAX_STATES : int ref + val O_DFA_WARN_TOO_LARGE : bool ref + + val setDfaDefaults : unit -> unit + val setDfaOptions : Options.Option list * (string -> unit) -> Options.Option list + + val dfaUsage : Options.Usage + end + +functor DfaOptions () : DfaOptions = + struct + open Options UtilInt + + val O_DFA_INITIAL_WIDTH = ref 4 + val O_DFA_MAX_STATES = ref 256 + val O_DFA_WARN_TOO_LARGE = ref true + + fun setDfaDefaults() = + let + val _ = O_DFA_INITIAL_WIDTH := 4 + val _ = O_DFA_MAX_STATES := 256 + val _ = O_DFA_WARN_TOO_LARGE := true + in () + end + + val dfaUsage = + [U_ITEM(["--dfa-initial-size=n"],"Initial size of DFA transition tables (16)"), + U_ITEM(["--dfa-initial-width=n"],"Same as --dfa-initial-size=2^n (4)"), + U_ITEM(["--dfa-max-size=n"],"Maximal size of DFAs for ambiguous content models (256)"), + U_ITEM(["--dfa-warn-size[=(yes|no)]"],"Warn about too large DFAs (yes)") + ] + + fun setDfaOptions(opts,doError) = + let + exception Failed of string option + + fun getNat str = + if str="" then raise Failed NONE + else let val cs = String.explode str + in foldl (fn (c,n) => if #"0">c orelse #"9" raise Failed + (SOME("number "^str^" is too large for this system")) + end + + val yesNo = "'yes' or 'no'" + fun tooLarge n = String.concat ["number ",n," is too large for this system"] + fun mustHave key = String.concat ["option --",key," must have an argument"] + fun mustBe key what = String.concat + ["the argument to option --",key," must be ",what] + + fun do_yesno(key,valOpt,flag) = + case valOpt + of NONE => flag := true + | SOME "yes" => flag := true + | SOME "no" => flag := false + | SOME s => doError (mustBe key yesNo) + + fun do_num(key,valOpt,flag) = + case valOpt + of NONE => doError (mustHave key) + | SOME s => flag := getNat s + handle Failed NONE => doError (mustBe key "a number") + | Failed (SOME s) => doError s + + fun do_dfa_ts(key,valOpt,toWidth) = + case valOpt + of NONE => doError (mustHave key) + | SOME s => O_DFA_INITIAL_WIDTH := toWidth (getNat s) + handle Failed NONE => doError (mustBe key "a number") + | Failed (SOME s) => doError s + + fun do_long(key,valOpt) = + case key + of "dfa-initial-size" => true before do_dfa_ts(key,valOpt,nextPowerTwo) + | "dfa-initial-width" => true before do_dfa_ts(key,valOpt,fn i => i) + | "dfa-max-size" => true before do_num(key,valOpt,O_DFA_MAX_STATES) + | "dfa-warn-size" => true before do_yesno(key,valOpt,O_DFA_WARN_TOO_LARGE) + | _ => false + + and doit nil = nil + | doit (opt::opts) = + case opt + of OPT_NOOPT => opts + | OPT_LONG(key,value) => if do_long(key,value) then doit opts + else opt::doit opts + | OPT_NEG _ => opt::doit opts + | OPT_SHORT _ => opt::doit opts + | OPT_STRING _ => opt::doit opts + in doit opts + end + end + + diff --git a/fxp/src/Parser/Dfa/dfaPassOne.sml b/fxp/src/Parser/Dfa/dfaPassOne.sml new file mode 100644 index 0000000..7ed6b6d --- /dev/null +++ b/fxp/src/Parser/Dfa/dfaPassOne.sml @@ -0,0 +1,85 @@ + + + +(*--------------------------------------------------------------------------*) +(* Structure: DfaPassOne *) +(* *) +(* Depends on: *) +(* DfaData *) +(* DfaUtil *) +(* *) +(* Exceptions raised by functions in this structure: *) +(* passOne : ConflictFirst *) +(*--------------------------------------------------------------------------*) +signature DfaPassOne = + sig + val passOne : bool -> DfaBase.ContentModel -> DfaBase.CM + end + +structure DfaPassOne : DfaPassOne = + struct + open DfaBase DfaUtil + + (*--------------------------------------------------------------------*) + (* Given a content model, number the leafs, compute Empty and First *) + (* for each node, and construct a corresponding CM annotated with *) + (* these informations. *) + (* *) + (* Numbering: *) + (* The leafs are numbered in left-to-right, depth-first order, *) + (* starting with 1 (0 will be the start state of the DFA). *) + (* *) + (* Empty a = false *) + (* Empty e? = Empty e* = true *) + (* Empty e+ = Empty e *) + (* Empty e1|...|eN = Empty e1 \/ ... \/ Empty eN *) + (* Empty e1,...,eN = Empty e1 /\ ... /\ Empty eN *) + (* *) + (* First a = {q,a}, where q is the number of this leaf. *) + (* First e? = First e* = First e+ = First e *) + (* First e1|...|eN = First e1 ++ ... ++ First eN *) + (* First e1,...,eN = ++{First eI | Empty eJ=False forall ja1 forall (q1,a1) in F1, (q1,a1) in F1} *) + (* error, if exist (q1,a) in F1, (q2,a) in F2 *) + (* then raise ConflictFirst(a,q1,q2) *) + (*--------------------------------------------------------------------*) + fun passOne nondet cm = + let + fun und(a,b) = a andalso b + fun oder(a,b) = a orelse b + + fun op_fst_seq (fst,fsts,mt) = if mt then mergeFirst nondet (fst,fsts) else fst + fun op_fst_or (fst,fsts,_) = mergeFirst nondet (fst,fsts) + + fun do_cm cm q = + case cm + of CM_ELEM a => (ELEM a,(q+1,false,[(q+1,a)])) + | CM_OPT cm => let val cmi as (_,(q1,_,fst)) = do_cm cm q + in (OPT cmi,(q1,true,fst)) + end + | CM_REP cm => let val cmi as (_,(q1,_,fst)) = do_cm cm q + in (REP cmi,(q1,true,fst)) + end + | CM_PLUS cm => let val cmi as (_,info1) = do_cm cm q + in (PLUS cmi,info1) + end + | CM_ALT cms => do_cms (ALT,false,oder,op_fst_or) cms q + | CM_SEQ cms => do_cms (SEQ,true,und,op_fst_seq) cms q + + and do_cms(con,null_mt,op_mt,op_fst) cms q = + let + fun doit [] q = ([],(q,null_mt,[])) + | doit (cm::cms) q = + let + val cmi as (_,(q1,mt1,fst1)) = do_cm cm q + val (cmis,(q2,mt2,fst2)) = doit cms q1 + in (cmi::cmis,(q2,op_mt(mt1,mt2),op_fst(fst1,fst2,mt1))) + end + val (cmis,info1) = doit cms q + in (con cmis,info1) + end + + in do_cm cm 0 + end + end diff --git a/fxp/src/Parser/Dfa/dfaPassThree.sml b/fxp/src/Parser/Dfa/dfaPassThree.sml new file mode 100644 index 0000000..343ac09 --- /dev/null +++ b/fxp/src/Parser/Dfa/dfaPassThree.sml @@ -0,0 +1,101 @@ + + + + + + + + + + + +(*--------------------------------------------------------------------------*) +(* Structure: DfaPassThree *) +(* *) +(* Depends on: *) +(* DfaData *) +(* DfaUtil *) +(* IntSets *) +(* IntSetDict *) +(* ParseOptions *) +(* *) +(* Exceptions raised by functions in this structure: *) +(* passThree : TooLarge *) +(*--------------------------------------------------------------------------*) +signature DfaPassThree = + sig + val passThree: bool -> (DfaBase.Follow * bool) vector -> DfaBase.Dfa + end + +functor DfaPassThree (structure DfaOptions : DfaOptions) : DfaPassThree = + struct + open + IntSets IntSetDict DfaBase DfaOptions DfaUtil + + (*--------------------------------------------------------------------*) + (* do the subset construction. *) + (*--------------------------------------------------------------------*) + (* given an automaton (Q,q0,F,delta), the subset automaton is *) + (* (Q',q0',F',delta') with: *) + (* - Q' = 2^Q *) + (* - q0'= {q0} *) + (* - F' = {S | S cap F <> empty} *) + (* - delta'(S,a) = {p | (q,a,p) in delta, q in S} *) + (*--------------------------------------------------------------------*) + fun makeDet tab = + let + (* the new start state is the singleton of the old start state *) + val sNull = singleIntSet 0 + + (* create a dictionary for the subsets, make sNull get index 0 *) + val tau = makeDict("",!O_DFA_INITIAL_WIDTH,(nil:Follow,false)) + val pInitial = getIndex(tau,sNull) + + (* enter a new set state. raise DfaTooLarge if the new state *) + (* would have a too large index *) + fun makeState s = + let val (max,i) = (!O_DFA_MAX_STATES,getIndex(tau,s)) + in if max>i then i else raise DfaTooLarge max + end + + (* compute the follow set for a set state from the follow sets *) + (* of its members *) + fun makeFollow NONE nil = nil + | makeFollow (SOME(s,a)) nil = [(makeState s,a)] + | makeFollow NONE ((q,a)::qas) = makeFollow (SOME(singleIntSet q,a)) qas + | makeFollow (SOME(s,a)) ((q,b)::qas) = + if a=b then makeFollow (SOME(addIntSet(q,s),a)) qas + else (makeState s,a)::makeFollow (SOME(singleIntSet q,b)) qas + + (* continue until all entries in the state dictionary are done -*) + fun doit i = + if i>=usedIndices tau then i + else let val sI = getKey(tau,i) + val lI = IntSet2List sI + val ffs = map (fn j => Vector.sub(tab,j)) lI + val (followJs,finI) = foldl + (fn ((flwJ,finJ),(flw,fin)) => (mergeFollow true (flwJ,flw), + finJ orelse fin)) + (nil,false) ffs + val followI = makeFollow NONE followJs + val _ = setByIndex(tau,i,(followI,finI)) + in doit (i+1) + end + + val size = doit 0 + in (* finally create a vector holding the new follow/fin pairs *) + Vector.tabulate (size,fn i => getByIndex(tau,i)) + end + + (*--------------------------------------------------------------------*) + (* given a vector of Follow and boolean final condition, make a dfa *) + (* out of it. if the first arg is true, then the content model was *) + (* ambiguous; in this case we must first apply a subset construction *) + (* in order to obtain a deterministic finite machine. *) + (*--------------------------------------------------------------------*) + fun passThree nondet tab = + let + val det = if nondet then makeDet tab else tab + in Vector.map makeRow det + end + end diff --git a/fxp/src/Parser/Dfa/dfaPassTwo.sml b/fxp/src/Parser/Dfa/dfaPassTwo.sml new file mode 100644 index 0000000..7b1c369 --- /dev/null +++ b/fxp/src/Parser/Dfa/dfaPassTwo.sml @@ -0,0 +1,77 @@ + + + + + +(*--------------------------------------------------------------------------*) +(* Structure: DfaPassTwo *) +(* *) +(* Depends on: *) +(* DfaData *) +(* DfaUtil *) +(* *) +(* Exceptions raised by functions in this structure: *) +(* passTwo : ConflictFollow *) +(*--------------------------------------------------------------------------*) +signature DfaPassTwo = + sig + val passTwo: bool -> DfaBase.CM -> (DfaBase.Follow * bool) vector + end + +structure DfaPassTwo : DfaPassTwo = + struct + open DfaBase DfaUtil + + (*--------------------------------------------------------------------*) + (* Given a CM annotated with leaf numbers (states), Empty and First, *) + (* compute Follow and Fin foreach node, and generate the transition *) + (* row if node is a leaf. Follow and Fin are computed top-down: *) + (* *) + (* (Top-Level): *) + (* Follow e = {}, Fin e = true *) + (* *) + (* (e=e1?): *) + (* Follow e1 = Follow e, Fin e1 = Fin e *) + (* *) + (* (e=e1*, e=e1+) *) + (* Follow e1 = Follow e1 ++ First e1, Fin e1 = Fin e *) + (* *) + (* (e=e1|...|eN) = *) + (* Follow eI = Follow e, Fin eI = Fin e for i=0...n *) + (* *) + (* (e=e1,...,eN) = *) + (* Follow eN = Follow e, Fin eN = Fin e *) + (* Follow eI = First eI+1, if Empty eI+1 = false, ia1 forall (q1,a1) in F1, (q1,a1) in F1} *) + (* error, if exist (q1,a) in F1, (q2,a) in F2 *) + (* then raise ConflictFirst(a,q1,q2) *) + (*--------------------------------------------------------------------*) + fun passTwo nondet (cmi as (_,(n,mt,fst))) = + let + val table = Array.array(n+1,(nil,false)) + + val _ = Array.update(table,0,(fst,mt)) + + fun do_cm (ff as (flw,fin)) (cm,(q,mt,fst)) = + case cm + of ELEM a => Array.update(table,q,ff) + | OPT cmi => do_cm ff cmi + | REP cmi => do_cm (mergeFollow nondet (fst,flw),fin) cmi + | PLUS cmi => do_cm (mergeFollow nondet (fst,flw),fin) cmi + | ALT cmis => app (do_cm ff) cmis + | SEQ cmis => ignore (do_seq ff cmis) + and do_seq ff cmis = foldr + (fn (cmi as (_,(_,mt,fst)),ff as (flw,fin)) + => (do_cm ff cmi; + if mt then (mergeFollow nondet (fst,flw),fin) else (fst,false))) + ff cmis + + val _ = do_cm (nil,true) cmi + + in Array.vector table + end + end diff --git a/fxp/src/Parser/Dfa/dfaString.sml b/fxp/src/Parser/Dfa/dfaString.sml new file mode 100644 index 0000000..c867b80 --- /dev/null +++ b/fxp/src/Parser/Dfa/dfaString.sml @@ -0,0 +1,78 @@ + + + + + +(*--------------------------------------------------------------------------*) +(* Structure: DfaString *) +(* *) +(* Notes: *) +(* This structure is needed for debugging of content models and tables. *) +(* *) +(* Depends on: *) +(* DfaData *) +(* UtilString *) +(* *) +(* Exceptions raised by functions in this structure: *) +(* Table2String : none *) +(* ContentModel2String : none *) +(*--------------------------------------------------------------------------*) +signature DfaString = + sig + val ContentModel2String : (int -> string) -> DfaData.ContentModel -> string + val Dfa2String : (int -> string) -> DfaData.Dfa -> string + end + +structure DfaString : DfaString = + struct + open DfaBase UtilString + + fun State2String q = if q=dfaError then "Error" else Int2String q + + fun Info2String Elem2String (q,mt,fst) = String.concat + (State2String q::Bool2xString ("[empty]","") mt + ::map (fn (q,a) => " "^Elem2String a^"->"^State2String q) fst) + + fun ContentModel2String Elem2String cm = + case cm + of CM_ELEM i => Elem2String i + | CM_OPT cm => ContentModel2String Elem2String cm^"?" + | CM_REP cm => ContentModel2String Elem2String cm^"*" + | CM_PLUS cm => ContentModel2String Elem2String cm^"+" + | CM_ALT cms => List2xString ("(","|",")") (ContentModel2String Elem2String) cms + | CM_SEQ cms => List2xString ("(",",",")") (ContentModel2String Elem2String) cms + + fun CM2String Elem2String = + let fun cm2s indent cm = + case cm + of (ELEM a,info) => String.concat + [indent,Elem2String a," ",Info2String Elem2String info,"\n"] + | (OPT cm',info) => String.concat + [indent,"? ",Info2String Elem2String info,"\n",cm2s (indent^" ") cm'] + | (REP cm',info) => String.concat + [indent,"* ",Info2String Elem2String info,"\n",cm2s (indent^" ") cm'] + | (PLUS cm',info) => String.concat + [indent,"+ ",Info2String Elem2String info,"\n",cm2s (indent^" ") cm'] + | (ALT cms,info) => String.concat + (indent^"| "::Info2String Elem2String info::"\n" + ::map (cm2s (indent^" ")) cms) + | (SEQ cms,info) => String.concat + (indent^", "::Info2String Elem2String info::"\n" + ::map (cm2s (indent^" ")) cms) + in cm2s "" + end + + fun Row2String Elem2String (lo,hi,tab,fin) = + String.concat + (Vector.foldri + (fn (i,q,yet) => if q<0 then yet + else " "::Elem2String (i+lo)::"->"::State2String q::yet) + (if fin then [" [Final]"] else nil) + tab) + + fun Dfa2String Elem2String tab = + String.concat + (Vector.foldri + (fn (q,row,yet) => State2String q::":"::Row2String Elem2String row::yet) + nil tab) + end diff --git a/fxp/src/Parser/Dfa/dfaUtil.sml b/fxp/src/Parser/Dfa/dfaUtil.sml new file mode 100644 index 0000000..8a88f7c --- /dev/null +++ b/fxp/src/Parser/Dfa/dfaUtil.sml @@ -0,0 +1,130 @@ + + + + + + +(*--------------------------------------------------------------------------*) +(* Structure: DfaUtil *) +(* *) +(* Depends on: *) +(* DfaData *) +(* UtilInt *) +(* *) +(* Exceptions raised by functions in this structure: *) +(* boundsFollow : none *) +(* cmSymbols : none *) +(* makeRow : none *) +(* mergeFirst : ConflictFirst *) +(* mergeFollow : ConflictFollow *) +(*--------------------------------------------------------------------------*) +signature DfaUtil = + sig + val mergeFirst : bool -> DfaBase.First * DfaBase.First -> DfaBase.First + val mergeFollow : bool -> DfaBase.Follow * DfaBase.Follow -> DfaBase.Follow + val boundsFollow : DfaBase.Follow -> DfaBase.Sigma * DfaBase.Sigma + val cmSymbols : DfaBase.ContentModel -> DfaBase.Sigma list + val makeRow : DfaBase.Follow * bool -> DfaBase.Row + end + +structure DfaUtil : DfaUtil = + struct + open UtilInt DfaBase + + (*--------------------------------------------------------------------*) + (* merge two First sets, raise ConflictFirst at conflict: there may *) + (* not be two entries (q1,a) and (q2,a) in the same First set, if *) + (* nondet is false. *) + (*--------------------------------------------------------------------*) + fun mergeFirst nondet ll = + let + fun go_det (nil,l) = l + | go_det (l,nil) = l + | go_det (l1 as (x1 as (q1,a1))::r1,l2 as (x2 as (q2,a2))::r2) = + case Int.compare(a1,a2) + of LESS => x1::go_det(r1,l2) + | GREATER => x2::go_det(l1,r2) + | EQUAL => raise ConflictFirst(a1,q1,q2) + + fun go_nondet (nil,l) = l + | go_nondet (l,nil) = l + | go_nondet (l1 as (x1 as (q1,a1))::r1,l2 as (x2 as (q2,a2))::r2) = + case Int.compare(a1,a2) + of LESS => x1::go_nondet(r1,l2) + | GREATER => x2::go_nondet(l1,r2) + | EQUAL => case Int.compare(q1,q2) + of LESS => x1::go_nondet(r1,l2) + | GREATER => x2::go_nondet(l1,r2) + | EQUAL => go_nondet(l1,r2) + in + if nondet then go_nondet ll else go_det ll + end + + (*--------------------------------------------------------------------*) + (* merge two Follow sets, raise ConflictFollow at conflict. there may *) + (* not be two entries (q1,a) and (q2,a) with q1<>q2 in the same Follow*) + (* set, if nondet is false. Note that, e.g. for (a+)+, Follow(a) = *) + (* Follow(a+) U First(a+), so duplicate occurrences of the same (q,a) *) + (* are possible (as opposed to First). *) + (*--------------------------------------------------------------------*) + fun mergeFollow nondet ll = + let + fun go_det (nil,l) = l + | go_det (l,nil) = l + | go_det (l1 as (x1 as (q1,a1))::r1,l2 as (x2 as (q2,a2))::r2) = + case Int.compare(a1,a2) + of LESS => x1::go_det(r1,l2) + | GREATER => x2::go_det(l1,r2) + | EQUAL => if q1=q2 then go_det(l1,r2) + else raise ConflictFollow(a1,q1,q2) + + fun go_nondet (nil,l) = l + | go_nondet (l,nil) = l + | go_nondet (l1 as (x1 as (q1,a1))::r1,l2 as (x2 as (q2,a2))::r2) = + case Int.compare(a1,a2) + of LESS => x1::go_nondet(r1,l2) + | GREATER => x2::go_nondet(l1,r2) + | EQUAL => case Int.compare(q1,q2) + of LESS => x1::go_nondet(r1,l2) + | GREATER => x2::go_nondet(l1,r2) + | EQUAL => go_nondet(l1,r2) + in + if nondet then go_nondet ll else go_det ll + end + + (*--------------------------------------------------------------------*) + (* what are the least and largest symbol occurring in a Follow set? *) + (*--------------------------------------------------------------------*) + fun boundsFollow (nil:Follow) = (1,0) + | boundsFollow [(q,a)] = (a,a) + | boundsFollow ((q,a)::xs) = (a,#2(List.last xs)) + + (*--------------------------------------------------------------------*) + (* return the list of all symbols occurring in a content model. *) + (*--------------------------------------------------------------------*) + fun cmSymbols cm = + let + fun do_cm(cm,yet) = + case cm + of CM_ELEM a => insertInt(a,yet) + | CM_OPT cm => do_cm(cm,yet) + | CM_REP cm => do_cm(cm,yet) + | CM_PLUS cm => do_cm(cm,yet) + | CM_ALT cms => foldr do_cm yet cms + | CM_SEQ cms => foldr do_cm yet cms + in do_cm(cm,nil) + end + + (*--------------------------------------------------------------------*) + (* given the follow set and the final flag, make a row in the dfa. *) + (*--------------------------------------------------------------------*) + fun makeRow (flw,fin) = + let + val (lo,hi) = boundsFollow flw + val tab = Array.array(hi-lo+1,dfaError) + val _ = app (fn (q,a) => Array.update (tab,a-lo,q)) flw + in + (lo,hi,Array.vector tab,fin) + end + + end diff --git a/fxp/src/Parser/Dtd/dtdAttributes.sml b/fxp/src/Parser/Dtd/dtdAttributes.sml new file mode 100644 index 0000000..3bfdb52 --- /dev/null +++ b/fxp/src/Parser/Dtd/dtdAttributes.sml @@ -0,0 +1,538 @@ +(*--------------------------------------------------------------------------*) +(* Structure: DtdAttributes *) +(* *) +(* Exceptions raised by functions in this structure: *) +(* checkAttValue : AttValue InternalError *) +(* checkDefinedIds : none *) +(* genMissingAtts : none *) +(* makeAttValue : AttValue InternalError *) +(*--------------------------------------------------------------------------*) +functor DtdAttributes (structure Dtd : Dtd + structure Entities : Entities + structure ParserOptions : ParserOptions) = + struct + structure DtdDeclare = DtdDeclare (structure Dtd = Dtd + structure Entities = Entities + structure ParserOptions = ParserOptions) + open + UniChar UniClasses UtilList + Base Dtd DtdDeclare Errors Entities HookData ParserOptions + + val THIS_MODULE = "DtdAttributes" + + exception AttValue of AppData + + (*--------------------------------------------------------------------*) + (* this is the list of language codes in ISO 639. *) + (*--------------------------------------------------------------------*) + val iso639codes = + Vector.fromList + ["AA","AB","AF","AM","AR","AS","AY","AZ", + "BA","BE","BG","BH","BI","BN","BO","BR", + "CA","CO","CS","CY", + "DA","DE","DZ", + "EL","EN","EO","ES","ET","EU", + "FA","FI","FJ","FO","FR","FY", + "GA","GD","GL","GN","GU", + "HA","HE","HI","HR","HU","HY", + "IA","ID","IE","IK","IN","IS","IT","IU","IW", + "JA","JI","JW", + "KA","KK","KL","KM","KN","KO","KS","KU","KY", + "LA","LN","LO","LT","LV", + "MG","MI","MK","ML","MN","MO","MR","MS","MT","MY", + "NA","NE","NL","NO", + "OC","OM","OR", + "PA","PL","PS","PT", + "QU", + "RM","RN","RO","RU","RW", + "SA","SD","SG","SH","SI","SK","SL","SM","SN","SO","SQ","SR","SS","ST","SU","SV","SW", + "TA","TE","TG","TH","TI","TK","TL","TN","TO","TR","TS","TT","TW", + "UG","UK","UR","UZ", + "VI","VO", + "WO", + "XH", + "YI","YO", + "ZA","ZH","ZU"] + + (*--------------------------------------------------------------------*) + (* a two-dimensional field [0..25][0..25] of booleans for ISO 639. *) + (*--------------------------------------------------------------------*) + val iso639field = + let + val arr = Array.tabulate(26,fn _ => Array.array(26,false)) + val _ = Vector.map + (fn s => Array.update(Array.sub(arr,ord(String.sub(s,0))-65), + ord(String.sub(s,1))-65, + true)) + iso639codes + in Vector.tabulate(26,fn i => Array.vector (Array.sub(arr,i))) + end + + (*--------------------------------------------------------------------*) + (* for a letter, compute ord(toUpper c)-ord(#"A"), for subscripting. *) + (*--------------------------------------------------------------------*) + val toUpperMask = Chars.notb(0wx20) + fun cIndex c = Chars.toInt(Chars.andb(c,toUpperMask)-0wx41) + + (*--------------------------------------------------------------------*) + (* are these two letters an ISO 639 code? *) + (*--------------------------------------------------------------------*) + fun isIso639 (c1,c2) = + if !O_CHECK_ISO639 then + Vector.sub(Vector.sub(iso639field,cIndex c1),cIndex c2) + handle Subscript => false + else isAsciiLetter c1 andalso isAsciiLetter c2 + + (*--------------------------------------------------------------------*) + (* does this match Subcode ('-' Subcode)* ? *) + (* is this a sequence of ('-' Subcode) ? *) + (* Iana codes and user codes also end on ([a-z] | [A-Z])+ *) + (*--------------------------------------------------------------------*) + fun isSubcode' nil = false + | isSubcode' (c::cs) = + let fun doit nil = true + | doit (c::cs) = if c=0wx2D then isSubcode' cs + else isAsciiLetter c andalso doit cs + in isAsciiLetter c andalso doit cs + end + fun isSubcode nil = true + | isSubcode (c::cs) = c=0wx2D andalso isSubcode' cs + val isIanaUser = isSubcode' + + (*--------------------------------------------------------------------*) + (* Check whether a "xml:lang" attribute matches the LanguageID *) + (* production. 2.12: *) + (* *) + (* [33] LanguageID ::= Langcode ('-' Subcode)* *) + (* [34] Langcode ::= ISO639Code | IanaCode | UserCode *) + (* [35] ISO639Code ::= ([a-z] | [A-Z]) ([a-z] | [A-Z]) *) + (* [36] IanaCode ::= ('i' | 'I') '-' ([a-z] | [A-Z])+ *) + (* [37] UserCode ::= ('x' | 'X') '-' ([a-z] | [A-Z])+ *) + (* [38] Subcode ::= ([a-z] | [A-Z])+ *) + (* *) + (* print an error and raise AttValue if the "xml:lang" attribute does *) + (* not have a valid value. *) + (*--------------------------------------------------------------------*) + fun checkAttSpec (a,q) (aidx,cs) = + if !O_CHECK_LANGID andalso aidx=xmlLangIdx + then let val valid = case cs + of c::0wx2D::cs' => (c=0wx49 orelse + c=0wx69 orelse + c=0wx58 orelse + c=0wx78) andalso isIanaUser cs' + | c1::c2::cs' => isIso639 (c1,c2) andalso isSubcode cs' + | _ => false + in + if valid then a + else raise AttValue(hookError(a,(getPos q,ERR_ATT_IS_NOT(cs,IT_LANG_ID)))) + end + else a + + (*--------------------------------------------------------------------*) + (* Normalize an attribute value of type other than CDATA, and split *) + (* it into tokens at space characters. Cf. 3.3.3: *) + (* *) + (* ... If the declared value is not CDATA, then the XML processor *) + (* must further process the normalized attribute value by dis- *) + (* carding any leading and trailing space (#x20) characters, and by *) + (* replacing sequences of space (#x20) characters by a single space *) + (* (#x20) character. *) + (* *) + (* replacement of references is already done when parsing the literal,*) + (* thus we need only do whitespace normalization. we don't need to *) + (* take care of the 3rd rule since replacement of sequences of #x20 *) + (* and then splitting subsumes its effect. *) + (* *) + (* return the list of tokens as character lists and the normalized *) + (* value as a char vector. *) + (*--------------------------------------------------------------------*) + fun splitAttValue av = + let + fun doOne nil = (nil,nil,nil) + | doOne (c::cs) = if c=0wx20 then let val (toks,ys) = doAll true cs + in (nil,toks,ys) + end + else let val (tok,toks,ys) = doOne cs + in ((c::tok),toks,c::ys) + end + and doAll addS nil = (nil,nil) + | doAll addS (c::cs) = if c=0wx20 then doAll addS cs + else let val (tok,toks,ys) = doOne cs + in ((c::tok)::toks, + if addS then 0wx20::c::ys else c::ys) + end + + val (tokens,normed) = doAll false av + in (Data2Vector normed,tokens) + end + (*--------------------------------------------------------------------*) + (* normalize an attribute value other than CDATA according to 3.3.3. *) + (* *) + (* return the normalized att value as a Vector. *) + (*--------------------------------------------------------------------*) + fun normAttValue av = + let fun doOne nil = nil + | doOne (c::cs) = if c=0wx20 then doAll true cs + else c::doOne cs + and doAll addS nil = nil + | doAll addS (c::cs) = if c=0wx20 then doAll addS cs + else let val ys = doOne cs + in if addS then 0wx20::c::ys else c::ys + end + val normed = doAll false av + in Data2Vector normed + end + + (*--------------------------------------------------------------------*) + (* Check whether a sequence of chars forms a name (token). *) + (*--------------------------------------------------------------------*) + fun isNmToken cs = List.all isName cs + fun isaName nil = false + | isaName (c::cs) = isNms c andalso List.all isName cs + + (*--------------------------------------------------------------------*) + (* Check whether a list of tokens is a single what fulfilling isWhat. *) + (* print an error and raise AttValue if it is not. *) + (*--------------------------------------------------------------------*) + fun checkOne (isWhat,what,detail) (a,q) toks = + case toks + of nil => raise AttValue (hookError(a,(getPos q,ERR_EXACTLY_ONE detail))) + | [one] => if isWhat one then one + else raise AttValue(hookError(a,(getPos q,ERR_ATT_IS_NOT(one,what)))) + | more => raise AttValue(hookError(a,(getPos q,ERR_AT_MOST_ONE detail))) + (*--------------------------------------------------------------------*) + (* Check whether a list of tokens is non-empty and all elements ful- *) + (* fil isWhat. *) + (* print an error and raise AttValue if not. *) + (*--------------------------------------------------------------------*) + fun checkList (isWhat,what,detail) (a,q) toks = + case toks + of nil => raise AttValue (hookError(a,(getPos q,ERR_AT_LEAST_ONE detail))) + | _ => app (fn one => if isWhat one then () + else let val err = ERR_ATT_IS_NOT(one,what) + in raise AttValue(hookError(a,(getPos q,err))) + end) toks + (*--------------------------------------------------------------------*) + (* Convert a list of tokens into an ID att value. 3.3.1: *) + (* *) + (* Validity Constraint: ID *) + (* Values of type ID must match the Name production. *) + (* *) + (* Validity Constraint: ID *) + (* ... A name must not appear more than once in an XML document as *) + (* a value of this type; i.e., ID values must uniquely identify the *) + (* elements which bear them. *) + (* *) + (* mark the value as used, print an error and raise AttValue if it *) + (* was already used. *) + (* print an error and raise AttValue if it is not a name. *) + (*--------------------------------------------------------------------*) + fun takeId (dtd,inDtd) (a,q) toks = + let val one = checkOne (isaName,IT_NAME,IT_ID_NAME) (a,q) toks + val idx = Id2Index dtd one + val _ = if inDtd then () + else let val (decl,refs) = getId dtd idx + in if decl then let val err = ERR_REPEATED_ID one + in raise AttValue (hookError(a,(getPos q,err))) + end + else setId dtd (idx,(true,refs)) + end + in (SOME(AV_ID idx),a) + end + + (*--------------------------------------------------------------------*) + (* Convert a list of tokens into an IDREF/IDREFS att value. 3.3.1: *) + (* *) + (* Validity Constraint: IDREF *) + (* Values of type IDREF must match the Name production. *) + (* *) + (* print an error an raise AttValue if it is not a (list of) name(s). *) + (*--------------------------------------------------------------------*) + fun setIdRef (dtd,q) idx = + let val (decl,refs) = getId dtd idx + in setId dtd (idx,(decl,getPos q::refs)) + end + fun takeIdref (dtd,_) (a,q) toks = + let val one = checkOne (isaName,IT_NAME,IT_ID_NAME) (a,q) toks + val idx=Id2Index dtd one + val _ = setIdRef (dtd,q) idx + in (SOME(AV_IDREF idx),a) + end + fun takeIdrefs (dtd,_) (a,q) toks = + let val _ = checkList (isaName,IT_NAME,IT_ID_NAME) (a,q) toks + val idxs = map (Id2Index dtd) toks + val _ = app (setIdRef (dtd,q)) idxs + in (SOME(AV_IDREFS idxs),a) + end + + (*--------------------------------------------------------------------*) + (* Convert a list of tokens into an ENTITY/IES att value. 3.3.1: *) + (* *) + (* Validity Constraint: Entity Name *) + (* Values of type ENTITY must match the Name production... *) + (* must match the name of an unparsed entity declared in the DTD. *) + (* *) + (* print an error and raise AttValue if a token is not a name. *) + (* print an error and raise AttValue if an entity is undeclared or a *) + (* parsed entity. *) + (*--------------------------------------------------------------------*) + fun checkEntity (dtd,inDtd) (a,q) name = + let val idx = GenEnt2Index dtd name + val (ent,_) = getGenEnt dtd idx + val _ = if inDtd then () + else case ent + of GE_UNPARSED _ => () + | GE_NULL => let val err = ERR_UNDECLARED(IT_GEN_ENT,name,LOC_NONE) + in raise AttValue (hookError(a,(getPos q,err))) + end + | _ => let val err = ERR_MUST_BE_UNPARSED(name,LOC_NONE) + in raise AttValue (hookError(a,(getPos q,err))) + end + in idx + end + fun takeEntity (dtd,inDtd) (aq as (a,_)) toks = + let val one = checkOne (isaName,IT_NAME,IT_ENT_NAME) aq toks + val idx = checkEntity (dtd,inDtd) aq one + in (SOME(AV_ENTITY idx),a) + end + fun takeEntities (dtd,inDtd) (aq as (a,_)) toks = + let val _ = checkList (isaName,IT_NAME,IT_ENT_NAME) aq toks + val idxs = map (checkEntity (dtd,inDtd) aq) toks + in (SOME(AV_ENTITIES idxs),a) + end + + (*--------------------------------------------------------------------*) + (* Convert a list of tokens into a NOTATION att value. 3.3.1: *) + (* *) + (* Validity Constraint: Notation Attributes *) + (* Values of this type must match one of the notation names *) + (* included in the declaration. *) + (* *) + (* print an error and raise AttValue if it is not a single name. *) + (* print an error and raise AttValue if the notation's index is not *) + (* in the list given as 1st arg. *) + (*--------------------------------------------------------------------*) + fun takeNotation is (dtd,inDtd) (aq as (a,q)) toks = + let val one = checkOne (isaName,IT_NAME,IT_NOT_NAME) aq toks + val idx = AttNot2Index dtd one + val _ = if member idx is then () + else let val nots = map (Index2AttNot dtd) is + val err = ERR_MUST_BE_AMONG(IT_NOT_NAME,one,nots) + in raise AttValue (hookError(a,(getPos q,err))) + end + in (SOME(AV_NOTATION(is,idx)),a) + end + + (*--------------------------------------------------------------------*) + (* Convert a list of tokens into an enumerated att value. 3.3.1: *) + (* *) + (* Validity Constraint: Enumeration *) + (* Values of this type must match one of the Nmtoken tokens in *) + (* the declaration. *) + (* *) + (* print an error and raise AttValue if it is not a single name token.*) + (* print an error and raise AttValue if the token's index is not *) + (* in the list given as 1st arg. *) + (*--------------------------------------------------------------------*) + fun takeGroup is (dtd,_) (aq as (a,q)) toks = + let val one = checkOne (isNmToken,IT_NMTOKEN,IT_NMTOKEN) aq toks + val idx = AttNot2Index dtd one + val _ = if member idx is then () + else let val toks = map (Index2AttNot dtd) is + val err = ERR_MUST_BE_AMONG(IT_NMTOKEN,one,toks) + in raise AttValue (hookError(a,(getPos q,err))) + end + in (SOME(AV_GROUP(is,idx)),a) + end + + (*--------------------------------------------------------------------*) + (* Given an attribute type and a list of characters, construct the *) + (* corresponding AttValue. *) + (* *) + (* print an error (and possibly raise AttValue) if the attribute *) + (* is ill-formed. *) + (*--------------------------------------------------------------------*) + fun makeAttValue dtd (a,q) (aidx,attType,ext,inDtd,cs) = + if attType=AT_CDATA + then let val cv = Data2Vector cs + in if !O_VALIDATE andalso hasDtd dtd + then (cv,(SOME(AV_CDATA cv),checkAttSpec (a,q) (aidx,cs))) + else (cv,(NONE,a)) + end + else + if !O_VALIDATE andalso hasDtd dtd then + let + val a1 = checkAttSpec (a,q) (aidx,cs) + val (cv,toks) = splitAttValue cs + val a2 = + if ext andalso standsAlone dtd + then let val cdata = Data2Vector cs + in if cdata=cv then a1 + else let val err = ERR_STANDALONE_NORM(Index2AttNot dtd aidx) + val _ = setStandAlone dtd (not (!O_ERROR_MINIMIZE)) + in hookError(a1,(getPos q,err)) + end + end + else a1 + in case attType + of AT_NMTOKEN => (cv,(SOME(AV_NMTOKEN(checkOne(isNmToken,IT_NMTOKEN, + IT_NMTOKEN) (a2,q) toks)),a2)) + | AT_NMTOKENS => (cv,(SOME(AV_NMTOKENS toks),a2)) before + checkList(isNmToken,IT_NMTOKEN,IT_NMTOKEN) (a2,q) toks + | AT_ID => (cv,takeId (dtd,inDtd) (a2,q) toks) + | AT_IDREF => (cv,takeIdref (dtd,inDtd) (a2,q) toks) + | AT_IDREFS => (cv,takeIdrefs (dtd,inDtd) (a2,q) toks) + | AT_ENTITY => (cv,takeEntity (dtd,inDtd) (a2,q) toks) + | AT_ENTITIES => (cv,takeEntities (dtd,inDtd) (a2,q) toks) + | AT_GROUP is => (cv,takeGroup is (dtd,inDtd) (a2,q) toks) + | AT_NOTATION is => (cv,takeNotation is (dtd,inDtd) (a2,q) toks) + | AT_CDATA => raise InternalError(THIS_MODULE,"makeAttValue", + "AT_CDATA in the innermost case") + end + else (normAttValue cs,(NONE,a)) + + (*--------------------------------------------------------------------*) + (* given an attribute value literal and the attribute type, generate *) + (* the AttValue, and check whether it complies with its default value.*) + (* If yes, make an AttPresent value out of it. *) + (* See 3.3.2: *) + (* *) + (* Validity Constraint: Fixed Attribute Default *) + (* If an attribute has a default value declared with the #FIXED *) + (* keyword, instances of that attribute must match the default *) + (* value. *) + (* *) + (* print an error and raise AttValue if the attribute value doesn't *) + (* comply. *) + (* *) + (* return the value as a AttPresent value. *) + (*--------------------------------------------------------------------*) + fun checkAttValue dtd (a,q) ((aidx,attType,defVal,ext),literal,cs) = + let val (cv,(av,a1)) = makeAttValue dtd (a,q) (aidx,attType,ext,false,cs) + in if !O_VALIDATE andalso hasDtd dtd then + case defVal + of AD_FIXED((def,cv',_),_) => + if cv=cv' then (AP_PRESENT(literal,cv,av),a1) + else raise AttValue + (hookError(a1,(getPos q,ERR_FIXED_VALUE(Index2AttNot dtd aidx,cv,cv')))) + | _ => (AP_PRESENT(literal,cv,av),a1) + else (AP_PRESENT(literal,cv,av),a1) + end + + (*--------------------------------------------------------------------*) + (* check a defaulted attribute value for validity. *) + (* *) + (* since the lexical constraints are checked when the default is *) + (* declared we only need to check whether notations are declared and *) + (* entities are declared and unparsed. An ID attribute cannot be *) + (* defaulted, so no need to check for duplicate ID attributes. *) + (*--------------------------------------------------------------------*) + fun checkDefaultValue dtd (a,q,pos) av = + let + fun checkEntity (idx,a) = + let val (ent,_) = getGenEnt dtd idx + in case ent + of GE_UNPARSED _ => a + | GE_NULL => hookError(a,(getPos q,ERR_UNDECLARED + (IT_GEN_ENT,Index2GenEnt dtd idx, + LOC_ATT_DEFAULT pos))) + | _ => hookError(a,(getPos q,ERR_MUST_BE_UNPARSED + (Index2GenEnt dtd idx,LOC_ATT_DEFAULT pos))) + end + + fun checkNotation (idx,a) = + if hasNotation dtd idx then a + else hookError(a,(getPos q,ERR_UNDECLARED + (IT_NOTATION,Index2AttNot dtd idx,LOC_ATT_DEFAULT pos))) + in + case av + of SOME(AV_ENTITY i) => checkEntity (i,a) + | SOME(AV_ENTITIES is) => foldl checkEntity a is + | SOME(AV_NOTATION(_,i)) => checkNotation(i,a) + | _ => a + end + + (*--------------------------------------------------------------------*) + (* Generate the attributes not specified in a start-tag, the defs of *) + (* these atts and the specified atts given as argument. 3.3.2: *) + (* *) + (* If the declaration is neither #REQUIRED nor #IMPLIED, then the *) + (* AttValue value contains the declared default value; ... If a *) + (* default value is declared, when an XML processor encounters an *) + (* omitted attribute, it is to behave as though the attribute were *) + (* present with the declared default value. *) + (* *) + (* Validity Constraint: Required Attribute *) + (* If the default declaration is the keyword #REQUIRED, then the *) + (* attribute must be specified for all elements of the type in the *) + (* attribute-list declaration. *) + (* *) + (* print an error if a required attribute was omitted. *) + (* *) + (* return the AttSpecList of all attributes for this tag. *) + (*--------------------------------------------------------------------*) + fun genMissingAtts dtd (a,q) (defs,specd) = + let + fun default a (idx,(v as (_,_,av),(pos,checked)),ext) = + let val a1 = if ext andalso !O_VALIDATE andalso standsAlone dtd + then let val err = ERR_STANDALONE_DEF(Index2AttNot dtd idx) + val _ = setStandAlone dtd (not (!O_ERROR_MINIMIZE)) + in hookError(a,(getPos q,err)) + end + else a + val a2 = if !O_VALIDATE andalso not (!checked andalso !O_ERROR_MINIMIZE) + then checkDefaultValue dtd (a1,q,pos) av before checked := true + else a1 + in (AP_DEFAULT v,a1) + end + fun doit a nil = (specd,a) + | doit a ((idx,_,dv,ext)::rest) = + let val (value,a1) = + case dv + of AD_DEFAULT v => default a (idx,v,ext) + | AD_FIXED v => default a (idx,v,ext) + | AD_IMPLIED => (AP_IMPLIED,a) + | AD_REQUIRED => + let val a1 = if not (!O_VALIDATE) then a + else hookError(a,(getPos q, + ERR_MISSING_ATT(Index2AttNot dtd idx))) + in (AP_MISSING,a1) + end + val (other,a2) = doit a1 rest + in ((idx,value,NONE)::other,a2) + end + in doit a defs + end + + (*--------------------------------------------------------------------*) + (* process an undeclared attribute in a start-tag. *) + (* At option, an error message is generated only once for the same *) + (* attribute and element. *) + (* *) + (* possibly print an error. *) + (* *) + (* return nothing. *) + (*--------------------------------------------------------------------*) + fun handleUndeclAtt dtd (a,q) (aidx,att,eidx,elem) = + if !O_ERROR_MINIMIZE then + let val {decl,atts,errAtts} = getElement dtd eidx + in if member aidx errAtts then a + else let val a1 = if !O_VALIDATE andalso hasDtd dtd + then let val err = ERR_UNDECL_ATT(att,elem) + in hookError(a,(getPos q,err)) + end + else a + val a2 = checkAttName (a1,q) att + val _ = setElement dtd (eidx,{decl = decl, + atts = atts, + errAtts = aidx::errAtts}) + in a2 + end + end + else let val a1 = if !O_VALIDATE andalso hasDtd dtd + then hookError(a,(getPos q,ERR_UNDECL_ATT(att,elem))) + else a + in checkAttName (a1,q) att + end + + end diff --git a/fxp/src/Parser/Dtd/dtdDeclare.sml b/fxp/src/Parser/Dtd/dtdDeclare.sml new file mode 100644 index 0000000..1e70ba4 --- /dev/null +++ b/fxp/src/Parser/Dtd/dtdDeclare.sml @@ -0,0 +1,466 @@ +(*--------------------------------------------------------------------------*) +(* Structure: DtdDeclare *) +(* *) +(*--------------------------------------------------------------------------*) +(* Functor: DtdDeclare *) +(*--------------------------------------------------------------------------*) +(* This module provides functions for adding declarations to the DTD tables *) +(* and for doing checks on components of declarations. *) +(*--------------------------------------------------------------------------*) +functor DtdDeclare (structure Dtd : Dtd + structure Entities : Entities + structure ParserOptions : ParserOptions) = + struct + open + UtilInt UtilList + Base Dtd Errors Entities ParserOptions UniChar UniClasses + + (*--------------------------------------------------------------------*) + (* check whether a sequence a chars is the b-adic representation of a *) + (* character's code, terminated by ";". base will be 10 or 16, isBase *) + (* will check for a character being a decimal/hexadecimal number. *) + (*--------------------------------------------------------------------*) + fun checkBasimal (base,baseValue) (ch:Char,cs) = + let fun doit _ (nil:Data) = false + | doit yet [0wx3B] = yet=ch + | doit yet (c::cs) = case baseValue c + of NONE => false + | SOME v => doit (base*yet+v) cs + in doit 0w0 cs + end + val checkDecimal = checkBasimal (0w10,decValue) + val checkHeximal = checkBasimal (0wx10,hexValue) + + (*--------------------------------------------------------------------*) + (* check a character reference for identifying a character. *) + (*--------------------------------------------------------------------*) + fun checkRef (ch,0wx26::0wx23::0wx78::cs) (* "&#x..." *) = checkHeximal(ch,cs) + | checkRef (ch,0wx26::0wx23::cs) (* "&#..." *) = checkDecimal(ch,cs) + | checkRef _ = false + + (*--------------------------------------------------------------------*) + (* check for a single character ch. *) + (*--------------------------------------------------------------------*) + fun checkSingle (ch,[c]) = c=ch + | checkSingle _ = false + + (*--------------------------------------------------------------------*) + (* check a predefined entity for being well defined. Note that both *) + (* a single char and a char ref representation are allowed, except *) + (* for 'amp' which must be escaped. *) + (*--------------------------------------------------------------------*) + fun checkPredef (idx,cs) = + case idx + of 1 => checkRef(0wx26,cs) + | 2 => checkSingle(0wx3C,cs) orelse checkRef(0wx3C,cs) + | 3 => checkSingle(0wx3E,cs) orelse checkRef(0wx3E,cs) + | 4 => checkSingle(0wx27,cs) orelse checkRef(0wx27,cs) + | 5 => checkSingle(0wx22,cs) orelse checkRef(0wx22,cs) + | _ => true + + (*--------------------------------------------------------------------*) + (* Given the declaration of an entity check whether it is predefined. *) + (* If no return false. If yes, check whether is was already declared *) + (* and whether it is correctly declared. See 4.6: *) + (* *) + (* All XML processors must recognize these entities whether they *) + (* are declared or not. For interoperability, valid XML documents *) + (* should declare these entities, like any others, before using *) + (* them. If the entities in question are declared, they must be *) + (* declared as internal entities whose replacement text is the *) + (* single character being escaped or a character reference to that *) + (* character, as shown below. *) + (* *) + (* *) + (* *) + (* *) + (* *) + (* *) + (* *) + (* Note that the < and & characters in the declarations of "lt" and *) + (* "amp" are doubly escaped to meet the requirement that entity *) + (* replacement be well-formed. *) + (* *) + (* print an error if the entity was already declared. *) + (* print an error if the declaration is not correct. *) + (*--------------------------------------------------------------------*) + fun checkPredefined dtd (a,q) (idx,ent) = + if !O_VALIDATE andalso idx>=1 andalso idx<=5 then + let + val a1 = if !O_WARN_MULT_ENT_DECL andalso isRedefined dtd idx + then let val warn = WARN_MULT_DECL(IT_GEN_ENT,Index2GenEnt dtd idx) + in hookWarning(a,(getPos q,warn)) + end + else a before setRedefined dtd idx + val a2 = + if !O_CHECK_PREDEFINED then + let val correct = + case ent + of GE_INTERN(_,rep) => checkPredef (idx,Vector2Data rep) + | _ => false + in if correct then a1 + else let val err = ERR_DECL_PREDEF(Index2GenEnt dtd idx,validPredef idx) + in hookError(a1,(getPos q,err)) + end + end + else a1 + in (true,a2) + end + else (false,a) + + (*--------------------------------------------------------------------*) + (* add an entity declaration to the DTD tables. 4.2 *) + (* *) + (* ... If the same entity is declared more than once, the first *) + (* declaration encountered is binding; at user option, an XML *) + (* processor may issue a warning if entities are declared multiple *) + (* times. *) + (* *) + (* For general entities, check whether it is a predefined entity and *) + (* if so, whether it is declared correctly. *) + (*--------------------------------------------------------------------*) + (* print a warning and ignore the declaration if the notation was *) + (* declared previously. *) + (*--------------------------------------------------------------------*) + fun addGenEnt dtd (a,q) (idx,ent,ext) = + case getGenEnt dtd idx + of (GE_NULL,_) => a before setGenEnt dtd (idx,(ent,ext)) + | _ => let val (pre,a1) = checkPredefined dtd (a,q) (idx,ent) + in if pre orelse not (!O_WARN_MULT_ENT_DECL) then a1 + else hookWarning(a1,(getPos q,WARN_MULT_DECL + (IT_GEN_ENT,Index2GenEnt dtd idx))) + end + + fun addParEnt dtd (a,q) (idx,ent,ext) = + case getParEnt dtd idx + of (PE_NULL,_) => a before setParEnt dtd (idx,(ent,ext)) + | _ => if !O_WARN_MULT_ENT_DECL + then hookWarning(a,(getPos q,WARN_MULT_DECL + (IT_PAR_ENT,Index2ParEnt dtd idx))) + else a + + (*--------------------------------------------------------------------*) + (* at option print a warning if not all predefined entities have been *) + (* declared. Cf. 4.1: *) + (* *) + (* For interoperability, valid documents should declare the *) + (* entities amp, lt, gt, apos, quot, in the form specified in *) + (* "4.6 Predefined Entities". *) + (*--------------------------------------------------------------------*) + fun checkPreDefined dtd (a,q) = + if !O_VALIDATE andalso !O_INTEROPERABILITY andalso + !O_WARN_SHOULD_DECLARE andalso hasDtd dtd + then case notRedefined dtd + of nil => a + | ents => hookWarning(a,(getPos q,WARN_SHOULD_DECLARE ents)) + else a + + (*--------------------------------------------------------------------*) + (* add a notation declaration to the DTD tables. *) + (* *) + (* though the rec. says nothing about repeated notation declarations, *) + (* I assume that the intention is to treat them like entities, i.e. *) + (* ignore repeated declarations with an optional warning. *) + (* *) + (* print a warning and ignore the declaration if the notation was *) + (* declared previously. *) + (*--------------------------------------------------------------------*) + fun addNotation dtd (a,q) (idx,nt) = + if hasNotation dtd idx + then if !O_WARN_MULT_NOT_DECL + then hookWarning(a,(getPos q,WARN_MULT_DECL + (IT_NOTATION,Index2AttNot dtd idx))) + else a + else a before setNotation dtd (idx,nt) + + (*--------------------------------------------------------------------*) + (* add an element declaration to the element table. Only the content *) + (* part of the element info is updated. 3.2: *) + (* *) + (* Validity Constraint: Unique Element Type Declaration *) + (* No element type may be declared more than once. *) + (* *) + (* print an error and ignore the declaration if the element was *) + (* declared previously. *) + (*--------------------------------------------------------------------*) + fun addElement dtd (a,q) (idx,cont,ext) = + let val {decl,atts,errAtts,...} = getElement dtd idx + in case decl + of NONE => a before setElement dtd (idx,{decl = SOME(cont,ext), + atts = atts, + errAtts = errAtts}) + | SOME _ => if !O_VALIDATE + then hookError(a,(getPos q,ERR_REDEC_ELEM(Index2Element dtd idx))) + else a + end + + (*--------------------------------------------------------------------*) + (* at option, pretend an element is declared by adding a default *) + (* declaration. Only the decl flag of the element info is updated. *) + (*--------------------------------------------------------------------*) + fun handleUndeclElement dtd idx = + let + val {atts,errAtts,...} = getElement dtd idx + val newInfo = {decl = SOME(CT_ANY,false), + atts = atts, + errAtts = errAtts} + in newInfo before setElement dtd (idx,newInfo) + end + + (*--------------------------------------------------------------------*) + (* check whether an element is declared and whether it already had an *) + (* attribute list declaration. Cf. 3.3: *) + (* *) + (* At user option, an XML processor may issue a warning if *) + (* attributes are declared for an element type not itself declared, *) + (* but this is not an error. *) + (* *) + (* ... an XML processor may at user option issue a warning when *) + (* more than one attribute-list declaration is provided for a given *) + (* element type, ... *) + (* *) + (* print a warning if the element is not declared or already had an *) + (* attribute list declaration. *) + (*--------------------------------------------------------------------*) + fun enterAttList dtd (a,q) idx = + let + val {decl,atts,errAtts,...} = getElement dtd idx + val a1 = if isSome decl orelse not (!O_WARN_ATT_NO_ELEM) then a + else hookWarning(a,(getPos q,WARN_ATT_UNDEC_ELEM(Index2Element dtd idx))) + in + case atts + of NONE => a1 before + setElement dtd (idx,{decl=decl,atts=SOME(nil,false),errAtts=errAtts}) + | _ => if !O_INTEROPERABILITY andalso !O_WARN_MULT_ATT_DECL + then hookWarning(a1,(getPos q,WARN_MULT_ATT_DECL(Index2Element dtd idx))) + else a1 + end + + (*--------------------------------------------------------------------*) + (* check whether attribute "xml:space" is declared correctly. 2.10: *) + (* *) + (* A special attribute named xml:space may be attached ... In valid *) + (* documents, this attribute, like any other, must be declared if *) + (* it is used. When declared, it must be given as an enumerated *) + (* type whose only possible values are "default" and "preserve". *) + (*--------------------------------------------------------------------*) + (* XML 1.0 (Third Edition) has corrected this to: When declared, *) + (* it MUST be given as an enumerated type whose values are one or *) + (* both of "default" and "preserve". *) + (*--------------------------------------------------------------------*) + + fun checkAttDef (a,q) (aidx,attType,_,_) = + if aidx<>xmlSpaceIdx then a + else + case attType of + AT_GROUP [a1,a2] => + if (a1 = preserveIdx andalso a2 = defaultIdx) + orelse (a2 = preserveIdx andalso a1 = defaultIdx) then a + else hookError(a,(getPos q,ERR_XML_SPACE)) + | AT_GROUP [a1] => + if (a1 = preserveIdx orelse a1 = defaultIdx) then a + else hookError(a,(getPos q,ERR_XML_SPACE)) + | _ => hookError(a,(getPos q,ERR_XML_SPACE)) + + + + (*--------------------------------------------------------------------*) + (* enter a definition of a single attribute to the element table. *) + (* ignore the definition if the attribute is already defined for that *) + (* element. Cf. 3.3: *) + (* *) + (* When more than one AttlistDecl is provided for a given element *) + (* type, the contents of all those provided are merged. When more *) + (* than one definition is provided for the same attribute of a *) + (* given element type, the first declaration is binding and later *) + (* declarations are ignored. For interoperability, an XML processor *) + (* may at user option issue a warning when ... more than one *) + (* attribute definition is provided for a given attribute, but this *) + (* is not an error. *) + (* *) + (* If the attribute type is ID, check whether an element already has *) + (* an attribute of that type. 3.3.1: *) + (* *) + (* Validity Constraint: One ID per Element Type *) + (* No element type may have more than one ID attribute specified. *) + (*--------------------------------------------------------------------*) + (* print an error if the element already has an ID attribute. *) + (* print a warning if the attr. is already defined for this element. *) + (*--------------------------------------------------------------------*) + (* return the new application data. *) + (*--------------------------------------------------------------------*) + fun addAttribute dtd (a,q) (eidx,attDef as (att,attType,attDefault,_)) = + let + val a1 = checkAttDef (a,q) attDef + + fun doit nil = (false,[attDef],a) + | doit (atts as (ad as (aidx,_,_,_))::rest) = + if aidx=att + then let val a1 = if !O_INTEROPERABILITY andalso !O_WARN_MULT_ATT_DEF + then let val warn = WARN_MULT_ATT_DEF + (Index2Element dtd eidx,Index2AttNot dtd att) + in hookWarning(a,(getPos q,warn)) + end + else a + in (true,atts,a1) + end + else (if aidx (c1=0wx58 orelse c1=0wx78) andalso + (c2=0wx4D orelse c2=0wx6D) andalso (c3=0wx4C orelse c3=0wx6C) + | _ => false + fun checkAttName (a,q) name = + if !O_CHECK_RESERVED andalso startsWithXml name then + case name + of [0wx78,0wx6d,0wx6c,0wx3a,0wx6c,0wx61,0wx6e,0wx67] (* ":lang" *) => a + | [0wx78,0wx6d,0wx6c,0wx3a,0wx73,0wx70,0wx61,0wx63,0wx65] (* ":space" *) => a + | _ => hookError(a,(getPos q,ERR_RESERVED(name,IT_ATT_NAME))) + else a + fun checkElemName (a,q) name = + if !O_CHECK_RESERVED andalso startsWithXml name + then hookError(a,(getPos q,ERR_RESERVED(name,IT_ELEM))) + else a + + (*--------------------------------------------------------------------*) + (* check for each element in the dtd, whether a name token occurs *) + (* more than once in its enumerated attribute types. *) + (* *) + (* print a warning for each element where this is true. *) + (* *) + (* return nothing. *) + (*--------------------------------------------------------------------*) + fun checkMultEnum dtd (a,q) = + if !O_INTEROPERABILITY andalso !O_WARN_MULT_ENUM then + let + fun doElem a idx = + let + (*-----------------------------------------------------*) + (* for each i, add i to yet if it not in that list. *) + (* otherwise add it to dup. *) + (*-----------------------------------------------------*) + fun do_list yd nil = yd + | do_list (yet,dup) (i::is) = + let val yd' = case insertNewInt (i,yet) + of NONE => (yet,insertInt (i,dup)) + | SOME new => (new,dup) + in do_list yd' is + end + (*-----------------------------------------------------*) + (* For each enumerated attribute type call the appro- *) + (* priate function. *) + (*-----------------------------------------------------*) + fun doit (yet,dup) nil = dup + | doit (yet,dup) ((_,attType,_,_)::rest) = + case attType + of AT_GROUP is => doit (do_list (yet,dup) is) rest + | AT_NOTATION is => doit (do_list (yet,dup) is) rest + | _ => doit (yet,dup) rest + + val defs = case #atts(getElement dtd idx) + of NONE => nil + | SOME(defs,_) => defs + val dup = doit (nil,nil) defs + in + if null dup then a + else hookWarning(a,(getPos q,WARN_ENUM_ATTS + (Index2Element dtd idx,map (Index2AttNot dtd) dup))) + end + (*-----------------------------------------------------------*) + (* the highest used index is usedIndices-1. *) + (*-----------------------------------------------------------*) + val maxIdx = maxUsedElem dtd + + fun doit a i = if i>maxIdx then a else doit (doElem a i) (i+1) + in + doit a 0 + end + else a + + (*--------------------------------------------------------------------*) + (* check for all id names refereneced by some IDREF attribute whether *) + (* it was also declared by an ID attribute. *) + (* *) + (* print an error if a referenced ID name was not defined. *) + (* *) + (* return nothing. *) + (*--------------------------------------------------------------------*) + fun checkDefinedIds dtd (a,q) = + if !O_VALIDATE then + let + val maxId = maxUsedId dtd + + fun doOne a i = let val (decl,refs) = getId dtd i + in if decl orelse null refs then a + else hookError(a,(hd refs,ERR_UNDECL_ID(Index2Id dtd i,tl refs))) + end + fun doAll a i = if i>maxId then a else doAll (doOne a i) (i+1) + in + doAll a 0 + end + else a + + (*--------------------------------------------------------------------*) + (* check for all declared unparsed entities, whether their notations *) + (* have been declared. *) + (* *) + (* print an error if a notation was not declared. *) + (* *) + (* return nothing. *) + (*--------------------------------------------------------------------*) + fun checkUnparsed dtd a = + if !O_VALIDATE then + let + val maxGen = maxUsedGen dtd + + fun doOne a i = + case getGenEnt dtd i + of (GE_UNPARSED(_,nidx,pos),_) => + if hasNotation dtd nidx then a + else hookError(a,(pos,ERR_UNDECLARED + (IT_NOTATION,Index2AttNot dtd nidx,LOC_NONE))) + | _ => a + fun doAll a i = if i>maxGen then a else doAll (doOne a i) (i+1) + in + doAll a 0 + end + else a + end diff --git a/fxp/src/Parser/Dtd/dtdManager.sml b/fxp/src/Parser/Dtd/dtdManager.sml new file mode 100644 index 0000000..4a5e0d8 --- /dev/null +++ b/fxp/src/Parser/Dtd/dtdManager.sml @@ -0,0 +1,71 @@ +(*--------------------------------------------------------------------------*) +(* Structure: Dtd *) +(* *) +(* Depends on: *) +(* UniChar *) +(* DtdAttributes *) +(* DtdElements *) +(* DtdEntities *) +(* DtdNotations *) +(* DtdStandalone *) +(* *) +(* Exceptions raised by functions in this structure: *) +(* initDtdTables : none *) +(* AttIdx2String : NoSuchSymbol *) +(* ElemIdx2String : NoSuchIndex *) +(* GenEntIdx2String : NoSuchIndex *) +(* IdIdx2String : NoSuchIndex *) +(* NotIdx2String : NoSuchIndex *) +(* GenEntity2String : NoSuchIndex *) +(* ElemInfo2String : NoSuchIndex NoSuchSymbol *) +(* printGenEntTable : NoSuchIndex *) +(* printElementTable : NoSuchIndex NoSuchSymbol *) +(* printDtdTables : NoSuchIndex NoSuchSymbol *) +(*--------------------------------------------------------------------------*) +signature DtdManager = + sig + include Entities + include Dtd + + exception AttValue of AppData + + val makeAttValue : Dtd -> AppData * State + -> int * Base.AttType * bool * bool * UniChar.Data + -> UniChar.Vector * (Base.AttValue option * AppData) + val checkAttValue : Dtd -> AppData * State + -> Base.AttDef * UniChar.Vector * UniChar.Data + -> HookData.AttPresent * AppData + val genMissingAtts : Dtd -> AppData * State + -> Base.AttDefList * HookData.AttSpecList -> HookData.AttSpecList * AppData + val handleUndeclAtt : Dtd -> AppData * State + -> int * UniChar.Data * int * UniChar.Data -> AppData + val handleUndeclElement : Dtd -> int -> Base.ElemInfo + + val checkAttName : AppData * State -> UniChar.Data -> AppData + val checkElemName : AppData * State -> UniChar.Data -> AppData + val checkDefinedIds : Dtd -> AppData * State -> AppData + val checkMultEnum : Dtd -> AppData * State -> AppData + val checkPreDefined : Dtd -> AppData * State -> AppData + val checkUnparsed : Dtd -> AppData -> AppData + + val enterAttList : Dtd -> AppData * State -> int -> AppData + + val addAttribute : Dtd -> AppData * State -> int * Base.AttDef -> AppData + val addElement : Dtd -> AppData * State -> int * Base.ContentSpec * bool -> AppData + val addGenEnt : Dtd -> AppData * State -> int * Base.GenEntity * bool -> AppData + val addNotation : Dtd -> AppData * State -> int * Base.ExternalId -> AppData + val addParEnt : Dtd -> AppData * State -> int * Base.ParEntity * bool -> AppData + end + +functor DtdManager (structure Dtd : Dtd + structure Hooks : Hooks + structure ParserOptions : ParserOptions) : DtdManager = + struct + structure Entities = Entities (structure Hooks = Hooks) + structure DtdAttributes = DtdAttributes (structure Dtd = Dtd + structure Entities = Entities + structure ParserOptions = ParserOptions) + open + Dtd + DtdAttributes + end diff --git a/fxp/src/Parser/Error/errorData.sml b/fxp/src/Parser/Error/errorData.sml new file mode 100644 index 0000000..72d9af6 --- /dev/null +++ b/fxp/src/Parser/Error/errorData.sml @@ -0,0 +1,176 @@ +structure ErrorData = + struct + (*--------------------------------------------------------------------*) + (* a position holds the filename, line and column number. *) + (*--------------------------------------------------------------------*) + type Position = string * int * int + val nullPosition = ("",0,0) + + datatype ExpItem = + EXP_CHAR of UniChar.Char + | EXP_DATA of UniChar.Data + | EXP_STRING of string + type Expected = ExpItem list + type Found = UniChar.Data + + datatype Location = + LOC_NONE + | LOC_AFTER_DTD + | LOC_ATT_DECL + | LOC_ATT_DEFAULT of Position + | LOC_ATT_VALUE + | LOC_CDATA + | LOC_CHOICE + | LOC_COMMENT + | LOC_CONTENT + | LOC_DECL + | LOC_DOC_DECL + | LOC_ELEM_DECL + | LOC_ENCODING + | LOC_ENT_DECL + | LOC_ENT_VALUE + | LOC_EPILOG + | LOC_ETAG + | LOC_IGNORED + | LOC_INCLUDED + | LOC_INT_DECL + | LOC_INT_SUBSET + | LOC_LITERAL + | LOC_MIXED + | LOC_NOT_DECL + | LOC_OUT_COND + | LOC_PROC + | LOC_PROLOG + | LOC_PUB_LIT + | LOC_SEQ + | LOC_STAG + | LOC_SUBSET + | LOC_SYS_LIT + | LOC_TEXT_DECL + | LOC_VERSION + | LOC_XML_DECL + + datatype EntityClass = + ENT_GENERAL + | ENT_PARAMETER + | ENT_EXTERNAL + | ENT_UNPARSED + + datatype Item = + IT_ATT_NAME + | IT_CDATA + | IT_CHAR of UniChar.Char + | IT_CHAR_REF + | IT_COND + | IT_DATA of UniChar.Data + | IT_DECL + | IT_DTD + | IT_ELEM + | IT_ENT_NAME + | IT_ETAG + | IT_GEN_ENT + | IT_ID_NAME + | IT_LANG_ID + | IT_NAME + | IT_NMTOKEN + | IT_NOT_NAME + | IT_NOTATION + | IT_PAR_ENT + | IT_PAR_REF + | IT_REF + | IT_STAG + | IT_TARGET + + datatype Error = + (* syntax errors *) + ERR_EMPTY of Location + | ERR_ENDED_BY_EE of Location + | ERR_EXPECTED of Expected * Found + | ERR_NON_XML_CHAR of UniChar.Char + | ERR_MISSING_WHITE + | ERR_NON_XML_CHARREF of UniChar.Char + | ERR_MUST_CHARREF of UniChar.Char (* for XML 1.1 *) + + (* other well-formedness errors *) + | ERR_CANT_PARSE of Location + | ERR_ELEM_ENT_NESTING of UniChar.Data + | ERR_ELEM_TYPE_MATCH of UniChar.Data * UniChar.Data + | ERR_OMITTED_END_TAG of UniChar.Data + | ERR_IGNORED_END_TAG of UniChar.Data * UniChar.Data + | ERR_ENDED_IN_PROLOG + | ERR_FORBIDDEN_HERE of Item * Location + | ERR_ILLEGAL_ENTITY of EntityClass * UniChar.Data * Location + | ERR_MULTIPLE_DTD + | ERR_MULT_ATT_SPEC of UniChar.Data + | ERR_RECURSIVE_ENTITY of EntityClass * UniChar.Data + | ERR_UNDEC_ENTITY of EntityClass * UniChar.Data + + (* validity errors concerning attributes *) + | ERR_AT_LEAST_ONE of Item + | ERR_AT_MOST_ONE of Item + | ERR_ATT_IS_NOT of UniChar.Data * Item + | ERR_EXACTLY_ONE of Item + | ERR_FIXED_VALUE of UniChar.Data * UniChar.Vector * UniChar.Vector + | ERR_ID_DEFAULT + | ERR_MISSING_ATT of UniChar.Data + | ERR_MULT_ID_ELEM of UniChar.Data + | ERR_MUST_BE_AMONG of Item * UniChar.Data * UniChar.Data list + | ERR_MUST_BE_UNPARSED of UniChar.Data * Location + | ERR_REPEATED_ID of UniChar.Data + | ERR_UNDECL_ATT of UniChar.Data * UniChar.Data + | ERR_UNDECL_ID of UniChar.Data * Position list + + (* validity errors concerning elements *) + | ERR_BAD_ELEM of UniChar.Data * UniChar.Data + | ERR_ELEM_CONTENT of Item + | ERR_EMPTY_TAG of UniChar.Data + | ERR_ENDED_EARLY of UniChar.Data + | ERR_MULT_MIXED of UniChar.Data + | ERR_NONEMPTY of UniChar.Data + | ERR_REDEC_ELEM of UniChar.Data + | ERR_ROOT_ELEM of UniChar.Data * UniChar.Data + + (* other validity errors *) + | ERR_DECL_ENT_NESTING of Location + | ERR_EE_INT_SUBSET + | ERR_GROUP_ENT_NESTING of Location + | ERR_NO_DTD + | ERR_STANDALONE_DEF of UniChar.Data + | ERR_STANDALONE_ELEM of UniChar.Data + | ERR_STANDALONE_ENT of EntityClass *UniChar.Data + | ERR_STANDALONE_NORM of UniChar.Data + | ERR_UNDECLARED of Item * UniChar.Data * Location + + (* miscellaneous errors *) + | ERR_DECL_PREDEF of UniChar.Data * UniChar.Vector + | ERR_NO_SUCH_FILE of string * string + | ERR_RESERVED of UniChar.Data * Item + | ERR_VERSION of string + | ERR_XML_SPACE + + (* compatibility errors *) + | ERR_AMBIGUOUS of UniChar.Data * int * int + | ERR_MUST_ESCAPE of UniChar.Char + + (* interoperability errors *) + | ERR_EMPTY_TAG_INTER of UniChar.Data + | ERR_MUST_BE_EMPTY of UniChar.Data + + (* decoding errors *) + | ERR_DECODE_ERROR of Decode.Error.DecodeError + + datatype Warning = + WARN_NO_XML_DECL + + | WARN_MULT_DECL of Item * UniChar.Data + | WARN_SHOULD_DECLARE of UniChar.Data list + + | WARN_ATT_UNDEC_ELEM of UniChar.Data + | WARN_MULT_ATT_DECL of UniChar.Data + | WARN_MULT_ATT_DEF of UniChar.Data * UniChar.Data + | WARN_ENUM_ATTS of UniChar.Data * UniChar.Data list + + | WARN_DFA_TOO_LARGE of UniChar.Data * int + + | WARN_NON_ASCII_URI of UniChar.Char + end diff --git a/fxp/src/Parser/Error/errorMessage.sml b/fxp/src/Parser/Error/errorMessage.sml new file mode 100644 index 0000000..9e2b5d0 --- /dev/null +++ b/fxp/src/Parser/Error/errorMessage.sml @@ -0,0 +1,209 @@ + + + + + + + + +signature ErrorMessage = + sig + val errorMessage : ErrorData.Error -> string list + val warningMessage : ErrorData.Warning -> string list + end + +structure ErrorMessage : ErrorMessage = + struct + open + Decode + UtilString + ErrorData ErrorString + + val quoteChar0 = quoteErrorChar0 + val quoteChar = quoteErrorChar + val quoteData = quoteErrorData + val quoteString = quoteErrorString + val quoteVector = quoteErrorVector + + fun errorMessage err = + case err + (* syntax errors *) + of ERR_EMPTY loc => ["Empty",Location2String loc] + | ERR_ENDED_BY_EE loc => [toUpperFirst (Location2String loc),"ended by entity end"] + | ERR_EXPECTED (exp,found) => + ["Expected",Expected2String exp,"but found",Found2String found] + | ERR_MISSING_WHITE => ["Missing white space"] + | ERR_NON_XML_CHAR c => ["Non-XML character",quoteChar0 c] + | ERR_NON_XML_CHARREF c => ["Reference to non-XML character",quoteChar0 c] + | ERR_MUST_CHARREF c => ["Control character",quoteChar0 c, + "must appear in XML 1.1 only as character reference"] + + + (* other well-formedness errors *) + | ERR_CANT_PARSE loc => ["Cannot parse",Location2String loc] + | ERR_ELEM_ENT_NESTING elem => + ["The first and last character of element",quoteData elem, + "are in different entities"] + | ERR_ELEM_TYPE_MATCH (elem,other) => + ["Element",quoteData elem,"was ended by an end-tag for",quoteData other] + | ERR_IGNORED_END_TAG(elem,other) => + ["An end-tag for element type",quoteData other,"is not allowed in the", + "content of element",quoteData elem] + | ERR_OMITTED_END_TAG elem => + ["Element",quoteData elem,"has no end-tag"] + | ERR_ENDED_IN_PROLOG => ["Document entity ended in prolog"] + | ERR_FORBIDDEN_HERE(what,loc) => + [AnItem2String what,"is not allowed",InLocation2String loc] + | ERR_ILLEGAL_ENTITY(what,ent,loc) => + ["Reference to",EntityClass2String what,"entity",quoteData ent,InLocation2String loc] + | ERR_MULTIPLE_DTD => ["Repeated document type declaration"] + | ERR_MULT_ATT_SPEC att => + ["A value for attribute",quoteData att,"was already specified in this tag"] + | ERR_RECURSIVE_ENTITY(what,ent) => + ["Reference to",EntityClass2String what,"entity",quoteData ent, + "that is already open"] + | ERR_UNDEC_ENTITY(what,ent) => + ["Reference to undeclared",EntityClass2String what,"entity",quoteData ent] + + (* validity errors concerning attributes *) + | ERR_AT_LEAST_ONE what => ["At least one",Item2String what,"must be specified"] + | ERR_AT_MOST_ONE what => ["Only one",Item2String what,"may be specified"] + | ERR_ATT_IS_NOT(cs,what) => [quoteData cs,"is not",AnItem2String what] + | ERR_EXACTLY_ONE what => [toUpperFirst (AnItem2String what),"must be specified"] + | ERR_FIXED_VALUE(att,value,fixed) => + ["Attribute",quoteData att,"has the value",quoteVector value, + "but was declared with a fixed default value of",quoteVector fixed] + | ERR_ID_DEFAULT => + ["An ID attribute must have a default value of #IMPLIED or #REQUIRED"] + | ERR_MISSING_ATT att => + ["No value was specified for required attribute",quoteData att] + | ERR_MULT_ID_ELEM elem => + ["Element type",quoteData elem,"already has an ID attribute"] + | ERR_MUST_BE_AMONG (what,x,ys) => + [toUpperFirst (Item2String what),quoteData x,"is none of", + List2xString ("",",","") quoteData ys] + | ERR_MUST_BE_UNPARSED (name,loc) => + [quoteData name,InLocation2String loc,"is not the name of an unparsed entity"] + | ERR_REPEATED_ID name => + ["ID name",quoteData name,"already occurred as an attribute value"] + | ERR_UNDECL_ATT(att,elem) => + ["Attribute",quoteData att,"was not declared for element type",quoteData elem] + | ERR_UNDECL_ID(name,refs) => + (if null refs then ["Reference to non-existent ID",quoteData name] + else ["Reference to non-existent ID",quoteData name, + "(also referenced at",List2xString ("",", ",")") Position2String refs]) + + (* validity errors concerning elements *) + | ERR_BAD_ELEM (curr,elem) => + ["Element type",quoteData elem,"not allowed at this point", + "in the content of element",quoteData curr] + | ERR_ELEM_CONTENT what => + [toUpperFirst (AnItem2String what),"is not allowed in element content"] + | ERR_EMPTY_TAG elem => + ["Empty-element tag for element type",quoteData elem, + "whose content model requires non-empty content"] + | ERR_ENDED_EARLY elem => + ["Element",quoteData elem,"ended before its content was completed"] + | ERR_MULT_MIXED elem => + ["Element type",quoteData elem,"already occurred in this mixed-content declaration"] + | ERR_NONEMPTY elem => + ["The end-tag for element",quoteData elem,"with declared EMPTY content", + "must follow immediately after its start-tag"] + | ERR_REDEC_ELEM elem => ["Element type",quoteData elem,"was already declared"] + | ERR_ROOT_ELEM (dec,root) => + ["Document element",quoteData root,"does not match the name", + quoteData dec,"in the document type declaration"] + + (* other validity errors *) + | ERR_DECL_ENT_NESTING loc => + ["The first and last character of this",Location2String loc, + "are not in the same entity replacement text"] + | ERR_EE_INT_SUBSET => + ["An entity end is not allowed in a declaration in the internal subset"] + | ERR_GROUP_ENT_NESTING loc => + ["The opening and closing parentheses of this",Location2String loc, + "are not in the same entity replacement text"] + | ERR_NO_DTD => + ["There is no document type declaration. Switching to semi-validating mode", + "(will not check for declaredness of entities, elements, etc.)"] + | ERR_STANDALONE_DEF att => + ["Externally declared attribute",quoteData att,"was defaulted,", + "although the standalone declaration is",quoteString "yes"] + | ERR_STANDALONE_ELEM elem => + ["White space occurred in the content of externally declared", + "element",quoteData elem,"with declared element content", + "although the standalone declaration is",quoteString "yes"] + | ERR_STANDALONE_ENT(what,ent) => + ["Reference to externally declared",EntityClass2String what,"entity", + quoteData ent^",","although the standalone declaration is",quoteString "yes"] + | ERR_STANDALONE_NORM att => + ["The value for externally declared attribute", + quoteData att,"was changed as a result of normalization,", + "although the standalone declaration is",quoteString "yes"] + | ERR_UNDECLARED (what,x,loc) => + ["Undeclared",Item2String what,quoteData x,InLocation2String loc] + + (* miscellaneous errors *) + | ERR_DECL_PREDEF(ent,def) => + ["General entity",quoteData ent,"must be declared as internal entity", + "with replacement text",quoteVector def] + | ERR_NO_SUCH_FILE(f,msg) => ["Could not open file",quoteString f,"("^msg^")"] + | ERR_RESERVED(name,what) => + [quoteData name,"is reserved for standardization and therefore not allowed as", + AnItem2String what] + | ERR_VERSION version => + ["XML version",quoteString version,"is not supported"] + | ERR_XML_SPACE => + ["Attribute",quoteString "xml:space","must be given an enumeration type", + "whose values are one or both of",quoteString "default","and",quoteString "preserve"] + + (* compatibility errors *) + | ERR_AMBIGUOUS(a,n1,n2) => + ["Content model is ambiguous: conflict between the",numberNth n1, + "and the",numberNth n2,"occurrence of element",quoteData a^".", + "Using an approximation instead"] + | ERR_MUST_ESCAPE c => ["Character",quoteChar c,"must be escaped for compatibility"] + + (* interoperability errors *) + | ERR_EMPTY_TAG_INTER elem => + ["Empty-element tag for element",quoteData elem,"with non-EMPTY declared content"] + | ERR_MUST_BE_EMPTY elem => + ["An empty-element tag must be used for element type", + quoteData elem,"with EMPTY declared content"] + + (* decoding errors *) + | ERR_DECODE_ERROR err => "Decoding error:"::Decode.Error.decodeMessage err + + fun warningMessage warn = + case warn + of WARN_NO_XML_DECL => ["Document entity has no XML declaration"] + + | WARN_MULT_DECL(what,name) => + ["Repeated declaration for",Item2String what,quoteData name] + | WARN_SHOULD_DECLARE(ents) => + let val (one,more) = (hd ents,tl ents) + in case more + of nil => ["The predefined entity",quoteData one,"should have been declared"] + | _ => ["The predefined entities",List2xString ("",", ","") quoteData more, + "and",quoteData one,"should have been declared"] + end + + | WARN_ATT_UNDEC_ELEM elem => + ["Attribute-list declaration for undeclared element type",quoteData elem] + | WARN_MULT_ATT_DECL elem => + ["Repeated attribute-list declaration for element type",quoteData elem] + | WARN_MULT_ATT_DEF(elem,att) => + ["Repeated definition of attribute",quoteData att,"for element type",quoteData elem] + | WARN_ENUM_ATTS(elem,names) => + ["The following name tokens occur more than once in the enumerated attribute", + "types of element",quoteData elem^":",List2xString ("",", ","") quoteData names] + + | WARN_DFA_TOO_LARGE (elem,max) => + ["The finite state machine for the content model of element type", + quoteData elem,"would have more than the maximal allowed number of", + Int2String max,"states. Using an approximation instead"] + + | WARN_NON_ASCII_URI c => + ["System identifier contains non-ASCII character",quoteChar c] + + end diff --git a/fxp/src/Parser/Error/errorString.sml b/fxp/src/Parser/Error/errorString.sml new file mode 100644 index 0000000..2984c46 --- /dev/null +++ b/fxp/src/Parser/Error/errorString.sml @@ -0,0 +1,179 @@ + + + + + + + + + + + + +signature ErrorString = + sig + val errorChar2String : UniChar.Char -> string + val errorData2String : UniChar.Data -> string + val errorVector2String : UniChar.Vector -> string + + val quoteErrorChar0 : UniChar.Char -> string + val quoteErrorChar : UniChar.Char -> string + val quoteErrorData : UniChar.Data -> string + val quoteErrorString : string -> string + val quoteErrorVector : UniChar.Vector -> string + + val Position2String : ErrorData.Position -> string + + val Expected2String : ErrorData.Expected -> string + val Found2String : ErrorData.Found -> string + + val Item2String : ErrorData.Item -> string + val AnItem2String : ErrorData.Item -> string + + val Location2String : ErrorData.Location -> string + val InLocation2String : ErrorData.Location -> string + + val EntityClass2String : ErrorData.EntityClass -> string + end + +structure ErrorString : ErrorString = + struct + open + ErrorData UniChar UtilString + + + fun errorChar2String c = + case c + of 0wx9 => "\\t" + | 0wxA => "\\n" + | _ => if (c>=0wx20 andalso c<0wx7F) orelse (c>0wx9F andalso c<0wx100) then String.implode [Char2char c] + else "U+"^UtilString.toUpperString + (StringCvt.padLeft #"0" 4 (Chars.toString c)) + + fun errorData2String cs = + String.concat (map errorChar2String cs) + fun errorVector2String vec = + errorData2String (Vector.foldr (op ::) nil vec) + + val QUOTE = "'" + fun quoteErrorChar0 c = QUOTE^errorChar2String c^QUOTE + fun quoteErrorChar c = if c=0wx0 then "entity end" else QUOTE^errorChar2String c^QUOTE + fun quoteErrorData cs = QUOTE^errorData2String cs^QUOTE + fun quoteErrorString s = QUOTE^s^QUOTE + fun quoteErrorVector v = QUOTE^errorVector2String v^QUOTE + + fun Position2String (fname,l,c) = + if fname="" then "" + else String.concat ["[",fname,":",Int2String l,".",Int2String c,"]"] + + fun ExpItem2String exp = + case exp + of EXP_CHAR c => quoteErrorChar c + | EXP_DATA cs => quoteErrorData cs + | EXP_STRING s => s + + fun Expected2String exp = + case exp + of nil => "nothing" + | [one] => ExpItem2String one + | _ => let val l=List.length exp + in List2xString ("",", ","") ExpItem2String (List.take (exp,l-1)) + ^" or "^ExpItem2String (List.last exp) + end + fun Found2String fnd = + case fnd + of [0wx0] => "entity end" + | cs => quoteErrorData cs + + fun Location2String loc = + case loc + of LOC_NONE => "nothing" + | LOC_AFTER_DTD => "document instance" + | LOC_ATT_DECL => "attribute list declaration" + | LOC_ATT_DEFAULT pos => "default value declared at "^Position2String pos + | LOC_ATT_VALUE => "attribute value" + | LOC_CDATA => "CDATA section" + | LOC_CHOICE => "choice list" + | LOC_COMMENT => "comment" + | LOC_CONTENT => "content" + | LOC_DECL => "declaration" + | LOC_DOC_DECL => "document type declaration" + | LOC_ELEM_DECL => "element type declaration" + | LOC_ENCODING => "encoding name" + | LOC_ENT_DECL => "entity declaration" + | LOC_ENT_VALUE => "entity value" + | LOC_EPILOG => "epilog" + | LOC_ETAG => "end-tag" + | LOC_IGNORED => "ignored section" + | LOC_INCLUDED => "included section" + | LOC_INT_DECL => "declaration in the internal subset" + | LOC_INT_SUBSET => "internal subset" + | LOC_LITERAL => "literal" + | LOC_MIXED => "Mixed list" + | LOC_NOT_DECL => "notation declaration" + | LOC_OUT_COND => "outside a conditional section" + | LOC_PROLOG => "prolog" + | LOC_PROC => "processing instruction" + | LOC_PUB_LIT => "public identifier" + | LOC_SEQ => "sequence list" + | LOC_STAG => "start-tag" + | LOC_SUBSET => "declaration subset" + | LOC_SYS_LIT => "system identifier" + | LOC_TEXT_DECL => "text declaration" + | LOC_VERSION => "version number" + | LOC_XML_DECL => "XML declaration" + fun InLocation2String loc = + case loc + of LOC_NONE => "" + | LOC_AFTER_DTD => "after the DTD" + | LOC_CONTENT => "in content" + | LOC_ATT_DEFAULT pos => "in default value declared at "^Position2String pos + | LOC_DOC_DECL => "in the document type declaration" + | LOC_EPILOG => "after the root element" + | LOC_INT_SUBSET => "in the internal subset" + | LOC_OUT_COND => "outside a conditional section" + | LOC_PROLOG => "in prolog" + | LOC_SUBSET => "in the declaration subset" + | LOC_XML_DECL => "in the XML declaration" + | _ => "in "^prependAnA (Location2String loc) + + fun EntityClass2String ent = + case ent + of ENT_GENERAL => "general" + | ENT_PARAMETER => "parameter" + | ENT_UNPARSED => "unparsed" + | ENT_EXTERNAL => "external" + + fun Item2String item = + case item + of IT_ATT_NAME => "attribute name" + | IT_CDATA => "CDATA section" + | IT_CHAR c => "character "^quoteErrorChar c + | IT_CHAR_REF => "character reference" + | IT_COND => "conditional section" + | IT_DATA cs => if null cs then "character data" else quoteErrorData cs + | IT_DECL => "declaration" + | IT_DTD => "document type declaration" + | IT_ELEM => "element type" + | IT_ENT_NAME => "entity name" + | IT_ETAG => "end-tag" + | IT_GEN_ENT => "general entity" + | IT_ID_NAME => "ID name" + | IT_LANG_ID => "language identifier" + | IT_NAME => "name" + | IT_NMTOKEN => "name token" + | IT_NOT_NAME => "notation name" + | IT_NOTATION => "notation" + | IT_PAR_ENT => "parameter entity" + | IT_PAR_REF => "parameter entity reference" + | IT_REF => "reference" + | IT_STAG => "start-tag" + | IT_TARGET => "target name" + + fun AnItem2String item = + case item + of IT_CHAR c => Item2String item + | IT_DATA cs => Item2String item + | _ => prependAnA (Item2String item) + end + diff --git a/fxp/src/Parser/Error/errorUtil.sml b/fxp/src/Parser/Error/errorUtil.sml new file mode 100644 index 0000000..af86100 --- /dev/null +++ b/fxp/src/Parser/Error/errorUtil.sml @@ -0,0 +1,85 @@ + + +signature ErrorUtil = + sig + val isFatalError : ErrorData.Error -> bool + val isDecodeError : ErrorData.Error -> bool + val isSyntaxError : ErrorData.Error -> bool + val isValidityError : ErrorData.Error -> bool + val isWellFormedError : ErrorData.Error -> bool + end + +structure ErrorUtil : ErrorUtil = + struct + open ErrorData + + fun isDecodeError err = + case err + of ERR_DECODE_ERROR _ => true + | _ => false + + fun isSyntaxError err = + case err + of ERR_EMPTY _ => true + | ERR_ENDED_BY_EE _ => true + | ERR_EXPECTED _ => true + | ERR_MISSING_WHITE => true + | ERR_NON_XML_CHAR _ => true + | ERR_NON_XML_CHARREF _ => true + | _ => false + + fun isWellFormedError err = + case err + of ERR_CANT_PARSE _ => true + | ERR_ELEM_ENT_NESTING _ => true + | ERR_ELEM_TYPE_MATCH _ => true + | ERR_OMITTED_END_TAG _ => true + | ERR_IGNORED_END_TAG _ => true + | ERR_ENDED_IN_PROLOG => true + | ERR_FORBIDDEN_HERE _ => true + | ERR_ILLEGAL_ENTITY _ => true + | ERR_MULTIPLE_DTD => true + | ERR_MULT_ATT_SPEC _ => true + | ERR_RECURSIVE_ENTITY _ => true + | ERR_UNDEC_ENTITY _ => true + | _ => isSyntaxError err + + fun isFatalError err = + case err + of ERR_NO_SUCH_FILE _ => true + | _ => isWellFormedError err + + fun isValidityError err = + case err + of ERR_AT_LEAST_ONE _ => true + | ERR_AT_MOST_ONE _ => true + | ERR_ATT_IS_NOT _ => true + | ERR_EXACTLY_ONE _ => true + | ERR_FIXED_VALUE _ => true + | ERR_ID_DEFAULT => true + | ERR_MISSING_ATT _ => true + | ERR_MULT_ID_ELEM _ => true + | ERR_MUST_BE_AMONG _ => true + | ERR_MUST_BE_UNPARSED _ => true + | ERR_REPEATED_ID _ => true + | ERR_UNDECL_ATT _ => true + | ERR_UNDECL_ID _ => true + | ERR_BAD_ELEM _ => true + | ERR_ELEM_CONTENT _ => true + | ERR_EMPTY_TAG _ => true + | ERR_ENDED_EARLY _ => true + | ERR_MULT_MIXED _ => true + | ERR_NONEMPTY _ => true + | ERR_REDEC_ELEM _ => true + | ERR_ROOT_ELEM _ => true + | ERR_DECL_ENT_NESTING _ => true + | ERR_EE_INT_SUBSET => true + | ERR_GROUP_ENT_NESTING _ => true + | ERR_NO_DTD => true + | ERR_STANDALONE_DEF _ => true + | ERR_STANDALONE_ELEM _ => true + | ERR_STANDALONE_ENT _ => true + | ERR_STANDALONE_NORM _ => true + | ERR_UNDECLARED _ => true + | _ => false + end diff --git a/fxp/src/Parser/Error/errors.sml b/fxp/src/Parser/Error/errors.sml new file mode 100644 index 0000000..bf66afe --- /dev/null +++ b/fxp/src/Parser/Error/errors.sml @@ -0,0 +1,6 @@ +structure Errors = + struct + open + UtilError + ErrorData ErrorMessage ErrorString ErrorUtil Expected + end diff --git a/fxp/src/Parser/Error/expected.sml b/fxp/src/Parser/Error/expected.sml new file mode 100644 index 0000000..b69ff44 --- /dev/null +++ b/fxp/src/Parser/Error/expected.sml @@ -0,0 +1,70 @@ + + + + +structure Expected = + struct + local + open UniChar ErrorData + in + val expAnElemName = [EXP_STRING "an element name"] + val expAnEntName = [EXP_STRING "an entity name"] + val expAName = [EXP_STRING "a name"] + val expANameToken = [EXP_STRING "a name token"] + val expANotName = [EXP_STRING "a notation name"] + val expATarget = [EXP_STRING "a target name"] + val expAttDefKey = [EXP_DATA (String2Data "REQUIRED"),EXP_DATA (String2Data "IMPLIED"), + EXP_DATA (String2Data "FIXED")] + val expAttNameGt = [EXP_STRING "an attribute name",EXP_CHAR 0wx3E] + val expAttSTagEnd = [EXP_STRING "an attribute name",EXP_CHAR 0wx3E, + EXP_DATA(String2Data "/>")] + val expAttType = [EXP_CHAR 0wx28,EXP_DATA (String2Data "CDATA"), + EXP_DATA (String2Data "ID"),EXP_DATA (String2Data "IDREF"), + EXP_DATA (String2Data "IDREFS"),EXP_DATA (String2Data "ENTITY"), + EXP_DATA (String2Data "ENTITIES"),EXP_DATA (String2Data "NMTOKEN"), + EXP_DATA (String2Data "NMTOKENS"),EXP_DATA (String2Data "NOTATION")] + val expBarRpar = [EXP_CHAR 0wx29,EXP_CHAR 0wx7C] + val expCdata = [EXP_DATA (String2Data "CDATA")] + fun expConCRpar c = [EXP_CHAR 0wx29,EXP_CHAR c] + val expConRpar = [EXP_CHAR 0wx29,EXP_CHAR 0wx2C,EXP_CHAR 0wx7C] + val expCondStatus = [EXP_DATA (String2Data "IGNORE"),EXP_DATA (String2Data "INCLUDE")] + val expContSpec = [EXP_CHAR 0wx28,EXP_DATA (String2Data "ANY"), + EXP_DATA (String2Data "EMPTY")] + val expElemLpar = [EXP_STRING "an element name",EXP_CHAR 0wx28] + val expEncStand = [EXP_DATA (String2Data "encoding"), + EXP_DATA (String2Data "standalone")] + val expDash = [EXP_CHAR 0wx2D] + val expDashDocLbrk = [EXP_CHAR 0wx2D,EXP_CHAR 0wx5B,EXP_DATA (String2Data "DOCTYPE")] + val expDashLbrack = [EXP_CHAR 0wx2D,EXP_CHAR 0wx5B] + val expDigitX = [EXP_STRING "a digit",EXP_CHAR 0wx78] + val expEncoding = [EXP_DATA (String2Data "encoding")] + val expEncVers = [EXP_DATA (String2Data "encoding"),EXP_DATA (String2Data "version")] + val expEntNamePero = [EXP_STRING "an entity name",EXP_CHAR 0wx25] + val expEq = [EXP_CHAR 0wx3D] + val expExclQuest = [EXP_CHAR 0wx21,EXP_CHAR 0wx3F] + val expExtId = [EXP_DATA (String2Data "PUBLIC"),EXP_DATA (String2Data "SYSTEM")] + val expGt = [EXP_CHAR 0wx3E] + val expGtNdata = [EXP_CHAR 0wx3E,EXP_DATA (String2Data "NDATA")] + val expHexDigit = [EXP_STRING "a hexadecimal digit"] + val expInSubset = [EXP_CHAR 0wx3C,EXP_CHAR 0wx5D,EXP_CHAR 0wx25, + EXP_STRING "white space"] + val expLbrack = [EXP_CHAR 0wx5B] + val expLitQuote = [EXP_CHAR 0wx22,EXP_CHAR 0wx27] + val expLitQuotExt = [EXP_CHAR 0wx22,EXP_CHAR 0wx27, + EXP_DATA (String2Data "PUBLIC"),EXP_DATA (String2Data "SYSTEM")] + val expLpar = [EXP_CHAR 0wx28] + val expNoYes = [EXP_DATA (String2Data "no"),EXP_DATA (String2Data "yes")] + val expPcdata = [EXP_DATA (String2Data "PCDATA")] + val expProcEnd = [EXP_DATA (String2Data "?>")] + val expQuoteRni = [EXP_CHAR 0wx22,EXP_CHAR 0wx27,EXP_CHAR 0wx23] + val expRbrack = [EXP_CHAR 0wx5D] + val expRep = [EXP_CHAR 0wx2A] + val expSemi = [EXP_CHAR 0wx3B] + val expStandOpt = [EXP_DATA (String2Data "standalone"),EXP_DATA (String2Data "?>")] + val expStartEnc = [EXP_STRING "a letter"] + val expStartMarkup = [EXP_DATA (String2Data "--"),EXP_DATA (String2Data "ATTLIST"), + EXP_DATA (String2Data "ELEMENT"),EXP_DATA (String2Data "ENTITY"), + EXP_DATA (String2Data "NOTATION")] + val expVersion = [EXP_DATA (String2Data "version")] + end + end diff --git a/fxp/src/Parser/Params/dtd.sml b/fxp/src/Parser/Params/dtd.sml new file mode 100644 index 0000000..fd94dd2 --- /dev/null +++ b/fxp/src/Parser/Params/dtd.sml @@ -0,0 +1,339 @@ +(*--------------------------------------------------------------------------*) +(* Structure: Dtd *) +(* *) +(* Exceptions raised by functions in this structure: *) +(* AttNot2Index : none *) +(* Element2Index : none *) +(* GenEnt2Index : none *) +(* Id2Index : none *) +(* Index2AttNot : NoSuchIndex *) +(* Index2Element : NoSuchIndex *) +(* Index2GenEnt : NoSuchIndex *) +(* Index2Id : NoSuchIndex *) +(* Index2ParEnt : NoSuchIndex *) +(* ParEnt2Index : none *) +(* entitiesWellformed : none *) +(* getElement : NoSuchIndex *) +(* getGenEnt : NoSuchIndex *) +(* getId : NoSuchIndex *) +(* getNotation : NoSuchIndex *) +(* getParEnt : NoSuchIndex *) +(* hasNotation : NoSuchIndex *) +(* initDtdTables : none *) +(* maxUsedElem : none *) +(* maxUsedId : none *) +(* printAttNotTable : none *) +(* printIdTable : none *) +(* printParEntTable : none *) +(* printxElementTable : none *) +(* printxGenEntTable : none *) +(* setElement : NoSuchIndex *) +(* setGenEnt : NoSuchIndex *) +(* setId : NoSuchIndex *) +(* setNotation : NoSuchIndex *) +(* setParEnt : NoSuchIndex *) +(*--------------------------------------------------------------------------*) +signature Dtd = + sig + type Dtd + + val hasDtd : Dtd -> bool + val hasExternal : Dtd -> bool + val standsAlone : Dtd -> bool + + val setHasDtd : Dtd -> unit + val setExternal : Dtd -> unit + val setStandAlone : Dtd -> bool -> unit + + val entitiesWellformed : Dtd -> bool + + val validPredef : int -> UniChar.Vector + val isRedefined : Dtd -> int -> bool + val setRedefined : Dtd -> int -> unit + val notRedefined : Dtd -> UniChar.Data list + + val AttNot2Index : Dtd -> UniChar.Data -> int + val Element2Index : Dtd -> UniChar.Data -> int + val Id2Index : Dtd -> UniChar.Data -> int + val GenEnt2Index : Dtd -> UniChar.Data -> int + val ParEnt2Index : Dtd -> UniChar.Data -> int + + + val hasAttNot : Dtd -> UniChar.Data -> int option + val hasElement : Dtd -> UniChar.Data -> int option + val hasId : Dtd -> UniChar.Data -> int option + val hasGenEnt : Dtd -> UniChar.Data -> int option + val hasParEnt : Dtd -> UniChar.Data -> int option + + val Index2Element : Dtd -> int -> UniChar.Data + val Index2Id : Dtd -> int -> UniChar.Data + val Index2GenEnt : Dtd -> int -> UniChar.Data + val Index2AttNot : Dtd -> int -> UniChar.Data + val Index2ParEnt : Dtd -> int -> UniChar.Data + + val getId : Dtd -> int -> Base.IdInfo + val getElement : Dtd -> int -> Base.ElemInfo + val getGenEnt : Dtd -> int -> Base.GenEntInfo + val getNotation : Dtd -> int -> Base.NotationInfo + val getParEnt : Dtd -> int -> Base.ParEntInfo + + val hasNotation : Dtd -> int -> bool + + val setId : Dtd -> int * Base.IdInfo -> unit + val setElement : Dtd -> int * Base.ElemInfo -> unit + val setGenEnt : Dtd -> int * Base.GenEntInfo -> unit + val setNotation : Dtd -> int * Base.ExternalId -> unit + val setParEnt : Dtd -> int * Base.ParEntInfo -> unit + + val maxUsedId : Dtd -> int + val maxUsedElem : Dtd -> int + val maxUsedGen : Dtd -> int + + val initDtdTables : unit -> Dtd + val printDtdTables : Dtd -> unit + + val printAttNotTable : Dtd -> unit + val printIdTable : Dtd -> unit + val printElementTable : Dtd -> unit + val printGenEntTable : Dtd -> unit + val printParEntTable : Dtd -> unit + + val defaultIdx : int + val preserveIdx : int + val xmlLangIdx : int + val xmlSpaceIdx : int + end + +structure Dtd : Dtd = + struct + open + UtilInt + Base UniChar + DataDict DataSymTab + + val O_TS_ELEM = ref 6 (* Initial size of element table *) + val O_TS_GEN_ENT = ref 6 (* Initial size of general entity table *) + val O_TS_ID = ref 6 (* Initial size of id attribute table *) + val O_TS_ATT_NOT = ref 6 (* Initial size of notation table *) + val O_TS_PAR_ENT = ref 6 (* Initial size of parameter entity table *) + + (*--------------------------------------------------------------------*) + (* this is how the predefined entities must be declared. *) + (*--------------------------------------------------------------------*) + val predefined = Vector.fromList + (map (fn (x,y,z) => (String2Data x,String2Vector y,String2Vector z)) + [("","",""), + ("amp" ,"'&'","&"), + ("lt" ,"'<'","<"), + ("gt" ,"'>'",">"), + ("apos","\"'\"" ,"'" ), + ("quot","'\"'" ,"\"" )]) + fun validPredef i = #3(Vector.sub(predefined,i)) + + (*--------------------------------------------------------------------*) + (* this type holds all information relevent to the DTD. *) + (*--------------------------------------------------------------------*) + type Dtd = {hasDtdFlag : bool ref, + standAloneFlag : bool ref, + externalFlag : bool ref, + elDict : ElemInfo DataDict.Dict, + genDict : GenEntInfo DataDict.Dict, + idDict : IdInfo DataDict.Dict, + notDict : NotationInfo DataDict.Dict, + parDict : ParEntInfo DataDict.Dict, + preRedef : bool array + } + + fun newDtd() = {hasDtdFlag = ref false, + standAloneFlag = ref false, + externalFlag = ref false, + elDict = nullDict ("element",nullElemInfo), + idDict = nullDict ("ID name",nullIdInfo), + genDict = nullDict ("general entity",(GE_NULL,false)), + notDict = nullDict ("attribute and notation",NONE:NotationInfo), + parDict = nullDict ("parameter entity",(PE_NULL,false)), + preRedef = Array.array(6,false) + } : Dtd + + val default = String2Data "default" + val preserve = String2Data "preserve" + val xmlLang = String2Data "xml:lang" + val xmlSpace = String2Data "xml:space" + + (*--------------------------------------------------------------------*) + (* standalone status, existance of a DTD and of external declarations *) + (* externalFlag is true if there is an external subset or a (not nece-*) + (* ssarily external) parameter entity reference in the DTD. (cf. 4.1) *) + (*--------------------------------------------------------------------*) + fun standsAlone (dtd:Dtd) = !(#standAloneFlag dtd) + fun hasExternal (dtd:Dtd) = !(#externalFlag dtd) + fun hasDtd (dtd:Dtd) = !(#hasDtdFlag dtd) + + fun setHasDtd (dtd:Dtd) = #hasDtdFlag dtd := true + fun setExternal (dtd:Dtd) = #externalFlag dtd := true + fun setStandAlone (dtd:Dtd) x = #standAloneFlag dtd := x + + + (*--------------------------------------------------------------------*) + (* 4.1: *) + (* Well-Formedness Constraint: Entity Declared *) + (* In a document without any DTD, a document with only an internal *) + (* DTD subset which contains no parameter entity references, or a *) + (* document with "standalone='yes'", the Name given in the entity *) + (* reference must match that in an entity declaration ... Note that *) + (* if entities are declared in the external subset or in external *) + (* parameter entities, a non-validating processor is not obligated *) + (* to read and process their declarations; for such documents, the *) + (* rule that an entity must be declared is a well-formedness *) + (* constraint only if standalone='yes'. *) + (* *) + (* Thus a reference to an undeclared entity is a well-formedness *) + (* error if either #hasDtdFlag or #externalFlag is false, or if *) + (* #standaloneFlag is true *) + (*--------------------------------------------------------------------*) + (* bug fixed 080600: changed !hasDtdFlag to not(!hasDtdFlag) *) + (*--------------------------------------------------------------------*) + fun entitiesWellformed ({hasDtdFlag,standAloneFlag,externalFlag,...}:Dtd) = + not (!hasDtdFlag andalso !externalFlag) orelse !standAloneFlag + + fun initStandalone ({hasDtdFlag,standAloneFlag,externalFlag,...}:Dtd) = + (hasDtdFlag := false; standAloneFlag := false; externalFlag := false) + + (*--------------------------------------------------------------------*) + (* this array tells whether the predefined entities (index 1-5) have *) + (* been declared in the dtd. *) + (*--------------------------------------------------------------------*) + fun isRedefined (dtd:Dtd) i = Array.sub(#preRedef dtd,i) + fun setRedefined (dtd:Dtd) i = Array.update(#preRedef dtd,i,true) + fun notRedefined dtd = List.mapPartial + (fn i => if isRedefined dtd i then NONE else SOME(#1(Vector.sub(predefined,i)))) + [1,2,3,4,5] + + fun AttNot2Index (dtd:Dtd) name = getIndex(#notDict dtd,name) + fun Element2Index (dtd:Dtd) name = getIndex(#elDict dtd,name) + fun GenEnt2Index (dtd:Dtd) name = getIndex(#genDict dtd,name) + fun Id2Index (dtd:Dtd) name = getIndex(#idDict dtd,name) + fun ParEnt2Index (dtd:Dtd) name = getIndex(#parDict dtd,name) + + fun hasAttNot (dtd:Dtd) name = hasIndex(#notDict dtd,name) + fun hasElement (dtd:Dtd) name = hasIndex(#elDict dtd,name) + fun hasId (dtd:Dtd) name = hasIndex(#idDict dtd,name) + fun hasGenEnt (dtd:Dtd) name = hasIndex(#genDict dtd,name) + fun hasParEnt (dtd:Dtd) name = hasIndex(#parDict dtd,name) + + fun Index2AttNot (dtd:Dtd) idx = getKey(#notDict dtd,idx) + fun Index2Element (dtd:Dtd) idx = getKey(#elDict dtd,idx) + fun Index2GenEnt (dtd:Dtd) idx = getKey(#genDict dtd,idx) + fun Index2Id (dtd:Dtd) idx = getKey(#idDict dtd,idx) + fun Index2ParEnt (dtd:Dtd) idx = getKey(#parDict dtd,idx) + + fun getElement (dtd:Dtd) idx = getByIndex(#elDict dtd,idx) + fun getGenEnt (dtd:Dtd) idx = getByIndex(#genDict dtd,idx) + fun getId (dtd:Dtd) idx = getByIndex(#idDict dtd,idx) + fun getNotation (dtd:Dtd) idx = getByIndex(#notDict dtd,idx) + fun getParEnt (dtd:Dtd) idx = getByIndex(#parDict dtd,idx) + + fun hasNotation (dtd:Dtd) idx = isSome(getByIndex(#notDict dtd,idx)) + + fun setElement (dtd:Dtd) (idx,el) = setByIndex(#elDict dtd,idx,el) + fun setGenEnt (dtd:Dtd) (idx,ge) = setByIndex(#genDict dtd,idx,ge) + fun setId (dtd:Dtd) (idx,a) = setByIndex(#idDict dtd,idx,a) + fun setNotation (dtd:Dtd) (idx,nt) = setByIndex(#notDict dtd,idx,SOME nt) + fun setParEnt (dtd:Dtd) (idx,pe) = setByIndex(#parDict dtd,idx,pe) + + fun maxUsedElem (dtd:Dtd) = usedIndices(#elDict dtd)-1 + fun maxUsedGen (dtd:Dtd) = usedIndices(#genDict dtd)-1 + fun maxUsedId (dtd:Dtd) = usedIndices(#idDict dtd)-1 + + (*--------------------------------------------------------------------*) + (* initialize the attribute tables. Make sure that indices 0...3 are *) + (* assigned to "default", "preserve", "xml:lang" and "xml:space". *) + (*--------------------------------------------------------------------*) + fun initAttNotTable (dtd as {idDict,notDict,...}:Dtd) = + let + val _ = clearDict(notDict,SOME(!O_TS_ATT_NOT)) + val _ = clearDict(idDict,SOME(!O_TS_ID)) + val _ = AttNot2Index dtd default + val _ = AttNot2Index dtd preserve + val _ = AttNot2Index dtd xmlLang + val _ = AttNot2Index dtd xmlSpace + in () + end + fun initElementTable (dtd:Dtd) = clearDict(#elDict dtd,SOME(!O_TS_ELEM)) + (*--------------------------------------------------------------------*) + (* reserve 0 for gen entity -, i.e., the document entity. *) + (* reserve 1 for gen entity amp, i.e., "&#38;" *) + (* reserve 2 for gen entity lt, i.e., "&#60;" *) + (* reserve 3 for gen entity gt, i.e., ">" *) + (* reserve 4 for gen entity apos, i.e., "'" *) + (* reserve 5 for gen entity quot, i.e., """ *) + (* reserve 0 for par entity -, i.e., the external dtd subset. *) + (* *) + (* Cf. 4.1: *) + (* *) + (* ... except that well-formed documents need not declare any of *) + (* the following entities: amp, lt, gt, apos, quot. *) + (* *) + (* and 4.6: *) + (* *) + (* *) + (* *) + (* *) + (* *) + (* *) + (*--------------------------------------------------------------------*) + fun initEntityTables (dtd as {genDict,parDict,preRedef,...}:Dtd) = + let + val _ = clearDict(genDict,SOME(!O_TS_GEN_ENT)) + val _ = clearDict(parDict,SOME(!O_TS_PAR_ENT)) + val _ = map (fn i => Array.update(preRedef,i,false)) [1,2,3,4,5] + val _ = GenEnt2Index dtd [0wx2D] (* "-" *) + val _ = ParEnt2Index dtd [0wx2D] (* "-" *) + val _ = VectorSlice.appi + (fn (_,(name,lit,cs)) + => (setGenEnt dtd (GenEnt2Index dtd name,(GE_INTERN(lit,cs),false)))) + (VectorSlice.slice (predefined,1,NONE)) + in () + end + + fun initDtdTables() = + let + val dtd = newDtd() + val _ = initAttNotTable dtd + val _ = initElementTable dtd + val _ = initEntityTables dtd + val _ = initStandalone dtd + in dtd + end + + local + val dtd = initDtdTables() + in + val defaultIdx = AttNot2Index dtd default + val preserveIdx = AttNot2Index dtd preserve + val xmlLangIdx = AttNot2Index dtd xmlLang + val xmlSpaceIdx = AttNot2Index dtd xmlSpace + end + + fun printAttNotTable (dtd:Dtd) = + printDict NotationInfo2String (#notDict dtd) + fun printElementTable dtd = + printDict (ElemInfo2xString (UniChar.Data2String o (Index2AttNot dtd), + UniChar.Data2String o (Index2Element dtd), + UniChar.Data2String o (Index2GenEnt dtd), + UniChar.Data2String o (Index2Id dtd), + UniChar.Data2String o (Index2AttNot dtd))) (#elDict dtd) + fun printGenEntTable dtd = + printDict (fn (ent,ext) => GenEntity2xString (Data2String o (Index2AttNot dtd)) ent + ^(if ext then "[external]" else "")) (#genDict dtd) + fun printIdTable (dtd:Dtd) = printDict (IdInfo2String) (#idDict dtd) + fun printParEntTable (dtd:Dtd) = + printDict (fn (ent,ext) => ParEntity2String ent + ^(if ext then "[external]" else "")) (#parDict dtd) + + fun printDtdTables dtd = (printAttNotTable dtd; + printElementTable dtd; + printGenEntTable dtd; + printIdTable dtd; + printParEntTable dtd) + end diff --git a/fxp/src/Parser/Params/hookData.sml b/fxp/src/Parser/Params/hookData.sml new file mode 100644 index 0000000..15a77c0 --- /dev/null +++ b/fxp/src/Parser/Params/hookData.sml @@ -0,0 +1,60 @@ +structure HookData = + struct + type StartEnd = Errors.Position * Errors.Position + (*--------------------------------------------------------------------*) + (* a text declaration consists of a version info and an encoding decl.*) + (* an xml declaration has an additional standalone decl. *) + (*--------------------------------------------------------------------*) + type TextDecl = string option * string option + type XmlDecl = string option * string option * bool option + + type XmlInfo = Uri.Uri * Encoding.Encoding * XmlDecl option + type ExtSubsetInfo = Uri.Uri * Encoding.Encoding * TextDecl option + type SubsetInfo = Errors.Position + type EndDtdInfo = Errors.Position + + type ErrorInfo = Errors.Position * Errors.Error + type WarningInfo = Errors.Position * Errors.Warning + type NoFileInfo = string * string + + type CommentInfo = StartEnd * UniChar.Vector + type ProcInstInfo = StartEnd * UniChar.Data * Errors.Position * UniChar.Vector + + type DtdInfo = int * Base.ExternalId option + + datatype AttPresent = + AP_IMPLIED + | AP_MISSING + | AP_DEFAULT of UniChar.Vector * UniChar.Vector * Base.AttValue option + | AP_PRESENT of UniChar.Vector * UniChar.Vector * Base.AttValue option + + type AttSpec = int * AttPresent * (UniChar.Data * UniChar.Data) option + type AttSpecList = AttSpec list + + type EndTagInfo = StartEnd * int * (int * UniChar.Data) option + type StartTagInfo = StartEnd * int * AttSpecList * UniChar.Data * bool + type WhiteInfo = UniChar.Vector + type CDataInfo = StartEnd * UniChar.Vector + type DataInfo = StartEnd * UniChar.Vector * bool + + type CharRefInfo = StartEnd * UniChar.Char * UniChar.Vector + type GenRefInfo = StartEnd * int * Base.GenEntity * bool + type ParRefInfo = StartEnd * int * Base.ParEntity * bool + type EntEndInfo = Errors.Position + + datatype MarkupDecl = + DEC_ATTLIST of int * (int * Base.AttType * Base.AttDefault) list * bool + | DEC_ELEMENT of int * Base.ContentSpec * bool + | DEC_GEN_ENT of int * Base.GenEntity * bool + | DEC_PAR_ENT of int * Base.ParEntity * bool + | DEC_NOTATION of int * Base.ExternalId * bool + type DeclInfo = StartEnd * MarkupDecl + + fun isExtDecl decl = + case decl + of DEC_ATTLIST(_,_,ext) => ext + | DEC_ELEMENT(_,_,ext) => ext + | DEC_GEN_ENT(_,_,ext) => ext + | DEC_PAR_ENT(_,_,ext) => ext + | DEC_NOTATION(_,_,ext) => ext + end diff --git a/fxp/src/Parser/Params/hooks.sml b/fxp/src/Parser/Params/hooks.sml new file mode 100644 index 0000000..8a4137a --- /dev/null +++ b/fxp/src/Parser/Params/hooks.sml @@ -0,0 +1,34 @@ + + + +signature Hooks = + sig + type AppData + type AppFinal + + val hookXml : AppData * HookData.XmlInfo -> AppData + val hookFinish : AppData -> AppFinal + + val hookError : AppData * HookData.ErrorInfo -> AppData + val hookWarning : AppData * HookData.WarningInfo -> AppData + + val hookProcInst : AppData * HookData.ProcInstInfo -> AppData + val hookComment : AppData * HookData.CommentInfo -> AppData + val hookWhite : AppData * HookData.WhiteInfo -> AppData + val hookDecl : AppData * HookData.DeclInfo -> AppData + + val hookStartTag : AppData * HookData.StartTagInfo -> AppData + val hookEndTag : AppData * HookData.EndTagInfo -> AppData + val hookCData : AppData * HookData.CDataInfo -> AppData + val hookData : AppData * HookData.DataInfo -> AppData + + val hookCharRef : AppData * HookData.CharRefInfo -> AppData + val hookGenRef : AppData * HookData.GenRefInfo -> AppData + val hookParRef : AppData * HookData.ParRefInfo -> AppData + val hookEntEnd : AppData * HookData.EntEndInfo -> AppData + + val hookDocType : AppData * HookData.DtdInfo -> AppData + val hookSubset : AppData * HookData.SubsetInfo -> AppData + val hookExtSubset : AppData * HookData.ExtSubsetInfo -> AppData + val hookEndDtd : AppData * HookData.EndDtdInfo -> AppData + end diff --git a/fxp/src/Parser/Params/ignore.sml b/fxp/src/Parser/Params/ignore.sml new file mode 100644 index 0000000..5baa1c4 --- /dev/null +++ b/fxp/src/Parser/Params/ignore.sml @@ -0,0 +1,31 @@ +structure IgnoreHooks = + struct + type AppData = unit + type AppFinal = unit + + fun hookXml(a,_) = a + fun hookFinish a = a + + fun hookError(a,_) = a + fun hookWarning(a,_) = a + + fun hookProcInst(a,_) = a + fun hookComment(a,_) = a + fun hookWhite(a,_) = a + fun hookDecl (a,_) = a + + fun hookStartTag(a,_) = a + fun hookEndTag(a,_) = a + fun hookCData(a,_) = a + fun hookData(a,_) = a + + fun hookCharRef(a,_) = a + fun hookGenRef(a,_) = a + fun hookParRef(a,_) = a + fun hookEntEnd(a,_) = a + + fun hookDocType(a,_) = a + fun hookSubset(a,_) = a + fun hookExtSubset(a,_) = a + fun hookEndDtd(a,_) = a + end diff --git a/fxp/src/Parser/Params/parserOptions.sml b/fxp/src/Parser/Params/parserOptions.sml new file mode 100644 index 0000000..20b1b65 --- /dev/null +++ b/fxp/src/Parser/Params/parserOptions.sml @@ -0,0 +1,294 @@ +(*--------------------------------------------------------------------------*) +(* Structure: ParserOptions *) +(* *) +(* Depends on: none *) +(*--------------------------------------------------------------------------*) +signature ParserOptions = + sig + structure DfaOptions : DfaOptions + + val O_CHECK_ISO639 : bool ref + val O_CHECK_LANGID : bool ref + val O_CHECK_PREDEFINED : bool ref + val O_CHECK_RESERVED : bool ref + val O_CHECK_VERSION : bool ref + + val O_WARN_MULT_ENUM : bool ref + val O_WARN_XML_DECL : bool ref + val O_WARN_ATT_NO_ELEM : bool ref + val O_WARN_MULT_ENT_DECL : bool ref + val O_WARN_MULT_NOT_DECL : bool ref + val O_WARN_MULT_ATT_DEF : bool ref + val O_WARN_MULT_ATT_DECL : bool ref + val O_WARN_SHOULD_DECLARE : bool ref + val O_WARN_NON_ASCII_URI : bool ref + + val O_ERROR_MINIMIZE : bool ref + + val O_VALIDATE : bool ref + val O_COMPATIBILITY : bool ref + val O_INTEROPERABILITY : bool ref + + val O_INCLUDE_EXT_PARSED : bool ref + val O_INCLUDE_PARAM_ENTS : bool ref + + val setParserDefaults : unit -> unit + val setParserOptions : Options.Option list * (string -> unit) -> Options.Option list + + val parserUsage : Options.Usage + end + +functor ParserOptions () : ParserOptions = + struct + structure DfaOptions = DfaOptions () + + open DfaOptions Options UtilInt UtilList + + val O_CHECK_VERSION = ref true (* check for conforming xml version? *) + val O_CHECK_ISO639 = ref true (* check whether a two-letter LangCode *) + (* is acording to ISO 639? *) + val O_CHECK_LANGID = ref true (* check whether a LangCode fullfills *) + (* IETF RFC 1766? *) + val O_CHECK_RESERVED = ref false(* check for names starting with xml? *) + val O_CHECK_PREDEFINED = ref true (* check declarations of predefined *) + val O_WARN_MULT_ENUM = ref true (* check whether a token occurs *) + (* twice in the enumerated attribute *) + (* types of the same element *) + val O_WARN_XML_DECL = ref false (* warn if the XML decl is missing? *) + + val O_WARN_ATT_NO_ELEM = ref true (* warn for undeclared elements *) + (* in att def list declarations? *) + + val O_WARN_MULT_ENT_DECL = ref true (* warn about redefined entities *) + val O_WARN_MULT_NOT_DECL = ref true (* warn about redefined notations*) + val O_WARN_SHOULD_DECLARE = ref true (* warn if predefined entities *) + (* are not declared in the dtd *) + + val O_WARN_MULT_ATT_DEF = ref true (* warn if an attributes is defd *) + (* twice for the same element? *) + val O_WARN_MULT_ATT_DECL = ref true (* warn if there are multiple att *) + (* def lists for one element? *) + val O_WARN_NON_ASCII_URI = ref true (* warn about non-ascii chars in *) + (* system identifiers? *) + + val O_ERROR_MINIMIZE = ref true (* try to avoid repeating errors? *) + + val O_VALIDATE = ref true + val O_COMPATIBILITY = ref true + val O_INTEROPERABILITY = ref false + + val O_INCLUDE_EXT_PARSED = ref false + val O_INCLUDE_PARAM_ENTS = ref false + + fun setParserDefaults() = + let + val _ = setDfaDefaults() + + val _ = O_CHECK_ISO639 := false + val _ = O_CHECK_LANGID := false + val _ = O_CHECK_PREDEFINED := true + val _ = O_CHECK_RESERVED := false + val _ = O_CHECK_VERSION := true + + val _ = O_WARN_MULT_ENUM := true + val _ = O_WARN_XML_DECL := false + val _ = O_WARN_ATT_NO_ELEM := false + val _ = O_WARN_MULT_ENT_DECL := false + val _ = O_WARN_MULT_NOT_DECL := false + val _ = O_WARN_MULT_ATT_DEF := false + val _ = O_WARN_MULT_ATT_DECL := false + val _ = O_WARN_SHOULD_DECLARE := true + val _ = O_WARN_NON_ASCII_URI := true + + val _ = O_VALIDATE := true + val _ = O_COMPATIBILITY := true + val _ = O_INTEROPERABILITY := false + + val _ = O_ERROR_MINIMIZE := true + + val _ = O_INCLUDE_EXT_PARSED := false + val _ = O_INCLUDE_PARAM_ENTS := false + in () + end + + val parserUsage = + [U_ITEM(["-[n]v","--validate[=(yes|no)]"],"Turn on or off validation (yes)"), + U_ITEM(["-[n]c","--compat[=(yes|no)]","--compatibility[=(yes|no)]"], + "Turn on or off compatibility checking (yes)"), + U_ITEM(["-[n]i","--interop[=(yes|no)]","--interoperability[=(yes|no)]"], + "Turn on or off interoperability checking (no)"), + U_SEP, + U_ITEM(["--few-errors[=(yes|no)]"],"Report fewer errors (no)"), + U_ITEM(["--check-reserved[=(yes|no)]"], + "Checking for reserved names (no)"), + U_ITEM(["--check-predef[=(yes|no)]","--check-predefined[=(yes|no)]"], + "Check declaration of predefined entities (yes)"), + U_ITEM(["--check-lang-id[=(yes|no)]"],"Checking language identifiers (no)"), + U_ITEM(["--check-iso639[=(yes|no)]"],"Check ISO 639 language codes (no)"), + U_ITEM(["--check-xml-version[=(yes|no)]"], "Check XML version number (yes)"), + U_SEP, + U_ITEM(["--warn-xml-decl[=(yes|no)]"],"Warn if there is no XML declaration (no)"), + U_ITEM(["--warn-att-elem[=(yes|no)]"], + "Warn about attlist declarations for undeclared elements (no)"), + U_ITEM(["--warn-predefined[=(yes|no)]"], + "Warn if the predefined entities are not declared (no)"), + U_ITEM(["--warn-mult-decl[=]"],"Warn about multiple declarations (none)"), + U_ITEM(["--warn-uri[=(yes|no)]"],"Warn about non-ASCII characters in URIs (yes)"), + U_ITEM(["--warn[=all]"],"Warn about nearly everything"), + U_ITEM(["--warn=none"],"Do not print warnings"), + U_SEP, + U_ITEM(["--include-ext[=(yes|no)]","--include-external[=(yes|no)]"], + "Include external entities in non-validating mode (no)"), + U_ITEM(["--include-par[=(yes|no)]","--include-parameter[=(yes|no)]"], + "Include parameter entities and external subset in "^ + "non-validating mode (no)"), + U_SEP] + @dfaUsage + + fun setParserOptions(opts,doError) = + let + datatype What = ATT | ATTLIST | ENT | NOT + + exception Failed of string option + + fun getNat str = + if str="" then raise Failed NONE + else let val cs = String.explode str + in foldl (fn (c,n) => if #"0">c orelse #"9" raise Failed + (SOME("number "^str^" is too large for this system")) + end + + val allNone = "'all' or 'none'" + val yesNo = "'yes' or 'no'" + val yesNoWhat = "'yes', 'no' or a list of 'att', 'attlist', 'ent' and 'not'" + fun errorMustBe(key,what) = doError + (String.concat ["the argument to option --",key," must be ",what]) + fun errorNoArg key = doError + (String.concat ["option --",key," has no argument"]) + + fun do_mult_decl(key,valOpt) = + let + val all = [ATT,ATTLIST,ENT,NOT] + fun setFlags whats = app (fn (what,flag) => flag := member what whats) + [(ATT,O_WARN_MULT_ATT_DEF),(ATTLIST,O_WARN_MULT_ATT_DECL), + (ENT,O_WARN_MULT_ENT_DECL),(NOT,O_WARN_MULT_NOT_DECL)] + in case valOpt + of NONE => setFlags all + | SOME "yes" => setFlags all + | SOME "no" => setFlags nil + | SOME s => let val fields = String.fields (fn c => #","=c) s + val whats = map + (fn s => case s + of "att" => ATT + | "attlist" => ATTLIST + | "ent" => ENT + | "not" => NOT + | _ => raise Failed NONE) fields + in setFlags whats + end + handle Failed _ => errorMustBe(key,yesNoWhat) + end + + fun do_noarg(key,valOpt,flag) = + case valOpt + of NONE => flag := true + | SOME _ => errorNoArg key + + fun do_yesno(key,valOpt,flag) = + case valOpt + of NONE => flag := true + | SOME "yes" => flag := true + | SOME "no" => flag := false + | SOME s => errorMustBe(key,yesNo) + + fun do_num(key,valOpt,flag) = + case valOpt + of NONE => errorMustBe(key,"a number") + | SOME s => flag := getNat s + handle Failed NONE => errorMustBe(key,"a number") + | Failed (SOME s) => doError s + + fun do_warn(key,valOpt) = + let val all = [O_WARN_MULT_ENUM,O_WARN_ATT_NO_ELEM, + O_WARN_MULT_ENT_DECL,O_WARN_MULT_NOT_DECL,O_WARN_MULT_ATT_DEF, + O_WARN_MULT_ATT_DECL,O_WARN_SHOULD_DECLARE,O_WARN_XML_DECL] + fun setFlags value = app (fn flag => flag := value) all + in case valOpt + of NONE => setFlags true + | SOME "all" => setFlags true + | SOME "none" => setFlags false + | SOME _ => errorMustBe(key,allNone) + end + + fun do_long(key,valOpt) = + case key + of "validate" => true before do_yesno(key,valOpt,O_VALIDATE) + | "compat" => true before do_yesno(key,valOpt,O_COMPATIBILITY) + | "compatibility" => true before do_yesno(key,valOpt,O_COMPATIBILITY) + | "interop" => true before do_yesno(key,valOpt,O_INTEROPERABILITY) + | "interoperability" => true before do_yesno(key,valOpt,O_INTEROPERABILITY) + + | "few-errors" => true before do_yesno(key,valOpt,O_ERROR_MINIMIZE) + + | "check-reserved" => true before do_yesno(key,valOpt,O_CHECK_RESERVED) + | "check-predef" => true before do_yesno(key,valOpt,O_CHECK_PREDEFINED) + | "check-predefined" => true before do_yesno(key,valOpt,O_CHECK_PREDEFINED) + | "check-lang-id" => true before do_yesno(key,valOpt,O_CHECK_LANGID) + | "check-iso639" => true before do_yesno(key,valOpt,O_CHECK_ISO639) + | "check-xml-version" => true before do_yesno(key,valOpt,O_CHECK_VERSION) + + | "warn" => true before do_warn(key,valOpt) + | "warn-xml-decl" => true before do_yesno(key,valOpt,O_WARN_XML_DECL) + | "warn-att-elem" => true before do_yesno(key,valOpt,O_WARN_ATT_NO_ELEM) + | "warn-predefined" => true before do_yesno(key,valOpt,O_WARN_SHOULD_DECLARE) + | "warn-mult-decl" => true before do_mult_decl(key,valOpt) + | "warn-uri" => true before do_yesno(key,valOpt,O_WARN_NON_ASCII_URI) + + | "include-ext" => true before do_yesno(key,valOpt,O_INCLUDE_EXT_PARSED) + | "include-external" => true before do_yesno(key,valOpt,O_INCLUDE_EXT_PARSED) + | "include-par" => true before do_yesno(key,valOpt,O_INCLUDE_PARAM_ENTS) + | "include-parameter" => true before do_yesno(key,valOpt,O_INCLUDE_PARAM_ENTS) + + | _ => false + + fun do_short cs = + let fun doOne c = + case c + of #"v" => false before O_VALIDATE := true + | #"c" => false before O_COMPATIBILITY := true + | #"i" => false before O_INTEROPERABILITY := true + | _ => true + in List.filter doOne cs + end + + fun do_neg cs = + let fun doOne c = + case c + of #"v" => false before O_VALIDATE := false + | #"c" => false before O_COMPATIBILITY := false + | #"i" => false before O_INTEROPERABILITY := false + | _ => true + in List.filter doOne cs + end + + and doit nil = nil + | doit (opt::opts) = + case opt + of OPT_NOOPT => opts + | OPT_LONG(key,value) => if do_long(key,value) then doit opts + else opt::doit opts + | OPT_SHORT cs => (case do_short cs + of nil => doit opts + | rest => OPT_SHORT rest::doit opts) + | OPT_NEG cs => (case do_neg cs + of nil => doit opts + | rest => OPT_NEG rest::doit opts) + | OPT_STRING s => opt::doit opts + + val opts1 = setDfaOptions (opts,doError) + in + doit opts1 + end + end diff --git a/fxp/src/Parser/Params/resolve.sml b/fxp/src/Parser/Params/resolve.sml new file mode 100644 index 0000000..88069eb --- /dev/null +++ b/fxp/src/Parser/Params/resolve.sml @@ -0,0 +1,18 @@ + + + + +signature Resolve = + sig + val resolveExtId : Base.ExternalId -> Uri.Uri + end + +structure ResolveNull : Resolve = + struct + open Base Errors Uri + + fun resolveExtId (EXTID(_,sys)) = + case sys + of NONE => raise NoSuchFile ("","Could not generate system identifier") + | SOME (base,file,_) => uriJoin(base,file) + end diff --git a/fxp/src/Parser/Parse/parseBase.sml b/fxp/src/Parser/Parse/parseBase.sml new file mode 100644 index 0000000..9842bdc --- /dev/null +++ b/fxp/src/Parser/Parse/parseBase.sml @@ -0,0 +1,160 @@ +signature ParseBase = + sig + include Dfa DtdManager Resolve DfaOptions ParserOptions + + exception NoSuchChar of AppData * State + exception NoSuchEntity of AppData * State + exception NotFound of UniChar.Char * AppData * State + exception SyntaxError of UniChar.Char * AppData * State + + val expectedOrEnded : Errors.Expected * Errors.Location -> UniChar.Char -> Errors.Error + + val recoverXml : UniChar.Char * AppData * State -> UniChar.Char * AppData * State + val recoverETag : UniChar.Char * AppData * State -> UniChar.Char * AppData * State + val recoverSTag : UniChar.Char * AppData * State -> bool * (UniChar.Char * AppData * State) + val recoverDecl : bool -> UniChar.Char * AppData * State -> (UniChar.Char * AppData * State) + + val useParamEnts : unit -> bool + end + +(*--------------------------------------------------------------------------*) +(* Structure: ParseBase *) +(*--------------------------------------------------------------------------*) +(* This structure provides exceptions for the Parse functions, and strings *) +(* for error generation (these strings don't really need to reside in their *) +(* own structure, but like this the code is more easier to read). *) +(*--------------------------------------------------------------------------*) +functor ParseBase (structure Dtd : Dtd + structure Hooks : Hooks + structure Resolve : Resolve + structure ParserOptions : ParserOptions) : ParseBase = + struct + structure DfaOptions = ParserOptions.DfaOptions + structure Dfa = Dfa (structure DfaOptions = DfaOptions) + structure DtdManager = DtdManager (structure Dtd = Dtd + structure Hooks = Hooks + structure ParserOptions = ParserOptions) + open + Base DtdManager DfaOptions Dfa Errors ParserOptions Resolve UniChar + + exception NoSuchChar of AppData * State + exception NoSuchEntity of AppData * State + exception NotFound of UniChar.Char * AppData * State + exception SyntaxError of UniChar.Char * AppData * State + + fun expectedOrEnded (exp,ended) c = + if c=0wx00 then ERR_ENDED_BY_EE ended + else ERR_EXPECTED(exp,[c]) + + (*--------------------------------------------------------------------*) + (* Besides "?>" also recognize ">" as end delimiter, because the typo *) + (* might be an omitted "?". Also stop on "<"; then the entire "?>" *) + (* was omitted; the "<" may not be consumed then. *) + (* Within literals dont recognize ">" and "<", but only "?>"; then *) + (* the typo is an omitted quote character. *) + (*--------------------------------------------------------------------*) + fun recoverXml caq = + let + fun do_lit ch (c,a,q) = + case c + of 0wx00 => (c,a,q) + | 0wx3F (* #"?" *) => + let val (c1,a1,q1) = getChar (a,q) + in if c1=0wx3E (* #">" *) then (c1,a1,q1) + else do_lit ch (c1,a1,q1) + end + | _ => if c=ch then (getChar (a,q)) + else do_lit ch (getChar (a,q)) + fun doit (c,a,q) = + case c + of 0wx00 => (c,a,q) + | 0wx22 (* #""""*) => doit (do_lit c (getChar (a,q))) + | 0wx25 (* #"%" *) => (c,a,q) + | 0wx26 (* #"&" *) => (c,a,q) + | 0wx27 (* #"'" *) => doit (do_lit c (getChar (a,q))) + | 0wx3C (* #"<" *) => (c,a,q) + | 0wx3E (* #">" *) => (getChar (a,q)) + | _ => doit (getChar (a,q)) + in + doit caq + end + + fun recoverETag caq = + let + fun do_lit ch (c,a,q) = + case c + of 0wx00 => (c,a,q) + | _ => if c=ch then (getChar (a,q)) + else do_lit ch (getChar (a,q)) + fun doit (c,a,q) = + case c + of 0wx00 => (c,a,q) + | 0wx22 (* #""""*) => doit (do_lit c (getChar (a,q))) + | 0wx26 (* #"&" *) => (c,a,q) + | 0wx27 (* #"'" *) => doit (do_lit c (getChar (a,q))) + | 0wx3E (* #">" *) => (getChar (a,q)) + | 0wx3C (* #"<" *) => (c,a,q) + | _ => doit (getChar (a,q)) + in + doit caq + end + + fun recoverSTag caq = + let + fun do_lit ch (c,a,q) = + case c + of 0wx00 => (c,a,q) + | _ => if c=ch then (getChar (a,q)) + else do_lit ch (getChar (a,q)) + fun doit (c,a,q) = + case c + of 0wx00 => (false,(c,a,q)) + | 0wx22 (* #""""*) => doit (do_lit c (getChar (a,q))) + | 0wx26 (* #"&" *) => (false,(c,a,q)) + | 0wx27 (* #"'" *) => doit (do_lit c (getChar (a,q))) + | 0wx2F (* #"/" *) => let val (c1,a1,q1) = getChar (a,q) + in if c1=0wx3E (* #">" *) then (true,(c1,a1,q1)) + else doit (c1,a1,q1) + end + | 0wx3E (* #">" *) => (false,getChar (a,q)) + | 0wx3C (* #"<" *) => (false,(c,a,q)) + | _ => doit (getChar (a,q)) + in + doit caq + end + + fun recoverDecl hasSubset caq = + let + fun do_lit ch (c,a,q) = + if c=0wx00 then (c,a,q) + else if c=ch then getChar (a,q) + else do_lit ch (getChar(a,q)) + fun do_decl (c,a,q) = + case c + of 0wx00 => (c,a,q) + | 0wx22 (* #"\""*) => do_decl (do_lit c (getChar (a,q))) + | 0wx27 (* #"'" *) => do_decl (do_lit c (getChar (a,q))) + | 0wx3E (* #">" *) => getChar (a,q) + | _ => do_decl (getChar (a,q)) + fun do_subset (c,a,q) = + case c + of 0wx00 => (c,a,q) + | 0wx3C (* #"<" *) => do_subset (do_decl (getChar (a,q))) + | 0wx5D (* #"]" *) => getChar (a,q) + | _ => do_subset (getChar (a,q)) + fun doit (c,a,q) = + case c + of 0wx00 => if isSpecial q then (c,a,q) else doit (getChar (a,q)) + | 0wx22 (* #"\""*) => doit (do_lit c (getChar (a,q))) + | 0wx25 (* #"%" *) => if hasSubset then (c,a,q) else doit (getChar (a,q)) + | 0wx27 (* #"'" *) => doit (do_lit c (getChar (a,q))) + | 0wx3C (* #"<" *) => (c,a,q) + | 0wx3E (* #">" *) => getChar (a,q) + | 0wx5B (* #"[" *) => if hasSubset then doit (do_subset (getChar (a,q))) + else doit (getChar (a,q)) + | _ => doit (getChar (a,q)) + in doit caq + end + + fun useParamEnts() = !O_VALIDATE orelse !O_INCLUDE_PARAM_ENTS + end diff --git a/fxp/src/Parser/Parse/parseContent.sml b/fxp/src/Parser/Parse/parseContent.sml new file mode 100644 index 0000000..e83c07a --- /dev/null +++ b/fxp/src/Parser/Parse/parseContent.sml @@ -0,0 +1,919 @@ +signature ParseContent = + sig + (*---------------------------------------------------------------------- + include ParseBase + + val parseName : UniChar.Char * AppData * State + -> UniChar.Data * (UniChar.Char * AppData * State) + + val openDocument : Uri.Uri option -> AppData + -> Encoding.Encoding * HookData.XmlDecl option * (UniChar.Char * AppData * State) + + val skipCharRef : AppData * State -> (UniChar.Char * AppData * State) + val skipReference : UniChar.Char * AppData * State -> (UniChar.Char * AppData * State) + + val parseComment : Errors.Position -> AppData * State -> (UniChar.Char * AppData * State) + val parseProcInstr : Errors.Position -> AppData * State -> (UniChar.Char * AppData * State) + + val skipTag : Errors.Location -> AppData * State -> (UniChar.Char * AppData * State) + val parseSTag : Dtd -> Errors.Position -> UniChar.Char * AppData * State + -> (HookData.StartTagInfo * Base.ElemInfo) * (UniChar.Char * AppData * State) + + val skipDecl : bool -> UniChar.Char * AppData * State -> UniChar.Char * AppData * State + + val parseDocTypeDecl : Dtd -> (UniChar.Char * AppData * State) + -> int option * (UniChar.Char * AppData * State) + ----------------------------------------------------------------------*) + include ParseDtd + + val skipBadSection : UniChar.Char * AppData * State -> (UniChar.Char * AppData * State) + + val parseElement : Dtd * int list * State * (HookData.StartTagInfo * Base.ElemInfo) + * (UniChar.Char * AppData * State) + -> (int * UniChar.Data * Errors.Position * Errors.Position) option + * (UniChar.Char * AppData * State) + end + +(*--------------------------------------------------------------------------*) +(* Structure: ParseContent *) +(* *) +(* Exceptions raised by functions in this structure: *) +(* skipBadSection : none *) +(* parseElement : none *) +(*--------------------------------------------------------------------------*) +functor ParseContent (structure ParseBase : ParseBase) + : ParseContent = +struct + structure ParseDtd = ParseDtd (structure ParseBase = ParseBase) + + open + Base Errors UniChar UniClasses UtilList + ParseDtd + + val THIS_MODULE = "ParseContent" + val DATA_BUFSIZE = 1024 + val dataBuffer = Array.array(DATA_BUFSIZE,0w0:UniChar.Char) + + (*--------------------------------------------------------------------*) + (* skip a cdata section, the initial "' Char* )) [[ *) + (* [21] CDEnd ::= ']]>' *) + (* *) + (* don't care abeout whether "CDATA[" is present. just skip until the *) + (* next "]]>" or entity end. *) + (* *) + (* return the remaining char and state. *) + (*--------------------------------------------------------------------*) + (* might raise: none *) + (*--------------------------------------------------------------------*) + fun skipBadSection caq = + let(*--------------------------------------------------------------*) + (* for a sequence of "]"s, check whether the last two are *) + (* followed by a ">" *) + (*--------------------------------------------------------------*) + fun checkEnd aq = + let val (c1,a1,q1) = getChar aq + in case c1 + of 0wx3E (* #">" *) => getChar(a1,q1) + | 0wx5D (* #"]" *) => checkEnd(a1,q1) + | _ => doit(c1,a1,q1) + end + and doit (c,a,q) = + case c + of 0wx00 => let val a1 = hookError(a,(getPos q,ERR_ENDED_BY_EE LOC_CDATA)) + in (c,a1,q) + end + | 0wx5D (* #"]" *) => let val (c1,a1,q1) = getChar(a,q) + in if c1=0wx5D (* #"]" *) then checkEnd(a1,q1) + else doit (c1,a1,q1) + end + | _ => doit (getChar(a,q)) + in doit caq + end + + (*--------------------------------------------------------------------*) + (* parse a cdata section, the initial "' Char* )) [[ *) + (* [21] CDEnd ::= ']]>' *) + (* *) + (* print an error and finish if an entity end is found. *) + (* *) + (* return the data as a Vector option and the next char & state. *) + (*--------------------------------------------------------------------*) + (* might raise: none *) + (*--------------------------------------------------------------------*) + fun parseCDataSection' (aq as (_,q)) = + let + (*--------------------------------------------------------------*) + (* for a sequence of "]"s, check whether the last two are *) + (* followed by a ">" *) + (*--------------------------------------------------------------*) + fun doEnd (text,q0,q1) (a2,q2) = + let val (c3,a3,q3) = getChar (a2,q2) + in case c3 + of 0wx00 => + let val a4 = hookError(a3,(getPos q3,ERR_ENDED_BY_EE LOC_CDATA)) + in (0wx5D::text,getPos q2,(c3,a4,q3)) + end + | 0wx3E => (* #">" *) (text,getPos q0,getChar(a3,q3)) + | 0wx5D => doEnd (0wx5D::text,q1,q2) (a3,q3) + | _ => doit (c3::0wx5D::0wx5D::text) (a3,q3) + end + and doBrack (text,q0) (a1,q1) = + let val (c2,a2,q2) = getChar(a1,q1) + in case c2 + of 0wx00 => + let val a3 = hookError(a2,(getPos q2,ERR_ENDED_BY_EE LOC_CDATA)) + in (0wx5D::text,getPos q1,(c2,a3,q2)) + end + | 0wx5D (* #"]" *) => doEnd (text,q0,q1) (a2,q2) + | _ => doit (c2::0wx5D::text) (a2,q2) + end + and doit text (a,q) = + let val (c1,a1,q1) = getChar(a,q) + in case c1 + of 0wx00 => + let val a2 = hookError(a1,(getPos q1,ERR_ENDED_BY_EE LOC_CDATA)) + in (text,getPos q,(c1,a2,q1)) + end + | 0wx5D (* #"]" *) => doBrack (text,q) (a1,q1) + | _ => doit (c1::text) (a1,q1) + end + val (c1,a1,q1) = getChar aq + val startPos = getPos q1 + val (cs,endPos,(c2,a2,q2)) = + case c1 + of 0wx00 => + let val a2 = hookError(a1,(getPos q1,ERR_ENDED_BY_EE LOC_CDATA)) + in (nil,getPos q,(c1,a2,q1)) + end + | 0wx5D (* #"]" *) => doBrack (nil,q) (a1,q1) + | _ => doit [c1] (a1,q1) + val text = Data2Vector(rev cs) + val a3 = hookCData(a1,((startPos,endPos),text)) + in (c2,a3,q2) + end + (*--------------------------------------------------------------------*) + (* parse a cdata section, the initial "' Char* )) [[ *) + (* [21] CDEnd ::= ']]>' *) + (* *) + (* print an error and skip the section if no name or a name other *) + (* than CDATA comes first, or no '[' follows the name. *) + (* *) + (* return the text of the section together with the remaining state. *) + (*--------------------------------------------------------------------*) + (* might raise: none *) + (*--------------------------------------------------------------------*) + fun parseCDataSection startPos aq = + let + val caq0 as (_,_,q0) = (getChar aq) + val (name,(c1,a1,q1)) = parseName caq0 + handle NotFound (c,a,q) => let val err = expectedOrEnded(expCdata,LOC_CDATA) c + in raise SyntaxError(c,hookError(a,(getPos q,err)),q) + end + + val _ = if name = [0wx43,0wx44,0wx41,0wx54,0wx41] (* "CDATA" *) then () + else let val err = ERR_EXPECTED(expCdata,name) + in raise SyntaxError(c1,hookError(a1,(getPos q0,err)),q1) + end + + val _ = if c1=0wx5B (* #"[" *) then () + else let val err = expectedOrEnded(expLbrack,LOC_CDATA) c1 + in raise SyntaxError(c1,hookError(a1,(getPos q1,err)),q1) + end + in + parseCDataSection'(a1,q1) + end + handle SyntaxError caq => skipBadSection caq + + (*--------------------------------------------------------------------*) + (* parse element or empty content. The second arg holds the unique *) + (* number of the element's first characters's entity, the index of *) + (* the current element, and the dfa for its content. Cf. 3: *) + (* *) + (* [39] element ::= EmptyElemTag *) + (* | STag content ETag *) + (* ... *) + (* Well-Formedness Constraint: Element Type Match *) + (* The Name in an element's end-tag must match the element type in *) + (* the start-tag. *) + (* *) + (* Validity Constraint: Element Valid *) + (* An element is valid if there is a declaration matching *) + (* elementdecl where the Name matches the element type, and one of *) + (* the following holds: *) + (* *) + (* 1. The declaration matches EMPTY and the element has no content. *) + (* 2. The declaration matches children and the sequence of child *) + (* elements belongs to the language generated by the regular *) + (* expression in the content model, with optional white space *) + (* (characters matching the nonterminal S) between each pair of *) + (* child elements. *) + (* *) + (* and 3.1: *) + (* *) + (* [43] content ::= (element | CharData | Reference | CDSect | PI *) + (* | Comment)* *) + (* 2.4: *) + (* The ampersand character (&) and the left angle bracket (<) may *) + (* appear in their literal form only when used as markup delimiters,*) + (* or within a comment, a processing instruction, or a CDATA *) + (* section... If they are needed elsewhere, they must be escaped *) + (* using either numeric character references or the strings "&" *) + (* and "<" respectively... *) + (* *) + (* consume the content of the element, accumulating it via the user *) + (* data functions (parameter a in subfunctions). trace the content *) + (* model of the element with a dfa transitions on a dfa state (para- *) + (* meter p in subfunctions). finish at the first end-tag, whether *) + (* matching or not, or at the document end. *) + (* *) + (* handle all syntax and other recoverable errors from subfunctions *) + (* and try to continue. *) + (* *) + (* return the accumulated user data and the next char and state. *) + (*--------------------------------------------------------------------*) + (* might raise: none *) + (*--------------------------------------------------------------------*) + fun parseElementContent dtd (openElems,startEnt,curr,dfa,ext,mt) caq = + let + (*--------------------------------------------------------------*) + (* check whether the dfa allows a transition/an end tag here. *) + (* print an error if not. After a transition return the new *) + (* dfa state. *) + (*--------------------------------------------------------------*) + fun fin_elem (a,pos,dfa,p) = + if dfaFinal(dfa,p) then a + else hookError(a,(pos,ERR_ENDED_EARLY(Index2Element dtd curr))) + fun trans_elem (a,q,dfa,p,el) = + let val p1 = dfaTrans(dfa,p,el) + in if p1<>dfaError then (p1,a) + else let val err = ERR_BAD_ELEM(Index2Element dtd curr,Index2Element dtd el) + in (p1,hookError(a,(getPos q,err))) + end + end + + (*--------------------------------------------------------------*) + (* consume all white space and skip all data until the next "<" *) + (* or "&". print an error for each sequence of data encountered.*) + (* *) + (* add the white space as data to the user data. *) + (* return the next char and state. *) + (*--------------------------------------------------------------*) + fun do_char_elem (c0,a0,q0) = + let + (*--------------------------------------------------------------*) + (* read data characters until the next "<", "&" or entity end. *) + (* add the data to the user data when an error occurs or no *) + (* more data follows. *) + (* *) + (* return the modified user data with the next char and state. *) + (*--------------------------------------------------------------*) + fun data_hook(a,q,cs) = + if null cs then a + else hookData(a,((getPos q0,getPos q),Data2Vector(rev cs),true)) + fun after_error (caq as (c,a,q)) = + case c + of 0wx00 => caq + | 0wx26 (* #"&" *) => caq + | 0wx3C (* #"<" *) => caq + | _ => after_error(getChar(a,q)) + fun do_data (yet,aq as (_,q)) = + let val (c1,a1,q1) = getChar aq + in case c1 + of 0wx00 => (c1,data_hook(a1,q,yet),q1) + | 0wx26 (* #"&" *) => (c1,data_hook(a1,q,yet),q1) + | 0wx3C (* #"<" *) => (c1,data_hook(a1,q,yet),q1) + | _ => + if isS c1 then do_data (c1::yet,(a1,q1)) + else let val a2 = data_hook(a1,q,yet) + val err = ERR_ELEM_CONTENT(IT_DATA nil) + val a3 = hookError(a2,(getPos q1,err)) + in after_error (getChar(a3,q1)) + end + end + in + if isS c0 then + let val a1 = if not (ext andalso standsAlone dtd) then a0 + else let val err = ERR_STANDALONE_ELEM(Index2Element dtd curr) + val _ = setStandAlone dtd (not (!O_ERROR_MINIMIZE)) + in hookError(a0,(getPos q0,err)) + end + in do_data ([c0],(a1,q0)) + end + else let val a1 = hookError(a0,(getPos q0,ERR_ELEM_CONTENT(IT_DATA nil))) + in after_error(getChar(a1,q0)) + end + end + (*--------------------------------------------------------------*) + (* consume a reference, handling errors by ignoring them. *) + (*--------------------------------------------------------------*) + fun do_ref (q,(c1,a1,q1)) = + if c1=0wx23 (* #"#" *) + (*------------------------------------------------------*) + (* it's a character reference. *) + (*------------------------------------------------------*) + then let val err = ERR_ELEM_CONTENT IT_CHAR_REF + val a2 = hookError(a1,(getPos q,err)) + in skipCharRef(a2,q1) + end + (*---------------------------------------------------------*) + (* it's a general entity reference. *) + (*---------------------------------------------------------*) + else let val ((id,ent),(a2,q2)) = parseGenRef dtd (c1,a1,q1) + in case ent + of GE_NULL => + let val a3 = hookGenRef(a2,((getPos q,getPos q2),id,ent,false)) + in (getChar(a3,q2)) + end + | GE_INTERN(_,rep) => + let + val q3 = pushIntern(q2,id,false,rep) + val a3 = hookGenRef(a2,((getPos q,getPos q2),id,ent,true)) + in (getChar(a3,q3)) + end + | GE_EXTERN ext => + if !O_VALIDATE orelse !O_INCLUDE_EXT_PARSED + then + let + val a3 = hookGenRef(a2,((getPos q,getPos q2),id,ent,true)) + val caq4 = #3(openExtern (id,false,resolveExtId ext) (a3,q2)) + handle CantOpenFile(fmsg,a) + => let val err = ERR_NO_SUCH_FILE fmsg + val a2 = hookError(a,(getPos q2,err)) + val a3 = hookEntEnd(a2,getPos q2) + in (getChar(a3,q2)) + end + in caq4 + end + else let val a3 = hookGenRef(a2,((getPos q,getPos q2),id,ent,false)) + in getChar(a3,q2) + end + | GE_UNPARSED _ => + raise InternalError + (THIS_MODULE,"parseElementContent", + "parseGenRef returned GE_UNPARSED") + end + (*-------------------------------------------------------*) + (* handle any errors in references by ignoring them. *) + (*-------------------------------------------------------*) + handle SyntaxError caq => caq + | NoSuchEntity aq => getChar aq + + (*--------------------------------------------------------------*) + (* handle an end-tag. finish the element in the user data and *) + (* return. *) + (* *) + (* print an error if the element's content is not yet finished. *) + (* print an error if the end-tag is for another element. *) + (* print an error if the element's first character was not in *) + (* the same entity. *) + (*--------------------------------------------------------------*) + and do_etag (p,etag as (elem,space,startPos,endPos),(c,a,q)) = + let + fun checkNesting a = + if getEntId q=startEnt then a + else hookError(a,(startPos,ERR_ELEM_ENT_NESTING(Index2Element dtd curr))) + in + if elem=curr then let val a1 = fin_elem (a,startPos,dfa,p) + val a2 = checkNesting a1 + val a3 = hookEndTag + (a2,((startPos,endPos),curr,SOME(elem,space))) + in (NONE,(c,a3,q)) + end + else if member elem openElems + then let val err = ERR_OMITTED_END_TAG(Index2Element dtd curr) + val a1 = hookError(a,(startPos,err)) + val a2 = fin_elem (a1,startPos,dfa,p) + val a3 = hookEndTag(a2,((startPos,endPos),curr,NONE)) + in (SOME etag,(c,a3,q)) + end + else if dfaFinal(dfa,p) + then let val err = ERR_ELEM_TYPE_MATCH(Index2Element dtd curr, + Index2Element dtd elem) + val a1 = hookError(a,(startPos,err)) + val a2 = checkNesting a1 + val a3 = hookEndTag(a2,((startPos,endPos),curr,SOME(elem,space))) + in (NONE,(c,a3,q)) + end + else let val err = ERR_IGNORED_END_TAG(Index2Element dtd curr, + Index2Element dtd elem) + val a1 = hookError(a,(startPos,err)) + in do_elem(p,(c,a1,q)) + end + end + + (*--------------------------------------------------------------*) + (* handle a declaration, proc. instr or tag. *) + (*--------------------------------------------------------------*) + and do_lt (p,q,(c1,a1,q1)) = + case c1 + of 0wx21 (* #"!" *) => + (*------------------------------------------------------*) + (* its a declaration, cdata section or comment. *) + (* Only comments are valid. *) + (*------------------------------------------------------*) + let val (c2,a2,q2) = getChar(a1,q1) + val caq3 = + case c2 + of 0wx2D (* #"-" *) => + let val (c3,a3,q3) = getChar(a2,q2) + in if c3=0wx2D then parseComment (getPos q) (a3,q3) + else let val err = ERR_EXPECTED(expDash,[c3]) + val a4 = hookError(a3,(getPos q3,err)) + in recoverDecl false (c3,a4,q3) + end + end + | 0wx5B (* #"[" *) => + let val a3 = hookError(a2,(getPos q2,ERR_ELEM_CONTENT IT_CDATA)) + in skipBadSection (getChar(a3,q2)) + end + | _ => (c2,hookError(a2,(getPos q2,ERR_EXPECTED(expDash,[c2]))),q2) + in do_elem(p,caq3) + end + | 0wx2F (* #"/" *) => + (let val (elem,space,endPos,caq2) = parseETag dtd (a1,q1) + in do_etag (p,(elem,space,getPos q,endPos),caq2) + end + handle SyntaxError caq => do_elem(p,caq)) + | 0wx3F (* #"?" *) => do_elem (p,parseProcInstr (getPos q) (a1,q1)) + | _ => + (*------------------------------------------------------*) + (* it's a start tag. the recursive call to parseElement *) + (* might return an end-tag that has to be consumed. *) + (*------------------------------------------------------*) + if isNms c1 then + let val (p1,(opt,caq2)) = + (let val (stag as ((_,elem,_,_,_),_),(c2,a2,q2)) = + parseSTag dtd (getPos q) (c1,a1,q1) + val (p1,a3) = trans_elem (a2,q1,dfa,p,elem) + in (p1,parseElement (dtd,curr::openElems,q,stag,(c2,a3,q2))) + end) + handle SyntaxError caq => (p,(NONE,caq)) + in case opt + of NONE => do_elem (p1,caq2) + | SOME etag => do_etag (p1,etag,caq2) + end + else let val err = ERR_FORBIDDEN_HERE(IT_CHAR 0wx3C,LOC_CONTENT) + val a2 = hookError(a1,(getPos q,err)) + in do_elem (p,(c1,a2,q1)) + end + + (*--------------------------------------------------------------*) + (* do element content. handle the document end by printing an *) + (* error and finishing like with an end-tag. *) + (*--------------------------------------------------------------*) + and do_elem (p,(c,a,q)) = + case c + of 0wx00 => if isSpecial q + then let val err = ERR_OMITTED_END_TAG(Index2Element dtd curr) + val a1 = hookError(a,(getPos q,err)) + val pos = getPos q + val a2 = fin_elem (a1,pos,dfa,p) + val a3 = hookEndTag(a2,((pos,pos),curr,NONE)) + in (NONE,(c,a3,q)) + end + else let val a1 = hookEntEnd(a,getPos q) + in do_elem (p,getChar(a1,q)) + end + | 0wx26 (* #"&" *) => do_elem (p,do_ref (q,getChar(a,q))) + | 0wx3C (* #"<" *) => do_lt (p,q,getChar(a,q)) + | _ => do_elem (p,do_char_elem (c,a,q)) + + (*--------------------------------------------------------------*) + (* do empty content. if the first thing to come is the current *) + (* element's end-tag, finish it. Otherwise print an error and *) + (* continue as for element content. *) + (*--------------------------------------------------------------*) + and do_empty (c,a,q) = + if c<>0wx3C (* #"<" *) + then let val a1 = hookError(a,(getPos q,ERR_NONEMPTY(Index2Element dtd curr))) + in do_elem (dfaInitial,(c,a1,q)) + end + else + let val (c1,a1,q1) = getChar(a,q) + in if c1<>0wx2F (* #"/" *) + then let val err = ERR_NONEMPTY(Index2Element dtd curr) + val a2 = hookError(a1,(getPos q,err)) + in do_lt (dfaInitial,q,(c1,a2,q1)) + end + else let val (elem,space,endPos,caq2) = parseETag dtd (a1,q1) + in do_etag (dfaInitial,(elem,space,getPos q,endPos),caq2) + end + handle SyntaxError caq => do_elem (dfaInitial,caq) + end + + in if mt then do_empty caq + else do_elem (dfaInitial,caq) + end + + (*--------------------------------------------------------------------*) + (* parse mixed or any content. The second arg holds the unique number *) + (* of the element's first characters's entity, the idx of the current *) + (* element, and a function for validating child elements. Cf. 3: *) + (* *) + (* [39] element ::= EmptyElemTag *) + (* | STag content ETag *) + (* ... *) + (* Well-Formedness Constraint: Element Type Match *) + (* The Name in an element's end-tag must match the element type in *) + (* the start-tag. *) + (* *) + (* Validity Constraint: Element Valid *) + (* An element is valid if there is a declaration matching *) + (* elementdecl where the Name matches the element type, and one of *) + (* the following holds: *) + (* ... *) + (* 3. The declaration matches Mixed and the content consists of *) + (* character data and child elements whose types match names in *) + (* the content model. *) + (* 4. The declaration matches ANY, and the types of any child *) + (* elements have been declared. *) + (* *) + (* 3.1: *) + (* *) + (* [43] content ::= (element | CharData | Reference | CDSect | PI *) + (* | Comment)* *) + (* 2.4: *) + (* The ampersand character (&) and the left angle bracket (<) may *) + (* appear in their literal form only when used as markup delimiters,*) + (* or within a comment, a processing instruction, or a CDATA *) + (* section... If they are needed elsewhere, they must be escaped *) + (* using either numeric character references or the strings "&" *) + (* and "<" respectively. The right angle bracket (>) may be *) + (* represented using the string ">", and must, for compatibility,*) + (* be escaped using ">" or a character reference when it appears *) + (* in the string "]]>" in content, when that string is not marking *) + (* the end of a CDATA section. *) + (* *) + (* consume the content of the element, accumulating it via the user *) + (* data functions (parameter a in subfunctions). for each child, *) + (* check whether it was specified in the element's Mixed content *) + (* specification (validate). finish at the first end-tag, whether *) + (* matching or not, or at the document end. *) + (* *) + (* handle all syntax and other recoverable errors from subfunctions *) + (* and try to continue. *) + (* *) + (* return the accumulated user data and the next char and state. *) + (*--------------------------------------------------------------------*) + (* might raise: none *) + (*--------------------------------------------------------------------*) + and parseMixedContent dtd (openElems,startEnt,curr,validate) caq = + let + (*--------------------------------------------------------------*) + (* read data characters until the next "<", "&" or entity end. *) + (* add the data to the user data when an error occurs or no *) + (* more data follows. *) + (* *) + (* return the modified user data with the next char and state. *) + (*--------------------------------------------------------------*) + fun do_data (br,(c0,a0,q0)) = + let + val pos0 = ref (getPos q0) + val _ = Array.update(dataBuffer,0,c0) + + fun data_hook (i,(a,q)) = + hookData(a,((!pos0,getPos q), + ArraySlice.vector(ArraySlice.slice(dataBuffer,0,SOME i)), + false)) + fun takeOne (c,qE,i,aq as (a,q)) = + if i (c1,data_hook(i,(a1,q)),q1) + | 0wx26 (* #"&" *) => (c1,data_hook(i,(a1,q)),q1) + | 0wx3C (* #"<" *) => (c1,data_hook(i,(a1,q)),q1) + | 0wx5D (* #"]" *) => do_br (n+1,takeOne(c1,q,i,(a1,q1))) + | 0wx3E (* #">" *) => + let val a2 = if n=1 then a1 + else hookError(a1,(getPos q1,ERR_MUST_ESCAPE c1)) + in doit (takeOne(c1,q,i,(a2,q1))) + end + | _ => doit (takeOne(c1,q,i,(a1,q1))) + end + and doit (i,aq as (_,q)) = + let val (c1,a1,q1) = getChar aq + in case c1 + of 0wx00 => (c1,data_hook(i,(a1,q)),q1) + | 0wx26 (* #"&" *) => (c1,data_hook(i,(a1,q)),q1) + | 0wx3C (* #"<" *) => (c1,data_hook(i,(a1,q)),q1) + | 0wx5D (* #"]" *) => if !O_COMPATIBILITY + then do_br (1,takeOne(c1,q,i,(a1,q1))) + else doit (takeOne(c1,q,i,(a1,q1))) + | _ => doit (takeOne(c1,q,i,(a1,q1))) + end + in + if br then do_br (1,(1,(a0,q0))) + else doit (1,(a0,q0)) + end + (* + fun do_data (br,(c0,a0,q0)) = + let + fun data_hook (yet,(a,q)) = + hookData(a,((getPos q0,getPos q),Data2Vector(rev yet),false)) + fun do_br (n,yet,aq as (_,q)) = + let val (c1,a1,q1) = getChar aq + in case c1 + of 0wx00 => (c1,data_hook(yet,(a1,q)),q1) + | 0wx26 (* #"&" *) => (c1,data_hook(yet,(a1,q)),q1) + | 0wx3C (* #"<" *) => (c1,data_hook(yet,(a1,q)),q1) + | 0wx5D (* #"]" *) => do_br (n+1,c1::yet,(a1,q1)) + | 0wx3E (* #">" *) => + let val a2 = if n=1 then a1 + else hookError(a1,(getPos q1,ERR_MUST_ESCAPE c1)) + in doit (c1::yet,(a2,q1)) + end + | _ => doit (c1::yet,(a1,q1)) + end + and doit (yet,aq as (_,q)) = + let val (c1,a1,q1) = getChar aq + in case c1 + of 0wx00 => (c1,data_hook(yet,(a1,q)),q1) + | 0wx26 (* #"&" *) => (c1,data_hook(yet,(a1,q)),q1) + | 0wx3C (* #"<" *) => (c1,data_hook(yet,(a1,q)),q1) + | 0wx5D (* #"]" *) => if !O_COMPATIBILITY + then do_br (1,c1::yet,(a1,q1)) + else doit (c1::yet,(a1,q1)) + | _ => doit (c1::yet,(a1,q1)) + end + in + if br then do_br (1,[0wx5D],(a0,q0)) + else doit ([c0],(a0,q0)) + end + *) + + (*--------------------------------------------------------------*) + (* consume a reference, handling errors by ignoring them. *) + (*--------------------------------------------------------------*) + fun do_ref (q0,(c,a,q)) = + if c=0wx23 (* #"#" *) + (*------------------------------------------------------*) + (* it's a character reference. *) + (*------------------------------------------------------*) + then let val (cs,(ch,a1,q1)) = parseCharRefLit [0wx23,0wx26] (a,q) + val cv = Data2Vector(rev cs) + val a2 = hookCharRef(a1,((getPos q0,getPos q1),ch,cv)) + in getChar(a2,q1) + end + handle SyntaxError caq => caq + | NoSuchChar aq => getChar aq + (*---------------------------------------------------------*) + (* it's a general entity reference. *) + (*---------------------------------------------------------*) + else let val ((id,ent),(a1,q1)) = parseGenRef dtd (c,a,q) + in case ent + of GE_NULL => + let val a2 = hookGenRef(a1,((getPos q0,getPos q1),id,ent,false)) + in getChar(a2,q1) + end + | GE_INTERN(_,rep) => + let + val q2 = pushIntern(q1,id,false,rep) + val a2 = hookGenRef(a1,((getPos q0,getPos q1),id,ent,true)) + in getChar(a2,q2) + end + | GE_EXTERN ext => + if !O_VALIDATE orelse !O_INCLUDE_EXT_PARSED + then + let + val a2 = hookGenRef(a1,((getPos q0,getPos q1),id,ent,true)) + val caq3 = #3(openExtern (id,false,resolveExtId ext) (a2,q1)) + handle CantOpenFile(fmsg,a) + => let val err = ERR_NO_SUCH_FILE fmsg + val a1 = hookError(a,(getPos q1,err)) + val a2 = hookEntEnd(a1,getPos q1) + in (getChar(a2,q1)) + end + in caq3 + end + else let val a2 = hookGenRef(a1,((getPos q0,getPos q1),id,ent,false)) + in getChar(a2,q1) + end + | GE_UNPARSED _ => + raise InternalError + ("THIS_MODULE","parseMixedContent", + "parseGenRef returned GE_UNPARSED") + end + (*-------------------------------------------------------*) + (* handle any errors in references by ignoring them. *) + (*-------------------------------------------------------*) + handle SyntaxError caq => caq + | NoSuchEntity aq => getChar aq + + (*--------------------------------------------------------------*) + (* handle an end-tag. finish the element in the user data and *) + (* return. *) + (* *) + (* print an error if the element's content is not yet finished. *) + (* print an error if the end-tag is for another element. *) + (* print an error if the element's first character was not in *) + (* the same entity. *) + (*--------------------------------------------------------------*) + and do_etag (etag as (elem,space,startPos,endPos),(c,a,q)) = + let + fun checkNesting a = + if getEntId q=startEnt then a + else hookError(a,(startPos,ERR_ELEM_ENT_NESTING(Index2Element dtd curr))) + in + if elem=curr then let val a1 = checkNesting a + val a2 = hookEndTag + (a1,((startPos,endPos),curr,SOME(elem,space))) + in (NONE,(c,a2,q)) + end + else if member elem openElems + then let val err = ERR_OMITTED_END_TAG(Index2Element dtd curr) + val a1 = hookError(a,(startPos,err)) + val a2 = hookEndTag(a1,((startPos,endPos),curr,NONE)) + in (SOME etag,(c,a2,q)) + end + else let val err = ERR_ELEM_TYPE_MATCH(Index2Element dtd curr, + Index2Element dtd elem) + val a1 = hookError(a,(startPos,err)) + val a2 = checkNesting a1 + val a3 = hookEndTag(a2,((startPos,endPos),curr,SOME(elem,space))) + in (NONE,(c,a3,q)) + end + end + + (*--------------------------------------------------------------*) + (* handle a declaration, proc. instr or tag. If it is an end- *) + (* tag, finish the element in the user data and return. *) + (* *) + (* print an error if the element's content is not yet finished. *) + (* print an error if the end-tag is for another element. *) + (* print an error if the element's first character was not in *) + (* the same entity. *) + (*--------------------------------------------------------------*) + and do_lt (q,(c1,a1,q1)) = + case c1 + of 0wx21 (* #"!" *) => + (*------------------------------------------------------*) + (* its a declaration, cdata section or comment. *) + (* Only comments and cdata sections are valid. *) + (*------------------------------------------------------*) + let val (c2,a2,q2) = getChar(a1,q1) + val caq3 = + case c2 + of 0wx2D (* #"-" *) => + let val (c3,a3,q3) = getChar(a2,q2) + in if c3=0wx2D then parseComment (getPos q) (a3,q3) + else let val err = ERR_EXPECTED(expDash,[c3]) + val a4 = hookError(a3,(getPos q3,err)) + in recoverDecl false (c3,a4,q3) + end + end + | 0wx5B (* #"[" *) => parseCDataSection (getPos q) (a2,q2) + | _ => + (c2,hookError(a2,(getPos q2,ERR_EXPECTED(expDashLbrack,[c2]))),q2) + in do_mixed caq3 + end + | 0wx2F (* #"/" *) => + (let val (elem,space,endPos,caq2) = parseETag dtd (a1,q1) + in do_etag ((elem,space,getPos q,endPos),caq2) + end + handle SyntaxError caq => do_mixed caq) + | 0wx3F (* #"?" *) => do_mixed (parseProcInstr (getPos q) (a1,q1)) + | _ => + (*------------------------------------------------------*) + (* it's a start tag. the recursive call to parseElement *) + (* might return an end-tag that has to be consumed. *) + (*------------------------------------------------------*) + if isNms c1 then + let val (opt,caq2) = + (let val (stag as ((_,elem,_,_,_),_),(c2,a2,q2)) = + parseSTag dtd (getPos q) (c1,a1,q1) + val a3 = validate (a2,q1) elem + in parseElement (dtd,curr::openElems,q,stag,(c2,a3,q2)) + end + handle SyntaxError caq => (NONE,caq)) + in case opt + of NONE => do_mixed caq2 + | SOME etag => do_etag (etag,caq2) + end + else let val err = ERR_FORBIDDEN_HERE(IT_CHAR 0wx3C,LOC_CONTENT) + val a2 = hookError(a1,(getPos q,err)) + in do_mixed (c1,a2,q1) + end + + (*--------------------------------------------------------------*) + (* do mixed content. handle the document end by printing an *) + (* error and finishing like with an end-tag. *) + (*--------------------------------------------------------------*) + and do_mixed (c,a,q) = + case c + of 0wx00 => if isSpecial q + then let val err = ERR_OMITTED_END_TAG(Index2Element dtd curr) + val a1 = hookError(a,(getPos q,err)) + val pos = getPos q + val a2 = hookEndTag(a1,((pos,pos),curr,NONE)) + in (NONE,(c,a2,q)) + end + else let val a1 = hookEntEnd(a,getPos q) + in do_mixed (getChar(a1,q)) + end + | 0wx26 (* #"&" *) => do_mixed (do_ref (q,getChar(a,q))) + | 0wx3C (* #"<" *) => do_lt (q,getChar(a,q)) + | 0wx5D => do_mixed (do_data (!O_COMPATIBILITY,(c,a,q))) + | _ => do_mixed (do_data (false,(c,a,q))) + in + do_mixed caq + end + + (*--------------------------------------------------------------------*) + (* parse an element, the start tag already read. the second arg holds *) + (* the number of the entity of the start-tag's first char, and the *) + (* start-tag information. The 1st arg is the start value for the user *) + (* data. 3: *) + (* *) + (* [39] element ::= EmptyElemTag *) + (* | STag content ETag *) + (* and 3.1: *) + (* *) + (* Empty-element tags may be used for any element which has no *) + (* content, whether or not it is declared using the keyword EMPTY. *) + (* For interoperability, the empty-element tag must be used, and *) + (* can only be used, for elements which are declared EMPTY. *) + (*--------------------------------------------------------------------*) + and parseElement (dtd,openElems,q0,(stag as (_,curr,_,_,mt),elemInfo),(c,a,q)) = + let + (*--------------------------------------------------------------*) + (* validate whether an element is allowed in mixed/any content. *) + (*--------------------------------------------------------------*) + fun trans_any (a,_) _ = a + fun trans_mixed is (a,q) i = + if member i is then a + else let val err = ERR_BAD_ELEM(Index2Element dtd curr,Index2Element dtd i) + in hookError(a,(getPos q,err)) + end + in + (*-----------------------------------------------------------*) + (* For empty-element tags, verify that the element's declar. *) + (* allows empty content. *) + (*-----------------------------------------------------------*) + if mt then + let val a1 = + if not (!O_VALIDATE andalso hasDtd dtd) then a + else + case #decl elemInfo + of (SOME(CT_EMPTY,_)) => a + | (SOME(CT_ELEMENT(_,dfa),_)) => + if not (dfaFinal(dfa,dfaInitial)) + then hookError(a,(getPos q0,ERR_EMPTY_TAG(Index2Element dtd curr))) + else if not (!O_INTEROPERABILITY) then a + else hookError + (a,(getPos q0,ERR_EMPTY_TAG_INTER (Index2Element dtd curr))) + | _ => if not (!O_INTEROPERABILITY) then a + else hookError(a,(getPos q0,ERR_EMPTY_TAG_INTER + (Index2Element dtd curr))) + in (NONE,(c,hookStartTag(a1,stag),q)) + end + (*-----------------------------------------------------------*) + (* for normal start-tags, check whether the element's decl. *) + (* requires an empty-element tag, or empty content, then *) + (* call the appropriate function that parses the content. *) + (*-----------------------------------------------------------*) + else + let val startEnt = getEntId q0 + in if !O_VALIDATE then + case getOpt(#decl elemInfo,(CT_ANY,false)) + of (CT_ANY,_) => parseMixedContent dtd + (openElems,startEnt,curr,trans_any) (c,hookStartTag(a,stag),q) + | (CT_MIXED is,_) => parseMixedContent dtd + (openElems,startEnt,curr,trans_mixed is) (c,hookStartTag(a,stag),q) + | (CT_ELEMENT(_,dfa),ext) => parseElementContent dtd + (openElems,startEnt,curr,dfa,ext,false) + (c,hookStartTag(a,stag),q) + | (CT_EMPTY,_) => + let val a1 = if not (!O_INTEROPERABILITY) then a + else let val err = ERR_MUST_BE_EMPTY(Index2Element dtd curr) + in hookError(a,(getPos q0,err)) + end + val a2 = hookStartTag(a1,stag) + in parseElementContent dtd + (openElems,startEnt,curr,emptyDfa,false,true) (c,a2,q) + end + else parseMixedContent dtd + (openElems,startEnt,curr,trans_any) (c,hookStartTag(a,stag),q) + end + end +end diff --git a/fxp/src/Parser/Parse/parseDecl.sml b/fxp/src/Parser/Parse/parseDecl.sml new file mode 100644 index 0000000..478e9a5 --- /dev/null +++ b/fxp/src/Parser/Parse/parseDecl.sml @@ -0,0 +1,1157 @@ +signature ParseDecl = + sig + (*---------------------------------------------------------------------- + include ParseBase + + val parseName : UniChar.Char * AppData * State + -> UniChar.Data * (UniChar.Char * AppData * State) + + val parseComment : Errors.Position -> AppData * State -> (UniChar.Char * AppData * State) + val parseProcInstr : Errors.Position -> AppData * State -> (UniChar.Char * AppData * State) + val skipS : UniChar.Char * AppData * State -> UniChar.Char * AppData * State + val skipSopt : UniChar.Char * AppData * State -> UniChar.Char * AppData * State + val skipSmay : UniChar.Char * AppData * State -> bool * (UniChar.Char * AppData * State) + + val openExtern : int * Uri.Uri -> AppData * State + -> Encoding.Encoding * HookData.TextDecl option * (UniChar.Char * AppData * State) + val openDocument : Uri.Uri option -> AppData + -> Encoding.Encoding * HookData.XmlDecl option * (UniChar.Char * AppData * State) + val openSubset : Uri.Uri -> AppData + -> Encoding.Encoding * HookData.TextDecl option * (UniChar.Char * AppData * State) + + val skipCharRef : AppData * State -> (UniChar.Char * AppData * State) + val skipReference : UniChar.Char * AppData * State -> (UniChar.Char * AppData * State) + val parseGenRef : Dtd -> UniChar.Char * AppData * State + -> (int * Base.GenEntity) * (AppData * State) + val parseParRef : Dtd -> UniChar.Char * AppData * State + -> (int * Base.ParEntity) * (AppData * State) + val parseCharRefLit : UniChar.Data -> AppData * State + -> UniChar.Data * (UniChar.Char * AppData * State) + val skipPSopt : Dtd -> UniChar.Char * AppData * State + -> UniChar.Char * AppData * State + + val skipTag : Errors.Location -> AppData * State -> (UniChar.Char * AppData * State) + val parseETag : Dtd -> AppData * State + -> int * UniChar.Data * Errors.Position * (UniChar.Char * AppData * State) + val parseSTag : Dtd -> Errors.Position -> UniChar.Char * AppData * State + -> (HookData.StartTagInfo * Base.ElemInfo) * (UniChar.Char * AppData * State) + ----------------------------------------------------------------------*) + include ParseTags + + val skipDecl : bool -> UniChar.Char * AppData * State -> UniChar.Char * AppData * State + + val parseExtIdSub : Dtd -> UniChar.Char * AppData * State + -> Base.ExternalId * bool * (UniChar.Char * AppData * State) + + val parseEntityDecl : Dtd -> EntId * Errors.Position * bool + -> UniChar.Char * AppData * State -> UniChar.Char * AppData * State + val parseElementDecl : Dtd -> EntId * Errors.Position * bool + -> UniChar.Char * AppData * State -> UniChar.Char * AppData * State + val parseNotationDecl : Dtd -> EntId * Errors.Position * bool + -> UniChar.Char * AppData * State -> UniChar.Char * AppData * State + val parseAttListDecl : Dtd -> EntId * Errors.Position * bool + -> UniChar.Char * AppData * State -> UniChar.Char * AppData * State + end + +(*--------------------------------------------------------------------------*) +(* Structure: ParseDecl *) +(* *) +(* Exceptions raised by functions in this structure: *) +(* skipDecl : none *) +(* parseExtIdSub : NotFound SyntaxError *) +(* parseEntityDecl : none *) +(* parseElementDecl : none *) +(* parseNotationDecl : none *) +(* parseAttListDecl : none *) +(*--------------------------------------------------------------------------*) +functor ParseDecl (structure ParseBase : ParseBase) + : ParseDecl = +struct + structure ParseTags = ParseTags (structure ParseBase = ParseBase) + + open + UtilInt UtilList + Base Errors HookData + ParseTags + + (*--------------------------------------------------------------------*) + (* skip a markup declaration, the initial "" if within a literal. yake care of internal subset if *) + (* the first arg is true. *) + (* *) + (* print an error and finish if an entity end is found. *) + (* *) + (* return the remaining char and state. *) + (*--------------------------------------------------------------------*) + (* might raise: none *) + (*--------------------------------------------------------------------*) + fun skipDecl hasSubset caq = + let + fun do_lit ch (c,a,q) = + if c=0wx00 then (c,a,q) + else if c=ch then getChar (a,q) + else do_lit ch (getChar(a,q)) + fun do_decl (c,a,q) = + case c + of 0wx00 => (c,a,q) + | 0wx22 (* #"\""" *) => do_decl (do_lit c (getChar(a,q))) + | 0wx27 (* #"'" *) => do_decl (do_lit c (getChar(a,q))) + | 0wx3E (* #">" *) => getChar(a,q) + | _ => do_decl (getChar(a,q)) + fun do_subset (c,a,q) = + case c + of 0wx00 => (c,a,q) + | 0wx3C (* #"<" *) => do_subset (do_decl (getChar(a,q))) + | 0wx5D (* #"]" *) => getChar(a,q) + | _ => do_subset (getChar(a,q)) + fun doit (c,a,q) = + case c + of 0wx00 => (c,hookError(a,(getPos q,ERR_ENDED_BY_EE LOC_DECL)),q) + | 0wx22 (* #"\"""*) => doit (do_lit c (getChar(a,q))) + | 0wx27 (* #"'" *) => doit (do_lit c (getChar(a,q))) + | 0wx3E (* #">" *) => getChar(a,q) + | 0wx5B (* #"[" *) => if hasSubset then doit (do_subset (getChar(a,q))) + else doit (getChar(a,q)) + | _ => doit (getChar(a,q)) + in doit caq + end + + (*--------------------------------------------------------------------*) + (* parse an external id, or a public id if the first arg is true. *) + (* Cf. 4.2.2 and 4.7: *) + (* *) + (* [75] ExternalID ::= 'SYSTEM' S SystemLiteral *) + (* | 'PUBLIC' S PubidLiteral S SystemLiteral *) + (* *) + (* [83] PublicID ::= 'PUBLIC' S PubidLiteral *) + (* *) + (* raise NotFound if no name is found first. *) + (* print an error if white space is missing. *) + (* print an error and raise SyntaxState if a wrong name is found. *) + (* print an Error and raise SyntaxState if a required literal is not *) + (* found (depends on optSys). *) + (* *) + (* return the public and system identifiers as string options, *) + (* a boolean, whether whit space followed the external id, *) + (* and the next character and the remaining state. *) + (*--------------------------------------------------------------------*) + (* might raise: NotFound SyntaxState *) + (*--------------------------------------------------------------------*) + fun parseExternalId dtd optSys (caq as (_,_,q))= + let + (* do not handle NotFound: in this case no extId was found *) + val (name,caq1) = parseName caq + val caq2 as (_,_,q2)= skipPS dtd caq1 + in + case name + of [0wx50,0wx55,0wx42,0wx4c,0wx49,0wx43] => (* "PUBLIC" *) + let + val (pub,pquote,caq3) = parsePubidLiteral caq2 + handle NotFound (c,a,q) => let val err = ERR_EXPECTED(expLitQuote,[c]) + val a1 = hookError(a,(getPos q,err)) + in raise SyntaxError (c,a1,q) + end + val (hadS,caq4 as (_,_,q4)) = skipPSmay dtd caq3 + in let + val (sys,squote,(c5,a5,q5)) = parseSystemLiteral caq4 + val base = getUri q4 + val a6 = if hadS then a5 else hookError(a5,(getPos q4,ERR_MISSING_WHITE)) + val (hadS6,caq6) = skipPSmay dtd (c5,a6,q5) + in + (EXTID(SOME(pub,pquote),SOME(base,sys,squote)),hadS6,caq6) + end + handle NotFound (c,a,q) => (* no system id *) + if optSys then (EXTID(SOME(pub,pquote),NONE),hadS,(c,a,q)) + else let val a1 = hookError(a,(getPos q,ERR_EXPECTED(expLitQuote,[c]))) + in raise SyntaxError (c,a1,q) + end + end + + | [0wx53,0wx59,0wx53,0wx54,0wx45,0wx4d] => (* "SYSTEM" *) + let + val (sys,squote,caq3) = parseSystemLiteral caq2 + handle NotFound (c,a,q) => let val err = ERR_EXPECTED(expLitQuote,[c]) + val a1 = hookError(a,(getPos q,err)) + in raise SyntaxError (c,a1,q) + end + val base = getUri q2 + val (hadS,caq4) = skipPSmay dtd caq3 + in + (EXTID(NONE,SOME(base,sys,squote)),hadS,caq4) + end + + | _ => let val (c2,a2,q2) = caq2 + val a3 = hookError(a2,(getPos q,ERR_EXPECTED(expExtId,name))) + in raise SyntaxError (c2,a3,q2) + end + end + (*--------------------------------------------------------------------*) + (* parse an external id in an entity definition. Cf. 4.2.2: *) + (* *) + (* print an Error and raise SyntaxState if no external id is found. *) + (*--------------------------------------------------------------------*) + (* might raise: SyntaxState *) + (*--------------------------------------------------------------------*) + fun parseExtIdEnt dtd caq = parseExternalId dtd false caq + handle NotFound (c,a,q) => let val err = ERR_EXPECTED(expLitQuotExt,[c]) + in raise SyntaxError (c,hookError(a,(getPos q,err)),q) + end + (*--------------------------------------------------------------------*) + (* parse an external or public id in a notation declaration. *) + (* *) + (* print an Error and raise SyntaxState if neither external nor *) + (* public id is found. *) + (*--------------------------------------------------------------------*) + (* might raise: SyntaxState *) + (*--------------------------------------------------------------------*) + fun parseExtIdNot dtd caq = parseExternalId dtd true caq + handle NotFound (c,a,q) => let val err = ERR_EXPECTED(expExtId,[c]) + in raise SyntaxError (c,hookError(a,(getPos q,err)),q) + end + (*--------------------------------------------------------------------*) + (* parse an external id for the external subset. *) + (* *) + (* raise NotFound if no external id is found. *) + (*--------------------------------------------------------------------*) + (* might raise: NotFound SyntaxState *) + (*--------------------------------------------------------------------*) + fun parseExtIdSub dtd caq = parseExternalId dtd false caq + + (*--------------------------------------------------------------------*) + (* parse a parameter entity declaration, starting after the '%'. The *) + (* unique entity id of the initial '<' is given as first arg. 4.2: *) + (* *) + (* [72] PEDecl ::= '' *) + (* [74] PEDef ::= EntityValue | ExternalID *) + (* *) + (* (see also the comments for ParseDtd.parseMarkupDecl). *) + (* *) + (* print an error if white space is missing. *) + (* print an error and raise SyntaxState if neither entity value nor *) + (* external identifier is found. *) + (* print an error and raise SyntaxState if the closing '>' is missing.*) + (* print an error if the '>' is not in the same entity as the ' let val err = ERR_EXPECTED(expAnEntName,[c]) + in raise SyntaxError (c,hookError(a,(getPos q,err)),q) + end + val idx = ParEnt2Index dtd name + val caq3 = skipPS dtd caq2 + + val (ent,(c4,a4,q4)) = + let val (ent,caq4) = parseEntityValue dtd PE_INTERN caq3 + val caq5 = skipPSopt dtd caq4 + in (ent,caq5) + end + handle NotFound caq => + let val (extId,_,caq1) = parseExtIdEnt dtd caq + in (PE_EXTERN extId,caq1) + end + + val a5 = if useParamEnts() orelse not ext then addParEnt dtd (a4,q1) (idx,ent,ext) else a4 + val a6 = hookDecl(a5,((startPos,getPos q4),DEC_PAR_ENT(idx,ent,ext))) + in + if c4<>0wx3E (* #">" *) + then let val a7 = hookError(a6,(getPos q4,ERR_EXPECTED(expGt,[c4]))) + in raise SyntaxError(c4,a7,q4) + end + else let val a7 = if not (!O_VALIDATE) orelse getEntId q4=startEnt then a6 + else hookError(a6,(getPos q4,ERR_DECL_ENT_NESTING LOC_ENT_DECL)) + in getChar(a7,q4) + end + end + + (*--------------------------------------------------------------------*) + (* parse a general entity declaration, starting with the name. The *) + (* unique entity id of the initial '<' is given as first arg. 4.2: *) + (* *) + (* [71] GEDecl ::= '' *) + (* [73] EntityDef ::= EntityValue | (ExternalID NDataDecl?) *) + (* *) + (* [76] NDataDecl ::= S 'NDATA' S Name [ VC: Notation *) + (* Declared ] *) + (* *) + (* If the NDataDecl is present, this is a general unparsed entity; *) + (* otherwise it is a parsed entity. *) + (* *) + (* Validity Constraint: Notation Declared *) + (* The Name must match the declared name of a notation. *) + (* *) + (* (see also the comments for ParseDtd.parseMarkupDecl). *) + (* *) + (* print an error if white space is missing. *) + (* print an error and raise SyntaxState if neither entity value nor *) + (* external identifier is found. *) + (* print an error if name other then 'NDATA' is found after ext. id. *) + (* print an error and raise SyntaxState if no name is found after the *) + (* 'NDATA'. *) + (* print an error if the notation is not declared. *) + (* print an error and raise SyntaxState if the closing '>' is missing.*) + (* print an error if the '>' is not in the same entity as the ' let val err = ERR_EXPECTED(expEntNamePero,[c]) + in raise SyntaxError (c,hookError(a,(getPos q,err)),q) + end + val idx = GenEnt2Index dtd name + val caq2 = skipPS dtd caq1 + + val (ent,expEnd,(c3,a3,q3)) = + (*-----------------------------------------------------------*) + (* Try for an internal entity. Then '>' must follow. *) + (*-----------------------------------------------------------*) + let + val (ent,caq3) = parseEntityValue dtd GE_INTERN caq2 + val caq4 = skipPSopt dtd caq3 + in + (ent,expGt,caq4) + end + handle NotFound cq => (* raised by parseEntityValue *) + (*-----------------------------------------------------------*) + (* Must be external. First parse the external identifier. *) + (*-----------------------------------------------------------*) + let + val (extId,hadS,caq1 as (_,_,q1)) = parseExtIdEnt dtd caq2 + in let + (*-----------------------------------------------------*) + (* Does a name follow? Then is must be 'NDATA' and the *) + (* notation name follows. Thus the entity is unparsed. *) + (* Also, only '>' may come next. *) + (* NotFound is handled at the end of the let. *) + (*-----------------------------------------------------*) + val (key,(c2,a2,q2)) = parseName caq1 + val a3 = if hadS then a2 else hookError(a2,(getPos q1,ERR_MISSING_WHITE)) + val a4 = if key = [0wx4e,0wx44,0wx41,0wx54,0wx41] (* "NDATA" *) then a3 + else hookError(a3,(getPos q1,ERR_EXPECTED(expGtNdata,key))) + + val caq5 as (_,_,q5) = skipPS dtd (c2,a4,q2) + + val (not,caq6) = parseName caq5 + handle NotFound (c,a,q) => let val err = ERR_EXPECTED(expANotName,[c]) + val a1 = hookError(a,(getPos q,err)) + in raise SyntaxError (c,a1,q) + end + val notIdx = AttNot2Index dtd not + val caq7 = skipPSopt dtd caq6 + in + (GE_UNPARSED(extId,notIdx,getPos q5),expGt,caq7) + end + handle NotFound caq => + (*--------------------------------------------------------*) + (* No 'NDATA' present, so it's parsed external entity. *) + (* A 'NDATA' might have followed. *) + (*--------------------------------------------------------*) + (GE_EXTERN extId,expGtNdata,caq) + end + + val a4 = if useParamEnts() orelse not ext then addGenEnt dtd (a3,q) (idx,ent,ext) else a3 + val a5 = hookDecl(a4,((startPos,getPos q3),DEC_GEN_ENT(idx,ent,ext))) + in + if c3<>0wx3E (* #">" *) + then let val a6 = hookError(a5,(getPos q3,ERR_EXPECTED(expGt,[c3]))) + in raise SyntaxError(c3,a6,q3) + end + else let val a6 = if not (!O_VALIDATE) orelse getEntId q3=startEnt then a5 + else hookError(a5,(getPos q3,ERR_DECL_ENT_NESTING LOC_ENT_DECL)) + in getChar(a6,q3) + end + end + + (*--------------------------------------------------------------------*) + (* parse an entity declaration, the initial '' *) + (* [72] PEDecl ::= '' *) + (* *) + (* (see also the comments for ParseDtd.parseMarkupDecl). *) + (* *) + (* raise SyntaxState in case of a syntax error. *) + (* print an error if white space is missing. *) + (* *) + (* print an error for entity end exceptions in subfunctions. *) + (* catch syntax errors by recovering to the next possible state. *) + (* *) + (* pass control to parseParEntDecl or parseGenEntDecl, depending on *) + (* whether the S is followed by a '%'. *) + (* return the remaining char and state. *) + (*--------------------------------------------------------------------*) + (* might raise: none *) + (*--------------------------------------------------------------------*) + fun parseEntityDecl dtd pars caq = + let + val (hadPero,caq1) = skipPSdec dtd caq + in + if hadPero then parseParEntDecl dtd pars caq1 + else parseGenEntDecl dtd pars caq1 + end + handle exn as SyntaxError (c,a,q) => + let val a1 = if c=0wx00 then hookError(a,(getPos q,ERR_ENDED_BY_EE LOC_ENT_DECL)) + else a + in recoverDecl false (c,a1,q) + end + + (*--------------------------------------------------------------------*) + (* parse a notation declaration, the initial '' *) + (* *) + (* (see also the comments for ParseDtd.parseMarkupDecl). *) + (* *) + (* print an error and raise SyntaxState if no notation name, no *) + (* external/public identifier or no final '>' is found. *) + (* print an error if the '>' is not in the same entity as the ' let val err = ERR_EXPECTED(expANotName,[c]) + in raise SyntaxError (c,hookError(a,(getPos q,err)),q) + end + val idx = AttNot2Index dtd name + val caq3 = skipPS dtd caq2 + + val (extId,_,(c4,a4,q4)) = parseExtIdNot dtd caq3 + + val a5 = if useParamEnts() orelse not ext then addNotation dtd (a4,q1) (idx,extId) else a4 + val a6 = hookDecl(a5,((startPos,getPos q4),DEC_NOTATION(idx,extId,ext))) + in + if c4<>0wx3E (* #">" *) + then let val a7 = hookError(a6,(getPos q4,ERR_EXPECTED(expGt,[c4]))) + in raise SyntaxError (c4,a7,q4) + end + else let val a7 = if not (!O_VALIDATE) orelse getEntId q4=startEnt then a6 + else hookError(a6,(getPos q4,ERR_DECL_ENT_NESTING LOC_NOT_DECL)) + in getChar(a7,q4) + end + end + handle exn as SyntaxError(c,a,q) => + let val a1 = if c=0wx00 then hookError(a,(getPos q,ERR_ENDED_BY_EE LOC_NOT_DECL)) + else a + in recoverDecl false (c,a1,q) + end + + (*--------------------------------------------------------------------*) + (* parse a mixed-content specification, the initial '(', S? and '#' *) + (* already read. The unique id of the openening paren's entity is *) + (* given as first arg. Cf. 3.2.1/2: *) + (* *) + (* Validity Constraint: Proper Group/PE Nesting *) + (* Parameter-entity replacement text must be properly nested with *) + (* parenthetized groups. That is to say, if either of the opening *) + (* or closing parentheses in a choice, seq, or Mixed construct is *) + (* contained in the replacement text for a parameter entity, both *) + (* must be contained in the same replacement text. *) + (* ... *) + (* [51] Mixed ::= '(' S? '#PCDATA' [ VC: Proper Group/PE *) + (* (S? '|' S? Name)* S? ')*' Nesting ] *) + (* | '(' S? '#PCDATA' S? ')' [ VC: No Duplicate *) + (* Types ] *) + (* *) + (* print an error and raise SyntaxState if no name is found first. *) + (* print an error if a name other than 'PCDATA' is found. *) + (* is found in the first place. *) + (* print an error if element names are specified but no '*' follows. *) + (* print an error if an element name is specified more than once. *) + (* print an error and raise SyntaxState if neither '|' nor ')' is *) + (* found after the 'PCDATA' or after an element name. *) + (* print an error if the closing parenthesis is not in the same *) + (* as the opening one. *) + (* *) + (* return the mixed-content specification, togther with the next *) + (* character and state. *) + (*--------------------------------------------------------------------*) + (* might raise: SyntaxState *) + (*--------------------------------------------------------------------*) + fun parseMixed dtd lparEnt (caq as (_,_,q)) = + let + fun doit is (c,a,q) = + case c + of 0wx29 (* #")" *) => + let val a1 = if not (!O_VALIDATE) orelse getEntId q=lparEnt then a + else hookError(a,(getPos q,ERR_GROUP_ENT_NESTING LOC_MIXED)) + in (rev is,getChar(a1,q)) + end + | 0wx7C (* #"|" *) => + let + val caq1 as (_,_,q1) = skipPSopt dtd (getChar(a,q)) + + val (name,(c2,a2,q2)) = parseName caq1 + handle NotFound (c,a,q) => let val err = ERR_EXPECTED(expAName,[c]) + val a1 = hookError(a,(getPos q,err)) + in raise SyntaxError (c,a1,q) + end + val i = Element2Index dtd name + val (newis,a3) = + if not (member i is) then (i::is,a2) + else let val a3 = if !O_VALIDATE + then hookError(a2,(getPos q1,ERR_MULT_MIXED name)) + else a2 + in (is,a3) + end + val caq3 = skipPSopt dtd (c2,a3,q2) + in doit newis caq3 + end + | _ => let val a1 = hookError(a,(getPos q,ERR_EXPECTED(expBarRpar,[c]))) + in raise SyntaxError (c,a1,q) + end + + val (name,(c1,a1,q1)) = parseName caq + handle NotFound (c,a,q) => let val err = ERR_EXPECTED(expPcdata,[c]) + in raise SyntaxError (c,hookError(a,(getPos q,err)),q) + end + val a2 = case name + of [0wx50,0wx43,0wx44,0wx41,0wx54,0wx41] (* "PCDATA" *) => a1 + | _ => hookError(a1,(getPos q,ERR_EXPECTED(expPcdata,name))) + + val caq2 = skipPSopt dtd (c1,a2,q1) + val (is,(c3,a3,q3)) = doit nil caq2 + + val caq4 = if c3=0wx2A (* #"*" *) then getChar(a3,q3) + else let val a4 = if null is then a3 + else hookError(a3,(getPos q3,ERR_EXPECTED(expRep,[c3]))) + in (c3,a4,q3) + end + in + (CT_MIXED is,caq4) + end + + (*--------------------------------------------------------------------*) + (* parse an optional occurrence indicator afer a content particle or *) + (* a content model, given as first argument. Cf. 3.2.1: *) + (* *) + (* [47] children ::= (choice | seq) ('?' | '*' | '+')? *) + (* [48] cp ::= (Name | choice | seq) ('?' | '*' | '+')? *) + (* *) + (* return the (possibly modified) content particle, together with the *) + (* next char and state. *) + (*--------------------------------------------------------------------*) + (* might raise: none *) + (*--------------------------------------------------------------------*) + fun parseOcc cm (c,a,q) = + case c + of 0wx3F (* #"?" *) => (CM_OPT cm,getChar(a,q)) + | 0wx2A (* #"*" *) => (CM_REP cm,getChar(a,q)) + | 0wx2B (* #"+" *) => (CM_PLUS cm,getChar(a,q)) + | _ => (cm,(c,a,q)) + + (*--------------------------------------------------------------------*) + (* parse a content particle. Cf. 3.2.1: *) + (* *) + (* Validity Constraint: Proper Group/PE Nesting *) + (* Parameter-entity replacement text must be properly nested with *) + (* parenthetized groups. ... *) + (* *) + (* (see also parseMixed) *) + (* *) + (* [48] cp ::= (Name | choice | seq) ('?' | '*' | '+')? *) + (* [49] choice ::= '(' S? cp [ VC: Proper Group/ *) + (* ( S? '|' S? cp )* S? ')' PE Nesting ] *) + (* [50] seq ::= '(' S? cp [ VC: Proper Group/ *) + (* ( S? ',' S? cp )* S? ')' PE Nesting ] *) + (* *) + (* print an error and raise SyntaxState if no element name or "(" is *) + (* found in the first place. *) + (* *) + (* return the content particle together with the next char and state. *) + (*--------------------------------------------------------------------*) + (* might raise: SyntaxState *) + (*--------------------------------------------------------------------*) + fun parseCP dtd (c,a,q) = + case c + of 0wx28 (* #"(" *) => + let + val lparEnt = getEntId q + val caq1 = skipPSopt dtd (getChar (a,q)) + in parseGroup dtd lparEnt caq1 + end + | _ => (* must be an element name *) + let + val (name,caq1) = parseName (c,a,q) + handle NotFound (c,a,q) => let val err = ERR_EXPECTED(expElemLpar,[c]) + val a1 = hookError(a,(getPos q,err)) + in raise SyntaxError (c,a1,q) + end + val idx = Element2Index dtd name + in + parseOcc (CM_ELEM idx) caq1 + end + + (*--------------------------------------------------------------------*) + (* parse a seq/choice, the first content particle and the connector *) + (* already parsed; the connector, the type of group and the entity id *) + (* of the opening parenthesis are given in first arg. Cf. 3.2.1: *) + (* *) + (* Validity Constraint: Proper Group/PE Nesting *) + (* Parameter-entity replacement text must be properly nested with *) + (* parenthetized groups. ... *) + (* *) + (* (see also parseMixed) *) + (* *) + (* [49] choice ::= '(' S? cp [ VC: Proper Group/ *) + (* ( S? '|' S? cp )* S? ')' PE Nesting ] *) + (* [50] seq ::= '(' S? cp [ VC: Proper Group/ *) + (* ( S? ',' S? cp )* S? ')' PE Nesting ] *) + (* *) + (* print an error and raise SyntaxState if something other than the *) + (* connector or ')' is found after a content particle. *) + (* print an error if the closing parenthesis of a group is not in the *) + (* same entity as the opening one. *) + (* *) + (* return the list of content particles parsed, together with the *) + (* remaining character and state. *) + (*--------------------------------------------------------------------*) + (* might raise: SyntaxState *) + (*--------------------------------------------------------------------*) + and parseGroup' dtd (con,loc,lparEnt) caq = + let fun doit caq = + let + val caq1 = skipPSopt dtd caq + val (cp,caq2) = parseCP dtd caq1 + val (c3,a3,q3) = skipPSopt dtd caq2 + in + if c3=0wx29 (* #")" ( *) + then let val a4 = if not (!O_VALIDATE) orelse getEntId q3=lparEnt then a3 + else hookError(a3,(getPos q3,ERR_GROUP_ENT_NESTING loc)) + in ([cp],getChar(a4,q3)) + end + else (if c3=con then let val (cps,caq4) = doit (getChar(a3,q3)) + in (cp::cps,caq4) + end + else let val err = ERR_EXPECTED(expConCRpar con,[c3]) + in raise SyntaxError (c3,hookError(a3,(getPos q3,err)),q3) + end) + end + in + doit caq + end + + (*--------------------------------------------------------------------*) + (* parse a seq/choice, the first content particle parsed; the entity *) + (* id of the opening parenthesis are given in first arg. Cf. 3.2.1: *) + (* *) + (* (see also parseMixed) *) + (* *) + (* [49] choice ::= '(' S? cp [ VC: Proper Group/ *) + (* ( S? '|' S? cp )* S? ')' PE Nesting ] *) + (* [50] seq ::= '(' S? cp [ VC: Proper Group/ *) + (* ( S? ',' S? cp )* S? ')' PE Nesting ] *) + (* *) + (* print an error and raise SyntaxState if neither '|' nor ',' nor *) + (* ')' follows the first content particle in a seq/choice. *) + (* *) + (* return the list of as a ContentModel, together with the remaining *) + (* character and state. *) + (*--------------------------------------------------------------------*) + (* might raise: SyntaxState *) + (*--------------------------------------------------------------------*) + and parseGroup dtd lparEnt caq = + let + val (cp,caq1) = parseCP dtd caq + val (c2,a2,q2) = skipPSopt dtd caq1 + val (group,caq3) = + case c2 + of 0wx29 (* #")" *) => + let val a3 = if not (!O_VALIDATE) orelse getEntId q2=lparEnt then a2 + else hookError(a2,(getPos q2,ERR_GROUP_ENT_NESTING LOC_SEQ)) + in (CM_SEQ[cp],getChar(a3,q2)) + end + | 0wx2C (* #"," *) => + let val (cps,caq3) = parseGroup' dtd (c2,LOC_SEQ,lparEnt) (getChar(a2,q2)) + in (CM_SEQ(cp::cps),caq3) + end + | 0wx7C (* #"|" *) => + let val (cps,caq3) = parseGroup' dtd (c2,LOC_CHOICE,lparEnt) (getChar(a2,q2)) + in (CM_ALT(cp::cps),caq3) + end + | _ => let val a3 = hookError(a2,(getPos q2,ERR_EXPECTED(expConRpar,[c2]))) + in raise SyntaxError (c2,a3,q2) + end + in parseOcc group caq3 + end + + (*--------------------------------------------------------------------*) + (* parse a content specification. Cf. 3.2/3.2.1: *) + (* *) + (* Validity Constraint: Proper Group/PE Nesting *) + (* Parameter-entity replacement text must be properly nested with *) + (* parenthetized groups. That is to say, if either of the opening *) + (* or closing parentheses in a choice, seq, or Mixed construct is *) + (* contained in the replacement text for a parameter entity, both *) + (* must be contained in the same replacement text. *) + (* ... *) + (* [46] contentspec ::= 'EMPTY' | 'ANY' | Mixed | children *) + (* *) + (* [47] children ::= (choice | seq) ('?' | '*' | '+')? *) + (* *) + (* [49] choice ::= '(' S? cp ( S? '|' S? cp )* S? ')' [ VC:Proper *) + (* [50] seq ::= '(' S? cp ( S? ',' S? cp )* S? ')' Group/PE *) + (* Nesting ]*) + (* *) + (* [51] Mixed ::= '(' S? '#PCDATA' [ VC: Proper Group/PE *) + (* (S? '|' S? Name)* S? ')*' Nesting ] *) + (* | '(' S? '#PCDATA' S? ')' [ VC: No Duplicate *) + (* Types ] *) + (* *) + (* print an error and raise SyntaxState if no children, Mixed, or *) + (* name is found. *) + (* print an error and assume ANY if an ambiguous content model is *) + (* specified. *) + (* print an error and assume ANY if a name other than EMPTY or ANY *) + (* is found. *) + (* print an error if the closing parenthesis of a Mixed is not in the *) + (* same entity as the opening one. *) + (* *) + (* return the parsed content specification, togther with the next *) + (* character and state. *) + (*--------------------------------------------------------------------*) + (* might raise: SyntaxState *) + (*--------------------------------------------------------------------*) + fun parseContentSpec dtd curr (c,a,q) = + case c + of 0wx28 (* #"(" *) => + let + val (c1,a1,q1) = skipPSopt dtd (getChar(a,q)) + val lparEnt = getEntId q + in + if c1=0wx23 (* #"#" *) + then parseMixed dtd lparEnt (getChar(a1,q1)) + else let val (cm,(c2,a2,q2)) = parseGroup dtd lparEnt (c1,a1,q1) + val (dfa,a3) = (makeDfa cm,a2) handle Ambiguous(a,n1,n2) + => if !O_COMPATIBILITY + then let val err = ERR_AMBIGUOUS(Index2Element dtd a,n1,n2) + val a3 = hookError(a2,(getPos q,err)) + val dfa = makeChoiceDfa cm + in (dfa,a3) + end + else (makeAmbiguous cm,a2) handle DfaTooLarge max + => let val a3 = if !O_DFA_WARN_TOO_LARGE + then hookWarning + (a2,(getPos q,WARN_DFA_TOO_LARGE(curr,max))) + else a2 + val dfa = makeChoiceDfa cm + in (dfa,a3) + end + in (CT_ELEMENT(cm,dfa),(c2,a3,q2)) + end + end + | _ => (* must be ANY or EMPTY *) + let + val (name,caq1 as (c1,a1,q1)) = parseName (c,a,q) + handle NotFound (c,a,q) => + let val err = ERR_EXPECTED(expContSpec,[c]) + in raise SyntaxError(c,hookError(a,(getPos q,err)),q) + end + in case name + of [0wx41,0wx4e,0wx59] (* "ANY" *) => (CT_ANY,caq1) + | [0wx45,0wx4d,0wx50,0wx54,0wx59] (* "EMPTY" *) => (CT_EMPTY,caq1) + | _ => let val a2 = hookError(a1,(getPos q,ERR_EXPECTED(expContSpec,name))) + in (CT_ANY,(c1,a2,q1)) + end + end + + (*--------------------------------------------------------------------*) + (* parse an element declaration, the initial '' Element Type *) + (* Declaration ] *) + (* *) + (* (see also the comments for ParseDtd.parseMarkupDecl). *) + (* *) + (* print an error and raise SyntaxState if no element name, no *) + (* content specification, or no final '>' is found. *) + (* print an error if the '>' is not in the same entity as the ' let val err = ERR_EXPECTED(expAnElemName,[c]) + in raise SyntaxError(c,hookError(a,(getPos q,err)),q) + end + val a3 = checkElemName (a2,q1) name + val idx = Element2Index dtd name + val caq3 = skipPS dtd (c2,a3,q2) + + val (contSpec,(c4,a4,q4)) = parseContentSpec dtd name caq3 + + val a5 = if useParamEnts() orelse not ext then addElement dtd (a4,q1) (idx,contSpec,ext) + else a4 + val a5' = hookDecl(a5,((startPos,getPos q4),DEC_ELEMENT(idx,contSpec,ext))) + + val (c6,a6,q6) = skipPSopt dtd (c4,a5',q4) + in + if c6<>0wx3E (* #">" *) + then let val a7 = hookError(a6,(getPos q6,ERR_EXPECTED(expGt,[c6]))) + in raise SyntaxError(c6,a7,q6) + end + else let val a7 = if not (!O_VALIDATE) orelse getEntId q6=startEnt then a6 + else hookError(a6,(getPos q6,ERR_DECL_ENT_NESTING LOC_ELEM_DECL)) + in getChar(a7,q6) + end + end + handle exn as SyntaxError (c,a,q) => + let val a1 = if c=0wx00 then hookError(a,(getPos q,ERR_ENDED_BY_EE LOC_ELEM_DECL)) + else a + in recoverDecl false (c,a1,q) + end + + (*--------------------------------------------------------------------*) + (* parse an enumerated attribute type, the '(' already consumed. the *) + (* 1st arg is a string describing the attribute (nmtoken or notation),*) + (* the 2nd arg is a function that parses a single token, the 3rd arg *) + (* a function for converting the token to its index. 3.3.1: *) + (* *) + (* [58] NotationType ::= 'NOTATION' S *) + (* '(' S? Name (S? '|' S? Name)* S? ')' *) + (* [59] Enumeration ::= '(' S? Nmtoken (S? '|' S? Nmtoken)* S? ')' *) + (* *) + (* print an error and raise SyntaxState if no token is found after a *) + (* '(' or '|', or if neither '|' nor ')' follows a token. *) + (* *) + (* return the (sorted) list of indices of the parsed tokens. *) + (*--------------------------------------------------------------------*) + (* might raise: SyntaxState *) + (*--------------------------------------------------------------------*) + fun parseEnumerated dtd (expWhat,parseToken,Token2Index) caq = + let fun doit idxs caq = + let + val caq1 as (_,_,q1) = skipPSopt dtd caq + val (nt,(c2,a2,q2)) = parseToken caq1 + handle NotFound (c,a,q) => let val err = ERR_EXPECTED(expWhat,[c]) + in raise SyntaxError(c,hookError(a,(getPos q,err)),q) + end + val (idx,a3) = Token2Index dtd (a2,q1) nt + val (c4,a4,q4) = skipPSopt dtd (c2,a3,q2) + val newIdxs = insertInt(idx,idxs) + in case c4 + of 0wx7C (* #"|" *) => doit newIdxs (getChar(a4,q4)) + | 0wx29 (* #")" *) => (newIdxs,getChar(a4,q4)) + | _ => let val a5 = hookError(a4,(getPos q4,ERR_EXPECTED(expBarRpar,[c4]))) + in raise SyntaxError (c4,a5,q4) + end + end + in doit nil caq + end + + (*--------------------------------------------------------------------*) + (* Convert a (name) token to its index as an enumerated attribute. *) + (* 3.3.1: *) + (* *) + (* Validity Constraint: Notation Attributes *) + (* ... all notation names in the declaration must be declared. *) + (* *) + (* print an error if a notation is not declared. *) + (*--------------------------------------------------------------------*) + (* might raise: SyntaxState *) + (*--------------------------------------------------------------------*) + fun Token2NmtokenIndex dtd (a,_) token = (AttNot2Index dtd token,a) + fun Token2NotationIndex dtd (a,q) token = + let + val idx = AttNot2Index dtd token + val a1 = if not (!O_VALIDATE) orelse hasNotation dtd idx then a + else hookError(a,(getPos q,ERR_UNDECLARED(IT_NOTATION,token,LOC_NONE))) + in (idx,a1) + end + + (*--------------------------------------------------------------------*) + (* parse an attribute type, the 1st arg being the element this decl. *) + (* refers to. 3.3.1: *) + (* *) + (* [54] AttType ::= StringType | TokenizedType | EnumeratedType *) + (* *) + (* [55] StringType ::= 'CDATA' *) + (* [56] TokenizedType ::= 'ID' [VC: One ID per Element Type ] *) + (* | 'IDREF' *) + (* | 'IDREFS' *) + (* | 'ENTITY' *) + (* | 'ENTITIES' *) + (* | 'NMTOKEN' *) + (* | 'NMTOKENS' *) + (* *) + (* Validity Constraint: One ID per Element Type *) + (* No element type may have more than one ID attribute specified. *) + (* *) + (* Enumerated Attribute Types *) + (* *) + (* [57] EnumeratedType ::= NotationType | Enumeration *) + (* [58] NotationType ::= 'NOTATION' S '(' ... *) + (* [59] Enumeration ::= '(' ... *) + (* *) + (* print an error and raise SyntaxState if no '(', or name is found *) + (* in the first place, or the name does not start an attribute type, *) + (* or if no '(' follows a 'NOTATION'. *) + (* print an error and assume NMTOKEN instead of ID if the element *) + (* already has an ID attribute. *) + (* *) + (* return the attribute type together with the next char and state. *) + (*--------------------------------------------------------------------*) + (* might raise: SyntaxState *) + (*--------------------------------------------------------------------*) + fun parseAttType dtd elem (c,a,q) = + if c=0wx28 (* #"(" *) then + let val (idxs,caq1) = parseEnumerated dtd + (expANameToken,parseNmtoken,Token2NmtokenIndex) (getChar(a,q)) + in (AT_GROUP idxs,caq1) + end + else let val (name,caq1 as (c1,a1,q1)) = parseName (c,a,q) + handle NotFound cq => let val err = ERR_EXPECTED(expAttType,[c]) + in raise SyntaxError (c,hookError(a,(getPos q,err)),q) + end + in case name + of [0wx43,0wx44,0wx41,0wx54,0wx41] (* "CDATA" *) => + (AT_CDATA,caq1) + | [0wx49,0wx44] (* "ID" *) => + (AT_ID,caq1) + | [0wx49,0wx44,0wx52,0wx45,0wx46] (* "IDREF" *) => + (AT_IDREF,caq1) + | [0wx49,0wx44,0wx52,0wx45,0wx46,0wx53] (* "IDREFS" *) => + (AT_IDREFS,caq1) + | [0wx45,0wx4e,0wx54,0wx49,0wx54,0wx59] (* "ENTITY" *) => + (AT_ENTITY,caq1) + | [0wx45,0wx4e,0wx54,0wx49,0wx54,0wx49,0wx45,0wx53] (* "ENTITIES" *) => + (AT_ENTITIES,caq1) + | [0wx4e,0wx4d,0wx54,0wx4f,0wx4b,0wx45,0wx4e] (* "NMTOKEN" *) => + (AT_NMTOKEN,caq1) + | [0wx4e,0wx4d,0wx54,0wx4f,0wx4b,0wx45,0wx4e,0wx53] (* "NMTOKEN" *) => + (AT_NMTOKENS,caq1) + | [0wx4e,0wx4f,0wx54,0wx41,0wx54,0wx49,0wx4f,0wx4e] (* "NOTATION" *) => + let val (c2,a2,q2) = skipPSopt dtd caq1 + in case c2 + of 0wx28 (* #"(" *) => + let val (idxs,caq3) = parseEnumerated dtd + (expANotName,parseName,Token2NotationIndex) (getChar(a2,q2)) + in (AT_NOTATION idxs,caq3) + end + | _ => let val err = ERR_EXPECTED(expLpar,[c2]) + in raise SyntaxError(c2,hookError(a2,(getPos q2,err)),q2) + end + end + | _ => let val a2 = hookError(a1,(getPos q,ERR_EXPECTED(expAttType,name))) + in raise SyntaxError (c1,a2,q1) + end + end + + (*--------------------------------------------------------------------*) + (* parse an attribute default, for an attribute whose type is given *) + (* the 1st argument. Cf. 3.3.2: *) + (* *) + (* [60] DefaultDecl ::= '#REQUIRED' | '#IMPLIED' *) + (* | (('#FIXED' S)? AttValue) *) + (* *) + (* Validity Constraint: Attribute Default Legal *) + (* The declared default value must meet the lexical constraints of *) + (* the declared attribute type. *) + (* *) + (* and 3.3.1: *) + (* *) + (* Validity Constraint: ID Attribute Default *) + (* An ID attribute must have a declared default of #IMPLIED or *) + (* #REQUIRED. *) + (* *) + (* print an error and raise SyntaxState if no '#' or literal is found *) + (* in the first place, or no name or a wrong name is found after the *) + (* '#', or if no literal follows the 'FIXED'. *) + (* print an error if white space is missing. *) + (* print an error and assume IMPLIED if the default for an ID attrib. *) + (* is not IMPLIED or REQUIRED. *) + (* *) + (* return the default together with the remaining char and state. *) + (*--------------------------------------------------------------------*) + (* might raise: SyntaxState *) + (*--------------------------------------------------------------------*) + fun parseDefaultDecl dtd (aidx,attType) (c,a,q) = + if c=0wx23 (* #"#" *) then + let + val caq0 as (_,_,q0) = (getChar(a,q)) + val (name,caq1) = parseName caq0 + handle NotFound (c,a,q) => let val err = ERR_EXPECTED(expAttDefKey,[c]) + in raise SyntaxError(c,hookError(a,(getPos q,err)),q) + end + in case name + of [0wx46,0wx49,0wx58,0wx45,0wx44] (* "FIXED" *) => + let + val caq2 as (_,_,q2) = skipPS dtd caq1 + val (lit,text,(c3,a3,q3)) = parseAttValue dtd caq2 + handle NotFound (c,a,q) => let val err = ERR_EXPECTED(expLitQuote,[c]) + val a1 = hookError(a,(getPos q,err)) + in raise SyntaxError (c,a1,q) + end + in + if !O_VALIDATE andalso isIdType attType + then let val a4 = hookError(a3,(getPos q,ERR_ID_DEFAULT)) + in (AD_IMPLIED,(c3,a4,q3)) + end + else + let val (cv,(av,a4)) = makeAttValue dtd (a3,q2) + (aidx,attType,false,true,text) + in (AD_FIXED((lit,cv,av),(getPos q2,ref false)),(c3,a4,q3)) + end + handle AttValue a => (AD_IMPLIED,(c3,a,q3)) + end + + | [0wx49,0wx4d,0wx50,0wx4c,0wx49,0wx45,0wx44] (* "IMPLIED" *) => + (AD_IMPLIED,caq1) + | [0wx52,0wx45,0wx51,0wx55,0wx49,0wx52,0wx45,0wx44] (* "REQUIRED" *) => + (AD_REQUIRED,caq1) + | _ => let val (c1,a1,q1) = caq1 + val a2 = hookError(a1,(getPos q0,ERR_EXPECTED(expAttDefKey,name))) + in raise SyntaxError (c1,a2,q1) + end + end + else let + val (lit,text,(c1,a1,q1)) = parseAttValue dtd (c,a,q) + handle NotFound (c,a,q) => let val err = ERR_EXPECTED(expQuoteRni,[c]) + val a1 = hookError(a,(getPos q,err)) + in raise SyntaxError(c,a1,q) + end + in + if !O_VALIDATE andalso isIdType attType + then let val a2 = hookError(a1,(getPos q,ERR_ID_DEFAULT)) + in (AD_IMPLIED,(c1,a2,q1)) + end + else let val (cv,(av,a2)) = makeAttValue dtd (a1,q) (aidx,attType,false,true,text) + in (AD_DEFAULT((lit,cv,av),(getPos q,ref false)),(c1,a2,q1)) + end + handle AttValue a => (AD_IMPLIED,(c1,a,q1)) + end + + (*--------------------------------------------------------------------*) + (* parse an attribute definition, the referred element given as 1st *) + (* argument. 3.3: *) + (* *) + (* [53] AttDef ::= S Name S AttType S DefaultDecl *) + (* *) + (* raise NotFound if no name is found (and thus no attribute def.) *) + (* print an error if white space is missing. *) + (* *) + (* enter the attribute definition into the element table. *) + (* return the next character and the remaining state. *) + (*--------------------------------------------------------------------*) + (* might raise: NotFound SyntaxState *) + (*--------------------------------------------------------------------*) + fun parseAttDef dtd (elem,ext) caq = + let + val (hadS,caq1 as (_,_,q1)) = skipPSmay dtd caq + + val (name,(c2,a2,q2)) = parseName caq1 (* NotFound falls through to the next level *) + val a3 = if hadS then a2 else hookError(a2,(getPos q1,ERR_MISSING_WHITE)) + val a4 = checkAttName (a3,q1) name + val idx = AttNot2Index dtd name + + val caq5 = skipPS dtd (c2,a4,q2) + val (attType,caq6) = parseAttType dtd elem caq5 + val caq7 = skipPS dtd caq6 + + val (attDef,(c8,a8,q8)) = parseDefaultDecl dtd (idx,attType) caq7 + + val a9 = if useParamEnts() orelse not ext + then addAttribute dtd (a8,q1) (elem,(idx,attType,attDef,ext)) else a8 + in + ((idx,attType,attDef),(c8,a9,q8)) + end + + (*--------------------------------------------------------------------*) + (* parse an attribute-list declaration, the initial '' *) + (* *) + (* (see also the comments for ParseDtd.parseMarkupDecl). *) + (* *) + (* check whether the element already had an attlist declaration. (cf. *) + (* DtdElements.enterAttDecl) *) + (* *) + (* print an error and raise SyntaxState if no element name, or no *) + (* final '>' is found. *) + (* print an error if the '>' is not in the same entity as the ' let val err = ERR_EXPECTED(expAnElemName,[c]) + in raise SyntaxError (c,hookError(a,(getPos q,err)),q) + end + val a3 = checkElemName (a2,q1) name + val idx = Element2Index dtd name + + val a4 = if !O_VALIDATE orelse not ext then enterAttList dtd (a3,q1) idx else a3 + + fun doit attDefs caq = + let val (attDef,caq1) = parseAttDef dtd (idx,ext) caq + handle NotFound (c,a,q) => raise NotFound + (c,hookDecl(a,((startPos,getPos q),DEC_ATTLIST(idx,rev attDefs,ext))),q) + | SyntaxError (c,a,q) => raise SyntaxError + (c,hookDecl(a,((startPos,getPos q),DEC_ATTLIST(idx,rev attDefs,ext))),q) + in doit (attDef::attDefs) caq1 + end + + val (c5,a5,q5) = doit nil (c2,a4,q2) handle NotFound caq => caq + in + if c5 <> 0wx3E (* #">" *) + then let val a6 = hookError(a5,(getPos q5,ERR_EXPECTED(expAttNameGt,[c5]))) + in raise SyntaxError (c5,a6,q5) + end + else let val a6 = if not (!O_VALIDATE) orelse getEntId q5=startEnt then a5 + else hookError(a5,(getPos q5,ERR_DECL_ENT_NESTING LOC_ATT_DECL)) + in getChar(a6,q5) + end + end + handle exn as SyntaxError (c,a,q) => + let val a1 = if c=0wx00 then hookError(a,(getPos q,ERR_ENDED_BY_EE LOC_ATT_DECL)) + else a + in recoverDecl false (c,a,q) + end +end diff --git a/fxp/src/Parser/Parse/parseDocument.sml b/fxp/src/Parser/Parse/parseDocument.sml new file mode 100644 index 0000000..0539821 --- /dev/null +++ b/fxp/src/Parser/Parse/parseDocument.sml @@ -0,0 +1,262 @@ +(*--------------------------------------------------------------------------*) +(* Structure: ParseDocument *) +(* *) +(* Exceptions raised by functions in this structure: *) +(* parseDocTypeDecl : none *) +(*--------------------------------------------------------------------------*) +functor Parse + (structure Dtd : Dtd + structure Hooks : Hooks + structure Resolve : Resolve + structure ParserOptions : ParserOptions) : + sig + val parseDocument : Uri.Uri option -> Dtd.Dtd option -> Hooks.AppData -> Hooks.AppFinal + end + = +struct + structure ParseBase = ParseBase (structure Dtd = Dtd + structure Hooks = Hooks + structure Resolve = Resolve + structure ParserOptions = ParserOptions) + + structure ParseContent = ParseContent (structure ParseBase = ParseBase) + + open + Base UniChar Errors UniClasses Uri + ParseContent + + val THIS_MODULE = "ParseContent" + + datatype Where = + PROLOG + | EPILOG + | INSTANCE of int option + + fun locOf wher = + case wher + of PROLOG => LOC_PROLOG + | INSTANCE _ => LOC_PROLOG + | EPILOG => LOC_EPILOG + + fun checkRoot dtd (a,q) (doc,stag as ((_,elem,_,_,_),_)) = + if !O_VALIDATE + then case doc + of NONE => a + | SOME doc => + if doc=elem then a + else let val err = ERR_ROOT_ELEM(Index2Element dtd doc, + Index2Element dtd elem) + in hookError(a,(getPos q,err)) + end + else a + + fun parseDoc dtd caq = + let + fun do_data wher caq = + let fun doit hadError ws (c,a,q) = + case c + of 0wx00 => (ws,(c,a,q)) + | 0wx26 (* #"&" *) => (ws,(c,a,q)) + | 0wx3C (* #"<" *) => (ws,(c,a,q)) + | 0wx09 (* #"\t"*) => doit hadError (c::ws) (getChar(a,q)) + | 0wx0A (* #"\n"*) => doit hadError (c::ws) (getChar(a,q)) + | 0wx20 (* #" " *) => doit hadError (c::ws) (getChar(a,q)) + | _ => let val a1 = if hadError then a + else hookError(a,(getPos q,ERR_FORBIDDEN_HERE + (IT_DATA nil,locOf wher))) + in doit true ws (getChar(a1,q)) + end + + val (ws,(c1,a1,q1)) = doit false nil caq + val a2 = if null ws then a1 + else hookWhite(a1,Data2Vector (rev ws)) + in (c1,a2,q1) + end + + fun do_decl wher q0 (c,a,q) = + case c + of 0wx2D (* #"-" *) => + let val (c1,a1,q1) = getChar(a,q) + in if c1=0wx2D then (wher,parseComment (getPos q0) (a1,q1)) + else let val err = ERR_EXPECTED(expDash,[c1]) + val a2 = hookError(a1,(getPos q1,err)) + val caq2 = recoverDecl false (c1,a2,q1) + in (wher,caq2) + end + end + | 0wx5B (* #"[" *) => + let + val err = ERR_FORBIDDEN_HERE (IT_CDATA,locOf wher) + val a1 = hookError(a,(getPos q0,err)) + val caq2 = skipBadSection (getChar(a1,q)) + in (wher,caq2) + end + | _ => + case wher + of PROLOG => + (let val (name,(c1,a1,q1)) = parseName (c,a,q) + handle NotFound (c,a,q) => + let val err = expectedOrEnded(expDashDocLbrk,LOC_DECL) c + in raise SyntaxError (c,hookError(a,(getPos q,err)),q) + end + + val _ = if name=[0wx44,0wx4f,0wx43,0wx54,0wx59,0wx50,0wx45] + (* "DOCTYPE" *) then () + else let val err = ERR_EXPECTED(expDashDocLbrk,name) + val a2 = hookError(a1,(getPos q,err)) + in raise SyntaxError (c1,a2,q1) + end + + val (doc,caq2) = parseDocTypeDecl dtd (c1,a1,q1) + in (INSTANCE doc,caq2) + end + handle SyntaxError caq => (PROLOG,recoverDecl true caq)) + + | _ => let val loc = if wher=EPILOG then LOC_EPILOG else LOC_AFTER_DTD + val err = ERR_FORBIDDEN_HERE (IT_DECL,loc) + val a1 = hookError(a,(getPos q0,err)) + val caq2 = skipDecl true (c,a1,q) + in (wher,caq2) + end + + and doit wher (c,a,q) = + case c + of 0wx00 => if isSpecial q then (wher,(a,q)) + else doit wher (getChar(a,q)) + (*--------------------------------------------------------------*) + (* References are forbidden outside the document element *) + (*--------------------------------------------------------------*) + | 0wx26 (* #"&" *) => + let + val (c1,a1,q1) = getChar(a,q) + val caq2 = + if c1=0wx23 (* #"#" *) + then let val err = ERR_FORBIDDEN_HERE(IT_CHAR_REF,locOf wher) + val a2 = hookError(a1,(getPos q,err)) + in skipCharRef (a2,q1) + end + else let val err = ERR_FORBIDDEN_HERE(IT_REF,locOf wher) + val a2 = hookError(a1,(getPos q,err)) + in skipReference (c1,a2,q1) + end + in doit wher caq2 + end + | 0wx3C (* #"<" *) => + let val (c1,a1,q1) = getChar (a,q) + in case c1 + of 0wx21 (* #"!" *) => + let val (wher1,caq2) = do_decl wher q (getChar(a1,q1)) + in doit wher1 caq2 + end + | 0wx2F (* #"/" *) => + let + val err = ERR_FORBIDDEN_HERE(IT_ETAG,locOf wher) + val a2 = hookError(a1,(getPos q,err)) + val caq3 = skipTag LOC_ETAG (a2,q1) + in doit wher caq3 + end + | 0wx3F (* #"?" *) => doit wher (parseProcInstr (getPos q) (a1,q1)) + | _ => + if isName c1 then + let val wher1 = + case wher + of PROLOG => INSTANCE NONE + | _ => wher + in case wher1 + of PROLOG => + raise InternalError(THIS_MODULE,"parseDoc.doit","") + | EPILOG => + let + val err = ERR_FORBIDDEN_HERE(IT_STAG,LOC_EPILOG) + val a2 = hookError(a1,(getPos q,err)) + val caq3 = skipTag LOC_STAG (a2,q1) + in doit EPILOG caq3 + end + | INSTANCE doc => + (let + val a2 = + if not (!O_VALIDATE) orelse isSome doc then a1 + else hookError(a1,(getPos q,ERR_NO_DTD)) + val (stag,(c3,a3,q3)) = parseSTag + dtd (getPos q) (c1,a2,q1) + val a4 = checkRoot dtd (a3,q1) (doc,stag) + val (opt,(c5,a5,q5)) = parseElement + (dtd,nil,q,stag,(c3,a4,q3)) + val a6 = checkDefinedIds dtd (a5,q5) + in case opt + of NONE => doit EPILOG (c5,a6,q5) + | SOME (_,_,startPos,_) => + let + val err = ERR_FORBIDDEN_HERE(IT_ETAG,LOC_EPILOG) + val a7 = hookError(a6,(startPos,err)) + in doit EPILOG (c5,a7,q5) + end + end + handle SyntaxError caq => doit wher1 caq) + end + else let val err = ERR_FORBIDDEN_HERE(IT_CHAR 0wx3C,locOf wher) + val a2 = hookError(a1,(getPos q,err)) + in doit wher (c1,a2,q1) + end + end + | _ => let val caq1 = do_data wher (c,a,q) + in doit wher caq1 + end + in + doit PROLOG caq + end + + (* to false. (cf. 2.9) *) + (* *) + (* ... If ... there is no standalone document declaration, the *) + (* value "no" is assumed. *) + fun parseDocument uriOpt dtdOpt a = + let + val dtd = case dtdOpt + of NONE => initDtdTables () + | SOME dtd => dtd + val (enc,xmlDecl,(c1,a1,q1)) = openDocument uriOpt a + val uri = getUri q1 + val alone = case xmlDecl + of (SOME(_,_,SOME sa)) => sa + | _ => false + val _ = if alone then setStandAlone dtd true else () + val a2 = hookXml(a1,(uri,enc,xmlDecl)) + val (wher,(a3,q3)) = + let + val version = case xmlDecl + of (SOME(SOME ver,_,_)) => ver + | _ => "1.0" + val getCharOld = !getCharRef + val isNmsOld = !isNmsRef + val isNameOld = !isNameRef + val isXmlOld = !isXmlRef + val _ = if version="1.0" then () + else + let + val _ = getCharRef := getChar11 + val _ = isNmsRef := isNms11 + val _ = isNameRef := isName11 + val _ = isXmlRef := isXml11 + in + () + end + val r = parseDoc dtd (c1,a2,q1) + val _ = getCharRef := getCharOld + val _ = isNmsRef := isNmsOld + val _ = isNameRef := isNameOld + val _ = isXmlRef := isXmlOld + in + r + end + val _ = closeAll q3 + val a4 = case wher + of EPILOG => a3 + | _ => hookError(a3,(getPos q3,ERR_ENDED_IN_PROLOG)) + in hookFinish a4 + end + handle CantOpenFile(fmsg,a) => + let val a1 = hookError(a,(nullPosition,ERR_NO_SUCH_FILE fmsg)) + in hookFinish a1 + end +end diff --git a/fxp/src/Parser/Parse/parseDtd.sml b/fxp/src/Parser/Parse/parseDtd.sml new file mode 100644 index 0000000..66f2672 --- /dev/null +++ b/fxp/src/Parser/Parse/parseDtd.sml @@ -0,0 +1,541 @@ +signature ParseDtd = + sig + (*---------------------------------------------------------------------- + include ParseBase + + val parseName : UniChar.Char * AppData * State + -> UniChar.Data * (UniChar.Char * AppData * State) + + val openExtern : int * Uri.Uri -> AppData * State + -> Encoding.Encoding * HookData.TextDecl option * (UniChar.Char * AppData * State) + val openDocument : Uri.Uri option -> AppData + -> Encoding.Encoding * HookData.XmlDecl option * (UniChar.Char * AppData * State) + + val skipCharRef : AppData * State -> (UniChar.Char * AppData * State) + val skipReference : UniChar.Char * AppData * State -> (UniChar.Char * AppData * State) + val parseGenRef : Dtd -> UniChar.Char * AppData * State + -> (int * Base.GenEntity) * (AppData * State) + val parseCharRefLit : UniChar.Data -> AppData * State + -> UniChar.Data * (UniChar.Char * AppData * State) + + val parseComment : Errors.Position -> AppData * State -> (UniChar.Char * AppData * State) + val parseProcInstr : Errors.Position -> AppData * State -> (UniChar.Char * AppData * State) + + val skipTag : Errors.Location -> AppData * State -> (UniChar.Char * AppData * State) + val parseETag : Dtd -> AppData * State + -> int * UniChar.Data * Errors.Position * (UniChar.Char * AppData * State) + val parseSTag : Dtd -> Errors.Position -> UniChar.Char * AppData * State + -> (HookData.StartTagInfo * Base.ElemInfo) * (UniChar.Char * AppData * State) + + val skipDecl : bool -> UniChar.Char * AppData * State -> UniChar.Char * AppData * State + ----------------------------------------------------------------------*) + include ParseDecl + + val parseDocTypeDecl : Dtd -> (UniChar.Char * AppData * State) + -> int option * (UniChar.Char * AppData * State) + end + +(*--------------------------------------------------------------------------*) +(* Structure: ParseDtd *) +(* *) +(* Exceptions raised by functions in this structure: *) +(* parseDocTypeDecl : none *) +(*--------------------------------------------------------------------------*) +functor ParseDtd (structure ParseBase : ParseBase) + : ParseDtd = +struct + structure ParseDecl = ParseDecl (structure ParseBase = ParseBase) + + open + Base UniChar Errors UniClasses + ParseDecl + + (*--------------------------------------------------------------------*) + (* parse a markup declaration other than a processing instruction, *) + (* " (* #"-" *) + let val (c1,a1,q1) = getChar (a,q) + in if c1<>0wx2D (* #"-" *) + then let val a2 = hookError(a1,(getPos q1,ERR_EXPECTED(expDash,[c1]))) + in recoverDecl false (c1,a2,q1) + end + else parseComment startPos (a1,q1) + end + | _ => let + val (name,caq1) = parseName (c,a,q) + handle NotFound (c,a,q) => let val err = ERR_EXPECTED(expStartMarkup,[c]) + val a1 = hookError(a,(getPos q,err)) + in raise SyntaxError (c,a1,q) + end + val ext = hasExternal dtd + in case name + of [0wx45,0wx4c,0wx45,0wx4d,0wx45,0wx4e,0wx54] (* "ELEMENT" *) => + parseElementDecl dtd (startEnt,startPos,ext) caq1 + | [0wx41,0wx54,0wx54,0wx4c,0wx49,0wx53,0wx54] (* "ATTLIST" *) => + parseAttListDecl dtd (startEnt,startPos,ext) caq1 + | [0wx4e,0wx4f,0wx54,0wx41,0wx54,0wx49,0wx4f,0wx4e] (* "NOTATION" *) => + parseNotationDecl dtd (startEnt,startPos,ext) caq1 + | [0wx45,0wx4e,0wx54,0wx49,0wx54,0wx59] (* "ENTITY" *) => + parseEntityDecl dtd (startEnt,startPos,ext) caq1 + | _ => let val (c1,a1,q1) = caq1 + val err = ERR_EXPECTED(expStartMarkup,name) + val a2 = hookError(a1,(getPos q,err)) + in recoverDecl false (c1,a2,q1) + end + end + + (*--------------------------------------------------------------------*) + (* skip an ignored section, starting after the '". 3.4: *) + (* *) + (* [63] ignoreSect ::= '' *) + (* [64] ignoreSectContents ::= Ignore ('' Ignore)* *) + (* [65] Ignore ::= Char* - (Char* ('') Char* ) *) + (* *) + (* ... If the keyword of the conditional section is IGNORE, then *) + (* the contents of the conditional section are not logically part *) + (* of the DTD. Note that for reliable parsing, the contents of even *) + (* ignored conditional sections must be read in order to detect *) + (* nested conditional sections and ensure that the end of the *) + (* outermost (ignored) conditional section is properly detected. *) + (* If a conditional section with a keyword of INCLUDE occurs within *) + (* a larger conditional section with a keyword of IGNORE, both the *) + (* outer and the inner conditional sections are ignored. *) + (* *) + (* print an error an finish if an entity end is encountered. *) + (* *) + (* return the next char and state. *) + (*--------------------------------------------------------------------*) + (* might raise: none *) + (*--------------------------------------------------------------------*) + fun skipIgnored caq = + let + (*--------------------------------------------------------------*) + (* level counts the nesting of conditional sections. *) + (* if the second char after a "<" ("]") is not a "[" ("]"), it *) + (* can nevertheless start another delimiter and is therefore *) + (* fed into a recursive call of doit. *) + (*--------------------------------------------------------------*) + fun doit level (c,a,q) = + case c + of 0wx00 => (c,hookError(a,(getPos q,ERR_ENDED_BY_EE LOC_IGNORED)),q) + | 0wx3C (* #"<" *) => + let val (c1,a1,q1) = getChar (a,q) + in if c1=0wx21 (* #"!" *) + then let val (c2,a2,q2) = (getChar(a1,q1)) + in if c2=0wx5B (* #"[" *) then doit (level+1) (getChar(a2,q2)) + else doit level (c2,a2,q2) + end + else doit level (c1,a1,q1) + end + | 0wx5D (* #"]" *) => + let val (c1,a1,q1) = getChar (a,q) + in if c1=0wx5D (* #"]" *) then doit' level (getChar (a1,q1)) + else doit level (c1,a1,q1) + end + | _ => doit level (getChar (a,q)) + (*--------------------------------------------------------------*) + (* if the second "]" is followed by a "]", then this might be *) + (* the real second "]". Therefore doit' loops as long as it *) + (* finds "]"'s. *) + (*--------------------------------------------------------------*) + and doit' level (c,a,q) = + case c + of 0wx3E (* #">" *) => if level>0 then doit (level-1) (getChar (a,q)) + else getChar (a,q) + | 0wx5D (* #"]" *) => doit' level (getChar (a,q)) + | _ => doit level (c,a,q) + in + doit 0 caq + end + + (*--------------------------------------------------------------------*) + (* parse the internal or external subset of the dtd. handle included *) + (* sections by counting their nesting level. Cf 2.8: *) + (* *) + (* Validity Constraint: Proper Declaration/PE Nesting *) + (* Parameter-entity replacement text must be properly nested with *) + (* markup declarations. That is to say, if either the first *) + (* character or the last character of a markup declaration *) + (* (markupdecl above) is contained in the replacement text for a *) + (* parameter-entity reference, both must be contained in the same *) + (* replacement text. *) + (* ... *) + (* [28] doctypedecl ::= '' *) + (* [29] markupdecl ::= elementdecl | AttlistDecl | EntityDecl *) + (* | NotationDecl | PI | Comment *) + (* [30] extSubset ::= TextDecl? extSubsetDecl *) + (* [31] extSubsetDecl ::= ( markupdecl | conditionalSect *) + (* | PEReference | S )* *) + (* and 3.4: *) + (* *) + (* [61] conditionalSect ::= includeSect | ignoreSect *) + (* [62] includeSect ::= '' *) + (* [63] ignoreSect ::= '' *) + (* *) + (* print an error and finish if the end of document is encountered in *) + (* the internal subset. *) + (* print an error and raise SyntaxState if a "<" is not followed by a *) + (* "!" or a "?". *) + (* print an error and raise SyntaxState if a "]" is not followed by *) + (* "]>". *) + (* print an error if a "" is found outside an included section. *) + (* print an error an raise SyntaxState if something other than a *) + (* markup declaration, parameter entity reference, white space or *) + (* a conditional section is encountered. *) + (* print an error and raise SyntaxState if a " (ws,(c,a,q)) + | 0wx09 => doit false (c::ws) (getChar(a,q)) + | 0wx0A => doit false (c::ws) (getChar(a,q)) + | 0wx20 => doit false (c::ws) (getChar(a,q)) + | 0wx25 => (ws,(c,a,q)) + | 0wx3C => (ws,(c,a,q)) + | 0wx5D => (ws,(c,a,q)) + | _ => if hadError then doit true ws (getChar(a,q)) + else let val err = ERR_FORBIDDEN_HERE(IT_DATA nil,LOC_SUBSET) + val a1 = hookError (a,(getPos q,err)) + in doit true ws (getChar(a1,q)) + end + + val (ws,(c1,a1,q1)) = doit false nil caq + val a2 = if null ws then a1 + else hookWhite(a1,Data2Vector (rev ws)) + in (c1,a2,q1) + end + + fun doit cond (c,a,q) = + case c + of 0wx00 => + if isSpecial q + (*---------------------------------------------------*) + (* the external subset ends at and of special entity.*) + (* so does the internal subset, but with error. *) + (*---------------------------------------------------*) + then + let val a1 = + if inDocEntity q + then hookError(a,(getPos q,ERR_ENDED_BY_EE LOC_INT_SUBSET)) + else if cond=0 then a + else hookError(a,(getPos q,ERR_ENDED_BY_EE LOC_INCLUDED)) + in (c,a1,q) + end + else let val a1 = hookEntEnd (a,getPos q) + in doit cond (getChar(a1,q)) + end + + (* ignore errors in parameter references -----------------*) + | 0wx25 (* #"%" *) => + let + val caq2 = + let val ((id,ent),(a1,q1)) = parseParRef dtd (getChar(a,q)) + in if !O_VALIDATE orelse !O_INCLUDE_PARAM_ENTS then + case ent + of PE_NULL => getChar(a1,q1) + | PE_INTERN(_,rep) => + let + val q2 = pushIntern(q1,id,true,rep) + val a2 = hookParRef(a1,((getPos q,getPos q1),id,ent,true)) + in getChar(a2,q2) + end + | PE_EXTERN extId => + let + val a2 = hookParRef(a1,((getPos q,getPos q1),id,ent,true)) + val caq3 = + #3(openExtern (id,true,resolveExtId extId) (a2,q1)) + handle CantOpenFile(fmsg,a) + => let val err = ERR_NO_SUCH_FILE fmsg + val a1 = hookError(a,(getPos q1,err)) + val a2 = hookEntEnd (a1,getPos q1) + in (getChar(a2,q1)) + end + in caq3 + end + (* changed 080600: setExternal is already called by parseParRef *) + else let val a2 = hookParRef(a1,((getPos q,getPos q1),id,ent,false)) + in getChar(a2,q1) + end + end + handle SyntaxError caq => caq + | NoSuchEntity aq => getChar aq + in doit cond caq2 + end + + | 0wx3C (* #"<" *) => + let val (c1,a1,q1) = getChar(a,q) + in case c1 + of 0wx3F => (* #"?" *) + let val caq2 = parseProcInstr (getPos q) (a1,q1) + in doit cond caq2 + end + | 0wx21 => (* #"!" *) + let val (c2,a2,q2) = (getChar(a1,q1)) + in if c2=0wx5B (* #"[" *) + then do_cond cond q (a2,q2) + else + let val caq3 = parseMarkupDecl dtd + (getEntId q,getPos q) (c2,a2,q2) + in doit cond caq3 + end + end + | _ => let val err = ERR_EXPECTED(expExclQuest,[c1]) + val a2 = hookError(a1,(getPos q1,err)) + val caq3 = recoverDecl false (c1,a2,q1) + in doit cond caq3 + end + end + + | 0wx5D (* #"]" *) => do_brack cond q (getChar(a,q)) + | _ => let val caq1 = do_data (c,a,q) + in doit cond caq1 + end + + and do_brack cond q0 (c,a,q) = + if inDocEntity q then (c,a,q) + else if c=0wx5D (* #"]" *) + then let val (c1,a1,q1) = getChar(a,q) + in if c1=0wx3E (* #">" *) + (* ignore wrong "]]>"'s ------------------*) + then if cond=0 + then let val err = ERR_FORBIDDEN_HERE(IT_DATA [c,c,c1], + LOC_OUT_COND) + val a2 = hookError(a1,(getPos q0,err)) + in doit cond (getChar(a2,q1)) + end + else doit (cond-1) (getChar(a1,q1)) + (* the second "]" may start another "]]>" ---*) + else let val a2 = hookError(a1,(getPos q1,ERR_EXPECTED(expGt,[c1]))) + in do_brack cond q (c1,a2,q1) + end + end + else let val a1 = hookError(a,(getPos q,ERR_EXPECTED(expRbrack,[c]))) + in doit cond (c,a1,q) + end + + and do_cond cond q0 (a,q) = + let + (* marked sections are forbidden in the internal subset. -*) + val inInt = inDocEntity q + val a1 = if inInt then hookError (a,(getPos q0,ERR_FORBIDDEN_HERE + (IT_COND,LOC_INT_SUBSET))) + else a + + val caq2 as (_,_,q2) = skipPSopt dtd (getChar(a1,q)) + + val (status,caq3) = + let + val (name,(c3,a3,q3)) = parseName caq2 + (* ignore sections with bad status keyword ---------*) + val (status,a4) = + case name + of [0wx49,0wx47,0wx4e,0wx4f,0wx52,0wx45] => (IGNORE,a3) + | [0wx49,0wx4e,0wx43,0wx4c,0wx55,0wx44,0wx45] => (INCLUDE,a3) + | _ => let val err = ERR_EXPECTED(expCondStatus,name) + val a4 = hookError(a3,(getPos q2,err)) + in (IGNORE,a4) + end + val (c5,a5,q5) = skipPSopt dtd (c3,a4,q3) + in (* ignore sections without "[" after keyword -------*) + if c5=0wx5B then (status,getChar(a5,q5)) + else let val a6 = hookError(a5,(getPos q5,ERR_EXPECTED(expLbrack,[c5]))) + in (IGNORE,(c5,a6,q5)) + end + end + handle NotFound (c,a,q) => let val err = ERR_EXPECTED(expCondStatus,[c]) + val a1 = hookError(a,(getPos q,err)) + in (IGNORE,(c,a1,q)) + end + in + (* ignore sections in the internal subset ----------------*) + case (status,inInt) + of (INCLUDE,_) => doit (cond+1) caq3 + | (_,_) => doit cond (skipIgnored caq3) + end + in + doit 0 caq + end + + (*--------------------------------------------------------------------*) + (* parse the internal subset of the dtd. Cf 2.8: *) + (* *) + (* return the remaining character and state. *) + (*--------------------------------------------------------------------*) + (* might raise: none *) + (*--------------------------------------------------------------------*) + fun parseInternalSubset dtd (a,q) = + let val a1 = hookSubset (a,getPos q) + in parseSubset dtd (getChar(a1,q)) + end + + (*--------------------------------------------------------------------*) + (* parse the external subset of the dtd, the filename given as first *) + (* argument. handle included sections by counting their nesting level.*) + (* the file is opened on its own stack, and closed at the end. *) + (* Cf 2.8: *) + (* *) + (* print an error and do nothing if the file cannot be opened. *) + (* *) + (* return nothing. *) + (*--------------------------------------------------------------------*) + (* might raise: none *) + (*--------------------------------------------------------------------*) + fun parseExternalSubset dtd (a,q) extId = + let + val uri = resolveExtId extId + val (enc,textDecl,(c1,a1,q1)) = openSubset uri a + val a2 = hookExtSubset (a1,(uri,enc,textDecl)) + val (_,a3,q3) = + let + val version = case textDecl + of (SOME(SOME ver,_)) => ver + | _ => "1.0" + val getCharOld = !getCharRef + val isNmsOld = !isNmsRef + val isNameOld = !isNameRef + val isXmlOld = !isXmlRef + val _ = if version="1.0" then () + else + let + val _ = getCharRef := getChar11 + val _ = isNmsRef := isNms11 + val _ = isNameRef := isName11 + val _ = isXmlRef := isXml11 + in + () + end + val r = parseSubset dtd (c1,a2,q1) + val _ = getCharRef := getCharOld + val _ = isNmsRef := isNmsOld + val _ = isNameRef := isNameOld + val _ = isXmlRef := isXmlOld + in + r + end + val _ = closeAll q3 + in a3 + end + handle CantOpenFile(fmsg,a) => hookError(a,(getPos q,ERR_NO_SUCH_FILE fmsg)) + + (*--------------------------------------------------------------------*) + (* Parse the document type declaration, the ' *) + (* *) + (* print an error and raise SyntaxState if no name is found. *) + (* print an error and raise SyntaxState if no final ">" is found. *) + (* external identifier is found. *) + (* print an error if white space is missing. *) + (* *) + (* return nothing. *) + (*--------------------------------------------------------------------*) + (* might raise: none *) + (*--------------------------------------------------------------------*) + fun parseDocTypeDecl dtd caq = + let + val _ = setHasDtd dtd + val caq1 = skipS caq + + val (doc,caq2) = parseName caq1 + handle NotFound (c,a,q) => let val err = ERR_EXPECTED(expAName,[c]) + in raise SyntaxError (c,hookError(a,(getPos q,err)),q) + end + val idx = Element2Index dtd doc + + val (hadS,caq3 as (_,_,q3)) = skipSmay caq2 + val (ext,(c4,a4,q4)) = let val (extId,_,(c4,a4,q4)) = parseExtIdSub dtd caq3 + val a5 = if hadS then a4 + else hookError(a4,(getPos q3,ERR_MISSING_WHITE)) + in (SOME extId,(c4,a5,q4)) + end + handle NotFound caq => (NONE,caq) + + val a4' = hookDocType(a4,(idx,ext)) + val (c5,a5,q5) = case c4 + of 0wx5B (* #"[" *) => + let val caq5 = parseInternalSubset dtd (a4',q4) + in skipSopt caq5 + end + | _ => (c4,a4',q4) + + val a6 = case ext + of NONE => a5 + | SOME extId => let val _ = setExternal dtd + in if !O_VALIDATE orelse !O_INCLUDE_PARAM_ENTS + then parseExternalSubset dtd (a5,q5) extId + else a5 + end + + val a7 = checkMultEnum dtd (a6,q5) + val a7'= checkPreDefined dtd (a7,q5) + val a8 = checkUnparsed dtd a7' + + val (c9,a9,q9) = if c5=0wx3E (* #">" *) then getChar(a8,q5) + else let val err = expectedOrEnded(expGt,LOC_DOC_DECL) c5 + val a9 = hookError(a8,(getPos q5,err)) + in recoverDecl false (c5,a9,q5) + end + in + (SOME idx,(c9,hookEndDtd(a9,getPos q9),q9)) + end + handle exn as SyntaxError(c,a,q) => + let val a1 = if c=0wx00 then hookError(a,(getPos q,ERR_ENDED_BY_EE LOC_DOC_DECL)) + else a + val (c2,a2,q2) = recoverDecl true (c,a1,q) + in (NONE,(c2,hookEndDtd(a2,getPos q2),q2)) + end +end diff --git a/fxp/src/Parser/Parse/parseLiterals.sml b/fxp/src/Parser/Parse/parseLiterals.sml new file mode 100644 index 0000000..281d99a --- /dev/null +++ b/fxp/src/Parser/Parse/parseLiterals.sml @@ -0,0 +1,458 @@ +signature ParseLiterals = + sig + (*---------------------------------------------------------------------- + include ParseBase + + val parseName : UniChar.Char * AppData * State + -> UniChar.Data * (UniChar.Char * AppData * State) + val parseNmtoken : UniChar.Char * AppData * State + -> UniChar.Data * (UniChar.Char * AppData * State) + + val parseComment : Errors.Position -> AppData * State -> (UniChar.Char * AppData * State) + val parseProcInstr : Errors.Position -> AppData * State -> (UniChar.Char * AppData * State) + val skipS : UniChar.Char * AppData * State -> UniChar.Char * AppData * State + val skipSopt : UniChar.Char * AppData * State -> UniChar.Char * AppData * State + val skipSmay : UniChar.Char * AppData * State -> bool * (UniChar.Char * AppData * State) + val parseSopt : UniChar.Data -> UniChar.Char * AppData * State + -> UniChar.Data * (UniChar.Char * AppData * State) + val parseSmay : UniChar.Data -> UniChar.Char * AppData * State + -> bool * (UniChar.Data * (UniChar.Char * AppData * State)) + val parseEq : UniChar.Char * AppData * State + -> UniChar.Data * (UniChar.Char * AppData * State) + + val openExtern : int * Uri.Uri -> AppData * State + -> Encoding.Encoding * HookData.TextDecl option * (UniChar.Char * AppData * State) + val openDocument : Uri.Uri option -> AppData + -> Encoding.Encoding * HookData.XmlDecl option * (UniChar.Char * AppData * State) + val openSubset : Uri.Uri -> AppData + -> Encoding.Encoding * HookData.TextDecl option * (UniChar.Char * AppData * State) + + val skipCharRef : AppData * State -> (UniChar.Char * AppData * State) + val skipReference : UniChar.Char * AppData * State -> (UniChar.Char * AppData * State) + val parseGenRef : Dtd -> UniChar.Char * AppData * State + -> (int * Base.GenEntity) * (AppData * State) + val parseParRef : Dtd -> UniChar.Char * AppData * State + -> (int * Base.ParEntity) * (AppData * State) + val parseCharRefLit : UniChar.Data -> AppData * State + -> UniChar.Data * (UniChar.Char * AppData * State) + val skipPS : Dtd -> UniChar.Char * AppData * State + -> UniChar.Char * AppData * State + val skipPSopt : Dtd -> UniChar.Char * AppData * State + -> UniChar.Char * AppData * State + val skipPSmay : Dtd -> UniChar.Char * AppData * State + -> bool * (UniChar.Char * AppData * State) + val skipPSdec : Dtd -> UniChar.Char * AppData * State + -> bool * (UniChar.Char * AppData * State) + ----------------------------------------------------------------------*) + include ParseRefs + + val parseSystemLiteral : UniChar.Char * AppData * State + -> Uri.Uri * UniChar.Char * (UniChar.Char * AppData * State) + val parsePubidLiteral : UniChar.Char * AppData * State + -> string * UniChar.Char * (UniChar.Char * AppData * State) + + val parseAttValue : Dtd -> UniChar.Char * AppData * State + -> UniChar.Vector * UniChar.Data * (UniChar.Char * AppData * State) + val parseEntityValue : Dtd -> (UniChar.Vector * UniChar.Vector -> 'a) + -> UniChar.Char * AppData * State + -> 'a * (UniChar.Char * AppData * State) + end + +(*--------------------------------------------------------------------------*) +(* Structure: ParseLiterals *) +(* *) +(* Exceptions raised by functions in this structure: *) +(* parseSystemLiteral : NotFound *) +(* parsePubidLiteral : NotFound *) +(* parseAttValue : NotFound *) +(* parseEntityValue : NotFound *) +(*--------------------------------------------------------------------------*) +functor ParseLiterals (structure ParseBase : ParseBase) + : ParseLiterals = +struct + structure ParseRefs = ParseRefs (structure ParseBase = ParseBase) + + open + Base UniChar Errors UniClasses Uri + ParseRefs + + val THIS_MODULE = "ParseLiterals" + + (*--------------------------------------------------------------------*) + (* parse a system literal, the quote character ("'" or '"') already --*) + (* read and passed as first argument. cf. 2.3: *) + (* *) + (* ... Note that a SystemLiteral can be parsed without scanning *) + (* for markup. *) + (* *) + (* [11] SystemLiteral ::= ('"' [^"]* '"') | ("'" [^']* "'") *) + (* *) + (* print an error and end the literal if an entity end is found. *) + (* *) + (* return the literal as a string together with the next character *) + (* and remaining state. *) + (*--------------------------------------------------------------------*) + (* might raise: none *) + (*--------------------------------------------------------------------*) + fun parseSystemLiteral' quote aq = + let + fun doit text (c,a,q) = + if c=quote then (text,getChar (a,q)) + else if c=0wx0 + then let val a1 = hookError(a,(getPos q,ERR_ENDED_BY_EE LOC_SYS_LIT)) + in (text,(c,a1,q)) + end + else if c>0wx7F andalso !O_WARN_NON_ASCII_URI + then let val a1 = hookWarning(a,(getPos q,WARN_NON_ASCII_URI c)) + in doit (c::text) (getChar(a1,q)) + end + else doit (c::text) (getChar(a,q)) + + val (text,caq1) = doit nil (getChar aq) + in + (Data2Uri(rev text),quote,caq1) + end + (*--------------------------------------------------------------------*) + (* parse a system literal. *) + (* *) + (* [11] SystemLiteral ::= ('"' [^"]* '"') | ("'" [^']* "'") *) + (* *) + (* raise NotFound if neither '"' nor "'" comes first. *) + (* *) + (* return the literal as a string together with the next character *) + (* and remaining state. *) + (*--------------------------------------------------------------------*) + (* might raise: NotFound *) + (*--------------------------------------------------------------------*) + fun parseSystemLiteral (c,a,q) = + if c=0wx22 (* "'" *) orelse + c=0wx27 (* '"' *) + then parseSystemLiteral' c (a,q) + else raise NotFound (c,a,q) + + (*--------------------------------------------------------------------*) + (* parse a pubid literal, the quote character ("'" or '"') already ---*) + (* read and passed as first argument. cf. 2.3: *) + (* *) + (* [12] PubidLiteral ::= '"' PubidChar* '"' *) + (* | "'" (PubidChar - "'")* "'" *) + (* *) + (* print an error and end the literal if an entity end is found. *) + (* print an error if a non-pubid character is found. *) + (* *) + (* return the literal as a string together with the next character *) + (* and remaining state. *) + (*--------------------------------------------------------------------*) + (* might raise: none *) + (*--------------------------------------------------------------------*) + fun parsePubidLiteral' quote aq = + let + fun doit (hadSpace,atStart,text) aq = + let val (c1,a1,q1) = getChar aq + in case c1 + of 0wx00 => let val a2 = hookError(a1,(getPos q1,ERR_ENDED_BY_EE LOC_PUB_LIT)) + in (text,(c1,a2,q1)) + end + | 0wx0A => doit (true,atStart,text) (a1,q1) + | 0wx20 => doit (true,atStart,text) (a1,q1) + | _ => + if c1=quote then (text,getChar (a1,q1)) + else if not (isPubid c1) + then let val err = ERR_FORBIDDEN_HERE(IT_CHAR c1,LOC_PUB_LIT) + val a2 = hookError(a1,(getPos q1,err)) + in doit (hadSpace,atStart,text) (a2,q1) + end + else if hadSpace andalso not atStart + then doit (false,false,c1::0wx20::text) (a1,q1) + else doit (false,false,c1::text) (a1,q1) + end + val (text,caq1) = doit (false,true,nil) aq + in + (Latin2String(rev text),quote,caq1) + end + (*--------------------------------------------------------------------*) + (* parse a pubid literal. *) + (* *) + (* [12] PubidLiteral ::= '"' PubidChar* '"' *) + (* | "'" (PubidChar - "'")* "'" *) + (* *) + (* raise NotFound if neither '"' nor "'" comes first. *) + (* *) + (* return the literal as a string together with the next character *) + (* and remaining state. *) + (*--------------------------------------------------------------------*) + (* might raise: NotFound *) + (*--------------------------------------------------------------------*) + fun parsePubidLiteral (c,a,q) = + if c=0wx22 (* "'" *) orelse + c=0wx27 (* '"' *) + then parsePubidLiteral' c (a,q) + else raise NotFound (c,a,q) + + (*--------------------------------------------------------------------*) + (* parse an entity value and the quote character ("'" or '"') passed *) + (* as first argument. Cf. 2.3: *) + (* *) + (* [9] EntityValue ::= '"' ([^%&"] | PEReference | Reference)* '"'*) + (* | "'" ([^%&'] | PEReference | Reference)* "'"*) + (* See also 4.4.5: *) + (* *) + (* When ... a parameter entity reference appears in a literal *) + (* entity value, its replacement text is processed in place of the *) + (* reference itself as though it were part of the document at the *) + (* location the reference was recognized, except that a single or *) + (* double quote character in the replacement text is always treated *) + (* as a normal data character and will not terminate the literal. *) + (* *) + (* and 4.4.7: *) + (* *) + (* When a general entity reference appears in the EntityValue in an *) + (* entity declaration, it is bypassed and left as is. *) + (* *) + (* A bypassed entity ref must, however, be checked for syntactic *) + (* validity, as opposed to SGML, where it is not even recognized. *) + (* *) + (* print an error and end the literal if an entity end is found at *) + (* the toplevel. *) + (* print an error if a general entity reference is ill-formed. *) + (* *) + (* handle any errors in references by ignoring them syntactically. *) + (* *) + (* return argument con applied to the entity value as a char buffer, *) + (* and the remaining char and state. *) + (*--------------------------------------------------------------------*) + (* might raise: none *) + (*--------------------------------------------------------------------*) + fun parseEntityValue' dtd (quote,con) aq = + let fun doit (level,hadCr,lit,text) (c1,a1,q1) = + case c1 + of 0wx00 => if level=0 then let val err = ERR_ENDED_BY_EE LOC_ENT_VALUE + val a2 = hookError(a1,(getPos q1,err)) + in (lit,text,(c1,a2,q1)) + end + else doit (level-1,false,lit,text) (getChar (a1,q1)) + | 0wx25 => (* #"%" *) + let val (level1,lit1,caq2) = + if inDocEntity q1 + then let val err = ERR_FORBIDDEN_HERE(IT_PAR_REF,LOC_INT_DECL) + val a2 = hookError(a1,(getPos q1,err)) + in (level,lit,skipReference (getChar(a2,q1))) + end + else + let val (lit1,((id,ent),(a2,q2))) = + if level=0 then parseParRefLit dtd (c1::lit) (getChar(a1,q1)) + else (lit,parseParRef dtd (getChar(a1,q1))) + in case ent + of PE_NULL => (level,lit1,getChar(a2,q2)) + | PE_INTERN(_,rep) => + let val q3 = pushIntern(q2,id,true,rep) + in (level+1,lit1,getChar(a2,q3)) + end + | PE_EXTERN extId => + let + val fname = resolveExtId extId + val caq3 = #3(openExtern (id,true,fname) (a2,q2)) + in (level+1,lit1,caq3) + end handle CantOpenFile(fmsg,a) + => let val err = ERR_NO_SUCH_FILE fmsg + val a1 = hookError(a,(getPos q1,err)) + in (level,lit1,getChar(a1,q1)) + end + end (* ignore syntax errors in references *) + handle SyntaxError caq => (level,lit,caq) + | NoSuchEntity aq => (level,lit,getChar aq) + in doit (level1,false,lit1,text) caq2 + end + | 0wx26 => (* #"&" *) + let val (c2,a2,q2) = getChar (a1,q1) + in (if c2=0wx23 (* #"#" *) + (*--------------------------------------------------*) + (* it's a character reference. *) + (*--------------------------------------------------*) + then (if level=0 + then + let val (lit3,(ch,a3,q3)) = + parseCharRefLit (c2::c1::lit) (a2,q2) + in doit (level,false,lit3,ch::text) (getChar(a3,q3)) + end + else let val (ch,a3,q3) = parseCharRef (a2,q2) + in doit (level,false,lit,ch::text) (getChar(a3,q3)) + end) + (* ignore errors in char references *) + handle SyntaxError caq => doit (level,false,lit,text) caq + | NoSuchChar aq => doit (level,false,lit,text) (getChar aq) + (*-----------------------------------------------------*) + (* it's a general entity reference. *) + (*-----------------------------------------------------*) + else let + val (fnd,lit3,text3,(c3,a3,q3)) = + parseEntName (c1::lit,c1::text) (c2,a2,q2) + val (lit4,text4,caq4) = + if not fnd then (lit,text,(c3,a3,q3)) + else if c3=0wx3B (* #";" *) + then (c3::lit3,c3::text3,(getChar(a3,q3))) + else let val err = ERR_EXPECTED(expSemi,[c3]) + val a4 = hookError(a3,(getPos q3,err)) + in (lit,text,(c3,a4,q3)) + end + in doit (level,false,lit4,text4) caq4 + end + ) + end + | 0wx0A => doit (level,false,if level=0 then c1::lit else lit, + if hadCr then text else c1::text) (getChar (a1,q1)) + | 0wx0D => doit (level,true,if level=0 then c1::lit else lit,0wx0A::text) + (getChar (a1,q1)) + | _ => if c1=quote andalso level=0 then (lit,text,getChar(a1,q1)) + else doit (level,false,if level=0 then c1::lit else lit,c1::text) + (getChar (a1,q1)) + + val (lit,text,caq1) = doit (0,false,nil,nil) (getChar aq) + val literal = Data2Vector(quote::rev(quote::lit)) + val repText = Data2Vector(rev text) + in + (con(literal,repText),caq1) + end + (*--------------------------------------------------------------------*) + (* parse an entity value. *) + (* *) + (* [9] EntityValue ::= '"' ([^%&"] | PEReference | Reference)* '"'*) + (* | "'" ([^%&'] | PEReference | Reference)* "'"*) + (* *) + (* raise NotFound if neither '"' nor "'" comes first. *) + (* *) + (* return the entity value as a char buffer, and the remaining char *) + (* and state. *) + (*--------------------------------------------------------------------*) + (* might raise: NotFound *) + (*--------------------------------------------------------------------*) + fun parseEntityValue dtd con (c,a,q) = + if c=0wx22 (* "'" *) orelse + c=0wx27 (* '"' *) + then parseEntityValue' dtd (c,con) (a,q) + else raise NotFound (c,a,q) + + (*--------------------------------------------------------------------*) + (* parse and normalize an attribute value, consume the final quote *) + (* character ("'" or '""') passed in the argument. Cf. 2.3: *) + (* *) + (* [10] AttValue ::= '"' ([^<&""] | Reference)* '"' *) + (* | "'" ([^<&'] | Reference)* "'" *) + (* See also 4.4.5: *) + (* *) + (* When an entity reference appears in an attribute value ..., *) + (* its replacement text is processed in place of the reference *) + (* itself as though it were part of the document at the location *) + (* the reference was recognized, except that a single or double *) + (* quote character in the replacement text is always treated as a *) + (* normal data character and will not terminate the literal. *) + (* *) + (* and 3.3.3: *) + (* *) + (* Before the value of an attribute is passed to the application *) + (* or checked for validity, the XML processor must normalize it as *) + (* follows: *) + (* *) + (* * a character reference is processed by appending the referenced *) + (* character to the attribute value *) + (* * an entity reference is processed by recursively processing the *) + (* replacement text of the entity *) + (* * a whitespace character (#x20, #xD, #xA, #x9) is processed by *) + (* appending #x20 to the normalized value, except that only a *) + (* single #x20 is appended for a "#xD#xA" sequence that is part *) + (* of an external parsed entity or the literal entity value of *) + (* an internal parsed entity *) + (* * other characters are processed by appending them to the *) + (* normalized value *) + (* *) + (* since #xD#xA are normalized by the parseEntityValue (internal) and *) + (* getChar (external entities), we don't need to care about that. *) + (*--------------------------------------------------------------------*) + (* print an error and end the literal if an entity end is found. *) + (* print an error if a general entity reference is ill-formed. *) + (* print an error if a reference to an external or unparsed entity is *) + (* found. *) + (* print an error if character '<' appears literally. *) + (* *) + (* handle any errors in references by ignoring them syntactically. *) + (* raise NotFound if neither '"' nor "'" comes first. *) + (* *) + (* return the list of chars in the value, and the next char and state *) + (*--------------------------------------------------------------------*) + (* might raise: NotFound *) + (*--------------------------------------------------------------------*) + fun parseAttValue dtd (quote,a,q) = + let fun doit (lhlt as (level,lit,text)) (c1,a1,q1) = + case c1 + of 0wx00 => if level=0 then let val err = ERR_ENDED_BY_EE LOC_ATT_VALUE + val a2 = hookError(a1,(getPos q1,err)) + in (lit,text,(c1,a2,q1)) + end + else doit (level-1,lit,text) (getChar (a1,q1)) + | 0wx26 => (* #"&" *) + let + val (c2,a2,q2) = getChar (a1,q1) + val ((level1,lit1,text1),caq3) = + (if c2=0wx23 (* #"#" *) + (*--------------------------------------------------*) + (* it's a character reference. *) + (*--------------------------------------------------*) + then if level=0 + then + let val (lit3,(ch,a3,q3)) = + parseCharRefLit (c2::c1::lit) (a2,q2) + in ((level,lit3,ch::text),getChar(a3,q3)) + end + else let val (ch,a3,q3) = parseCharRef (a2,q2) + in ((level,lit,ch::text),getChar (a3,q3)) + end + (*-----------------------------------------------------*) + (* it's a general entity reference. *) + (*-----------------------------------------------------*) + else + let val (lit3,((id,ent),(a3,q3))) = + if level=0 then parseGenRefLit dtd (c1::lit) (c2,a2,q2) + else (nil,parseGenRef dtd (c2,a2,q2)) + in case ent + of GE_NULL => ((level,lit3,text),getChar(a3,q3)) + | GE_INTERN(_,rep) => + let val q4 = pushIntern(q3,id,false,rep) + in ((level+1,lit3,text),getChar (a3,q4)) + end + | GE_EXTERN _ => + let val err = ERR_ILLEGAL_ENTITY + (ENT_EXTERNAL,Index2GenEnt dtd id,LOC_ATT_VALUE) + val a4 = hookError(a3,(getPos q2,err)) + in ((level,lit,text),getChar (a4,q3)) + end + | GE_UNPARSED _ => raise InternalError + (THIS_MODULE,"parseAttValue'", + "parseGenRef returned GE_UNPARSED") + end) + (*------------------------------------------------------*) + (* handle any errors in references by ignoring them. *) + (*------------------------------------------------------*) + handle SyntaxError caq => ((level,lit,text),caq) + | NoSuchEntity aq => ((level,lit,text),getChar aq) + | NoSuchChar aq => ((level,lit,text),getChar aq) + in doit (level1,lit1,text1) caq3 + end + | 0wx3C => let val err = ERR_FORBIDDEN_HERE(IT_CHAR c1,LOC_ATT_VALUE) + val a2 = hookError(a1,(getPos q1,err)) + val lit1 = if level=0 then c1::lit else lit + in doit (level,lit1,c1::text) (getChar (a2,q1)) + end + | _ => if isS c1 then doit (level,if level=0 then c1::lit else lit,0wx20::text) + (getChar (a1,q1)) + else (if c1=quote andalso level=0 then (lit,text,getChar (a1,q1)) + else doit (level,if level=0 then c1::lit else lit,c1::text) + (getChar (a1,q1))) + + + val _ = if quote=0wx22 orelse quote=0wx27 (* "'",'"' *) then () + else raise NotFound (quote,a,q) + val (lit,text,caq1) = doit (0,nil,nil) (getChar(a,q)) + in + (Data2Vector(quote::rev(quote::lit)),rev text,caq1) + end + end diff --git a/fxp/src/Parser/Parse/parseMisc.sml b/fxp/src/Parser/Parse/parseMisc.sml new file mode 100644 index 0000000..1899445 --- /dev/null +++ b/fxp/src/Parser/Parse/parseMisc.sml @@ -0,0 +1,299 @@ + + + + + + + + + + +signature ParseMisc = + sig + (*---------------------------------------------------------------------- + include ParseBase + + val parseName : UniChar.Char * AppData * State + -> UniChar.Data * (UniChar.Char * AppData * State) + val parseNmtoken : UniChar.Char * AppData * State + -> UniChar.Data * (UniChar.Char * AppData * State) + val parseNameLit : UniChar.Data -> UniChar.Char * AppData * State + -> UniChar.Data * UniChar.Data * (UniChar.Char * AppData * State) + val parseEntName : UniChar.Data * UniChar.Data -> UniChar.Char * AppData * State + -> bool * UniChar.Data * UniChar.Data * (UniChar.Char * AppData * State) + ----------------------------------------------------------------------*) + include ParseNames + + val skipS : UniChar.Char * AppData * State -> UniChar.Char * AppData * State + val skipSopt : UniChar.Char * AppData * State -> UniChar.Char * AppData * State + val skipSmay : UniChar.Char * AppData * State -> bool * (UniChar.Char * AppData * State) + + val parseSopt : UniChar.Data -> UniChar.Char * AppData * State + -> UniChar.Data * (UniChar.Char * AppData * State) + val parseSmay : UniChar.Data -> UniChar.Char * AppData * State + -> bool * (UniChar.Data * (UniChar.Char * AppData * State)) + + val skipEq : UniChar.Char * AppData * State + -> UniChar.Char * AppData * State + val parseEq : UniChar.Char * AppData * State + -> UniChar.Data * (UniChar.Char * AppData * State) + + val parseComment : Errors.Position -> AppData * State -> (UniChar.Char * AppData * State) + val parseProcInstr : Errors.Position -> AppData * State -> (UniChar.Char * AppData * State) + end + +(*--------------------------------------------------------------------------*) +(* Structure: ParseMisc *) +(* *) +(* Exceptions raised by functions in this structure: *) +(* skipS : none *) +(* skipSopt : none *) +(* skipSmay : none *) +(* skipEq : SyntaxError *) +(* skipComment : none *) +(* parseComment : none *) +(* parseProcInstr : none *) +(*--------------------------------------------------------------------------*) +functor ParseMisc (structure ParseBase : ParseBase) + : ParseMisc = +struct + structure ParseNames = ParseNames (structure ParseBase = ParseBase) + + open + UniChar Errors ParseNames + + (*--------------------------------------------------------------------*) + (* parse a sequence of white space. 2.3: *) + (* *) + (* [3] S ::= (#x20 | #x9 | #xD | #xA)+ *) + (*--------------------------------------------------------------------*) + (* parse optional white space. *) + (*--------------------------------------------------------------------*) + (* Return type: Char * AppData * State *) + (*--------------------------------------------------------------------*) + fun skipSopt (c,a,q) = + case c + of 0wx09 => skipSopt (getChar (a,q)) + | 0wx0A => skipSopt (getChar (a,q)) + | 0wx20 => skipSopt (getChar (a,q)) + | _ => (c,a,q) + fun parseSopt cs (c,a,q) = + case c + of 0wx09 => parseSopt (c::cs) (getChar (a,q)) + | 0wx0A => parseSopt (c::cs) (getChar (a,q)) + | 0wx20 => parseSopt (c::cs) (getChar (a,q)) + | _ => (cs,(c,a,q)) + (*--------------------------------------------------------------------*) + (* parse optional white space. *) + (*--------------------------------------------------------------------*) + (* Return type: bool * (Char * AppData * State) *) + (* the bool indicates whether white space was found or not. *) + (*--------------------------------------------------------------------*) + fun skipSmay (c,a,q) = + case c + of 0wx09 => (true,skipSopt (getChar (a,q))) + | 0wx0A => (true,skipSopt (getChar (a,q))) + | 0wx20 => (true,skipSopt (getChar (a,q))) + | _ => (false,(c,a,q)) + fun parseSmay cs (c,a,q) = + case c + of 0wx09 => (true,parseSopt (c::cs) (getChar (a,q))) + | 0wx0A => (true,parseSopt (c::cs) (getChar (a,q))) + | 0wx20 => (true,parseSopt (c::cs) (getChar (a,q))) + | _ => (false,(cs,(c,a,q))) + (*--------------------------------------------------------------------*) + (* parse required white space. *) + (*--------------------------------------------------------------------*) + (* print an error if no white space character is found. *) + (*--------------------------------------------------------------------*) + (* Return type: Char * AppData * State *) + (*--------------------------------------------------------------------*) + fun skipS (c,a,q) = + case c + of 0wx09 => skipSopt (getChar (a,q)) + | 0wx0A => skipSopt (getChar (a,q)) + | 0wx20 => skipSopt (getChar (a,q)) + | _ => (c,hookError(a,(getPos q,ERR_MISSING_WHITE)),q) + + (*--------------------------------------------------------------------*) + (* parse a "=" together with surrounding white space. Cf. 28: *) + (* *) + (* [25] Eq ::= S? '=' S? *) + (*--------------------------------------------------------------------*) + (* Raises: *) + (* SyntaxError if no "=" is found. *) + (*--------------------------------------------------------------------*) + (* Return type: Char * AppData * State *) + (*--------------------------------------------------------------------*) + fun skipEq caq = + let val (c1,a1,q1) = skipSopt caq + in if c1=0wx3D then skipSopt (getChar (a1,q1)) + else let val a2 = hookError(a1,(getPos q1,ERR_EXPECTED(expEq,[c1]))) + in raise SyntaxError(c1,a2,q1) + end + end + fun parseEq caq = + let val (cs1,(c1,a1,q1)) = parseSopt nil caq + in if c1=0wx3D + then let val (cs2,caq2)= parseSopt (c1::cs1) (getChar (a1,q1)) + in (rev cs2,caq2) + end + else let val a2 = hookError(a1,(getPos q1,ERR_EXPECTED(expEq,[c1]))) + in raise SyntaxError(c1,a2,q1) + end + end + + (*--------------------------------------------------------------------*) + (* parse a comment, the initial "<--" already consumed. cf. 2.5: *) + (* *) + (* They are not part of the document's character data; an XML *) + (* processor may, but need not, make it possible for an application *) + (* to retrieve the text of comments. For compatibility, the string *) + (* "--" (double-hyphen) must not occur within comments. *) + (* *) + (* [15] Comment ::= '' *) + (*--------------------------------------------------------------------*) + (* print an error and end the comment if an entity end is found. *) + (* print an error if the comment contains "--". *) + (*--------------------------------------------------------------------*) + (* add the comment to the user data. *) + (*--------------------------------------------------------------------*) + (* Return type: Char * AppData * State *) + (*--------------------------------------------------------------------*) + fun parseComment startPos aq = + let + fun check_end yet (a0,q0) = + let val (c,a,q) = getChar (a0,q0) + in if c=0wx2D (* #"-" *) + then let val (c1,a1,q1) = getChar (a,q) + in if c1=0wx3E (* #">" *) + then let val cs = Data2Vector(rev yet) + val a2 = hookComment(a1,((startPos,getPos q1),cs)) + in getChar(a2,q1) + end + else let val a2 = if not (!O_COMPATIBILITY) then a1 + else hookError(a1,(getPos q0,ERR_FORBIDDEN_HERE + (IT_DATA [c,c],LOC_COMMENT))) + in doit (c::c::yet) (c1,a2,q1) + end + end + else doit (0wx2D::yet) (c,a,q) + end + and doit yet (c,a,q) = + if c=0wx2D (* #"-" *) then check_end yet (a,q) + else if c<>0wx00 then doit (c::yet) (getChar (a,q)) + else let val err = ERR_ENDED_BY_EE LOC_COMMENT + val a1 = hookError(a,(getPos q,err)) + val cs = Data2Vector(rev yet) + val a2 = hookComment(a1,((startPos,getPos q),cs)) + in (c,a2,q) + end + in doit nil (getChar aq) + end + + (*--------------------------------------------------------------------*) + (* check whether a name matches "xml", disregarding case, cf. 2.6: *) + (* *) + (* [17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l')) *) + (* *) + (* The target names "XML", "xml", and so on are reserved for *) + (* standardization in this or future versions of this specification.*) + (*--------------------------------------------------------------------*) + (* print an error if it does match. *) + (*--------------------------------------------------------------------*) + (* Return type: AppData *) + (*--------------------------------------------------------------------*) + fun checkPiTarget (a,q) name = + case name + of [c1,c2,c3] => if ((c1=0wx58 orelse c1=0wx78) andalso + (c2=0wx4D orelse c2=0wx6D) andalso + (c3=0wx4C orelse c3=0wx6C)) + then hookError(a,(getPos q,ERR_RESERVED(name,IT_TARGET))) + else a + | _ => a + (*--------------------------------------------------------------------*) + (* parse a processing instruction, the initial "' Char* )))? '?>'*) + (* *) + (* The first arg consists of the target and the (reversed) list of *) + (* leading characters of the text that have been looked ahead. *) + (*--------------------------------------------------------------------*) + (* print an error and end the proc. instr. if an entity end is found. *) + (*--------------------------------------------------------------------*) + (* add the processing instruction to the user data. *) + (*--------------------------------------------------------------------*) + (* Return type: Char * AppData * State *) + (*--------------------------------------------------------------------*) + fun parseProcInstr' (startPos,target,txtPos,yetText) caq = + let + fun doit text (c1,a1,q1) = + case c1 + of 0wx00 => let val a2 = hookError(a1,(getPos q1,ERR_ENDED_BY_EE LOC_PROC)) + in (text,getPos q1,(c1,a2,q1)) + end + | 0wx3F => (* #"?" *) + let val (c2,a2,q2) = getChar (a1,q1) + in case c2 + of 0wx3E => (* #">" *) (text,getPos q2,getChar(a2,q2)) + | _ => doit (c1::text) (c2,a2,q2) + end + | _ => doit (c1::text) (getChar (a1,q1)) + + val (cs,endPos,(c2,a2,q2)) = doit yetText caq + val text = Data2Vector(rev cs) + val a3 = hookProcInst(a2,((startPos,endPos),target,txtPos,text)) + in + (c2,a3,q2) + end + (*--------------------------------------------------------------------*) + (* parse a processing instruction, the initial "' Char* )))? '?>'*) + (*--------------------------------------------------------------------*) + (* print an error and end the proc. instr. if an entity end is found. *) + (* print an error if no target name is found. *) + (* print an error if no whitespace follows the target. *) + (*--------------------------------------------------------------------*) + (* add the processing instruction to the user data. *) + (*--------------------------------------------------------------------*) + (* Return type: Char * AppData * State *) + (*--------------------------------------------------------------------*) + fun parseProcInstr startPos (a,q) = + let + (* NotFound is handled after the 'in .. end' *) + val (target,(c1,a1,q1)) = parseName (getChar(a,q)) + val a1 = checkPiTarget (a1,q) target + in + case c1 + of 0wx00 => + let + val a2 = hookError(a1,(getPos q1,ERR_ENDED_BY_EE LOC_PROC)) + val a3 = hookProcInst(a2,((startPos,getPos q1),target,getPos q1,nullVector)) + in (c1,a3,q1) + end + | 0wx3F => (* #"?" *) + let val (c2,a2,q2) = getChar (a1,q1) + in case c2 + of 0wx3E => (* #">" *) + let val a3 = hookProcInst(a2,((startPos,getPos q2),target, + getPos q1,nullVector)) + in getChar (a3,q2) + end + | _ => let val a3 = hookError(a2,(getPos q1,ERR_MISSING_WHITE)) + in parseProcInstr' (startPos,target,getPos q1,[c1]) (c2,a3,q2) + end + end + | _ => let val (hadS,(c2,a2,q2)) = skipSmay (c1,a1,q1) + val a3 = if hadS then a2 + else hookError(a2,(getPos q2,ERR_MISSING_WHITE)) + in parseProcInstr' (startPos,target,getPos q2,nil) (c2,a3,q2) + end + end + handle NotFound(c,a,q) => + let val a1 = hookError(a,(getPos q,ERR_EXPECTED(expATarget,[c]))) + in parseProcInstr' (startPos,nullData,getPos q,nil) (c,a1,q) + end +end diff --git a/fxp/src/Parser/Parse/parseNames.sml b/fxp/src/Parser/Parse/parseNames.sml new file mode 100644 index 0000000..db54b39 --- /dev/null +++ b/fxp/src/Parser/Parse/parseNames.sml @@ -0,0 +1,108 @@ + + + + + + + +signature ParseNames = + sig + include ParseBase + + val parseName : UniChar.Char * AppData * State + -> UniChar.Data * (UniChar.Char * AppData * State) + val parseNmtoken : UniChar.Char * AppData * State + -> UniChar.Data * (UniChar.Char * AppData * State) + + val parseNameLit : UniChar.Data -> UniChar.Char * AppData * State + -> UniChar.Data * UniChar.Data * (UniChar.Char * AppData * State) + val parseEntName : UniChar.Data * UniChar.Data -> UniChar.Char * AppData * State + -> bool * UniChar.Data * UniChar.Data * (UniChar.Char * AppData * State) + end + +(*--------------------------------------------------------------------------*) +(* Structure: ParseNames *) +(* *) +(* Exceptions raised by functions in this structure: *) +(* parseEntName : none *) +(* parseName : NotFound *) +(* parseNmtoken : NotFound *) +(*--------------------------------------------------------------------------*) +functor ParseNames (structure ParseBase : ParseBase) + : ParseNames = +struct + open + Errors ParseBase UniClasses + + (*--------------------------------------------------------------------*) + (* parse (the remainder of) a name or nmtoken. *) + (* *) + (* [5] Name ::= (Letter | '_' | ':') (NameChar)* *) + (* *) + (* raise NotFound if no name/name start character comes first. *) + (* *) + (* return the name as a list of characters, together with the next *) + (* character and the remaining state. *) + (*--------------------------------------------------------------------*) + (* XML 1.1 *) + (* [5] Name ::= NameStartChar (NameChar)* *) + (*--------------------------------------------------------------------*) + fun parseName' (c,a,q) = + if isName c + then let val (cs,caq1) = parseName'(getChar(a,q)) + in (c::cs,caq1) + end + else (nil,(c,a,q)) + fun parseName (c,a,q) = + if isNms c + then let val (cs,caq1) = parseName'(getChar(a,q)) + in (c::cs,caq1) + end + else raise NotFound(c,a,q) + fun parseNmtoken (c,a,q) = + if isName c + then let val (cs,caq1) = parseName'(getChar(a,q)) + in (c::cs,caq1) + end + else raise NotFound(c,a,q) + + (*--------------------------------------------------------------------*) + (* parse a name, additionally accumulating its characters in reverse *) + (* order to the first argument. *) + (* *) + (* raise NotFound if no name/name start character comes first. *) + (*--------------------------------------------------------------------*) + fun parseNameLit cs (c,a,q) = + let fun doit (cs,ns) (c,a,q) = + if isName c then doit (c::cs,c::ns) (getChar(a,q)) + else (cs,rev ns,(c,a,q)) + in + if isNms c then doit (c::cs,[c]) (getChar(a,q)) + else raise NotFound(c,a,q) + end + (*--------------------------------------------------------------------*) + (* parse a name, accumulating its reverse in the first arg text. This *) + (* is useful for parsing of entity values, where entity references *) + (* are parsed but bypassed, and must thus be accumulated together *) + (* the other literal text. *) + (* *) + (* print an error if no name/name start character comes first. *) + (* *) + (* return a boolean indicating whether a name was found, the reverse *) + (* name as a list of characters, concatenated with the text in the *) + (* first arg, together with the next character and remaining state. *) + (*--------------------------------------------------------------------*) + fun parseEntName (lit,text) (c,a,q) = + let + fun doit (lit,text) (c,a,q) = + if isName c then doit (c::lit,c::text) (getChar (a,q)) + else (true,lit,text,(c,a,q)) + in + if isNms c then doit (c::lit,c::text) (getChar (a,q)) + else let val a1 = hookError(a,(getPos q,ERR_EXPECTED(expAnEntName,[c]))) + in (false,lit,text,(c,a1,q)) + end + end + + end + diff --git a/fxp/src/Parser/Parse/parseRefs.sml b/fxp/src/Parser/Parse/parseRefs.sml new file mode 100644 index 0000000..a58b493 --- /dev/null +++ b/fxp/src/Parser/Parse/parseRefs.sml @@ -0,0 +1,720 @@ +signature ParseRefs = + sig + (*---------------------------------------------------------------------- + include ParseBase + + val parseName : UniChar.Char * AppData * State + -> UniChar.Data * (UniChar.Char * AppData * State) + val parseNmtoken : UniChar.Char * AppData * State + -> UniChar.Data * (UniChar.Char * AppData * State) + val parseEntName : UniChar.Data * UniChar.Data -> UniChar.Char * AppData * State + -> bool * UniChar.Data * UniChar.Data * (UniChar.Char * AppData * State) + + val parseComment : Errors.Position -> AppData * State -> (UniChar.Char * AppData * State) + val parseProcInstr : Errors.Position -> AppData * State -> (UniChar.Char * AppData * State) + val skipS : UniChar.Char * AppData * State -> UniChar.Char * AppData * State + val skipSopt : UniChar.Char * AppData * State -> UniChar.Char * AppData * State + val skipSmay : UniChar.Char * AppData * State -> bool * (UniChar.Char * AppData * State) + val parseSopt : UniChar.Data -> UniChar.Char * AppData * State + -> UniChar.Data * (UniChar.Char * AppData * State) + val parseSmay : UniChar.Data -> UniChar.Char * AppData * State + -> bool * (UniChar.Data * (UniChar.Char * AppData * State)) + val parseEq : UniChar.Char * AppData * State + -> UniChar.Data * (UniChar.Char * AppData * State) + + val openExtern : int * Uri.Uri -> AppData * State + -> Encoding.Encoding * HookData.TextDecl option * (UniChar.Char * AppData * State) + val openDocument : Uri.Uri option -> AppData + -> Encoding.Encoding * HookData.XmlDecl option * (UniChar.Char * AppData * State) + val openSubset : Uri.Uri -> AppData + -> Encoding.Encoding * HookData.TextDecl option * (UniChar.Char * AppData * State) + ----------------------------------------------------------------------*) + include ParseXml + + val parseCharRef : AppData * State -> UniChar.Char * AppData * State + val parseGenRef : Dtd -> UniChar.Char * AppData * State + -> (int * Base.GenEntity) * (AppData * State) + val parseParRef : Dtd -> UniChar.Char * AppData * State + -> (int * Base.ParEntity) * (AppData * State) + + val parseCharRefLit : UniChar.Data -> AppData * State + -> UniChar.Data * (UniChar.Char * AppData * State) + val parseGenRefLit : Dtd -> UniChar.Data -> UniChar.Char * AppData * State + -> UniChar.Data * ((int * Base.GenEntity) * (AppData * State)) + val parseParRefLit : Dtd -> UniChar.Data -> UniChar.Char * AppData * State + -> UniChar.Data * ((int * Base.ParEntity) * (AppData * State)) + + val skipCharRef : AppData * State -> (UniChar.Char * AppData * State) + val skipReference : UniChar.Char * AppData * State -> (UniChar.Char * AppData * State) + + val skipPS : Dtd -> UniChar.Char * AppData * State + -> UniChar.Char * AppData * State + val skipPSopt : Dtd -> UniChar.Char * AppData * State + -> UniChar.Char * AppData * State + val skipPSmay : Dtd -> UniChar.Char * AppData * State + -> bool * (UniChar.Char * AppData * State) + val skipPSdec : Dtd -> UniChar.Char * AppData * State + -> bool * (UniChar.Char * AppData * State) + end + +(*--------------------------------------------------------------------------*) +(* Structure: ParseRefs *) +(* *) +(* Exceptions raised by functions in this structure: *) +(* parseCharRef : NoSuchChar SyntaxError *) +(* parseGenRef : NoSuchEntity SyntaxState *) +(* parseParRef : NoSuchEntity SyntaxState *) +(* skipCharRef : none *) +(* skipPS : none *) +(* skipPSdec : none *) +(* skipPSmay : none *) +(* skipPSopt : none *) +(* skipReference : none *) +(*--------------------------------------------------------------------------*) +functor ParseRefs (structure ParseBase : ParseBase) + : ParseRefs = +struct + structure ParseXml = ParseXml (structure ParseBase = ParseBase) + + open + Base Errors UniClasses + ParseXml + + (*--------------------------------------------------------------------*) + (* parse a character reference, the "&#" already read. See 4.1: *) + (* *) + (* [66] CharRef ::= '&#' [0-9]+ ';' *) + (* | '&#x' [0-9a-fA-F]+ ';' [ WFC: Legal Character ] *) + (* *) + (* Well-Formedness Constraint: Legal Character *) + (* Characters referred to using character references must match the *) + (* production for Char. *) + (* *) + (* If the character reference begins with "&#x", the digits and *) + (* letters up to the terminating ; provide a hexadecimal *) + (* representation of the character's code point in ISO/IEC 10646. *) + (* If it begins just with "&#", the digits up to the terminating ; *) + (* provide a decimal representation of the character's code point. *) + (* *) + (* raise SyntaxError if no number or x plus hexnum is found, or if no *) + (* semicolon follows it. *) + (* raise NoSuchChar if the reference is to a non-XML character. *) + (* *) + (* return the character referred to, and the remaining state. *) + (*--------------------------------------------------------------------*) + fun parseCharRef aq = + let + (*--------------------------------------------------------------*) + (* parse a (hexa)decimal number, accumulating the value in the *) + (* first parameter. *) + (* *) + (* return the numbers value as a Char. *) + (*--------------------------------------------------------------*) + fun do_hex_n yet (c,a,q) = + case hexValue c + of NONE => (yet,(c,a,q)) + | SOME v => do_hex_n (0wx10*yet+v) (getChar (a,q)) + fun do_dec_n yet (c,a,q) = + case decValue c + of NONE => (yet,(c,a,q)) + | SOME v => do_dec_n (0wx0A*yet+v) (getChar (a,q)) + (*--------------------------------------------------------------*) + (* Parse a (hexa)decimal number of at least one digit. *) + (* *) + (* raise SyntaxError if no hexdigit is found first. *) + (* *) + (* return the numbers value as a Char. *) + (*--------------------------------------------------------------*) + fun do_hex_1 (c,a,q) = + case hexValue c + of SOME v => do_hex_n v (getChar (a,q)) + | NONE => let val a1 = hookError(a,(getPos q,ERR_EXPECTED(expHexDigit,[c]))) + in raise SyntaxError(c,a1,q) + end + (*--------------------------------------------------------------*) + (* Parse a decimal number of at least one digit, or a hexnumber *) + (* if the first character is 'x'. *) + (* *) + (* raise SyntaxError if neither 'x' nor digit is found first. *) + (* *) + (* return the number's value as a Char. *) + (*--------------------------------------------------------------*) + fun do_dec_1 (c,a,q) = + case decValue c + of SOME v => do_dec_n v (getChar (a,q)) + | NONE => if c=0wx78 (* #"x" *) + then do_hex_1 (getChar (a,q)) + else let val a1 = hookError(a,(getPos q,ERR_EXPECTED(expDigitX,[c]))) + in raise SyntaxError(c,a1,q) + end + + val (ch,(c1,a1,q1)) = do_dec_1 (getChar aq) + + val _ = if c1=0wx3B then () + else let val a2 = hookError(a1,(getPos q1,ERR_EXPECTED(expSemi,[c1]))) + in raise SyntaxError(c1,a2,q1) + end + + val _ = if isXml ch then () + else let val a2 = hookError(a1,(getPos q1,ERR_NON_XML_CHARREF ch)) + in raise NoSuchChar (a2,q1) + end + in (ch,a1,q1) + end + fun parseCharRefLit cs aq = + let + (*--------------------------------------------------------------*) + (* parse a (hexa)decimal number, accumulating the value in the *) + (* first parameter. *) + (* *) + (* return the numbers value as a Char. *) + (*--------------------------------------------------------------*) + fun do_hex_n (cs,yet) (c,a,q) = + case hexValue c + of NONE => (cs,yet,(c,a,q)) + | SOME v => do_hex_n (c::cs,0wx10*yet+v) (getChar (a,q)) + fun do_dec_n (cs,yet) (c,a,q) = + case decValue c + of NONE => (cs,yet,(c,a,q)) + | SOME v => do_dec_n (c::cs,0wx0A*yet+v) (getChar (a,q)) + (*--------------------------------------------------------------*) + (* Parse a (hexa)decimal number of at least one digit. *) + (* *) + (* raise SyntaxError if no hexdigit is found first. *) + (* *) + (* return the numbers value as a Char. *) + (*--------------------------------------------------------------*) + fun do_hex_1 cs (c,a,q) = + case hexValue c + of SOME v => do_hex_n (c::cs,v) (getChar (a,q)) + | NONE => let val a1 = hookError(a,(getPos q,ERR_EXPECTED(expHexDigit,[c]))) + in raise SyntaxError(c,a1,q) + end + (*--------------------------------------------------------------*) + (* Parse a decimal number of at least one digit, or a hexnumber *) + (* if the first character is 'x'. *) + (* *) + (* raise SyntaxError if neither 'x' nor digit is found first. *) + (* *) + (* return the number's value as a Char. *) + (*--------------------------------------------------------------*) + fun do_dec_1 cs (c,a,q) = + case decValue c + of SOME v => do_dec_n (c::cs,v) (getChar (a,q)) + | NONE => if c=0wx78 (* #"x" *) + then do_hex_1 (c::cs) (getChar (a,q)) + else let val a1 = hookError(a,(getPos q,ERR_EXPECTED(expDigitX,[c]))) + in raise SyntaxError(c,a1,q) + end + + val (cs1,ch,(c1,a1,q1)) = do_dec_1 cs (getChar aq) + + val _ = if c1=0wx3B then () + else let val a2 = hookError(a1,(getPos q1,ERR_EXPECTED(expSemi,[c1]))) + in raise SyntaxError(c1,a2,q1) + end + + val _ = if isXml ch then () + else let val a2 = hookError(a1,(getPos q1,ERR_NON_XML_CHARREF ch)) + in raise NoSuchChar (a2,q1) + end + in (c1::cs1,(ch,a1,q1)) + end + + (*--------------------------------------------------------------------*) + (* parse a general entity reference, the "&" already read. See 4.1: *) + (* *) + (* [68] EntityRef ::= '&' Name ';' [ WFC: Entity Declared ] *) + (* [ VC: Entity Declared ] *) + (* [ WFC: Parsed Entity ] *) + (* [ WFC: No Recursion ] *) + (* *) + (* Well-Formedness Constraint: Entity Declared *) + (* In a document without any DTD, a document with only an internal *) + (* DTD subset which contains no parameter entity references, or a *) + (* document with "standalone='yes'", the Name given in the entity *) + (* reference must match that in an entity declaration, ... *) + (* ... the declaration of a general entity must precede any *) + (* reference to it which appears in a default value in an *) + (* attribute-list declaration. *) + (* *) + (* Validity Constraint: Entity Declared *) + (* In a document with an external subset or external parameter *) + (* entities with "standalone='no'", the Name given in the entity *) + (* reference must match that in an entity declaration. ... *) + (* ... the declaration of a general entity must precede any *) + (* reference to it which appears in a default value in an *) + (* attribute-list declaration. *) + (* *) + (* Thus: in both cases it is an error if the entity is not declared. *) + (* The only difference is the impact on well-formednes/validity. *) + (* *) + (* There are three contexts in which a general entity reference can *) + (* appear: in content, in attribute value, in entity value. This *) + (* passage states that it need not be declared prior to a reference *) + (* in an entity value. But in this context, it is bypassed and not *) + (* included, i.e., it need not be recognized. *) + (* *) + (* Well-Formedness Constraint: Parsed Entity *) + (* An entity reference must not contain the name of an unparsed *) + (* entity. Unparsed entities may be referred to only in attribute *) + (* values ... *) + (* *) + (* Well-Formedness Constraint: No Recursion *) + (* A parsed entity must not contain a recursive reference to *) + (* itself, either directly or indirectly. *) + (* *) + (* print an error and raise SyntaxState if no name is found, or if no *) + (* semicolon follows it. *) + (* print an error and return GE_NULL if the reference is to an *) + (* undeclared, unparsed or open entity. *) + (* *) + (* return the entity referred to, and the remaining state. *) + (*--------------------------------------------------------------------*) + fun parseGenRef dtd (caq as (_,_,q)) = + let + val (name,(c1,a1,q1)) = parseName caq + handle NotFound (c,a,q) => let val err = ERR_EXPECTED(expAnEntName,[c]) + val a1 = hookError(a,(getPos q,err)) + in raise SyntaxError(c,a1,q) + end + val _ = if c1=0wx3B then () + else let val a2 = hookError(a1,(getPos q1,ERR_EXPECTED(expSemi,[c1]))) + in raise SyntaxError(c1,a2,q1) + end + + val idx = GenEnt2Index dtd name + val (ent,ext) = getGenEnt dtd idx + + val _ = (* check whether entity is undeclared/unparsed/open *) + case ent + of GE_NULL => + if entitiesWellformed dtd + then let val err = ERR_UNDEC_ENTITY(ENT_GENERAL,name) + val a2 = hookError(a1,(getPos q,err)) + in raise NoSuchEntity (a2,q1) + end + else if useParamEnts() + then let val err = ERR_UNDECLARED(IT_GEN_ENT,name,LOC_NONE) + val a2 = hookError(a1,(getPos q,err)) + in raise NoSuchEntity (a2,q1) + end + else () + | GE_UNPARSED _ => let val err = ERR_ILLEGAL_ENTITY(ENT_UNPARSED,name,LOC_NONE) + val a2 = hookError(a1,(getPos q,err)) + in raise NoSuchEntity (a2,q1) + end + | _ => if isOpen(idx,false,q1) + then let val err = ERR_RECURSIVE_ENTITY(ENT_GENERAL,name) + val a2 = hookError(a1,(getPos q,err)) + in raise NoSuchEntity (a2,q1) + end + else () + + val a2 = + if ext andalso !O_VALIDATE andalso standsAlone dtd andalso inDocEntity q1 + then let val _ = if !O_ERROR_MINIMIZE then setStandAlone dtd false else () + in hookError(a1,(getPos q,ERR_STANDALONE_ENT(ENT_GENERAL,name))) + end + else a1 + + in ((idx,ent),(a2,q1)) + end + fun parseGenRefLit dtd cs (caq as (_,_,q)) = + let + val (cs1,name,(c1,a1,q1)) = parseNameLit cs caq + handle NotFound (c,a,q) => let val err = ERR_EXPECTED(expAnEntName,[c]) + val a1 = hookError(a,(getPos q,err)) + in raise SyntaxError(c,a1,q) + end + val _ = if c1=0wx3B then () + else let val a2 = hookError(a1,(getPos q1,ERR_EXPECTED(expSemi,[c1]))) + in raise SyntaxError(c1,a2,q1) + end + + val idx = GenEnt2Index dtd name + val (ent,ext) = getGenEnt dtd idx + + val _ = (* check whether entity is undeclared/unparsed/open *) + case ent + of GE_NULL => + if entitiesWellformed dtd + then let val err = ERR_UNDEC_ENTITY(ENT_GENERAL,name) + val a2 = hookError(a1,(getPos q,err)) + in raise NoSuchEntity (a2,q1) + end + else if useParamEnts() + then let val err = ERR_UNDECLARED(IT_GEN_ENT,name,LOC_NONE) + val a2 = hookError(a1,(getPos q,err)) + in raise NoSuchEntity (a2,q1) + end + else () + | GE_UNPARSED _ => let val err = ERR_ILLEGAL_ENTITY(ENT_UNPARSED,name,LOC_NONE) + val a2 = hookError(a1,(getPos q,err)) + in raise NoSuchEntity (a2,q1) + end + | _ => if isOpen(idx,false,q1) + then let val err = ERR_RECURSIVE_ENTITY(ENT_GENERAL,name) + val a2 = hookError(a1,(getPos q,err)) + in raise NoSuchEntity (a2,q1) + end + else () + + val a2 = + if ext andalso !O_VALIDATE andalso standsAlone dtd andalso inDocEntity q1 + then let val _ = if !O_ERROR_MINIMIZE then setStandAlone dtd false else () + in hookError(a1,(getPos q,ERR_STANDALONE_ENT(ENT_GENERAL,name))) + end + else a1 + + in (c1::cs1,((idx,ent),(a2,q1))) + end + + (*--------------------------------------------------------------------*) + (* parse a parameter entity reference, the "%" already read. See 4.1: *) + (* *) + (* [69] PEReference ::= '%' Name ';' [ VC: Entity Declared ] *) + (* [ WFC: No Recursion ] *) + (* [ WFC: In DTD ] *) + (* *) + (* Well-Formedness Constraint: Entity Declared *) + (* In a document without any DTD, a document with only an internal *) + (* DTD subset which contains no parameter entity references, or a *) + (* document with "standalone='yes'", the Name given in the entity *) + (* reference must match that in an entity declaration, ... *) + (* The declaration of a parameter entity must precede any reference *) + (* to it... *) + (* *) + (* Validity Constraint: Entity Declared *) + (* In a document with an external subset or external parameter *) + (* entities with "standalone='no'", the Name given in the entity *) + (* reference must match that in an entity declaration. ... *) + (* The declaration of a parameter entity must precede any reference *) + (* to it... *) + (* *) + (* Thus: in both cases it is an error if the entity is not declared. *) + (* The only difference is the impact on well-formednes/validity. *) + (* Because the thing to be parsed is a parameter entity reference, *) + (* this DTD has references, and thus an undeclared entity is probably *) + (* a validity and not a well-formedness error. Thus setExternal must *) + (* be called before determining a possible error! *) + (* *) + (* Well-Formedness Constraint: No Recursion *) + (* A parsed entity must not contain a recursive reference to *) + (* itself, either directly or indirectly. *) + (* *) + (* print an error and raise SyntaxError if no name is found, or if no *) + (* semicolon follows it. *) + (* print an error and return PE_NULL if the reference is to an *) + (* undeclared or open entity. *) + (* *) + (* return the entity referred to, and the remaining state. *) + (*--------------------------------------------------------------------*) + fun parseParRef dtd (caq as (_,_,q)) = + let + val (name,(c1,a1,q1)) = parseName caq + handle NotFound(c,a,q) => let val err = ERR_EXPECTED(expAnEntName,[c]) + val a1 = hookError(a,(getPos q,err)) + in raise SyntaxError(c,a1,q) + end + + val _ = if c1=0wx3B then () + else let val err = ERR_EXPECTED(expSemi,[c1]) + val a2 = hookError(a1,(getPos q1,err)) + in raise SyntaxError(c1,a2,q1) + end + + val _ = setExternal dtd; + val idx = ParEnt2Index dtd name + val (ent,ext) = getParEnt dtd idx + + val _ = (* check whether entity is declared *) + case ent + of PE_NULL => + if entitiesWellformed dtd + then let val err = ERR_UNDEC_ENTITY(ENT_PARAMETER,name) + val a2 = hookError(a1,(getPos q,err)) + in raise NoSuchEntity (a2,q1) + end + else if useParamEnts() + then let val err = ERR_UNDECLARED(IT_PAR_ENT,name,LOC_NONE) + val a2 = hookError(a1,(getPos q,err)) + in raise NoSuchEntity (a2,q1) + end + else () + (* check whether the entity is already open *) + | _ => if isOpen(idx,true,q1) + then let val err = ERR_RECURSIVE_ENTITY(ENT_PARAMETER,name) + val a2 = hookError(a1,(getPos q,err)) + in raise NoSuchEntity (a2,q1) + end + else () + in ((idx,ent),(a1,q1)) + end + fun parseParRefLit dtd cs (caq as (_,_,q)) = + let + val (cs1,name,(c1,a1,q1)) = parseNameLit cs caq + handle NotFound(c,a,q) => let val err = ERR_EXPECTED(expAnEntName,[c]) + val a1 = hookError(a,(getPos q,err)) + in raise SyntaxError(c,a1,q) + end + + val _ = if c1=0wx3B then () + else let val err = ERR_EXPECTED(expSemi,[c1]) + val a2 = hookError(a1,(getPos q1,err)) + in raise SyntaxError(c1,a2,q1) + end + + val _ = setExternal dtd; + val idx = ParEnt2Index dtd name + val (ent,ext) = getParEnt dtd idx + + val _ = (* check whether entity is declared *) + case ent + of PE_NULL => + if entitiesWellformed dtd + then let val err = ERR_UNDEC_ENTITY(ENT_PARAMETER,name) + val a2 = hookError(a1,(getPos q,err)) + in raise NoSuchEntity (a2,q1) + end + else if useParamEnts() + then let val err = ERR_UNDECLARED(IT_PAR_ENT,name,LOC_NONE) + val a2 = hookError(a1,(getPos q,err)) + in raise NoSuchEntity (a2,q1) + end + else () + (* check whether the entity is already open *) + | _ => if isOpen(idx,true,q1) + then let val err = ERR_RECURSIVE_ENTITY(ENT_PARAMETER,name) + val a2 = hookError(a1,(getPos q,err)) + in raise NoSuchEntity (a2,q1) + end + else () + in (c1::cs1,((idx,ent),(a1,q1))) + end + + (*--------------------------------------------------------------------*) + (* skip a general/parameter entity reference, the "&/%" already read. *) + (* *) + (* print an error if no name is found, or if no semicolon follows it. *) + (* *) + (* handle any SyntaxState by returning its char and state. *) + (* *) + (* return the remaining state. *) + (*--------------------------------------------------------------------*) + fun skipReference caq = + let val (_,(c1,a1,q1)) = parseName caq + in if c1=0wx3B then getChar (a1,q1) + else let val err = ERR_EXPECTED(expSemi,[c1]) + val a2 = hookError(a1,(getPos q1,err)) + in (c1,a2,q1) + end + end + handle NotFound (c,a,q) => let val err = ERR_EXPECTED(expAnEntName,[c]) + val a1 = hookError(a,(getPos q,err)) + in (c,a1,q) + end + + (*--------------------------------------------------------------------*) + (* skip a character reference, the "&#" already read. See 4.1: *) + (* *) + (* print an error if no number or x plus hexnum is found, or if no *) + (* semicolon follows it. *) + (* *) + (* handle any SyntaxState by returning its char and state. *) + (* *) + (* return the remaining char and state. *) + (*--------------------------------------------------------------------*) + fun skipCharRef aq = + let + (*--------------------------------------------------------------*) + (* skip a (hexa)decimal number. *) + (*--------------------------------------------------------------*) + fun skip_ximal isX (c,a,q) = + if isX c then skip_ximal isX (getChar (a,q)) else (c,a,q) + + val (c1,a1,q1) = getChar aq + val (c2,a2,q2) = + if isDec c1 then skip_ximal isDec (getChar (a1,q1)) + else if c1=0wx78 (* #"x" *) + then let val (c2,a2,q2) = getChar (a1,q1) + in if isHex c2 then skip_ximal isHex (getChar (a2,q2)) + else let val err = ERR_EXPECTED(expHexDigit,[c2]) + val a3 = hookError(a2,(getPos q2,err)) + in raise SyntaxError(c2,a3,q2) + end + end + else let val a2 = hookError(a1,(getPos q1,ERR_EXPECTED(expDigitX,[c1]))) + in raise SyntaxError (c1,a2,q1) + end + + in if c2=0wx3B then getChar (a2,q2) + else (c2,hookError(a2,(getPos q2,ERR_EXPECTED(expSemi,[c2]))),q2) + end + handle SyntaxError caq => caq + + (*--------------------------------------------------------------------*) + (* parse a sequence of white space in markup declarations. Cf. 2.3: *) + (* *) + (* [3] S ::= (#x20 | #x9 | #xD | #xA)+ *) + (* *) + (* and 2.8 states: *) + (* *) + (* The markup declarations may be made up in whole or in part of *) + (* the replacement text of parameter entities. The productions *) + (* later in this specification for individual nonterminals *) + (* (elementdecl, AttlistDecl, and so on) describe the declarations *) + (* after all the parameter entities have been included. *) + (* *) + (* in markup declarations, we thus have to include entity references *) + (* and skip entity ends, except for the document end. *) + (* *) + (* Well-Formedness Constraint: PEs in Internal Subset *) + (* In the internal DTD subset, parameter-entity references can *) + (* occur only where markup declarations can occur, not within *) + (* markup declarations. (This does not apply to references that *) + (* occur in external parameter entities or to the external subset.) *) + (* *) + (* we therefore always check whether we are in the internal subset *) + (* before including a parameter entity. *) + (*--------------------------------------------------------------------*) + (* handle a parameter entity reference *) + (*--------------------------------------------------------------------*) + fun doParRef dtd (caq as (c,a,q)) = + if inDocEntity q + then let val err = ERR_FORBIDDEN_HERE(IT_PAR_REF,LOC_INT_DECL) + val a1 = hookError(a,(getPos q,err)) + in skipReference (c,a1,q) + end + else let val ((id,ent),(a1,q1)) = parseParRef dtd caq + in case ent + of PE_NULL => getChar (a1,q1) + | PE_INTERN (_,rep) => getChar(a1,(pushIntern(q1,id,true,rep))) + | PE_EXTERN extId => #3(openExtern(id,true,resolveExtId extId) (a1,q1)) + handle CantOpenFile(fmsg,a) + => let val err = ERR_NO_SUCH_FILE fmsg + val a1 = hookError(a,(getPos q1,err)) + in (getChar(a1,q1)) + end + end + handle SyntaxError caq => caq + | NoSuchEntity aq => getChar aq + (*--------------------------------------------------------------------*) + (* parse optional white space. *) + (* *) + (* catch SyntaxState exceptions from parameter refs. *) + (* *) + (* print an error if a parameter entity reference or an entity end is *) + (* found inside the internal subset. *) + (* *) + (* return the following character and the remaining state. *) + (*--------------------------------------------------------------------*) + fun skipPSopt dtd caq = + let fun doit (c,a,q) = + case c + of 0wx00 => + if isSpecial q then (c,a,q) + else let val a1 = if !O_VALIDATE andalso inDocEntity q + then hookError(a,(getPos q,ERR_EE_INT_SUBSET)) + else a + in doit (getChar (a1,q)) + end + | 0wx09 => doit (getChar (a,q)) + | 0wx0A => doit (getChar (a,q)) + | 0wx20 => doit (getChar (a,q)) + | 0wx25 (* #"%" *) => doit (doParRef dtd (getChar (a,q))) + | _ => (c,a,q) + in doit caq + end + (*--------------------------------------------------------------------*) + (* parse optional white space. *) + (* *) + (* catch SyntaxState exceptions from parameter refs. *) + (* *) + (* print an error if a parameter entity reference or an entity end is *) + (* found inside the internal subset. *) + (* *) + (* return a boolean whether white space was actually found, and the *) + (* following character with the remaining state. *) + (*--------------------------------------------------------------------*) + fun skipPSmay dtd (c,a,q) = + case c + of 0wx00 => + if isSpecial q then (false,(c,a,q)) + else let val a1 = if !O_VALIDATE andalso inDocEntity q + then hookError(a,(getPos q,ERR_EE_INT_SUBSET)) + else a + in (true,skipPSopt dtd (getChar (a1,q))) + end + | 0wx09 => (true,skipPSopt dtd (getChar (a,q))) + | 0wx0A => (true,skipPSopt dtd (getChar (a,q))) + | 0wx20 => (true,skipPSopt dtd (getChar (a,q))) + | 0wx25 (* #"%" *) => (true,skipPSopt dtd (doParRef dtd (getChar (a,q)))) + | _ => (false,(c,a,q)) + (*--------------------------------------------------------------------*) + (* parse required white space. *) + (* *) + (* catch SyntaxState exceptions from parameter refs. *) + (* *) + (* print an error and return if no white space character is found. *) + (* print an error if a parameter entity reference or an entity end is *) + (* found inside the internal subset. *) + (* *) + (* return the following character and the remaining state. *) + (*--------------------------------------------------------------------*) + fun skipPS dtd (c,a,q) = + case c + of 0wx00 => + if isSpecial q then (c,hookError(a,(getPos q,ERR_MISSING_WHITE)),q) + else let val a1 = if !O_VALIDATE andalso inDocEntity q + then hookError(a,(getPos q,ERR_EE_INT_SUBSET)) + else a + in skipPSopt dtd (getChar (a1,q)) + end + | 0wx09 => skipPSopt dtd (getChar (a,q)) + | 0wx0A => skipPSopt dtd (getChar (a,q)) + | 0wx20 => skipPSopt dtd (getChar (a,q)) + | 0wx25 (* #"%" *) => skipPSopt dtd (doParRef dtd (getChar (a,q))) + | _ => (c,hookError(a,(getPos q,ERR_MISSING_WHITE)),q) + (*--------------------------------------------------------------------*) + (* parse required white space, taking care of a single '%' character. *) + (* this is only needed before the entity name in an entity decl. *) + (* *) + (* catch SyntaxState exceptions from parameter refs. *) + (* *) + (* print an error if no white space character is found. *) + (* print an error if a parameter entity reference or an entity end is *) + (* found inside the internal subset. *) + (* *) + (* return a boolean whether a '%' was found, the following character *) + (* and the remaining state. *) + (*--------------------------------------------------------------------*) + fun skipPSdec dtd caq = + let fun doit req (c,a,q) = + case c + of 0wx00 => + if isSpecial q then (false,(c,a,q)) + else let val a1 = if !O_VALIDATE andalso inDocEntity q + then hookError(a,(getPos q,ERR_EE_INT_SUBSET)) + else a + in doit false (getChar (a1,q)) + end + | 0wx09 => doit false (getChar (a,q)) + | 0wx0A => doit false (getChar (a,q)) + | 0wx20 => doit false (getChar (a,q)) + | 0wx25 => (* #"%" *) + let val (c1,a1,q1) = getChar (a,q) + in if isNms c1 then doit false (doParRef dtd (c1,a1,q1)) + else let val a2 = if req then hookError(a1,(getPos q,ERR_MISSING_WHITE)) + else a1 + in (true,(c1,a2,q1)) + end + end + | _ => let val a1 = if req then hookError(a,(getPos q,ERR_MISSING_WHITE)) + else a + in (false,(c,a1,q)) + end + in + doit true caq + end +end diff --git a/fxp/src/Parser/Parse/parseTags.sml b/fxp/src/Parser/Parse/parseTags.sml new file mode 100644 index 0000000..63be9f7 --- /dev/null +++ b/fxp/src/Parser/Parse/parseTags.sml @@ -0,0 +1,329 @@ +signature ParseTags = + sig + (*---------------------------------------------------------------------- + include ParseBase + + val parseName : UniChar.Char * AppData * State + -> UniChar.Data * (UniChar.Char * AppData * State) + val parseNmtoken : UniChar.Char * AppData * State + -> UniChar.Data * (UniChar.Char * AppData * State) + + val parseComment : Errors.Position -> AppData * State -> (UniChar.Char * AppData * State) + val parseProcInstr : Errors.Position -> AppData * State -> (UniChar.Char * AppData * State) + val skipS : UniChar.Char * AppData * State -> UniChar.Char * AppData * State + val skipSopt : UniChar.Char * AppData * State -> UniChar.Char * AppData * State + val skipSmay : UniChar.Char * AppData * State -> bool * (UniChar.Char * AppData * State) + + val openExtern : int * Uri.Uri -> AppData * State + -> Encoding.Encoding * HookData.TextDecl option * (UniChar.Char * AppData * State) + val openDocument : Uri.Uri option -> AppData + -> Encoding.Encoding * HookData.XmlDecl option * (UniChar.Char * AppData * State) + val openSubset : Uri.Uri -> AppData + -> Encoding.Encoding * HookData.TextDecl option * (UniChar.Char * AppData * State) + + val skipCharRef : AppData * State -> (UniChar.Char * AppData * State) + val skipReference : UniChar.Char * AppData * State -> (UniChar.Char * AppData * State) + val parseGenRef : Dtd -> UniChar.Char * AppData * State + -> (int * Base.GenEntity) * (AppData * State) + val parseParRef : Dtd -> UniChar.Char * AppData * State + -> (int * Base.ParEntity) * (AppData * State) + val parseCharRefLit : UniChar.Data -> AppData * State + -> UniChar.Data * (UniChar.Char * AppData * State) + val skipPS : Dtd -> UniChar.Char * AppData * State + -> UniChar.Char * AppData * State + val skipPSopt : Dtd -> UniChar.Char * AppData * State + -> UniChar.Char * AppData * State + val skipPSmay : Dtd -> UniChar.Char * AppData * State + -> bool * (UniChar.Char * AppData * State) + val skipPSdec : Dtd -> UniChar.Char * AppData * State + -> bool * (UniChar.Char * AppData * State) + + val parseSystemLiteral : UniChar.Char * AppData * State + -> Uri.Uri * UniChar.Char * (UniChar.Char * AppData * State) + val parsePubidLiteral : UniChar.Char * AppData * State + -> string * UniChar.Char * (UniChar.Char * AppData * State) + val parseAttValue : Dtd -> UniChar.Char * AppData * State + -> UniChar.Vector * UniChar.Data * (UniChar.Char * AppData * State) + val parseEntityValue : Dtd -> (UniChar.Vector * UniChar.Vector -> 'a) + -> UniChar.Char * AppData * State + -> 'a * (UniChar.Char * AppData * State) + ----------------------------------------------------------------------*) + include ParseLiterals + + val skipTag : Errors.Location -> AppData * State -> (UniChar.Char * AppData * State) + + val parseETag : Dtd -> AppData * State + -> int * UniChar.Data * Errors.Position * (UniChar.Char * AppData * State) + val parseSTag : Dtd -> Errors.Position -> UniChar.Char * AppData * State + -> (HookData.StartTagInfo * Base.ElemInfo) * (UniChar.Char * AppData * State) + end + +(*--------------------------------------------------------------------------*) +(* Structure: ParseTags *) +(* *) +(* Exceptions raised by functions in this structure: *) +(* skipTag : none *) +(* parseETag : SyntaxState *) +(* parseSTag : SyntaxState *) +(*--------------------------------------------------------------------------*) +functor ParseTags (structure ParseBase : ParseBase) + : ParseTags = +struct + structure ParseLiterals = ParseLiterals (structure ParseBase = ParseBase) + + open + UtilList + Base Errors UniClasses + ParseLiterals + + (*--------------------------------------------------------------------*) + (* parse an end-tag, the "' *) + (* *) + (* and 3. states: *) + (* *) + (* Validity Constraint: Element Valid *) + (* An element is valid if there is a declaration matching elementdecl *) + (* where the Name matches the element type, and ... *) + (* *) + (* print an error, recover and raise SyntaxState if no name is found. *) + (* print an error and recover if no ">" is found. *) + (* print an error if the element is not declared. *) + (* *) + (* return the index of the element, and the next char and state. *) + (*--------------------------------------------------------------------*) + (* might raise: SyntaxState *) + (*--------------------------------------------------------------------*) + fun parseETag dtd aq = + let + val caq0 as (_,_,q0) = getChar aq + val (elem,(c1,a1,q1)) = parseName caq0 + handle NotFound (c,a,q) => let val err = expectedOrEnded (expAName,LOC_ETAG) c + val a1 = hookError(a,(getPos q,err)) + val caq1 = recoverETag (c,a1,q) + in raise SyntaxError caq1 + end + val idx = Element2Index dtd elem + val elemInfo as {decl,...} = getElement dtd idx + val a1' = if isSome decl then a1 + else let val a2 = if not (!O_VALIDATE andalso hasDtd dtd) then a1 + else let val err = ERR_UNDECLARED(IT_ELEM,elem,LOC_ETAG) + val a1' = hookError(a1,(getPos q0,err)) + val _ = if not (!O_ERROR_MINIMIZE) then () + else ignore (handleUndeclElement dtd idx) + in a1' + end + in checkElemName (a2,q0) elem + end + + val (cs,(c2,a2,q2)) = parseSopt nil (c1,a1',q1) + val space = rev cs + in + if c2=0wx3E (* #">" *) then (idx,space,getPos q2,getChar(a2,q2)) + else let val err = expectedOrEnded (expGt,LOC_ETAG) c2 + val a3 = hookError(a2,(getPos q2,err)) + val caq3 = recoverETag(c2,a3,q2) + in (idx,space,getPos q2,caq3) + end + end + + (*--------------------------------------------------------------------*) + (* parse a start-tag or an empty-element-tag, the "<" already read. *) + (* 3.1: *) + (* *) + (* [40] STag ::= '<' Name (S Attribute)* S? '>' *) + (* [ WFC: Unique Att Spec ] *) + (* [41] Attribute ::= Name Eq AttValue [ VC: Attribute Value Type ] *) + (* *) + (* Well-Formedness Constraint: Unique Att Spec *) + (* No attribute name may appear more than once in the same *) + (* start-tag or empty-element tag. *) + (* *) + (* Validity Constraint: Attribute Value Type *) + (* The attribute must have been declared; the value must be of the *) + (* type declared for it. *) + (* *) + (* [44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>' *) + (* [ WFC: Unique Att Spec ] *) + (* *) + (* and 3. states: *) + (* *) + (* Validity Constraint: Element Valid *) + (* An element is valid if there is a declaration matching elementdecl *) + (* where the Name matches the element type, and ... *) + (* *) + (* catch entity end exceptions in subfunctions by printing an error *) + (* and re-raising the exception. *) + (* *) + (* print an error, recover and raise SyntaxState if no element name *) + (* is found. *) + (* print an error and recover if no ">" or "/>" is found. *) + (* print an error and continue if no "=" is found after an att name. *) + (* print an error and recover if no literal is found after the "=". *) + (* print an error if white space is missing. *) + (* print an error if the element is not declared. *) + (* print an error and ignore the attribute if an attribute is *) + (* specified twice. *) + (* print an error if an attribute is not declared. *) + (* *) + (* return the index of the element, its ElemInfo, the list of *) + (* AttSpecs (specified and omitted atts) and a boolean whether it was *) + (* an empty-element-tag, together with the next char and state. *) + (*--------------------------------------------------------------------*) + (* might raise: SyntaxState *) + (*--------------------------------------------------------------------*) + fun parseSTag dtd startPos (caq as (_,_,q)) = + let + val (elem,(c1,a1,q1)) = parseName caq + handle NotFound (c,a,q) => let val err = expectedOrEnded (expAName,LOC_STAG) c + val a1 = hookError(a,(getPos q,err)) + val (_,caq1) = recoverSTag (c,a1,q) + in raise SyntaxError (c,a1,q) + end + val eidx = Element2Index dtd elem + val elemInfo as {atts,decl,...} = getElement dtd eidx + val defs = case atts + of NONE => nil + | SOME (defs,_) => defs + val (a1',elemInfo) = + if isSome decl then (a1,elemInfo) + else + let val (a2,newInfo) = + if not (!O_VALIDATE andalso hasDtd dtd) then (a1,elemInfo) + else let val err = ERR_UNDECLARED(IT_ELEM,elem,LOC_STAG) + val a1' = hookError(a1,(getPos q,err)) + val newInfo = if not (!O_ERROR_MINIMIZE) then elemInfo + else handleUndeclElement dtd eidx + in (a1',newInfo) + end + in (checkElemName (a2,q) elem,newInfo) + end + + val hscaq2 = parseSmay nil (c1,a1',q1) + + (*--------------------------------------------------------------*) + (* yet are the indices of attributes encountered yet, old are *) + (* the valid attributes specified yet, and todo are the defs of *) + (* attributes yet to be specified. hadS indicates whether white *) + (* space preceded. *) + (*--------------------------------------------------------------*) + fun doit (yet,old,todo) (hadS,(sp,(c,a,q))) = + case c + of 0wx3E (* #">" *) => (old,todo,sp,false,q,getChar(a,q)) + | 0wx2F (* #"/" *) => + let val (c1,a1,q1) = getChar(a,q) + in if c1=0wx3E (* #">" *) then (old,todo,sp,true,q1,getChar(a1,q1)) + else let val err = expectedOrEnded (expGt,LOC_STAG) c1 + val a2 = hookError(a1,(getPos q1,err)) + val (mt,caq2) = recoverSTag (c1,a2,q1) + in (old,todo,sp,mt,q,caq2) + end + end + | _ => + if not (isNms c) + then let val err = expectedOrEnded (expAttSTagEnd,LOC_STAG) c + val a1 = hookError(a,(getPos q,err)) + val (mt,caq1) = recoverSTag (c,a1,q) + in (old,todo,sp,mt,q,caq1) + end + else + let(* first parse the name of the attribute *) + val (att,(c1,a1,q1)) = parseName (c,a,q) + val a2 = if hadS then a1 + else hookError(a1,(getPos q,ERR_MISSING_WHITE)) + + (* now get its index, check whether it already *) + (* occurred and get its definition. *) + val aidx = AttNot2Index dtd att + val (hadIt,a3) = + if member aidx yet + then (true,hookError(a2,(getPos q,ERR_MULT_ATT_SPEC att))) + else (false,a2) + + val (def,rest) = findAndDelete (fn (i,_,_,_) => i=aidx) todo + val a4 = if isSome def orelse hadIt then a3 + else handleUndeclAtt dtd (a3,q) (aidx,att,eidx,elem) + + (* consume the " = ", ignore errors *) + val (eq,caq5 as (_,_,q5)) = parseEq (c1,a4,q1) + handle SyntaxError caq => ([0wx3D],caq) + + (* now parse the attribute value *) + val (literal,value,(c6,a6,q6)) = parseAttValue dtd caq5 + + (* possibly make a new AttSpec *) + val space = rev sp + val (new,a7) = + if hadIt then (old,a6) + else case def + of NONE => + if !O_VALIDATE andalso hasDtd dtd then (old,a6) + else (let val (attVal,a7) = checkAttValue dtd (a6,q5) + (defaultAttDef aidx,literal,value) + in ((aidx,attVal,SOME(space,eq))::old,a7) + end + handle AttValue a => (old,a)) + | SOME ad => + let val (attVal,a7) = checkAttValue dtd (a6,q5) + (ad,literal,value) + in ((aidx,attVal,SOME(space,eq))::old,a7) + end + handle AttValue a => (old,a) + val hscaq8 = parseSmay nil (c6,a7,q6) + in + doit (aidx::yet,new,rest) hscaq8 + end + handle NotFound (c,a,q) (* raised by parseAttValue above *) + => let val err = expectedOrEnded (expLitQuote,LOC_STAG) c + val a1 = hookError(a,(getPos q,err)) + val (mt,caq1) = recoverSTag (c,a1,q) + in (old,todo,sp,mt,q,caq1) + end + + val (specd,todo,sp,empty,qe,(c3,a3,q3)) = doit (nil,nil,defs) hscaq2 + val space = rev sp + + (* generate the defaults for unspecified attributes *) + val (all,a4) = genMissingAtts dtd (a3,qe) (todo,rev specd) + in + ((((startPos,getPos q3),eidx,all,space,empty),elemInfo),(c3,a4,q3)) + end + + (*--------------------------------------------------------------------*) + (* skip a tag, the initial "<" or "" and *) + (* "/>" if within a literal. *) + (* *) + (* print an error and finish if an entity end is found. *) + (* *) + (* return the remaining char and state. *) + (*--------------------------------------------------------------------*) + (* might raise: none *) + (*--------------------------------------------------------------------*) + fun skipTag loc aq = + let + fun do_lit ch (c,a,q) = + if c=0wx00 then let val a1 = hookError(a,(getPos q,ERR_ENDED_BY_EE loc)) + in (c,a1,q) + end + else if c=ch then doit (getChar(a,q)) + else do_lit ch (getChar(a,q)) + + and doit (c,a,q) = + case c + of 0wx00 => let val a1 = hookError(a,(getPos q,ERR_ENDED_BY_EE loc)) + in (c,a1,q) + end + | 0wx22 (* #"\""*) => do_lit c (getChar(a,q)) + | 0wx27 (* #"'" *) => do_lit c (getChar(a,q)) + | 0wx2F (* #"/" *) => (case getChar(a,q) + of (0wx3E,a1,q1) (* #">" *) => getChar(a1,q1) + | caq1 => doit caq1) + | 0wx3E (* #">" *) => getChar(a,q) + | _ => doit(getChar(a,q)) + in doit (getChar aq) + end +end + diff --git a/fxp/src/Parser/Parse/parseXml.sml b/fxp/src/Parser/Parse/parseXml.sml new file mode 100644 index 0000000..f3f81fd --- /dev/null +++ b/fxp/src/Parser/Parse/parseXml.sml @@ -0,0 +1,679 @@ +signature ParseXml = + sig + (*---------------------------------------------------------------------- + include ParseBase + + val parseName : UniChar.Char * AppData * State + -> UniChar.Data * (UniChar.Char * AppData * State) + val parseNmtoken : UniChar.Char * AppData * State + -> UniChar.Data * (UniChar.Char * AppData * State) + val parseNameLit : UniChar.Data -> UniChar.Char * AppData * State + -> UniChar.Data * UniChar.Data * (UniChar.Char * AppData * State) + val parseEntName : UniChar.Data * UniChar.Data -> UniChar.Char * AppData * State + -> bool * UniChar.Data * UniChar.Data * (UniChar.Char * AppData * State) + + val parseComment : Errors.Position -> AppData * State -> (UniChar.Char * AppData * State) + val parseProcInstr : Errors.Position -> AppData * State -> (UniChar.Char * AppData * State) + val skipS : UniChar.Char * AppData * State -> UniChar.Char * AppData * State + val skipSopt : UniChar.Char * AppData * State -> UniChar.Char * AppData * State + val skipSmay : UniChar.Char * AppData * State -> bool * (UniChar.Char * AppData * State) + val parseSopt : UniChar.Data -> UniChar.Char * AppData * State + -> UniChar.Data * (UniChar.Char * AppData * State) + val parseSmay : UniChar.Data -> UniChar.Char * AppData * State + -> bool * (UniChar.Data * (UniChar.Char * AppData * State)) + val parseEq : UniChar.Char * AppData * State + -> UniChar.Data * (UniChar.Char * AppData * State) + ----------------------------------------------------------------------*) + include ParseMisc + + val openDocument : Uri.Uri option -> AppData + -> Encoding.Encoding * HookData.XmlDecl option * (UniChar.Char * AppData * State) + val openSubset : Uri.Uri -> AppData + -> Encoding.Encoding * HookData.TextDecl option * (UniChar.Char * AppData * State) + val openExtern : int * bool * Uri.Uri -> AppData * State + -> Encoding.Encoding * HookData.TextDecl option * (UniChar.Char * AppData * State) + end + +(*--------------------------------------------------------------------------*) +(* Structure: ParseXml *) +(* *) +(* Exceptions raised by functions in this structure: *) +(* openDocument : NoSuchFile *) +(* openExtern : none *) +(* openSubset : NoSuchFile *) +(*--------------------------------------------------------------------------*) +functor ParseXml (structure ParseBase : ParseBase) + : ParseXml = +struct + structure ParseMisc = ParseMisc (structure ParseBase = ParseBase) + + open + Errors UniChar UniClasses UtilString + ParseMisc + + fun checkVersionNum (a,q) version = + if not (!O_CHECK_VERSION) orelse version="1.0" orelse version ="1.1" then a (* XML 1.1 also allowed *) + else hookError(a,(getPos q,ERR_VERSION version)) + + (*--------------------------------------------------------------------*) + (* parse a version number, the quote character ("'" or '"') passed as *) + (* first argument. cf. 2.8: *) + (* *) + (* [24] VersionInfo ::= S 'version' Eq (' VersionNum ' *) + (* | " VersionNum ") *) + (* [26] VersionNum ::= ([a-zA-Z0-9_.:] | '-')+ *) + (* *) + (* print an error and end the literal if an entity end is found. *) + (* print an error if a disallowed character is found. *) + (* *) + (* return the version number as a string option, together with the *) + (* next character and state. *) + (*--------------------------------------------------------------------*) + (* might raise: none *) + (*--------------------------------------------------------------------*) + fun parseVersionNum quote aq = + let + fun doit text (c,a,q) = + if c=quote then (text,getChar (a,q)) + else if isVers c then doit (c::text) (getChar (a,q)) + else if c=0wx0 + then let val a1 = hookError(a,(getPos q,ERR_ENDED_BY_EE LOC_VERSION)) + in (text,(c,a1,q)) + end + else let val err = ERR_FORBIDDEN_HERE(IT_CHAR c,LOC_VERSION) + val a1 = hookError(a,(getPos q,err)) + in doit text (getChar (a1,q)) + end + + val (c1,a1,q1) = getChar aq + + val (text,(c2,a2,q2)) = + if isVers c1 then doit [c1] (getChar (a1,q1)) + else if c1=quote + then let val a2 = hookError(a1,(getPos q1,ERR_EMPTY LOC_VERSION)) + in (nil,getChar (a2,q1)) + end + else if c1=0wx00 + then let val a2 = hookError(a1,(getPos q1,ERR_ENDED_BY_EE LOC_VERSION)) + val a3 = hookError(a2,(getPos q1,ERR_EMPTY LOC_VERSION)) + in (nil,(c1,a3,q1)) + end + else let val err = ERR_FORBIDDEN_HERE(IT_CHAR c1,LOC_VERSION) + val a2 = hookError(a1,(getPos q1,err)) + in doit nil (getChar (a2,q1)) + end + val version = Latin2String (rev text) + val a3 = checkVersionNum (a2,q1) version + in + (SOME version,(c2,a3,q2)) + end + (*--------------------------------------------------------------------*) + (* parse a version info starting after 'version'. Cf. 2.8: *) + (* *) + (* [24] VersionInfo ::= S 'version' Eq (' VersionNum ' *) + (* | " VersionNum ") *) + (* *) + (* print an error and raise SyntaxState if no '=' is found. *) + (* print an error and raise SyntaxState if no quote sign is found. *) + (* *) + (* return the version number as a string option, together with the *) + (* next char and the remaining state. *) + (*--------------------------------------------------------------------*) + (* might raise: SyntaxState *) + (*--------------------------------------------------------------------*) + fun parseVersionInfo caq = + let val (c1,a1,q1) = skipEq caq + in case c1 + of 0wx22 (* '""' *) => parseVersionNum c1 (a1,q1) + | 0wx27 (* "'" *) => parseVersionNum c1 (a1,q1) + | _ => let val a2 = hookError(a1,(getPos q1,ERR_EXPECTED(expLitQuote,[c1]))) + in raise SyntaxError(c1,a2,q1) + end + end + + (*--------------------------------------------------------------------*) + (* parse an encoding name, the quote character ("'" or '"') passed as *) + (* first argument. cf. 4.3.3: *) + (* *) + (* [80] EncodingDecl ::= S 'encoding' Eq ('"' EncName '"' *) + (* |"'" EncName "'") *) + (* *) + (* [81] EncName ::= [A-Za-z] /* Encoding name *) + (* ([A-Za-z0-9._] | '-')* contains only Latin *) + (* characters */ *) + (* *) + (* print an error and end the literal if an entity end is found. *) + (* print an error if a disallowed character is found. *) + (* *) + (* return the encoding name as a string option, together with the *) + (* next character and state. *) + (*--------------------------------------------------------------------*) + (* might raise: none *) + (*--------------------------------------------------------------------*) + fun parseEncName quote aq = + let + fun doit text (c,a,q) = + if c=quote then (text,getChar (a,q)) + else if isEnc c then doit (c::text) (getChar (a,q)) + else if c=0wx00 + then let val a1 = hookError(a,(getPos q,ERR_ENDED_BY_EE LOC_ENCODING)) + in (text,(c,a1,q)) + end + else let val err = ERR_FORBIDDEN_HERE(IT_CHAR c,LOC_ENCODING) + val a1 = hookError(a,(getPos q,err)) + in doit text (getChar (a,q)) + end + + val (c1,a1,q1) = getChar aq + + val (text,caq2) = + if isEncS c1 then doit [c1] (getChar (a1,q1)) + else if c1=quote + then let val a2 = hookError(a1,(getPos q1,ERR_EMPTY LOC_ENCODING)) + in (nil,getChar (a2,q1)) + end + else if c1=0wx00 + then let val a2 = hookError(a1,(getPos q1,ERR_ENDED_BY_EE LOC_ENCODING)) + val a3 = hookError(a2,(getPos q1,ERR_EMPTY LOC_ENCODING)) + in (nil,(c1,a3,q1)) + end + else let val a2 = hookError(a1,(getPos q1,ERR_EXPECTED(expStartEnc,[c1]))) + in doit nil (getChar (a2,q1)) + end + + val enc = toUpperString (Latin2String (rev text)) + in + (enc,caq2) + end + (*--------------------------------------------------------------------*) + (* parse an encoding decl starting after 'encoding'. Cf. 4.3.3: *) + (* *) + (* *) + (* [80] EncodingDecl ::= S 'encoding' Eq ('"' EncName '"' *) + (* |"'" EncName "'") *) + (* *) + (* print an error and raise SyntaxState if no '=' is found. *) + (* print an error and raise SyntaxState if no quote sign is found. *) + (* *) + (* return the encoding name as a string option, together with the *) + (* next char and the remaining state. *) + (*--------------------------------------------------------------------*) + (* might raise: SyntaxState *) + (*--------------------------------------------------------------------*) + fun parseEncodingDecl caq = + let val (c1,a1,q1) = skipEq caq + in case c1 + of 0wx22 (* '""' *) => parseEncName c1 (a1,q1) + | 0wx27 (* "'" *) => parseEncName c1 (a1,q1) + | _ => let val a2 = hookError(a1,(getPos q1,ERR_EXPECTED(expLitQuote,[c1]))) + in raise SyntaxError(c1,a2,q1) + end + end + + (*--------------------------------------------------------------------*) + (* parse a standalone declaration starting after 'standalone'. *) + (* Cf. 2.9: *) + (* *) + (* [32] SDDecl ::= S 'standalone' Eq [ VC: Standalone *) + (* ( ("'" ('yes' | 'no') "'") Document *) + (* | ('"' ('yes' | 'no') '"')) Declaration ] *) + (* *) + (* print an error and raise SyntaxState if no '=' is found. *) + (* print an error and raise SyntaxState if no literal is found. *) + (* print an error and end the literal if an entity end is found. *) + (* print an error if the literal is neither 'yes' nor 'no'. *) + (* *) + (* return the standalone status as a boolean option, together with *) + (* the next character and the remaining state. *) + (*--------------------------------------------------------------------*) + (* might raise: SyntaxState *) + (*--------------------------------------------------------------------*) + fun parseStandaloneDecl caq0 = + let + val (quote,a,q) = skipEq caq0 + + fun doit text (c,a,q) = + if c=quote then (text,getChar (a,q)) + else if c<>0wx0 then doit (c::text) (getChar (a,q)) + else let val a1 = hookError(a,(getPos q,ERR_ENDED_BY_EE LOC_LITERAL)) + in (text,(c,a1,q)) + end + + val caq1 as (_,_,q1) = + case quote + of 0wx22 (* '""' *) => (getChar (a,q)) + | 0wx27 (* "'" *) => (getChar (a,q)) + | _ => let val a1 = hookError(a,(getPos q,ERR_EXPECTED(expLitQuote,[quote]))) + in raise SyntaxError(quote,a1,q) + end + val (text,caq2) = doit nil caq1 + in + case text + of [0wx73,0wx65,0wx79] (* reversed "yes" *) => (SOME true,caq2) + | [0wx6f,0wx6e] (* reversed "no" *) => (SOME false,caq2) + | revd => let val (c2,a2,q2) = caq2 + val a3 = hookError(a2,(getPos q1,ERR_EXPECTED(expNoYes,revd))) + in (NONE,(c2,a3,q2)) + end + end + + (*--------------------------------------------------------------------*) + (* parse an xml declaration starting after 'xml ' (i.e. the first *) + (* white space character is already consumed). Cf. 2.8: *) + (* *) + (* [23] XMLDecl ::= ''*) + (* *) + (* [24] VersionInfo ::= S 'version' Eq (' VersionNum ' *) + (* | " VersionNum ") *) + (* *) + (* [32] SDDecl ::= S 'standalone' Eq [ VC: Standalone *) + (* ( ("'" ('yes' | 'no') "'") Document *) + (* | ('"' ('yes' | 'no') '"')) Declaration ] *) + (* *) + (* [80] EncodingDecl ::= S 'encoding' Eq ('"' EncName '"' *) + (* |"'" EncName "'") *) + (* *) + (* default version, encoding and standalone status to NONE. *) + (* *) + (* print an error if no leading white space is found. *) + (* print an error whenever a wrong name is encountered. *) + (* print an Error if no VersionInfo is found. *) + (* print an Error if no '?>' is found at the end. *) + (* print an error and raise SyntaxState if no '=' or no literal is *) + (* found in VersionInfo, EncodingDecl or SDDecl. *) + (* print an error if a literal does not have a correct value. *) + (* *) + (* return the corresponding XmlDecl option and the next char & state. *) + (*--------------------------------------------------------------------*) + (* might raise: SyntaxState *) + (*--------------------------------------------------------------------*) + fun parseXmlDecl auto caq = + let + (*-----------------------------------------------------------------*) + (* skip the '?>' at the end of the xml declaration. *) + (* *) + (* print an error and raise SyntaxState if no '?>' is found. *) + (* *) + (* return the info passed as first arg, and the next char & state. *) + (*-----------------------------------------------------------------*) + (* might raise: SyntaxState *) + (*-----------------------------------------------------------------*) + fun skipXmlDeclEnd enc res (c,a,q) = + if c=0wx3F (* "#?" *) + then let val (c1,a1,q1) = getChar (a,q) + in if c1=0wx3E (* #">" *) then (enc,SOME res,getChar (a1,q1)) + else let val a2 = hookError(a1,(getPos q1,ERR_EXPECTED(expGt,[c1]))) + in raise SyntaxError (c1,a2,q1) + end + end + else let val a1 = hookError(a,(getPos q,ERR_EXPECTED(expProcEnd,[c]))) + in raise SyntaxError (c,a1,q) + end + (*-----------------------------------------------------------------*) + (* parse the remainder after the keyword 'standalone', the version *) + (* and encoding already parsed and given in the first arg. *) + (* *) + (* pass the version,encoding and sd status to skipXmlDeclEnd *) + (*-----------------------------------------------------------------*) + (* might raise: SyntaxState *) + (*-----------------------------------------------------------------*) + fun parseXmlDeclAfterS enc (v,e) caq = + let + val (alone,caq1) = parseStandaloneDecl caq + val caq2 = skipSopt caq1 + in skipXmlDeclEnd enc (v,e,alone) caq2 + end + (*-----------------------------------------------------------------*) + (* parse the remainder after the encoding declaration, the version *) + (* and encoding already parsed and given in the first arg. *) + (* *) + (* print an error if a name other than 'standalone' is found. *) + (* *) + (* pass the version and encoding to parseXmlDeclAfterS. *) + (*-----------------------------------------------------------------*) + (* might raise: SyntaxState *) + (*-----------------------------------------------------------------*) + fun parseXmlDeclBeforeS enc (v,e) caq = + let + val (hadS,caq1 as (_,_,q1)) = skipSmay caq + val (name,(c2,a2,q2)) = parseName caq1 (* NotFound handled below *) + val a3 = if hadS then a2 + else hookError(a2,(getPos q1,ERR_MISSING_WHITE)) + in case name + of [0wx73,0wx74,0wx61,0wx6e,0wx64,0wx61,0wx6c,0wx6f,0wx6e,0wx65] => + (* "standalone" *) parseXmlDeclAfterS enc (v,e) (c2,a3,q2) + | _ => let val a4 = hookError(a3,(getPos q1,ERR_EXPECTED(expStandOpt,name))) + in parseXmlDeclAfterS enc (v,e) (c2,a4,q2) + end + end + handle NotFound caq => (* exception raised by parseName *) + skipXmlDeclEnd enc (v,e,NONE) caq + (*-----------------------------------------------------------------*) + (* parse the remainder after the keyword 'encoding', the version *) + (* already parsed and given in the first arg. *) + (* *) + (* pass the version and encoding and to parseXmlDeclBeforeS *) + (*-----------------------------------------------------------------*) + (* might raise: SyntaxState *) + (*-----------------------------------------------------------------*) + fun parseXmlDeclAfterE ver caq = + let + val (enc,(c1,a1,q1)) = parseEncodingDecl caq + val (a2,q2,enc1) = changeAuto(a1,q1,enc) + in + parseXmlDeclBeforeS enc1 (ver,SOME enc) (c1,a2,q2) + end + (*-----------------------------------------------------------------*) + (* parse the remainder after the version info, the version already *) + (* parsed and given in the first arg. *) + (* *) + (* print an error if a name other than 'encoding' or 'standalone' *) + (* is found. *) + (* *) + (* pass obtained/default values to parseXmlDeclAfter[E|S] or to *) + (* skipXmlDeclEnd. *) + (*-----------------------------------------------------------------*) + (* might raise: SyntaxState *) + (*-----------------------------------------------------------------*) + fun parseXmlDeclBeforeE ver caq = + let + val (hadS,caq1 as (_,_,q1)) = skipSmay caq + val (name,(c2,a2,q2)) = parseName caq1 (* NotFound handled below *) + val a3 = if hadS then a2 + else hookError(a2,(getPos q1,ERR_MISSING_WHITE)) + in + case name + of [0wx65,0wx6e,0wx63,0wx6f,0wx64,0wx69,0wx6e,0wx67] => + (* "encoding" *) parseXmlDeclAfterE ver (c2,a3,q2) + | [0wx73,0wx74,0wx61,0wx6e,0wx64,0wx61,0wx6c,0wx6f,0wx6e,0wx65] => + (* "standalone" *) parseXmlDeclAfterS auto (ver,NONE) (c2,a3,q2) + | _ => let val a4 = hookError(a3,(getPos q1,ERR_EXPECTED(expEncStand,name))) + in parseXmlDeclAfterE ver (c2,a4,q2) + end + end + handle NotFound caq => (* exception raised by parseName *) + skipXmlDeclEnd auto (ver,NONE,NONE) caq + + (*-----------------------------------------------------------------*) + (* do the main work. if the first name is not 'version' then it *) + (* might be 'encoding' or 'standalone'. Then take the default *) + (* NONE for version and - if needed - encoding and call the *) + (* appropriate function. otherwise assume a typo and parse the *) + (* version number, then call parseXmlDeclBeforeE. if no name is *) + (* found at all, proceed with skipXmlDeclEnd. *) + (* *) + (* print an error and raise SyntaxState if an entity end is found. *) + (* print an error and raise SyntaxState if appropriate. *) + (* print an error if a name other than 'version' is found. *) + (*-----------------------------------------------------------------*) + (* might raise: SyntaxState *) + (*-----------------------------------------------------------------*) + val caq1 as (_,_,q1) = skipSopt caq + val (name,(caq2 as (c2,a2,q2))) = parseName caq1 + handle NotFound (c,a,q) => let val err = ERR_EXPECTED(expVersion,[c]) + val a1 = hookError(a,(getPos q,err)) + in raise SyntaxError (c,a1,q) + end + in + if name=[0wx76,0wx65,0wx72,0wx73,0wx69,0wx6f,0wx6e] (* "version" *) + then let val (ver,caq3) = parseVersionInfo caq2 + in parseXmlDeclBeforeE ver caq3 + end + else let val a3 = hookError(a2,(getPos q1,ERR_EXPECTED(expVersion,name))) + in case name + of [0wx65,0wx6e,0wx63,0wx6f,0wx64,0wx69,0wx6e,0wx67] => + (* "encoding" *) parseXmlDeclAfterE NONE (c2,a3,q2) + | [0wx73,0wx74,0wx61,0wx6e,0wx64,0wx61,0wx6c,0wx6f,0wx6e,0wx65] => + (* "standalone" *) parseXmlDeclAfterS auto (NONE,NONE) (c2,a3,q2) + | _ => let val (ver,caq3) = parseVersionInfo (c2,a3,q2) + in parseXmlDeclBeforeE ver caq3 + end + end + end + (*----------------------------------------------------------------*) + (* catch entity end exceptions raised by subfunctions, print an *) + (* error and re-raise the exception. *) + (*----------------------------------------------------------------*) + handle SyntaxError(c,a,q) => + let val err = if c=0wx0 then ERR_ENDED_BY_EE LOC_XML_DECL + else ERR_CANT_PARSE LOC_XML_DECL + val a1 = hookError(a,(getPos q,err)) + in (auto,NONE,recoverXml(c,a1,q)) + end + + (*--------------------------------------------------------------------*) + (* parse a text declaration starting after 'xml ' (i.e. the first *) + (* white space character is already consumed). Cf. 2.8: *) + (* *) + (* [77] TextDecl ::= '' *) + (* *) + (* [24] VersionInfo ::= S 'version' Eq (' VersionNum ' *) + (* | " VersionNum ") *) + (* *) + (* [80] EncodingDecl ::= S 'encoding' Eq ('"' EncName '"' *) + (* |"'" EncName "'") *) + (* *) + (* default version and encoding to NONE. *) + (* *) + (* print an error if no leading white space is found. *) + (* print an error whenever a wrong name is encountered. *) + (* print an Error if no EncodingDecl is found. *) + (* print an Error if '?>' is found at the end. *) + (* print an error and raise SyntaxState if no '=' or no literal is *) + (* found in VersionInfo or EncodingDecl. *) + (* print an error if a literal does not have a correct value. *) + (* *) + (* return the corresponding TextDecl option and the next char & state.*) + (*--------------------------------------------------------------------*) + (* might raise: SyntaxState *) + (*--------------------------------------------------------------------*) + fun parseTextDecl auto caq = + let + (*-----------------------------------------------------------------*) + (* skip the '?>' at the end of the text declaration. *) + (* *) + (* print an error and raise SyntaxState if no '?>' is found. *) + (* *) + (* return the info passed as first arg, and the next char & state. *) + (*-----------------------------------------------------------------*) + (* might raise: SyntaxState *) + (*-----------------------------------------------------------------*) + fun skipTextDeclEnd enc res (c,a,q) = + if c=0wx3F (* "#?" *) + then let val (c1,a1,q1) = getChar (a,q) + in if c1=0wx3E (* #">" *) then (enc,SOME res,getChar (a1,q1)) + else let val a2 = hookError(a1,(getPos q1,ERR_EXPECTED(expGt,[c1]))) + in raise SyntaxError(c1,a2,q1) + end + end + else let val a1 = hookError(a,(getPos q,ERR_EXPECTED(expProcEnd,[c]))) + in raise SyntaxError(c,a1,q) + end + (*-----------------------------------------------------------------*) + (* parse the remainder after the keyword 'encoding', the version *) + (* already parsed and given in the first arg. *) + (* *) + (* pass the version and encoding and to skipTextDeclEnd. *) + (*-----------------------------------------------------------------*) + (* might raise: SyntaxState *) + (*-----------------------------------------------------------------*) + fun parseTextDeclAfterE ver caq = + let + val (enc,(c1,a1,q1)) = parseEncodingDecl caq + val (a2,q2,enc1) = changeAuto(a1,q1,enc) + val caq3 = skipSopt (c1,a2,q2) + in skipTextDeclEnd enc1 (ver,SOME enc) caq3 + end + (*-----------------------------------------------------------------*) + (* parse the remainder after the version info, the version given *) + (* as first argument. *) + (* *) + (* print an error and raise SyntaxState is no name is found. *) + (* print an error if a name other than 'encoding' is found. *) + (* *) + (* pass obtained/default values to parseTextDeclAfterE. *) + (*-----------------------------------------------------------------*) + (* might raise: SyntaxState *) + (*-----------------------------------------------------------------*) + fun parseTextDeclBeforeE ver caq = + let + val caq1 as (_,_,q1) = skipS caq + val (name,caq2) = parseName caq1 + handle NotFound (c,a,q) => let val err = ERR_EXPECTED(expEncoding,[c]) + val a1 = hookError(a,(getPos q,err)) + in raise SyntaxError (c,a1,q) + end + in + if name=[0wx65,0wx6e,0wx63,0wx6f,0wx64,0wx69,0wx6e,0wx67] (* "encoding" *) + then parseTextDeclAfterE ver caq2 + else let val (c2,a2,q2) = caq2 + val a3 = hookError(a2,(getPos q1,ERR_EXPECTED(expEncoding,name))) + in parseTextDeclAfterE ver (c2,a3,q2) + end + end + (*-----------------------------------------------------------------*) + (* do the main work. if the first name is neither 'version' nor *) + (* 'encoding' then assume typo of 'version'. Then parse the *) + (* version number, call parseTextDeclBeforeE. if no name is found *) + (* at all, proceed with skipTextDeclEnd. *) + (* *) + (* print an error and raise SyntaxState if appropriate. *) + (* print an error if a name other than 'version' or 'encoding' is *) + (* found. *) + (*-----------------------------------------------------------------*) + (* might raise: SyntaxState *) + (*-----------------------------------------------------------------*) + val caq1 as (_,_,q1) = skipSopt caq + val (name,caq2) = parseName caq1 + handle NotFound (c,a,q) => let val err = ERR_EXPECTED(expEncVers,[c]) + val a1 = hookError(a,(getPos q,err)) + in raise SyntaxError(c,a1,q) + end + in case name + of [0wx76,0wx65,0wx72,0wx73,0wx69,0wx6f,0wx6e] => (* "version" *) + let val (ver,caq3) = parseVersionInfo caq2 + in parseTextDeclBeforeE ver caq3 + end + | [0wx65,0wx6e,0wx63,0wx6f,0wx64,0wx69,0wx6e,0wx67] => (* "encoding" *) + parseTextDeclAfterE NONE caq2 + | _ => let val (c2,a2,q2) = caq2 + val a3 = hookError(a2,(getPos q1,ERR_EXPECTED(expEncVers,name))) + val (ver,caq3) = parseVersionInfo (c2,a3,q2) + in parseTextDeclBeforeE ver caq3 + end + end + (*----------------------------------------------------------------*) + (* catch entity end exceptions raised by subfunctions, print an *) + (* error and re-raise the exception. *) + (*----------------------------------------------------------------*) + handle SyntaxError(c,a,q) => + let val err = if c=0wx0 then ERR_ENDED_BY_EE LOC_TEXT_DECL + else ERR_CANT_PARSE LOC_TEXT_DECL + val a1 = hookError(a,(getPos q,err)) + in (auto,NONE,recoverXml(c,a1,q)) + end + + (*--------------------------------------------------------------------*) + (* check for the string " if isS c1 then (true,(a1,q1)) + else (false,(a1,ungetChars(q1,rev(c1::seen)))) + | c::cs => if c1=c then doit (c1::seen,cs) (a1,q1) + else (false,(a1,ungetChars(q1,rev(c1::seen)))) + end + in doit (nil,unseen) aq + end + + (*--------------------------------------------------------------------*) + (* consume the text/xml declaration. The first parameter is a pair of *) + (* the function that parses the declaration and a boolean indicating *) + (* whether a warning should we produced if the declaration is missing.*) + (* The second parameter is a pair (seen,auto), where auto is the *) + (* auto-detected encoding, and seen is SOME cs, if auto-detection *) + (* found some initial characters cs of the string " raise CantOpenFile(fmsg,a) + + (*--------------------------------------------------------------------*) + (* open the external subset; consume its text declaration if present. *) + (* See 2.8: *) + (* *) + (* [30] extSubset ::= TextDecl? extSubsetDecl *) + (* *) + (* return the optional text declaration and the first char and state. *) + (*--------------------------------------------------------------------*) + (* might raise: NoSuchFile *) + (*--------------------------------------------------------------------*) + fun openSubset uri a = + let val (q,auto) = pushSpecial (EXT_SUBSET,SOME uri) + in findTextDecl (parseTextDecl,false) auto (a,q) + end + handle NoSuchFile fmsg => raise CantOpenFile(fmsg,a) + + (*--------------------------------------------------------------------*) + (* open the document entity; consume its xml declaration if present. *) + (* See 2.8: *) + (* *) + (* [1] document ::= prolog element Misc* *) + (* [22] prolog ::= XMLDecl? Misc* (doctypedecl Misc* )? *) + (* *) + (* return the optional xml declaration and the first char and state. *) + (*--------------------------------------------------------------------*) + (* might raise: NoSuchFile *) + (*--------------------------------------------------------------------*) + fun openDocument uri a = + let val (q,auto) = pushSpecial (DOC_ENTITY,uri) + in findTextDecl (parseXmlDecl,!O_WARN_XML_DECL) auto (a,q) + end + handle NoSuchFile fmsg => raise CantOpenFile(fmsg,a) +end diff --git a/fxp/src/Parser/entities.sml b/fxp/src/Parser/entities.sml new file mode 100644 index 0000000..e2cbcf0 --- /dev/null +++ b/fxp/src/Parser/entities.sml @@ -0,0 +1,570 @@ +(*--------------------------------------------------------------------------*) +(* Structure: Entities *) +(* *) +(* Exceptions raised by functions in this structure: *) +(* closeAll : none *) +(* getChar : none *) +(* getEntId : none *) +(* getPos : none *) +(* inInternalSubset : none *) +(* isOpenEntity : none *) +(* isSpecialEnd : none *) +(* Position2String : none *) +(* pushDummy : none *) +(* pushExtern : NoSuchFile *) +(* pushIntern : none *) +(* pushSpecial : NoSuchFile *) +(* statePos : none *) +(*--------------------------------------------------------------------------*) +(* This module maintains the entity stack. For each open entity it holds a *) +(* buffer to read characters from. When the buffer is exceeded, it gets re- *) +(* filled with new characters, depending on the entity's encoding. *) +(* *) +(****************************************************************************) +(* End-of-line handling as specified in 2.11 is performed: *) +(* in XML 1.0 ***************************************************************) +(****************************************************************************) +(* ... To simplify the tasks of applications, wherever an external parsed *) +(* entity or the literal entity value of an internal parsed entity *) +(* contains either the literal two-character sequence "#xD#xA" or a *) +(* standalone literal #xD, an XML processor must pass to the application *) +(* the single character #xA. *) +(* (This behavior can conveniently be produced by normalizing all line *) +(* breaks to #xA on input, before parsing.) *) +(****************************************************************************) +(* in XML 1.1 ***************************************************************) +(****************************************************************************) +(* To simplify the tasks of applications, the XML processor MUST behave *) +(* as if it normalized all line breaks in external parsed entities *) +(* (including the document entity) on input, before parsing, *) +(* by translating all of the following to a single #xA character: *) +(* 1. the two-character sequence #xD #xA *) +(* 2. the two-character sequence #xD #x85 *) +(* 3. the single character #x85 *) +(* 4. the single character #x2028 *) +(* 5. any #xD character that is not immediately followed by #xA or #x85.*) +(* *) +(* The characters #x85 and #x2028 cannot be reliably recognized and *) +(* translated until an entity's encoding declaration (if present) has *) +(* been read. Therefore, it is a fatal error to use them within the XML *) +(* declaration or text declaration. *) +(****************************************************************************) +(* *) +(* It also checks for illegal characters, cf. 2.2: *) +(* *) +(* [2] Char ::= #x9 | #xA | #xD /* any Unicode character, *) +(* | [#x20-#xD7FF] excluding the surrogate *) +(* | [#xE000-#xFFFD] blocks, FFFE, and FFFF. */ *) +(* | [#x10000-#x10FFFF] *) +(* *) +(* More precisely, it assumes that all decoded characters are valid Unicode *) +(* characters. It thus only checks for control characters other than #x9, *) +(* #xA or #xD. *) +(*--------------------------------------------------------------------------*) +signature Entities = + sig + include Hooks + + type State + eqtype EntId + datatype Special = DOC_ENTITY | EXT_SUBSET + + exception CantOpenFile of (string * string) * AppData + + val pushIntern : State * int * bool * UniChar.Vector -> State + val pushExtern : State * int * bool * Uri.Uri -> State * Encoding.Encoding + val pushSpecial : Special * Uri.Uri option -> State * Encoding.Encoding + + val closeAll : State -> unit + + val commitAuto : AppData * State -> AppData * State + val changeAuto : AppData * State * string -> AppData * State * Encoding.Encoding + + val getEntId : State -> EntId + val getPos : State -> Errors.Position + val getUri : State -> Uri.Uri + + val getChar : AppData * State -> UniChar.Char * AppData * State + val getChar11 : AppData * State -> UniChar.Char * AppData * State + val getCharRef : (AppData * State -> UniChar.Char * AppData * State) ref + val ungetChars : State * UniChar.Data -> State + + val isOpen : int * bool * State -> bool + val isSpecial : State -> bool + val inDocEntity : State -> bool + end + +functor Entities (structure Hooks : Hooks) : Entities = + struct +(* + structure Entities0=Entities0(structure Hooks = Hooks) + open Entities0 +*) + open UniChar Decode Decode.Error Errors Hooks Uri UtilError + + val THIS_MODULE = "Entities" + val BUFSIZE = 1024 + type CharBuffer = UniChar.Char array + + (*--------------------------------------------------------------------*) + (* A special entity can not be popped from the stack by getChar, so *) + (* it must be popped explicitly. This is for the document entity and *) + (* the external subset. *) + (*--------------------------------------------------------------------*) + datatype Special = DOC_ENTITY | EXT_SUBSET + (*--------------------------------------------------------------------*) + (* In order to distinguish a general entity from a paramter entity, *) + (* entity idxs are marked with this datatype. *) + (*--------------------------------------------------------------------*) + datatype EntId = GENERAL of int | PARAMETER of int + + (*--------------------------------------------------------------------*) + (* Make an EntId from the entity's index. *) + (*--------------------------------------------------------------------*) + fun makeEntId(idx,isParam) = + if isParam then PARAMETER idx else GENERAL idx + + (*--------------------------------------------------------------------*) + (* A non-empty stack is: *) + (* *) + (* an internal entity INT(buf,size,idx,(id,other)): *) + (* - (vec,idx,size) is a buffer,current index and its size; *) + (* - id is the index of the entity's name in the entity table. *) + (* - other contains the underlying entities (the rest of the stack). *) + (* The components are nested according to access frequency. *) + (* *) + (* an external entity has three forms: *) + (* EXT2(buf,size,idx,line,col,break,(dec,err,typ)) *) + (* - (buf,size,idx) is a buffer, its size and current index; *) + (* - (line,col) are the line and column; *) + (* - break is a boolean indicating whether the last character was a *) + (* carriage return (0xD) (then a succeeding line feed (0xA) must be *) + (* supressed); *) + (* - err is an option: if it is SOME(f,ee,err) then it indicates that *) + (* the array was finished by a decoding error err, with the basic *) + (* file f; f was at end of file if ee is true. Otherwise there was *) + (* no error when loading the array. *) + (* - dec describies the encoding of the entity and thus, how more *) + (* data can be loaded; *) + (* - typ is either of the form SPECIAL spec indicating a special *) + (* entity; then this is the only entity on the stack. Otherwise it *) + (* is NORMAL(id,other) for a normal external entity, with: *) + (* + id is the index of the entity's name in the DTD; *) + (* + other is the underlying stack. *) + (* The components are nested according to access frequency. *) + (* *) + (* The second form of an external entity is *) + (* EXT1(dec,line,col,break,typ). This is an unbuffered *) + (* entity whose encoding declaration is being read. We may not load *) + (* an array of characters as a whole because the encoding might still *) + (* change. The components have the same meaning as for EXT2. *) + (* *) + (* A closed entity remains on the stack until the next getChar, for *) + (* purposes of error printing. A closed external entity has the form *) + (* CLOSED(dec,l,col,typ); components have the same meaning *) + (* as for open external entities. A closed internal entity has the *) + (* form ENDED(id,other) with components as above. *) + (* *) + (* Sometimes (for parsing xml/decl declarations) we need a lookahead. *) + (* LOOKING(cs,q) is a state remembering all chars cs looked ahead up *) + (* to state q, in reverse order. LOOKED(cs,q) is an undone lookahead, *) + (* the looked-ahead chars now in the right order. *) + (*--------------------------------------------------------------------*) + datatype ExtType = SPECIAL of Special | NORMAL of EntId * State + and State = + LOOKED of Data * State + | ENDED of EntId * State + | CLOSED of DecFile * int * int * ExtType + | INT of Vector * int * int * (EntId * State) + | EXT1 of DecFile * int * int * bool * ExtType + | EXT2 of CharBuffer * int * int * int * int * bool + * (DecFile * DecodeError option * ExtType) + + exception CantOpenFile of (string * string) * AppData + + (*--------------------------------------------------------------------*) + (* Extract the unique number from a state. *) + (*--------------------------------------------------------------------*) + fun getExtEntId extType = + case extType + of SPECIAL DOC_ENTITY => GENERAL 0 + | SPECIAL EXT_SUBSET => PARAMETER 0 + | NORMAL(id,_) => id + fun getEntId q = + case q + of LOOKED (_,q) => getEntId q + | ENDED(id,_) => id + | CLOSED(_,_,_,extType) => getExtEntId extType + | INT(_,_,_,(id,_)) => id + | EXT1(_,_,_,_,extType) => getExtEntId extType + | EXT2(_,_,_,_,_,_,(_,_,extType)) => getExtEntId extType + + (*--------------------------------------------------------------------*) + (* Find the nearest enclosing external entity, and return its *) + (* filename, line and column number. *) + (*--------------------------------------------------------------------*) + fun getPos q = + case q + of ENDED(_,other) => getPos other + | INT(_,_,_,(_,other)) => getPos other + | CLOSED(dec,l,col,_) => (decName dec,l,col) + | EXT1(dec,l,col,_,_) => (decName dec,l,col) + | EXT2(_,_,_,l,col,_,(dec,_,_)) => (decName dec,l,col) + | LOOKED (cs,q) => let val (f,l,c) = getPos q + val k = length cs + in if c>=k then (f,l,c-k) else (f,l,0) + end + + (*--------------------------------------------------------------------*) + (* get the path of the nearest enclosing external entity. *) + (*--------------------------------------------------------------------*) + fun getUri q = + case q + of LOOKED (_,q) => getUri q + | ENDED(_,other) => getUri other + | INT(_,_,_,(_,other)) => getUri other + | CLOSED(dec,l,col,_) => decUri dec + | EXT1(dec,l,col,_,_) => decUri dec + | EXT2(_,_,_,l,col,_,(dec,_,_)) => decUri dec + + (*--------------------------------------------------------------------*) + (* close all files, return nothing. *) + (*--------------------------------------------------------------------*) + fun closeAll q = + case q + of LOOKED(_,other) => closeAll other + | ENDED(_,other) => closeAll other + | CLOSED(_,_,_,SPECIAL _) => () + | CLOSED(_,_,_,NORMAL(_,other)) => closeAll other + | INT(_,_,_,(_,other)) => closeAll other + | EXT1(dec,_,_,_,SPECIAL _) => ignore(decClose dec) + | EXT1(dec,_,_,_,NORMAL(_,other)) => (ignore (decClose dec); closeAll other) + | EXT2(_,_,_,_,_,_,(dec,_,SPECIAL _)) => ignore(decClose dec) + | EXT2(_,_,_,_,_,_,(dec,_,NORMAL(_,other))) => (ignore (decClose dec); closeAll other) + + (*--------------------------------------------------------------------*) + (* is this entity already on the stack? *) + (*--------------------------------------------------------------------*) + fun isOpen (idx,isParam,q) = + let val id = makeEntId(idx,isParam) + fun doit q = + case q + of LOOKED (_,other) => doit other + | ENDED(id',other) => id=id' orelse doit other + | CLOSED(_,_,_,SPECIAL _) => false + | CLOSED(_,_,_,NORMAL(id',other)) => id=id' orelse doit other + | INT(_,_,_,(id',other)) => id=id' orelse doit other + | EXT1(_,_,_,_,SPECIAL _) => false + | EXT1(_,_,_,_,NORMAL(id',other)) => id=id' orelse doit other + | EXT2(_,_,_,_,_,_,(_,_,SPECIAL _)) => false + | EXT2(_,_,_,_,_,_,(_,_,NORMAL(id',other))) => id=id' orelse doit other + in doit q + end + + (*--------------------------------------------------------------------*) + (* are we in the internal subset, i.e., in the document entity? *) + (* The internal subset can only be in the document entity, since no *) + (* parameter entities are declared prior to it. The document entity *) + (* is then the only entity on the stack. *) + (*--------------------------------------------------------------------*) + fun inDocEntity q = + case q + of LOOKED (_,q) => inDocEntity q + | ENDED(_,other) => inDocEntity other + | INT(_,_,_,(_,other)) => inDocEntity other + | CLOSED(_,_,_,NORMAL _) => false + | CLOSED(_,_,_,SPECIAL what) => what=DOC_ENTITY + | EXT1(_,_,_,_,NORMAL _) => false + | EXT1(_,_,_,_,SPECIAL what) => what=DOC_ENTITY + | EXT2(_,_,_,_,_,_,(_,_,NORMAL _)) => false + | EXT2(_,_,_,_,_,_,(_,_,SPECIAL what)) => what=DOC_ENTITY + + (*--------------------------------------------------------------------*) + (* is this state the document end, i.e., are all entities closed? *) + (*--------------------------------------------------------------------*) + fun isSpecial q = + case q + of LOOKED (_,q) => isSpecial q + | CLOSED(_,_,_,SPECIAL _) => true + | EXT1(_,_,_,_,SPECIAL _) => true + | EXT2(_,_,_,_,_,_,(_,_,SPECIAL _)) => true + | _ => false + + (*--------------------------------------------------------------------*) + (* Initialize and load a new buffer when opening an external entity. *) + (*--------------------------------------------------------------------*) + fun initArray dec = + let + val arr = Array.array(BUFSIZE,0wx0) + val (n,dec1,err) = decGetArray dec arr + in (arr,n,dec1,err) + end + + (*--------------------------------------------------------------------*) + (* Open an external/internal entity. *) + (*--------------------------------------------------------------------*) + fun pushIntern(q,id,isParam,vec) = + INT(vec,Vector.length vec,0,(makeEntId(id,isParam),q)) + fun pushExtern(q,id,isParam,uri) = + let + val dec = decOpenXml (SOME uri) + val auto = decEncoding dec + val q1 = EXT1(dec,1,0,false,NORMAL(makeEntId(id,isParam),q)) + in (q1,auto) + end + fun pushSpecial(what,uri) = + let + val dec = decOpenXml uri + val auto = decEncoding dec + val q = EXT1(dec,1,0,false,SPECIAL what) + in (q,auto) + end + + (*--------------------------------------------------------------------*) + (* confirm the autodetected encoding of an external entity. *) + (*--------------------------------------------------------------------*) + fun commitAuto(a,q) = + case q + of EXT1(dec,l,col,brk,typ) => + let + val a1 = a before decCommit dec + handle DecError(_,_,err) + => hookError(a,(getPos q,ERR_DECODE_ERROR err)) + val (arr,n,dec1,err) = initArray dec + in (a1,EXT2(arr,n,0,l,col,brk,(dec1,err,typ))) + end +(* + in (a1,EXT1(dec,l,col,brk,typ)) + end +*) + | LOOKED(cs,q1) => let val (a1,q2) = commitAuto (a,q1) + in (a1,LOOKED(cs,q2)) + end + | CLOSED _ => (a,q) + | _ => raise InternalError(THIS_MODULE,"commitAuto", + "entity is neither EXT1 nor CLOSED nor LOOKED") + + (*--------------------------------------------------------------------*) + (* change from the autodetected encoding to the declared one. *) + (*--------------------------------------------------------------------*) + fun changeAuto (a,q,decl) = + case q + of EXT1(dec,l,col,brk,typ) => + let + val dec1 = decSwitch(dec,decl) + handle DecError(dec,_,err) + => let val a1 = hookError(a,(getPos q,ERR_DECODE_ERROR err)) + val _ = decClose dec + val uri = decName dec + val msg = case err + of ERR_UNSUPPORTED_ENC _ => "Unsupported encoding" + | _ => "Declared encoding incompatible" + ^"with auto-detected encoding" + in raise CantOpenFile ((uri,msg),a1) + end + val newEnc = decEncoding dec1 + val (arr,n,dec2,err) = initArray dec1 + in (a,EXT2(arr,n,0,l,col,brk,(dec2,err,typ)),newEnc) + end +(* + in (a,EXT1(dec1,l,col,brk,typ),newEnc) + end +*) + + | LOOKED(cs,q1) => let val (a2,q2,enc2) = changeAuto(a,q1,decl) + in (a2,LOOKED(cs,q2),enc2) + end + | CLOSED(dec,_,_,_) => (a,q,decEncoding dec) + | _ => raise InternalError(THIS_MODULE,"changeAuto", + "entity is neither EXT1 nor CLOSED nor LOOKED") + + + + (*--------------------------------------------------------------------*) + (* Get one character from the current entity. Possibly reload buffer. *) + (* Return 0wx0 at entity end. Otherwise check whether the character *) + (* is valid (cf. 2.2). If the last character was a carriage return *) + (* (0xD) supress a line feed (0xA). *) + (*--------------------------------------------------------------------*) + fun getChar (a,q) = + case q + of ENDED(_,other) => getChar(a,other) + | CLOSED(_,_,_,typ) => + (case typ + of SPECIAL _ => raise InternalError (THIS_MODULE,"getChar", + "attempt to read beyond special entity end") + | NORMAL(_,other) => getChar(a,other)) + | INT(vec,s,i,io) => + if i>=s then (0wx0,a,ENDED io) + else (Vector.sub(vec,i),a,INT(vec,s,i+1,io)) + | EXT1(dec,l,col,br,typ) => + (let + val (c,dec1) = decGetChar dec + in + if (* c>=0wx20 orelse c=0wx09 *) + c>=0wx0020 + andalso (c<=0wxD7FF + orelse c>=0wxE000 andalso (c<=0wxFFFD + orelse c>=0wx10000)) + orelse c=0wx9 + then (c,a,EXT1(dec1,l,col+1,false,typ)) + else + if c=0wxA + then if br then getChar(a,EXT1(dec1,l,col,false,typ)) + else (c,a,EXT1(dec1,l+1,0,false,typ)) + else (if c=0wxD then (0wxA,a,EXT1(dec1,l+1,0,true,typ)) + else let val a1 = hookError(a,(getPos q,ERR_NON_XML_CHAR c)) + in getChar(a1,EXT1(dec1,l,col+1,false,typ)) + end) + end + handle DecEof dec => (0wx0,a,CLOSED(dec,l,col,typ)) + | DecError(dec,eof,err) => + let val err = ERR_DECODE_ERROR err + val a1 = hookError(a,(getPos q,err)) + in if eof then (0wx0,a,CLOSED(dec,l,col,typ)) + else getChar(a1,EXT1(dec,col,l,br,typ)) + end) + | EXT2(arr,s,i,l,col,br,det) => + if i=0wx20 orelse c=0wx09 *) + (* c>=0wx0020 andalso c<=0wxD7FF orelse c=0wx9 orelse *) + (* c>=0wxE000 andalso c<=0wxFFFD orelse c>=0wx10000 *) + c>=0wx0020 + andalso (c<=0wxD7FF + orelse c>=0wxE000 andalso (c<=0wxFFFD + orelse c>=0wx10000)) + orelse c=0wx9 + then (c,a,EXT2(arr,s,i+1,l,col+1,false,det)) + else if c=0wxA + then if br then getChar(a,EXT2(arr,s,i+1,l,col,false,det)) + else (c,a,EXT2(arr,s,i+1,l+1,0,false,det)) + else (if c=0wxD then (0wxA,a,EXT2(arr,s,i+1,l+1,0,true,det)) + else let val a1 = hookError(a,(getPos q,ERR_NON_XML_CHAR c)) + in getChar(a1,EXT2(arr,s,i+1,l,col+1,false,det)) + end) + end + else let val (dec,err,typ) = det + val (a1,(n,dec1,err1)) = + case err + of NONE => if s=BUFSIZE then (a,decGetArray dec arr) + else (a,(0,dec,NONE)) + | SOME err => (hookError(a,(getPos q,ERR_DECODE_ERROR err)), + decGetArray dec arr) + in if n=0 andalso not (isSome err1) + then (0wx0,a1,CLOSED(dec1,l,col,typ)) + else getChar(a1,EXT2(arr,n,0,l,col,br,(dec1,err1,typ))) + end + | LOOKED(nil,q) => getChar(a,q) + | LOOKED(c::cs,q) => (c,a,LOOKED(cs,q)) + + fun getChar11 (a,q) = + case q + of ENDED(_,other) => getChar11(a,other) + | CLOSED(_,_,_,typ) => + (case typ + of SPECIAL _ => raise InternalError (THIS_MODULE,"getChar11", + "attempt to read beyond special entity end") + | NORMAL(_,other) => getChar11(a,other)) + | INT(vec,s,i,io) => + if i>=s then (0wx0,a,ENDED io) + else (Vector.sub(vec,i),a,INT(vec,s,i+1,io)) + | EXT1(dec,l,col,br,typ) => (* br = whether the previous char was 0wx0D *) + (let + val (c,dec1) = decGetChar dec + in + (* cf 2.2 and 2.11 (end-of-line handling) *) + if c>=0wx1 + andalso (c<=0wxD7FF orelse c>=0wxE000 andalso (c<=0wxFFFD orelse + c>=0wx10000 andalso c<=0wx10FFFF)) + then + if c=0wx2028 then (0wxA,a,EXT1(dec1,l+1,0,false,typ)) + else + if (c=0wxA orelse c=0wx85) then + if br then getChar11(a,EXT1(dec1,l,col,false,typ)) + (* c and 0wxD was previously translated to 0wxA *) + else (0wxA,a,EXT1(dec1,l+1,0,false,typ)) + else if c=0wxD then (* whatever follows a 0wxA must be produced (cf. 2.11) *) + (0wxA,a,EXT1(dec1,l+1,0,true,typ)) + else + if c<0wx7F orelse c>0wx9F then (c,a,EXT1(dec1,l,col+1,false,typ)) + else (* in XML 1.1 the control characters 0wx7F through 0wx9F must appear + only as chracter references *) + let + val a1 = hookError(a,(getPos q,ERR_MUST_CHARREF c)) + in + getChar11(a1,EXT1(dec1,l,col+1,false,typ)) + end + else + let + val a1 = hookError(a,(getPos q,ERR_NON_XML_CHAR c)) + in + getChar11(a1,EXT1(dec1,l,col+1,false,typ)) + end + end + handle DecEof dec => (0wx0,a,CLOSED(dec,l,col,typ)) + | DecError(dec,eof,err) => + let val err = ERR_DECODE_ERROR err + val a1 = hookError(a,(getPos q,err)) + in if eof then (0wx0,a,CLOSED(dec,l,col,typ)) + else getChar11(a1,EXT1(dec,col,l,br,typ)) + end) + | EXT2(arr,s,i,l,col,br,det) => + if i=0wx1 + andalso (c<=0wxD7FF orelse c>=0wxE000 andalso (c<=0wxFFFD orelse + c>=0wx10000 andalso c<=0wx10FFFF)) + then + if c=0wx2028 then (0wxA,a,EXT2(arr,s,i+1,l+1,0,false,det)) + else + if (c=0wxA orelse c=0wx85) then + if br then getChar11(a,EXT2(arr,s,i+1,l,col,false,det)) + (* c and 0wxD was previously translated to 0wxA *) + else (0wxA,a,EXT2(arr,s,i+1,l+1,0,false,det)) + else if c=0wxD then (* whatever follows a 0wxA must be produced (cf. 2.11) *) + (0wxA,a,EXT2(arr,s,i+1,l+1,0,true,det)) + else + if c<0wx7F orelse c>0wx9F then (c,a,EXT2(arr,s,i+1,l,col+1,false,det)) + else (* in XML 1.1 the control characters 0wx7F through 0wx9F must appear + only as chracter references *) + let + val a1 = hookError(a,(getPos q,ERR_MUST_CHARREF c)) + in + getChar11(a1,EXT2(arr,s,i+1,l,col+1,false,det)) + end + else + let + val a1 = hookError(a,(getPos q,ERR_NON_XML_CHAR c)) + in + getChar(a1,EXT2(arr,s,i+1,l,col+1,false,det)) + end + end + else let val (dec,err,typ) = det + val (a1,(n,dec1,err1)) = + case err + of NONE => if s=BUFSIZE then (a,decGetArray dec arr) + else (a,(0,dec,NONE)) + | SOME err => (hookError(a,(getPos q,ERR_DECODE_ERROR err)), + decGetArray dec arr) + in if n=0 andalso not (isSome err1) + then (0wx0,a1,CLOSED(dec1,l,col,typ)) + else getChar11(a1,EXT2(arr,n,0,l,col,br,(dec1,err1,typ))) + end + | LOOKED(nil,q) => getChar11(a,q) + | LOOKED(c::cs,q) => (c,a,LOOKED(cs,q)) + + val getCharRef = ref getChar + + fun getChar x = !getCharRef x + + + (*--------------------------------------------------------------------*) + (* unget a list of characters. *) + (*--------------------------------------------------------------------*) + fun ungetChars (q,cs) = LOOKED(cs,q) + + end diff --git a/fxp/src/Parser/version.sml b/fxp/src/Parser/version.sml new file mode 100644 index 0000000..c74c0df --- /dev/null +++ b/fxp/src/Parser/version.sml @@ -0,0 +1,4 @@ +structure Version = + struct + val FXP_VERSION = "2.0" + end diff --git a/fxp/src/ROOT.ML b/fxp/src/ROOT.ML new file mode 100644 index 0000000..a2b0516 --- /dev/null +++ b/fxp/src/ROOT.ML @@ -0,0 +1,95 @@ +use "Util/utilString.sml"; +use "Util/utilHash.sml"; +use "Util/utilCompare.sml"; +use "Unicode/Chars/uniChar.sml"; +use "Util/SymDict/key.sml"; +use "Util/utilError.sml"; +use "Util/utilInt.sml"; +use "Util/SymDict/dict.sml"; +use "Util/SymDict/stringDict.sml"; +use "Unicode/encoding.sml"; +use "Unicode/Encode/encodeBasic.sml"; +use "Unicode/Encode/encodeError.sml"; +use "Unicode/Encode/encodeMisc.sml"; +use "Unicode/Encode/encode.sml"; +use "Unicode/Chars/charClasses.sml"; +use "Unicode/Chars/uniRanges.sml"; +use "Unicode/Chars/uniClasses.sml"; +use "Unicode/Uri/uriDecode.sml"; +use "Unicode/Uri/uriEncode.sml"; +use "config.sml"; +use "Unicode/Uri/uri.sml"; +use "Unicode/Decode/decodeFile.sml"; +use "genRandom.sml"; +use "Util/utilTime.sml"; +use "Util/utilList.sml"; +use "Util/intLists.sml"; +use "Util/SymDict/symbolTable.sml"; +use "Util/SymDict/intListDict.sml"; +use "Util/SymDict/intDict.sml"; +use "Unicode/Chars/testClasses.sml"; +use "Unicode/Chars/charVecDict.sml"; +use "Parser/version.sml"; +use "Unicode/Decode/decodeError.sml"; +use "Unicode/Decode/decodeUtil.sml"; +use "Unicode/Decode/decodeUtf8.sml"; +use "Unicode/Decode/decodeUtf16.sml"; +use "Unicode/Decode/decodeUcs4.sml"; +use "Unicode/Decode/decodeUcs2.sml"; +use "Unicode/Decode/decodeMisc.sml"; +use "Unicode/Decode/decode.sml"; +use "Parser/Error/errorData.sml"; +use "Parser/Error/errorString.sml"; +use "Parser/Error/errorMessage.sml"; +use "Parser/Error/errorUtil.sml"; +use "Parser/Error/expected.sml"; +use "Parser/Error/errors.sml"; +use "Parser/Dfa/dfaData.sml"; +use "Parser/Base/baseData.sml"; +use "Parser/Dfa/dfaString.sml"; +use "Parser/Base/baseString.sml"; +use "Parser/Base/base.sml"; +use "Parser/Params/resolve.sml"; +use "Catalog/catError.sml"; +use "Catalog/catParams.sml"; +use "Unicode/Uri/uriDict.sml"; +use "Catalog/catData.sml"; +use "Util/options.sml"; +use "Parser/Dfa/dfaOptions.sml"; +use "Parser/Params/parserOptions.sml"; +use "Parser/Params/hookData.sml"; +use "Parser/Params/hooks.sml"; +use "Unicode/Chars/dataDict.sml"; +use "Parser/Params/dtd.sml"; +use "Parser/Dfa/dfaUtil.sml"; +use "Util/intSets.sml"; +use "Util/SymDict/intSetDict.sml"; +use "Parser/Dfa/dfaPassThree.sml"; +use "Parser/Dfa/dfaError.sml"; +use "Parser/Dfa/dfaPassOne.sml"; +use "Parser/Dfa/dfaPassTwo.sml"; +use "Parser/Dfa/dfa.sml"; +use "Parser/entities.sml"; +use "Parser/Dtd/dtdDeclare.sml"; +use "Parser/Dtd/dtdAttributes.sml"; +use "Parser/Dtd/dtdManager.sml"; +use "Parser/Parse/parseBase.sml"; +use "Parser/Parse/parseNames.sml"; +use "Parser/Parse/parseMisc.sml"; +use "Parser/Parse/parseXml.sml"; +use "Parser/Parse/parseRefs.sml"; +use "Parser/Parse/parseLiterals.sml"; +use "Parser/Parse/parseTags.sml"; +use "Parser/Parse/parseDecl.sml"; +use "Parser/Parse/parseDtd.sml"; +use "Parser/Parse/parseContent.sml"; +use "Parser/Parse/parseDocument.sml"; +use "Catalog/catFile.sml"; +use "Catalog/socatParse.sml"; +use "Catalog/catDtd.sml"; +use "Parser/Params/ignore.sml"; +use "Catalog/catHooks.sml"; +use "Catalog/catParse.sml"; +use "Catalog/catalog.sml"; +use "Catalog/catResolve.sml"; +use "Catalog/catOptions.sml"; diff --git a/fxp/src/Unicode/Chars/charClasses.sml b/fxp/src/Unicode/Chars/charClasses.sml new file mode 100644 index 0000000..27aa78d --- /dev/null +++ b/fxp/src/Unicode/Chars/charClasses.sml @@ -0,0 +1,158 @@ +(*--------------------------------------------------------------------------*) +(* Structure: CharClasses *) +(* *) +(* Notes: *) +(* This implementation uses the UNSAFE array operations, and does NO *) +(* range checks. This is for efficiency reasons. *) +(* If class=makeCharClass(lo,hi) then a filed of size hi-lo+1 is allo- *) +(* cated. In order to lookup a character, first make sure it in [lo..hi], *) +(* then subtract lo before calling inCharClass! *) +(* The same holds for addChar. *) +(* *) +(* Depends on: *) +(* UniChar *) +(* UtilInt *) +(* *) +(* Exceptions raised by functions in this structure: *) +(* addChar : none *) +(* addCharClass : none *) +(* inCharClass : none *) +(* makeCharClass : none *) +(*--------------------------------------------------------------------------*) +signature CharClasses = + sig + type CharClass + type MutableClass + type CharInterval = UniChar.Char * UniChar.Char + type CharRange = CharInterval list + + val initialize : CharInterval -> MutableClass + val finalize : MutableClass -> CharClass + + val addChar : MutableClass * UniChar.Char * UniChar.Char * UniChar.Char -> unit + val addCharRange : MutableClass * UniChar.Char * UniChar.Char * CharRange -> CharRange + + val inCharClass : UniChar.Char * CharClass -> bool + end + +structure CharClasses : CharClasses = + struct + open UniChar + + type CharInterval = Char * Char + type CharRange = CharInterval list + + val Char2Word = Word.fromLargeWord o Chars.toLargeWord + + (*--------------------------------------------------------------------*) + (* helpers *) + (*--------------------------------------------------------------------*) + infix 5 >> >>> <<< + infix 6 || ||| + infix 6 -- + infix 7 & && &&& + val op >> = Chars.>> + val op -- = Chars.- + val op || = Chars.orb + val op && = Chars.andb + val op >>> = Word32.>> + val op <<< = Word32.<< + val op &&& = Word32.andb + val op ||| = Word32.orb + val op & = Word.andb + + val max32 = Word32.notb 0wx0 + + (*--------------------------------------------------------------------*) + (* a char class is an array of words, interpreted as bitvectors. *) + (*--------------------------------------------------------------------*) + type MutableClass = Word32.word array + type CharClass = Word32.word vector + + (*--------------------------------------------------------------------*) + (* each word in a char class holds 32 entries. Thus the for a char c *) + (* is c div 32 == c >> 5. The bitmask is a word of zeros, only the *) + (* significant bit for c, i.e. the (c && 31==0x1F)th bit set to one. *) + (*--------------------------------------------------------------------*) + fun indexMask c = let val idx = Chars.toInt(c>>0w5) + val mask = 0wx1 <<< Char2Word c & 0w31 + in (idx,mask) + end + + (*--------------------------------------------------------------------*) + (* generate index and mask, then lookup. *) + (*--------------------------------------------------------------------*) + fun inCharClass(c,vec) = let val (idx,mask) = indexMask c + in mask &&& Vector.sub(vec,idx) <> 0wx0 + end + + (*--------------------------------------------------------------------*) + (* generate a CharClass large enough to hold (max-min+1) characters. *) + (*--------------------------------------------------------------------*) + fun initialize(min,max) = + Array.array((Chars.toInt max-Chars.toInt min+1) div 32+1,0wx0):MutableClass + fun finalize arr = Array.vector arr + + (*--------------------------------------------------------------------*) + (* add a single character to a CharClass. *) + (*--------------------------------------------------------------------*) + fun addChar(cls,min,max,c) = + let + val (idx,new) = indexMask c + val old = Array.sub(cls,idx) + in + Array.update(cls,idx,old|||new) + end + + (*--------------------------------------------------------------------*) + (* add a full range of characters to a CharClass. *) + (* this is the only function that computes the offset before access *) + (* to the array. *) + (*--------------------------------------------------------------------*) + fun addCharRange(cls,min,max,range) = (* returns intervals from range which are not between min and max *) + let + fun doOne (lo,hi) = + let + val (l,h) = (lo-min,hi-min) + val (idxL,idxH) = ((Chars.toInt l) div 32,(Chars.toInt h) div 32) + val (bitL,bitH) = (Char2Word l & 0w31,Char2Word h & 0w31) + in + if idxL=idxH then + let + val new = (max32>>>(0w31-bitH+bitL))<<>>(0w31-bitH) + val oldL = Array.sub(cls,idxL) + val oldH = Array.sub(cls,idxH) + val _ = Array.update(cls,idxL,oldL|||newL) + val _ = Array.update(cls,idxH,oldH|||newH) + val _ = UtilInt.appInterval (fn i => Array.update(cls,i,max32)) + (idxL+1,idxH-1) + in () + end + else () + end + fun doAll nil = nil + | doAll ((lh as (lo,hi))::lhs) = + if himax then lh::doAll lhs + else if lo=min andalso hi<=max + then (doOne lh; doAll lhs) + else if lo>=min andalso hi>max + then (doOne(lo,max); (max+0w1,hi)::lhs) + else (doOne(min,max); (max+0w1,hi)::lhs) + val _ = doAll range + in + doAll range + end + end + diff --git a/fxp/src/Unicode/Chars/charVecDict.sml b/fxp/src/Unicode/Chars/charVecDict.sml new file mode 100644 index 0000000..2de2c4f --- /dev/null +++ b/fxp/src/Unicode/Chars/charVecDict.sml @@ -0,0 +1,11 @@ +structure KeyVector : Key = + struct + type Key = UniChar.Vector + + val null = UniChar.nullVector + val compare = UniChar.compareVector + val toString = UniChar.Vector2String + val hash = UniChar.hashVector + end + +structure VectorDict = Dict (structure Key = KeyVector) diff --git a/fxp/src/Unicode/Chars/dataDict.sml b/fxp/src/Unicode/Chars/dataDict.sml new file mode 100644 index 0000000..dc20810 --- /dev/null +++ b/fxp/src/Unicode/Chars/dataDict.sml @@ -0,0 +1,22 @@ + + + + + + + + +structure KeyData : Key = + struct + type Key = UniChar.Data + + val null = UniChar.nullData + val hash = UniChar.hashData + val compare = UniChar.compareData + val toString = UniChar.Data2String + end + +structure DataDict = Dict (structure Key = KeyData) +structure DataSymTab = SymTable (structure Key = KeyData) + + diff --git a/fxp/src/Unicode/Chars/testClasses.sml b/fxp/src/Unicode/Chars/testClasses.sml new file mode 100644 index 0000000..d569c34 --- /dev/null +++ b/fxp/src/Unicode/Chars/testClasses.sml @@ -0,0 +1,46 @@ +structure TestClasses = + struct + open UniChar UniClasses UniRanges UtilList + + fun wordUpto(n,m) = if Word.<(m,n) then nil else n::wordUpto(Word.+(n,0w1),m) + fun inCharRange(c:Char,cr) = List.exists (fn (lo,hi) => lo<=c andalso hi>=c) cr + + fun testClass(className,isClass,classRange,stop) = + let + val _ = print ("Testing class "^className^":") + fun testOne c = if isClass c = inCharRange(c,classRange) then () + else let val str = String.concat + ["TestClasses: ",Char2Uni c, + if isClass c then " may not " else " must ", + "be in this class."] + val _ = print (str^"\n") + in raise Fail str + end + handle exn => + let val str = String.concat + ["TestClasses: Unexpected exception for ", + Chars.toString c,":",exnMessage exn] + val _ = print (str^"\n") + in raise Fail str + end + fun debugOne c = if c mod 0wx40 <> 0wx0 then () + else if c mod 0wx1000 <> 0wx00 then print "." + else print "\n." + fun testAll c = if c>=stop then () + else (debugOne c; testOne c; testAll (c+0w1)) + val _ = testAll 0w0 + val _ = print "\n" + in () + end + + fun testClasses() = + let + val _ = testClass("name start",isNms,nmsRange,0wx10010) + val _ = testClass("name",isName,nameRange,0wx10010) + val _ = testClass("pubid",isPubid,pubidRange,0wx100) + val _ = testClass("enc",isEnc,encRange,0wx100) + in () + end + + (* val _ = testClasses() *) + end diff --git a/fxp/src/Unicode/Chars/uniChar.sml b/fxp/src/Unicode/Chars/uniChar.sml new file mode 100644 index 0000000..df4ff5f --- /dev/null +++ b/fxp/src/Unicode/Chars/uniChar.sml @@ -0,0 +1,129 @@ +(*--------------------------------------------------------------------------*) +(* Structure: UniChar *) +(* *) +(* Depends on: *) +(* UtilString *) +(* *) +(* Exceptions raised by functions in this structure: *) +(*--------------------------------------------------------------------------*) +signature UniChar = + sig + structure Chars : WORD + + type Char = Chars.word + type Data = Char list + type Vector = Char vector + + val nullData : Data + val nullVector : Vector + + val hashChar : Char -> word + val hashData : Data -> word + val hashVector : Vector -> word + + val compareChar : Char * Char -> order + val compareData : Data * Data -> order + val compareVector : Vector * Vector -> order + + val char2Char : char -> Char + val Char2char : Char -> char + + val Char2Uni : Char -> string + val Char2String : Char -> string + + val String2Data : string -> Data + val Data2String : Data -> string + val Latin2String : Data -> string + + val Data2Vector : Data -> Vector + val Vector2Data : Vector -> Data + + val String2Vector : string -> Vector + val Vector2String : Vector -> string + + val quoteUni : Char -> string -> string + val quoteChar : Char -> Char -> string + val quoteData : Char -> Data -> string + val quoteVector : Char -> Vector -> string + end + +structure UniChar : UniChar = + struct + val O_VECTOR_PRINTLEN = 48 + + structure Chars = Word + + val _ = if Chars.wordSize > 21 then () + else let val str = ("UniChar: Chars.wordSize is too small.\n"^ + "Cannot compile on this system!\n" ) + val _ = print str + in raise Fail str + end + + type Char = Chars.word + type Data = Char list + + type CharInterval = Char * Char + type CharRange = CharInterval list + + type Vector = Char vector + + val nullChar = 0wx0:Char + val nullData = nil:Data + val nullVector = Vector.fromList nullData + + val hashChar = Word.fromLargeWord o Chars.toLargeWord + val hashData = UtilHash.hashList hashChar + val hashVector = UtilHash.hashVector hashChar + + val compareChar = Chars.compare + val compareData = UtilCompare.compareList compareChar + val compareVector = UtilCompare.compareVector compareChar + + val char2Char = Chars.fromLargeWord o Word8.toLargeWord o Byte.charToByte + val Char2char = Byte.byteToChar o Word8.fromLargeWord o Chars.toLargeWord + + fun Char2Uni c = + "U+"^UtilString.toUpperString(StringCvt.padLeft #"0" 4 (Chars.toString c)) + fun Char2String c = + case c + of 0wx9 => "\\t" + | 0wxA => "\\n" + | _ => if c<0wx100 then String.implode [Char2char c] + else Char2Uni c + + fun String2Data s = map char2Char (String.explode s) + fun Data2String cs = String.concat (map Char2String cs) + fun Latin2String cs = String.implode (map Char2char cs) + + val Data2Vector = Vector.fromList + fun String2Vector s = Vector.tabulate(String.size s,fn i => char2Char(String.sub(s,i))) + + fun Vector2Data vec = Vector.foldr (op ::) nil vec + fun Vector2String vec = + let + val maxlen = O_VECTOR_PRINTLEN + val len = Vector.length vec + in + if len<=maxlen orelse maxlen=0 + then Data2String (Vector2Data vec) + else let + val cs1 = VectorSlice.foldri + (fn (_,c,cs) => c::cs) + nil + (VectorSlice.slice (vec,0,SOME (maxlen div 2))) + val cs2 = VectorSlice.foldri + (fn (_,c,cs) => c::cs) + nil + (VectorSlice.slice (vec,len-3-maxlen div 2,NONE)) + in Data2String cs1^"..."^Data2String cs2 + end + end + + fun quoteUni q s = let val sQ = Char2String q in sQ^s^sQ end + fun quoteChar q c = if c=0wx0 then "entity end" else quoteUni q (Char2String c) + fun quoteData q cs = quoteUni q (Data2String cs) + fun quoteVector q v = quoteUni q (Vector2String v) + end + + diff --git a/fxp/src/Unicode/Chars/uniClasses.sml b/fxp/src/Unicode/Chars/uniClasses.sml new file mode 100644 index 0000000..b013722 --- /dev/null +++ b/fxp/src/Unicode/Chars/uniClasses.sml @@ -0,0 +1,222 @@ + + + + +(*--------------------------------------------------------------------------*) +(* Structure: UniClasses *) +(* *) +(* Notes: *) +(* read CharClasses in order to understand how CharClasses are handled. *) +(* *) +(* Depends on: *) +(* UniChar *) +(* CharClasses *) +(* *) +(* Exceptions raised by functions in this structure: *) +(* decValue : none *) +(* hexValue : none *) +(* isAsciiLetter : none *) +(* isEnc : none *) +(* isEncS : none *) +(* isName : none *) +(* isNms : none *) +(* isPubid : none *) +(* isS : none *) +(* isXml : none *) +(* isUnicode : none *) +(* isVers : none *) +(*--------------------------------------------------------------------------*) +signature UniClasses = + sig + val isName : UniChar.Char -> bool + val isName11 : UniChar.Char -> bool + val isNameRef : (UniChar.Char -> bool) ref + val isNms : UniChar.Char -> bool + val isNms11 : UniChar.Char -> bool + val isNmsRef : (UniChar.Char -> bool) ref + val isXml : UniChar.Char -> bool + val isXml11 : UniChar.Char -> bool + val isXmlRef : (UniChar.Char -> bool) ref + val isPubid : UniChar.Char -> bool + val isS : UniChar.Char -> bool + val isEnc : UniChar.Char -> bool + val isEncS : UniChar.Char -> bool + val isVers : UniChar.Char -> bool + val isDec : UniChar.Char -> bool + val isHex : UniChar.Char -> bool + val isUnicode : UniChar.Char -> bool + + val decValue : UniChar.Char -> UniChar.Char option + val hexValue : UniChar.Char -> UniChar.Char option + + val isAsciiLetter : UniChar.Char -> bool + end + +structure UniClasses : UniClasses = + struct + open UniChar CharClasses UniRanges + + (*--------------------------------------------------------------------*) + (* initialize the character classes. *) + (*--------------------------------------------------------------------*) + local + val nmsTemp = initialize(0wx0000,0wx3FFF) + val restNms = addCharRange(nmsTemp,0wx0000,0wx3FFF,nmsRange) + val _ = if restNms=[(0wxAC00,0wxD7A3), (* interval in BaseChar not between 0 and 3FFF *) + (0wx4E00,0wx9FA5) (* interval in Ideographic not between 0 and 3FFF *) + ] then () + else print ("Warning: extra characters after computing nms char class.\n") + + val nms11Temp = initialize(0wx0000,0wxFFFF) + val restNms11 = addCharRange(nms11Temp,0wx0000,0wxFFFF,nameStartCharRange) + val _ = if restNms11=[(0wx10000,0wxEFFFF)] then () + else print ("Warning: extra characters after computing nms11 char class.\n") + + val nameTemp = initialize(0wx0000,0wxFFFF) (* should probably be enough 3FFF *) + val restName = addCharRange(nameTemp,0wx0000,0wx3FFF,nameRange) + val _ = if restName=[(0wxAC00,0wxD7A3),(0wx4E00,0wx9FA5)] then () + else print ("Warning: extra characters after computing name char class.\n") + + val name11Temp = initialize(0wx0000,0wxFFFF) + val restName11 = addCharRange(name11Temp,0wx0000,0wxFFFF,nameCharRange) + val _ = if restName11=[(0wx10000,0wxEFFFF)] then () + else print ("Warning: extra characters after computing name11 char class.\n") + + val pubTemp = initialize(0wx0000,0wx007F) + val restPubid = addCharRange(pubTemp,0wx0000,0wx007F,pubidRange) + val _ = if restPubid=nil then () + else print ("Warning: extra characters after computing pubid char class.\n") + + val encTemp = initialize(0wx0000,0wx007F) + val restEnc = addCharRange(encTemp,0wx0000,0wx007F,encRange) + val _ = if restEnc=nil then () + else print ("Warning: extra characters after computing enc char class.\n") + in + val nmsClass = finalize nmsTemp + val nms11Class = finalize nms11Temp + val nameClass = finalize nameTemp + val name11Class = finalize name11Temp + val pubClass = finalize pubTemp + val encClass = finalize encTemp + end + + (*--------------------------------------------------------------------*) + (* is a character a name start char? *) + (*--------------------------------------------------------------------*) + fun isNms c = if c<0wx4000 then inCharClass(c,nmsClass) + else + c>=0wx4E00 andalso c<=0wx9FA5 orelse (* legal interval for nms but not in nmsClass *) + c>=0wxAC00 andalso c<=0wxD7A3 (* legal interval for nms but not in nmsClass *) + + (* for XML 1.1 *) + fun isNms11 c = if c<=0wxFFFF then inCharClass(c,nms11Class) + else c>=0wx10000 andalso c<=0wxEFFFF + + val isNmsRef = ref isNms + + fun isNms x = (!isNmsRef) x + + + (*--------------------------------------------------------------------*) + (* is a character a name char? *) + (*--------------------------------------------------------------------*) + fun isName c = if c<0wx4000 then inCharClass(c,nameClass) + else + c>=0wx4E00 andalso c<=0wx9FA5 orelse + c>=0wxAC00 andalso c<=0wxD7A3 + + (* for XML 1.1 *) + fun isName11 c = if c<=0wxFFFF then inCharClass(c,name11Class) + else c>=0wx10000 andalso c<=0wxEFFFF + + val isNameRef = ref isName + + fun isName x = (!isNameRef) x + + (*--------------------------------------------------------------------*) + (* XML characters if not checked for Unicode char in advance. *) + (*--------------------------------------------------------------------*) + fun isXml (c:UniChar.Char) = + c>=0wx0020 andalso c<=0wxD7FF orelse + c>=0wxE000 andalso c<=0wxFFFD orelse + c>=0wx10000 andalso c<=0wx10FFFF orelse + c=0wx9 orelse c=0wxA orelse c=0wxD + (**********************************************************************) + (* XML 1.1 *) + (* Char ::= [#x1-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] [2] *) + (**********************************************************************) + fun isXml11 (c:UniChar.Char) = + c>=0wx1 andalso c<=0wxD7FF orelse + c>=0wxE000 andalso c<=0wxFFFD orelse + c>=0wx10000 andalso c<=0wx10FFFF + + val isXmlRef = ref isXml + + fun isXml x = (!isXmlRef) x + + (*--------------------------------------------------------------------*) + (* is a character a pubid char? *) + (*--------------------------------------------------------------------*) + fun isPubid c = c<0wx80 andalso inCharClass(c,pubClass) + + (*--------------------------------------------------------------------*) + (* is a character valid in an encoding name, at its start, or in a *) + (* version number? *) + (*--------------------------------------------------------------------*) + fun isEnc c = + c<0wx80 andalso inCharClass(c,encClass) + fun isEncS (c:UniChar.Char) = + c>=0wx41 andalso c<=0wx5A orelse + c>=0wx61 andalso c<=0wx7A + fun isVers c = + isEnc c orelse c=0wx3A (* #":" *) + + (*--------------------------------------------------------------------*) + (* these are the valid Unicode characters (including surrogates). *) + (*--------------------------------------------------------------------*) + fun isUnicode (c:UniChar.Char) = c<=0wx10FFFF + + (*--------------------------------------------------------------------*) + (* the frontend supresses 0wxD (carriage return), but its is still *) + (* present when encoding is recognized. *) + (*--------------------------------------------------------------------*) + fun isS (c:UniChar.Char) = + case c + of 0wx09 => true + | 0wx0A => true + | 0wx0D => true + | 0wx20 => true + | _ => false + + (*--------------------------------------------------------------------*) + (* is this character an ascii decimal/hexadecimal digit? *) + (*--------------------------------------------------------------------*) + fun isDec (c:UniChar.Char) = + c>=0wx30 andalso c<=0wx39 + fun isHex (c:UniChar.Char) = + c>=0wx30 andalso c<=0wx39 orelse + c>=0wx41 andalso c<=0wx46 orelse + c>=0wx61 andalso c<=0wx66 + + (*--------------------------------------------------------------------*) + (* calculate the decimal/hexadecimal value of an ascii (hex-)digit. *) + (*--------------------------------------------------------------------*) + fun decValue (c:UniChar.Char) = + let val v = c-0wx30 + in if v<=0wx9 then SOME v else NONE + end + fun hexValue (c:UniChar.Char) = + let val v = c-0wx30 + in if v<=0wx9 then SOME v + else (if c>=0wx41 andalso c<=0wx46 then SOME(c-0wx37) + else if c>=0wx61 andalso c<=0wx66 then SOME(c-0wx57) + else NONE) + end + + (*--------------------------------------------------------------------*) + (* is c in [a-z]+[A-Z]? *) + (*--------------------------------------------------------------------*) + fun isAsciiLetter (c:UniChar.Char) = + c>=0wx41 andalso c<=0wx5A orelse + c>=0wx61 andalso c<=0wx7A + end diff --git a/fxp/src/Unicode/Chars/uniRanges.sml b/fxp/src/Unicode/Chars/uniRanges.sml new file mode 100644 index 0000000..72858cf --- /dev/null +++ b/fxp/src/Unicode/Chars/uniRanges.sml @@ -0,0 +1,431 @@ + + + + +structure UniRanges = + struct + val digitRange = [(0wx0030,0wx0039), + (0wx0660,0wx0669), + (0wx06F0,0wx06F9), + (0wx0966,0wx096F), + (0wx09E6,0wx09EF), + (0wx0A66,0wx0A6F), + (0wx0AE6,0wx0AEF), + (0wx0B66,0wx0B6F), + (0wx0BE7,0wx0BEF), + (0wx0C66,0wx0C6F), + (0wx0CE6,0wx0CEF), + (0wx0D66,0wx0D6F), + (0wx0E50,0wx0E59), + (0wx0ED0,0wx0ED9), + (0wx0F20,0wx0F29) + ] : CharClasses.CharRange + + val digitRange09 = [(0wx0030,0wx0039), + (0wx0660,0wx0669), + (0wx06F0,0wx06F9), + (0wx0E50,0wx0E59), + (0wx0ED0,0wx0ED9), + (0wx0F20,0wx0F29) + ] : CharClasses.CharRange + + val digitRange6F = [(0wx0966,0wx096F), + (0wx09E6,0wx09EF), + (0wx0A66,0wx0A6F), + (0wx0AE6,0wx0AEF), + (0wx0B66,0wx0B6F), + (0wx0BE7,0wx0BEF), + (0wx0C66,0wx0C6F), + (0wx0CE6,0wx0CEF), + (0wx0D66,0wx0D6F) + ] : CharClasses.CharRange + + val baseRange = [(0wx0041,0wx005A), + (0wx0061,0wx007A), + (0wx00C0,0wx00D6), + (0wx00D8,0wx00F6), + (0wx00F8,0wx00FF), + (0wx0100,0wx0131), + (0wx0134,0wx013E), + (0wx0141,0wx0148), + (0wx014A,0wx017E), + (0wx0180,0wx01C3), + (0wx01CD,0wx01F0), + (0wx01F4,0wx01F5), + (0wx01FA,0wx0217), + (0wx0250,0wx02A8), + (0wx02BB,0wx02C1), + (0wx0386,0wx0386), + (0wx0388,0wx038A), + (0wx038C,0wx038C), + (0wx038E,0wx03A1), + (0wx03A3,0wx03CE), + (0wx03D0,0wx03D6), + (0wx03DA,0wx03DA), + (0wx03DC,0wx03DC), + (0wx03DE,0wx03DE), + (0wx03E0,0wx03E0), + (0wx03E2,0wx03F3), + (0wx0401,0wx040C), + (0wx040E,0wx044F), + (0wx0451,0wx045C), + (0wx045E,0wx0481), + (0wx0490,0wx04C4), + (0wx04C7,0wx04C8), + (0wx04CB,0wx04CC), + (0wx04D0,0wx04EB), + (0wx04EE,0wx04F5), + (0wx04F8,0wx04F9), + (0wx0531,0wx0556), + (0wx0559,0wx0559), + (0wx0561,0wx0586), + (0wx05D0,0wx05EA), + (0wx05F0,0wx05F2), + (0wx0621,0wx063A), + (0wx0641,0wx064A), + (0wx0671,0wx06B7), + (0wx06BA,0wx06BE), + (0wx06C0,0wx06CE), + (0wx06D0,0wx06D3), + (0wx06D5,0wx06D5), + (0wx06E5,0wx06E6), + (0wx0905,0wx0939), + (0wx093D,0wx093D), + (0wx0958,0wx0961), + (0wx0985,0wx098C), + (0wx098F,0wx0990), + (0wx0993,0wx09A8), + (0wx09AA,0wx09B0), + (0wx09B2,0wx09B2), + (0wx09B6,0wx09B9), + (0wx09DC,0wx09DD), + (0wx09DF,0wx09E1), + (0wx09F0,0wx09F1), + (0wx0A05,0wx0A0A), + (0wx0A0F,0wx0A10), + (0wx0A13,0wx0A28), + (0wx0A2A,0wx0A30), + (0wx0A32,0wx0A33), + (0wx0A35,0wx0A36), + (0wx0A38,0wx0A39), + (0wx0A59,0wx0A5C), + (0wx0A5E,0wx0A5E), + (0wx0A72,0wx0A74), + (0wx0A85,0wx0A8B), + (0wx0A8D,0wx0A8D), + (0wx0A8F,0wx0A91), + (0wx0A93,0wx0AA8), + (0wx0AAA,0wx0AB0), + (0wx0AB2,0wx0AB3), + (0wx0AB5,0wx0AB9), + (0wx0ABD,0wx0ABD), + (0wx0AE0,0wx0AE0), + (0wx0B05,0wx0B0C), + (0wx0B0F,0wx0B10), + (0wx0B13,0wx0B28), + (0wx0B2A,0wx0B30), + (0wx0B32,0wx0B33), + (0wx0B36,0wx0B39), + (0wx0B3D,0wx0B3D), + (0wx0B5C,0wx0B5D), + (0wx0B5F,0wx0B61), + (0wx0B85,0wx0B8A), + (0wx0B8E,0wx0B90), + (0wx0B92,0wx0B95), + (0wx0B99,0wx0B9A), + (0wx0B9C,0wx0B9C), + (0wx0B9E,0wx0B9F), + (0wx0BA3,0wx0BA4), + (0wx0BA8,0wx0BAA), + (0wx0BAE,0wx0BB5), + (0wx0BB7,0wx0BB9), + (0wx0C05,0wx0C0C), + (0wx0C0E,0wx0C10), + (0wx0C12,0wx0C28), + (0wx0C2A,0wx0C33), + (0wx0C35,0wx0C39), + (0wx0C60,0wx0C61), + (0wx0C85,0wx0C8C), + (0wx0C8E,0wx0C90), + (0wx0C92,0wx0CA8), + (0wx0CAA,0wx0CB3), + (0wx0CB5,0wx0CB9), + (0wx0CDE,0wx0CDE), + (0wx0CE0,0wx0CE1), + (0wx0D05,0wx0D0C), + (0wx0D0E,0wx0D10), + (0wx0D12,0wx0D28), + (0wx0D2A,0wx0D39), + (0wx0D60,0wx0D61), + (0wx0E01,0wx0E2E), + (0wx0E30,0wx0E30), + (0wx0E32,0wx0E33), + (0wx0E40,0wx0E45), + (0wx0E81,0wx0E82), + (0wx0E84,0wx0E84), + (0wx0E87,0wx0E88), + (0wx0E8A,0wx0E8A), + (0wx0E8D,0wx0E8D), + (0wx0E94,0wx0E97), + (0wx0E99,0wx0E9F), + (0wx0EA1,0wx0EA3), + (0wx0EA5,0wx0EA5), + (0wx0EA7,0wx0EA7), + (0wx0EAA,0wx0EAB), + (0wx0EAD,0wx0EAE), + (0wx0EB0,0wx0EB0), + (0wx0EB2,0wx0EB3), + (0wx0EBD,0wx0EBD), + (0wx0EC0,0wx0EC4), + (0wx0F40,0wx0F47), + (0wx0F49,0wx0F69), + (0wx10A0,0wx10C5), + (0wx10D0,0wx10F6), + (0wx1100,0wx1100), + (0wx1102,0wx1103), + (0wx1105,0wx1107), + (0wx1109,0wx1109), + (0wx110B,0wx110C), + (0wx110E,0wx1112), + (0wx113C,0wx113C), + (0wx113E,0wx113E), + (0wx1140,0wx1140), + (0wx114C,0wx114C), + (0wx114E,0wx114E), + (0wx1150,0wx1150), + (0wx1154,0wx1155), + (0wx1159,0wx1159), + (0wx115F,0wx1161), + (0wx1163,0wx1163), + (0wx1165,0wx1165), + (0wx1167,0wx1167), + (0wx1169,0wx1169), + (0wx116D,0wx116E), + (0wx1172,0wx1173), + (0wx1175,0wx1175), + (0wx119E,0wx119E), + (0wx11A8,0wx11A8), + (0wx11AB,0wx11AB), + (0wx11AE,0wx11AF), + (0wx11B7,0wx11B8), + (0wx11BA,0wx11BA), + (0wx11BC,0wx11C2), + (0wx11EB,0wx11EB), + (0wx11F0,0wx11F0), + (0wx11F9,0wx11F9), + (0wx1E00,0wx1E9B), + (0wx1EA0,0wx1EF9), + (0wx1F00,0wx1F15), + (0wx1F18,0wx1F1D), + (0wx1F20,0wx1F45), + (0wx1F48,0wx1F4D), + (0wx1F50,0wx1F57), + (0wx1F59,0wx1F59), + (0wx1F5B,0wx1F5B), + (0wx1F5D,0wx1F5D), + (0wx1F5F,0wx1F7D), + (0wx1F80,0wx1FB4), + (0wx1FB6,0wx1FBC), + (0wx1FBE,0wx1FBE), + (0wx1FC2,0wx1FC4), + (0wx1FC6,0wx1FCC), + (0wx1FD0,0wx1FD3), + (0wx1FD6,0wx1FDB), + (0wx1FE0,0wx1FEC), + (0wx1FF2,0wx1FF4), + (0wx1FF6,0wx1FFC), + (0wx2126,0wx2126), + (0wx212A,0wx212B), + (0wx212E,0wx212E), + (0wx2180,0wx2182), + (0wx3041,0wx3094), + (0wx30A1,0wx30FA), + (0wx3105,0wx312C), + (0wxAC00,0wxD7A3) + ] : CharClasses.CharRange + + val ideoRange = [(0wx3007,0wx3007), + (0wx3021,0wx3029), + (0wx4E00,0wx9FA5) + ] : CharClasses.CharRange + + val combRange = [(0wx0300,0wx0345), + (0wx0360,0wx0361), + (0wx0483,0wx0486), + (0wx0591,0wx05A1), + (0wx05A3,0wx05B9), + (0wx05BB,0wx05BD), + (0wx05BF,0wx05BF), + (0wx05C1,0wx05C2), + (0wx05C4,0wx05C4), + (0wx064B,0wx0652), + (0wx0670,0wx0670), + (0wx06D6,0wx06DC), + (0wx06DD,0wx06DF), + (0wx06E0,0wx06E4), + (0wx06E7,0wx06E8), + (0wx06EA,0wx06ED), + (0wx0901,0wx0903), + (0wx093C,0wx093C), + (0wx093E,0wx094C), + (0wx094D,0wx094D), + (0wx0951,0wx0954), + (0wx0962,0wx0963), + (0wx0981,0wx0983), + (0wx09BC,0wx09BC), + (0wx09BE,0wx09BE), + (0wx09BF,0wx09BF), + (0wx09C0,0wx09C4), + (0wx09C7,0wx09C8), + (0wx09CB,0wx09CD), + (0wx09D7,0wx09D7), + (0wx09E2,0wx09E3), + (0wx0A02,0wx0A02), + (0wx0A3C,0wx0A3C), + (0wx0A3E,0wx0A3E), + (0wx0A3F,0wx0A3F), + (0wx0A40,0wx0A42), + (0wx0A47,0wx0A48), + (0wx0A4B,0wx0A4D), + (0wx0A70,0wx0A71), + (0wx0A81,0wx0A83), + (0wx0ABC,0wx0ABC), + (0wx0ABE,0wx0AC5), + (0wx0AC7,0wx0AC9), + (0wx0ACB,0wx0ACD), + (0wx0B01,0wx0B03), + (0wx0B3C,0wx0B3C), + (0wx0B3E,0wx0B43), + (0wx0B47,0wx0B48), + (0wx0B4B,0wx0B4D), + (0wx0B56,0wx0B57), + (0wx0B82,0wx0B83), + (0wx0BBE,0wx0BC2), + (0wx0BC6,0wx0BC8), + (0wx0BCA,0wx0BCD), + (0wx0BD7,0wx0BD7), + (0wx0C01,0wx0C03), + (0wx0C3E,0wx0C44), + (0wx0C46,0wx0C48), + (0wx0C4A,0wx0C4D), + (0wx0C55,0wx0C56), + (0wx0C82,0wx0C83), + (0wx0CBE,0wx0CC4), + (0wx0CC6,0wx0CC8), + (0wx0CCA,0wx0CCD), + (0wx0CD5,0wx0CD6), + (0wx0D02,0wx0D03), + (0wx0D3E,0wx0D43), + (0wx0D46,0wx0D48), + (0wx0D4A,0wx0D4D), + (0wx0D57,0wx0D57), + (0wx0E31,0wx0E31), + (0wx0E34,0wx0E3A), + (0wx0E47,0wx0E4E), + (0wx0EB1,0wx0EB1), + (0wx0EB4,0wx0EB9), + (0wx0EBB,0wx0EBC), + (0wx0EC8,0wx0ECD), + (0wx0F18,0wx0F19), + (0wx0F35,0wx0F35), + (0wx0F37,0wx0F37), + (0wx0F39,0wx0F39), + (0wx0F3E,0wx0F3E), + (0wx0F3F,0wx0F3F), + (0wx0F71,0wx0F84), + (0wx0F86,0wx0F8B), + (0wx0F90,0wx0F95), + (0wx0F97,0wx0F97), + (0wx0F99,0wx0FAD), + (0wx0FB1,0wx0FB7), + (0wx0FB9,0wx0FB9), + (0wx20D0,0wx20DC), + (0wx20E1,0wx20E1), + (0wx302A,0wx302F), + (0wx3099,0wx3099), + (0wx309A,0wx309A) + ] : CharClasses.CharRange + + val extRange = [(0wx00B7,0wx00B7), + (0wx02D0,0wx02D0), + (0wx02D1,0wx02D1), + (0wx0387,0wx0387), + (0wx0640,0wx0640), + (0wx0E46,0wx0E46), + (0wx0EC6,0wx0EC6), + (0wx3005,0wx3005), + (0wx3031,0wx3035), + (0wx309D,0wx309E), + (0wx30FC,0wx30FE) + ] : CharClasses.CharRange + + val nmsRange = List.concat + [[(0wx3A,0wx3A),(0wx5F,0wx5F)](* :_ *), + (* HACK: added to be able to parse ArgoUML xmi.id's *) + [(0wx2D,0wx2D),(0wx2E,0wx2E)], (* -. *) + digitRange, (* another hack: ArgoUML xmi.id's now start with digits... *) + baseRange, + ideoRange] + + val nameRange = List.concat + [[(0wx2D,0wx2D),(0wx2E,0wx2E)](* -. *), + digitRange, + combRange, + extRange, + nmsRange] + + val pubidRange = List.concat + [map (fn c => (c,c)) [0wx0A,0wx0D,0wx20], (* space,cr,lf *) + map (fn c => (c,c)) (UniChar.String2Data "-'()+,./:=?;!*#@$_%"), + [(0wx0030,0wx0039),(0wx0041,0wx005A),(0wx0061,0wx007A)] (* [0-9A-Za-z] *) + ] : CharClasses.CharRange + + val encRange = + [(0wx002D,0wx002E), (* -. *) + (0wx0030,0wx0039), (* 0-9 *) + (0wx0041,0wx005A), (* A-Z *) + (0wx005F,0wx005F), (* _ *) + (0wx0061,0wx007A) (* a-z *) + ] : CharClasses.CharRange + +(****************************************************************************) +(* XML 1.1 *) +(* *) +(* NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | *) +(* [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | *) +(* [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | *) +(* [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | *) +(* [#x10000-#xEFFFF] *) +(* NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | *) +(* [#x0300-#x036F] | [#x203F-#x2040] *) +(****************************************************************************) + + val nameStartCharRange = + [(0wx3A,0wx3A),(* : *) + (0wx0041,0wx005A), (* A-Z *) + (0wx005F,0wx005F), (* _ *) + (0wx0061,0wx007A), (* a-z *) + (0wxC0,0wxD6), + (0wxD8,0wxF6), + (0wxF8,0wx2FF), + (0wx370,0wx37D), + (0wx37F,0wx1FFF), + (0wx200C,0wx200D), + (0wx2070,0wx218F), + (0wx2C00,0wx2FEF), + (0wx3001,0wxD7FF), + (0wxF900,0wxFDCF), + (0wxFDF0,0wxFFFD), + (0wx10000,0wxEFFFF) + ] : CharClasses.CharRange + + val nameCharRange = + nameStartCharRange@ + [(0wx002D,0wx002E), (* -. *) + (0wx0030,0wx0039), (* 0-9 *) + (0wxB7,0wxB7), + (0wx0300,0wx036F), + (0wx203F,0wx2040) + ] : CharClasses.CharRange + + end diff --git a/fxp/src/Unicode/Decode/decode.sml b/fxp/src/Unicode/Decode/decode.sml new file mode 100644 index 0000000..556c2de --- /dev/null +++ b/fxp/src/Unicode/Decode/decode.sml @@ -0,0 +1,295 @@ +(*--------------------------------------------------------------------------*) +(* Structure: Decode *) +(* *) +(* Exceptions raised by functions in this structure: *) +(* checkEncoding : NoSuchFile *) +(* encCloseFile : none *) +(* encFileName : none *) +(*--------------------------------------------------------------------------*) +signature Decode = + sig + structure Error : DecodeError + + type DecFile + + exception DecEof of DecFile + exception DecError of DecFile * bool * Error.DecodeError + + val decUri : DecFile -> Uri.Uri + val decName : DecFile -> string + val decEncoding : DecFile -> Encoding.Encoding + + val decOpenXml : Uri.Uri option -> DecFile + val decOpenUni : Uri.Uri option * Encoding.Encoding -> DecFile + val decClose : DecFile -> DecFile + + val decCommit : DecFile -> unit + val decSwitch : DecFile * string -> DecFile + + val decGetChar : DecFile -> UniChar.Char * DecFile + val decGetArray : DecFile -> UniChar.Char array -> int * DecFile * Error.DecodeError option + end + +structure Decode : Decode = + struct + structure Error = DecodeError + open + UniChar Encoding Error + DecodeFile DecodeMisc DecodeUcs2 DecodeUcs4 + DecodeUtf16 DecodeUtf8 DecodeUtil + + type DecFile = Encoding * File + exception DecEof of DecFile + exception DecError of DecFile * bool * DecodeError + + (*--------------------------------------------------------------------*) + (* close an encoded entity. *) + (*--------------------------------------------------------------------*) + fun decClose (_,f) = (NOENC,f) before closeFile f + (*--------------------------------------------------------------------*) + (* get the uri string of an encoded entity. *) + (*--------------------------------------------------------------------*) + fun decName (_,f) = fileName f + (*--------------------------------------------------------------------*) + (* get the uri of an encoded entity. *) + (*--------------------------------------------------------------------*) + fun decUri (_,f) = fileUri f + (*--------------------------------------------------------------------*) + (* get the encoding of an encoded entity. *) + (*--------------------------------------------------------------------*) + fun decEncoding (enc,_) = enc + + (*--------------------------------------------------------------------*) + (* commit the auto-detected encoding. *) + (*--------------------------------------------------------------------*) + fun decCommit (enc,f) = + case enc + of UTF8 => () + | UTF16B => () + | UTF16L => () + | _ => raise DecError((enc,f),false,ERR_NO_ENC_DECL(encodingName enc)) + + (*--------------------------------------------------------------------*) + (* change to another - compatible - encoding. *) + (*--------------------------------------------------------------------*) + fun decSwitch ((enc,f),decl) = + let + val decEnc = isEncoding decl + val _ = if decEnc<>NOENC then () + else raise DecError((enc,f),false,ERR_UNSUPPORTED_ENC decl) + val newEnc = switchEncoding(enc,decEnc) + val _ = if decEnc<>NOENC orelse enc=NOENC then () + else raise DecError((enc,f),false,ERR_INCOMPATIBLE_ENC(encodingName enc,decl)) + in (newEnc,f) + end + + (*--------------------------------------------------------------------*) + (* get a character from an encoded entity. *) + (*--------------------------------------------------------------------*) + fun decGetChar (enc,f) = + let val (c,f1) = + case enc + of NOENC => raise EndOfFile f + | ASCII => getCharAscii f + | EBCDIC => getCharEbcdic f + | LATIN1 => getCharLatin1 f + | UCS2B => getCharUcs2b f + | UCS2L => getCharUcs2l f + | UCS4B => getCharUcs4b f + | UCS4L => getCharUcs4l f + | UCS4SB => getCharUcs4sb f + | UCS4SL => getCharUcs4sl f + | UTF8 => getCharUtf8 f + | UTF16B => getCharUtf16b f + | UTF16L => getCharUtf16l f + in (c,(enc,f1)) + end + handle EndOfFile f => raise DecEof(NOENC,f) + | DecodeError(f,eof,err) => raise DecError((enc,f),eof,err) + + (*--------------------------------------------------------------------*) + (* Load new characters, depending on the current entity's encoding. *) + (*--------------------------------------------------------------------*) + fun decGetArray (enc,f) arr = + let + (*--------------------------------------------------------------*) + (* Load the buffer with len new characters, or until the entity *) + (* end is reached. Close the current file in that case. *) + (* Local exception Ended is needed in order to preserve tail *) + (* recursion. *) + (*--------------------------------------------------------------*) + fun loadArray getChar = + let + val ende = Array.length arr + exception Error of int * exn + fun doit (idx,f) = + if idx=ende then (ende,(enc,f),NONE) + else let val (c,f1) = getChar f handle exn => raise Error (idx,exn) + val _ = Array.update(arr,idx,c) + in doit (idx+1,f1) + end + in doit (0,f) handle Error(idx,exn) + => case exn + of EndOfFile f => (idx,(NOENC,f),NONE) + | DecodeError (f,_,err) => (idx,(enc,f),SOME err) + | _ => raise exn + end + in case enc + of NOENC => (0,(NOENC,f),NONE) + | ASCII => loadArray getCharAscii + | EBCDIC => loadArray getCharEbcdic + | LATIN1 => loadArray getCharLatin1 + | UCS2B => loadArray getCharUcs2b + | UCS2L => loadArray getCharUcs2l + | UCS4B => loadArray getCharUcs4b + | UCS4L => loadArray getCharUcs4l + | UCS4SB => loadArray getCharUcs4sb + | UCS4SL => loadArray getCharUcs4sl + | UTF8 => loadArray getCharUtf8 + | UTF16B => loadArray getCharUtf16b + | UTF16L => loadArray getCharUtf16l + end + + + (*--------------------------------------------------------------------*) + (* open an XML file and try to auto-detect its encoding. *) + (*--------------------------------------------------------------------*) + (* Auto-detection of the encoding of XML entities according to App. F *) + (* of the XML recommendation. *) + (* *) + (* The file is opened in basic mode and upto four bytes are read from *) + (* it in order to detect the encoding: if they constitute a prefix of *) + (* " (nil,f) + + fun detect bs = + case bs + of + [0wx0,0wx0,0wxFE,0wxFF] => (UCS4B,nil) + | [0wxFF,0wxFE,0wx0,0wx0] => (UCS4L,nil) + | [0wxFE,0wxFF,0wx0,b4] => + if b4 <> 0wx0 then (UTF16B,[0wx0,b4]) + else (UTF8,bs) + | [0wxFF,0wxFE,b3,0wx0] => + if b3 <> 0wx0 then (UTF16L,[b3,0wx0]) + else (UTF8,bs) + | [0wxEF,0wxBB,0wxBF,b4] => (UTF8,[b4]) + | [0wx0,0wx0,0wx0,0wx3C] => (UCS4B,bs) + | [0wx3C,0wx0,0wx0,0wx0] => (UCS4L,bs) + | [0wx0,0wx0,0wx3C,0wx0] => (UCS4SB,bs) + | [0wx0,0wx3C,0wx0,0wx0] => (UCS4SL,bs) + | [0wx0,b2,b3,b4] => + if (b2=0wx3C orelse b2=0wx25 orelse b2=0wx20 + orelse b2=0wx09 orelse b2=0wx0D orelse b2=0wx0A) + andalso (b3<>0wx0 orelse b4<>0wx0) then (UTF16B,bs) + else (UTF8,bs) + | [b1,0wx0,b3,b4] => + if (b1=0wx3C orelse b1=0wx25 orelse b1=0wx20 + orelse b1=0wx09 orelse b1=0wx0D orelse b1=0wx0A) + andalso (b3<>0wx0 orelse b4<>0wx0) then (UTF16L,bs) + else (UTF8,bs) + | [0wx4C,0wx6F,0wxA7,0wx94] => (EBCDIC,bs) + | _ => (UTF8,bs) + + val f = openFile uri + val (bs,f1) = get4Bytes(0,f) + val (enc,unget) = detect bs + in (enc,ungetBytes(f1,unget)) + end + + (*--------------------------------------------------------------------*) + (* open a Unicode file. Check whether it starts with a byte order *) + (* mark. If yes, chose UTF16 encoding, otherwise use the default that *) + (* is provided as second argument. *) + (* *) + (* return the encoded file, a list of bytes looked ahead and the *) + (* encoding. *) + (*--------------------------------------------------------------------*) + fun decOpenUni (uri,default) = + let + fun def(f,bs) = + (default,ungetBytes(f,bs)) + fun detect f = + let val (b1,f1) = getByte f + in case b1 + of 0wxFE => (let val (b2,f2) = getByte f1 + in if b2 = 0wxFF then (UTF16B,f2) + else def(f2,[b1,b2]) + end handle EndOfFile f => def(f,[b1])) + | 0wxFF => (let val (b2,f2) = getByte f1 + in if b2 = 0wxFE then (UTF16L,f2) + else def(f2,[b1,b2]) + end handle EndOfFile f => def(f,[b1])) + | _ => def(f1,[b1]) + end handle EndOfFile f => def(f,nil) + val f = openFile uri + val (enc,f1) = detect f + in (enc,f1) + end + end + diff --git a/fxp/src/Unicode/Decode/decodeError.sml b/fxp/src/Unicode/Decode/decodeError.sml new file mode 100644 index 0000000..72b84a4 --- /dev/null +++ b/fxp/src/Unicode/Decode/decodeError.sml @@ -0,0 +1,118 @@ + + + + + +(*--------------------------------------------------------------------------*) +(* Structure: DecodeError *) +(* *) +(* Exceptions raised by functions in this structure: *) +(* decodeMessage : none *) +(*--------------------------------------------------------------------------*) +signature DecodeError = + sig + datatype DecodeError = + ERR_ILLEGAL_CHAR of DecodeFile.Byte * string + | ERR_NON_UNI_UCS4 of UniChar.Char + | ERR_EOF_UCS4 of int * DecodeFile.Byte list + | ERR_NON_DIRECT_UTF7 of DecodeFile.Byte + | ERR_PADDING_UTF7 of UniChar.Char + | ERR_ILLFORMED_UTF8 of DecodeFile.Byte * int * int + | ERR_ILLEGAL_UTF8 of DecodeFile.Byte + | ERR_INVALID_UTF8_SEQ of DecodeFile.Byte list + | ERR_EOF_UTF8 of int * int + | ERR_NON_UNI_UTF8 of UniChar.Char * int + | ERR_EOF_UCS2 of DecodeFile.Byte + | ERR_EOF_UTF16 of DecodeFile.Byte + | ERR_LOW_SURROGATE of UniChar.Char + | ERR_HIGH_SURROGATE of UniChar.Char * UniChar.Char + | ERR_EOF_SURROGATE of UniChar.Char + | ERR_NO_ENC_DECL of string + | ERR_UNSUPPORTED_ENC of string + | ERR_INCOMPATIBLE_ENC of string * string + + val decodeMessage : DecodeError -> string list + + exception DecodeError of DecodeFile.File * bool * DecodeError + end + +structure DecodeError : DecodeError = + struct + open + DecodeFile UtilString UniChar + + datatype DecodeError = + ERR_ILLEGAL_CHAR of DecodeFile.Byte * string + | ERR_NON_UNI_UCS4 of UniChar.Char + | ERR_EOF_UCS4 of int * DecodeFile.Byte list + | ERR_NON_DIRECT_UTF7 of DecodeFile.Byte + | ERR_PADDING_UTF7 of UniChar.Char + | ERR_ILLFORMED_UTF8 of DecodeFile.Byte * int * int + | ERR_ILLEGAL_UTF8 of DecodeFile.Byte + | ERR_INVALID_UTF8_SEQ of DecodeFile.Byte list + | ERR_EOF_UTF8 of int * int + | ERR_NON_UNI_UTF8 of UniChar.Char * int + | ERR_EOF_UCS2 of DecodeFile.Byte + | ERR_EOF_UTF16 of DecodeFile.Byte + | ERR_LOW_SURROGATE of UniChar.Char + | ERR_HIGH_SURROGATE of UniChar.Char * UniChar.Char + | ERR_EOF_SURROGATE of UniChar.Char + | ERR_NO_ENC_DECL of string + | ERR_UNSUPPORTED_ENC of string + | ERR_INCOMPATIBLE_ENC of string * string + + fun Char2Hex c = "0x"^UtilString.toUpperString(StringCvt.padLeft #"0" 4 (Chars.toString c)) + + fun decodeMessage err = + case err + of ERR_ILLEGAL_CHAR(b,what) => + [Byte2Hex b,"is not",prependAnA what,"character"] + + | ERR_NON_UNI_UCS4 c => + ["UCS-4 coded non-Unicode character",Char2Uni c] + | ERR_EOF_UCS4(pos,bytes) => + ["End of file after",Int2String pos,"bytes of UCS-4 character", + "starting with ",List2String0 Byte2Hex bytes] + + | ERR_NON_DIRECT_UTF7 b => + ["Indirect UTF-7 character ",Byte2Hex b,"in non-shifted mode"] + | ERR_PADDING_UTF7 pad => + ["Non-zero padding",Char2Hex pad,"at end of UTF-7 shifted sequence"] + + | ERR_ILLFORMED_UTF8 (b,len,pos) => + [numberNth pos,"byte",Byte2Hex b,"of a",Int2String len^"-byte", + "UTF-8 sequence does not start with bits 10"] + | ERR_ILLEGAL_UTF8 b => + ["Byte",Byte2Hex b,"is neither ASCII nor does it start", + "a valid multi-byte UTF-8 sequence"] + | ERR_EOF_UTF8 (len,pos) => + ["End of file terminates a ",Int2String len^"-byte", + "UTF-8 sequence before the ",numberNth pos,"byte"] + | ERR_NON_UNI_UTF8 (c,len) => + [Int2String len^"-byte UTF-8 sequence decodes to non-Unicode character",Char2Uni c] + | ERR_INVALID_UTF8_SEQ bs => + ["Invalid UTF-8 sequence",List2xString (""," ","") Byte2Hex bs] + + | ERR_EOF_UCS2 b => + ["End of file before second byte of UCS-2 character starting with",Byte2Hex b] + | ERR_EOF_UTF16 b => + ["End of file before second byte of UTF-16 character starting with",Byte2Hex b] + + | ERR_LOW_SURROGATE c => + ["Low surrogate",Char2Uni c,"without preceding high surrogate"] + | ERR_HIGH_SURROGATE (c,c1) => + ["High surrogate",Char2Uni c,"followed by",Char2Uni c1,"instead of low surrogate"] + | ERR_EOF_SURROGATE c => + ["High surrogate",Char2Uni c,"followed by the end of file"] + + | ERR_NO_ENC_DECL auto => + ["Couldn't parse encoding declaration but auto-detected encoding",auto,"required so"] + | ERR_UNSUPPORTED_ENC enc => + ["Unsupported encoding",enc] + | ERR_INCOMPATIBLE_ENC (enc,auto) => + ["Encoding",enc,"is incompatible with auto-detected encoding",auto] + + exception DecodeError of File * bool * DecodeError + end + + diff --git a/fxp/src/Unicode/Decode/decodeFile.sml b/fxp/src/Unicode/Decode/decodeFile.sml new file mode 100644 index 0000000..51b7724 --- /dev/null +++ b/fxp/src/Unicode/Decode/decodeFile.sml @@ -0,0 +1,151 @@ +(*--------------------------------------------------------------------------*) +(* Structure: DecodeBasic *) +(* *) +(* Exceptions raised by functions in this structure: *) +(* closeFile : none *) +(* filePos : none *) +(* fileName : none *) +(* nextByte : EndOfFile *) +(* openFile : NoSuchFile *) +(*--------------------------------------------------------------------------*) +signature DecodeFile = + sig + structure Bytes : WORD + + type File + type Byte = Bytes.word + + exception EndOfFile of File + + val Char2Byte : UniChar.Char -> Byte + val Byte2Char : Byte -> UniChar.Char + val Byte2Hex : Byte -> string + + val openFile : Uri.Uri option -> File + val closeFile : File -> unit + + val getByte : File -> Byte * File + val ungetBytes : File * Byte list -> File + + val fileUri : File -> Uri.Uri + val fileName : File -> string + end + +structure DecodeFile : DecodeFile = + struct + open + UniChar Uri UtilError + + structure Bytes = Word8 + type Byte = Bytes.word + + fun Byte2Char b = Chars.fromLargeWord(Bytes.toLargeWord b) + fun Byte2Hex b = + "0x"^UtilString.toUpperString(StringCvt.padLeft #"0" 2 (Bytes.toString b)) + fun Char2Byte c = Bytes.fromLargeWord(Chars.toLargeWord c) + + type instream = TextIO.instream + val closeIn = TextIO.closeIn + val input = TextIO.input + val input1 = TextIO.input1 + val openIn = TextIO.openIn + val stdIn = TextIO.stdIn + + (*--------------------------------------------------------------------*) + (* a file type is stdin or a uri with its string representation and *) + (* the file it is mapped to. *) + (* a file position is a stream, an int position and a file type. *) + (* a file is a file position, a buffer, its size and current index. *) + (*--------------------------------------------------------------------*) + datatype FileType = STD | FNAME of (Uri * string * string * bool) + type FilePos = FileType * instream * int + type File = FilePos * Word8Vector.vector * int * int + + exception EndOfFile of File + val nullVec = Word8Vector.fromList nil + + (*--------------------------------------------------------------------*) + (* return the uri of a file. *) + (*--------------------------------------------------------------------*) + fun fileUri ((typ,_,_),_,_,_) = + case typ + of STD => emptyUri + | FNAME(uri,_,_,_) => uri + (*--------------------------------------------------------------------*) + (* return the uri string name of a file. *) + (*--------------------------------------------------------------------*) + fun fileName ((typ,_,_),_,_,_) = + case typ + of STD => "" + | FNAME(_,str,_,_) => str + (*--------------------------------------------------------------------*) + (* return the uri string and the position in the the file. *) + (*--------------------------------------------------------------------*) + fun filePos ((typ,_,p),_,s,i) = + case typ + of STD => ("",p+i-s) + | FNAME(_,str,_,_) => (str,p+i-s) + + (*--------------------------------------------------------------------*) + (* open a file; report IO errors by raising NoSuchFile. *) + (*--------------------------------------------------------------------*) + fun openFile uriOpt = + let val (typ,stream) = + case uriOpt + of NONE => (STD,stdIn) + | SOME uri => let val (str,fname,tmp) = retrieveUri uri + in (FNAME(uri,str,fname,tmp),openIn fname) + end + handle IO.Io {name,cause,...} + => raise NoSuchFile(name,exnMessage cause) + in ((typ,stream,0),nullVec,0,0) + end + + (*--------------------------------------------------------------------*) + (* close the file; ignore IO errors. *) + (*--------------------------------------------------------------------*) + fun closeStream (typ,stream,_) = + case typ + of STD => () + | FNAME(_,uri,fname,tmp) + => let val _ = closeIn stream handle IO.Io _ => () + val _ = (if tmp andalso OS.FileSys.access(fname,nil) + then OS.FileSys.remove fname else ()) + handle exn as OS.SysErr _ => + TextIO.output(TextIO.stdErr,String.concat + ["Error removing temporary file ",fname,"for URI",uri, + "(",exnMessage exn,")\n"]) + + in () + end + fun closeFile (tsp,_,_,_) = closeStream tsp + + (*--------------------------------------------------------------------*) + (* read a byte from the file; if at the end of buffer, reload it. *) + (* if a reload fails or returns an IO error, raise EndOfFile. --------*) + (*--------------------------------------------------------------------*) + fun getByte (tsp,vec,s,i) = + if i nullVec + val s = Word8Vector.length v + in if s=0 then let val _ = closeStream tsp + in raise EndOfFile(tsp,v,0,0) + end + else (Word8Vector.sub(v,0),((typ,stream,pos+s),v,s,1)) + end + + (*--------------------------------------------------------------------*) + (* un-get some bytes. this should only happen while checking for a *) + (* byte-order mark or xml/text declaration. It should be efficient in *) + (* that case, otherwise might be very space-consuming. *) + (*--------------------------------------------------------------------*) + fun ungetBytes ((tsp,vec,s,i),bs) = + let val len = length bs + in if len<=i then (tsp,vec,s,i-len) + else let val diff = len-i + val vec0 = Word8Vector.fromList(List.take(bs,diff)) + in (tsp,Word8Vector.concat [vec0,vec],s+diff,0) + end + end + end diff --git a/fxp/src/Unicode/Decode/decodeMisc.sml b/fxp/src/Unicode/Decode/decodeMisc.sml new file mode 100644 index 0000000..81993ba --- /dev/null +++ b/fxp/src/Unicode/Decode/decodeMisc.sml @@ -0,0 +1,76 @@ +signature DecodeMisc = + sig + val getCharAscii : DecodeFile.File -> UniChar.Char * DecodeFile.File + val getCharEbcdic : DecodeFile.File -> UniChar.Char * DecodeFile.File + val getCharEof : DecodeFile.File -> UniChar.Char * DecodeFile.File + val getCharLatin1 : DecodeFile.File -> UniChar.Char * DecodeFile.File + end + +structure DecodeMisc : DecodeMisc = + struct + open + UniChar DecodeFile DecodeError + + fun getCharEof f = raise EndOfFile f + + (*--------------------------------------------------------------------*) + (* ASCII characters must be lower than 0wx80 *) + (*--------------------------------------------------------------------*) + fun getCharAscii f = + let val (b,f1) = getByte f + in if b<0wx80 then (Byte2Char b,f1) + else raise DecodeError(f1,false,ERR_ILLEGAL_CHAR(b,"ASCII")) + end + + (*--------------------------------------------------------------------*) + (* LATIN-1 is the first plane of Unicode. *) + (*--------------------------------------------------------------------*) + fun getCharLatin1 f = let val (b,f1) = getByte f + in (Byte2Char b,f1) + end + + (*--------------------------------------------------------------------*) + (* EBCDIC is mapped to the first plane of Unicode. *) + (*--------------------------------------------------------------------*) + (* according to rfc-1345 (and gnu recode experiments) *) + val ebcdic2latinTab = Vector.fromList + [0wx00,0wx01,0wx02,0wx03,0wx9C,0wx09,0wx86,0wx7F, + 0wx97,0wx8D,0wx8E,0wx0B,0wx0C,0wx0D,0wx0E,0wx0F, + 0wx10,0wx11,0wx12,0wx13,0wx9D,0wx85,0wx08,0wx87, + 0wx18,0wx19,0wx92,0wx8F,0wx1C,0wx1D,0wx1E,0wx1F, + 0wx80,0wx81,0wx82,0wx83,0wx84,0wx0A,0wx17,0wx1B, + 0wx88,0wx89,0wx8A,0wx8B,0wx8C,0wx05,0wx06,0wx07, + 0wx90,0wx91,0wx16,0wx93,0wx94,0wx95,0wx96,0wx04, + 0wx98,0wx99,0wx9A,0wx9B,0wx14,0wx15,0wx9E,0wx1A, + 0wx20,0wxA0,0wxA1,0wxA2,0wxA3,0wxA4,0wxA5,0wxA6, + 0wxA7,0wxA8,0wx5B,0wx2E,0wx3C,0wx28,0wx2B,0wx21, + 0wx26,0wxA9,0wxAA,0wxAB,0wxAC,0wxAD,0wxAE,0wxAF, + 0wxB0,0wxB1,0wx5D,0wx24,0wx2A,0wx29,0wx3B,0wx5E, + 0wx2D,0wx2F,0wxB2,0wxB3,0wxB4,0wxB5,0wxB6,0wxB7, + 0wxB8,0wxB9,0wx7C,0wx2C,0wx25,0wx5F,0wx3E,0wx3F, + 0wxBA,0wxBB,0wxBC,0wxBD,0wxBE,0wxBF,0wxC0,0wxC1, + 0wxC2,0wx60,0wx3A,0wx23,0wx40,0wx27,0wx3D,0wx22, + 0wxC3,0wx61,0wx62,0wx63,0wx64,0wx65,0wx66,0wx67, + 0wx68,0wx69,0wxC4,0wxC5,0wxC6,0wxC7,0wxC8,0wxC9, + 0wxCA,0wx6A,0wx6B,0wx6C,0wx6D,0wx6E,0wx6F,0wx70, + 0wx71,0wx72,0wxCB,0wxCC,0wxCD,0wxCE,0wxCF,0wxD0, + 0wxD1,0wx7E,0wx73,0wx74,0wx75,0wx76,0wx77,0wx78, + 0wx79,0wx7A,0wxD2,0wxD3,0wxD4,0wxD5,0wxD6,0wxD7, + 0wxD8,0wxD9,0wxDA,0wxDB,0wxDC,0wxDD,0wxDE,0wxDF, + 0wxE0,0wxE1,0wxE2,0wxE3,0wxE4,0wxE5,0wxE6,0wxE7, + 0wx7B,0wx41,0wx42,0wx43,0wx44,0wx45,0wx46,0wx47, + 0wx48,0wx49,0wxE8,0wxE9,0wxEA,0wxEB,0wxEC,0wxED, + 0wx7D,0wx4A,0wx4B,0wx4C,0wx4D,0wx4E,0wx4F,0wx50, + 0wx51,0wx52,0wxEE,0wxEF,0wxF0,0wxF1,0wxF2,0wxF3, + 0wx5C,0wx9F,0wx53,0wx54,0wx55,0wx56,0wx57,0wx58, + 0wx59,0wx5A,0wxF4,0wxF5,0wxF6,0wxF7,0wxF8,0wxF9, + 0wx30,0wx31,0wx32,0wx33,0wx34,0wx35,0wx36,0wx37, + 0wx38,0wx39,0wxFA,0wxFB,0wxFC,0wxFD,0wxFE,0wxFF + ] + + fun ebcdic2latin b = Vector.sub(ebcdic2latinTab,Word8.toInt b) + + fun getCharEbcdic f = let val (b,f1) = getByte f + in (ebcdic2latin b,f1) + end + end diff --git a/fxp/src/Unicode/Decode/decodeUcs2.sml b/fxp/src/Unicode/Decode/decodeUcs2.sml new file mode 100644 index 0000000..08a0ab2 --- /dev/null +++ b/fxp/src/Unicode/Decode/decodeUcs2.sml @@ -0,0 +1,37 @@ + + + + + + + +signature DecodeUcs2 = + sig + val getCharUcs2b : DecodeFile.File -> UniChar.Char * DecodeFile.File + val getCharUcs2l : DecodeFile.File -> UniChar.Char * DecodeFile.File + end + +structure DecodeUcs2 : DecodeUcs2 = + struct + open + UniChar Encoding + DecodeFile DecodeError DecodeUtil + + fun getCharUcs2b f = + let + val (b1,f1) = getByte f + val (b2,f2) = getByte f1 handle exn as EndOfFile f + => raise DecodeError(f,true,ERR_EOF_UCS2 b1) + val c = Chars.orb(Chars.<<(Byte2Char b1,0w8),Byte2Char b2) + in (c,f2) + end + + fun getCharUcs2l f = + let + val (b1,f1) = getByte f + val (b2,f2) = getByte f1 handle exn as EndOfFile f + => raise DecodeError(f,true,ERR_EOF_UCS2 b1) + val c = Chars.orb(Chars.<<(Byte2Char b2,0w8),Byte2Char b1) + in (c,f2) + end + end diff --git a/fxp/src/Unicode/Decode/decodeUcs4.sml b/fxp/src/Unicode/Decode/decodeUcs4.sml new file mode 100644 index 0000000..eb608a4 --- /dev/null +++ b/fxp/src/Unicode/Decode/decodeUcs4.sml @@ -0,0 +1,91 @@ + + + + + + + + +signature DecodeUcs4 = + sig + val getCharUcs4b : DecodeFile.File -> UniChar.Char * DecodeFile.File + val getCharUcs4l : DecodeFile.File -> UniChar.Char * DecodeFile.File + val getCharUcs4sb : DecodeFile.File -> UniChar.Char * DecodeFile.File + val getCharUcs4sl : DecodeFile.File -> UniChar.Char * DecodeFile.File + end + +structure DecodeUcs4 : DecodeUcs4 = + struct + open + UniChar UniClasses + DecodeFile DecodeError DecodeUtil + + fun getCharUcs4b f = + let + val (b1,f1) = getByte f + val (b2,f2) = getByte f1 handle EndOfFile f + => raise DecodeError(f,true,ERR_EOF_UCS4(1,[b1])) + val (b3,f3) = getByte f2 handle EndOfFile f + => raise DecodeError(f,true,ERR_EOF_UCS4(1,[b1,b2])) + val (b4,f4) = getByte f3 handle EndOfFile f + => raise DecodeError(f,true,ERR_EOF_UCS4(1,[b1,b2,b3])) + val c = Chars.orb(Chars.orb(Chars.<<(Byte2Char b1,0w24), + Chars.<<(Byte2Char b2,0w16)), + Chars.orb(Chars.<<(Byte2Char b3,0w08), + Byte2Char b4)) + in if isUnicode c then (c,f4) + else raise DecodeError(f4,false,ERR_NON_UNI_UCS4 c) + end + + fun getCharUcs4l f = + let + val (b1,f1) = getByte f + val (b2,f2) = getByte f1 handle EndOfFile f + => raise DecodeError(f,true,ERR_EOF_UCS4(1,[b1])) + val (b3,f3) = getByte f2 handle EndOfFile f + => raise DecodeError(f,true,ERR_EOF_UCS4(1,[b1,b2])) + val (b4,f4) = getByte f3 handle EndOfFile f + => raise DecodeError(f,true,ERR_EOF_UCS4(1,[b1,b2,b3])) + val c = Chars.orb(Chars.orb(Chars.<<(Byte2Char b4,0w24), + Chars.<<(Byte2Char b3,0w16)), + Chars.orb(Chars.<<(Byte2Char b2,0w08), + Byte2Char b1)) + in if isUnicode c then (c,f4) + else raise DecodeError(f4,false,ERR_NON_UNI_UCS4 c) + end + + fun getCharUcs4sb f = + let + val (b1,f1) = getByte f + val (b2,f2) = getByte f1 handle EndOfFile f + => raise DecodeError(f,true,ERR_EOF_UCS4(1,[b1])) + val (b3,f3) = getByte f2 handle EndOfFile f + => raise DecodeError(f,true,ERR_EOF_UCS4(1,[b1,b2])) + val (b4,f4) = getByte f3 handle EndOfFile f + => raise DecodeError(f,true,ERR_EOF_UCS4(1,[b1,b2,b3])) + val c = Chars.orb(Chars.orb(Chars.<<(Byte2Char b2,0w24), + Chars.<<(Byte2Char b1,0w16)), + Chars.orb(Chars.<<(Byte2Char b4,0w08), + Byte2Char b3)) + in if isUnicode c then (c,f4) + else raise DecodeError(f4,false,ERR_NON_UNI_UCS4 c) + end + + fun getCharUcs4sl f = + let + val (b1,f1) = getByte f + val (b2,f2) = getByte f1 handle EndOfFile f + => raise DecodeError(f,true,ERR_EOF_UCS4(1,[b1])) + val (b3,f3) = getByte f2 handle EndOfFile f + => raise DecodeError(f,true,ERR_EOF_UCS4(1,[b1,b2])) + val (b4,f4) = getByte f3 handle EndOfFile f + => raise DecodeError(f,true,ERR_EOF_UCS4(1,[b1,b2,b3])) + val c = Chars.orb(Chars.orb(Chars.<<(Byte2Char b3,0w24), + Chars.<<(Byte2Char b4,0w16)), + Chars.orb(Chars.<<(Byte2Char b1,0w08), + Byte2Char b2)) + in if isUnicode c then (c,f4) + else raise DecodeError(f4,false,ERR_NON_UNI_UCS4 c) + end + end + diff --git a/fxp/src/Unicode/Decode/decodeUtf16.sml b/fxp/src/Unicode/Decode/decodeUtf16.sml new file mode 100644 index 0000000..a5726f3 --- /dev/null +++ b/fxp/src/Unicode/Decode/decodeUtf16.sml @@ -0,0 +1,61 @@ + + + + + + + +signature DecodeUtf16 = + sig + val getCharUtf16b : DecodeFile.File -> UniChar.Char * DecodeFile.File + val getCharUtf16l : DecodeFile.File -> UniChar.Char * DecodeFile.File + end + +structure DecodeUtf16 : DecodeUtf16 = + struct + open + UniChar Encoding + DecodeFile DecodeError DecodeUtil + + fun getCharUtf16b f = + let + val (b1,f1) = getByte f + val (b2,f2) = getByte f1 handle exn as EndOfFile f + => raise DecodeError(f,true,ERR_EOF_UTF16 b1) + val c = Chars.orb(Chars.<<(Byte2Char b1,0w8),Byte2Char b2) + in + if isSurrogate c then (* Chars.orb(c,0wx7FF)=0wxDFFF *) + if isLowSurrogate c then raise DecodeError(f2,false,ERR_LOW_SURROGATE c) + else let + val (b3,f3) = getByte f2 handle exn as EndOfFile f + => raise DecodeError(f,true,ERR_EOF_SURROGATE c) + val (b4,f4) = getByte f3 handle exn as EndOfFile f + => raise DecodeError(f,true,ERR_EOF_UTF16 b3) + val c1 = Chars.orb(Chars.<<(Byte2Char b3,0w8),Byte2Char b4) + in if isLowSurrogate c1 then (combineSurrogates(c,c1),f4) + else raise DecodeError(f4,false,ERR_HIGH_SURROGATE(c,c1)) + end + else (c,f2) + end + + fun getCharUtf16l f = + let + val (b1,f1) = getByte f + val (b2,f2) = getByte f1 handle exn as EndOfFile f + => raise DecodeError(f,true,ERR_EOF_UTF16 b1) + val c = Chars.orb(Chars.<<(Byte2Char b2,0w8),Byte2Char b1) + in + if isSurrogate c then + if isLowSurrogate c then raise DecodeError(f2,false,ERR_LOW_SURROGATE c) + else let + val (b3,f3) = getByte f2 handle exn as EndOfFile f + => raise DecodeError(f,true,ERR_EOF_SURROGATE c) + val (b4,f4) = getByte f3 handle exn as EndOfFile f + => raise DecodeError(f,true,ERR_EOF_UTF16 b3) + val c1 = Chars.orb(Chars.<<(Byte2Char b4,0w8),Byte2Char b3) + in if isLowSurrogate c1 then (combineSurrogates(c,c1),f4) + else raise DecodeError(f4,false,ERR_HIGH_SURROGATE(c,c1)) + end + else (c,f2) + end + end diff --git a/fxp/src/Unicode/Decode/decodeUtf8.sml b/fxp/src/Unicode/Decode/decodeUtf8.sml new file mode 100644 index 0000000..563f714 --- /dev/null +++ b/fxp/src/Unicode/Decode/decodeUtf8.sml @@ -0,0 +1,176 @@ +signature DecodeUtf8 = + sig + val getCharUtf8 : DecodeFile.File -> UniChar.Char * DecodeFile.File + end + +structure DecodeUtf8 : DecodeUtf8 = + struct + open + UniChar UniClasses UtilError UtilInt + DecodeFile DecodeError DecodeUtil + + val THIS_MODULE = "DecodeUtf8" + + infix 8 <<< + infix 7 && + infix 6 ||| + + val op && = Bytes.andb + val op <<< = Chars.<< + val op ||| = Chars.orb + + val byte1switch = Vector.tabulate + (256,fn i => + if i<0x80 then 1 + else if i<0xC0 then 0 + else if i<0xE0 then 2 + else if i<0xF0 then 3 + else if i<0xF8 then 4 + else if i<0xFC then 5 + else if i<0xFE then 6 + else 0) + + val diff2 : Char = 0wx00003080 + val diff3 : Char = diff2 <<< 0wx6 ||| 0wx00020080 + val diff4 : Char = diff3 <<< 0wx6 ||| 0wx00400080 + val diff5 : Char = diff4 <<< 0wx6 ||| 0wx08000080 + val diff6 : Char = diff5 <<< 0wx6 ||| 0wx00000080 + + fun getCharUtf8 f = + let val (b1,f1) = getByte f + in if b1<0wx80 then (Byte2Char b1,f1) + else let val n = Vector.sub(byte1switch,Word8.toInt b1) + in case n + of 0 (* error *) => raise DecodeError(f1,false,ERR_ILLEGAL_UTF8 b1) + | 1 => (Byte2Char b1,f1) + | 2 => + let + val (b2,f2) = getByte f1 handle EndOfFile f + => raise DecodeError(f,true,ERR_EOF_UTF8(n,2)) + in if b2 && 0wxC0 <> 0wx80 + then raise DecodeError(f2,false,ERR_ILLFORMED_UTF8(b2,n,2)) + else let val c = Byte2Char b1 <<< 0w6 + Byte2Char b2 - diff2 + in if c>=0wx80 then (c,f2) + else raise DecodeError(f2,false,ERR_INVALID_UTF8_SEQ [b1,b2]) + end + end + | 3 => + let + val (b2,f2) = getByte f1 handle EndOfFile f + => raise DecodeError(f,true,ERR_EOF_UTF8(n,2)) + val (b3,f3) = getByte f2 handle EndOfFile f + => raise DecodeError(f,true,ERR_EOF_UTF8(n,3)) + in + if b2 && 0wxC0 <> 0wx80 + then raise DecodeError(f3,false,ERR_ILLFORMED_UTF8(b2,n,2)) + else if b3 && 0wxC0 <> 0wx80 + then raise DecodeError(f3,false,ERR_ILLFORMED_UTF8(b2,n,3)) + else let val c = (Byte2Char b1 <<< 0w12 + + Byte2Char b2 <<< 0w06 + + Byte2Char b3 - diff3) + in if c>=0wx800 then (c,f3) + else raise DecodeError + (f3,false,ERR_INVALID_UTF8_SEQ [b1,b2,b3]) + end + end + | 4 => + let + val (b2,f2) = getByte f1 handle EndOfFile f + => raise DecodeError(f,true,ERR_EOF_UTF8(n,2)) + val (b3,f3) = getByte f2 handle EndOfFile f + => raise DecodeError(f,true,ERR_EOF_UTF8(n,3)) + val (b4,f4) = getByte f3 handle EndOfFile f + => raise DecodeError(f,true,ERR_EOF_UTF8(n,4)) + in + if b2 && 0wxC0 <> 0wx80 + then raise DecodeError(f4,false,ERR_ILLFORMED_UTF8(b2,n,2)) + else if b3 && 0wxC0 <> 0wx80 + then raise DecodeError(f4,false,ERR_ILLFORMED_UTF8(b2,n,3)) + else if b4 && 0wxC0 <> 0wx80 + then raise DecodeError(f4,false,ERR_ILLFORMED_UTF8(b2,n,4)) + else let val c = (Byte2Char b1 <<< 0w18 + + Byte2Char b2 <<< 0w12 + + Byte2Char b3 <<< 0w06 + + Byte2Char b4 - diff4) + in + if c>=0wx100000 andalso c<=0wx10FFFF then (c,f4) + else if c<0wx10000 + then raise DecodeError + (f4,false,ERR_INVALID_UTF8_SEQ [b1,b2,b3,b4]) + else raise DecodeError + (f4,false,ERR_NON_UNI_UTF8(c,n)) + end + end + | 5 => + let + val (b2,f2) = getByte f1 handle EndOfFile f + => raise DecodeError(f,true,ERR_EOF_UTF8(n,2)) + val (b3,f3) = getByte f2 handle EndOfFile f + => raise DecodeError(f,true,ERR_EOF_UTF8(n,3)) + val (b4,f4) = getByte f3 handle EndOfFile f + => raise DecodeError(f,true,ERR_EOF_UTF8(n,4)) + val (b5,f5) = getByte f4 handle EndOfFile f + => raise DecodeError(f,true,ERR_EOF_UTF8(n,5)) + in + if b2 && 0wxC0 <> 0wx80 + then raise DecodeError(f5,false,ERR_ILLFORMED_UTF8(b2,n,2)) + else if b3 && 0wxC0 <> 0wx80 + then raise DecodeError(f5,false,ERR_ILLFORMED_UTF8(b2,n,3)) + else if b4 && 0wxC0 <> 0wx80 + then raise DecodeError(f5,false,ERR_ILLFORMED_UTF8(b2,n,4)) + else if b5 && 0wxC0 <> 0wx80 + then raise DecodeError(f5,false,ERR_ILLFORMED_UTF8(b2,n,5)) + else let val c = (Byte2Char b1 <<< 0w24 + + Byte2Char b2 <<< 0w18 + + Byte2Char b3 <<< 0w12 + + Byte2Char b4 <<< 0w06 + + Byte2Char b5 - diff5) + in if c<0wx200000 + then raise DecodeError + (f5,false,ERR_INVALID_UTF8_SEQ [b1,b2,b3,b4,b5]) + else raise DecodeError + (f5,false,ERR_NON_UNI_UTF8(c,n)) + end + end + | 6 => + let + val (b2,f2) = getByte f1 handle EndOfFile f + => raise DecodeError(f,true,ERR_EOF_UTF8(n,2)) + val (b3,f3) = getByte f2 handle EndOfFile f + => raise DecodeError(f,true,ERR_EOF_UTF8(n,3)) + val (b4,f4) = getByte f3 handle EndOfFile f + => raise DecodeError(f,true,ERR_EOF_UTF8(n,4)) + val (b5,f5) = getByte f4 handle EndOfFile f + => raise DecodeError(f,true,ERR_EOF_UTF8(n,5)) + val (b6,f6) = getByte f5 handle EndOfFile f + => raise DecodeError(f,true,ERR_EOF_UTF8(n,6)) + in + if b2 && 0wxC0 <> 0wx80 + then raise DecodeError(f6,false,ERR_ILLFORMED_UTF8(b2,n,2)) + else if b3 && 0wxC0 <> 0wx80 + then raise DecodeError(f6,false,ERR_ILLFORMED_UTF8(b2,n,3)) + else if b4 && 0wxC0 <> 0wx80 + then raise DecodeError(f6,false,ERR_ILLFORMED_UTF8(b2,n,4)) + else if b5 && 0wxC0 <> 0wx80 + then raise DecodeError(f6,false,ERR_ILLFORMED_UTF8(b2,n,5)) + else if b6 && 0wxC0 <> 0wx80 + then raise DecodeError(f6,false,ERR_ILLFORMED_UTF8(b2,n,6)) + else let val c = (Byte2Char b1 <<< 0w30 + + Byte2Char b2 <<< 0w24 + + Byte2Char b3 <<< 0w18 + + Byte2Char b4 <<< 0w12 + + Byte2Char b5 <<< 0w06 + + Byte2Char b6 - diff6) + in if c<0wx4000000 + then raise DecodeError + (f6,false,ERR_INVALID_UTF8_SEQ [b1,b2,b3,b4,b5,b6]) + else raise DecodeError + (f6,false,ERR_NON_UNI_UTF8(c,n)) + end + end + | _ => raise InternalError(THIS_MODULE,"getCharUtf8", + "byte1switch holds "^Int.toString n^ + ">6 for byte "^Bytes.toString b1) + end + end + end diff --git a/fxp/src/Unicode/Decode/decodeUtil.sml b/fxp/src/Unicode/Decode/decodeUtil.sml new file mode 100644 index 0000000..1626a41 --- /dev/null +++ b/fxp/src/Unicode/Decode/decodeUtil.sml @@ -0,0 +1,41 @@ +(* +require "basis.__word"; +require "basis.__word8"; + +require "chars"; +require "decodeBasic"; +require "decodeError"; +*) + +(*--------------------------------------------------------------------------*) +(* Structure: DecodeUtil *) +(* *) +(* Exceptions raised by functions in this structure: *) +(* combineSurrogates : none *) +(* combineUcs4big : none *) +(* combineUcs4little : none *) +(* combineUcs4strangeBig : none *) +(* combineUcs4strangeLittle : none *) +(* combineUtf16big : none *) +(* combineUtf16little : none *) +(* isLowSurrogate : none *) +(* isHighSurrogate : none *) +(* isSurrogate : none *) +(*--------------------------------------------------------------------------*) +signature DecodeUtil = + sig + val isSurrogate : UniChar.Char -> bool + val isLowSurrogate : UniChar.Char -> bool + val isHighSurrogate : UniChar.Char -> bool + val combineSurrogates : UniChar.Char * UniChar.Char -> UniChar.Char + end + +structure DecodeUtil : DecodeUtil = + struct + open UniChar DecodeFile DecodeError + + fun isSurrogate c = Chars.orb(c,0wx7FF)=0wxDFFF + fun isLowSurrogate c = Chars.orb(c,0wx3FF)=0wxDFFF + fun isHighSurrogate c = Chars.orb(c,0wx3FF)=0wxDBFF + fun combineSurrogates(hi,lo) = (hi-0wxD800)*0wx400+lo+0wx2400 : Char + end diff --git a/fxp/src/Unicode/Encode/encode.sml b/fxp/src/Unicode/Encode/encode.sml new file mode 100644 index 0000000..7cc5ef5 --- /dev/null +++ b/fxp/src/Unicode/Encode/encode.sml @@ -0,0 +1,86 @@ + + + + + + + + + + +signature Encode = + sig + include EncodeError + + type File + type EncFile + + val encNoFile : EncFile + val encStdOut : EncFile + val encOpenFile : string * Encoding.Encoding * string -> EncFile + val encCloseFile : EncFile -> unit + val encAdapt : EncFile * File -> EncFile + + val encPutChar : EncFile * UniChar.Char -> EncFile + val encValidChar : EncFile * UniChar.Char -> bool + end + +structure Encode : Encode = + struct + open + Encoding UtilError + EncodeBasic EncodeError EncodeMisc + + type EncFile = Encoding * File + + val encNoFile = (NOENC,stdOutFile) + val encStdOut = (LATIN1,stdOutFile) + + fun encAdapt((enc,_),f) = (enc,f) + + fun encValidChar((enc,_),c) = + case enc + of ASCII => validCharAscii c + | EBCDIC => validCharEbcdic c + | LATIN1 => validCharLatin1 c + | _ => true + + fun encPutChar((enc,f),c) = + let val f1 = + case enc + of NOENC => f + | ASCII => (writeCharAscii(c,f)) + | EBCDIC => (writeCharEbcdic(c,f)) + | LATIN1 => (writeCharLatin1(c,f)) + | UCS2B => (writeCharUcs2B(c,f)) + | UCS2L => (writeCharUcs2L(c,f)) + | UCS4B => (writeCharUcs4B(c,f)) + | UCS4L => (writeCharUcs4L(c,f)) + | UCS4SB => (writeCharUcs4SB(c,f)) + | UCS4SL => (writeCharUcs4SL(c,f)) + | UTF8 => (writeCharUtf8(c,f)) + | UTF16B => (writeCharUtf16B(c,f)) + | UTF16L => (writeCharUtf16L(c,f)) + in (enc,f1) + end + + fun encCloseFile(_,f) = closeFile f + + fun encOpenFile (fname,enc,name) = + let + val outEnc = + case enc + of NOENC => + (case isEncoding name + of NOENC => raise NoSuchFile(fname,"Unsupported encoding \""^name^"\"") + | enc => enc) + | enc => enc + val f = openFile fname + val f1 = case outEnc + of UTF16B => writeByte(writeByte(f,0wxFE),0wxFF) + | UTF16L => writeByte(writeByte(f,0wxFF),0wxFE) + | _ => f + in (outEnc,f1) + end + end + diff --git a/fxp/src/Unicode/Encode/encodeBasic.sml b/fxp/src/Unicode/Encode/encodeBasic.sml new file mode 100644 index 0000000..6cae3be --- /dev/null +++ b/fxp/src/Unicode/Encode/encodeBasic.sml @@ -0,0 +1,48 @@ + + + + + + +(*--------------------------------------------------------------------------*) +(* Structure: EncodeBasic *) +(* *) +(* Exceptions raised by functions in this structure: *) +(* closeFile : none *) +(* fileName : none *) +(* openFile : NoSuchFile *) +(* writeByte : Io *) +(*--------------------------------------------------------------------------*) +signature EncodeBasic = + sig + type File + + val stdOutFile : File + val closeFile : File -> unit + val fileName : File -> string + val openFile : string -> File + val writeByte : File * Word8.word -> File + end + +structure EncodeBasic : EncodeBasic = + struct + open UtilError + + type outstream = TextIO.outstream + val closeOut = TextIO.closeOut + val openOut = TextIO.openOut + val output1 = TextIO.output1 + val stdOut = TextIO.stdOut + + type File = string * outstream + + val stdOutFile = ("-",stdOut) + + fun closeFile(fname,s) = if fname="-" then () else closeOut s + fun fileName(fname,_) = if fname="-" then "" else fname + fun openFile fname = + if fname = "-" then (fname,stdOut) + else (fname,openOut fname) + handle IO.Io {name,cause,...} => raise NoSuchFile(name,exnMessage cause) + fun writeByte (f as (_,s),b) = f before output1(s,chr(Word8.toInt b)) + end diff --git a/fxp/src/Unicode/Encode/encodeError.sml b/fxp/src/Unicode/Encode/encodeError.sml new file mode 100644 index 0000000..1f33ce0 --- /dev/null +++ b/fxp/src/Unicode/Encode/encodeError.sml @@ -0,0 +1,32 @@ + + + + + + + +signature EncodeError = + sig + datatype EncodeError = + ERR_ILLEGAL_CHAR of UniChar.Char * string + + val encodeMessage : EncodeError -> string list + + exception EncodeError of EncodeBasic.File * EncodeError + end + +structure EncodeError : EncodeError = + struct + open + UtilString + UniChar + + datatype EncodeError = + ERR_ILLEGAL_CHAR of UniChar.Char * string + + fun encodeMessage err = + case err + of ERR_ILLEGAL_CHAR(c,what) => [Char2Uni c,"is not",prependAnA what,"character"] + + exception EncodeError of EncodeBasic.File * EncodeError + end diff --git a/fxp/src/Unicode/Encode/encodeMisc.sml b/fxp/src/Unicode/Encode/encodeMisc.sml new file mode 100644 index 0000000..b1a10e6 --- /dev/null +++ b/fxp/src/Unicode/Encode/encodeMisc.sml @@ -0,0 +1,205 @@ +(* +require "basis.__word"; +require "basis.__word8"; +require "basis.__word8_vector"; + +require "chars"; +require "encodeBasic"; +require "encodeError"; +*) +signature EncodeMisc = + sig + val writeCharAscii : UniChar.Char * EncodeBasic.File -> EncodeBasic.File + val writeCharEbcdic : UniChar.Char * EncodeBasic.File -> EncodeBasic.File + val writeCharLatin1 : UniChar.Char * EncodeBasic.File -> EncodeBasic.File + val writeCharUcs4B : UniChar.Char * EncodeBasic.File -> EncodeBasic.File + val writeCharUcs4L : UniChar.Char * EncodeBasic.File -> EncodeBasic.File + val writeCharUcs4SB : UniChar.Char * EncodeBasic.File -> EncodeBasic.File + val writeCharUcs4SL : UniChar.Char * EncodeBasic.File -> EncodeBasic.File + val writeCharUtf8 : UniChar.Char * EncodeBasic.File -> EncodeBasic.File + val writeCharUtf16B : UniChar.Char * EncodeBasic.File -> EncodeBasic.File + val writeCharUtf16L : UniChar.Char * EncodeBasic.File -> EncodeBasic.File + val writeCharUcs2B : UniChar.Char * EncodeBasic.File -> EncodeBasic.File + val writeCharUcs2L : UniChar.Char * EncodeBasic.File -> EncodeBasic.File + + val validCharAscii : UniChar.Char -> bool + val validCharEbcdic : UniChar.Char -> bool + val validCharLatin1 : UniChar.Char -> bool + end + +structure EncodeMisc : EncodeMisc = + struct + open UniChar EncodeBasic EncodeError + + infix 8 >> + infix 7 && + infix 6 || + + val op && = Chars.andb + val op >> = Chars.>> + val op || = Word8.orb + + fun splitSurrogates (c : Char) = + (((c-0wx10000) >> 0w10)+0wxD800,c && 0wx3FF + 0wxDC00) + + fun Char2Byte c = Word8.fromLargeWord(Chars.toLargeWord c) + + (*---------------------------------------------------------------------*) + (* Ascii *) + (*---------------------------------------------------------------------*) + fun validCharAscii (c : Char) = c<0wx80 + fun writeCharAscii(c,f) = + if c<0wx80 then writeByte(f,Char2Byte c) + else raise EncodeError(f,ERR_ILLEGAL_CHAR(c,"ASCII")) + + (*---------------------------------------------------------------------*) + (* Ebcdic *) + (*---------------------------------------------------------------------*) + val latin2ebcdicTab = Word8Vector.fromList + [0wx00,0wx01,0wx02,0wx03,0wx37,0wx2D,0wx2E,0wx2F, + 0wx16,0wx05,0wx25,0wx0B,0wx0C,0wx0D,0wx0E,0wx0F, + 0wx10,0wx11,0wx12,0wx13,0wx3C,0wx3D,0wx32,0wx26, + 0wx18,0wx19,0wx3F,0wx27,0wx1C,0wx1D,0wx1E,0wx1F, + 0wx40,0wx4F,0wx7F,0wx7B,0wx5B,0wx6C,0wx50,0wx7D, + 0wx4D,0wx5D,0wx5C,0wx4E,0wx6B,0wx60,0wx4B,0wx61, + 0wxF0,0wxF1,0wxF2,0wxF3,0wxF4,0wxF5,0wxF6,0wxF7, + 0wxF8,0wxF9,0wx7A,0wx5E,0wx4C,0wx7E,0wx6E,0wx6F, + 0wx7C,0wxC1,0wxC2,0wxC3,0wxC4,0wxC5,0wxC6,0wxC7, + 0wxC8,0wxC9,0wxD1,0wxD2,0wxD3,0wxD4,0wxD5,0wxD6, + 0wxD7,0wxD8,0wxD9,0wxE2,0wxE3,0wxE4,0wxE5,0wxE6, + 0wxE7,0wxE8,0wxE9,0wx4A,0wxE0,0wx5A,0wx5F,0wx6D, + 0wx79,0wx81,0wx82,0wx83,0wx84,0wx85,0wx86,0wx87, + 0wx88,0wx89,0wx91,0wx92,0wx93,0wx94,0wx95,0wx96, + 0wx97,0wx98,0wx99,0wxA2,0wxA3,0wxA4,0wxA5,0wxA6, + 0wxA7,0wxA8,0wxA9,0wxC0,0wx6A,0wxD0,0wxA1,0wx07, + 0wx20,0wx21,0wx22,0wx23,0wx24,0wx15,0wx06,0wx17, + 0wx28,0wx29,0wx2A,0wx2B,0wx2C,0wx09,0wx0A,0wx1B, + 0wx30,0wx31,0wx1A,0wx33,0wx34,0wx35,0wx36,0wx08, + 0wx38,0wx39,0wx3A,0wx3B,0wx04,0wx14,0wx3E,0wxE1, + 0wx41,0wx42,0wx43,0wx44,0wx45,0wx46,0wx47,0wx48, + 0wx49,0wx51,0wx52,0wx53,0wx54,0wx55,0wx56,0wx57, + 0wx58,0wx59,0wx62,0wx63,0wx64,0wx65,0wx66,0wx67, + 0wx68,0wx69,0wx70,0wx71,0wx72,0wx73,0wx74,0wx75, + 0wx76,0wx77,0wx78,0wx80,0wx8A,0wx8B,0wx8C,0wx8D, + 0wx8E,0wx8F,0wx90,0wx9A,0wx9B,0wx9C,0wx9D,0wx9E, + 0wx9F,0wxA0,0wxAA,0wxAB,0wxAC,0wxAD,0wxAE,0wxAF, + 0wxB0,0wxB1,0wxB2,0wxB3,0wxB4,0wxB5,0wxB6,0wxB7, + 0wxB8,0wxB9,0wxBA,0wxBB,0wxBC,0wxBD,0wxBE,0wxBF, + 0wxCA,0wxCB,0wxCC,0wxCD,0wxCE,0wxCF,0wxDA,0wxDB, + 0wxDC,0wxDD,0wxDE,0wxDF,0wxEA,0wxEB,0wxEC,0wxED, + 0wxEE,0wxEF,0wxFA,0wxFB,0wxFC,0wxFD,0wxFE,0wxFF + ] + fun validCharEbcdic (c : Char) = c<0wx100 + fun writeCharEbcdic(c,f) = + if c<0wx100 then writeByte(f,Word8Vector.sub(latin2ebcdicTab,Chars.toInt c)) + else raise EncodeError(f,ERR_ILLEGAL_CHAR(c,"EBCDIC")) + + (*---------------------------------------------------------------------*) + (* Latin1 *) + (*---------------------------------------------------------------------*) + fun validCharLatin1 (c : Char) = c<0wx100 + fun writeCharLatin1(c,f) = + if c<0wx100 then writeByte(f,Char2Byte c) + else raise EncodeError(f,ERR_ILLEGAL_CHAR(c,"LATIN-1")) + + (*---------------------------------------------------------------------*) + (* UCS-4 *) + (*---------------------------------------------------------------------*) + fun ucs4Bytes c = (Char2Byte(c >> 0w24), + Char2Byte(c >> 0w16), + Char2Byte(c >> 0w8), + Char2Byte c) + fun writeCharUcs4 perm = + fn (c,f) => let val bytes = ucs4Bytes c + val (b1,b2,b3,b4) = perm bytes + val f1 = writeByte(f,b1) + val f2 = writeByte(f1,b2) + val f3 = writeByte(f2,b3) + val f4 = writeByte(f3,b4) + in f4 + end + fun permUcs4B x = x + fun permUcs4L (b1,b2,b3,b4) = (b4,b3,b2,b1) + fun permUcs4SB (b1,b2,b3,b4) = (b2,b1,b4,b3) + fun permUcs4SL (b1,b2,b3,b4) = (b3,b4,b1,b2) + + val writeCharUcs4B = writeCharUcs4 permUcs4B + val writeCharUcs4L = writeCharUcs4 permUcs4L + val writeCharUcs4SB = writeCharUcs4 permUcs4SB + val writeCharUcs4SL = writeCharUcs4 permUcs4SL + + (*---------------------------------------------------------------------*) + (* UTF-8 *) + (*---------------------------------------------------------------------*) + fun writeCharUtf8(c,f) = + if c<0wx80 then writeByte(f,Char2Byte c) + else if c<0wx800 + then let val f1 = writeByte(f,0wxC0 || Char2Byte(c >> 0w6)) + val f2 = writeByte(f1,0wx80 || Char2Byte(c && 0wx3F)) + in f2 + end + else if c<0wx10000 + then let val f1 = writeByte(f, 0wxE0 || Char2Byte(c >> 0w12)) + val f2 = writeByte(f1,0wx80 || Char2Byte((c >> 0w6) && 0wx3F)) + val f3 = writeByte(f2,0wx80 || Char2Byte(c && 0wx3F)) + in f3 + end + else if c<0wx200000 + then let val f1 = writeByte(f, 0wxF0 || Char2Byte(c >> 0w18)) + val f2 = writeByte(f1,0wx80 || Char2Byte((c >> 0w12) && 0wx3F)) + val f3 = writeByte(f2,0wx80 || Char2Byte((c >> 0w6) && 0wx3F)) + val f4 = writeByte(f3,0wx80 || Char2Byte(c && 0wx3F)) + in f4 + end + else if c<0wx4000000 + then let val f1 = writeByte(f, 0wxF8 || Char2Byte(c >> 0w24)) + val f2 = writeByte(f1,0wx80 || Char2Byte((c >> 0w18) && 0wx3F)) + val f3 = writeByte(f2,0wx80 || Char2Byte((c >> 0w12) && 0wx3F)) + val f4 = writeByte(f3,0wx80 || Char2Byte((c >> 0w6) && 0wx3F)) + val f5 = writeByte(f4,0wx80 || Char2Byte(c && 0wx3F)) + in f5 + end + else let val f1 = writeByte(f, 0wxFC || Char2Byte(c >> 0w30)) + val f2 = writeByte(f1,0wx80 || Char2Byte((c >> 0w24) && 0wx3F)) + val f3 = writeByte(f2,0wx80 || Char2Byte((c >> 0w18) && 0wx3F)) + val f4 = writeByte(f3,0wx80 || Char2Byte((c >> 0w12) && 0wx3F)) + val f5 = writeByte(f4,0wx80 || Char2Byte((c >> 0w6) && 0wx3F)) + val f6 = writeByte(f5,0wx80 || Char2Byte(c && 0wx3F)) + in f6 + end + + (*---------------------------------------------------------------------*) + (* UTF-16 *) + (*---------------------------------------------------------------------*) + fun oneUtf16 isL (c,f) = + let val (b1,b2) = (Char2Byte(c >> 0w8),Char2Byte c) + in if isL then writeByte(writeByte(f,b2),b1) + else writeByte(writeByte(f,b1),b2) + end + fun writeCharUtf16 isL = + fn (c,f) => + if c<0wx10000 then oneUtf16 isL (c,f) + else let val (hi,lo) = splitSurrogates c + val f1 = oneUtf16 isL (hi,f) + val f2 = oneUtf16 isL (lo,f1) + in f2 + end + val writeCharUtf16B = writeCharUtf16 false + val writeCharUtf16L = writeCharUtf16 true + + (*---------------------------------------------------------------------*) + (* UCS-2 *) + (*---------------------------------------------------------------------*) + fun writeCharUcs2 isL = + fn (c,f) => + if c<0wx10000 + then let val (b1,b2) = (Char2Byte(c >> 0w8),Char2Byte c) + in if isL then writeByte(writeByte(f,b2),b1) + else writeByte(writeByte(f,b1),b2) + end + else raise EncodeError(f,ERR_ILLEGAL_CHAR(c,"UCS-2")) + + val writeCharUcs2B = writeCharUcs2 false + val writeCharUcs2L = writeCharUcs2 true + + end diff --git a/fxp/src/Unicode/Uri/uri.sml b/fxp/src/Unicode/Uri/uri.sml new file mode 100644 index 0000000..ca62d57 --- /dev/null +++ b/fxp/src/Unicode/Uri/uri.sml @@ -0,0 +1,197 @@ +(* +require "basis.__array"; +require "basis.__byte"; +require "basis.__string"; +require "basis.__vector"; +require "basis.__word"; +require "basis.__word8"; + +require "util.unsafe"; +require "util.utilInt"; + +require "chars"; +require "naming"; +*) +signature Uri = + sig + eqtype Uri + + val emptyUri : Uri + + val hashUri : Uri -> word + val compareUri : Uri * Uri -> order + + val uriJoin : Uri * Uri -> Uri + val uriSuffix : Uri -> string + + val Data2Uri : UniChar.Data -> Uri + val Vector2Uri : UniChar.Vector -> Uri + val String2Uri : string -> Uri + val Uri2String : Uri -> string + + val retrieveUri : Uri -> string * string * bool + end + +structure Uri :> Uri = + struct + open UniChar UniClasses UriDecode UriEncode UtilError UtilInt + + (*--------------------------------------------------------------------*) + (* decoding *) + (*--------------------------------------------------------------------*) + type Uri = string + + val emptyUri = "" + + val Vector2Uri = Vector2UriUtf8 + val Data2Uri = Data2UriUtf8 + val String2Uri = String2UriUtf8 + val Uri2String = decodeUriUtf8 + + val slash = "/" + + fun uriSuffix s = + let fun search i = if i<0 then NONE else case String.sub(s,i) + of #"." => SOME i + | #"/" => NONE + | _ => search (i-1) + in case search (String.size s-1) + of NONE => "" + | SOME i => String.extract(s,i+1,NONE) + end + + fun isScheme c = + Char.isAlphaNum c orelse #"+"=c orelse #"-"=c orelse #"."=c + + fun uriAbsolute uri = + let fun search i = + if i>=String.size uri then false + else let val c=String.sub(uri,i) + in if #":"=c then true else if isScheme c then search (i+1) + else false + end + in + if uri="" then false + else if Char.isAlpha (String.sub(uri,0)) then search 1 + else false + end + fun uriRelative uri = not (uriAbsolute uri) + + fun uriLocal uri = + if String.isPrefix "file:" uri + then SOME(String.extract(uri,5,NONE)) + else if uriRelative uri then SOME uri + else NONE + + fun uriPath s = + let + fun search (i,hadSlash) = + if i<0 then if hadSlash then SOME 0 else NONE + else case String.sub(s,i) + of #"/" => if hadSlash then NONE else search(i-1,true) + | _ => if hadSlash then SOME(i+1) else search(i-1,false) + val len = String.size s + val posOpt = search(len-1,false) + in case posOpt + of NONE => emptyUri + | SOME i => if i=0 then slash + else String.extract(s,0,SOME(i+1)) + end + + fun uriAuth uri = + let + fun searchScheme i = + if i>=String.size uri then NONE + else let val c=String.sub(uri,i) + in if #":"=c then SOME i else if isScheme c then searchScheme (i+1) + else NONE + end + fun searchSlash i = + if i>=String.size uri then NONE + else let val c=String.sub(uri,i) + in if #"/"=c then SOME i else searchSlash (i+1) + end + in + if uri="" then "" + else if not (Char.isAlpha(String.sub(uri,0))) then "" + else case searchScheme 1 + of NONE => "" + | SOME i => + if String.size uri<=i+2 then String.extract(uri,0,SOME(i+1)) + else if #"/"=String.sub(uri,i+1) andalso #"/"=String.sub(uri,i+2) + then case searchSlash (i+3) + of NONE => uri + | SOME j => String.extract(uri,0,SOME j) + else String.extract(uri,0,SOME(i+1)) + end + + fun uriScheme uri = + let + fun searchScheme i = + if i>=String.size uri then NONE + else let val c=String.sub(uri,i) + in if #":"=c then SOME i else if isScheme c then searchScheme (i+1) + else NONE + end + in + if uri="" then "" + else if not (Char.isAlpha(String.sub(uri,0))) then "" + else case searchScheme 1 + of NONE => "" + | SOME i => String.extract(uri,0,SOME(i+1)) + end + + fun uriJoin(abs,rel) = + if rel="" then uriPath abs + else if abs="" then rel + else if String.isPrefix "//" rel then uriScheme abs^rel + else if #"/"=String.sub(rel,0) then uriAuth abs^rel + else if uriAbsolute rel then rel + else uriPath abs^rel + + val compareUri = String.compare + val hashUri = UtilHash.hashString + + fun convertCommand str (src,dst) = + let + val s = Substring.full str + fun doit ss s = + if Substring.isEmpty s then ss + else let val (sl,sr) = Substring.splitr (fn c => #"%"<>c) s + in if Substring.isEmpty sl then sr::ss + else let val sl' = Substring.trimr 1 sl + in case Substring.first sr + of SOME #"1" => let val sr' = Substring.triml 1 sr + in doit (Substring.full src::sr'::ss) sl' + end + | SOME #"2" => let val sr' = Substring.triml 1 sr + in doit (Substring.full dst::sr'::ss) sl' + end + | _ => doit (Substring.full "%"::sr::ss) sl' + end + end + val ss = doit nil s + val s = Substring.concat ss + in s + end + + fun retrieveRemote uri = + let + val tmp = OS.FileSys.tmpName() + val cmd = convertCommand Config.retrieveCommand (uri,tmp) + val status = OS.Process.system cmd + val _ = if OS.Process.isSuccess status then () + else let val _ = (OS.FileSys.remove tmp + handle OS.SysErr _ => ()) + val cmd = convertCommand + Config.retrieveCommand ("",tmp) + in raise NoSuchFile (uri,"command '"^cmd^"' failed") + end + in (Uri2String uri,tmp,true) + end + + fun retrieveUri uri = + case uriLocal uri + of SOME f => (Uri2String uri,Uri2String f,false) + | NONE => retrieveRemote uri + end diff --git a/fxp/src/Unicode/Uri/uriDecode.sml b/fxp/src/Unicode/Uri/uriDecode.sml new file mode 100644 index 0000000..4831e4d --- /dev/null +++ b/fxp/src/Unicode/Uri/uriDecode.sml @@ -0,0 +1,135 @@ +signature UriDecode = + sig + val decodeUriLatin : string -> string + val decodeUriUtf8 : string -> string + end + +structure UriDecode : UriDecode = + struct + open UniChar UtilInt + + infix 8 << <<< + infix 7 && + infix 6 || ||| + + val op && = Word8.andb + val op << = Word8.<< + val op <<< = Chars.<< + val op || = Word8.orb + val op ||| = Chars.orb + + val Byte2Char = Chars.fromLargeWord o Word8.toLargeWord + + fun hexValue c = + if #"0"<=c andalso #"9">=c then SOME (Byte.charToByte c-0wx30) + else if #"A"<=c andalso #"F">=c then SOME (Byte.charToByte c-0wx37) + else if #"a"<=c andalso #"f">=c then SOME (Byte.charToByte c-0wx57) + else NONE + + exception Failed of char list + + fun getQuads cs = + case cs + of c1::c2::cs1 => (case (hexValue c1,hexValue c2) + of (SOME b1,SOME b2) => ((b1 << 0w4 || b2),cs1) + | _ => raise Failed cs1) + | _ => raise Failed nil + + (*--------------------------------------------------------------------*) + (* decode UTF-8 *) + (*--------------------------------------------------------------------*) + val byte1switch = Array.array(256,1) (* 1 byte *) + val _ = appInterval (fn i => Array.update(byte1switch,i,0)) (0x80,0xBF) (* Error *) + val _ = appInterval (fn i => Array.update(byte1switch,i,2)) (0xC0,0xDF) (* 2 bytes *) + val _ = appInterval (fn i => Array.update(byte1switch,i,3)) (0xE0,0xEF) (* 3 bytes *) + val _ = appInterval (fn i => Array.update(byte1switch,i,4)) (0xF0,0xF7) (* 4 bytes *) + val _ = appInterval (fn i => Array.update(byte1switch,i,5)) (0xF8,0xFB) (* 5 bytes *) + val _ = appInterval (fn i => Array.update(byte1switch,i,6)) (0xFC,0xFD) (* 6 bytes *) + + val diff2 = 0wx00003080 + val diff3 = diff2 <<< 0wx6 ||| 0wx00020080 + val diff4 = diff3 <<< 0wx6 ||| 0wx00400080 + val diff5 = diff4 <<< 0wx6 ||| 0wx08000080 + val diff6 = diff5 <<< 0wx6 ||| 0wx00000080 + val diffsByLen = Vector.fromList [0w0,0w0,diff2,diff3,diff4,diff5,diff6] + + fun getByte cs = + case cs + of #"%"::cs1 => getQuads cs1 + | c::cs1 => (Byte.charToByte c,cs1) + | nil => raise Failed nil + + fun getBytes(b,cs,n) = + let + fun do_err (cs,m) = + if n do_err(cs,m+1) + val w1 = if b && 0wxC0 = 0wx80 then w <<< 0w6 + Byte2Char b + else do_err(cs1,m+1) + in doit (w1,cs1,m+1) + end + val (w,cs1) = doit (Byte2Char b,cs,2) + val diff = Vector.sub(diffsByLen,n) + val c = w-diff + in + if c<0wx100 then (Char2char c,cs1) + else raise Failed cs1 + end + + fun getCharUtf8 cs = + let val (b,cs1) = getQuads cs + in case Array.sub(byte1switch,Word8.toInt b) + of 0 (* error *) => raise Failed cs1 + | 1 (* 1 byte *) => (Byte.byteToChar b,cs1) + | n (* n bytes *) => getBytes(b,cs1,n) + end + + fun decodeUriUtf8 str = + let + val cs = String.explode str + + fun doit yet nil = yet + | doit yet (c::cs) = + if #"%"<>c then doit (c::yet) cs + else let val (yet1,cs1) = let val (ch,cs1) = getCharUtf8 cs + in (ch::yet,cs1) + end + handle Failed cs => (yet,cs) + in doit yet1 cs1 + end + in + String.implode(rev(doit nil cs)) + end + + (*--------------------------------------------------------------------*) + (* decode Latin *) + (*--------------------------------------------------------------------*) + fun getChar cs = + case cs + of #"%"::cs1 => let val (b,cs2) = getQuads cs1 + in (Byte.byteToChar b,cs2) + end + | c::cs1 => (c,cs1) + | nil => raise Failed nil + + fun decodeUriLatin str = + let + val cs = String.explode str + + fun doit yet nil = yet + | doit yet (c::cs) = + let val (yet1,cs1) = let val (ch,cs1) = getChar cs + in (ch::yet,cs1) + end + handle Failed cs => (yet,cs) + in doit yet1 cs1 + end + in + String.implode(rev(doit nil cs)) + end + end diff --git a/fxp/src/Unicode/Uri/uriDict.sml b/fxp/src/Unicode/Uri/uriDict.sml new file mode 100644 index 0000000..96baa7f --- /dev/null +++ b/fxp/src/Unicode/Uri/uriDict.sml @@ -0,0 +1,18 @@ + + + + + + + +structure KeyUri : Key = + struct + type Key = Uri.Uri + + val null = Uri.emptyUri + val compare = Uri.compareUri + val toString = Uri.Uri2String + val hash = Uri.hashUri + end + +structure UriDict = Dict (structure Key = KeyUri) diff --git a/fxp/src/Unicode/Uri/uriEncode.sml b/fxp/src/Unicode/Uri/uriEncode.sml new file mode 100644 index 0000000..bf5ba91 --- /dev/null +++ b/fxp/src/Unicode/Uri/uriEncode.sml @@ -0,0 +1,98 @@ +signature UriEncode = + sig + val Data2UriUtf8 : UniChar.Data -> string + val Data2UriLatin : UniChar.Data -> string + + val Vector2UriUtf8 : UniChar.Vector -> string + val Vector2UriLatin : UniChar.Vector -> string + + val String2UriUtf8 : string -> string + val String2UriLatin : string -> string + end + +structure UriEncode : UriEncode = + struct + + open UniChar UniClasses + + infix 8 >> >>> + infix 7 && &&& + infix 6 || + + val op && = Word8.andb + val op &&& = Chars.andb + val op >> = Word8.>> + val op >>> = Chars.>> + val op || = Word8.orb + + val Char2Byte = Word8.fromLargeWord o Chars.toLargeWord + + fun encodeCharUtf8 c = + if c<0wx80 then [Char2Byte c] + else if c<0wx800 + then [0wxC0 || Char2Byte(c >>> 0w6), + 0wx80 || Char2Byte(c &&& 0wx3F)] + else if c<0wx10000 + then [0wxE0 || Char2Byte(c >>> 0w12), + 0wx80 || Char2Byte((c >>> 0w6) &&& 0wx3F), + 0wx80 || Char2Byte(c &&& 0wx3F)] + else if c<0wx200000 + then [0wxF0 || Char2Byte(c >>> 0w18), + 0wx80 || Char2Byte((c >>> 0w12) &&& 0wx3F), + 0wx80 || Char2Byte((c >>> 0w6) &&& 0wx3F), + 0wx80 || Char2Byte(c &&& 0wx3F)] + else if c<0wx4000000 + then [0wxF8 || Char2Byte(c >>> 0w24), + 0wx80 || Char2Byte((c >>> 0w18) &&& 0wx3F), + 0wx80 || Char2Byte((c >>> 0w12) &&& 0wx3F), + 0wx80 || Char2Byte((c >>> 0w6) &&& 0wx3F), + 0wx80 || Char2Byte(c &&& 0wx3F)] + else [0wxFC || Char2Byte(c >>> 0w30), + 0wx80 || Char2Byte((c >>> 0w24) &&& 0wx3F), + 0wx80 || Char2Byte((c >>> 0w18) &&& 0wx3F), + 0wx80 || Char2Byte((c >>> 0w12) &&& 0wx3F), + 0wx80 || Char2Byte((c >>> 0w6) &&& 0wx3F), + 0wx80 || Char2Byte(c &&& 0wx3F)] + + fun Byte2Cc b = + let fun Quad2C b = if b<0wxA then Byte.byteToChar(b+0wx30) else Byte.byteToChar(b+0wx37) + in (Quad2C(b >> 0w4),Quad2C(b && 0wx0F)) + end + + fun precedesHex (i,cv) = + if Vector.length cv <= i+2 then false + else let val (c1,c2) = (Vector.sub(cv,i+1),Vector.sub(cv,i+2)) + in isHex c1 andalso isHex c2 + end + + fun Vector2UriUtf8 cv = + let val revd = Vector.foldli + (fn (i,c,s) => if c<0wx80 andalso (c<>0wx25 orelse precedesHex(i,cv)) + then Char2char c::s + else foldl (fn (b,s) => let val (c1,c2) = Byte2Cc b + in c2::c1:: #"%"::s + end) + s (encodeCharUtf8 c)) + nil cv + in String.implode (rev revd) + end + + fun Vector2UriLatin cv = + let val revd = Vector.foldli + (fn (i,c,s) => if c<0wx80 andalso (c<>0wx25 orelse precedesHex(i,cv)) + then Char2char c::s + else (if c>= 0w100 then s + else let val (c1,c2) = Byte2Cc (Char2Byte c) + in c2::c1:: #"%"::s + end)) + nil cv + in String.implode (rev revd) + end + + val Data2UriUtf8 = Vector2UriUtf8 o Data2Vector + val Data2UriLatin = Vector2UriLatin o Data2Vector + + val String2UriUtf8 = Vector2UriUtf8 o String2Vector + val String2UriLatin = Vector2UriLatin o String2Vector + end + diff --git a/fxp/src/Unicode/encoding.sml b/fxp/src/Unicode/encoding.sml new file mode 100644 index 0000000..b19f2c2 --- /dev/null +++ b/fxp/src/Unicode/encoding.sml @@ -0,0 +1,89 @@ + + +signature Encoding = + sig + datatype Encoding = + NOENC | ASCII | EBCDIC | LATIN1 + | UCS4B | UCS4L | UCS4SB | UCS4SL + | UCS2B | UCS2L | UTF16B | UTF16L + | UTF8 + + val UCS2 : Encoding + val UCS4 : Encoding + val UTF16 : Encoding + + val encodingName : Encoding -> string + val isEncoding : string -> Encoding + val switchEncoding : Encoding * Encoding -> Encoding + end + +structure Encoding : Encoding = + struct + open StringDict + + datatype Encoding = + NOENC | ASCII | EBCDIC | LATIN1 + | UCS4B | UCS4L | UCS4SB | UCS4SL + | UCS2B | UCS2L | UTF16B | UTF16L + | UTF8 + + val UCS2 = UCS2B + val UCS4 = UCS4B + val UTF16 = UTF16B + + fun encodingName enc = + case enc + of NOENC => "NONE" + | ASCII => "ASCII" + | EBCDIC => "EBCDIC" + | LATIN1 => "ISO-8859-1" + | UCS2B => "UCS-2" + | UCS2L => "UCS-2" + | UCS4B => "UCS-4" + | UCS4L => "UCS-4" + | UCS4SB => "UCS-4" + | UCS4SL => "UCS-4" + | UTF8 => "UTF-8" + | UTF16B => "UTF-16" + | UTF16L => "UTF-16" + + val encDict = makeDict("encoding",6,NOENC) + val encAliases = + [(ASCII,["ANSI_X3.4-1968","ANSI_X3.4-1986","ASCII","US-ASCII","US", + "ISO646-US","ISO-IR-6","ISO_646.IRV:1991","IBM367","CP367"]), + (EBCDIC,["EBCDIC"]), + (LATIN1,["ISO_8859-1:1987","ISO-8859-1","ISO_8859-1", + "ISO-IR-100","CP819","IBM819","L1","LATIN1"]), + (UCS2,["UCS-2","ISO-10646-UCS-2"]), + (UCS4,["UCS-4","ISO-10646-UCS-4"]), + (UTF16,["UTF-16"]), + (UTF8,["UTF-8"]) + ] + val _ = app (fn (x,ys) => app (fn y => setByKey(encDict,y,x)) ys) encAliases + fun isEncoding name = getByKey(encDict,name) + + fun compatAscii new = + case new + of ASCII => new + | LATIN1 => new + | UTF8 => new + | _ => NOENC + fun compatUcs4 (old,new) = + if new=UCS4 then old else NOENC + + fun switchEncoding(old,new) = + case old + of NOENC => NOENC + | ASCII => compatAscii new + | EBCDIC => if new=EBCDIC then new else NOENC + | LATIN1 => compatAscii new + | UCS4B => compatUcs4(old,new) + | UCS4L => compatUcs4(old,new) + | UCS4SB => compatUcs4(old,new) + | UCS4SL => compatUcs4(old,new) + | UTF16B => if new=UTF16 then old else if new=UCS2 then UCS2B else NOENC + | UTF16L => if new=UTF16 then old else if new=UCS2 then UCS2L else NOENC + | UCS2B => if new=UCS2 then old else if new=UTF16 then UTF16B else NOENC + | UCS2L => if new=UCS2 then old else if new=UTF16 then UTF16L else NOENC + | UTF8 => compatAscii new + end diff --git a/fxp/src/Util/SymDict/dict.sml b/fxp/src/Util/SymDict/dict.sml new file mode 100644 index 0000000..1dd1e6a --- /dev/null +++ b/fxp/src/Util/SymDict/dict.sml @@ -0,0 +1,323 @@ +(*--------------------------------------------------------------------------*) +(* Functor: Dict *) +(* *) +(* Depends on: *) +(* Chars *) +(* *) +(* Exceptions raised by functions in this functor: *) +(* addByIndex : NoSuchIndex *) +(* addByKey : InternalError *) +(* getByIndex : NoSuchIndex *) +(* getByKey : InternalError *) +(* getIndex : InternalError *) +(* getKey : NoSuchIndex *) +(* hasIndex : none *) +(* makeDict : none *) +(* nullDict : none *) +(* printDict : none *) +(* usedIndices : none *) +(*--------------------------------------------------------------------------*) +(* A dictionary maps keys to consecutive integers and additionally holds *) +(* a value of arbitrary type for each entry. *) +(*--------------------------------------------------------------------------*) +signature Dict = + sig + type Key + type 'a Dict + + exception NoSuchIndex + + val nullDict : string * 'a -> 'a Dict + val makeDict : string * int * 'a -> 'a Dict + val clearDict : 'a Dict * int option -> unit + + val hasIndex : 'a Dict * Key -> int option + val getIndex : 'a Dict * Key -> int + val getKey : 'a Dict * int -> Key + + val getByIndex : 'a Dict * int -> 'a + val getByKey : 'a Dict * Key -> 'a + + val setByIndex : 'a Dict * int * 'a -> unit + val setByKey : 'a Dict * Key * 'a -> unit + + val usedIndices : 'a Dict -> int + + val extractDict : 'a Dict -> (Key * 'a) array + val printDict : ('a -> string) -> 'a Dict -> unit + end + +functor Dict (structure Key : Key) : Dict = + struct + open UtilError UtilInt + + type Key = Key.Key + + exception NoSuchIndex + + (*--------------------------------------------------------------------*) + (* a dictionary can have at most size MAX_WIDTH. This is because *) + (* arrays may at most have Array.maxLen elements. We only use powers *) + (* of two as sizes, so we are really only interested in the position *) + (* of maxLen's highest bit. That would be the maximal width for hash *) + (* tables, and thus we must decrease it by one for obtaining the max *) + (* table width. *) + (*--------------------------------------------------------------------*) + fun highestBit w = if w=0w0 then 0 else 1+highestBit(Word.>>(w,0w1)) + val MAX_WIDTH = highestBit (Word.fromInt Array.maxLen)-1 + + type Bucket = (Key * int) list + val nullBucket = nil : Bucket + + (*--------------------------------------------------------------------*) + (* buckets are unsorted - they are probably small, so comparing the *) + (* keys might be overkill. *) + (*--------------------------------------------------------------------*) + fun addToBucket (ni as (key,_),bucket) = + let + fun doit nil = [ni] + | doit (nis as (ni' as (key',_))::rest) = + case Key.compare (key',key) + of LESS => ni'::doit rest + | EQUAL => ni::rest + | GREATER => ni::nis + in + doit bucket + end + fun searchBucket (key,bucket) = + let + fun doit nil = NONE + | doit ((key',i)::rest) = + case Key.compare (key',key) + of LESS => doit rest + | EQUAL => SOME i + | GREATER => NONE + in + doit bucket + end + + (*--------------------------------------------------------------------*) + (* a dictionary consists of *) + (* - a string desc saying what is stored in this dictionary *) + (* - an array tab holding for each index its key and value *) + (* - a hash table, i.e. Bucket array, of double size than tab *) + (* - a hashFun mapping Key to the range of the hash table *) + (* - an integer width for computing table sizes *) + (* - an integer size wich is the size of the value table *) + (* - an integer count holding the next free index *) + (* - a default value for the value table *) + (*--------------------------------------------------------------------*) + type 'a Dict = {desc : string, + tab : (Key * 'a) array ref, + hashTab : Bucket array ref, + hashFun : (Key -> int) ref, + width : int ref, (* bit width *) + size : int ref, (* tab size=2^width, hash size is double *) + count : int ref, (* number of entries *) + def : 'a (* default for values *) + } + fun nullDict (desc,def) = {desc = desc, + tab = ref (Array.array(1,(Key.null,def))), + hashTab = ref (Array.array(2,nullBucket)), + hashFun = ref (fn _ => 0), + count = ref 0, + size = ref 1, + width = ref 0, + def = def} + + (*--------------------------------------------------------------------*) + (* how many entries are in the dictionary? *) + (*--------------------------------------------------------------------*) + fun usedIndices ({count,...}:'a Dict) = !count + + (*--------------------------------------------------------------------*) + (* what is the table load, i.e. percentage of number of entries to *) + (* hash table size = 100*count/(2*size) = 50*count/size. *) + (*--------------------------------------------------------------------*) + fun hashRatio({count,size,...}:'a Dict) = 50 * !count div !size + handle Div => 100 + + (*--------------------------------------------------------------------*) + (* this is the hash function. Key.hash hashes data to arbitrary *) + (* words, that are mapped to the hash range by this function, where *) + (* mask is the bitmask corresponding to the size of the hash table: *) + (* 1. square the word produced by Key.hash *) + (* 2. take the width bits from the middle of the square, these are *) + (* the bit-places influenced by all input bit-places: *) + (* - shift to the right by half of the destination width *) + (* - mask out all bits to the left of destination *) + (* this is a simple strategy but experiences good results. *) + (*--------------------------------------------------------------------*) + fun square (x:word) = Word.*(x,x) + fun hashKey(half,mask) x = + Word.toInt(Word.andb(mask,Word.>>(square(Key.hash x),half))) + fun makeHashFun(size,width) = + let + val mask = 0w2*Word.fromInt size-0w1 + val half = Word.fromInt((width+1) div 2) + in + hashKey(half,mask) + end + + (*--------------------------------------------------------------------*) + (* create a new dictionary for 2^w, but at least 2 and at most 2^m *) + (* entries, where m is the value of MAX_WIDTH. *) + (*--------------------------------------------------------------------*) + fun makeDict (desc,w,def) = + let + val width= Int.min(Int.max(1,w),MAX_WIDTH) + val size = Word.toInt(Word.<<(0w1,Word.fromInt(width-1))) + in {desc = desc, + tab = ref (Array.array(size,(Key.null,def))), + hashTab = ref (Array.array(2*size,nullBucket)), + hashFun = ref (makeHashFun(size,width)), + width = ref width, + size = ref size, + count = ref 0, + def = def} + end + + (*--------------------------------------------------------------------*) + (* clear a dictionary. If the 2nd arg is SOME w, use w for resizing. *) + (*--------------------------------------------------------------------*) + fun clearDict (dict:'a Dict,widthOpt) = + case widthOpt + of NONE => + let + val {tab=ref tab,hashTab=ref hashTab,size,count,def,...} = dict + val _ = appInterval (fn i => Array.update(tab,i,(Key.null,def))) (0,!count-1) + val _ = appInterval (fn i => Array.update(hashTab,i,nullBucket)) (0,!size*2-1) + in + count := 0 + end + | SOME w => + let + val {tab,hashTab,hashFun,width,size,count,def,...} = dict + val newWidth = Int.min(Int.max(1,w),MAX_WIDTH) + val newSize = Word.toInt(Word.<<(0w1,Word.fromInt(newWidth-1))) + val _ = tab := (Array.array(newSize,(Key.null,def))) + val _ = hashTab := (Array.array(2*newSize,nullBucket)) + val _ = hashFun := (makeHashFun(newSize,newWidth)) + val _ = width := newWidth + val _ = size := newSize + in + count := 0 + end + + (*--------------------------------------------------------------------*) + (* grow a dictionary to the double size. raise InternalError if the *) + (* dictionary already has maximal size. *) + (*--------------------------------------------------------------------*) + fun growDictionary ({desc,tab,hashTab,hashFun,width,size,count,def}:'a Dict) = + let + val oldTab = !tab + val _ = if !width < MAX_WIDTH then width := !width+1 + else raise InternalError + ("Dict","growDictionary", + String.concat ["growing the ",desc," dictionary ", + "exceeded the system maximum size of ", + Int.toString Array.maxLen," for arrays"]) + val _ = size := !size*2 + val _ = tab := Array.array(!size,(Key.null,def)) + val _ = hashTab := Array.array(!size*2,nullBucket) + val _ = hashFun := makeHashFun(!size,!width) + + fun addTo (i,kv as (key,_)) = + let + val idx = !hashFun key + val _ = Array.update(!hashTab,idx,addToBucket((key,i),Array.sub(!hashTab,idx))) + val _ = Array.update(!tab,i,kv) + in () + end + in + Array.appi addTo oldTab + end + + (*--------------------------------------------------------------------*) + (* lookup the key for an index of the dictionary. *) + (*--------------------------------------------------------------------*) + fun getKey({tab,count,...}:'a Dict,idx) = + if !count>idx then #1(Array.sub(!tab,idx)) + else raise NoSuchIndex + + (*--------------------------------------------------------------------*) + (* map a Key to its index in the dictionary. if it is not in the *) + (* dictionary yet, add a new entry with a new index. grow the table *) + (* if there is no more free index in the dictionary. *) + (*--------------------------------------------------------------------*) + fun getIndex(dict as {tab,hashTab,hashFun,size,count,def,...}:'a Dict,key) = + let + val k = !hashFun key + val bucket = Array.sub(!hashTab,k) + in + case searchBucket(key,bucket) + of SOME idx => idx + | NONE => let val idx = !count + val (k',buck') = if !size>idx then (k,bucket) + else let val _ = growDictionary dict + val k' = !hashFun key + val buck' = Array.sub(!hashTab,k') + in (k',buck') + end + val _ = Array.update(!hashTab,k',addToBucket((key,idx),buck')) + val _ = Array.update(!tab,idx,(key,def)) + val _ = count := idx+1 + in idx + end + end + + (*--------------------------------------------------------------------*) + (* does a Key have an entry in a dictionary? *) + (*--------------------------------------------------------------------*) + fun hasIndex({hashTab,hashFun,...}:'a Dict,key) = + let + val idx = !hashFun key + val bucket = Array.sub(!hashTab,idx) + in + searchBucket(key,bucket) + end + + (*--------------------------------------------------------------------*) + (* get the value stored for index idx *) + (*--------------------------------------------------------------------*) + fun getByIndex({tab,count,...}:'a Dict,idx) = + if !count>idx then #2(Array.sub(!tab,idx)) + else raise NoSuchIndex + + (*--------------------------------------------------------------------*) + (* get the value stored for a key *) + (*--------------------------------------------------------------------*) + fun getByKey(dict,key) = + getByIndex(dict,getIndex(dict,key)) + + (*--------------------------------------------------------------------*) + (* enter a value for index idx. *) + (*--------------------------------------------------------------------*) + fun setByIndex({tab,count,...}:'a Dict,idx,a) = + if !count>idx then let val (key,_) = Array.sub(!tab,idx) + in Array.update(!tab,idx,(key,a)) + end + else raise NoSuchIndex + + (*--------------------------------------------------------------------*) + (* enter a value for a key. *) + (*--------------------------------------------------------------------*) + fun setByKey(dict,key,v) = + setByIndex(dict,getIndex(dict,key),v) + + (*--------------------------------------------------------------------*) + (* extract the contents of the dictionary to an array. *) + (*--------------------------------------------------------------------*) + fun extractDict({count,tab,...}:'a Dict) = + Array.tabulate(!count,fn i => Array.sub(!tab,i)) + + (*--------------------------------------------------------------------*) + (* print the contents of the dictionary. *) + (*--------------------------------------------------------------------*) + fun printDict X2String ({desc,tab,count,...}:'a Dict) = + (print (desc^" dictionary:\n"); + ArraySlice.appi + (fn (n,(key,value)) => + print (" "^Int.toString n^": "^Key.toString key^" = "^X2String value^"\n")) + (ArraySlice.slice(!tab,0,SOME (!count)))) + end diff --git a/fxp/src/Util/SymDict/intDict.sml b/fxp/src/Util/SymDict/intDict.sml new file mode 100644 index 0000000..a74a4f8 --- /dev/null +++ b/fxp/src/Util/SymDict/intDict.sml @@ -0,0 +1,21 @@ + + + + + + + +structure KeyInt : Key = + struct + type Key = int + + val null = 0 + val hash = Word.fromInt + val compare = Int.compare + val toString = Int.toString + end + +structure IntDict = Dict (structure Key = KeyInt) +structure IntSymTab = SymTable (structure Key = KeyInt) + + diff --git a/fxp/src/Util/SymDict/intListDict.sml b/fxp/src/Util/SymDict/intListDict.sml new file mode 100644 index 0000000..6c354ee --- /dev/null +++ b/fxp/src/Util/SymDict/intListDict.sml @@ -0,0 +1,20 @@ + + + + + + +structure KeyIntList : Key = + struct + type Key = int list + + val null = nil + val hash = UtilHash.hashList Word.fromInt + val compare = UtilCompare.compareList Int.compare + val toString = UtilString.List2String Int.toString + end + +structure IntListDict = Dict (structure Key = KeyIntList) +structure IntListSymTab = SymTable (structure Key = KeyIntList) + + diff --git a/fxp/src/Util/SymDict/intSetDict.sml b/fxp/src/Util/SymDict/intSetDict.sml new file mode 100644 index 0000000..aa7264a --- /dev/null +++ b/fxp/src/Util/SymDict/intSetDict.sml @@ -0,0 +1,23 @@ + + + + + + + +structure KeyIntSet : Key = + struct + open IntSets UtilString + + type Key = IntSet + + val null = emptyIntSet + val hash = hashIntSet + val compare = compareIntSets + val toString = (List2xString ("{",",","}") Int2String) o IntSet2List + end + +structure IntSetDict = Dict (structure Key = KeyIntSet) +structure IntSetSymTab = SymTable (structure Key = KeyIntSet) + + diff --git a/fxp/src/Util/SymDict/key.sml b/fxp/src/Util/SymDict/key.sml new file mode 100644 index 0000000..9f86ca8 --- /dev/null +++ b/fxp/src/Util/SymDict/key.sml @@ -0,0 +1,16 @@ + + + +(*--------------------------------------------------------------------------*) +(* In order to be used as a dictinary/symbol table key, a type must have a *) +(* null value, hash to words, must be comparable and printable. *) +(*--------------------------------------------------------------------------*) +signature Key = + sig + type Key + + val null : Key + val hash : Key -> word + val compare : Key * Key -> order + val toString : Key -> string + end diff --git a/fxp/src/Util/SymDict/stringDict.sml b/fxp/src/Util/SymDict/stringDict.sml new file mode 100644 index 0000000..afc8975 --- /dev/null +++ b/fxp/src/Util/SymDict/stringDict.sml @@ -0,0 +1,20 @@ + + + + + + + + +structure KeyString : Key = + struct + type Key = string + + val null = "" + val hash = UtilHash.hashString + val compare = String.compare + + fun toString str = str + end + +structure StringDict = Dict (structure Key = KeyString) diff --git a/fxp/src/Util/SymDict/symbolTable.sml b/fxp/src/Util/SymDict/symbolTable.sml new file mode 100644 index 0000000..5d03e45 --- /dev/null +++ b/fxp/src/Util/SymDict/symbolTable.sml @@ -0,0 +1,314 @@ + + + + + + +(*--------------------------------------------------------------------------*) +(* Functor: SymbolTable *) +(* *) +(* Exceptions raised by functions in this structure: *) +(* getSymIndex : Key.InternalError *) +(* getSymKey : NoSuchSymbol *) +(* hasSymIndex : none *) +(* makeSymTable : none *) +(* nullSymTable : none *) +(* printSymTable : none *) +(* usedSymbols : none *) +(*--------------------------------------------------------------------------*) +(* A symbol table maps Keys to consecutive integers. *) +(*--------------------------------------------------------------------------*) +signature SymTable = + sig + type Key + type SymTable + + exception NoSuchSymbol + + val nullSymTable : string -> SymTable + val makeSymTable : string * int -> SymTable + val clearSymTable : SymTable * int option -> unit + + val hasSymIndex : SymTable * Key -> int option + val getSymIndex : SymTable * Key -> int + val getSymKey : SymTable * int -> Key + val usedSymbols : SymTable -> int + + val assignSymIndex : SymTable * Key * int -> unit + val reserveSymIndex : SymTable -> int + + val extractSymTable : SymTable -> Key vector + val printSymTable : SymTable -> unit + end + +functor SymTable (structure Key : Key) : SymTable = + struct + open UtilError UtilInt + + exception NoSuchSymbol + + type Key = Key.Key + + (*--------------------------------------------------------------------*) + (* a symbol table can have at most size MAX_WIDTH. This is because *) + (* arrays may at most have Array.maxLen elements. We only use powers *) + (* of two as sizes, so we are really only interested in the position *) + (* of maxLen's highest bit. That would be the maximal width for hash *) + (* tables, and thus we must decrease it by one for obtaining the max *) + (* table width. *) + (*--------------------------------------------------------------------*) + fun highestBit w = if w=0w0 then 0 else 1+highestBit(Word.>>(w,0w1)) + val MAX_WIDTH = highestBit (Word.fromInt Array.maxLen)-1 + + type Bucket = (Key * int) list + val nullBucket = nil : Bucket + + (*--------------------------------------------------------------------*) + (* buckets are sorted - though they are probably small. *) + (*--------------------------------------------------------------------*) + fun addToBucket (ni as (key,_),bucket) = + let + fun doit nil = [ni] + | doit (nis as (ni' as (key',_))::rest) = + case Key.compare (key',key) + of LESS => ni'::doit rest + | EQUAL => ni::rest + | GREATER => ni::nis + in + doit bucket + end + fun searchBucket (key,bucket) = + let + fun doit nil = NONE + | doit ((key',i)::rest) = + case Key.compare (key',key) + of LESS => doit rest + | EQUAL => SOME i + | GREATER => NONE + in + doit bucket + end + + (*--------------------------------------------------------------------*) + (* a symbol table consists of *) + (* - an array tab holding for each index its key *) + (* - a hash table, i.e. Bucket array, of double size than tab *) + (* - a hashFun mapping Key to the range of the hash table *) + (* - an integer width for computing table sizes *) + (* - an integer size wich is the size of the value table *) + (* - an integer count holding the next free index *) + (*--------------------------------------------------------------------*) + type SymTable = {desc : string, + tab : Key array ref, + hash : Bucket array ref, + hashFun : (Key -> int) ref, + width : int ref, (* bit width *) + size : int ref, (* tab size=2^width, hash size is double *) + count : int ref (* number of entries *) + } + + fun nullSymTable desc = {desc = desc, + tab = ref (Array.array(1,Key.null)), + hash = ref (Array.array(2,nullBucket)), + hashFun = ref (fn _ => 0), + count = ref 0, + size = ref 1, + width = ref 0} : SymTable + + (*--------------------------------------------------------------------*) + (* how many entries are in the symtable? *) + (*--------------------------------------------------------------------*) + fun usedSymbols ({count,...}:SymTable) = !count + + (*--------------------------------------------------------------------*) + (* what is the table load, i.e. percentage of number of entries to *) + (* hash table size = 100*count/(2*size) = 50*count/size. *) + (*--------------------------------------------------------------------*) + fun hashRatio({count,size,...}:SymTable) = 50 * !count div !size + handle Div => 100 + + (*--------------------------------------------------------------------*) + (* this is the hash function. Key.hash hashes data to arbitrary *) + (* words, that are mapped to the hash range by this function, where *) + (* mask is the bitmask corresponding to the size of the hash table: *) + (* 1. square the word produced by Key.hash *) + (* 2. take the width bits from the middle of the square, these are *) + (* the bit-places influenced by all input bit-places: *) + (* - shift to the right by half of the destination width *) + (* - mask out all bits to the left of destination *) + (* this is a simple strategy but experiences good results. *) + (*--------------------------------------------------------------------*) + fun square (x:word) = Word.*(x,x) + fun hashKey(half,mask) x = + Word.toInt(Word.andb(mask,Word.>>(square(Key.hash x),half))) + fun makeHashFun(size,width) = + let + val mask = Word.fromInt(2*size-1) + val half = Word.fromInt((width+1) div 2) + in + hashKey(half,mask) + end + + (*--------------------------------------------------------------------*) + (* create a new symtable for 2^w, but at least 2 and at most 2^m *) + (* entries, where m is the value of MAX_WIDTH. *) + (*--------------------------------------------------------------------*) + fun makeSymTable (desc,w) = + let + val width= Int.min(Int.max(1,w),MAX_WIDTH) + val size = Word.toInt(Word.<<(0w1,Word.fromInt(width-1))) + in {desc = desc, + tab = ref (Array.array(size,Key.null)), + hash = ref (Array.array(2*size,nullBucket)), + hashFun = ref (makeHashFun(size,width)), + width = ref width, + size = ref size, + count = ref 0} + end + + (*--------------------------------------------------------------------*) + (* clear a dictionary. If the 2nd arg is SOME w, use w for resizing. *) + (*--------------------------------------------------------------------*) + fun clearSymTable (symTab:SymTable,widthOpt) = + case widthOpt + of NONE => + let + val {tab=ref tab,hash=ref hash,size,count,...} = symTab + val _ = appInterval (fn i => Array.update(tab,i,Key.null)) (0,!count-1) + val _ = appInterval (fn i => Array.update(hash,i,nullBucket)) (0,!size*2-1) + in + count := 0 + end + | SOME w => + let + val {tab,hash,hashFun,width,size,count,...} = symTab + val newWidth = Int.min(Int.max(1,w),MAX_WIDTH) + val newSize = Word.toInt(Word.<<(0w1,Word.fromInt(newWidth-1))) + val _ = tab := (Array.array(newSize,Key.null)) + val _ = hash := (Array.array(2*newSize,nullBucket)) + val _ = hashFun := (makeHashFun(newSize,newWidth)) + val _ = width := newWidth + val _ = size := newSize + in + count := 0 + end + + (*--------------------------------------------------------------------*) + (* grow a symtable to the double size. raise InternalError if the *) + (* table already has maximal size. *) + (*--------------------------------------------------------------------*) + fun growTable ({desc,tab,hash,hashFun,width,size,count}:SymTable) = + let + val newWidth = if !width < MAX_WIDTH then !width+1 + else raise InternalError + ("SymTable","growTable", + String.concat ["growing the ",desc," symbol table ", + "exceeded the system maximum size of ", + Int.toString Array.maxLen," for arrays"]) + val newSize = !size*2 + + val oldTab = !tab + val newTab = Array.array(newSize,Key.null) + val newHash = Array.array(2*newSize,nullBucket) + val newHashFun = makeHashFun(newSize,newWidth) + + fun addToNew (inv as (i,key)) = + let + val idx = newHashFun key + val _ = Array.update(newHash,idx,addToBucket((key,i),Array.sub(newHash,idx))) + val _ = Array.update(newTab,i,key) + in () + end + val _ = Array.appi addToNew (!tab) + + val _ = tab := newTab + val _ = hash := newHash + val _ = size := newSize + val _ = width := newWidth + val _ = hashFun := newHashFun + in () + end + + (*--------------------------------------------------------------------*) + (* lookup the key for an index of the symbol table. *) + (*--------------------------------------------------------------------*) + fun getSymKey({tab,count,...}:SymTable,idx) = + if !count>idx then Array.sub(!tab,idx) + else raise NoSuchSymbol + + (*--------------------------------------------------------------------*) + (* map a Key to its index in the symbol table. if it is not in the *) + (* symbol table yet, add a new entry with a new index. grow the table *) + (* if there is no more free index in the table. *) + (*--------------------------------------------------------------------*) + fun getSymIndex(st as {tab,hash,hashFun,size,count,...}:SymTable,key) = + let + val idx = !hashFun key + val bucket = Array.sub(!hash,idx) + in + case searchBucket(key,bucket) + of SOME i => i + | NONE => let val i = !count + val (idx',buck') = if !size>i then (idx,bucket) + else let val _ = growTable st + val idx' = !hashFun key + val buck' = Array.sub(!hash,idx') + in (idx',buck') + end + val _ = Array.update(!hash,idx',addToBucket((key,i),buck')) + val _ = Array.update(!tab,i,key) + val _ = count := i+1 + in i + end + end + + (*--------------------------------------------------------------------*) + (* does a Key have an entry in a symbol table? *) + (*--------------------------------------------------------------------*) + fun hasSymIndex({hash,hashFun,...}:SymTable,key) = + let + val idx = !hashFun key + val buck = Array.sub(!hash,idx) + in + searchBucket(key,buck) + end + + (*--------------------------------------------------------------------*) + (* reserve an index for a (yet unknown) key. *) + (*--------------------------------------------------------------------*) + fun reserveSymIndex(st as {size,count=count as ref i,...}:SymTable) = + let + val _ = if !size>i then () else growTable st + val _ = count := i+1 + in i + end + + (*--------------------------------------------------------------------*) + (* assign an index to a (previously reserved) index. *) + (*--------------------------------------------------------------------*) + fun assignSymIndex(st as {count,hash,hashFun,tab,...}:SymTable,key,i) = + if !count<=i then raise NoSuchSymbol + else let val idx = !hashFun key + val buck = Array.sub(!hash,idx) + val newBuck = addToBucket((key,i),buck) + val _ = Array.update(!hash,idx,newBuck) + val _ = Array.update(!tab,i,key) + in () + end + + (*--------------------------------------------------------------------*) + (* extract the contents of a symbol table to a vector. *) + (*--------------------------------------------------------------------*) + fun extractSymTable({count,tab,...}:SymTable) = + ArraySlice.vector(ArraySlice.slice(!tab,0,SOME(!count))) + + (*--------------------------------------------------------------------*) + (* print the contents of the symbol table. *) + (*--------------------------------------------------------------------*) + fun printSymTable ({desc,tab,count,...}:SymTable) = + (print (desc^" table:\n"); + ArraySlice.appi + (fn (n,key) => + print (" "^Int.toString n^": "^Key.toString key^"\n")) + (ArraySlice.slice(!tab,0,SOME (!count)))) + end diff --git a/fxp/src/Util/intLists.sml b/fxp/src/Util/intLists.sml new file mode 100644 index 0000000..4be52de --- /dev/null +++ b/fxp/src/Util/intLists.sml @@ -0,0 +1,49 @@ +signature IntLists = + sig + type IntList = int list + + val emptyIntList : IntList + val singleIntList : int -> IntList + val fullIntList : int -> IntList + + val isEmptyIntList : IntList -> bool + val inIntList : int * IntList -> bool + val subIntList : IntList * IntList -> bool + + val compareIntLists: IntList * IntList -> order + val hashIntList : IntList -> word + + val addIntList : int * IntList -> IntList + val delIntList : int * IntList -> IntList + + val cupIntLists : IntList * IntList -> IntList + val capIntLists : IntList * IntList -> IntList + val diffIntLists : IntList * IntList -> IntList + + val IntList2String : IntList -> string + end + +structure IntLists : IntLists = + struct + open UtilCompare UtilHash UtilInt UtilList UtilString + + type IntList = int list + + val emptyIntList = nil : IntList + + fun fullIntList n = intervalList(0,n) + fun singleIntList n = [n] + val isEmptyIntList = null + + val inIntList = elem Int.compare + val subIntList = sub Int.compare + val addIntList = insert Int.compare + val delIntList = delete Int.compare + val capIntLists = cap Int.compare + val cupIntLists = merge Int.compare + val diffIntLists = diff Int.compare + val compareIntLists = compareList Int.compare + val hashIntList = hashList hashInt + + val IntList2String = List2String Int.toString + end diff --git a/fxp/src/Util/intSets.sml b/fxp/src/Util/intSets.sml new file mode 100644 index 0000000..e0ca583 --- /dev/null +++ b/fxp/src/Util/intSets.sml @@ -0,0 +1,173 @@ + + + + + + + +signature IntSets = + sig + eqtype IntSet + + val emptyIntSet : IntSet + val singleIntSet : int -> IntSet + val fullIntSet : int -> IntSet + + val isEmptyIntSet : IntSet -> bool + val inIntSet : int * IntSet -> bool + + val compareIntSets: IntSet * IntSet -> order + val hashIntSet : IntSet -> word + + val addIntSet : int * IntSet -> IntSet + val delIntSet : int * IntSet -> IntSet + + val cupIntSets : IntSet * IntSet -> IntSet + val capIntSets : IntSet * IntSet -> IntSet + val diffIntSets : IntSet * IntSet -> IntSet + + val IntSet2List : IntSet -> int list + val IntList2Set : int list -> IntSet + end + +structure IntSets : IntSets = + struct + structure W = Word32 + val wordSize = W.wordSize + + type IntSet = W.word vector + + infix 7 << >> + infix 6 && + infix 5 || + + val op >> = W.>> + val op << = W.<< + val op && = W.andb + val op || = W.orb + val !! = W.notb + + fun normalize (vec:IntSet) = + let val max = Vector.foldli + (fn (i,w,max) => if w=0wx0 then i else max) 0 vec + in VectorSlice.vector(VectorSlice.slice (vec,0,SOME max)) + end + + val emptyIntSet = Vector.fromList nil : IntSet + + fun fullIntSet n = let val size = (n+wordSize-1) div wordSize + val full = 0w0-0w1:W.word + val bits = (n-1) mod wordSize+1 + val last = full >> (Word.fromInt (wordSize-bits)) + in Vector.tabulate(n div wordSize+1, + fn i => if i if i=idx then mask else 0w0):IntSet + end + + fun isEmptyIntSet vec = Vector.length vec=0 + + fun inIntSet(n,vec) = + let val idx = n div wordSize + in if idx>=Vector.length vec then false + else let val mask = 0w1 << (Word.fromInt (n mod wordSize)) + in Vector.sub(vec,idx) && mask <> 0w0 + end + end + + fun addIntSet(n,vec) = + let + val idx = n div wordSize + val mask = 0w1 << (Word.fromInt (n mod wordSize)) + val size = Vector.length vec + in + if size>idx + then Vector.mapi (fn (i,x) => if i=idx then x||mask else x) vec + else Vector.tabulate + (idx+1,fn i => if i if i=idx then x && mask else x) vec + end + in normalize vec1 + end + + fun capIntSets(vec1,vec2) = + let + val l12 = Int.min(Vector.length vec1,Vector.length vec2) + val v12 = Vector.tabulate(l12,fn i => Vector.sub(vec1,i) && Vector.sub(vec2,i)) + in + normalize v12 + end + + fun cupIntSets(vec1,vec2) = + let + val (l1,l2) = (Vector.length vec1,Vector.length vec2) + val (shorter,longer,v) = if l1<=l2 then (l1,l2,vec2) else (l2,l1,vec1) + in + Vector.tabulate (longer,fn i => if i>=shorter then Vector.sub(v,i) + else Vector.sub(vec1,i) || Vector.sub(vec2,i)) + end + + fun diffIntSets(vec1,vec2) = + let + val (l1,l2) = (Vector.length vec1,Vector.length vec2) + val vec1 = Vector.tabulate + (l1,fn i => if i>=l2 then Vector.sub(vec1,i) + else Vector.sub(vec1,i) && !!(Vector.sub(vec2,i))) + in normalize vec1 + end + + fun IntList2Set l = List.foldl addIntSet emptyIntSet l + + fun IntSet2List vec = + let + val size = Vector.length vec + fun doOne (w,off,yet) = + let fun doit (i,mask) = + if i=wordSize then yet + else if w&&mask=0w0 then doit(i+1,mask<<0wx1) + else (off+i)::doit(i+1,mask<<0wx1) + in doit(0,0wx1) + end + fun doAll i = if i>=size then nil + else doOne(Vector.sub(vec,i),wordSize*i,(doAll (i+1))) + in doAll 0 + end + + fun compareIntSets (vec1,vec2:IntSet) = + let + val (l1,l2) = (Vector.length vec1,Vector.length vec2) + val (l12,ifEq) = case Int.compare(l1,l2) + of LESS => (l1,LESS) + | order => (l2,order) + fun doit i = if i>=l12 then ifEq + else case W.compare(Vector.sub(vec1,i),Vector.sub(vec2,i)) + of EQUAL => doit (i+1) + | order => order + in doit 0 + end + + val intShift = case Int.precision + of NONE => 0w0 + | SOME x => Word.fromInt(Int.max(wordSize-x+1,0)) + + fun hashIntSet vec = + case Vector.length vec + of 0 => 0w0 + | 1 => Word.fromInt(W.toInt(W.>>(Vector.sub(vec,0),intShift))) + | l => Word.fromInt(W.toInt(W.>>(Vector.sub(vec,0)+Vector.sub(vec,l-1),intShift))) + end diff --git a/fxp/src/Util/options.sml b/fxp/src/Util/options.sml new file mode 100644 index 0000000..b813267 --- /dev/null +++ b/fxp/src/Util/options.sml @@ -0,0 +1,105 @@ +signature Options= + sig + datatype Option = + OPT_LONG of string * string option + | OPT_SHORT of char list + | OPT_NEG of char list + | OPT_NOOPT + | OPT_STRING of string + val parseOptions : string list -> Option list + + datatype UsageItem = + U_SEP + | U_TITLE of string + | U_ITEM of string list * string + type Usage = UsageItem list + val printUsage : TextIO.outstream -> string -> Usage -> unit + end + +structure Options : Options = + struct + exception BadOption of string + + datatype Option = + OPT_LONG of string * string option + | OPT_SHORT of char list + | OPT_NEG of char list + | OPT_NOOPT + | OPT_STRING of string + + datatype UsageItem = + U_SEP + | U_TITLE of string + | U_ITEM of string list * string + type Usage = UsageItem list + + fun parseOptions ss = + let + fun doOne opt = + if String.isPrefix "--" opt + then let val opt1 = Substring.extract(opt,2,NONE) + val (key0,opt2) = Substring.splitl (fn c => #"="<>c) opt1 + val key = if Substring.isEmpty key0 then raise BadOption opt + else Substring.string key0 + val valOpt = if Substring.isPrefix "=" opt2 + then let val val0 = Substring.triml 1 opt2 + in if Substring.isEmpty val0 + then raise BadOption opt + else SOME(Substring.string val0) + end + else NONE + in OPT_LONG(key,valOpt) + end + handle BadOption s => if opt="--" then OPT_NOOPT else OPT_STRING opt + else if String.isPrefix "-" opt + then let val chars = tl(String.explode opt) + (* val _ = app (fn c => if Char.isAlphaNum c then () + else raise BadOption opt) chars *) + in case chars + of nil => OPT_STRING opt + | #"n"::(cs as _::_) => OPT_NEG cs + | _ => OPT_SHORT chars + end + handle BadOption s => OPT_STRING opt + else OPT_STRING opt + + fun doAll nil = nil + | doAll (s::ss) = let val opt = doOne s + in case opt + of OPT_NOOPT => opt::map OPT_STRING ss + | _ => opt::doAll ss + end + in doAll ss + end + + fun printUsage stream prog usage = + let + val KEY_WIDTH = 30 + val LINE_WIDTH = 80 + val EMPTY_KEY = UtilString.nBlanks KEY_WIDTH + fun appendKeys col nil = if col>KEY_WIDTH then "\n"^EMPTY_KEY + else UtilString.nBlanks (KEY_WIDTH-col) + | appendKeys col [key] = key^" "^appendKeys (col+1+String.size key) nil + | appendKeys col (key::keys) = let val col1 = col+2+String.size key + in if col1>KEY_WIDTH + then key^",\n"^appendKeys 0 keys + else key^", "^appendKeys col1 keys + end + fun makeKey keylist = appendKeys 0 keylist + val makeText = UtilString.breakLines(LINE_WIDTH-KEY_WIDTH) + fun format (keylist,text) = + let val key = makeKey keylist + in case makeText text + of nil => [key] + | line::lines => key^line::map (fn line => EMPTY_KEY^line) lines + end + val _ = app (fn x => TextIO.output(stream,x)) + ["Usage: ",prog," [option ...] file\n","where option is one of:\n\n"] + val _ = app (fn item => app (fn x => TextIO.output(stream,x^"\n")) + (case item + of U_SEP => [""] + | U_TITLE txt => ["",txt] + | U_ITEM option => format option)) usage + in () + end + end diff --git a/fxp/src/Util/utilCompare.sml b/fxp/src/Util/utilCompare.sml new file mode 100644 index 0000000..01a8dc6 --- /dev/null +++ b/fxp/src/Util/utilCompare.sml @@ -0,0 +1,89 @@ +signature UtilCompare = + sig + type 'a Comparer = 'a * 'a -> order + + val comparePair : 'a Comparer * 'b Comparer -> ('a * 'b) Comparer + val compareTriple : 'a Comparer * 'b Comparer * 'c Comparer -> ('a * 'b * 'c) Comparer + + val compareOption : 'a Comparer -> 'a option Comparer + val compareList : 'a Comparer -> 'a list Comparer + val compareVector : 'a Comparer -> 'a vector Comparer + + val compareInt : int Comparer + val compareIntPair : (int * int) Comparer + val compareIntTriple : (int * int * int) Comparer + + val compareWord : word Comparer + val compareWordPair : (word * word) Comparer + val compareWordTriple : (word * word * word) Comparer + end + +structure UtilCompare : UtilCompare = + struct + type 'a Comparer = 'a * 'a -> order + + fun comparePair (compareA,compareB) ((a1,b1),(a2,b2)) = + case compareA(a1,a2) + of EQUAL => compareB(b1,b2) + | order => order + fun compareTriple (compareA,compareB,compareC) ((a1,b1,c1),(a2,b2,c2)) = + case compareA(a1,a2) + of EQUAL => (case compareB(b1,b2) + of EQUAL => compareC(c1,c2) + | order => order) + | order => order + + val compareInt = Int.compare + fun compareIntPair((x1,y1),(x2,y2)) = + case Int.compare(x1,x2) + of EQUAL => Int.compare (y1,y2) + | order => order + fun compareIntTriple((x1,y1,z1),(x2,y2,z2)) = + case Int.compare(x1,x2) + of EQUAL => (case Int.compare (y1,y2) + of EQUAL => Int.compare (z1,z2) + | order => order) + | order => order + + val compareWord = Word.compare + fun compareWordPair((x1,y1),(x2,y2)) = + case Word.compare(x1,x2) + of EQUAL => Word.compare (y1,y2) + | order => order + fun compareWordTriple((x1,y1,z1),(x2,y2,z2)) = + case Word.compare(x1,x2) + of EQUAL => (case Word.compare (y1,y2) + of EQUAL => Word.compare (z1,z2) + | order => order) + | order => order + + fun compareOption compareA opts = + case opts + of (NONE,NONE) => EQUAL + | (NONE,SOME x) => LESS + | (SOME x,NONE) => GREATER + | (SOME x,SOME y) => compareA(x,y) + + fun compareList compA ll = + let fun doit (nil,nil) = EQUAL + | doit (nil,_) = LESS + | doit (_,nil) = GREATER + | doit (a1::as1,a2::as2) = case compA(a1,a2) + of EQUAL => doit(as1,as2) + | order => order + in doit ll + end + + fun compareVector compA (vec1,vec2) = + let val (l,l2) = (Vector.length vec1,Vector.length vec2) + in case Int.compare(l,l2) + of EQUAL => let fun doit i = if i>=l then EQUAL + else case compA(Vector.sub(vec1,i),Vector.sub(vec2,i)) + of EQUAL => doit (i+1) + | order => order + in doit 0 + end + | order => order + end + end + diff --git a/fxp/src/Util/utilError.sml b/fxp/src/Util/utilError.sml new file mode 100644 index 0000000..b890426 --- /dev/null +++ b/fxp/src/Util/utilError.sml @@ -0,0 +1,49 @@ + + + + + +signature UtilError = + sig + exception InternalError of string * string * string + exception NoSuchFile of string * string + + val formatMessage : int * int -> string list -> string + end + +structure UtilError : UtilError = + struct + open UtilString + + exception InternalError of string * string * string + exception NoSuchFile of string * string + + fun formatMessage (indentWidth,lineWidth) strs = + let + val indent = nBlanks indentWidth + val nl = "\n"^indent + val blank = " " + val dot = "." + + fun isSep c = #" "=c orelse #"\n"=c orelse #"\t"=c + + fun go (w,yet) nil = List.rev ("\n"::yet) + | go (w,yet) (x::xs) = + let + val y = if null xs then x^dot else x + val l = String.size y + val w1 = w+l + val (w2,yet2) = if w1<=lineWidth then (w1,y::yet) + else (indentWidth+l,y::nl::yet) + val (w3,yet3) = if null xs then (w2,yet2) + else (if w2 word) * ('b -> word) -> 'a * 'b -> word + val hashTriple : ('a -> word) * ('b -> word) * ('c -> word) -> 'a * 'b * 'c -> word + + val hashOption : ('a -> word) -> 'a option -> word + val hashList : ('a -> word) -> 'a list -> word + val hashVector : ('a -> word) -> 'a vector -> word + + val hashString : string -> word + + val hashInt : int -> word + val hashIntPair : int * int -> word + val hashIntTriple : int * int * int -> word + + val hashWord : word -> word + val hashWordPair : word * word -> word + val hashWordTriple : word * word * word -> word + end + +structure UtilHash : UtilHash = + struct + fun hashPair (hashA,hashB) (a,b) = + 0w1327 * hashA a + 0w3853 * hashB b + fun hashTriple (hashA,hashB,hashC) (a,b,c) = + 0w1327 * hashA a + 0w3853 * hashB b + 0w2851 * hashC c + + val hashInt = + Word.fromInt + fun hashIntPair (i,j) = + 0w1327 * Word.fromInt i + 0w3853 * Word.fromInt j + fun hashIntTriple (i,j,k) = + 0w1327 * Word.fromInt i + 0w3853 * Word.fromInt j + 0w2851 * Word.fromInt k + + fun hashWord w = w + fun hashWordPair (i,j) = 0w1327 * i + 0w3853 * j + fun hashWordTriple (i,j,k) = 0w1327 * i + 0w3853 * j + 0w2851 * k + + val hashChar = Word.fromInt o ord + fun hashString s = + case String.size s + of 0 => 0wx0 + | 1 => 0w1 + hashChar(String.sub(s,0)) + | 2 => let val w1 = String.sub(s,0) + val w2 = String.sub(s,1) + in 0w2 + hashChar w1 * 0wx1327 + hashChar w2 + end + | n => let val w1 = String.sub(s,0) + val w2 = String.sub(s,1) + val wn = String.sub(s,n-1) + in 0w3 + hashChar w1 * 0wx3853 + hashChar w2 * 0wx1327 + hashChar wn + end + + + fun hashOption hashA opt = + case opt + of NONE => 0w0 + | SOME a => 0w1 + hashA a + + fun hashList hashA l = + case l + of nil => 0wx0 + | [a] => 0w1 + hashA a + | a1::a2::_ => 0w2 + 0w3853 * hashA a1 + 0wx1327 * hashA a2 + + fun hashVector hashA cv = + case Vector.length cv + of 0 => 0wx0 + | 1 => 0w1 + hashA(Vector.sub(cv,0)) + | 2 => let val w1 = Vector.sub(cv,0) + val w2 = Vector.sub(cv,1) + in 0w2 + hashA w1 * 0wx1327 + hashA w2 + end + | n => let val w1 = Vector.sub(cv,0) + val w2 = Vector.sub(cv,1) + val wn = Vector.sub(cv,n-1) + in 0w3 + hashA w1 * 0wx3853 + hashA w2 * 0wx1327 + hashA wn + end + end + diff --git a/fxp/src/Util/utilInt.sml b/fxp/src/Util/utilInt.sml new file mode 100644 index 0000000..c215c35 --- /dev/null +++ b/fxp/src/Util/utilInt.sml @@ -0,0 +1,86 @@ +(*--------------------------------------------------------------------------*) +(* Structure: UtilInt *) +(* *) +(* Depends on: *) +(* *) +(* Exceptions raised by functions in this structure: *) +(* appInterval : none *) +(* insertInt : none *) +(* insertNewInt : none *) +(* nextPowerTwo : none *) +(*--------------------------------------------------------------------------*) +signature UtilInt = + sig + val intervalList : (int * int) -> int list + val appInterval : (int -> unit) -> (int * int) -> unit + val insertInt : int * int list -> int list + val insertNewInt : int * int list -> int list option + val powerOfTwo : int -> int + val nextPowerTwo : int -> int + end + +structure UtilInt : UtilInt = + struct + (*--------------------------------------------------------------------*) + (* generate the list [n,...,m] *) + (*--------------------------------------------------------------------*) + fun intervalList(n,m) = if n>m then nil else n::intervalList(n+1,m) + + (*--------------------------------------------------------------------*) + (* apply f to each number in [n...m] *) + (*--------------------------------------------------------------------*) + fun appInterval f (n,m) = + let fun doit i = + if i>m then () + else let val _ = f i + in doit (i+1) + end + in doit n + end + + (*--------------------------------------------------------------------*) + (* insert an integer into a sorted list without duplicates. *) + (*--------------------------------------------------------------------*) + fun insertInt (x:int,l) = + let fun go nil = [x] + | go (l as y::ys) = case Int.compare (x,y) + of LESS => x::l + | EQUAL => l + | GREATER => y::go ys + in go l + end + + (*--------------------------------------------------------------------*) + (* insert an integer into a sorted list if it is not yet in it. *) + (*--------------------------------------------------------------------*) + fun insertNewInt (x:int,l) = + let + fun go nil = SOME [x] + | go (l as y::ys) = case Int.compare (x,y) + of LESS => SOME(x::l) + | EQUAL => NONE + | GREATER => case go ys + of NONE => NONE + | SOME xys => SOME(y::xys) + in go l + end + + (*--------------------------------------------------------------------*) + (* compute the power to the base of two. *) + (*--------------------------------------------------------------------*) + fun powerOfTwo n = + if n=0 then 1 + else if n mod 2=0 then let val x=powerOfTwo (n div 2) in x*x end + else let val x=powerOfTwo (n-1) in 2*x end + + (*--------------------------------------------------------------------*) + (* find the smallest p with 2^p >= n. *) + (*--------------------------------------------------------------------*) + fun nextPowerTwo n = + let fun doit (p,m) = + if m>=n then p + else if m*m<2*n then doit (2*p,m*m) + else doit (1+p,2*m) + in doit (1,2) + end + end diff --git a/fxp/src/Util/utilList.sml b/fxp/src/Util/utilList.sml new file mode 100644 index 0000000..1b7ad39 --- /dev/null +++ b/fxp/src/Util/utilList.sml @@ -0,0 +1,198 @@ + + + +(*--------------------------------------------------------------------------*) +(* Structure: UtilList *) +(* *) +(* Depends on: *) +(* *) +(* Exceptions raised by functions in this structure: *) +(* member : none *) +(* findAndDelete : none *) +(*--------------------------------------------------------------------------*) +signature UtilList = + sig + val split : ('a -> bool) -> 'a list -> 'a list list + val member : ''a -> ''a list -> bool + val mapAllPairs : ('a * 'b -> 'c) -> 'a list * 'b list -> 'c list + val findAndMap : ('a -> 'b option) -> 'a list -> 'b option + val findAndDelete : ('a -> bool) -> 'a list -> ('a option * 'a list) + + val sort : ('a * 'a -> order) -> 'a list -> 'a list + val merge : ('a * 'a -> order) -> 'a list * 'a list -> 'a list + val diff : ('a * 'a -> order) -> 'a list * 'a list -> 'a list + val cap : ('a * 'a -> order) -> 'a list * 'a list -> 'a list + val sub : ('a * 'a -> order) -> 'a list * 'a list -> bool + val insert : ('a * 'a -> order) -> 'a * 'a list -> 'a list + val delete : ('a * 'a -> order) -> 'a * 'a list -> 'a list + val elem : ('a * 'a -> order) -> 'a * 'a list -> bool + end + +structure UtilList : UtilList = + struct + (*--------------------------------------------------------------------*) + (* split a list into a list of lists at each element fullfilling p. *) + (*--------------------------------------------------------------------*) + fun split p l = + let val (one,ls) = foldr + (fn (a,(curr,ls)) => if p a then (nil,curr::ls) else (a::curr,ls)) + (nil,nil) l + in one::ls + end + + (*--------------------------------------------------------------------*) + (* is x a member of l? *) + (*--------------------------------------------------------------------*) + fun member x l = List.exists (fn y => x=y) l + + (*--------------------------------------------------------------------*) + (* for [a1,...,an] and [b1,...,bk], generate *) + (* [f(a1,b1),f(a1,b2),...,f(an,bk-1),f(an,bk)]. *) + (*--------------------------------------------------------------------*) + fun mapAllPairs f (ass,bs) = + foldr + (fn (a,cs) => foldr (fn (b,cs) => f(a,b)::cs) cs bs) + nil ass + + (*--------------------------------------------------------------------*) + (* find the first element x of l such that f x = SOME y, and return *) + (* f x. If there is no such x, return NONE. *) + (*--------------------------------------------------------------------*) + fun findAndMap _ nil = NONE + | findAndMap f (x::xs) = case f x of NONE => findAndMap f xs | y => y + + (*--------------------------------------------------------------------*) + (* find the first element x of l such that f x = true, delete it from *) + (* l, and return SOME x with the modified list. If there is no such x *) + (* return (NONE,l). *) + (*--------------------------------------------------------------------*) + fun findAndDelete _ nil = (NONE,nil) + | findAndDelete f (x::xs) = + if f x then (SOME x,xs) + else let val (y,ys) = findAndDelete f xs in (y,x::ys) end + + (*--------------------------------------------------------------------*) + (* given a function that compares elements, merge two sorted lists. *) + (*--------------------------------------------------------------------*) + fun merge comp (l1,l2) = + let + fun go (nil,l) = l + | go (l,nil) = l + | go (l1 as (x1::r1),l2 as (x2::r2)) = + case comp(x1,x2) + of LESS => x1::go(r1,l2) + | EQUAL => go(l1,r2) + | GREATER => x2::go(l1,r2) + in go(l1,l2) + end + + (*--------------------------------------------------------------------*) + (* given a comparing function, compute the intersection of two *) + (* ordered lists. *) + (*--------------------------------------------------------------------*) + fun cap comp (l1,l2) = + let + fun go (nil,l) = nil + | go (l,nil) = nil + | go (l1 as (x1::r1),l2 as (x2::r2)) = + case comp(x1,x2) + of LESS => go(r1,l2) + | EQUAL => x1::go(r1,r2) + | GREATER => go(l1,r2) + in go(l1,l2) + end + + (*--------------------------------------------------------------------*) + (* given a comparing function, compute the difference of two *) + (* ordered lists. *) + (*--------------------------------------------------------------------*) + fun diff comp (l1,l2) = + let + fun go (nil,l) = nil + | go (l,nil) = l + | go (l1 as (x1::r1),l2 as (x2::r2)) = + case comp(x1,x2) + of LESS => x1::go(r1,l2) + | EQUAL => go(r1,r2) + | GREATER => go(l1,r2) + in go(l1,l2) + end + + (*--------------------------------------------------------------------*) + (* given a comparing function, find out whether an ordered list is *) + (* contained in an other ordered list. *) + (*--------------------------------------------------------------------*) + fun sub comp (l1,l2) = + let + fun go (nil,l) = true + | go (l,nil) = false + | go (l1 as (x1::r1),l2 as (x2::r2)) = + case comp(x1,x2) + of LESS => false + | EQUAL => go(r1,r2) + | GREATER => go(l1,r2) + in go(l1,l2) + end + + (*--------------------------------------------------------------------*) + (* given a function that compares elements, insert an element into an *) + (* ordered list. *) + (*--------------------------------------------------------------------*) + fun insert comp (x,l) = + let + fun go nil = [x] + | go (l as y::ys) = + case comp(x,y) + of LESS => x::l + | EQUAL => l + | GREATER => y::go ys + in go l + end + + (*--------------------------------------------------------------------*) + (* given a function that compares elements, delete an element from *) + (* an ordered list. *) + (*--------------------------------------------------------------------*) + fun delete comp (x,l) = + let + fun go nil = [x] + | go (l as y::ys) = + case comp(x,y) + of LESS => l + | EQUAL => ys + | GREATER => y::go ys + in go l + end + + (*--------------------------------------------------------------------*) + (* given a function that compares elements, insert an element into an *) + (* ordered list. *) + (*--------------------------------------------------------------------*) + fun elem comp (x,l) = + let + fun go nil = false + | go (l as y::ys) = + case comp(x,y) + of LESS => false + | EQUAL => true + | GREATER => go ys + in go l + end + + (*--------------------------------------------------------------------*) + (* merge-sort a list of elements comparable with the function in the *) + (* 1st argument. Preserve duplicate elements. *) + (*--------------------------------------------------------------------*) + fun sort _ nil = nil + | sort comp l = + let fun mergeOne (x::y::l) = merge comp (x,y)::mergeOne l + | mergeOne l = l + fun mergeAll [l] = l + | mergeAll ls = mergeAll (mergeOne ls) + val singles = map (fn x => [x]) l + in + mergeAll singles + end + + end + diff --git a/fxp/src/Util/utilString.sml b/fxp/src/Util/utilString.sml new file mode 100644 index 0000000..799ab44 --- /dev/null +++ b/fxp/src/Util/utilString.sml @@ -0,0 +1,238 @@ +(*--------------------------------------------------------------------------*) +(* Structure: UtilString *) +(*--------------------------------------------------------------------------*) +signature UtilString = + sig + val quoteString : char -> string -> string + + val numberNth : int -> string + val prependAnA : string -> string + + val nBlanks : int -> string + val padxLeft : char -> string * int -> string + val padxRight : char -> string * int -> string + + val breakLines : int -> string -> string list + + val toUpperFirst : string -> string + val toUpperString : string -> string + + val Int2String : int -> string + + val Bool2xString : string * string -> bool -> string + val Bool2String : bool -> string + + val Option2xString : string * (('a -> string) -> 'a -> string) + -> ('a -> string) -> 'a option -> string + val Option2String0 : ('a -> string) -> 'a option -> string + val Option2String : ('a -> string) -> 'a option -> string + + val List2xString : string * string * string -> ('a -> string) -> 'a list -> string + val List2String0 : ('a -> string) -> 'a list -> string + val List2String : ('a -> string) -> 'a list -> string + + val Vector2xString : string * string * string -> ('a -> string) -> 'a vector -> string + val Vector2String : ('a -> string) -> 'a vector -> string + end + +structure UtilString : UtilString = + struct + fun quoteString q s = let val quote = String.implode [q] in quote^s^quote end + + (*--------------------------------------------------------------------*) + (* generate a string with the ordinal number of n, by appending *) + (* "st", "nd", "rd" or "th" to the number. *) + (*--------------------------------------------------------------------*) + fun numberNth n = + let val suffix = case n mod 9 + of 1 => "st" + | 2 => "nd" + | 3 => "rd" + | _ => "th" + in Int.toString n^suffix + end + + (*--------------------------------------------------------------------*) + (* is the single character c represented by a word starting with a *) + (* vocal in the alphabet? (l~ell->true, k~kay->false) *) + (*--------------------------------------------------------------------*) + fun vocalLetter c = + case Char.toLower c + of #"a" => true + | #"f" => true + | #"h" => true + | #"i" => true + | #"l" => true + | #"m" => true + | #"n" => true + | #"o" => true + | #"r" => true + | #"s" => true + | #"x" => true + | #"8" => true + | _ => false + + (*--------------------------------------------------------------------*) + (* is character c a vocal? *) + (*--------------------------------------------------------------------*) + fun isVocal c = + case Char.toLower c + of #"a" => true + | #"e" => true + | #"i" => true + | #"o" => true + | #"u" => true + | _ => false + + (*--------------------------------------------------------------------*) + (* does a word require "an" as undefinite article? true if: *) + (* - it is a single letter that starts with a vocal in the alphabet *) + (* - its first two letters are capitals, i.e. it is an abbreviation, *) + (* and its first letter starts with a vocal in the alphabet *) + (* - it has more than one letter, is not an abbreviation, and either *) + (* + it starts with a, i or o *) + (* + it starts with e and the second letter is not a u (europe) *) + (* + it starts with a u and continues with a vocal (very unlikely, *) + (* only in c.s., like uuencoded or uid *) + (* + it starts with a u, continues with a consonant not followed by *) + (* an i (like in unicode); that is something like un-... *) + (* This ruleset is not complete since it does not cover, e.g., the *) + (* word uninvented, but sufficient for most cases. *) + (* (Is english pronounciation decidable at all?) *) + (*--------------------------------------------------------------------*) + fun extendsAtoAn word = + case String.explode word + of nil => false + | [c] => vocalLetter c + | c1::c2::cs => if not (Char.isLower c1 orelse Char.isLower c2) + then vocalLetter c1 + else case Char.toLower c1 + of #"a" => true + | #"i" => true + | #"o" => true + | #"e" => Char.toLower c2 <> #"u" + | #"u" => if isVocal c2 then false + else (case cs + of nil => true + | c3::_ => Char.toLower c3 <> #"i") + | _ => false + + (*--------------------------------------------------------------------*) + (* add an undefinite article to a word. *) + (*--------------------------------------------------------------------*) + fun prependAnA word = if extendsAtoAn word then "an "^word else "a "^word + + (*--------------------------------------------------------------------*) + (* generate a list/string of n times character c. *) + (*--------------------------------------------------------------------*) + fun nCharsC c n = if n>0 then c::nCharsC c (n-1) else nil + fun nChars c n = String.implode (nCharsC c n) + val nBlanks = nChars #" " + + (*--------------------------------------------------------------------*) + (* add a minimal number of characters c to the left/right of a string *) + (* in order to make its length at least n. *) + (*--------------------------------------------------------------------*) + fun padxLeft c (s,n) = (nChars c (n-String.size s))^s + fun padxRight c (s,n) = s^(nChars c (n-String.size s)) + val padLeft = padxLeft #" " + val padRight = padxRight #" " + + (*--------------------------------------------------------------------*) + (* break a string into several lines of length width. *) + (*--------------------------------------------------------------------*) + fun breakLines width str = + let + val tokens = String.tokens (fn c => #" "=c) str + fun makeLine(toks,lines) = if null toks then lines + else (String.concat (rev toks))::lines + fun doit w (toks,lines) nil = makeLine(toks,lines) + | doit w (toks,lines) (one::rest) = + let + val l = String.size one + val w1 = w+l + in + if w1=width then doit 0 (nil,one::makeLine(toks,lines)) rest + else doit (l+1) ([" ",one],makeLine(toks,lines)) rest + end + in List.rev (doit 0 (nil,nil) tokens) + end + + (*--------------------------------------------------------------------*) + (* convert the first/all characters of a string to upper case *) + (*--------------------------------------------------------------------*) + fun toUpperFirst str = + case String.explode str + of nil => "" + | c::cs => String.implode (Char.toUpper c::cs) + fun toUpperString str = + String.implode(map Char.toUpper (String.explode str)) + + (*--------------------------------------------------------------------*) + (* return a string representation of an int, char or unit. *) + (*--------------------------------------------------------------------*) + val Int2String = Int.toString + val Char2String = Char.toString + fun Unit2String() = "()" + + (*--------------------------------------------------------------------*) + (* return a string representation of a boolean. *) + (*--------------------------------------------------------------------*) + fun Bool2xString (t,f) b = if b then t else f + val Bool2String = Bool2xString ("true","false") + + (*--------------------------------------------------------------------*) + (* return a string representation of an option. *) + (* the first arg is a string for the NONE case, the second a function *) + (* that converts x to a string, given a function for doing so. *) + (*--------------------------------------------------------------------*) + fun Option2xString (none,Some2String) x2String opt = + case opt + of NONE => none + | SOME x => Some2String x2String x + fun Option2String0 x2String = Option2xString ("",fn f => fn x => f x) x2String + fun Option2String x2String = Option2xString ("NONE",fn f => fn x => "SOME "^f x) x2String + + (*--------------------------------------------------------------------*) + (* return a string representation of list; start with pre, separate *) + (* with sep and finish with post; use X2String for each element. *) + (*--------------------------------------------------------------------*) + fun List2xString (pre,sep,post) X2String nil = pre^post + | List2xString (pre,sep,post) X2String l = + let fun doit nil _ = [post] + | doit (x::r) str = str::X2String x::doit r sep + in String.concat (doit l pre) + end + fun List2String X2String nil = "[]" + | List2String X2String l = + let fun doit nil _ = ["]"] + | doit (x::r) str = str::X2String x::doit r "," + in String.concat (doit l "[") + end + fun List2String0 X2String nil = "" + | List2String0 X2String l = + let fun doit nil _ = nil + | doit (x::r) str = str::X2String x::doit r " " + in String.concat (doit l "") + end + + (* a compiler bug in smlnj 110 makes the following uncompilable: *) + (* fun List2String X2String xs = List2xString ("[",",","]") X2String xs *) + (* fun List2String0 X2String xs = List2xString (""," ","") X2String xs *) + + (*--------------------------------------------------------------------*) + (* return a string representation of list; start with pre, separate *) + (* with sep and finish with post; use X2String for each element. *) + (*--------------------------------------------------------------------*) + fun Vector2xString (pre,sep,post) X2String vec = + if Vector.length vec=0 then pre^post + else String.concat + (pre::X2String(Vector.sub(vec,0)):: + VectorSlice.foldri + (fn (_,x,yet) => sep::X2String x::yet) + [post] + (VectorSlice.slice (vec,1,NONE))) + fun Vector2String X2String vec = Vector2xString ("#[",",","]") X2String vec + end diff --git a/fxp/src/Util/utilTime.sml b/fxp/src/Util/utilTime.sml new file mode 100644 index 0000000..0c58b4e --- /dev/null +++ b/fxp/src/Util/utilTime.sml @@ -0,0 +1,37 @@ + + + +(*--------------------------------------------------------------------------*) +(* Structure: UtilTime *) +(* *) +(* Depends on: *) +(* *) +(* Exceptions raised by functions in this structure: *) +(* time : none *) +(* timeN : none *) +(*--------------------------------------------------------------------------*) +signature UtilTime = + sig + val time : ('a -> 'b) -> 'a -> 'b * {usr:Time.time, sys:Time.time} + val timeN : int -> ('a -> 'b) -> 'a -> 'b * {usr:Time.time, sys:Time.time} + end + +structure UtilTime : UtilTime = + struct + (*--------------------------------------------------------------------*) + (* run f on x, and measure the runtime. return the result and time. *) + (*--------------------------------------------------------------------*) + fun time f x = let val timer = Timer.startCPUTimer () + val y = f x + val ptime = Timer.checkCPUTimer timer + in (y,ptime) + end + + (*--------------------------------------------------------------------*) + (* run f n times on x, and measure the runtime. return the time. *) + (*--------------------------------------------------------------------*) + fun timeN n f x = + let fun iter m = if m<=1 then f x else (ignore (f x); iter (m-1)) + in time iter n + end + end diff --git a/fxp/src/config.sml b/fxp/src/config.sml new file mode 100644 index 0000000..5955dd5 --- /dev/null +++ b/fxp/src/config.sml @@ -0,0 +1,19 @@ +structure Config = + struct + (*---------------------------------------------------------------------*) + (* The OS command for retrieving a URI from the internet and storing *) + (* it in a local file, where *) + (* %1 is replaced by the URI. *) + (* %2 is replaced by the local filename. *) + (* It is recommended that the command exits with failure in case the *) + (* URI cannot be retrieved. If the command generates a HTML error *) + (* message instead (like, e.g., lynx), this HTML file is considered *) + (* to be XML and will probably cause a mess of parsing errors. If you *) + (* don't need URI retrieval, use "exit 1" which always fails. *) + (* Sensible values are, e.g.: *) + (* val retrieveCommand = "wget -qO %2 %1" *) + (* val retrieveCommand = "got_it -o %2 %1" *) + (* val retrieveCommand = "urlget -s -o %2 %1" *) + (*---------------------------------------------------------------------*) + val retrieveCommand = "wget -qO %2 %1" + end diff --git a/fxp/src/fxlib.cm b/fxp/src/fxlib.cm new file mode 100644 index 0000000..87079c6 --- /dev/null +++ b/fxp/src/fxlib.cm @@ -0,0 +1,106 @@ +Group is +#if(defined(SMLNJ_VERSION) && (SMLNJ_MINOR_VERSION < 60)) + $/basis.cm + $smlnj/compiler/compiler.cm +#endif + +#if(defined(SMLNJ_VERSION) && (SMLNJ_MINOR_VERSION >= 60)) + $smlnj/basis/basis.cm + $smlnj/compiler/compiler.cm +#endif + + config.sml + Util/utilCompare.sml + Util/utilString.sml + Util/utilError.sml + Util/utilHash.sml + Util/utilInt.sml + Util/utilList.sml + Util/utilTime.sml + Util/intLists.sml + Util/intSets.sml + Util/options.sml + Util/SymDict/key.sml + Util/SymDict/dict.sml + Util/SymDict/symbolTable.sml + Util/SymDict/intSetDict.sml + Util/SymDict/intDict.sml + Util/SymDict/intListDict.sml + Util/SymDict/stringDict.sml + Unicode/Chars/uniChar.sml + Unicode/Chars/charClasses.sml + Unicode/Chars/charVecDict.sml + Unicode/Chars/dataDict.sml + Unicode/Chars/uniRanges.sml + Unicode/Chars/uniClasses.sml + Unicode/Chars/testClasses.sml + Unicode/Uri/uriDecode.sml + Unicode/Uri/uriEncode.sml + Unicode/Uri/uri.sml + Unicode/Uri/uriDict.sml + Unicode/encoding.sml + Unicode/Encode/encodeBasic.sml + Unicode/Encode/encodeError.sml + Unicode/Encode/encodeMisc.sml + Unicode/Encode/encode.sml + Unicode/Decode/decodeFile.sml + Unicode/Decode/decodeError.sml + Unicode/Decode/decodeMisc.sml + Unicode/Decode/decodeUtil.sml + Unicode/Decode/decodeUcs2.sml + Unicode/Decode/decodeUcs4.sml + Unicode/Decode/decodeUtf16.sml + Unicode/Decode/decodeUtf8.sml + Unicode/Decode/decode.sml + Parser/version.sml + Parser/Dfa/dfaData.sml + Parser/Dfa/dfaError.sml + Parser/Dfa/dfaOptions.sml + Parser/Dfa/dfaUtil.sml + Parser/Dfa/dfaPassOne.sml + Parser/Dfa/dfaPassTwo.sml + Parser/Dfa/dfaPassThree.sml + Parser/Dfa/dfaString.sml + Parser/Dfa/dfa.sml + Parser/Error/errorData.sml + Parser/Error/errorString.sml + Parser/Error/errorMessage.sml + Parser/Error/errorUtil.sml + Parser/Error/expected.sml + Parser/Error/errors.sml + Parser/Base/baseData.sml + Parser/Base/baseString.sml + Parser/Base/base.sml + Parser/Params/dtd.sml + Parser/Params/hookData.sml + Parser/Params/hooks.sml + Parser/Params/ignore.sml + Parser/Params/parserOptions.sml + Parser/Params/resolve.sml + Parser/entities.sml + Parser/Dtd/dtdDeclare.sml + Parser/Dtd/dtdAttributes.sml + Parser/Dtd/dtdManager.sml + Parser/Parse/parseBase.sml + Parser/Parse/parseNames.sml + Parser/Parse/parseMisc.sml + Parser/Parse/parseXml.sml + Parser/Parse/parseRefs.sml + Parser/Parse/parseLiterals.sml + Parser/Parse/parseTags.sml + Parser/Parse/parseDecl.sml + Parser/Parse/parseDtd.sml + Parser/Parse/parseContent.sml + Parser/Parse/parseDocument.sml + Catalog/catData.sml + Catalog/catDtd.sml + Catalog/catError.sml + Catalog/catParams.sml + Catalog/catFile.sml + Catalog/catHooks.sml + Catalog/catOptions.sml + Catalog/socatParse.sml + Catalog/catParse.sml + Catalog/catalog.sml + Catalog/catResolve.sml + genRandom.sml diff --git a/fxp/src/fxlib.mlb b/fxp/src/fxlib.mlb new file mode 100644 index 0000000..54cfafa --- /dev/null +++ b/fxp/src/fxlib.mlb @@ -0,0 +1,105 @@ +ann + "deadCode true" + "warnMatch true" + "sequenceUnit true" +in + local + $(MLTON_ROOT)/basis/basis.mlb + in + config.sml + Util/utilCompare.sml + Util/utilString.sml + Util/utilError.sml + Util/utilHash.sml + Util/utilInt.sml + Util/utilList.sml + Util/utilTime.sml + Util/intLists.sml + Util/intSets.sml + Util/options.sml + Util/SymDict/key.sml + Util/SymDict/dict.sml + Util/SymDict/symbolTable.sml + Util/SymDict/intSetDict.sml + Util/SymDict/intDict.sml + Util/SymDict/intListDict.sml + Util/SymDict/stringDict.sml + Unicode/Chars/uniChar.sml + Unicode/Chars/charClasses.sml + Unicode/Chars/charVecDict.sml + Unicode/Chars/dataDict.sml + Unicode/Chars/uniRanges.sml + Unicode/Chars/uniClasses.sml + Unicode/Chars/testClasses.sml + Unicode/Uri/uriDecode.sml + Unicode/Uri/uriEncode.sml + Unicode/Uri/uri.sml + Unicode/Uri/uriDict.sml + Unicode/encoding.sml + Unicode/Encode/encodeBasic.sml + Unicode/Encode/encodeError.sml + Unicode/Encode/encodeMisc.sml + Unicode/Encode/encode.sml + Unicode/Decode/decodeFile.sml + Unicode/Decode/decodeError.sml + Unicode/Decode/decodeMisc.sml + Unicode/Decode/decodeUtil.sml + Unicode/Decode/decodeUcs2.sml + Unicode/Decode/decodeUcs4.sml + Unicode/Decode/decodeUtf16.sml + Unicode/Decode/decodeUtf8.sml + Unicode/Decode/decode.sml + Parser/version.sml + Parser/Dfa/dfaData.sml + Parser/Dfa/dfaError.sml + Parser/Dfa/dfaOptions.sml + Parser/Dfa/dfaUtil.sml + Parser/Dfa/dfaPassOne.sml + Parser/Dfa/dfaPassTwo.sml + Parser/Dfa/dfaPassThree.sml + Parser/Dfa/dfaString.sml + Parser/Dfa/dfa.sml + Parser/Error/errorData.sml + Parser/Error/errorString.sml + Parser/Error/errorMessage.sml + Parser/Error/errorUtil.sml + Parser/Error/expected.sml + Parser/Error/errors.sml + Parser/Base/baseData.sml + Parser/Base/baseString.sml + Parser/Base/base.sml + Parser/Params/dtd.sml + Parser/Params/hookData.sml + Parser/Params/hooks.sml + Parser/Params/ignore.sml + Parser/Params/parserOptions.sml + Parser/Params/resolve.sml + Parser/entities.sml + Parser/Dtd/dtdDeclare.sml + Parser/Dtd/dtdAttributes.sml + Parser/Dtd/dtdManager.sml + Parser/Parse/parseBase.sml + Parser/Parse/parseNames.sml + Parser/Parse/parseMisc.sml + Parser/Parse/parseXml.sml + Parser/Parse/parseRefs.sml + Parser/Parse/parseLiterals.sml + Parser/Parse/parseTags.sml + Parser/Parse/parseDecl.sml + Parser/Parse/parseDtd.sml + Parser/Parse/parseContent.sml + Parser/Parse/parseDocument.sml + Catalog/catData.sml + Catalog/catDtd.sml + Catalog/catError.sml + Catalog/catParams.sml + Catalog/catFile.sml + Catalog/catHooks.sml + Catalog/catOptions.sml + Catalog/socatParse.sml + Catalog/catParse.sml + Catalog/catalog.sml + Catalog/catResolve.sml + genRandom.sml + end +end diff --git a/fxp/src/genRandom.sml b/fxp/src/genRandom.sml new file mode 100644 index 0000000..d56b9c9 --- /dev/null +++ b/fxp/src/genRandom.sml @@ -0,0 +1,49 @@ +structure GenRandom = + struct + open Encode UniChar UniClasses DecodeFile + + infix 6 || + infix 8 << + val op || = Chars.orb + val op << = Chars.<< + + fun combineUcs4big(b1,b2,b3,b4) = + Byte2Char b1 << 0w24 || Byte2Char b2 << 0w16 || Byte2Char b3 << 0w08 || Byte2Char b4 + + fun genRandom (name,size,mask) = + let + val urand = BinIO.openIn ("/dev/urandom") + val f = encOpenFile(name,Encoding.UCS4,"UCS-4") + val f1 = foldl (fn (c,f) => encPutChar(f,char2Char c)) f + (String.explode "\n\n") + + exception Error of Encode.EncFile * int + fun doit (f,n) = if n<=1 then f + else let val w = let val b1 = valOf (BinIO.input1 urand) + val b2 = valOf (BinIO.input1 urand) + val b3 = valOf (BinIO.input1 urand) + val b4 = valOf (BinIO.input1 urand) + in combineUcs4big(b1,b2,b3,b4) + end + handle Option => raise Error(f,n) + val c = Chars.andb(mask,w) + in if isUnicode c andalso isXml c + andalso c<>0wx3C andalso c<>0wx26 + andalso c<>0wx0D andalso c<>0wx3E + then let val (f1,n1) = + if n mod 80 = 0 + then (encPutChar(f,0wx0A),n-1) else (f,n) + val f2 = encPutChar(f1,c) + in doit(f2,n1-1) + end + else (print "."; doit (f,n)) + end + + val f2 = doit (f1,size-1) handle Error(f,n) + => (f before print ("Error after "^Int.toString (size-n)^" characters!\n")) + val f3 = foldl (fn (c,f) => encPutChar(f,char2Char c)) f (String.explode "\n\n") + val _ = encCloseFile f3 + val _ = BinIO.closeIn urand + in () + end + end

+What is fxp?