mau.parsers package

Submodules

mau.parsers.arguments_parser module

class mau.parsers.arguments_parser.ArgumentsParser[source]

Bases: BaseParser

get_arguments_and_reset()[source]
parse()[source]

Run the parser on the lexed tokens.

pop()[source]

Return the first unnamed argument, removing it from the list. If no arguments are available it returns None.

set_names_and_defaults(positional_names, default_values=None)[source]

Gives names to positional arguments and assigns default values to the ones that have not been initialised.

mau.parsers.base_parser module

class mau.parsers.base_parser.BaseParser[source]

Bases: object

analyse(text)[source]
check_current_token(ttype, tvalue=None, check=None)[source]

Just check the type and value of the current token without advancing the index.

collect(stop_tokens, preserve_escaped_stop_tokens=False)[source]

Collect all tokens until one of the stop_tokens pops up. Escape tokens “" are removed unless preserve_escaped_stop_tokens is set to True.

collect_join(stop_tokens, join_with='', preserve_escaped_stop_tokens=False)[source]

Collect all tokens until one of the stop_tokens pops up and join them in a single string. This works exactly like collect but returns a string of tokens joined with the given characters.

property current_token

Returns the token being parsed. We often need to know which token we are currently parsing, but we might already have parsed all of them, so this convenience method wraps the possible index error.

error(message=None)[source]
force_token(ttype, tvalue=None)[source]

Return the next token and advances the index, but forces the token to have a specific type and optionally a value. If the token doesn’t match the provided values the function raises an ExpectedError

get_token(ttype=None, tvalue=None, check=None)[source]

Return the next token and advances the index. This function returns the next token and then advances the index, and can optionally check its type or value (see _check_token). The token is stored it in self._current_token.

load(text)[source]

Load the given text and run the lexer on it.

parse()[source]

Run the parser on the lexed tokens.

peek_token(ttype=None, tvalue=None, check=None)[source]

Return the next token without advancing the index.

peek_token_is(ttype=None, tvalue=None, check=None)[source]

Peek a token and check it. This works like peek_token, but returns a boolean instead of raising an exception.

put_token(token)[source]
exception mau.parsers.base_parser.ConfigurationError[source]

Bases: ValueError

This is a configuration error.

exception mau.parsers.base_parser.ExpectedError(message=None, context=None)[source]

Bases: ParserError

This exception signals that we were expecting a different token.

exception mau.parsers.base_parser.ParserError(message=None, context=None)[source]

Bases: ValueError

This is a detailed parser error

exception mau.parsers.base_parser.TokenError[source]

Bases: ValueError

This is used by the parser to exit the context.

mau.parsers.base_parser.parser(func)[source]

mau.parsers.main_parser module

exception mau.parsers.main_parser.EngineError[source]

Bases: ValueError

Used to signal that the engine selected for a code block is not known

class mau.parsers.main_parser.MainParser(variables=None)[source]

Bases: BaseParser

parse()[source]

Run the parser on the lexed tokens.

mau.parsers.main_parser.header_anchor(text, level)[source]

Return a sanitised anchor for a header.

mau.parsers.nodes module

class mau.parsers.nodes.BlockNode(blocktype, content, secondary_content, title=None, classes=None, engine=None, preprocessor=None, args=None, kwargs=None)[source]

Bases: Node

A block.

This node contains a generic block.

Parameters
  • blocktype – the type of this block

  • content – content of the block

  • secondary_content – secondary content of this block

  • title – title of this block

  • classes – a comma-separated list of classes

  • engine – the engine used to render this block

  • preprocessor – the preprocessor used for this block

  • args – unnamed arguments

  • kwargs – named arguments

asdict()[source]
node_type = 'block'
class mau.parsers.nodes.ClassNode(classes, content)[source]

Bases: Node

Text with one or more class.

This node contains text that has been assigned one or more classes.

value

the text contained in the node

classes

the classes assigned to the text

Type

list

asdict()[source]
node_type = 'class'
class mau.parsers.nodes.CommandNode(name, args=None, kwargs=None)[source]

Bases: Node

A Mau command.

This represents a command issued in a Mau document.

Parameters
  • name – the name of the command

  • args – unnamed arguments

  • kwargs – named arguments

asdict()[source]
node_type = 'command'
class mau.parsers.nodes.ContainerNode(content)[source]

Bases: Node

asdict()[source]
node_type = 'container_node'
class mau.parsers.nodes.ContentImageNode(uri, alt_text, classes=None, title=None, kwargs=None)[source]

Bases: Node

An image included in the page.

This represents an image included in the page.

Parameters
  • uri – the URI of the image

  • alt_text – alternative text if the image is not available

  • classes (list) – list of classes added to the image

  • title – caption of the image

  • kwargs – named arguments

asdict()[source]
node_type = 'content_image'
class mau.parsers.nodes.ContentNode(uri, title=None, args=None, kwargs=None)[source]

Bases: Node

Content included in the page.

This represents generic content included in the page.

Parameters
  • uri – the URI of the image

  • title – caption of the image

  • args – unnamed arguments

  • kwargs – named arguments

asdict()[source]
node_type = 'content'
class mau.parsers.nodes.DocumentNode(content)[source]

Bases: ContainerNode

A document.

This node represents the full document.

Parameters

content – the content of the document

node_type = 'document'
class mau.parsers.nodes.FootnoteDefNode(number, refanchor, defanchor, content)[source]

Bases: FootnoteNode

node_type = 'footnote_def'
class mau.parsers.nodes.FootnoteNode(number, refanchor, defanchor, content)[source]

Bases: Node

Footnote definition/reference.

This node contains a footnote definition or reference.

number

number of this footnote

refanchor

anchor ID of the reference

defanchor

anchor ID of the definition

asdict()[source]
node_type = 'footnote'
class mau.parsers.nodes.FootnoteRefNode(number, refanchor, defanchor, content)[source]

Bases: FootnoteNode

node_type = 'footnote_ref'
class mau.parsers.nodes.FootnotesNode(entries=None)[source]

Bases: Node

A list of footnote definitions.

This node contains the footnote definitions.

Parameters

entries – a list of FootnoteDefNode objects

asdict()[source]
node_type = 'footnotes'
class mau.parsers.nodes.HeaderNode(value, level, anchor, kwargs=None)[source]

Bases: Node

A header.

This node represents a header.

Parameters
  • value – the text in the header

  • level – the level of the header (1 is most important)

  • anchor – the ID anchor of this node

  • kwargs – named arguments

asdict()[source]
node_type = 'header'
class mau.parsers.nodes.HorizontalRuleNode[source]

Bases: Node

A horizontal rule.

asdict()[source]
class mau.parsers.nodes.ImageNode(uri, alt_text=None, width=None, height=None)[source]

Bases: Node

Inline image.

This node contains an inline image.

uri

the URI of the image

alt_text

alternative text if the image is not available

width

width of the image

height

height fo the image

asdict()[source]
node_type = 'image'
class mau.parsers.nodes.LinkNode(target, text)[source]

Bases: Node

Link macro.

This node contains a link.

target

the target of the link

text

the text of the link

asdict()[source]
node_type = 'link'
class mau.parsers.nodes.ListItemNode(level, content)[source]

Bases: Node

An entry in a list.

This node contains an entry of an ordered or unordered list.

Parameters
  • level – the level of depth of this entry in the list

  • content – the content of the entry

asdict()[source]
node_type = 'list_item'
class mau.parsers.nodes.ListNode(ordered, items, main_node=False)[source]

Bases: Node

A list.

This node contains an ordered or unordered list.

Parameters
  • ordered (bool) – whether the list is ordered or not

  • items (list) – entries contained in this entry

  • main_node (bool) – whether this is the main node of the list

asdict()[source]
node_type = 'list'
class mau.parsers.nodes.MacroNode(name, args=None, kwargs=None)[source]

Bases: Node

Base node for macros.

This node contains a macro, with a name and arguments.

value

the name of the macro

arguments

the string of arguments

asdict()[source]
node_type = 'macro'
class mau.parsers.nodes.Node[source]

Bases: object

asdict()[source]
node_type = 'node'
class mau.parsers.nodes.ParagraphNode(content, args=None, kwargs=None)[source]

Bases: Node

A paragraph.

This is a wrapper around a single SentenceNode. This node is not recursive.

Parameters
  • content (SentenceNode) – the text of the paragraph

  • args – unnamed arguments

  • kwargs – named arguments

asdict()[source]
node_type = 'paragraph'
class mau.parsers.nodes.SentenceNode(content)[source]

Bases: ContainerNode

A recursive container node.

This node represents the content of a paragraph, but it is recursive, while ParagraphNode is not. It can contain other SentenceNode objects, or other types of nodes like TextNode, StyleNode or MacroNode.

content

a list of nodes contained in this node

Type

list

node_type = 'sentence'
class mau.parsers.nodes.SourceNode(language, callouts, highlights, delimiter, code, title=None, kwargs=None)[source]

Bases: Node

A block of verbatim text or source code.

This node contains verbatim text or source code.

Parameters
  • language – the language of the code contained in this block

  • callouts – callouts for this source code {“markers”: [(linenum, name)], “contents”: {name:text}}

  • highlights – list of lines that have to be highlighted

  • delimiter – callouts delimiter

  • code – content of the block

  • title – title of this block

  • kwargs – named arguments

asdict()[source]
node_type = 'source'
class mau.parsers.nodes.StyleNode(value, content)[source]

Bases: WrapperNode

Describes the style applied to a node.

It contains a single node that is styled with the given value. Currently Mau supports 2 styles represented by * and _ but this node is agnostic.

value

the name of the style

Type

str

content

a single node

Type

SentenceNode

node_type = 'style'
class mau.parsers.nodes.TextNode(value)[source]

Bases: ValueNode

This contains plain text and is created as a collation of multiple WordNode objects

value

the text contained in the node

node_type = 'text'
class mau.parsers.nodes.TocEntryNode(header_node, children=None)[source]

Bases: Node

An entry of the Table of Contents.

This node contains an entry of the Table of Contents.

Parameters
  • level – level of this entry (level of the header)

  • text – the text of the entry

  • anchor – the ID of the header

  • children – child entries

asdict()[source]
node_type = 'toc_entry'
class mau.parsers.nodes.TocNode(entries=None)[source]

Bases: Node

A Table of Contents.

This node contains the entries of the Table of Contents.

Parameters

entries – a list of TocEntryNode objects

asdict()[source]
node_type = 'toc'
class mau.parsers.nodes.ValueNode(value)[source]

Bases: Node

asdict()[source]
node_type = 'value_node'
class mau.parsers.nodes.VerbatimNode(value)[source]

Bases: ValueNode

Verbatim text.

This node contains verbatim text.

value

the text contained in the node

node_type = 'verbatim'
class mau.parsers.nodes.WordNode(value)[source]

Bases: ValueNode

This is a single word, it’s used internally and eventually packed together with others into a TextNode

node_type = 'word'
class mau.parsers.nodes.WrapperNode(value, content)[source]

Bases: ValueNode

asdict()[source]
node_type = 'wrapper_node'
mau.parsers.nodes.extract_tags_from_kwargs(kwargs)[source]

mau.parsers.preprocess_variables_parser module

exception mau.parsers.preprocess_variables_parser.PreprocessError[source]

Bases: ValueError

class mau.parsers.preprocess_variables_parser.PreprocessVariablesParser(variables=None)[source]

Bases: BaseParser

parse()[source]

Run the parser on the lexed tokens.

mau.parsers.text_parser module

class mau.parsers.text_parser.TextParser(footnotes_start_with=1, v1_backward_compatibility=False)[source]

Bases: BaseParser

parse()[source]

Run the parser on the lexed tokens.

parse_class()[source]

Parse a class in the form [class]#content#.

parse_escape()[source]

Parse an escaped element.

parse_macro()[source]
parse_macro_class()[source]

Parse a class macro in the form [class](text, “class1,class2,…”).

parse_macro_footnote(arguments)[source]

Parse a footnote macro in the form [footnote](content).

parse_macro_image()[source]

Parse an inline image macro in the form [image](uri, alt_text, width, height).

Parse a link macro in the form [link](target, text).

parse_macro_mailto()[source]

Parse a mailto macro in the form [mailto](email).

parse_sentence(stop_tokens=None)[source]

Parse a sentence, which is made of multiple elements identified by parse_styled_text, until the EOF, the EOL, or a specific set of tokens passed as argument.

parse_style()[source]

Parse a sentence surrounded by style markers.

parse_styled_text(stop_tokens=None)[source]

Parse multiple possible elements: escapes, classes, macros, verbatim, styles, links, words. This is a helper for the function parse_sentence that takes into account all possible elements of syntax, stopping if the token is among the listed ones.

parse_verbatim()[source]

Parse text in verbatim.

parse_word()[source]

Parse a single word.

set_names_and_defaults(positional_names, default_values=None)[source]

A wrapper for the method set_names_and_defaults() of ArgumentParser that raises a ParserError with a broader context. The argument parser is applied on the arguments only, so the error reporting is limited to that string, while the TextParser has knowledge of the whole line.

mau.parsers.text_parser.footnote_anchors(content)[source]

Return the id of the reference and the id of the definition.

Module contents