From d134b6a12d7b2141350fdfac75bd4fafd06c47dc Mon Sep 17 00:00:00 2001 From: Eric Vergnaud Date: Sun, 3 Jun 2018 11:21:37 +0800 Subject: [PATCH] Fixes #2301 --- .../descriptors/ParserExecDescriptors.java | 35 +++++++++++++++++++ .../Python3/src/antlr4/atn/SemanticContext.py | 4 +-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/descriptors/ParserExecDescriptors.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/descriptors/ParserExecDescriptors.java index 297d2989e..ca6e393dd 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/descriptors/ParserExecDescriptors.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/descriptors/ParserExecDescriptors.java @@ -854,4 +854,39 @@ public class ParserExecDescriptors { @CommentHasStringValue public String grammar; } + + /** + * This is a regression test for antlr/antlr4#2301. + */ + public static class OrderingPredicates extends BaseParserTestDescriptor { + public String input = "POINT AT X"; + public String output = null; + public String errors = null; + public String startRule = "expr"; + public String grammarName = "Issue2301"; + + /** + grammar Issue2301; + + SPACES: [ \t\r\n]+ -> skip; + + AT: 'AT'; + X : 'X'; + Y : 'Y'; + + ID: [A-Z]+; + + constant + : 'DUMMY' + ; + + expr + : ID constant? + | expr AT X + | expr AT Y + ; + */ + @CommentHasStringValue + public String grammar; + } } diff --git a/runtime/Python3/src/antlr4/atn/SemanticContext.py b/runtime/Python3/src/antlr4/atn/SemanticContext.py index 548d7eaba..d4593195e 100644 --- a/runtime/Python3/src/antlr4/atn/SemanticContext.py +++ b/runtime/Python3/src/antlr4/atn/SemanticContext.py @@ -135,8 +135,8 @@ class PrecedencePredicate(SemanticContext): else: return None - def __cmp__(self, other): - return self.precedence - other.precedence + def __lt__(self, other): + return self.precedence < other.precedence def __hash__(self): return 31