Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add and improve docstrings #1326

Merged
merged 1 commit into from
Aug 23, 2023
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 lark/ast_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Module of utilities for transforming a lark.Tree into a custom Abstract Syntax Tree
Module of utilities for transforming a lark.Tree into a custom Abstract Syntax Tree (AST defined in classes)
"""

import inspect, re
Expand Down
2 changes: 1 addition & 1 deletion lark/indenter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"Provides Indentation services for languages with indentation similar to Python"
"Provides a post-lexer for implementing Python-style indentation."

from abc import ABC, abstractmethod
from typing import List, Iterator
Expand Down
4 changes: 4 additions & 0 deletions lark/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
has_interegular = False

class Pattern(Serialize, ABC):
"An abstraction over regular expressions."

value: str
flags: Collection[str]
Expand Down Expand Up @@ -112,6 +113,7 @@ def max_width(self) -> int:


class TerminalDef(Serialize):
"A definition of a terminal"
__serialize_fields__ = 'name', 'pattern', 'priority'
__serialize_namespace__ = PatternStr, PatternRE

Expand Down Expand Up @@ -269,6 +271,8 @@ def __eq__(self, other):


class LineCounter:
"A utility class for keeping track of line & column information"

__slots__ = 'char_pos', 'line', 'column', 'line_start_pos', 'newline_char'

def __init__(self, newline_char):
Expand Down
4 changes: 3 additions & 1 deletion lark/load_grammar.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Parses and creates Grammar objects"""
"""Parses and compiles Lark grammars into an internal representation.
"""

import hashlib
import os.path
import sys
Expand Down
2 changes: 2 additions & 0 deletions lark/parse_tree_builder.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Provides functions for the automatic building and shaping of the parse-tree."""

from typing import List

from .exceptions import GrammarError, ConfigurationError
Expand Down
2 changes: 1 addition & 1 deletion lark/parser_frontends.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def create_earley_parser(lexer_conf: LexerConf, parser_conf: ParserConf, options

class CYK_FrontEnd:
def __init__(self, lexer_conf, parser_conf, options=None):
self._analysis = GrammarAnalyzer(parser_conf)
# self._analysis = GrammarAnalyzer(parser_conf)
self.parser = cyk.Parser(parser_conf.rules)

self.callbacks = parser_conf.callbacks
Expand Down
2 changes: 2 additions & 0 deletions lark/parsers/grammar_analysis.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"Provides for superficial grammar analysis."

from collections import Counter, defaultdict

from ..utils import bfs, fzset, classify
Expand Down
3 changes: 2 additions & 1 deletion lark/reconstruct.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Reconstruct text from a tree, based on Lark grammar"""
"""This is an experimental tool for reconstructing text from a shaped tree, based on a Lark grammar.
"""

from typing import Dict, Callable, Iterable, Optional

Expand Down