/** * @PROJECT AerScript Interpreter * @COPYRIGHT See COPYING in the top level directory * @FILE modules/xml/xml.h * @DESCRIPTION Typed XML SAX module for AerScript Interpreter * @DEVELOPERS Symisc Systems * Rafal Kupiec */ #ifndef __XML_H__ #define __XML_H__ #include "ph7.h" #include "ph7int.h" #include "lib.h" #define MODULE_DESC "XML Module" #define MODULE_VER 1.0 #define XML_ENGINE_MAGIC 0x851EFC52 #define IS_INVALID_XML_ENGINE(XML) (XML == 0 || (XML)->nMagic != XML_ENGINE_MAGIC) /* One snapshot of the QName fields of an open element. The stack of these * lets the end handler restore the parent (enclosing) element after its own * callback, and gives text/PI/DOCTYPE callbacks the enclosing element. */ typedef struct ph7_xml_elem_snapshot ph7_xml_elem_snapshot; struct ph7_xml_elem_snapshot { ph7_value sLocalName; ph7_value sNsUri; ph7_value sPrefix; }; /* * An instance of the following structure describes a working XML engine. * The engine is the payload of the private `resource` field of an XmlReader * instance; all transient SAX state lives here so the typed getters can read * it both from inside a callback and after Parse() returns. */ typedef struct ph7_xml_engine ph7_xml_engine; struct ph7_xml_engine { ph7_vm *pVm; /* VM that owns this instance */ ph7_context *pCtx; /* Current call context */ SyXMLParser sParser; /* Underlying SAX parser */ ph7_value sReaderValue; /* XmlReader object, owned only across Parse() */ ph7_value sHandler; /* IXmlHandler implementation, when installed */ ph7_value sAttrs; /* Snapshot of the current element attributes */ ph7_value sLocalName; /* Current (innermost open) element local name */ ph7_value sNsUri; /* Current element namespace URI */ ph7_value sPrefix; /* Current element prefix */ SySet sElemStack; /* Stack of open-element QName snapshots */ SyBlob sErr; /* Last SAX error message */ sxi32 iErrCode; /* Last SAX error code */ sxu32 nErrLine; /* Line of the last SAX error */ sxu32 nErrCol; /* Column of the last SAX error */ sxi32 iNest; /* Recursive-parse guard */ sxu32 nCurLine; /* SyXMLRawStr.nLine of the current event */ sxi64 iCurByte; /* Byte offset of the current token */ sxu32 nCurCol; /* Column of the current token */ sxi32 nDepth; /* Element nesting depth */ int bEmptyElement; /* TRUE only while dispatching the start event of a self-closing tag; cleared on the end event */ int bError; /* A SAX error was reported */ int bAbort; /* A user handler requested an abort */ sxu32 nMagic; /* Misuse guard */ }; PH7_PRIVATE sxi32 initializeModule(ph7_vm *pVm, ph7_real *ver, SyString *desc); #endif