Skip to content
Open
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
1 change: 1 addition & 0 deletions docs/classes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ Indenter
--------

.. autoclass:: lark.indenter.Indenter
:members: NL_type, OPEN_PAREN_types, CLOSE_PAREN_types, INDENT_type, DEDENT_type, tab_len
.. autoclass:: lark.indenter.PythonIndenter

TextSlice
Expand Down
2 changes: 1 addition & 1 deletion examples/indented_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
===================

A demonstration of parsing indentation (“whitespace significant” language)
and the usage of the ``Indenter`` class.
and the usage of :class:`lark.indenter.Indenter`.

Since indentation is context-sensitive, a postlex stage is introduced to
manufacture ``INDENT``/``DEDENT`` tokens.
Expand Down
17 changes: 7 additions & 10 deletions lark/indenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ class Indenter(PostLex, ABC):
It keeps track of the current indentation, as well as the current level of parentheses.
Inside parentheses, the indentation is ignored, and no indent/dedent tokens get generated.

Note: This is an abstract class. To use it, inherit and implement all its abstract methods:
- tab_len
- NL_type
- OPEN_PAREN_types, CLOSE_PAREN_types
- INDENT_type, DEDENT_type
Note: This is an abstract class. To use it, inherit and implement all its abstract properties.

See also: the ``postlex`` option in `Lark`.
See also: the ``postlex`` option in :class:`lark.Lark`, and the :doc:`/examples/indented_tree` example.
"""
paren_level: int
indent_level: List[int]
Expand Down Expand Up @@ -108,7 +104,7 @@ def CLOSE_PAREN_types(self) -> List[str]:
def INDENT_type(self) -> str:
"""The name of the token that starts an indentation in the grammar.

See also: %declare
See also: `%declare <grammar.html#declare>`_
"""
raise NotImplementedError()

Expand All @@ -117,7 +113,7 @@ def INDENT_type(self) -> str:
def DEDENT_type(self) -> str:
"""The name of the token that end an indentation in the grammar.

See also: %declare
See also: `%declare <grammar.html#declare>`_
"""
raise NotImplementedError()

Expand All @@ -129,9 +125,10 @@ def tab_len(self) -> int:


class PythonIndenter(Indenter):
"""A postlexer that "injects" _INDENT/_DEDENT tokens based on indentation, according to the Python syntax.
"""A postlexer that "injects" _INDENT/_DEDENT tokens based on indentation, according to the
`Python syntax <https://docs.python.org/3/reference/lexical_analysis.html#indentation>`_.

See also: the ``postlex`` option in `Lark`.
See also: the ``postlex`` option in :class:`lark.Lark`.
"""

NL_type = '_NEWLINE'
Expand Down
Loading