Summary
As indicated in ELTN-C, we intend to keep the Lua API for ELTN as simple as possible. We therefore will implement only the following functions:
- eltn.parse
- eltn.parse_file
- eltn.emit
- eltn.error
Documentation
eltn.parse
eltn.parse(eltn_string) => eltn_table | nil, error
Converts a string of ELTN text into (usually) nested tables. If the ELTN text is malformed or invalid, returns nil with an error string.
eltn.parse_file
eltn.parse_file(filename) => eltn_table | nil, error
Opens a file of ELTN text and parses it into (usually) nested tables. If the ELTN text is malformed or invalid, returns nil with an error string.
eltn.emit
eltn.emit(eltn_table [, options]) => eltn_string | nil, error
Accepts a structure of nested tables and converts it into a string of ELTN text. If the table structure cannot be converted, returns nil and an error string.
options is a table with the following keys:
- eltn.OPT_PRETTY – (
true|false) whether tin include whitespace. - eltn.OPT_INDENT – (
0 ... 8) the number of spaces to indent. - eltn.OPT_VARS – (
true|false) whether to parse the topmost table as a list of variables.
eltn.error
eltn.error(error) => error_table | *error*
Parses an error string into a table. The table may contain the following fields:
- line – the line where the error occurred.
- col – the column where the error occurred.
- errno – a numerical error code.
- description – a description of the error (in English).
If the function cannot parse the error string, it will return the original string.
Implementation Details
Parsing
The parser will use the lpeg or lpeglabel libraries to parse the code and construct a structure of tables.
Emitting
The emitter uses ordinary recursive code.
The emitter is not a general Lua table pretty-printer. In particular, if the emitter encounters the same table twice, or finds a key that is not a string, number, boolean, or printable userdata,it will halt with an error.