Method Parser.Tabular()->compile()


Method compile

array|mapping compile(string|Stdio.File|Stdio.FILE input)

Description

Compiles the format description language into a compiled structure that can be fed to setformat, fetch, or create.

  • The format description is case sensitive.

  • The format description starts with a single line containing: [Tabular description begin]

  • The format description ends with a single line containing: [Tabular description end]

  • Any lines before the startline are skipped.

  • Any lines after the endline are not consumed.

  • Empty lines are skipped.

  • Comments start after a # or ;.

  • The depth level of a field is indicated by the number of leading spaces or colons at the beginning of the line.

  • The fieldname must not contain any whitespace.

  • An arbitrary number of single character field delimiters can be specified between brackets, e.g. [,;] or [,] would be for CSV.

  • When field delimiters are being used: in case of CSV type delimiters [\t,; ] the standard CSV quoting rules apply, in case other delimiters are used, no quoting is supported and the last field on a line should not specify a delimiter, but should specify a 0 fieldwidth instead.

  • A fixed field width can be specified by a plain decimal integer, a value of 0 indicates a field with arbitrary length that extends till the end of the line.

  • A matching regular expression can be enclosed in "", it has to match the complete field content and uses Regexp.SimpleRegexp syntax.

  • On records the following options are supported:

    mandatory

    This record is required.

    fold

    Fold this record's contents in the enclosing record.

    single

    This record is present at most once.

  • On fields the following options are supported:

    drop

    After reading and matching this field, drop the field content from the resulting mappingstructure.

See also

setformat(), create(), fetch()

Example

Example of the description language:

[Tabular description begin] csv :gtz ::mybankno [,] ::transferdate [,] ::mutatiesoort [,] ::volgnummer [,] ::bankno [,] ::name [,] ::kostenplaats [,] drop ::amount [,] ::afbij [,] ::mutatie [,] ::reference [,] ::valutacode [,] mt940 :messageheader1 mandatory ::exporttime "0000" drop ::CS1 " " drop ::exportday "01" drop ::exportaddress 12 ::exportnumber 5 "[0-9]+" :messageheader3 mandatory fold single ::messagetype "940" drop ::CS1 " " drop ::messagepriority "00" drop :TRN fold ::tag ":20:" drop ::reference "GTZPB|MPBZ|INGEB" :accountid fold ::tag ":25:" drop ::accountno 10 :statementno fold ::tag ":28C:" drop ::settlementno 0 drop :openingbalance mandatory single ::tag ":60F:" drop ::creditdebit 1 ::date 6 ::currency "EUR" ::amount 0 "[0-9]+,[0-9][0-9]" :statements ::statementline mandatory fold single :::tag ":61:" drop :::valuedate 6 :::creditdebit 1 :::amount "[0-9]+,[0-9][0-9]" :::CS1 "N" drop :::transactiontype 3 # 3 for Postbank, 4 for ING :::paymentreference 0 ::informationtoaccountowner fold single :::tag ":86:" drop :::accountno "[0-9]*( |)" :::accountname 0 ::description fold :::description 0 "|[^:].*" :closingbalance mandatory single ::tag ":62[FM]:" drop ::creditdebit 1 ::date 6 ::currency "EUR" ::amount 0 "[0-9]+,[0-9][0-9]" :informationtoaccountowner fold single ::tag ":86:" drop ::debit "D" drop ::debitentries 6 ::credit "C" drop ::creditentries 6 ::debit "D" drop ::debitamount "[0-9]+,[0-9][0-9]" ::credit "C" drop ::creditamount "[0-9]+,[0-9][0-9]" drop ::accountname "(\n[^-:][^\n]*)*" drop :messagetrailer mandatory single ::start "-" ::end "XXX" [Tabular description end]