DocParser

A Document parser us used to parse a TextBlock out of a stream.

Methods

__init__(self, src)

   def __init__(self, src):

Constructs a DocParser from the given source stream.

_debug(self, loc, blk)

   def _debug(self, loc, blk):

If in debug mode, prints a loc followed by blk.debug() (blk is expected to be a text block).

_getCurLine(self)

   def _getCurLine(self):

Returns the current line of the buffer, returns None if the source stream has terminated.

_getNextFullLine(self)

   def _getNextFullLine(self):

Like getCurLine(), but keeps reading lines until it encounters a line devoid of whitespace or the until end of the file.

_getNextLine(self)

   def _getNextLine(self):

Returns the next line of the stream (following the current line).

_harvestBuffer(self, rx, replacement)

   def _harvestBuffer(self, rx = None, replacement = None):

'Harvests' the entire buffer or up till the regular expression if one is supplied.

If no regular expression is given, returns the entire buffer and replaces it with an empty string.

If a regular expression is provided, returns up to the beginning of the regular expression and truncates up to the end of the regular expression. In this mode of operation, the buffer is never left empty, because the parser expects it to contain the remainder of the current line. If replacement is provided, it is appended to the end of the value to be returned.

_levelOfIndent(self, line)

   def _levelOfIndent(self, line):

Computes the level of indentation for the given line.

_parseDefinitionList(self, indent)

   def _parseDefinitionList(self, indent):

Parses a definition list block.

_parseExec(self, txt, term)

   def _parseExec(self, txt, term):

Parses and executes an "exec" block, reading the output of the executed command and then parsing it as an NML document.

_parseLiteral(self, txt, term)

   def _parseLiteral(self, txt, term):

Parses a literal text block. Literal blocks have no special character sequences except for the terminator and escape characters.

_parsePara(self, indent)

   def _parsePara(self, indent):

Create, parse and return the next paragraph.

_parsePreformatted(self, type, term)

   def _parsePreformatted(self, type, term):

_parsePreformattedLiteral(self, txt, lineTerm, term)

   def _parsePreformattedLiteral(self, txt, lineTerm, term = None):

Preformatted literals are basically just blocks of text that are interred by the block as a single string. The only characters that are special are the terminator and the necessary escape characters (<terminator> and \).

For a line terminated preformatted literal, lineTerm must contain a regular expression that matches the entire contents of the line, excluding trailing and leading whitespace.

_parseText(self, type, term, tightLeft, indent)

   def _parseText(self, type, term, tightLeft = 0, indent = 0):

Parses the next text block.

type

the block type.

term

the terminator string. If this value is None, the text block returns on an empty (all whitepsace) line or a line matching one of the kinds of line that starts a new block.

tightLeft

If true, the text block binds tightly (with no interspersed whitespace) to the text to the left of it.

indent

If this is not zero, it represent the level of indentation that the text block must maintain. If a line is encountered that is below that level of indentation, block processing is terminated.

_parseUnorderedList(self, indent)

   def _parseUnorderedList(self, indent):

Parses an unordered list.

_pullLine(self)

   def _pullLine(self):

Pulls a line from the source stream, takes it from the nextLine variable if it is not None.

_searchForTerminator(self, target, terminator)

   def _searchForTerminator(self, target, terminator):

Searches the string target for the first occurrence of the string terminator. Returns a match object or None.

_searchSpecial(self, target, startPos, terminator)

   def _searchSpecial(self, target, startPos, terminator = None):

Returns a match object for the next special character sequence or terminator (as supplied), whichever comes first.

Returns None if neither is available.

_setCurLine(self, newCur)

   def _setCurLine(self, newCur):

Sets the current line to newCur. Deprecated. Use _harvestBuffer()

_warn(self, msg, block)

   def _warn(self, msg, block):

Warns the user of things that could be manifestations of errors.

parseAnything(self, block, indent)

   def parseAnything(self, block, indent):

Not entirely sure where this fits in: parses meta-level structures, recognizes special sequences for unordered lists and definition lists and paragraphs.

parseDoc(self)

   def parseDoc(self):

Parse (and return) the entire document from the stream.