The main quickly module
The quickly module.
On first import, our own language definitions are added to the parce registry.
- find(name=None, *, filename=None, mimetype=None, contents=None)[source]
Find a root lexicon, either by language name, or by filename, mimetype and/or contents.
If you specify a name, tries to find the language with that name, ignoring the other arguments.
If you don’t specify a name, but instead one or more of the other (keyword) arguments, tries to find the language based on filename, mimetype or contents.
If a language is found, returns the root lexicon. If no language could be found, None is returned (which can also be used as root lexicon, resulting in an empty token tree).
Examples:
>>> import parce >>> parce.find("xml") Xml.root >>> parce.find(contents='{"key": 123;}') Json.root >>> parce.find(filename="style.css") Css.root
This function uses the
registry
module and by default it finds all bundled languages. See the module’s documentation to find out how to add your own languages to a registry.
- load(filename, lexicon=True, encoding=None, errors=None, newline=None)[source]
Convenience function to read text from
filename
and return aparce.Document
.If
lexicon
is True, the lexicon will be guessed based on filename and contents. If it is a string name, its name is looked up in the registry; otherwise the lexicon is used directly.The
encoding
, if specified, is used to read the file; otherwise the encoding is autodetected. Theerrors
andnewline
arguments will be passed to Python’sopen()
function. RaisesOSError
if the file can’t be read.
- version_string
The version as a string.