Tayra

Template. Script. Distribute

ast – Abstract syntax tree

Module containing Terminal and Non-terminal definitions.

The AST tree is constructed according to the parser-grammar defined in tayra.parser. From the root non-terminal use the children() method on every node to walk through the tree.

Module contents

class tayra.ast.Node(parser)[source]

Bases: builtins.object

Base class for all Terminal and Non-terminal nodes. Initialize parent object on the node.

bubbleup(attrname, value)[source]

Bubble up value value to the root node and save that as its attribute attrname

bubbleupaccum(attrname, value, to=None)[source]

Same as bubbleup(), but instead of assigning the value to attrname, it is appended to the list.

children()[source]

Return a tuple of children for this node in the same order as parsed by the grammar rule. Must always be overriden by the deriving class.

dump(context)[source]

Simply dump the contents of this node and its children node and return the same.

generate(igen, *args, **kwargs)[source]

Code generation phase. The result must be an executable python script

getroot()[source]

Get root node traversing backwards from this self node.

headpass1(igen)[source]

Pre-processing phase 1, useful to implement multi-pass compilers

headpass2(igen)[source]

Pre-processing phase 2, useful to implement multi-pass compilers

lstrip(chars)[source]

Strip the leftmost chars from the Terminal nodes. Each terminal node must return remaining characters. In case of the Non-terminal node, call all the children node’s lstrip() method, until the caller recieves a non-empty return value.

parent = None

Immediate non-terminal parent node.

parser = None

tayra.parser.TTLParser instance.

rstrip(chars)[source]

Strip the rightmost chars from the Terminal nodes. Each terminal node must return remaining characters. In case of the Non-terminal node, call all the children node’s rstrip() method, until the caller recieves a non-empty return value.

show(buf=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, offset=0, attrnames=False, showcoord=False)[source]

Pretty print the Node and all its attributes and children (recursively) to a buffer.

buf,
Open IO buffer into which the Node is printed.
offset,
Initial offset (amount of leading spaces).
attrnames,
True if you want to see the attribute names in name=value pairs. False to only see the values.
showcoord,
Do you want the coordinates of each Node to be displayed.
tailpass(igen)[source]

Post-processing phase 1, useful to implement multi-pass compilers

validate()[source]

Validate this node and all the children nodes. Expected to be called before starting head-passes on the tree.

class tayra.ast.Terminal(parser, lineno, terminal='', **kwargs)[source]

Bases: tayra.ast.Node

Abstract base class for all terminal nodes. Initialize terminal attribute

dump(context)[source]

Simply dump the contents of this node and its children node and return the same.

generate(igen, *args, **kwargs)[source]

Dump the content.

lineno = None

Line number reference where the node starts in the text. Useful in debug mode.

lstrip(chars)[source]

Strip off the leftmost characters from the terminal string. Return the remaining characters.

rstrip(chars)[source]

Strip off the rightmost characters from the terminal string. Return the remaining characters.

show(buf=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, offset=0, attrnames=False, showcoord=False)[source]

Pretty print the Node and all its attributes and children (recursively) to a buffer.

buf,
Open IO buffer into which the Node is printed.
offset,
Initial offset (amount of leading spaces)
attrnames,
True if you want to see the attribute names in name=value pairs. False to only see the values.
showcoord,
Do you want the coordinates of each Node to be displayed.
terminal = ''

Terminal’s token String.

class tayra.ast.NonTerminal(parser, *args, **kwargs)[source]

Bases: tayra.ast.Node

Abstract base class for all non-terminalnodes. Initialize _terms and _nonterms

_nonterms = []

List of NonTerminal nodes under this node.

_terms = []

List of Terminal nodes under this node.

flatten(attrnode, attrs)[source]

Instead of recursing through left-recursive grammar, flatten them into sequential list for looping on them later.

gencontrolblock(igen, parts, lineno, *args, **kwargs)[source]

Generate control blocks, if-elif-else, for and while loops.

genfunction(igen, dline, funsign, script, *args, **kwargs)[source]

Generate function block for @def and @interface.

lstrip(chars)[source]

Strip off the leftmost characters from children nodes. Stop stripping on recieving non null string.

rstrip(chars)[source]

Strip off the rightmost characters from children nodes. Stop stripping on recieving non null string.

class tayra.ast.DocType(parser, directive, newlines)[source]

class to handle doctype grammar. Note that DTDs are deprecated in HTML5. We will have to wait and see how it evolves under HTML5.

ttl doctype name Transted to html
html4.01transitional <!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd“>
html4.01strict <!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN” “http://www.w3.org/TR/html4/strict.dtd“>
html4.01frameset <!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Frameset//EN” “http://www.w3.org/TR/html4/frameset.dtd“>
xhtml1.0transitional <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/ xhtml1-transitional.dtd”>
xhtml1.0strict <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/ xhtml1-strict.dtd”>
xhtml1.0frameset <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Frameset//EN” “http://www.w3.org/TR/xhtml1/DTD/ xhtml1-frameset.dtd”>
xhtml1.1

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.1//EN” “http://www.w3.org/TR/xhtml11/DTD/

xhtml11.dtd”>
xhtml1.1basic <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML Basic 1.1//EN” “http://www.w3.org/TR/xhtml-basic/ xhtml-basic11.dtd”>
xhtml1.1mobile <!DOCTYPE html PUBLIC “-//WAPFORUM//DTD XHTML Mobile 1.2//EN” “http://www.openmobilealliance.org/tech/DTD/ xhtml-mobile12.dtd”>
xhtml+rdfa1.0 <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML+RDFa 1.0//EN” “http://www.w3.org/MarkUp/DTD/ xhtml-rdfa-1.dtd”>
html <!DOCTYPE html>

Table Of Contents

Related Topics

This Page