Skip to content
Snippets Groups Projects
Commit 3e93e203 authored by Paweł Kędzia's avatar Paweł Kędzia
Browse files

Grammar for actions: select, delete, relabel and unify

parent 5abf043c
Branches
No related merge requests found
......@@ -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
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment