SgmlParser

The SgmlParser class parses a data stream into a normalized sequence of start tags, end tags, and content. More...

Publicly inherits QObject, StyleSheetReceiver.

Public Methods

SgmlParser( );
voidstyleSheet( StyleSheet* styleSheet );
const QList<Style>&styleStack( );
const QList<STag>&tagStack( );
~SgmlParser( );

Public Slots

voiddata( const char* bytes, int length );
voiddtd( Dtd* dtd );
voidendOfData( );
voidlexerDone( );
voidtoken( Token token, const char* text );

Private Methods

voidcloseTags( int depth );
voidcommit( );
booldoContent( QString text );
booldoEndTag( QString tag, int depth );
booldoEndTagHack( QString tag );
booldoStartTag( STag& tag, int depth );
booletagOptional( int depth );
boolexcluded( QString tag, int depth );
boolfitsModel( QString tag, int depth );
boolincluded( QString tag, int depth );
voidlogStack( );
voidopenTag( STag& tag );
voidrollback( );
boolsatisfied( int depth );
booltryOptional( int depth );

Signals

voidcontent( QString text );
voiddone( );
voiddtdSelected( QString dtdName );
voidendTag( );
voidfwdData( const char* bytes, int length );
voidfwdEndOfData( );
voidstartTag( );

Private Data Members

QString_attrName;
QString_attrValue;
Dtd*_dtd;
QString_dtdName;
QString_dtdType;
bool_endOfData;
QString_leftover;
SgmlLexer*_lexer;
QList<Op>_ops;
QList<State>_stack;
STag_startTag;
StyleSheet*_styleSheet;
QList<Style>_styleStack;
QString_tag;
QList<STag>_tagStack;

Detailed Documentation

The SgmlParser class parses a data stream into a normalized sequence of start tags, end tags, and content.

The SgmlParser converts a stream of SGML tokens into a normailzed stream of start tags, end tags, and content. The stream is normalized because for Every star tag there is a corresponding end tag. This makes the job of rendering the document much easier.

This parser is capable of inserting optional end tags, optional start tags, and even empty elements where needed to insure that the document structure given in the DTD is satisfied. It will even make some pretty good guesses when parsing documents with errors, so that it can continue to parse the rest of the document.

Public Methods Documentation

SgmlParser ( );

Create a new SgmlParser. Create an SgmlLexer to do some of the dirty work.

Public Slots Documentation

void data ( const char* bytes, int length );

Forward the data signals to the SgmlLexer.

void dtd ( Dtd* dtd );

This slot is activated when the DtdManager has finished processing our DTD request. Feed any queued data to the SgmlLexer.

void endOfData ( );

Forward the endOfData signal to the SgmlLexer.

void lexerDone ( );

This slot is activated after the last token has been received. Try to close any open tags on the stack.

void token ( Token token, const char* text );

Process a token from the lexer. Try to parse tokens into start tags, end tags, and content. Then normalize the tag stream with doStartTag() and doEndTag().

Private Methods Documentation

void closeTags ( int depth );

Close off all the tags up to, but not including, the tag at the given stack depth. Just create the necessary operations, but don't apply them yet.

void commit ( );

We've successfully fit the start/end tag into the content model. Now actually emit the start and end tags.

bool doContent ( QString text );

Emit the given content.

bool doEndTag ( QString tag, int depth );

Try to fit the given end tag into the parse tree for the current document instance.

bool doEndTagHack ( QString tag );

This is a kludge to cope with documents that have overlapping start and end tags. For example http://www.troll.no/ ;)

bool doStartTag ( STag& tag, int depth );

Try to fit the given start tag into the parse tree for the current document instance.

bool etagOptional ( int depth );

Returns TRUE if the end tag for the element at the given stack depth is optional.

bool excluded ( QString tag, int depth );

Returns TRUE if the given element is excluded from the content model at the given stack depth.

bool fitsModel ( QString tag, int depth );

Returns TRUE if the given tag can be directly fit into the content model of the element at the given stack depth.

bool included ( QString tag, int depth );

Returns TRUE if the given element is included in the content model at the given stack depth.

void openTag ( STag& tag );

Open a new tag and push it onto the stack. Just create the operations, but don't apply them yet.

void rollback ( );

Back out any changes made to the tag stack while trying to fit in a start or end tag.

bool satisfied ( int depth );

Returns TRUE if the content model at the given stack depth is in an accepting state.

bool tryOptional ( int depth );

See if there is an element with an optional start tag that can be inserted into the content model for the element at the given stack depth. Returns TRUE if successful.

Signals Documentation

void content ( QString text );

This signal is emitted when content is parsed.

void done ( );

This signal is emitted when no more tags or content will be emitted.

void dtdSelected ( QString dtdName );

This signal is emitted to inform the browser that we have settled on a DTD.

void endTag ( );

This signal is emitted when an end tag is parsed.

void fwdData ( const char* bytes, int length );

This signal is used to forward the data signals to the SgmlLexer.

void fwdEndOfData ( );

This signal is used to forward the endOfData signal to the SgmlLexer.

void startTag ( );

This signal is emitted when a start tag is parsed. The tag includes any attributes that were present.


Return to Index.
Automatically generated on Aug 11 23:32