diff --git a/libwccl/parser/grammar.g b/libwccl/parser/grammar.g index c6937c0e867135d84567961abcd9a18c985ffe98..20e53c3b0fad1f5857b7c47b18889722dbc05c41 100644 --- a/libwccl/parser/grammar.g +++ b/libwccl/parser/grammar.g @@ -57,6 +57,13 @@ header { #include <libwccl/ops/functions/bool/iterations/atleast.h> #include <libwccl/ops/functions/bool/iterations/leftlook.h> #include <libwccl/ops/functions/bool/iterations/rightlook.h> + + // actions + #include <libwccl/ops/actions/unify.h> + #include <libwccl/ops/actions/delete.h> + #include <libwccl/ops/actions/select.h> + #include <libwccl/ops/actions/relabel.h> + // Unicode String #include <unicode/uniset.h> @@ -1322,6 +1329,135 @@ symset_setvar } ; +// ---------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- +// Tagging rules: +// ---------------------------------------------------------------------------- +rule_action + [const Corpus2::Tagset& tagset, Variables& vars] + returns [boost::shared_ptr<Action> action] + : action = action_select [tagset, vars] + | action = action_delete [tagset, vars] + | action = action_relabel [tagset, vars] + // + | action = action_unify [tagset, vars] + // +; + +// ---------------------------------------------------------------------------- +// Select action: +// select(position, predicate) or select(predicate); +action_select + [const Corpus2::Tagset& tagset, Variables& vars] + returns [boost::shared_ptr<Select> action] +{ + boost::shared_ptr<Function<Position> > pos; + boost::shared_ptr<Function<Bool> > condition; +} + : "select" LPAREN + ( + (position_operator [tagset, vars]) => + ( + pos = position_operator [tagset, vars] COMMA + condition = bool_operator [tagset, vars] { + // select(positon, condition); + action.reset(new Select(condition)); + } + ) + | + ( + condition = bool_operator [tagset, vars] { + // select(condition); + action.reset(new Select(condition, pos)); + } + ) + ) + RPAREN +; + +// ---------------------------------------------------------------------------- +// Delete action +// delete(position, predicate) or delete(predicate); +action_delete + [const Corpus2::Tagset& tagset, Variables& vars] + returns [boost::shared_ptr<Delete> action] +{ + boost::shared_ptr<Function<Position> > pos; + boost::shared_ptr<Function<Bool> > condition; +} + : "delete" LPAREN + ( + (position_operator [tagset, vars]) => + ( + pos = position_operator [tagset, vars] COMMA + condition = bool_operator [tagset, vars] { + // delete(positon, condition); + action.reset(new Delete(condition)); + } + ) + | + ( + condition = bool_operator [tagset, vars] { + // delete(condition); + action.reset(new Delete(condition, pos)); + } + ) + ) + RPAREN +; + +// ---------------------------------------------------------------------------- +// Relabel action +// relabel(pos, symset, predicate) or relabel(symset, predicate) +action_relabel + [const Corpus2::Tagset& tagset, Variables& vars] + 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 [tagset, vars]) => + ( + pos = position_operator [tagset, vars] COMMA + replace_with = symset_operator [tagset, vars] COMMA + condition = bool_operator [tagset, vars] { + // relabel(pos, symset, predicate) + action.reset(new Relabel(replace_with, condition, pos)); + } + ) + | + ( + replace_with = symset_operator [tagset, vars] COMMA + condition = bool_operator [tagset, vars] { + // relabel(symset, predicate) + action.reset(new Relabel(replace_with, condition)); + } + ) + ) + RPAREN +; + +// ---------------------------------------------------------------------------- +// Unify action +action_unify + [const Corpus2::Tagset& tagset, Variables& vars] + 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 [tagset, vars] COMMA + pos_end = position_operator [tagset, vars] COMMA + attribs_expr = symset_operator [tagset, vars] + RPAREN { + action.reset(new Unify(pos_begin, pos_end, attribs_expr)); + } +; + /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// // ANTLR LEXER