From 9716df817281a4854895bc12d5870f55120431d2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pawe=C5=82=20K=C4=99dzia?= <pawel.kedzia@pwr.wroc.pl>
Date: Fri, 22 Apr 2011 00:07:29 +0200
Subject: [PATCH] Added empty() operator to the grammar (for strset, symset and
 match)

---
 libwccl/parser/grammar.g | 81 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 81 insertions(+)

diff --git a/libwccl/parser/grammar.g b/libwccl/parser/grammar.g
index 628410a..f0f634b 100644
--- a/libwccl/parser/grammar.g
+++ b/libwccl/parser/grammar.g
@@ -35,6 +35,7 @@ header {
 	#include <libwccl/ops/functions/bool/predicates/issubsetof.h>
 	#include <libwccl/ops/functions/bool/predicates/isinside.h>
 	#include <libwccl/ops/functions/bool/predicates/isoutside.h>
+	#include <libwccl/ops/functions/bool/predicates/isempty.h>
 	#include <libwccl/ops/functions/bool/predicates/equals.h>
 	#include <libwccl/ops/functions/bool/predicates/weakagreement.h>
 	#include <libwccl/ops/functions/bool/predicates/pointagreement.h>
@@ -1055,6 +1056,8 @@ bool_operator
 	| ret = bool_condition  [tagset, vars]
 	// setvar:
 	| ret = setvar_operator [tagset, vars]
+	// empty
+	| ret = empty_operator  [tagset, vars]
 	// equal/in/inter:
 	| ret = equal_operator  [tagset, vars]
 	| ret = in_operator     [tagset, vars]
@@ -1639,6 +1642,84 @@ symset_setvar
 		}
 ;
 
+// ----------------------------------------------------------------------------
+// empty() operator
+// Returns boost::shared_ptr<Function<Bool> > 
+//----------------------------------------------------------------------------
+empty_operator
+	[const Corpus2::Tagset& tagset, Variables& vars]
+	returns [boost::shared_ptr<Function<Bool> > op]
+	: "empty" LPAREN
+		(
+			  (match_empty[tagset, vars]) => 
+				(
+					op = match_empty  [tagset, vars]
+				)
+			| (symset_empty [tagset, vars]) => 
+				(
+					op = symset_empty [tagset, vars]
+				)
+			| op = strset_empty [tagset, vars]
+		)
+	RPAREN
+;
+
+/*
+empty_operator
+	[const Corpus2::Tagset& tagset, Variables& vars]
+	returns [boost::shared_ptr<Function<Bool> > op]
+	: "empty" LPAREN
+	(
+		  op = match_empty  [tagset, vars]
+		| op = symset_empty [tagset, vars]
+		| op = strset_empty [tagset, vars]
+	)
+	RPAREN
+;
+*/
+
+//----------------------------------------------------------------------------
+// match empty() operator
+// Returns boost::shared_ptr<Function<Bool> > 
+match_empty
+	[const Corpus2::Tagset& tagset, Variables& vars]
+	returns [boost::shared_ptr<Function<Bool> > op]
+{
+	boost::shared_ptr<Function<Match> > arg;
+}
+	: arg = match_fit [tagset, vars] {
+		op.reset(new IsEmpty<Match>(arg));
+	}
+;
+
+//----------------------------------------------------------------------------
+// SymSet empty() operator
+// Returns boost::shared_ptr<Function<Bool> > 
+symset_empty
+	[const Corpus2::Tagset& tagset, Variables& vars]
+	returns [boost::shared_ptr<Function<Bool> > op]
+{
+	boost::shared_ptr<Function<TSet> > arg;
+}
+	: arg = symset_operator [tagset, vars] {
+		op.reset(new IsEmpty<TSet>(arg));
+	}
+;
+
+//----------------------------------------------------------------------------
+// Strset empty() operator
+// Returns boost::shared_ptr<Function<Bool> > 
+strset_empty
+	[const Corpus2::Tagset& tagset, Variables& vars]
+	returns [boost::shared_ptr<Function<Bool> > op]
+{
+	boost::shared_ptr<Function<StrSet> > arg;
+}
+	: arg = strset_operator [tagset, vars] {
+		op.reset(new IsEmpty<StrSet>(arg));
+	}
+;
+
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // Tagging actions and rules:
-- 
GitLab