Welcome | Get started | Dive into Lino | Contribute | Topics | Reference | More

lino.modlib.memo.parser

See introduction in memo : The memo parser.

TODO:

  • the auto-completer might insert the full text into the editor after the pattern. The user can then decide whether to leave it or not.

  • The memo commands might also be defined as suggesters with a trigger of type "[ticket ". Note that in that case we need to add a new attribute "suffix", which would be empty for # and @ but "]" for memo commands.

Functions

split_name_rest(s)

Classes

Parser(**context)

The memo parser.

Suggester(trigger, data, fldname[, ...])

Holds the configuration for the behaviour of a given "trigger".

class lino.modlib.memo.parser.Suggester(trigger, data, fldname, formatter=<class 'str'>, value=<function Suggester.<lambda>>, getter=None)

Bases: object

Holds the configuration for the behaviour of a given "trigger".

Every value of Parser.suggesters is an instance of this.

class lino.modlib.memo.parser.Parser(**context)

Bases: object

The memo parser.

add_suggester(*args, **kwargs)

Add a Suggester (see there for args and kwargs).

register_command(cmdname, func: Callable[[Any, str, str, dict], None])

Register a memo command identified by the given text cmd.

func is the command handler. It must be a callable that will be called with two positional arguments ar and params.

register_django_model(name, model, cmd=None)

Register the given string name as command for referring to database rows of the given Django database model model.

Optional keyword arguments are

  • cmd the command handler used by parse()

get_referred_objects(text)

Yield all database objects referred in the given text using a suggester.

parse(src, ar=None, context=None, mentions=None)

Parse the given string src, replacing memo commands by their result.

ar is the action request asking to parse. User permissions and front-end renderer of this request apply.

context is a dict of variables to make available when parsing expressions in safe mode.

If mentions is specified, it should be a set to collect mentioned database objects.