[Python-modules-commits] [sphinx] 08/17: make grammar generation deterministic
Dmitry Shachnev
mitya57 at moszumanska.debian.org
Wed Mar 2 07:30:02 UTC 2016
This is an automated email from the git hooks/post-receive script.
mitya57 pushed a commit to branch master
in repository sphinx.
commit 2004e60dbeb61237e8563589af139c8a36e8693f
Author: Val Lorentz <progval at progval.net>
Date: Thu Oct 8 13:58:13 2015 -0700
make grammar generation deterministic
Forwarded: https://github.com/sphinx-doc/sphinx/pull/2009
Last-Update: 2015-09-03
Patch-Name: reproducible_grammar.diff
---
sphinx/pycode/pgen2/pgen.py | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/sphinx/pycode/pgen2/pgen.py b/sphinx/pycode/pgen2/pgen.py
index e199ed8..85a1bcc 100644
--- a/sphinx/pycode/pgen2/pgen.py
+++ b/sphinx/pycode/pgen2/pgen.py
@@ -4,6 +4,10 @@
from __future__ import print_function
from six import iteritems
+try:
+ from collections import OrderedDict
+except ImportError: # Fallback for Python 2.6
+ OrderedDict = dict
# Pgen imports
@@ -57,7 +61,7 @@ class ParserGenerator(object):
def make_first(self, c, name):
rawfirst = self.first[name]
first = {}
- for label in rawfirst:
+ for label in sorted(rawfirst):
ilabel = self.make_label(c, label)
##assert ilabel not in first # X X X failed on <> ... !=
first[ilabel] = 1
@@ -138,8 +142,8 @@ class ParserGenerator(object):
totalset[label] = 1
overlapcheck[label] = {label: 1}
inverse = {}
- for label, itsfirst in iteritems(overlapcheck):
- for symbol in itsfirst:
+ for label, itsfirst in sorted(overlapcheck.items()):
+ for symbol in sorted(itsfirst):
if symbol in inverse:
raise ValueError("rule %s is ambiguous; %s is in the"
" first sets of %s as well as %s" %
@@ -349,6 +353,9 @@ class NFAState(object):
assert isinstance(next, NFAState)
self.arcs.append((label, next))
+ def __hash__(self):
+ return hash(tuple(x[0] for x in self.arcs))
+
class DFAState(object):
def __init__(self, nfaset, final):
@@ -357,7 +364,10 @@ class DFAState(object):
assert isinstance(final, NFAState)
self.nfaset = nfaset
self.isfinal = final in nfaset
- self.arcs = {} # map from label to DFAState
+ self.arcs = OrderedDict() # map from label to DFAState
+
+ def __hash__(self):
+ return hash(tuple(self.arcs))
def addarc(self, next, label):
assert isinstance(label, str)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/sphinx.git
More information about the Python-modules-commits
mailing list