Module pl.sip

Simple Input Patterns (SIP).

Functions

compile (spec, options) convert a SIP pattern into a matching function.
create_pattern (spec, options, fieldnames, fieldtypes) convert a SIP pattern into the equivalent Lua regular expression.
fields (spec, f) given a pattern and a file object, return an iterator over the results
match (spec, line, res, options) match a SIP pattern against a string, returning results in a table.
pattern (spec, fun) register a match which will be used in the read function.
read (f) enter a loop which applies all registered matches to the input file.


Functions

compile (spec, options)
convert a SIP pattern into a matching function. The returned function takes two arguments, the line and an empty table. If the line matched the pattern, then this function return true and the table is filled with field-value pairs.

Parameters:

  • spec: a SIP pattern
  • options: optional table; {anywhere=true} will stop pattern anchoring at start

Return value:

    a function if successful, or nil,
create_pattern (spec, options, fieldnames, fieldtypes)
convert a SIP pattern into the equivalent Lua regular expression.

Parameters:

  • spec: a SIP pattern
  • options:
  • fieldnames: an optional table which is to be filled with fieldnames
  • fieldtypes: an optional table which maps the names to their types
fields (spec, f)
given a pattern and a file object, return an iterator over the results

Parameters:

  • spec: a SIP pattern
  • f: a file - use standard input if not specified.
match (spec, line, res, options)
match a SIP pattern against a string, returning results in a table.

Parameters:

  • spec: a SIP pattern
  • line: a string
  • res: a table to receive values
  • options: (optional) option table
pattern (spec, fun)
register a match which will be used in the read function.

Parameters:

  • spec: a SIP pattern
  • fun: a function to be called with the results of the match

See also:

read (f)
enter a loop which applies all registered matches to the input file.

Parameters:

  • f: a file object; if nil, then io.stdin is assumed.

Valid XHTML 1.0!