A Document parser us used to parse a TextBlock out of a stream.
def __init__(self, src):
Constructs a DocParser from the given source stream.
If in debug mode, prints a loc followed by blk.debug() (blk is expected to be
a text block).
Returns the current line of the buffer, returns None if the source stream has
terminated.
Like getCurLine(), but keeps reading lines until it encounters a line devoid
of whitespace or the until end of the file.
Returns the next line of the stream (following the current line).
'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.
Computes the level of indentation for the given line.
Parses a definition list block.
Parses and executes an "exec" block, reading the output of the executed
command and then parsing it as an NML document.
Parses a literal text block. Literal blocks have no special character
sequences except for the terminator and escape characters.
Create, parse and return the next paragraph.
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.
Parses the next text block.
the block type.
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.
If true, the text block binds tightly (with no interspersed whitespace) to
the text to the left of it.
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.
Parses an unordered list.
Pulls a line from the source stream, takes it from the nextLine
variable if it is not None.
Searches the string target for the first occurrence of the string
terminator. Returns a match object or None.
Returns a match object for the next special character sequence or terminator
(as supplied), whichever comes first.
Returns None if neither is available.
Sets the current line to newCur. Deprecated. Use _harvestBuffer()
Warns the user of things that could be manifestations of errors.
Not entirely sure where this fits in: parses meta-level structures,
recognizes special sequences for unordered lists and definition lists and
paragraphs.
Parse (and return) the entire document from the stream.
_debug(self, loc, blk)
def _debug(self, loc, blk):
_getCurLine(self)
def _getCurLine(self):
_getNextFullLine(self)
def _getNextFullLine(self):
_getNextLine(self)
def _getNextLine(self):
_harvestBuffer(self, rx, replacement)
def _harvestBuffer(self, rx = None, replacement = None):
_levelOfIndent(self, line)
def _levelOfIndent(self, line):
_parseDefinitionList(self, indent)
def _parseDefinitionList(self, indent):
_parseExec(self, txt, term)
def _parseExec(self, txt, term):
_parseLiteral(self, txt, term)
def _parseLiteral(self, txt, term):
_parsePara(self, indent)
def _parsePara(self, indent):
_parsePreformatted(self, type, term)
def _parsePreformatted(self, type, term):
_parsePreformattedLiteral(self, txt, lineTerm, term)
def _parsePreformattedLiteral(self, txt, lineTerm, term = None):
_parseText(self, type, term, tightLeft, indent)
def _parseText(self, type, term, tightLeft = 0, indent = 0):
_parseUnorderedList(self, indent)
def _parseUnorderedList(self, indent):
_pullLine(self)
def _pullLine(self):
_searchForTerminator(self, target, terminator)
def _searchForTerminator(self, target, terminator):
_searchSpecial(self, target, startPos, terminator)
def _searchSpecial(self, target, startPos, terminator = None):
_setCurLine(self, newCur)
def _setCurLine(self, newCur):
_warn(self, msg, block)
def _warn(self, msg, block):
parseAnything(self, block, indent)
def parseAnything(self, block, indent):
parseDoc(self)
def parseDoc(self):