lexor package

To use lexor as a module you should explore in detail the packages provided with lexor. These packages contain many other functions and information which can help you convert your document in the way you desire.

core:The core of lexor defines basic objects such as Document and provides the main objects that define the functions provided in this module.
command:This module is in charge of providing all the available commands to lexor.

In this module we can find useful functions to quickly parse, convert and write files without first creating any of the main lexor objects.

lexor.lexor(src, search=False, **keywords)[source]

Utility function to parse and convert a file or string specified by src. If search is True then it will attemp to search for src in the paths specified by the enviromental variable $LEXORINPUTS. The following are all the valid keywords and its defaults that this function accepts:

  • parser_style: '_'
  • parser_lang: None
  • parser_defaults: None,
  • convert_style: '_',
  • convert_from: None,
  • convert_to: 'html',
  • convert_defaults: None,
  • convert: 'true'

Returns the converted Document object and the log Document containing possible warning or error messages.

lexor.parse(text, lang='xml', style='default')[source]

Parse the text in the language specified by lang and return its Document form and a Document log containing the errors encountered during parsing.

lexor.read(filename, style='default', lang=None)[source]

Read and parse a file. If lang is not specified then the language is assummed from the filename extension. Returns the Document form and a Document log containing the errors encountered during parsing.

lexor.convert(doc, lang=None, style='default')[source]

Convert the Document doc to another language in a given style. If the lang is not specified then the doc is tranformed to the same language as the Document using the default style.

lexor.write(doc, filename=None, mode='w', **options)[source]

Write doc to a file. To write to the standard output use the default parameters, otherwise provide filename. If filename is provided you have the option of especifying the mode: 'w' or 'a'.

You may also provide a file you may have opened yourself in place of filename so that the writer writes to that file, in this case the mode is ignored.

The valid options depends on the language the document specifies. See the DEFAULT values a particular writer style has to obtain the valid options.

lexor.init(**keywords)[source]

Every lexor style needs to call the init function. These are the valid keywords to initialize a style:

  • version: (major, minor, micro, alpha/beta/rc/final, #)
  • lang
  • [to_lang]
  • type
  • description
  • author
  • author_email
  • [url]
  • license
  • path: Must be set to __file__.