Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ test: lint tatsu_test documentation examples


tatsu_test: clean
pytest
pytest --cov


documentation: sphinx
Expand Down
1 change: 0 additions & 1 deletion docs/mini-tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,6 @@ The following code generator translates input expressions to the postfix instruc
from tatsu.model import Node
from tatsu.walkers import NodeWalker
from tatsu.mixins.indent import IndentPrintMixin
from tatsu.codegen import ModelRenderer

THIS_MODULE = sys.modules[__name__]

Expand Down
19 changes: 7 additions & 12 deletions docs/models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ Tree* (`AST`_) that reflects the semantic structure of what was parsed.
But an `AST`_ doesn't carry information about the rule that generated
it, so navigating the trees may be difficult.

|TatSu| defines the ``tatsu.model.ModelBuilderSemantics`` semantics
class which helps construct object models from abtract syntax trees:
|TatSu| defines the ``tatsu.semantics.ModelBuilderSemantics`` semantics
class which helps construct object models from abstract syntax trees:

.. code:: python

from tatsu.model import ModelBuilderSemantics
from tatsu.semantics import ModelBuilderSemantics

parser = MyParser(semantics=ModelBuilderSemantics())

Expand All @@ -42,7 +42,7 @@ You can also use `Python`_'s built-in types as node types, and
integer::int = /[0-9]+/ ;

``ModelBuilderSemantics`` acts as any other semantics class, so its
default behavior can be overidden by defining a method to handle the
default behavior can be overridden by defining a method to handle the
result of any particular grammar rule.


Expand All @@ -52,7 +52,7 @@ Viewing Models as JSON


Models generated by |TatSu| can be viewed by converting them to a JSON-compatible structure
with the help of ``tatsu.util.asjson()``. The protocol tries to provide the best
with the help of ``tatsu.util.asjson.asjson()``. The protocol tries to provide the best
representation for common types, and can handle any type using ``repr()``. There are provisions for structures with back-references, so there's no infinite recursion.

.. code:: python
Expand All @@ -74,7 +74,7 @@ You can also write your own version of ``asjson()`` to handle special cases that
Walking Models
~~~~~~~~~~~~~~

The class ``tatsu.model.NodeWalker`` allows for the easy traversal
The class ``tatsu.walkers.NodeWalker`` allows for the easy traversal
(*walk*) a model constructed with a ``ModelBuilderSemantics`` instance:

.. code:: python
Expand Down Expand Up @@ -116,7 +116,7 @@ methods such as:

Which nodes get *walked* is up to the ``NodeWalker`` implementation. Some
strategies for walking *all* or *most* nodes are implemented as classes
in ``tatsu.wakers``, such as ``PreOrderWalker`` and ``DepthFirstWalker``.
in ``tatsu.walkers``, such as ``PreOrderWalker`` and ``DepthFirstWalker``.

Sometimes nodes must be walked more than once for the purpose at hand, and it's
up to the walker how and when to do that.
Expand Down Expand Up @@ -162,8 +162,3 @@ generators*:
op = self.walk(node.op)

print(type(node).__name__, op, left, right)


class Operator(ModelRenderer):
template = '{left} {op} {right}'

2 changes: 1 addition & 1 deletion docs/translation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ modified by overriding the ``render_fields(fields)`` method. Fields
themselves are *lazily rendered* before being expanded by the template,
so a field may be an instance of a ``ModelRenderer`` descendant.

The ``rendering`` module defines a ``Formatter`` enhanced to support the
The ``tatsu.codegen.rendering`` module defines a ``Formatter`` enhanced to support the
rendering of items in an *iterable* one by one. The syntax to achieve
that is:

Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,10 @@ include = ["tatsu*"]
target-version = ["py310"]
line-length=79
skip-magic-trailing-comma=true


[tool.coverage.run]
omit = [
"test/*",
"tatsu/diagrams.py",
]
1 change: 1 addition & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ astroid
docutils
mypy
pytest
pytest-cov
pytest-flake8
pytest-mypy
rich
Expand Down
2 changes: 1 addition & 1 deletion tatsu/codegen/cgbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from ..exceptions import CodegenError
from ..objectmodel import Node
from ..rendering import Renderer, RenderingFormatter, render
from .rendering import Renderer, RenderingFormatter, render

__all__ = [
'DelegatingRenderingFormatter',
Expand Down
2 changes: 1 addition & 1 deletion tatsu/codegen/objectmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from ..codegen.cgbase import CodeGenerator, ModelRenderer
from ..exceptions import CodegenError
from ..objectmodel import BASE_CLASS_TOKEN, Node
from ..rendering import Renderer
from .rendering import Renderer

NODE_NAME_PATTERN = r'(?!\d)\w+(' + rf'{BASE_CLASS_TOKEN}' + r'(?!\d)\w+)*'

Expand Down
2 changes: 1 addition & 1 deletion tatsu/rendering.py → tatsu/codegen/rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import itertools
import string

from .util import indent, isiter, trim
from tatsu.util import indent, isiter, trim


def render(item, join='', **fields):
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion tatsu/contexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from contextlib import contextmanager, suppress
from copy import copy

from tatsu.collections.boundeddict import BoundedDict

from . import buffering, color, tokenizing
from .ast import AST
from .collections import OrderedSet as oset
Expand Down Expand Up @@ -41,7 +43,6 @@
safe_name,
trim,
)
from .util.boundeddict import BoundedDict
from .util.unicode_characters import (
C_CUT,
C_ENTRY,
Expand Down