Skip to content
Snippets Groups Projects
grammar.g 65.9 KiB
Newer Older
	int offset = 0;
	boost::shared_ptr<Function<StrSet> > o_ret;
			o_ret = strset_operator [scope] COMMA offset = number 
		RPAREN {
			ret.reset(new Affix(o_ret, offset));
		}
// ----------------------------------------------------------------------------
Adam Wardynski's avatar
Adam Wardynski committed
// A wrapper for strset value and strset variable
	[ParsingScope& scope]
	returns [boost::shared_ptr<Function<StrSet> > op]
	| op = strset_variable [scope.variables()]
// ----------------------------------------------------------------------------
// if (Bool, StrSet, StrSet)
// ? StrSet ? Bool : []
	[ParsingScope& scope]
	returns [boost::shared_ptr<Function<StrSet> > op]
	boost::shared_ptr<Function<Bool> > test;
	boost::shared_ptr<Function<StrSet> > p_true, p_false;
	: "if" LPAREN test  = bool_operator [scope] COMMA 
							p_true  = strset_operator   [scope] 
							(COMMA p_false = strset_operator [scope])? 
			op.reset(new Conditional<StrSet>(test, p_true, p_false));
			op.reset(new Conditional<StrSet>(test, p_true));
			p_true = strset_operator [scope]
			test = bool_operator [scope] {
			op.reset(new Conditional<StrSet>(test, p_true));
///////////////////////////////////////////////////////////////////////////////
Adam Wardynski's avatar
Adam Wardynski committed
// Bool operator 
// Returns boost::shared_ptr<Function<Bool> >
///////////////////////////////////////////////////////////////////////////////
bool_operator
	[ParsingScope& scope]
	returns [boost::shared_ptr<Function<Bool> > ret]
	: ret = bool_and        [scope]  
	| ret = bool_or         [scope]  
	| ret = bool_nor        [scope]  
	| ret = bool_var_val    [scope]	
	| ret = bool_regex      [scope]
	| ret = bool_inout      [scope]
	| ret = bool_condition  [scope]
	| ret = setvar_operator [scope]
	| ret = empty_operator  [scope]
	| ret = equal_operator  [scope]
	| ret = in_operator     [scope]
	| ret = inter_operator  [scope]
	| ret = bool_iteration  [scope]
	| ret = bool_agreement  [scope]
	| ret = bool_phrase     [scope]
	// annotation
	| ret = bool_ann        [scope]
	| ret = bool_annsub     [scope]
	| ret = debug_print_operator [scope]
Paweł Kędzia's avatar
Paweł Kędzia committed
	//
	| LPAREN ret = bool_operator [scope] RPAREN
// ----------------------------------------------------------------------------
// comma-separated predicates (bool operators)
bool_operator_comma_sep
	[ParsingScope& scope]
	returns 
		[boost::shared_ptr<std::vector<boost::shared_ptr<Function<Bool> > > > ret_v]
	boost::shared_ptr<Function<Bool> > pred;
	ret_v.reset(
		new std::vector<boost::shared_ptr<Function<Bool> > >
	: pred = bool_operator [scope] { 
		ret_v->push_back(pred);
		COMMA pred = bool_operator [scope] {
// ----------------------------------------------------------------------------
	[ParsingScope& scope]
	returns [boost::shared_ptr<Function<Bool> > op]
	boost::shared_ptr<std::vector<boost::shared_ptr<Function<Bool> > > > ret_v;
	: "and" LPAREN ret_v = bool_operator_comma_sep [scope] RPAREN {
			op.reset(new And(ret_v));
// ----------------------------------------------------------------------------
	[ParsingScope& scope]
	returns [boost::shared_ptr<Function<Bool> > op]
	boost::shared_ptr<std::vector<boost::shared_ptr<Function<Bool> > > > ret_v;
	: "or" LPAREN ret_v = bool_operator_comma_sep [scope] RPAREN {
			op.reset(new Or(ret_v));
// ----------------------------------------------------------------------------
	[ParsingScope& scope]
	returns [boost::shared_ptr<Function<Bool> > op]
	boost::shared_ptr<std::vector<boost::shared_ptr<Function<Bool> > > > ret_v;
	: "not" LPAREN ret_v = bool_operator_comma_sep [scope] RPAREN {
			op.reset(new Nor(ret_v));
// ----------------------------------------------------------------------------
// Wrapper for bool value and bool variable
bool_var_val
	[ParsingScope& scope]
	returns [boost::shared_ptr<Function<Bool> > op]
	| op = bool_variable [scope.variables()]
// ----------------------------------------------------------------------------
	[ParsingScope& scope]
	returns [boost::shared_ptr<Function<Bool> > op]
{
	boost::shared_ptr<Function<StrSet> > expr;
}
	: "regex" 
		LPAREN 
			expr = strset_operator [scope] COMMA reg: STRING 
		RPAREN {
			op.reset(new Regex(expr, token_ref_to_ustring(reg)));
		}
;

// ----------------------------------------------------------------------------
// Input/output operator
bool_inout
	[ParsingScope& scope]
	returns [boost::shared_ptr<Function<Bool> > op]
{
	boost::shared_ptr<Function<Position> > ret_pos;
}
	: "inside"  LPAREN ret_pos = position_operator [scope] RPAREN {
	| "outside" LPAREN ret_pos = position_operator [scope] RPAREN {
		op.reset(new IsOutside(ret_pos));
	}
;

// ----------------------------------------------------------------------------
// if (Bool, Bool, Bool)
// ? Bool ? Bool : False
bool_condition
	[ParsingScope& scope]
	returns [boost::shared_ptr<Function<Bool> > op]
{
	boost::shared_ptr<Function<Bool> > test, p_true, p_false;
}
	: "if" LPAREN test = bool_operator [scope] COMMA 
							p_true = bool_operator [scope] 
							(COMMA p_false = bool_operator [scope])? 
	RPAREN {
		if (p_false) {
			op.reset(new Conditional<Bool>(test, p_true, p_false));
		}
		else {
			op.reset(new Conditional<Bool>(test, p_true));
		}
	}
	| Q_MARK 
			p_true = bool_operator [scope]
			test = bool_operator [scope] {
			op.reset(new Conditional<Bool>(test, p_true));
		}
;

// ----------------------------------------------------------------------------
// Equal operator
equal_operator
	[ParsingScope& scope]
	returns [boost::shared_ptr<Function<Bool> > op]
	boost::shared_ptr<Function<TSet> > t1, t2;
	boost::shared_ptr<Function<Bool> > b1, b2;
	boost::shared_ptr<Function<StrSet>  > s1, s2;
	boost::shared_ptr<Function<Position> > p1, p2;
		(position_operator [scope]) =>
			p1 = position_operator [scope] COMMA 
			p2 = position_operator [scope] {
				op.reset(new Equals<Position>(p1, p2));
		(symset_operator [scope]) =>
			t1 = symset_operator [scope] COMMA  
			t2 = symset_operator [scope] {
		(strset_operator [scope]) =>
			s1 = strset_operator [scope] COMMA  
			s2 = strset_operator [scope] {
			b1 = bool_operator [scope] COMMA
			b2 = bool_operator [scope] {
				op.reset(new Equals<Bool>(b1, b2));
// ----------------------------------------------------------------------------
	[ParsingScope& scope]
	returns [boost::shared_ptr<Function<Bool> > op]
	boost::shared_ptr<Function<TSet> > t1, t2;
	boost::shared_ptr<Function<StrSet> > s1, s2;
		(symset_operator [scope]) =>
			t1 = symset_operator [scope] COMMA 
			t2 = symset_operator [scope] {
				op.reset(new IsSubsetOf<TSet>(t1, t2));
			s1 = strset_operator [scope] COMMA
			s2 = strset_operator [scope] {
				op.reset(new IsSubsetOf<StrSet>(s1, s2));
;
// ----------------------------------------------------------------------------
	[ParsingScope& scope]
	returns [boost::shared_ptr<Function<Bool> > op]
	boost::shared_ptr<Function<TSet> > t1, t2;
	boost::shared_ptr<Function<StrSet> > s1, s2;
		(symset_operator [scope]) =>
			t1 = symset_operator [scope] COMMA  
			t2 = symset_operator [scope]  {
				op.reset(new Intersects<TSet>(t1, t2));
			s1 = strset_operator [scope] COMMA  
			s2 = strset_operator [scope]  {
				op.reset(new Intersects<StrSet>(s1, s2));
// ----------------------------------------------------------------------------
// Annotation operator.
bool_ann
	[ParsingScope& scope]
	returns [boost::shared_ptr<Function<Bool> > op]
{
	boost::shared_ptr< Function<Match> > match_from;
	boost::shared_ptr< Function<Match> > match_to;
	std::string chan_name;
}
	: "ann" LPAREN
			match_from = match_operator [scope] COMMA
			(match_to  = match_operator [scope] COMMA)?
			name : STRING
		RPAREN {
			if (match_to) {
				// TODO
				// op.reset(new Ann(match_from, match_to, chan_name));
			} else {
				// TODO
				// op.reset(new Ann(match_from, chan_name));
			}
		}
;


ilor's avatar
ilor committed
// ----------------------------------------------------------------------------
// Annotation-sub operator.
bool_annsub
	[ParsingScope& scope]
ilor's avatar
ilor committed
	returns [boost::shared_ptr<Function<Bool> > op]
{
	boost::shared_ptr< Function<Match> > match_from;
	boost::shared_ptr< Function<Match> > match_to;
	std::string chan_name;
}
	: "annsub" LPAREN
		match_from = match_operator [scope] COMMA
		(match_to = match_operator [scope] COMMA)?
ilor's avatar
ilor committed
		name : STRING
		RPAREN
		{
			if (match_to) {
				op.reset(new AnnSub(match_from, match_to, chan_name));
			} else {
				op.reset(new AnnSub(match_from, chan_name));
			}
		}
;

// ----------------------------------------------------------------------------
// Debug printing:
debug_print_operator
	[ParsingScope& scope]
	returns [boost::shared_ptr<Function<Bool> > ret]
{
	boost::shared_ptr<FunctionBase> v;
}
	: "debug" LPAREN
	(
		(position_operator [scope]) =>
			v = position_operator [scope] {
		(symset_operator [scope]) =>
			v = symset_operator [scope] {
		(strset_operator [scope]) =>
			v = strset_operator [scope] {
		(bool_operator [scope]) =>
			v = bool_operator [scope] {
			v = match_operator [scope] {
				ret.reset(new DebugPrint(v));
			}
		)
// ----------------------------------------------------------------------------
// Iterations:
bool_iteration
	[ParsingScope& scope]
	returns [boost::shared_ptr<Function<Bool> > ret]
{
	int min_match = 0;
	boost::shared_ptr<Function<Bool> > expr;
	boost::shared_ptr<Function<Position> > lpos, rpos;
	boost::shared_ptr<VariableAccessor<Position> > pacc;
}
	: "only" LPAREN 
			lpos = position_operator [scope] COMMA 
			rpos = position_operator [scope] COMMA
			pacc = position_variable_acc [scope.variables()]     COMMA
			expr = bool_operator     [scope]
		RPAREN {
			ret.reset(new Only(lpos, rpos, *pacc, expr));
		}

	| "atleast" LPAREN
			lpos = position_operator [scope] COMMA 
			rpos = position_operator [scope] COMMA
			pacc = position_variable_acc [scope.variables()]     COMMA
			expr = bool_operator     [scope] COMMA
			min_match = number
		RPAREN {
			ret.reset(new AtLeast(lpos, rpos, *pacc, expr, min_match));
		}
	| "llook" LPAREN //note inverted rpos/lpos order
			rpos = position_operator [scope] COMMA 
			lpos = position_operator [scope] COMMA
			pacc = position_variable_acc [scope.variables()]     COMMA
			expr = bool_operator     [scope] 
		RPAREN {
			ret.reset(new LeftLook(lpos, rpos, *pacc, expr));
		}
	| "rlook" LPAREN
			lpos = position_operator [scope] COMMA 
			rpos = position_operator [scope] COMMA
			pacc = position_variable_acc [scope.variables()]     COMMA
			expr = bool_operator     [scope] 
		RPAREN {
			ret.reset(new RightLook(lpos, rpos, *pacc, expr));
		}
;

// ----------------------------------------------------------------------------
// Agreement operator: agr, agrpp, wagr
bool_agreement
	[ParsingScope& scope]
	returns [boost::shared_ptr<Function<Bool> > ret]
{
	boost::shared_ptr<Function<TSet> > expr;
	boost::shared_ptr<Function<Position> > lpos, rpos;
}
	: "agr"   LPAREN 
			lpos = position_operator [scope] COMMA 
			rpos = position_operator [scope] COMMA 
			expr = symset_operator [scope]
			ret.reset(new StrongAgreement(lpos, rpos, expr, scope.tagset()));
			lpos = position_operator [scope] COMMA 
			rpos = position_operator [scope] COMMA 
			expr = symset_operator [scope]
			ret.reset(new PointAgreement(lpos, rpos, expr, scope.tagset()));
			lpos = position_operator [scope] COMMA 
			rpos = position_operator [scope] COMMA 
			expr = symset_operator [scope]
			ret.reset(new WeakAgreement(lpos, rpos, expr, scope.tagset()));
Paweł Kędzia's avatar
Paweł Kędzia committed
// ----------------------------------------------------------------------------
// Parse operator on L1 level
bool_phrase
	[ParsingScope& scope]
Paweł Kędzia's avatar
Paweł Kędzia committed
	returns [boost::shared_ptr<Function<Bool> > ret]
	: ret = bool_phrase_annotation [scope]
	| ret = bool_phrase_iteration  [scope]
Paweł Kędzia's avatar
Paweł Kędzia committed
;

// ----------------------------------------------------------------------------
// Annotation operator: phrase, phrase_beg, phrase_end, phrase_whole, phrase_pp
bool_phrase_annotation
	[ParsingScope& scope]
Paweł Kędzia's avatar
Paweł Kędzia committed
	returns [boost::shared_ptr<Function<Bool> > ret]
{
	boost::shared_ptr<Function<Position> > lpos, rpos;
}
	: "phrase" LPAREN 
			lpos = position_operator [scope] COMMA n1: STRING 
Paweł Kędzia's avatar
Paweł Kędzia committed
		RPAREN {
			// TODO
		}
	| "phrase_beg" LPAREN 
			lpos = position_operator [scope] COMMA n2: STRING 
Paweł Kędzia's avatar
Paweł Kędzia committed
		RPAREN {
			// TODO
		}
	| "phrase_end" LPAREN 
			lpos = position_operator [scope] COMMA n3: STRING 
Paweł Kędzia's avatar
Paweł Kędzia committed
		RPAREN {
			// TODO
		}
	| "phrase_whole" LPAREN 
			lpos = position_operator [scope] COMMA 
			rpos = position_operator [scope] COMMA n4: STRING 
Paweł Kędzia's avatar
Paweł Kędzia committed
		RPAREN {
			// TODO
		}
	| "phrase_pp" LPAREN 
			lpos = position_operator [scope] COMMA 
			rpos = position_operator [scope] COMMA n5: STRING 
Paweł Kędzia's avatar
Paweł Kędzia committed
		RPAREN {
			// TODO
		}
;

// ----------------------------------------------------------------------------
// Phrase iteration operator: lphrase, rphrase
bool_phrase_iteration
	[ParsingScope& scope]
Paweł Kędzia's avatar
Paweł Kędzia committed
	returns [boost::shared_ptr<Function<Bool> > ret]
{
	boost::shared_ptr<Function<Position> > position;
	boost::shared_ptr<VarGetter<Position> > var_position;
}
	: "lphrase" LPAREN
			position     = position_operator [scope] COMMA
			var_position = position_variable [scope.variables()]         COMMA
Paweł Kędzia's avatar
Paweł Kędzia committed
			n1: STRING
		RPAREN {
			// TODO
		}
	| "rphrase" LPAREN 
			position     = position_operator [scope] COMMA
			var_position = position_variable [scope.variables()]         COMMA
Paweł Kędzia's avatar
Paweł Kędzia committed
			n2: STRING
		RPAREN {
			// TODO
		}
;


// ----------------------------------------------------------------------------
// Setvar operator
// Returns boost::shared_ptr<Function<Bool> >
// ----------------------------------------------------------------------------
setvar_operator 
	[ParsingScope& scope]
	returns [boost::shared_ptr<Function<Bool> > ret]
	: "setvar" LPAREN
	  (
		  ret = position_setvar [scope]
		| ret = bool_setvar     [scope]
		| ret = strset_setvar   [scope]
		| ret = symset_setvar   [scope]
	  )
	  RPAREN
;

// ----------------------------------------------------------------------------
// Setvar for position
position_setvar 
	[ParsingScope& scope]
	returns [boost::shared_ptr<Function<Bool> > op]
	boost::shared_ptr<Function<Position> > ret_op;
	boost::shared_ptr<VariableAccessor<Position> > ret_acc;
	:	ret_acc = position_variable_acc [scope.variables()]
		ret_op  = position_operator [scope] {
			op.reset(new VarSetter<Position>(*ret_acc, ret_op));
// ----------------------------------------------------------------------------
	[ParsingScope& scope]
	returns [boost::shared_ptr<Function<Bool> > op]
	boost::shared_ptr<Function<Bool> > ret_op;
	boost::shared_ptr<VariableAccessor<Bool> > ret_acc;
	:	ret_acc = bool_variable_acc [scope.variables()]
		ret_op  = bool_operator [scope] {
			op.reset(new VarSetter<Bool>(*ret_acc, ret_op));
// ----------------------------------------------------------------------------
	[ParsingScope& scope]
	returns [boost::shared_ptr<Function<Bool> > op]
	boost::shared_ptr<Function<StrSet> > ret_op;
	boost::shared_ptr<VariableAccessor<StrSet> > ret_acc;
	: ret_acc = strset_variable_acc [scope.variables()]
		ret_op  = strset_operator [scope] {
			op.reset(new VarSetter<StrSet>(*ret_acc, ret_op));
// ----------------------------------------------------------------------------
	[ParsingScope& scope]
	returns [boost::shared_ptr<Function<Bool> > op]
	boost::shared_ptr<Function<TSet> > ret_op;
	boost::shared_ptr<VariableAccessor<TSet> > ret_acc;
	: ret_acc = symset_variable_acc [scope.variables()]
	  ret_op  = symset_operator [scope] {
			op.reset(new VarSetter<TSet>(*ret_acc, ret_op));
// ----------------------------------------------------------------------------
// empty() operator
// Returns boost::shared_ptr<Function<Bool> > 
//----------------------------------------------------------------------------
empty_operator
	[ParsingScope& scope]
	returns [boost::shared_ptr<Function<Bool> > op]
	: "empty" LPAREN
		(
			  (match_empty[scope]) => 
					op = match_empty  [scope]
			| (symset_empty [scope]) => 
					op = symset_empty [scope]
			| op = strset_empty [scope]
	[ParsingScope& scope]
	returns [boost::shared_ptr<Function<Bool> > op]
	: "empty" LPAREN
	(
		  op = match_empty  [scope]
		| op = symset_empty [scope]
		| op = strset_empty [scope]
	)
	RPAREN
;
*/

//----------------------------------------------------------------------------
// match empty() operator
// Returns boost::shared_ptr<Function<Bool> > 
match_empty
	[ParsingScope& scope]
	returns [boost::shared_ptr<Function<Bool> > op]
{
	boost::shared_ptr<Function<Match> > arg;
}
	: arg = match_operator [scope] {
		op.reset(new IsEmpty<Match>(arg));
	}
;

//----------------------------------------------------------------------------
// SymSet empty() operator
// Returns boost::shared_ptr<Function<Bool> > 
symset_empty
	[ParsingScope& scope]
	returns [boost::shared_ptr<Function<Bool> > op]
{
	boost::shared_ptr<Function<TSet> > arg;
}
	: arg = symset_operator [scope] {
		op.reset(new IsEmpty<TSet>(arg));
	}
;

//----------------------------------------------------------------------------
// Strset empty() operator
// Returns boost::shared_ptr<Function<Bool> > 
strset_empty
	[ParsingScope& scope]
	returns [boost::shared_ptr<Function<Bool> > op]
{
	boost::shared_ptr<Function<StrSet> > arg;
}
	: arg = strset_operator [scope] {
///////////////////////////////////////////////////////////////////////////////
// Match functional operators,
// which return boost::shared_ptr<Function<Match> >
///////////////////////////////////////////////////////////////////////////////

// ----------------------------------------------------------------------------
// A wrapper for match variable and match value.
match_var_val [ParsingScope& scope]
	returns [boost::shared_ptr<Function<Match> > ret]
	: ret = match_vector_variable [scope.variables()]
	| ret = match_value_const
;

///////////////////////////////////////////////////////////////////////////////
// Match operators.
// Returns boost::shared_ptr<Function<Match> >
///////////////////////////////////////////////////////////////////////////////
match_operator
  [ParsingScope& scope]
	( ret = match_var_val [scope]
	| {LA(1)==LITERAL_M || LA(1)==COLON}? ("M")? {
			ret.reset(new VarGetter<Match>(scope.variables().create_accessor<Match>("_M")));
			ret.reset(new VarGetter<Match>(scope.variables().create_accessor<Match>("_M")));
	| LPAREN ret = match_operator [scope] RPAREN
Adam Wardynski's avatar
Adam Wardynski committed
	( // if there's a colon after the match, we have a submatch reference
		COLON i: UNSIGNED_INT { ret.reset(new Submatch(ret, token_ref_to_int(i))); }
	)*
;

// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Tagging actions and rules:
// ----------------------------------------------------------------------------

// ----------------------------------------------------------------------------
// Single action such as select, delete, relabel or unify
action
	[ParsingScope& scope]
	returns [boost::shared_ptr<TagAction> act]
	: act = action_select  [scope]
	| act = action_delete  [scope]
	| act = action_relabel [scope]
	| act = action_unify [scope]
	| act = action_mark [scope]
	| act = action_unmark [scope]

// Action sequence - the actions are separated with commas:
// 	select(...), select(...), delete(...)
action_sequence
	[ParsingScope& scope]
	returns [boost::shared_ptr<std::vector<boost::shared_ptr<TagAction> > > v_act]
	boost::shared_ptr<TagAction> act;
	v_act.reset(new std::vector<boost::shared_ptr<TagAction> >);
	: act = action[scope] {
		COMMA act = action[scope] {
			v_act->push_back(act);
		}
	)*
;

// ----------------------------------------------------------------------------
// Single rule:
// 	rule(NAME, ACTIONS) or rule(NAME, COND, ACTIONS)
rule
	[ParsingScope& scope]
Adam Wardynski's avatar
Adam Wardynski committed
	returns [boost::shared_ptr<TagRule> rle]
{
	boost::shared_ptr<Function<Bool> > condition;
	boost::shared_ptr<std::vector<boost::shared_ptr<TagAction> > > actions;
	: "rule" LPAREN name: STRING COMMA 
				(condition = bool_operator [scope] COMMA)?
				actions = action_sequence [scope] 
		RPAREN {
			if (condition) {
				rle.reset(
					new TagRule(token_ref_to_std_string(name), scope.variables(), actions, condition));
					new TagRule(token_ref_to_std_string(name), scope.variables(), actions));
	: "rule" LPAREN name: STRING COMMA
	(
		(bool_operator[scope]) =>
			condition = bool_operator [scope] COMMA
			actions = action_sequence [scope] {
				// rule(NAME, COND, ACTIONS)
				rle.reset(
					new TagRule(token_ref_to_std_string(name), scope.variables(), actions, condition));
			actions = action_sequence [scope] {
				rle.reset(new TagRule(token_ref_to_std_string(name), scope.variables(), actions));
	[ParsingScope& scope]
	returns [boost::shared_ptr<TagRuleSequence> rule_seq]
{
	// FIXME czy tutaj przypadkiem nie powinno byc shared_ptr?
Adam Wardynski's avatar
Adam Wardynski committed
	boost::shared_ptr<TagRule> rle;
	rule_seq.reset(new TagRuleSequence());
	: rle = rule [scope] {
ilor's avatar
ilor committed
		rule_seq->push_back(*rle);
		COMMA rle = rule [scope] {
ilor's avatar
ilor committed
			rule_seq->push_back(*rle);
		}
	)*
;

// Temporary name. 
// This is wrapper for rule_sequence in rules section in the wccl file
rules
	[ParsingScope& scope]
	returns [boost::shared_ptr<TagRuleSequence> rule_seq]
	: "rules" LPAREN rule_seq = rule_sequence [scope] RPAREN {

// ----------------------------------------------------------------------------
// Select action: 
//	select(position, predicate) or select(predicate);
action_select 
	[ParsingScope& scope]
	returns [boost::shared_ptr<Select> action]
{
	boost::shared_ptr<Function<Position> > pos;
	boost::shared_ptr<Function<Bool> > condition;
}
	: "select" LPAREN
	(
		(position_operator [scope]) =>
			pos = position_operator [scope] COMMA
			condition = bool_operator [scope] {
				// select(positon, condition); 
				action.reset(new Select(condition, pos));
			condition = bool_operator [scope] {
				action.reset(new Select(condition));
			}
		)
	) 
	RPAREN
;

// ----------------------------------------------------------------------------
// Delete action
//	delete(position, predicate) or delete(predicate);
action_delete
	[ParsingScope& scope]
	returns [boost::shared_ptr<Delete> action]
{
	boost::shared_ptr<Function<Position> > pos;
	boost::shared_ptr<Function<Bool> > condition;
}
	: "delete" LPAREN
	(
		(position_operator [scope]) =>
			pos = position_operator [scope] COMMA
			condition = bool_operator [scope] {
				// delete(positon, condition); 
ilor's avatar
ilor committed
				action.reset(new Delete(condition, pos));
			condition = bool_operator [scope] {
ilor's avatar
ilor committed
				action.reset(new Delete(condition));
			}
		)
	) 
	RPAREN
;

// ----------------------------------------------------------------------------
// Relabel action
// 	relabel(pos, symset, predicate) or relabel(symset, predicate)
action_relabel
	[ParsingScope& scope]
	returns [boost::shared_ptr<Relabel> action]
{
	boost::shared_ptr<Function<Position> > pos;
	boost::shared_ptr<Function<Bool> > condition;
	boost::shared_ptr<Function<TSet> > replace_with;
}
	: "relabel" LPAREN
	(
		(position_operator [scope]) =>
			pos = position_operator [scope] COMMA
			replace_with = symset_operator [scope] COMMA
			condition = bool_operator [scope] {
				// relabel(pos, symset, predicate)
				action.reset(new Relabel(replace_with, condition, pos));
			}
		)
	|
		(
			replace_with = symset_operator [scope] COMMA
			condition = bool_operator [scope] {
				// relabel(symset, predicate)
				action.reset(new Relabel(replace_with, condition));
			}
		)
	)
	RPAREN
;

// ----------------------------------------------------------------------------
// Unify action 
action_unify
	[ParsingScope& scope]
	returns [boost::shared_ptr<Unify> action]
{
	boost::shared_ptr<Function<TSet> > attribs_expr;
	boost::shared_ptr<Function<Position> > pos_begin, pos_end;
}
	: "unify" LPAREN
			pos_begin    = position_operator [scope] COMMA
			pos_end      = position_operator [scope] COMMA
			attribs_expr = symset_operator   [scope]
		RPAREN  {
			action.reset(new Unify(pos_begin, pos_end, attribs_expr));
		}
;

// ----------------------------------------------------------------------------