diff --git a/parsing/automaton.py b/parsing/automaton.py index 0f8be6e..8f40da2 100644 --- a/parsing/automaton.py +++ b/parsing/automaton.py @@ -158,7 +158,7 @@ def __hash__(self) -> int: return self._hash def __eq__(self, other: Any) -> bool: - if type(other) == ItemSet: + if type(other) is ItemSet: return self._kernel.keys() == other._kernel.keys() else: return NotImplemented @@ -589,7 +589,7 @@ def __repr__(self) -> str: conflict = "XXX" break - if type(action) == ShiftAction: + if type(action) is ShiftAction: lines.append( "%s %15r : %-6s %d [%s]" % ( @@ -601,7 +601,7 @@ def __repr__(self) -> str: ) ) else: - assert type(action) == ReduceAction + assert type(action) is ReduceAction lines.append( "%s %15r : %-6s %r" % (conflict, sym, "reduce", action.production) @@ -1715,16 +1715,16 @@ def _resolve( ) -> ConflictResolution: ret: ConflictResolution - if type(oldAct) == ShiftAction: + if type(oldAct) is ShiftAction: oldPrec = sym.prec - elif type(oldAct) == ReduceAction: + elif type(oldAct) is ReduceAction: oldPrec = oldAct.production.prec else: assert False - if type(newAct) == ShiftAction: + if type(newAct) is ShiftAction: newPrec = sym.prec - elif type(newAct) == ReduceAction: + elif type(newAct) is ReduceAction: newPrec = newAct.production.prec else: assert False @@ -1740,9 +1740,9 @@ def _resolve( if oldPrec.assoc == "split" or newPrec.assoc == "split": ret = "both" - elif type(newAct) == type(oldAct): - assert type(newAct) == ReduceAction - assert type(oldAct) == ReduceAction + elif type(newAct) is type(oldAct): + assert type(newAct) is ReduceAction + assert type(oldAct) is ReduceAction # Fatal reduce/reduce conflict. ret = "err" else: @@ -1765,16 +1765,16 @@ def _resolve( if assoc == "fail": ret = "err" elif assoc == "left": - if type(oldAct) == ShiftAction: + if type(oldAct) is ShiftAction: ret = "new" else: - assert type(newAct) == ShiftAction + assert type(newAct) is ShiftAction ret = "old" elif assoc == "right": - if type(oldAct) == ShiftAction: + if type(oldAct) is ShiftAction: ret = "old" else: - assert type(newAct) == ShiftAction + assert type(newAct) is ShiftAction ret = "new" elif assoc == "nonassoc": ret = "neither" diff --git a/parsing/glrparser.py b/parsing/glrparser.py index 3cda854..3e4459a 100644 --- a/parsing/glrparser.py +++ b/parsing/glrparser.py @@ -127,7 +127,7 @@ def token(self, token: Token) -> None: tokenSpec = self._spec.sym_spec(token) self._act(token, tokenSpec) # type: ignore if len(self._gss) == 0: - raise UnexpectedToken("Unexpected token: %r" % token) + raise UnexpectedToken(f"Unexpected token: {token:r}") def eoi(self) -> None: """ @@ -141,7 +141,7 @@ def eoi(self) -> None: for path in top.paths(): assert len(path) == 5 if self.verbose: - print(" --> accept %r" % path) + print(f" --> accept {path:r}") edge = path[1] assert isinstance(edge, Gsse) assert isinstance(edge.value, Nonterm) @@ -181,7 +181,7 @@ def _reductions(self, sym: Token, symSpec: TokenSpec) -> None: self._gss.pop(i) else: for action in self._action[top.nextState][symSpec]: - if type(action) == ReduceAction: + if type(action) is ReduceAction: if len(action.production.rhs) == 0: if action.production not in epsilons: assert ( @@ -324,7 +324,7 @@ def _enqueueLimitedReductions( for top in self._gss: if symSpec in self._action[top.nextState]: for action in self._action[top.nextState][symSpec]: - if type(action) == ReduceAction: + if type(action) is ReduceAction: if len(action.production.rhs) == 0: if ( gotos[top.nextState][action.production.lhs] @@ -377,7 +377,7 @@ def _shifts(self, sym: Token, symSpec: TokenSpec) -> None: for topA in prevGss: if symSpec in self._action[topA.nextState]: for action in self._action[topA.nextState][symSpec]: - if type(action) == ShiftAction: + if type(action) is ShiftAction: merged = False for topB in self._gss: if topB.nextState == topA.nextState: diff --git a/parsing/lrparser.py b/parsing/lrparser.py index 54dcc40..3b7662b 100644 --- a/parsing/lrparser.py +++ b/parsing/lrparser.py @@ -26,7 +26,7 @@ class Lr(Parser): def __init__(self, spec: Spec) -> None: if __debug__: - if type(self) == Lr: + if type(self) is Lr: assert spec.pureLR assert spec.conflicts == 0 self._spec = spec @@ -86,11 +86,11 @@ def _act(self, sym: Token, symSpec: TokenSpec) -> None: if self.verbose: print(" --> %r" % action) - if type(action) == ShiftAction: + if type(action) is ShiftAction: self._stack.append((sym, action.nextState)) break else: - assert type(action) == ReduceAction + assert type(action) is ReduceAction self._reduce(action.production) if self.verbose: diff --git a/pyproject.toml b/pyproject.toml index 1d5d465..903cfdd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,8 +1,20 @@ [project] name = "parsing" -description = "LR(1) parser generator for Python" +description = "LR(1) parser generator for Python and CFSM and GLR parser drivers" requires-python = ">=3.7.0" -dynamic = ["version"] +dynamic = ["version", "dependencies", "optional-dependencies"] +license = { file = "LICENSE" } +authors = [{ name = "Jason Evans", email = "jasone@canonware.com" }] +readme = { file = "README.rst", content-type = "text/x-rst" } +classifiers = [ + 'Development Status :: 5 - Production/Stable', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: MIT License', + 'Operating System :: OS Independent', + 'Programming Language :: Python :: 3', + 'Topic :: Software Development :: Compilers', + 'Topic :: Text Processing :: General', +] [build-system] requires = ["setuptools>=42", "wheel"] diff --git a/setup.py b/setup.py index d22ed29..b424cc3 100644 --- a/setup.py +++ b/setup.py @@ -10,10 +10,6 @@ _ROOT = pathlib.Path(__file__).parent -with open(str(_ROOT / "README.rst")) as f: - readme = f.read() - - with open(str(_ROOT / "parsing" / "_version.py")) as f: for line in f: if line.startswith("__version__ ="): @@ -88,26 +84,8 @@ def finalize_options(self) -> None: setup( - name="parsing", version=VERSION, python_requires=">=3.7.0", - url="http://www.canonware.com/Parsing/", - license="MIT", - author="Jason Evans", - author_email="jasone@canonware.com", - description="A pure-Python module that implements an LR(1) " - "parser generator, as well as CFSM and GLR parser drivers.", - long_description=readme, - long_description_content_type="text/x-rst", - classifiers=[ - "Development Status :: 5 - Production/Stable", - "Intended Audience :: Developers", - "License :: OSI Approved :: MIT License", - "Operating System :: OS Independent", - "Programming Language :: Python :: 3", - "Topic :: Software Development :: Compilers", - "Topic :: Text Processing :: General", - ], packages=["parsing", "parsing.tests", "parsing.tests.specs"], package_data={"parsing": ["py.typed"]}, setup_requires=setup_requires,