From a554b994901183b0d679b9518f242f8c51ebb5e5 Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Tue, 18 Sep 2018 10:47:08 +0200
Subject: [PATCH] fix consistency detection of CNF grammar

---
 alib2data/src/grammar/ContextFree/CNF.h | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/alib2data/src/grammar/ContextFree/CNF.h b/alib2data/src/grammar/ContextFree/CNF.h
index 6a32e8d711..2c23c845e1 100644
--- a/alib2data/src/grammar/ContextFree/CNF.h
+++ b/alib2data/src/grammar/ContextFree/CNF.h
@@ -515,7 +515,7 @@ public:
 	static bool used ( const grammar::CNF < SymbolType > & grammar, const SymbolType & symbol ) {
 		for ( const std::pair < const SymbolType, ext::set < ext::variant < SymbolType, ext::pair < SymbolType, SymbolType > > > > & rule : grammar.getRules ( ) )
 			for ( const ext::variant < SymbolType, ext::pair < SymbolType, SymbolType > > & rhs : rule.second )
-				if ( ( rhs.template is < SymbolType > ( ) && ( rhs.template get < SymbolType > ( ) == symbol ) ) || ( rhs.template get < ext::pair < SymbolType, SymbolType > > ( ).first == symbol ) )
+				if ( ( rhs.template is < SymbolType > ( ) && ( rhs.template get < SymbolType > ( ) == symbol ) ) )
 					return true;
 
 		return false;
@@ -568,9 +568,13 @@ public:
 			if ( rule.first == symbol )
 				return true;
 
-			for ( const ext::variant < SymbolType, ext::pair < SymbolType, SymbolType > > & rhs : rule.second )
-				if ( rhs.template get < ext::pair < SymbolType, SymbolType > > ( ).second == symbol )
+			for ( const ext::variant < SymbolType, ext::pair < SymbolType, SymbolType > > & rhs : rule.second ) {
+				if ( rhs.template is < SymbolType > ( ) )
+					continue;
+
+				if ( rhs.template get < ext::pair < SymbolType, SymbolType > > ( ).first == symbol || rhs.template get < ext::pair < SymbolType, SymbolType > > ( ).second == symbol )
 					return true;
+			}
 
 		}
 
-- 
GitLab