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

Fix unpickling when compiled with newer mypycs #9

Merged
merged 1 commit into from
Jun 29, 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
3 changes: 3 additions & 0 deletions parsing/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@

from __future__ import annotations

from mypy_extensions import mypyc_attr


@mypyc_attr(serializable=True, allow_interpreted_subclasses=True)
class Symbol:
pass

Expand Down
7 changes: 5 additions & 2 deletions parsing/automaton.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
Tuple,
Type,
)
from mypy_extensions import mypyc_attr

import collections
import inspect
Expand Down Expand Up @@ -97,6 +98,7 @@ def computeFirstSet(s: Tuple[SymbolSpec, ...]) -> frozenset[SymbolSpec]:
return firstSet


@mypyc_attr(serializable=True, allow_interpreted_subclasses=True)
class ItemSet:
def __init__(self, items: Iterable[Tuple[Item, set[SymbolSpec]]]) -> None:
self._kernel: Dict[Item, set[SymbolSpec]] = {}
Expand Down Expand Up @@ -216,9 +218,9 @@ def closure(self) -> None:
def goto(self, sym: SymbolSpec) -> ItemSet | None:
items = self._symMap.get(sym)
if items:
return ItemSet(
return ItemSet([
(i.production.item(i.dotPos + 1), self._all[i]) for i in items
)
])
else:
return None

Expand Down Expand Up @@ -274,6 +276,7 @@ def weakCompat(self, other: ItemSet) -> bool:
return True


@mypyc_attr(serializable=True, allow_interpreted_subclasses=True)
class Spec(interfaces.Spec):
"""
The Spec class contains the read-only data structures that the Parser
Expand Down
10 changes: 10 additions & 0 deletions parsing/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
Type,
)

from mypy_extensions import mypyc_attr

import re
import sys
from parsing.ast import Token, Nonterm
Expand All @@ -48,6 +50,7 @@
import types


@mypyc_attr(serializable=True, allow_interpreted_subclasses=True)
class PrecedenceSpec:
assoc_tok_re: ClassVar[re.Pattern[str]] = re.compile(
r"([<>=])([A-Za-z]\w*)"
Expand Down Expand Up @@ -83,11 +86,13 @@ def __repr__(self) -> str:
)


@mypyc_attr(serializable=True, allow_interpreted_subclasses=True)
class PrecedenceRef(PrecedenceSpec):
def __init__(self, name: str) -> None:
super().__init__(name, "fail", {})


@mypyc_attr(serializable=True, allow_interpreted_subclasses=True)
class SymbolSpec:
name: str
prec: PrecedenceSpec
Expand Down Expand Up @@ -122,6 +127,7 @@ def followSetMerge(self, set: Iterable[SymbolSpec]) -> bool:
return ret


@mypyc_attr(serializable=True, allow_interpreted_subclasses=True)
class NontermSpec(SymbolSpec):
token_re: ClassVar[re.Pattern[str]] = re.compile(r"([A-Za-z]\w*)")
precedence_tok_re: ClassVar[re.Pattern[str]] = re.compile(
Expand Down Expand Up @@ -193,6 +199,7 @@ def from_class(


# AKA terminal symbol.
@mypyc_attr(serializable=True, allow_interpreted_subclasses=True)
class TokenSpec(SymbolSpec):
def __init__(
self,
Expand All @@ -204,6 +211,7 @@ def __init__(
self.tokenType = tokenType


@mypyc_attr(serializable=True, allow_interpreted_subclasses=True)
class Item:
production: Production
dotPos: int
Expand Down Expand Up @@ -260,6 +268,7 @@ def lr0__repr__(self) -> str:
_item_cache: dict[tuple[Production, int], Item] = {}


@mypyc_attr(serializable=True, allow_interpreted_subclasses=True)
class Production:
def __init__(
self,
Expand Down Expand Up @@ -347,6 +356,7 @@ def reduce(self, userStartSym: SymbolSpec, eoi: EndOfInputSpec) -> None:
pass


@mypyc_attr(serializable=True, allow_interpreted_subclasses=True)
class Action:
"""
Abstract base class, subclassed by {Shift,Reduce}Action."""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@


USE_MYPYC = False
MYPY_DEPENDENCY = "mypy>=0.910"
MYPY_DEPENDENCY = "mypy>=1.4.1"
setup_requires = []
ext_modules = []

Expand Down