File: nxml-rap.el.html

This uses xmltok.el to do XML parsing. The fundamental problem is how to handle changes. We don't want to maintain a complete parse tree. We also don't want to reparse from the start of the document on every keystroke. However, it is not possible in general to parse an XML document correctly starting at a random point in the middle. The main problems are comments, CDATA sections and processing instructions: these can all contain things that are indistinguishable from elements. Literals in the prolog are also a problem. Attribute value literals are not a problem because attribute value literals cannot contain less-than signs.

Our strategy is to keep track of just the problematic things. Specifically, we keep track of all comments, CDATA sections and processing instructions in the instance. We do this by marking the first character of these with the generic string syntax by setting a 'syntax-table' text property in sgml-syntax-propertize.

Thus to parse some random point in the file we first ensure that we have scanned up to that point. Then we search backwards for a <. Then we check whether the < has the generic string syntax. If it does we go backwards to first character of the generic string (this character must be a <). Then we start parsing forward from the < we have found.

The prolog has to be parsed specially, so we also keep track of the end of the prolog in nxml-prolog-end. The prolog is reparsed on every change to the prolog. This won't work well if people try to edit huge internal subsets. Hopefully that will be rare.

We rely on the syntax-propertize-function machinery to keep track of the changes in the buffer. Fontification also relies on correct syntax-table properties. This means that scanning for these constructs had better be quick. Fortunately it is. Firstly, the typical proportion of comments, CDATA sections and processing instructions is small relative to other things. Secondly, to scan we just search for the regexp <[!?].

Defined variables (1)

nxml-prolog-endInteger giving position following end of the prolog.

Defined functions (10)

nxml-get-inside(POS)
nxml-inside-end(POS)
nxml-inside-start(POS)
nxml-move-outside-backwards()
nxml-move-tag-backwards(BOUND)
nxml-scan-element-backward(FROM &optional UP BOUND)
nxml-scan-element-forward(FROM &optional UP)
nxml-scan-error(&rest ARGS)
nxml-token-after()
nxml-token-before()

Defined faces (0)