HaXml-1.25.3: Utilities for manipulating XML documents

Safe HaskellSafe-Inferred




You don't normally need to use this Lex module directly - it is called automatically by the parser. (This interface is only exposed for debugging purposes.)

This is a hand-written lexer for tokenising the text of an XML document so that it is ready for parsing. It attaches position information in (line,column) format to every token. The main entry point is xmlLex. A secondary entry point, xmlReLex, is provided for when the parser needs to stuff a string back onto the front of the text and re-tokenise it (typically when expanding macros).

As one would expect, the lexer is essentially a small finite state machine.


Entry points to the lexer

xmlLex :: String -> String -> [Token] Source

The first argument to xmlLex is the filename (used for source positions, especially in error messages), and the second is the string content of the XML file.

xmlReLex :: Posn -> String -> [Token] Source

xmlReLex is used when the parser expands a macro (PE reference). The expansion of the macro must be re-lexed as if for the first time.

reLexEntityValue :: (String -> Maybe String) -> Posn -> String -> [Token] Source

reLexEntityValue is used solely within parsing an entityvalue. Normally, a PERef is logically separated from its surroundings by whitespace. But in an entityvalue, a PERef can be juxtaposed to an identifier, so the expansion forms a new identifier. Thus the need to rescan the whole text for possible PERefs.

Token types

type Token = (Posn, TokenT) Source

All tokens are paired up with a source position. Lexical errors are passed back as a special TokenT value.

data Section Source