Abstract
Describes Python classes that assist in scanning and reporting errors on data read from a stream.
This publication is available in Web form and also as a PDF document.
Please forward any comments to tcc-doc@nmt.edu.
Table of Contents
Log objectScan class: Managing progress through a streamlogscan.pyclass LogLog.addLogFile(): Log to another fileLog.setPrefix(): Change the prefixLog.msgKind(): Send a message of a given
kindLog.error(): Send an error messageLog.warning(): Send a warning messageLog.message(): General message, not
countedLog.write(): Send a message to all
current outputsLog.fatal(): Write a message and stopLog.count(): How many messages of a given
kind?logtest: Test driver for LogScan classScan.__init__(): The constructorScan.__findInput(): Find the input
streamScan.close(): Close the streamScan.atEndLine(): Are we at the end of
the current line?Scan.nextLine(): Advance to the next
lineScan.error(): Issue an error messageScan.msgKind(): General message writerScan.move(): Advance the scan positionScan.tab(): Move to a specific
positionScan.__effPos(): Calculate an effective
positionScan.isPos(): Is the current position a given
value?Scan.find(): Search for a constant
stringScan.upToRe(): Search for a regular
expression matchScan.deblankFile(): Skip whitespace over
multiple linesScan.deblankLine(): Skip whitespace on the
current lineScan.match(): Match a specific stringScan.matchArb(): Case-insensitive
matchScan.tabMatch(): Advance if there is a
matchScan.tabMatchArb(): Case-insensitive match and
moveScan.reMatch(): Match a regular
expressionScan.tabReMatch(): Match and advance the
positionScan.integer(): Parse an integerScan.fixed(): Parse a float
constantScan.flatInt(): Parse a fixed-size integer
fieldSingleton class: A classic design patternSingletonThis document describes three related Python classes that the author has found useful for many kinds of input processing:
The singleton Log object is used to centralize the
processing of errors and error messages.
The Scan class is used to coordinate the scanning of
an input stream with the generation of error messages
related to that stream.
In the first sections of this document, we will describe the interfaces to these classes. Later sections will walk you through the actual code.