From 49470830baeec73a995632776a8765f7f414c6f7 Mon Sep 17 00:00:00 2001 From: Nicholas Chammas Date: Fri, 5 Jun 2026 14:06:18 -0400 Subject: [PATCH] show indenter property docs + add working links --- docs/classes.rst | 1 + examples/indented_tree.py | 2 +- lark/indenter.py | 17 +++++++---------- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/docs/classes.rst b/docs/classes.rst index 7e88cefb1..b19ad797e 100644 --- a/docs/classes.rst +++ b/docs/classes.rst @@ -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 diff --git a/examples/indented_tree.py b/examples/indented_tree.py index a43733e42..649159f09 100644 --- a/examples/indented_tree.py +++ b/examples/indented_tree.py @@ -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. diff --git a/lark/indenter.py b/lark/indenter.py index 58bb26cca..33b8b54f6 100644 --- a/lark/indenter.py +++ b/lark/indenter.py @@ -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] @@ -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 `_ """ raise NotImplementedError() @@ -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 `_ """ raise NotImplementedError() @@ -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 `_. - See also: the ``postlex`` option in `Lark`. + See also: the ``postlex`` option in :class:`lark.Lark`. """ NL_type = '_NEWLINE'