mau.parsers package¶
Submodules¶
mau.parsers.arguments_parser module¶
- class mau.parsers.arguments_parser.ArgumentsParser[source]¶
Bases:
BaseParser
mau.parsers.base_parser module¶
- class mau.parsers.base_parser.BaseParser[source]¶
Bases:
object- 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.
- 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.
- peek_token(ttype=None, tvalue=None, check=None)[source]¶
Return the next token without advancing the index.
- exception mau.parsers.base_parser.ConfigurationError[source]¶
Bases:
ValueErrorThis is a configuration error.
- exception mau.parsers.base_parser.ExpectedError(message=None, context=None)[source]¶
Bases:
ParserErrorThis exception signals that we were expecting a different token.
- exception mau.parsers.base_parser.ParserError(message=None, context=None)[source]¶
Bases:
ValueErrorThis is a detailed parser error
- exception mau.parsers.base_parser.TokenError[source]¶
Bases:
ValueErrorThis is used by the parser to exit the context.
mau.parsers.main_parser module¶
- exception mau.parsers.main_parser.EngineError[source]¶
Bases:
ValueErrorUsed to signal that the engine selected for a code block is not known
- class mau.parsers.main_parser.MainParser(variables=None)[source]¶
Bases:
BaseParser
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:
NodeA 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
- node_type = 'block'¶
- class mau.parsers.nodes.ClassNode(classes, content)[source]¶
Bases:
NodeText with one or more class.
This node contains text that has been assigned one or more classes.
- value¶
the text contained in the node
- node_type = 'class'¶
- class mau.parsers.nodes.CommandNode(name, args=None, kwargs=None)[source]¶
Bases:
NodeA Mau command.
This represents a command issued in a Mau document.
- Parameters
name – the name of the command
args – unnamed arguments
kwargs – named arguments
- node_type = 'command'¶
- class mau.parsers.nodes.ContentImageNode(uri, alt_text, classes=None, title=None, kwargs=None)[source]¶
Bases:
NodeAn 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 imagetitle – caption of the image
kwargs – named arguments
- node_type = 'content_image'¶
- class mau.parsers.nodes.ContentNode(uri, title=None, args=None, kwargs=None)[source]¶
Bases:
NodeContent 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
- node_type = 'content'¶
- class mau.parsers.nodes.DocumentNode(content)[source]¶
Bases:
ContainerNodeA 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:
NodeFootnote 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
- 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:
NodeA list of footnote definitions.
This node contains the footnote definitions.
- Parameters
entries – a list of FootnoteDefNode objects
- node_type = 'footnotes'¶
- class mau.parsers.nodes.HeaderNode(value, level, anchor, kwargs=None)[source]¶
Bases:
NodeA 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
- node_type = 'header'¶
- class mau.parsers.nodes.ImageNode(uri, alt_text=None, width=None, height=None)[source]¶
Bases:
NodeInline 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
- node_type = 'image'¶
- class mau.parsers.nodes.LinkNode(target, text)[source]¶
Bases:
NodeLink macro.
This node contains a link.
- target¶
the target of the link
- text¶
the text of the link
- node_type = 'link'¶
- class mau.parsers.nodes.ListItemNode(level, content)[source]¶
Bases:
NodeAn 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
- node_type = 'list_item'¶
- class mau.parsers.nodes.ListNode(ordered, items, main_node=False)[source]¶
Bases:
NodeA list.
This node contains an ordered or unordered list.
- Parameters
- node_type = 'list'¶
- class mau.parsers.nodes.MacroNode(name, args=None, kwargs=None)[source]¶
Bases:
NodeBase node for macros.
This node contains a macro, with a name and arguments.
- value¶
the name of the macro
- arguments¶
the string of arguments
- node_type = 'macro'¶
- class mau.parsers.nodes.ParagraphNode(content, args=None, kwargs=None)[source]¶
Bases:
NodeA paragraph.
This is a wrapper around a single
SentenceNode. This node is not recursive.- Parameters
content (
SentenceNode) – the text of the paragraphargs – unnamed arguments
kwargs – named arguments
- node_type = 'paragraph'¶
- class mau.parsers.nodes.SentenceNode(content)[source]¶
Bases:
ContainerNodeA recursive container node.
This node represents the content of a paragraph, but it is recursive, while
ParagraphNodeis not. It can contain otherSentenceNodeobjects, or other types of nodes likeTextNode,StyleNodeorMacroNode.- node_type = 'sentence'¶
- class mau.parsers.nodes.SourceNode(language, callouts, highlights, delimiter, code, title=None, kwargs=None)[source]¶
Bases:
NodeA 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
- node_type = 'source'¶
- class mau.parsers.nodes.StyleNode(value, content)[source]¶
Bases:
WrapperNodeDescribes 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.
- content¶
a single node
- Type
- node_type = 'style'¶
- class mau.parsers.nodes.TextNode(value)[source]¶
Bases:
ValueNodeThis 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:
NodeAn 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
- node_type = 'toc_entry'¶
- class mau.parsers.nodes.TocNode(entries=None)[source]¶
Bases:
NodeA Table of Contents.
This node contains the entries of the Table of Contents.
- Parameters
entries – a list of TocEntryNode objects
- node_type = 'toc'¶
- class mau.parsers.nodes.VerbatimNode(value)[source]¶
Bases:
ValueNodeVerbatim text.
This node contains verbatim text.
- value¶
the text contained in the node
- node_type = 'verbatim'¶
- class mau.parsers.nodes.WordNode(value)[source]¶
Bases:
ValueNodeThis is a single word, it’s used internally and eventually packed together with others into a TextNode
- node_type = 'word'¶
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
mau.parsers.text_parser module¶
- class mau.parsers.text_parser.TextParser(footnotes_start_with=1, v1_backward_compatibility=False)[source]¶
Bases:
BaseParser- parse_macro_image()[source]¶
Parse an inline image macro in the form [image](uri, alt_text, width, height).
- 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_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.
- 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.