Skip to content

Commit

Permalink
Update parsimonious to 0.10.0 (#8730)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Kirsche committed Sep 13, 2022
1 parent 3ec7b1f commit 65c4ddf
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 24 deletions.
1 change: 0 additions & 1 deletion stubs/parsimonious/@tests/stubtest_allowlist.txt
@@ -1,2 +1 @@
parsimonious.nodes.Node.__repr__
parsimonious.nodes.RuleDecoratorMeta.__new__
2 changes: 1 addition & 1 deletion stubs/parsimonious/METADATA.toml
@@ -1 +1 @@
version = "0.9.*"
version = "0.10.*"
1 change: 1 addition & 0 deletions stubs/parsimonious/parsimonious/exceptions.pyi
Expand Up @@ -11,6 +11,7 @@ class ParseError(StrAndRepr, Exception):
def line(self) -> int: ...
def column(self) -> int: ...

class LeftRecursionError(ParseError): ...
class IncompleteParseError(ParseError): ...

class VisitationError(Exception):
Expand Down
26 changes: 18 additions & 8 deletions stubs/parsimonious/parsimonious/expressions.pyi
@@ -1,4 +1,5 @@
import collections.abc
from _typeshed import Self
from collections.abc import Callable, Mapping
from re import Pattern
from typing import Any, Union
Expand All @@ -9,20 +10,22 @@ from parsimonious.grammar import Grammar
from parsimonious.nodes import Node
from parsimonious.utils import StrAndRepr

MARKER: Any

_CALLABLE_RETURN_TYPE: TypeAlias = Union[int, tuple[int, list[Node]], Node, None]
_CALLABLE_TYPE: TypeAlias = (
Callable[[str, int], _CALLABLE_RETURN_TYPE]
| Callable[[str, int, Mapping[tuple[int, int], Node], ParseError, Grammar], _CALLABLE_RETURN_TYPE]
)

def is_callable(value: object) -> bool: ...
def expression(callable: _CALLABLE_TYPE, rule_name: str, grammar: Grammar) -> Expression: ...

IN_PROGRESS: object

class Expression(StrAndRepr):
name: str
identity_tuple: tuple[str]
def __init__(self, name: str = ...) -> None: ...
def resolve_refs(self: Self, rule_map: Mapping[str, Expression]) -> Self: ...
def parse(self, text: str, pos: int = ...) -> Node: ...
def match(self, text: str, pos: int = ...) -> Node: ...
def match_core(self, text: str, pos: int, cache: Mapping[tuple[int, int], Node], error: ParseError) -> Node: ...
Expand Down Expand Up @@ -57,11 +60,18 @@ class Compound(Expression):

class Sequence(Compound): ...
class OneOf(Compound): ...
class Lookahead(Compound): ...
class Not(Compound): ...
class Optional(Compound): ...
class ZeroOrMore(Compound): ...

class OneOrMore(Compound):
class Lookahead(Compound):
negativity: bool
def __init__(self, member: Expression, *, negative: bool = ..., **kwargs: Any) -> None: ...

def Not(term: Expression) -> Lookahead: ...

class Quantifier(Compound):
min: int
def __init__(self, member: Expression, name: str = ..., min: int = ...) -> None: ...
max: float
def __init__(self, member: Expression, *, min: int = ..., max: float = ..., name: str = ..., **kwargs: Any) -> None: ...

def ZeroOrMore(member: Expression, name: str = ...) -> Quantifier: ...
def OneOrMore(member: Expression, name: str = ..., min: int = ...) -> Quantifier: ...
def Optional(member: Expression, name: str = ...) -> Quantifier: ...
27 changes: 14 additions & 13 deletions stubs/parsimonious/parsimonious/grammar.pyi
Expand Up @@ -3,7 +3,7 @@ from collections import OrderedDict
from collections.abc import Callable, Mapping
from typing import Any, NoReturn

from parsimonious.expressions import _CALLABLE_TYPE, Expression, Literal, Lookahead, Not, OneOf, Regex, Sequence, TokenMatcher
from parsimonious.expressions import _CALLABLE_TYPE, Expression, Literal, Lookahead, OneOf, Regex, Sequence, TokenMatcher
from parsimonious.nodes import Node, NodeVisitor

class Grammar(OrderedDict[str, Expression]):
Expand All @@ -20,6 +20,7 @@ rule_syntax: str

class LazyReference(str):
name: str
def resolve_refs(self, rule_map: Mapping[str, Expression | LazyReference]) -> Expression: ...

class RuleVisitor(NodeVisitor):
quantifier_classes: dict[str, type[Expression]]
Expand All @@ -28,24 +29,24 @@ class RuleVisitor(NodeVisitor):
visit_atom: Callable[[RuleVisitor, Node, collections.abc.Sequence[Any]], Any]
custom_rules: dict[str, Expression]
def __init__(self, custom_rules: Mapping[str, Expression] | None = ...) -> None: ...
def visit_rules(
self, node: Node, rules_list: collections.abc.Sequence[Any]
) -> tuple[OrderedDict[str, Expression], Expression | None]: ...
def visit_parenthesized(self, node: Node, parenthesized: collections.abc.Sequence[Any]) -> Expression: ...
def visit_quantifier(self, node: Node, quantifier: collections.abc.Sequence[Any]) -> Node: ...
def visit_quantified(self, node: Node, quantified: collections.abc.Sequence[Any]) -> Expression: ...
def visit_lookahead_term(self, node: Node, lookahead_term: collections.abc.Sequence[Any]) -> Lookahead: ...
def visit_not_term(self, node: Node, not_term: collections.abc.Sequence[Any]) -> Lookahead: ...
def visit_rule(self, node: Node, rule: collections.abc.Sequence[Any]) -> Expression: ...
def visit_label(self, node: Node, label: collections.abc.Sequence[Any]) -> str: ...
def visit_sequence(self, node: Node, sequence: collections.abc.Sequence[Any]) -> Sequence: ...
def visit_ored(self, node: Node, ored: collections.abc.Sequence[Any]) -> OneOf: ...
def visit_or_term(self, node: Node, or_term: collections.abc.Sequence[Any]) -> Expression: ...
def visit_sequence(self, node: Node, sequence: collections.abc.Sequence[Any]) -> Sequence: ...
def visit_not_term(self, node: Node, not_term: collections.abc.Sequence[Any]) -> Not: ...
def visit_lookahead_term(self, node: Node, lookahead_term: collections.abc.Sequence[Any]) -> Lookahead: ...
def visit_quantified(self, node: Node, quantified: collections.abc.Sequence[Any]) -> Expression: ...
def visit_quantifier(self, node: Node, quantifier: collections.abc.Sequence[Any]) -> Node: ...
def visit_label(self, node: Node, label: collections.abc.Sequence[Any]) -> str: ...
def visit_reference(self, node: Node, reference: collections.abc.Sequence[Any]) -> LazyReference: ...
def visit_literal(self, node: Node, literal: collections.abc.Sequence[Any]) -> Literal: ...
def visit_spaceless_literal(self, spaceless_literal: Node, visited_children: collections.abc.Sequence[Any]) -> Literal: ...
def visit_regex(self, node: Node, regex: collections.abc.Sequence[Any]) -> Regex: ...
def visit_parenthesized(self, node: Node, parenthesized: collections.abc.Sequence[Any]) -> Expression: ...
def visit_spaceless_literal(self, spaceless_literal: Node, visited_children: collections.abc.Sequence[Any]) -> Literal: ...
def visit_literal(self, node: Node, literal: collections.abc.Sequence[Any]) -> Literal: ...
def generic_visit(self, node: Node, visited_children: collections.abc.Sequence[Any]) -> collections.abc.Sequence[Any] | Node: ... # type: ignore[override]
def visit_rules(
self, node: Node, rules_list: collections.abc.Sequence[Any]
) -> tuple[OrderedDict[str, Expression], Expression | None]: ...

class TokenRuleVisitor(RuleVisitor):
def visit_spaceless_literal(
Expand Down
3 changes: 2 additions & 1 deletion stubs/parsimonious/parsimonious/nodes.pyi
Expand Up @@ -19,6 +19,7 @@ class Node:
@property
def text(self) -> str: ...
def prettily(self, error: Node | None = ...) -> str: ...
def __repr__(self, top_level: bool = ...) -> str: ...

class RegexNode(Node):
match: Match[str]
Expand All @@ -27,7 +28,7 @@ class RuleDecoratorMeta(type): ...

class NodeVisitor(metaclass=RuleDecoratorMeta):
grammar: Grammar | Any
unwrapped_exceptions: tuple[type[Exception], ...]
unwrapped_exceptions: tuple[type[BaseException], ...]
def visit(self, node: Node) -> Any: ...
def generic_visit(self, node: Node, visited_children: Sequence[Any]) -> NoReturn: ...
def parse(self, text: str, pos: int = ...) -> Node: ...
Expand Down

0 comments on commit 65c4ddf

Please sign in to comment.