plainbox.impl.parsers – generic parser interface

This module offers high-level API for parsing text into hierarchical data structures, in particular, JSON. Parsers like this can be used to create abstract syntax trees of compatible inputs. For convenience and scriptability any parser is expected to be able to dump its AST as JSON.

class plainbox.impl.parsers.IParser[source]

Bases: object

Abstract interface for parsers.

The interface is meant to be suitable for the implementation of the plainbox dev parse command. It offers a simple API for parsing strings and getting JSON in result.

name

name of the parser

parse_text_to_ast(text)[source]

Parse the specified text and return a parser-specific native Abstract Syntax Tree that represents the input.

Any exception gets logged and causes None to be returned.

parse_text_to_json(text)[source]

Parse the specified text and return a JSON string representing the result.

Returns:None in case of parse error
Returns:string representing JSON version of the parsed AST
summary

one-line description of the parser

class plainbox.impl.parsers.ParserPlugIn(name: str, obj: object, load_time: float = 0, wrap_time: float = 0)[source]

Bases: plainbox.impl.parsers.IParser, plainbox.impl.secure.plugins.PlugIn

PlugIn wrapping a parser function.

Useful for wrapping checkbox parser functions.

name

name of the parser

parse_text_to_ast(text)[source]

Parse the specified text and return a parser-specific native Abstract Syntax Tree that represents the input.

Any exception gets logged and causes None to be returned.

parse_text_to_json(text)[source]

Parse the specified text and return a JSON string representing the result.

Returns:None in case of parse error
Returns:string representing JSON version of the parsed AST
parser_fn

real parser function

plugin_load_time

time, in fractional seconds, that was needed to load the plugin

plugin_name

plugin name, arbitrary string

plugin_object

plugin object, arbitrary object

plugin_wrap_time

time, in fractional seconds, that was needed to wrap the plugin

summary

one-line description of the parser

This value is computed from the docstring of the wrapped function. In fact, it is the fist line of the docstring.

comments powered by Disqus