Module pl.sip

Simple Input Patterns (SIP). SIP patterns start with '$', then a one-letter type, and then an optional variable in curly braces.

 Type    Meaning v         variable, or identifier. i          possibly signed integer f          floating-point number r          'rest of line' q         quoted string (either ' or ") p         a path name (         anything inside (...) [         anything inside [...] {         anything inside {...} <         anything inside <...> [---standard patterns-------------------------] S         non-space d         digits etc  Example: sip.match('($q{first},$q{second})','("john","smith")',res) result is: true 'res' is: {second='smith',first='john'} 

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.
match_at_start (spec, line, res) match a SIP pattern against the start of a string.
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.

Parameters:

  • spec: a SIP pattern
  • line: a string
  • res: a table to receive values
  • options: (optional) option table

Return value:

    true or false
match_at_start (spec, line, res)
match a SIP pattern against the start of a string.

Parameters:

  • spec: a SIP pattern
  • line: a string
  • res: a table to receive values

Return value:

    true or false
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!