Previous section To contents Next section

14.24 Parser.SGML

CLASS
Parser.SGML

DESCRIPTION
This is a handy simple parser of SGML-like syntax like HTML. It doesn't do anything advanced, but finding the corresponding end-tags.

It's used like this:

array res=Parser.SGML()->feed(string)->finish()->result();

The resulting structure is an array of atoms, where the atom can be a string or a tag. A tag contains a similar array, as data.

Example: A string "<gat>&nbsp;<gurka>&nbsp;</gurka>&nbsp;<banan>&nbsp;<kiwi>&nbsp;</gat>" results in

({
tag "gat" object with data:
({
tag "gurka" object with data:
({
" "
})
tag "banan" object with data:
({
" "
tag "kiwi" object with data:
({
" "
})
})
})
})

ie, simple "tags" (not containers) are not detected, but containers are ended implicitely by a surrounding container _with_ an end tag.

The 'tag' is an object with the following variables:

string name;           - name of tag
mapping args;          - argument to tag
int line,char,column;  - position of tag
string file;           - filename (see create)
array(SGMLatom) data;  - contained data

METHOD
Parser.SGML.create

SYNTAX
void create()
void create(string filename)

DESCRIPTION
This object is created with this filename. It's passed to all created tags, for debug and trace purposes.

NOTE
No, it doesn't read the file itself. See feed.

METHOD
Parser.SGML.result,
Parser.SGML.finish,
Parser.SGML.feed

SYNTAX
object feed(string s)
array finish()
array result(string s)

DESCRIPTION
Feed new data to the object, or finish the stream. No result can be used until finish() is called.

Both finish() and result() returns the computed data.

feed() returns the called object.


Previous section To contents Next section