77 lines
3.4 KiB
C
77 lines
3.4 KiB
C
/**
|
|
* @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 <devel@symisc.net>
|
|
* Rafal Kupiec <belliash@codingworkshop.eu.org>
|
|
*/
|
|
#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_TOTAL_HANDLER (PH7_XML_DOCTYPE + 1)
|
|
#define XML_ENGINE_MAGIC 0x851EFC52
|
|
#define IS_INVALID_XML_ENGINE(XML) (XML == 0 || (XML)->nMagic != XML_ENGINE_MAGIC)
|
|
|
|
enum ph7_xml_handler_id {
|
|
PH7_XML_START_TAG = 0, /* Start element */
|
|
PH7_XML_END_TAG, /* End element */
|
|
PH7_XML_CDATA, /* Character data */
|
|
PH7_XML_PI, /* Processing instruction */
|
|
PH7_XML_DEF, /* Default (unused) */
|
|
PH7_XML_UNPED, /* Unparsed entity (unused) */
|
|
PH7_XML_ND, /* Notation declaration (unused) */
|
|
PH7_XML_EER, /* External entity reference (unused) */
|
|
PH7_XML_NS_START, /* Start namespace declaration */
|
|
PH7_XML_NS_END, /* End namespace declaration */
|
|
PH7_XML_DOCTYPE /* DOCTYPE directive */
|
|
};
|
|
|
|
/*
|
|
* 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 aCB[XML_TOTAL_HANDLER]; /* Convenience callbacks by event id */
|
|
ph7_value sParserValue; /* Resource value holding this engine */
|
|
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 element local name */
|
|
ph7_value sNsUri; /* Current element namespace URI */
|
|
ph7_value sPrefix; /* Current element prefix */
|
|
/* Reserved: the public API forwards QName components separately and never
|
|
* concatenates URI + separator + local name, so this value is unused. */
|
|
int ns_sep;
|
|
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
|