internal package
Foswiki::Tables::Parser
internal package
Foswiki::Parsers::Table
Re-usable sequential access event-based parser for TML tables.
A sequential access event-based parser works by parsing content
and calling back to "event listeners" when syntactic constructs
are recognised.
StaticMethod
parse( $text, \&dispatch )
- $text - text to parse
- \&dispatch($event_name, ...) - event dispatcher (function)
This is a sequential event-based parser. As each line in the text is read,
it is analysed and if it meets the criteria for an event, it is fired.
In keeping with the line-oriented nature of TML, the parser works on
a line-by-line basis.
<verbatim>
and
<literal>
blocks are
respected.
Events are fired by a call to $dispatch( ... ). The following events are
fired:
open_table($line)
Opens a new table with the given line. Note that this same line will be passed
to new_row as well.
close_table()
Close the currently open table.
line($line)
Called for any line that is not part of a table and is not caught by
an
early_line
event handler returning true.
open_tr($before)
Called on each row in an open table (including the header and footer rows)
-
$before
- leading content (spaces and |)
th($pre, $data, $post)
Called to create a table header cell.
-
$pre
- preamble (spaces)
-
$data
- real content
-
$post
- postamble (spaces)
td($pre, $data, $post)
Called to create a table cell.
-
$pre
- preamble (spaces)
-
$data
- real content
-
$post
- postamble (spaces)
close_tr($after)
Called to close an open table row.
-
$after
- trailing content (| and spaces)
Called at end of all input.
An additional event is provided for those seeking to perform special
processing of certain lines, including rewriting them.
early_line($line) -> $integer
Mainly provided for handling lines other than TML content that may
interact with tables during a static parse e.g. special macros such
as %EDITTABLE.
The first result should be 0 to continue normal processing of the line,
1 to skip further processing of this line.
Note that
early_line
operates on the internal representation of the
line in the parser. Certain constructs, such as verbatim blocks, are
specially marked in this content.
early_line
can be used to rewrite
the line in place, but only with
great care. Caveat emptor.
The
early_line
fired for all lines that may be part of
a table (i.e. not verbatim or literal lines).
StaticMethod
split_cell($cell) → ($pre, $main, $post, $ish)
Given a table cell datum with significant leading and trailing space,
split the cell data into pre-, main-, and post- text, and set $ish
if it is a header cell.