From 26401e189edf93897203d803c8ea1cc3df93921e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pawe=C5=82=20K=C4=99dzia?= <pawel.kedzia@pwr.wroc.pl>
Date: Mon, 14 Mar 2011 15:58:32 +0100
Subject: [PATCH] Values and variables for the MatchVector type

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

diff --git a/libwccl/parser/grammar.g b/libwccl/parser/grammar.g
index b8d0aa4..712d2c0 100644
--- a/libwccl/parser/grammar.g
+++ b/libwccl/parser/grammar.g
@@ -67,6 +67,10 @@ header {
 	#include <libwccl/ops/tagactions/select.h>
 	#include <libwccl/ops/tagactions/relabel.h>
 
+	// Match operators
+	#include <libwccl/values/tokenmatch.h>
+	#include <libwccl/values/annotationmatch.h>
+	#include <libwccl/ops/match/applyoperator.h>
 
 	// Unicode String
 	#include <unicode/uniset.h>
@@ -379,6 +383,67 @@ position_value
 	}
 ;
 
+// ----------------------------------------------------------------------------
+// Value used into match operator such as TOK[position] and ANN[position, name]
+// Returns boost::shared_ptr<Match>
+match_value
+	returns [boost::shared_ptr<Match> val]
+	: val = token_match_value
+	| val = ann_match_value
+	| val = match_vector_value
+;
+
+// token match value
+// Returns boost::shared_ptr<TokenMatch>
+token_match_value
+	returns [boost::shared_ptr<TokenMatch> val]
+{
+	boost::shared_ptr<Position> p;
+}
+	: "TOK"LBRACKET p = position_literal RBRACKET {
+		val.reset(new TokenMatch(*p));
+	}
+;
+
+// annotation match value
+// Returns boost::shared_ptr<AnnotationMatch> 
+ann_match_value
+	returns [boost::shared_ptr<AnnotationMatch> val]
+{
+	boost::shared_ptr<Position> p;
+}
+	: "ANN" LBRACKET p = position_literal COMMA channel : STRING RBRACKET {
+		val.reset(new AnnotationMatch(*p, token_ref_to_std_string(channel)));
+	}
+;
+
+// annotation match vector: MATCH() or MATCH(token, ann, MATCH())
+// Returns boost::shared_ptr<MatchVector>
+match_vector_value
+	returns [boost::shared_ptr<MatchVector> val]
+{
+	val.reset(new MatchVector());
+}
+	: "MATCH" LPAREN (match_vector_value_item[val])? RPAREN
+;
+
+// Body of the MATCH value. It only adds vector items to the MatchVector
+// Item may be single or multiple
+match_vector_value_item [boost::shared_ptr<MatchVector>& mvector]
+{
+	boost::shared_ptr<Match> m_val;
+}
+	: m_val = match_value {
+		mvector->append(m_val);
+	} 
+	(
+		COMMA
+		m_val = match_value {
+			mvector->append(m_val);
+		}
+	)*
+;
+
 // ----------------------------------------------------------------------------
 // Number may be unsigned or signed: 1, +1, -1
 number 
@@ -517,6 +582,36 @@ bool_variable
 	}
 ;
 
+// ----------------------------------------------------------------------------
+// Match: $m:name
+// Get mach vector variable from variavles (before put into variables)
+// Returns boost::shared_ptr<VariableAccessor<Match> >
+match_vector_variable_acc
+	[Variables& vars]
+	returns [boost::shared_ptr<VariableAccessor<Match> > mvv_acc]
+	: MATCH_VECTOR_PREFIX n: SYMBOL {
+			vars.get_put<Match>(str_token_rem_grav(n));
+
+			VariableAccessor<Match> acc = 
+				vars.create_accessor<Match>(str_token_rem_grav(n));
+
+			mvv_acc.reset(new VariableAccessor<Match>(acc));
+	}
+;
+
+// Vargetter for the match vector variavle. Wrapper for match_vector_variable_acc
+// Returns boost::shared_ptr<VarGetter<Match> >
+match_vector_variable
+	[Variables& vars]
+	returns [boost::shared_ptr<VarGetter<Match> > mvv]
+{
+	boost::shared_ptr<VariableAccessor<Match> > mvv_acc;
+}
+	: mvv_acc = match_vector_variable_acc [vars] {
+		mvv.reset(new VarGetter<Match>(*mvv_acc));
+	}
+;
+
 ///////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////
 // OPERATORS
@@ -1678,6 +1773,13 @@ options {
 	: '$'
 ;
 
+MATCH_VECTOR_PREFIX
+options {
+	paraphrase = "Match vector prefix";
+}
+	: "$m:"
+;
+
 LBRACKET 
 options {
 	paraphrase = "'['";
-- 
GitLab