Newer
Older
| ret = bool_regex [tagset, vars]
| ret = bool_inout [tagset, vars]
| ret = bool_condition [tagset, vars]
// setvar:
| ret = setvar_operator [tagset, vars]
// equal/in/inter:
| ret = equal_operator [tagset, vars]
| ret = in_operator [tagset, vars]
| ret = inter_operator [tagset, vars]
// iterations
| ret = bool_iteration [tagset, vars]
// agreement
| ret = bool_agreement [tagset, vars]
//
ilor
committed
// debug operators
| ret = debug_print_operator [tagset, vars]
| LPAREN ret = bool_operator [tagset, vars] RPAREN
// ----------------------------------------------------------------------------
// comma-separated predicates (bool operators)
bool_operator_comma_sep
[const Corpus2::Tagset& tagset, Variables& vars]
returns
[boost::shared_ptr<std::vector<boost::shared_ptr<Function<Bool> > > > ret_v]
boost::shared_ptr<Function<Bool> > pred;
new std::vector<boost::shared_ptr<Function<Bool> > >
: pred = bool_operator [tagset, vars] {
ret_v->push_back(pred);
}
(
COMMA pred = bool_operator [tagset, vars] {
ret_v->push_back(pred);
}
)*
// ----------------------------------------------------------------------------
// And operator.
bool_and
[const Corpus2::Tagset& tagset, Variables& vars]
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 [tagset, vars] RPAREN {
op.reset(new And(ret_v));
// ----------------------------------------------------------------------------
// Or operator
bool_or
[const Corpus2::Tagset& tagset, Variables& vars]
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 [tagset, vars] RPAREN {
op.reset(new Or(ret_v));
// ----------------------------------------------------------------------------
// Nor/Not operator
bool_nor
[const Corpus2::Tagset& tagset, Variables& vars]
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 [tagset, vars] RPAREN {
op.reset(new Nor(ret_v));
// ----------------------------------------------------------------------------
// Wrapper for bool value and bool variable
bool_var_val
[const Corpus2::Tagset& /*tagset*/, Variables& vars]
returns [boost::shared_ptr<Function<Bool> > op]
: op = bool_value
| op = bool_variable [vars]
// ----------------------------------------------------------------------------
// Regex operator
bool_regex
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Function<Bool> > op]
{
boost::shared_ptr<Function<StrSet> > expr;
}
: "regex"
LPAREN
expr = strset_operator [tagset, vars] COMMA reg: STRING
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
RPAREN {
op.reset(new Regex(expr, token_ref_to_ustring(reg)));
}
;
// ----------------------------------------------------------------------------
// Input/output operator
bool_inout
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Function<Bool> > op]
{
boost::shared_ptr<Function<Position> > ret_pos;
}
: "inside" LPAREN ret_pos = position_operator [tagset, vars] RPAREN {
op.reset(new IsInside(ret_pos));
}
| "outside" LPAREN ret_pos = position_operator [tagset, vars] RPAREN {
op.reset(new IsOutside(ret_pos));
}
;
// ----------------------------------------------------------------------------
// if (Bool, Bool, Bool)
// ? Bool ? Bool : False
bool_condition
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Function<Bool> > op]
{
boost::shared_ptr<Function<Bool> > test, p_true, p_false;
}
: "if" LPAREN test = bool_operator [tagset, vars] COMMA
p_true = bool_operator [tagset, vars]
(COMMA p_false = bool_operator [tagset, vars])?
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 [tagset, vars]
Q_MARK
test = bool_operator [tagset, vars] {
op.reset(new Conditional<Bool>(test, p_true));
}
;
// ----------------------------------------------------------------------------
// Equal operator
equal_operator
[const Corpus2::Tagset& tagset, Variables& vars]
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;
: "equal" LPAREN
(position_operator [tagset, vars]) =>
p1 = position_operator [tagset, vars] COMMA
p2 = position_operator [tagset, vars] {
op.reset(new Equals<Position>(p1, p2));
|
(symset_operator [tagset, vars]) =>
t1 = symset_operator [tagset, vars] COMMA
t2 = symset_operator [tagset, vars] {
op.reset(new Equals<TSet>(t1, t2));
}
)
|
(strset_operator [tagset, vars]) =>
s1 = strset_operator [tagset, vars] COMMA
s2 = strset_operator [tagset, vars] {
op.reset(new Equals<StrSet>(s1, s2));
}
)
|
(
b1 = bool_operator [tagset, vars] COMMA
b2 = bool_operator [tagset, vars] {
op.reset(new Equals<Bool>(b1, b2));
// ----------------------------------------------------------------------------
// In operator
in_operator
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Function<Bool> > op]
boost::shared_ptr<Function<TSet> > t1, t2;
boost::shared_ptr<Function<StrSet> > s1, s2;
Paweł Kędzia
committed
}
:
"in" LPAREN
(symset_operator [tagset, vars]) =>
t1 = symset_operator [tagset, vars] COMMA
t2 = symset_operator [tagset, vars] {
op.reset(new IsSubsetOf<TSet>(t1, t2));
s1 = strset_operator [tagset, vars] COMMA
s2 = strset_operator [tagset, vars] {
op.reset(new IsSubsetOf<StrSet>(s1, s2));
;
// ----------------------------------------------------------------------------
// Inter operator
inter_operator
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Function<Bool> > op]
boost::shared_ptr<Function<TSet> > t1, t2;
boost::shared_ptr<Function<StrSet> > s1, s2;
:
"inter" LPAREN
(symset_operator [tagset, vars]) =>
t1 = symset_operator [tagset, vars] COMMA
t2 = symset_operator [tagset, vars] {
op.reset(new Intersects<TSet>(t1, t2));
s1 = strset_operator [tagset, vars] COMMA
s2 = strset_operator [tagset, vars] {
op.reset(new Intersects<StrSet>(s1, s2));
ilor
committed
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
// ----------------------------------------------------------------------------
// Debug printing:
debug_print_operator
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Function<Bool> > ret]
{
boost::shared_ptr<FunctionBase> v;
}
: "debug" LPAREN
(
(position_operator [tagset, vars]) =>
(
v = position_operator [tagset, vars] {
ret.reset(new DebugPrint(v));
}
)
|
(symset_operator [tagset, vars]) =>
(
v = symset_operator [tagset, vars] {
ret.reset(new DebugPrint(v));
}
)
|
(strset_operator [tagset, vars]) =>
(
v = strset_operator [tagset, vars] {
ret.reset(new DebugPrint(v));
}
)
|
(
v = bool_operator [tagset, vars] {
ret.reset(new DebugPrint(v));
}
)
)
RPAREN
;
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
// ----------------------------------------------------------------------------
// Iterations:
bool_iteration
[const Corpus2::Tagset& tagset, Variables& vars]
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 [tagset, vars] COMMA
rpos = position_operator [tagset, vars] COMMA
pacc = position_variable_acc [vars] COMMA
expr = bool_operator [tagset, vars]
RPAREN {
ret.reset(new Only(lpos, rpos, *pacc, expr));
}
| "atleast" LPAREN
lpos = position_operator [tagset, vars] COMMA
rpos = position_operator [tagset, vars] COMMA
pacc = position_variable_acc [vars] COMMA
expr = bool_operator [tagset, vars] 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 [tagset, vars] COMMA
lpos = position_operator [tagset, vars] COMMA
pacc = position_variable_acc [vars] COMMA
expr = bool_operator [tagset, vars]
RPAREN {
ret.reset(new LeftLook(lpos, rpos, *pacc, expr));
}
| "rlook" LPAREN
lpos = position_operator [tagset, vars] COMMA
rpos = position_operator [tagset, vars] COMMA
pacc = position_variable_acc [vars] COMMA
expr = bool_operator [tagset, vars]
RPAREN {
ret.reset(new RightLook(lpos, rpos, *pacc, expr));
}
;
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
// ----------------------------------------------------------------------------
// Agreement operator: agr, agrpp, wagr
bool_agreement
[const Corpus2::Tagset& tagset, Variables& vars]
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 [tagset, vars] COMMA
rpos = position_operator [tagset, vars] COMMA
expr = symset_operator [tagset, vars]
RPAREN {
ret.reset(new StrongAgreement(lpos, rpos, expr, tagset));
}
| "agrpp" LPAREN
lpos = position_operator [tagset, vars] COMMA
rpos = position_operator [tagset, vars] COMMA
expr = symset_operator [tagset, vars]
RPAREN {
ret.reset(new PointAgreement(lpos, rpos, expr, tagset));
}
| "wagr" LPAREN
lpos = position_operator [tagset, vars] COMMA
rpos = position_operator [tagset, vars] COMMA
expr = symset_operator [tagset, vars]
RPAREN {
ret.reset(new WeakAgreement(lpos, rpos, expr, tagset));
}
;
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
// ----------------------------------------------------------------------------
// Parse operator on L1 level
bool_phrase
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Function<Bool> > ret]
: ret = bool_phrase_annotation [tagset, vars]
| ret = bool_phrase_iteration [tagset, vars]
;
// ----------------------------------------------------------------------------
// Annotation operator: phrase, phrase_beg, phrase_end, phrase_whole, phrase_pp
bool_phrase_annotation
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Function<Bool> > ret]
{
boost::shared_ptr<Function<Position> > lpos, rpos;
}
: "phrase" LPAREN
lpos = position_operator [tagset, vars] COMMA n1: STRING
RPAREN {
// TODO
}
| "phrase_beg" LPAREN
lpos = position_operator [tagset, vars] COMMA n2: STRING
RPAREN {
// TODO
}
| "phrase_end" LPAREN
lpos = position_operator [tagset, vars] COMMA n3: STRING
RPAREN {
// TODO
}
| "phrase_whole" LPAREN
lpos = position_operator [tagset, vars] COMMA
rpos = position_operator [tagset, vars] COMMA n4: STRING
RPAREN {
// TODO
}
| "phrase_pp" LPAREN
lpos = position_operator [tagset, vars] COMMA
rpos = position_operator [tagset, vars] COMMA n5: STRING
RPAREN {
// TODO
}
;
// ----------------------------------------------------------------------------
// Phrase iteration operator: lphrase, rphrase
bool_phrase_iteration
[const Corpus2::Tagset& tagset, Variables& vars]
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 [tagset, vars] COMMA
var_position = position_variable [vars] COMMA
n1: STRING
RPAREN {
// TODO
}
| "rphrase" LPAREN
position = position_operator [tagset, vars] COMMA
var_position = position_variable [vars] COMMA
n2: STRING
RPAREN {
// TODO
}
;
// ----------------------------------------------------------------------------
// Setvar operator
// Returns boost::shared_ptr<Function<Bool> >
// ----------------------------------------------------------------------------
setvar_operator
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Function<Bool> > ret]
: "setvar" LPAREN
(
ret = position_setvar [tagset, vars]
| ret = bool_setvar [tagset, vars]
| ret = strset_setvar [tagset, vars]
| ret = symset_setvar [tagset, vars]
)
RPAREN
;
// ----------------------------------------------------------------------------
// Setvar for position
position_setvar
[const Corpus2::Tagset& tagset, Variables& vars]
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 [vars]
COMMA
ret_op = position_operator [tagset, vars] {
op.reset(new VarSetter<Position>(*ret_acc, ret_op));
// ----------------------------------------------------------------------------
// Setvar for bool
bool_setvar
[const Corpus2::Tagset& tagset, Variables& vars]
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 [vars]
COMMA
ret_op = bool_operator [tagset, vars] {
op.reset(new VarSetter<Bool>(*ret_acc, ret_op));
// ----------------------------------------------------------------------------
// Setvar for strset
strset_setvar
[const Corpus2::Tagset& tagset, Variables& vars]
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 [vars]
COMMA
ret_op = strset_operator [tagset, vars] {
op.reset(new VarSetter<StrSet>(*ret_acc, ret_op));
Paweł Kędzia
committed
}
// ----------------------------------------------------------------------------
// Setvar for symset
symset_setvar
[const Corpus2::Tagset& tagset, Variables& vars]
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 [vars]
COMMA
ret_op = symset_operator [tagset, vars] {
op.reset(new VarSetter<TSet>(*ret_acc, ret_op));
}
;
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Tagging actions and rules:
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Single action such as select, delete, relabel or unify
action
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<TagAction> act]
: act = action_select [tagset, vars]
| act = action_delete [tagset, vars]
| act = action_relabel [tagset, vars]
| act = action_unify [tagset, vars]
| act = action_mark [tagset, vars]
| act = action_unmark [tagset, vars]
// Action sequence - the actions are separated with commas:
// select(...), select(...), delete(...)
action_sequence
[const Corpus2::Tagset& tagset, Variables& vars]
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[tagset, vars] {
v_act->push_back(act);
}
(
COMMA act = action[tagset, vars] {
v_act->push_back(act);
}
)*
;
// ----------------------------------------------------------------------------
// Single rule:
// rule(NAME, ACTIONS) or rule(NAME, COND, ACTIONS)
rule
[const Corpus2::Tagset& tagset, Variables& vars]
{
boost::shared_ptr<Function<Bool> > condition;
boost::shared_ptr<std::vector<boost::shared_ptr<TagAction> > > actions;
: "rule" LPAREN name: STRING COMMA
(condition = bool_operator [tagset, vars] COMMA)?
actions = action_sequence [tagset, vars]
RPAREN {
if (condition) {
rle.reset(
new TagRule(token_ref_to_std_string(name), vars, actions, condition));
}
else {
rle.reset(
new TagRule(token_ref_to_std_string(name), vars, actions));
: "rule" LPAREN name: STRING COMMA
(
(bool_operator[tagset, vars]) =>
(
condition = bool_operator [tagset, vars] COMMA
actions = action_sequence [tagset, vars] {
// rule(NAME, COND, ACTIONS)
rle.reset(
new TagRule(token_ref_to_std_string(name), vars, actions, condition));
}
)
|
(
actions = action_sequence [tagset, vars] {
// rule(NAME, ACTIONS)
rle.reset(new TagRule(token_ref_to_std_string(name), vars, actions));
}
)
)
RPAREN
;
// Rule sequence
rule_sequence
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<RuleSequence> rule_seq]
{
// FIXME czy tutaj przypadkiem nie powinno byc shared_ptr?
}
: rle = rule [tagset, vars] {
}
(
COMMA rle = rule [tagset, vars] {
}
)*
;
// Temporary name.
// This is wrapper for rule_sequence in rules section in the wccl file
rules
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<RuleSequence> rule_seq]
: "rules" LPAREN rule_seq = rule_sequence [tagset, vars] RPAREN {
//
}
;
// ----------------------------------------------------------------------------
// 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, pos));
}
)
|
(
condition = bool_operator [tagset, vars] {
// select(condition);
action.reset(new Select(condition));
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
}
)
)
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);
}
)
|
(
condition = bool_operator [tagset, vars] {
// delete(condition);
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
}
)
)
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));
}
;
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
// ----------------------------------------------------------------------------
// Mark action
action_mark
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Mark> action]
{
boost::shared_ptr<Function<Position> > pos_begin, pos_end, pos_head;
}
: "mark" LPAREN
pos_begin = position_operator [tagset, vars] COMMA
pos_end = position_operator [tagset, vars] COMMA
(pos_head = position_operator [tagset, vars] COMMA)?
chan_name: STRING
RPAREN {
action.reset(new Mark(pos_begin, pos_end, pos_head, ((antlr::Token*)chan_name)->getText()));
}
;
// ----------------------------------------------------------------------------
// Unmark action
action_unmark
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Unmark> action]
{
boost::shared_ptr<Function<Position> > pos;
}
: "unmark" LPAREN
pos = position_operator [tagset, vars] COMMA
chan_name: STRING
RPAREN {
action.reset(new Unmark(pos, ((antlr::Token*)chan_name)->getText()));
}
;
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Match rules
// Returns boost::shared_ptr<Expression>
match_rule_operator
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Expression> ret_op]
{
//
}
: ret_op = match_apply_operator [tagset, vars]
;
// Match apply operator:
// apply(match(), cond(conditions), actions(actions))
// apply(match(), actions(actions))
// Returns boost::shared_ptr<ApplyOperator>
match_apply_operator
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<ApplyOperator> ret_op]
{
VariableAccessor<Match> matches = vars.create_accessor<Match>("_M");;
boost::shared_ptr<const MatchOperator> match_op;
boost::shared_ptr<std::vector<boost::shared_ptr<MatchAction> > > actions;
boost::shared_ptr<std::vector<boost::shared_ptr<Function<Bool> > > > conditions;
: "apply" LPAREN
match_op = match_operator[tagset, vars] COMMA
("cond" LPAREN conditions = bool_operator_comma_sep [tagset, vars] RPAREN COMMA)?
"actions" LPAREN actions = match_action_comma_sep [tagset, vars] RPAREN
RPAREN {
if (conditions) {
ret_op.reset(
new ApplyOperator(matches, match_op, actions, conditions)
);
}
else {
ret_op.reset(
new ApplyOperator(matches, match_op, actions)
);
}
}
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
;
// Match operator: match(match_conditions)
// Returns boost::shared_ptr<MatchOperator>
match_operator
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<MatchOperator> op]
{
boost::shared_ptr<ConjConditions> match_cond;
}
: "match" LPAREN match_cond = match_condition [tagset,vars] RPAREN {
op.reset(new MatchOperator(match_cond));
}
;
// Match conditions. Wrapper for vector of the match conditions
match_condition
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<ConjConditions> condition]
{
std::vector<boost::shared_ptr<const MatchCondition> > m_cond;
}
: m_cond = match_condition_in [tagset, vars] {
condition.reset(new ConjConditions(m_cond));
}
;
// Match conditions.
// Retutns std::vector< boost::shared_ptr<const MatchCondition> >
match_condition_in
[const Corpus2::Tagset& tagset, Variables& vars]
returns [std::vector< boost::shared_ptr<const MatchCondition> > ret]
{
boost::shared_ptr<const MatchCondition> r_cond;
}
: r_cond = match_cond_all[tagset, vars] {
ret.push_back(r_cond);
}
(
COMMA
r_cond = match_cond_all[tagset, vars] {
ret.push_back(r_cond);
}
)*
;
// One of the match condition
// Returns boost::shared_ptr<const MatchCondition>
match_cond_all
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<const MatchCondition> ret]
: ret = match_cond_optional [tagset, vars]
| ret = match_cond_repeate [tagset, vars]
;
// Match condition - optional
// Returns boost::shared_ptr<OptionalMatch>
match_cond_optional
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<OptionalMatch> mtch]
{
boost::shared_ptr<ConjConditions> m_cond;
}
: "optional" LPAREN m_cond = match_condition [tagset, vars] RPAREN {
mtch.reset(new OptionalMatch(m_cond));
}
;
// Match condition - repeat
// Returns boost::shared_ptr<RepeatedMatch>
match_cond_repeate
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<RepeatedMatch> mtch]
{
boost::shared_ptr<ConjConditions> m_cond;
}
: "repeat" LPAREN m_cond = match_condition [tagset, vars] RPAREN {
mtch.reset(new RepeatedMatch(m_cond));
}
;
// ----------------------------------------------------------------------------
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
// Match actions. Match action can be mark or unmark
// Returns boost::shared_ptr<MatchAction>
match_action
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<MatchAction> m_act]
: m_act = match_mark_action [tagset, vars]
| m_act = match_unmark_action [tagset, vars]
;
// Match mark action
// Returns ???
match_mark_action
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<MatchAction> m_act]
: "mark" LPAREN /* TODO */ RPAREN
;
// Match unmark action
// Returns ???
match_unmark_action
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<MatchAction> m_act]
: "unmark" LPAREN /* TODO */ RPAREN
;
// Match action separated by comma
// Returns boost::shared_ptr<std::vector<boost::shared_ptr<MatchAction> > >
match_action_comma_sep
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<std::vector<boost::shared_ptr<MatchAction> > > r_vec]
{
boost::shared_ptr<MatchAction> act;
r_vec.reset(
new std::vector<boost::shared_ptr<MatchAction> >
);
}
: act = match_action [tagset, vars] {
r_vec->push_back(act);
}
(
COMMA act = match_action [tagset, vars] {
r_vec->push_back(act);
}
)*
;
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
class ANTLRLexer extends Lexer;
options {
exportVocab = ANTLRExpr;
charVocabulary = '\3'..'\377';
: '"'! (~('"' | '\n' | '\r'))* '"'!
| '\''! (~('\'' | '\n' | '\r'))* '\''!
: ('-'|'+') (' '!|'\t'!)* ('0'..'9')+
UNSIGNED_INT
options {
paraphrase = "Unsigned integer";
}