Newer
Older
//don't try to add all the headers inside our namespace
#include <libwccl/parser/ParserException.h>
#include <libwccl/parser/parsingscope.h>
#include <cstdio>
#include <antlr/Token.hpp>
#include <boost/lexical_cast.hpp>
// values/variables
#include <libwccl/variables.h>
#include <libwccl/values/bool.h>
#include <libwccl/values/tset.h>
#include <libwccl/values/strset.h>
#include <libwccl/values/position.h>
// sentence context
#include <libwccl/sentencecontext.h>
// operators
#include <libwccl/ops/operator.h>
#include <libwccl/ops/functions/constant.h>
#include <libwccl/ops/functions/vargetter.h>
#include <libwccl/ops/functions/conditional.h>
#include <libwccl/ops/functions/setops.h>
#include <libwccl/ops/functions/bool/varsetter.h>
ilor
committed
#include <libwccl/ops/functions/bool/predicates/debug.h>
#include <libwccl/ops/functions/bool/predicates/ambiguous.h>
#include <libwccl/ops/functions/bool/predicates/issingular.h>
#include <libwccl/ops/functions/bool/predicates/or.h>
#include <libwccl/ops/functions/bool/predicates/nor.h>
#include <libwccl/ops/functions/bool/predicates/and.h>
#include <libwccl/ops/functions/bool/predicates/regex.h>
#include <libwccl/ops/functions/bool/predicates/intersects.h>
#include <libwccl/ops/functions/bool/predicates/issubsetof.h>
#include <libwccl/ops/functions/bool/predicates/isinside.h>
#include <libwccl/ops/functions/bool/predicates/isoutside.h>
#include <libwccl/ops/functions/bool/predicates/isempty.h>
#include <libwccl/ops/functions/bool/predicates/equals.h>
#include <libwccl/ops/functions/bool/predicates/weakagreement.h>
#include <libwccl/ops/functions/bool/predicates/pointagreement.h>
#include <libwccl/ops/functions/bool/predicates/strongagreement.h>
#include <libwccl/ops/functions/bool/predicates/anntoken.h>
#include <libwccl/ops/functions/strset/affix.h>
#include <libwccl/ops/functions/strset/getorth.h>
#include <libwccl/ops/functions/strset/toupper.h>
#include <libwccl/ops/functions/strset/tolower.h>
#include <libwccl/ops/functions/strset/getlemmas.h>
#include <libwccl/ops/functions/strset/lextranslator.h>
Adam Radziszewski
committed
#include <libwccl/ops/functions/strset/anninter.h>
#include <libwccl/ops/functions/tset/getsymbols.h>
#include <libwccl/ops/functions/tset/getwordclass.h>
#include <libwccl/ops/functions/tset/getsymbolsinrange.h>
#include <libwccl/ops/functions/position/relativeposition.h>
#include <libwccl/ops/functions/position/lasttoken.h>
#include <libwccl/ops/functions/position/firsttoken.h>
#include <libwccl/ops/functions/bool/iterations/only.h>
#include <libwccl/ops/functions/bool/iterations/atleast.h>
#include <libwccl/ops/functions/bool/iterations/leftlook.h>
#include <libwccl/ops/functions/bool/iterations/rightlook.h>
#include <libwccl/ops/functions/bool/iterations/skip.h>
ilor
committed
#include <libwccl/ops/matchrule.h>
#include <libwccl/ops/tagrulesequence.h>
#include <libwccl/ops/tagactions/unify.h>
#include <libwccl/ops/tagactions/delete.h>
#include <libwccl/ops/tagactions/select.h>
#include <libwccl/ops/tagactions/relabel.h>
#include <libwccl/ops/tagactions/mark.h>
#include <libwccl/ops/tagactions/unmark.h>
// Match operators
#include <libwccl/values/tokenmatch.h>
#include <libwccl/values/annotationmatch.h>
#include <libwccl/values/matchvector.h>
#include <libwccl/ops/match/applyoperator.h>
#include <libwccl/ops/match/conditions/optionalmatch.h>
#include <libwccl/ops/match/conditions/repeatedmatch.h>
#include <libwccl/ops/match/conditions/isannotatedas.h>
#include <libwccl/ops/match/conditions/matchtext.h>
#include <libwccl/ops/match/conditions/conjconditions.h>
#include <libwccl/ops/match/conditions/tokencondition.h>
#include <libwccl/ops/match/conditions/oneof.h>
#include <libwccl/ops/match/conditions/longest.h>
#include <libwccl/ops/match/actions/markmatch.h>
#include <libwccl/ops/match/actions/unmarkmatch.h>
#include <libwccl/ops/match/actions/setpropmatch.h>
#include <libwccl/ops/match/actions/overwritematch.h>
#include <libwccl/ops/functions/match/submatch.h>
// Wccl whole file syntax
#include <libwccl/wcclfile.h>
#include <libwccl/lexicon/lexiconparser.h>
// Unicode String
#include <unicode/uniset.h>
#include <unicode/unistr.h>
ANTLR_BEGIN_NAMESPACE(Wccl)
Paweł Kędzia
committed
genHashLines = false;
namespace = "Wccl";
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
Paweł Kędzia
committed
exportVocab = ANTLRExpr;
const UnicodeString token_ref_to_ustring(antlr::RefToken& rstr) const {
return UnicodeString::fromUTF8(((antlr::Token*)rstr)->getText().c_str()).unescape();
Paweł Kędzia
committed
const UnicodeString str_token_ref_to_ustring(antlr::RefToken& rstr) const {
UnicodeString ret_ustr, ustr = token_ref_to_ustring(rstr);
if (ustr.length() < 3) {
return "";
}
ustr.extract(1, ustr.length() - 2, ret_ustr);
return ret_ustr;
}
Paweł Kędzia
committed
//
const std::string str_token_rem_grav(antlr::RefToken& rstr) const {
size_t len = 0;
std::string ret = token_ref_to_std_string(rstr);
if ((len = ret.length()) < 2) {
return ret;
}
if (ret[0] == '`' && ret[len - 1] == '`') {
return ret.substr(1, len - 2);
}
return ret;
}
//
const std::string token_ref_to_std_string(antlr::RefToken& rstr) const {
return (((antlr::Token*)rstr)->getText());
//
int token_ref_to_int(antlr::RefToken& rstr) {
return atoi(((antlr::Token*)rstr)->getText().c_str());
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// ----------------------------------------------------------------------------
// Rule for parsing string set operator with scope.
// Returns boost::shared_ptr<Operator<StrSet> >
parse_strset_operator
Paweł Kędzia
committed
[const Corpus2::Tagset &tagset]
returns [boost::shared_ptr<Operator<StrSet> > res]
Lexicons empty_lex;
ParsingScope scope(tagset, empty_lex);
: res = functional_operator_strset [scope]
EOF
// ----------------------------------------------------------------------------
// Rule for parsing bool operator with scope.
// Returns boost::shared_ptr<Operator<Bool> >
parse_bool_operator
Paweł Kędzia
committed
[const Corpus2::Tagset &tagset]
returns [boost::shared_ptr<Operator<Bool> > res]
Lexicons empty_lex;
ParsingScope scope(tagset, empty_lex);
: res = functional_operator_bool [scope]
EOF
// ----------------------------------------------------------------------------
// Rule for parsing symbol set operator with scope.
// Returns boost::shared_ptr<Operator<TSet> >
parse_symset_operator
Paweł Kędzia
committed
[const Corpus2::Tagset &tagset]
returns [boost::shared_ptr<Operator<TSet> > res]
Lexicons empty_lex;
ParsingScope scope(tagset, empty_lex);
: res = functional_operator_symset [scope]
EOF
// ----------------------------------------------------------------------------
// Rule for parsing position operator with scope.
// Returns boost::shared_ptr<Operator<Position> >
parse_position_operator
returns [boost::shared_ptr<Operator<Position> > res]
Lexicons empty_lex;
ParsingScope scope(tagset, empty_lex);
: res = functional_operator_position [scope]
EOF
;
// ----------------------------------------------------------------------------
// Rule for parsing match operator with scope.
// Returns boost::shared_ptr<Operator<Position> >
parse_match_operator
[const Corpus2::Tagset &tagset]
returns [boost::shared_ptr<Operator<Match> > res]
{
Lexicons empty_lex;
ParsingScope scope(tagset, empty_lex);
: res = functional_operator_match [scope]
EOF
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Rule for parsing single WCCL Rule
Adam Radziszewski
committed
parse_single_tag_rule
[const Corpus2::Tagset &tagset]
Lexicons empty_lex;
ParsingScope scope(tagset, empty_lex);
Adam Radziszewski
committed
: rle = tag_rule [scope]
Adam Radziszewski
committed
// Rule for parsing tag rule section in the wccl file
// Returns boost::shared_ptr<TagRuleSequence>
Adam Radziszewski
committed
parse_tag_rule_sequence
[const Corpus2::Tagset& tagset]
returns [boost::shared_ptr<TagRuleSequence> rule_seq]
Lexicons empty_lex;
ParsingScope scope(tagset, empty_lex);
Adam Radziszewski
committed
: rule_seq = tag_rules[scope]
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Rule for parsing the match rules
ilor
committed
// Returns boost::shared_ptr<Matching::MatchRule>
parse_match_rule
[const Corpus2::Tagset& tagset]
ilor
committed
returns [boost::shared_ptr<Matching::MatchRule> ret_match]
Lexicons empty_lex;
ParsingScope scope(tagset, empty_lex);
: ret_match = match_rule_operator[scope]
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Rule for parsing wccl files
parse_wccl_file
[const Corpus2::Tagset& tagset, const std::string search_path]
returns [boost::shared_ptr<WcclFile> wccl_file]
{
wccl_file = boost::make_shared<WcclFile>(tagset, search_path);
: (imports_section [*wccl_file])?
(wccl_file_section [*wccl_file])+
EOF
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// VALUES
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// ----------------------------------------------------------------------------
// Single or multiple (comma separated) elements in string set, may be:
// 'a' "a" [] ['a'] ['a', 'b'] ["a"] ["a", "b"] ['a', "b"]
// Parsing strset literal and returning plain strset value.
// Returns boost::shared_ptr<StrSet>
strset_literal
returns [boost::shared_ptr<StrSet> s_set]
Paweł Kędzia
committed
{
s_set.reset(new StrSet());
Paweł Kędzia
committed
}
: s0: STRING {
s_set->insert(token_ref_to_ustring(s0));
| LBRACKET
(
s1: STRING {
s_set->insert(token_ref_to_ustring(s1));
}
(
COMMA s2: STRING {
s_set->insert(token_ref_to_ustring(s2));
}
)*
)?
RBRACKET
;
// Returns boost::shared_ptr<Constant<StrSet> >
strset_value
returns [boost::shared_ptr<Constant<StrSet> > val]
boost::shared_ptr<StrSet> set;
: set = strset_literal {
val.reset(new Constant<StrSet>(*set));
Paweł Kędzia
committed
// ----------------------------------------------------------------------------
// Element of sym set. This rule inserts element into symbol set
// using corresponding tagset.
// WARNING! This rule can throw ParserException! Be careful!
symset_elem
[const Corpus2::Tagset& tagset, boost::shared_ptr<TSet>& t_set]
}
catch(Corpus2::TagParseError &e) {
throw(ParserException(e.info()));
}
// Symset literal. Symset element may be:
// a, `a ` (this is guaranteed by lexer rule - SYMBOL) or {a} {`a`} {a, b}
// {`a`, `b`} {a, `b`} {`a`, b}
// Parsing symset literal and returning plain symset value.
// Returns boost::shared_ptr<TSet>
symset_literal
returns [boost::shared_ptr<TSet> t_set]
Paweł Kędzia
committed
{
t_set.reset(new TSet());
Paweł Kędzia
committed
}
: symset_elem [tagset, t_set]
(
symset_elem [tagset, t_set] (COMMA symset_elem [tagset, t_set])*
)?
// Symset value, as constant symbol set
// Returns boost::shared_ptr<Constant<TSet> >
symset_value
returns [boost::shared_ptr<Constant<TSet> > val]
boost::shared_ptr<TSet> set;
: set = symset_literal [tagset] {
val.reset(new Constant<TSet>(*set));
Paweł Kędzia
committed
// ----------------------------------------------------------------------------
// Bool literal. May be True or False. Parsing bool literal and returning
// plain bool value.
// Returns boost::shared_ptr<Bool>
Paweł Kędzia
committed
bool_literal
returns [boost::shared_ptr<Bool> val]
: "True" { val.reset(new Bool(Bool(true ))); }
| "False" { val.reset(new Bool(Bool(false))); }
Paweł Kędzia
committed
;
// Bool value, as constat bool Value
// Returns boost::shared_ptr<Constant<Bool> >
bool_value
returns [boost::shared_ptr<Constant<Bool> > val]
Paweł Kędzia
committed
{
boost::shared_ptr<Bool> bool_lit;
Paweł Kędzia
committed
}
: bool_lit = bool_literal {
val.reset(new Constant<Bool>(*bool_lit));
Paweł Kędzia
committed
}
Paweł Kędzia
committed
// ----------------------------------------------------------------------------
// Position literal may be:
// (+|-)?(0-9)+ or begin or end or nowhere
// Parsing position literal and returning plain position value.
// returns boost::shared_ptr<Position>
Paweł Kędzia
committed
position_literal
returns [boost::shared_ptr<Position> val]
val.reset(new Position(Position(i)));
val.reset(new Position(Position(Position::Begin)));
Paweł Kędzia
committed
}
val.reset(new Position(Position(Position::End)));
val.reset(new Position(Position(Position::Nowhere)));
Paweł Kędzia
committed
}
;
// Position as constant position value
// Returns boost::shared_ptr<Constant<Position> >
Paweł Kędzia
committed
position_value
returns [boost::shared_ptr<Constant<Position> > val]
Paweł Kędzia
committed
{
boost::shared_ptr<Position> pos_lit;
Paweł Kędzia
committed
}
: pos_lit = position_literal {
val.reset(new Constant<Position>(*pos_lit));
// ----------------------------------------------------------------------------
// Value used into match operator such as TOK[position] and ANN[position, name]
// Returns boost::shared_ptr<Match>
Adam Wardynski
committed
match_literal
returns [boost::shared_ptr<Match> val]
{
boost::shared_ptr<MatchData> m;
}
Adam Wardynski
committed
: m = match_data_literal {
val.reset(new Match(m));
}
;
// Constant match value
// Returns boost::shared_ptr<Constant<Match> >
match_value_const
returns [boost::shared_ptr<Constant<Match> > val]
{
boost::shared_ptr<Match> m;
}
Adam Wardynski
committed
: m = match_literal {
val.reset(new Constant<Match>(*m));
}
;
// ----------------------------------------------------------------------------
// Value used into match operator such as TOK[position] and ANN[position, name]
// Returns boost::shared_ptr<MatchData>
Adam Wardynski
committed
match_data_literal
returns [boost::shared_ptr<MatchData> val]
Adam Wardynski
committed
: val = token_match_literal
| val = ann_match_literal
| val = match_vector_literal
Adam Wardynski
committed
// token match literal - TOK[position]
// Returns boost::shared_ptr<TokenMatch>
Adam Wardynski
committed
token_match_literal
returns [boost::shared_ptr<TokenMatch> val]
{
}
: "TOK" LBRACKET u: UNSIGNED_INT RBRACKET {
val.reset(new TokenMatch(token_ref_to_int(u)));
Adam Wardynski
committed
// annotation match literal - ANN[position, name]
// Returns boost::shared_ptr<AnnotationMatch>
Adam Wardynski
committed
ann_match_literal
returns [boost::shared_ptr<AnnotationMatch> val]
{
}
: "ANN" LBRACKET u : UNSIGNED_INT COMMA channel : STRING RBRACKET {
val.reset(new AnnotationMatch(token_ref_to_int(u), token_ref_to_std_string(channel)));
Adam Wardynski
committed
// annotation match vector literal: MATCH() or MATCH(token, ann, MATCH())
// Returns boost::shared_ptr<MatchVector>
Adam Wardynski
committed
match_vector_literal
returns [boost::shared_ptr<MatchVector> val]
{
val.reset(new MatchVector());
}
Adam Wardynski
committed
: "MATCH" LPAREN (match_vector_literal_item[val])? RPAREN
;
// Body of the MATCH value. It only adds vector items to the MatchVector
// Item may be single or multiple
Adam Wardynski
committed
match_vector_literal_item [boost::shared_ptr<MatchVector>& mvector]
{
boost::shared_ptr<Match> m_val;
}
Adam Wardynski
committed
: m_val = match_literal {
mvector->append(m_val);
}
(
COMMA
Adam Wardynski
committed
m_val = match_literal {
mvector->append(m_val);
}
)*
;
// ----------------------------------------------------------------------------
// Number may be unsigned or signed: 1, +1, -1
number
returns [int ret]
{
ret = 0;
}
: s: SIGNED_INT { ret = token_ref_to_int(s); }
| u: UNSIGNED_INT { ret = token_ref_to_int(u); }
;
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// VARIABLES
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// ----------------------------------------------------------------------------
// Position: $Name
// Get position variable (however, before put into) from variables
// Returns boost::shared_ptr<VariableAccessor<Position> >
[Variables& vars]
returns [boost::shared_ptr<VariableAccessor<Position> > pos_acc]
Paweł Kędzia
committed
: POS_PREFIX n: SYMBOL {
vars.get_put<Position>(str_token_rem_grav(n));
VariableAccessor<Position> acc =
vars.create_accessor<Position>(str_token_rem_grav(n));
pos_acc.reset(new VariableAccessor<Position>(acc));
// VarGetter for Position variable. This rule wrapped position_variable_acc.
// Returs boost::shared_ptr<VarGetter<Position> >
[Variables& vars]
returns [boost::shared_ptr<VarGetter<Position> > op]
boost::shared_ptr<VariableAccessor<Position> > pos_acc;
}
: pos_acc = position_variable_acc [vars] {
op.reset(new VarGetter<Position>(*pos_acc));
Paweł Kędzia
committed
// ----------------------------------------------------------------------------
Paweł Kędzia
committed
// String set, $s:name
// This expression gets variable of StrSet type from the scope's Variables.
// Creates one first if it's not yet there.
//
// Returns boost::shared_ptr<VariableAccessor<StrSet> >
strset_variable_acc
[Variables& vars]
returns [boost::shared_ptr<VariableAccessor<StrSet> > strset_acc]
Paweł Kędzia
committed
: STR_PREFIX n: SYMBOL {
vars.get_put<StrSet>(str_token_rem_grav(n));
VariableAccessor<StrSet> acc =
vars.create_accessor<StrSet>(str_token_rem_grav(n));
strset_acc.reset(new VariableAccessor<StrSet>(acc));
// Vargetter for StrSet variable. This rule wrapped strset_variable_acc.
// Returns boost::shared_ptr<VarGetter<StrSet> >
strset_variable
[Variables& vars]
returns [boost::shared_ptr<VarGetter<StrSet> > op]
boost::shared_ptr<VariableAccessor<StrSet> > strset_acc;
: strset_acc = strset_variable_acc [vars] {
op.reset(new VarGetter<StrSet>(*strset_acc));
Paweł Kędzia
committed
// ----------------------------------------------------------------------------
Paweł Kędzia
committed
// Symbol set: $t:name
// This expression gets variable of TSet type from the scope's Variables.
// Creates one first if it's not there yet.
//
// Returns boost::shared_ptr<VariableAccessor<TSet> >
symset_variable_acc
[Variables& vars]
returns [boost::shared_ptr<VariableAccessor<TSet> > symset_acc]
Paweł Kędzia
committed
: TST_PREFIX n: SYMBOL {
vars.get_put<TSet>(str_token_rem_grav(n));
VariableAccessor<TSet> acc =
vars.create_accessor<TSet>(str_token_rem_grav(n));
symset_acc.reset(new VariableAccessor<TSet>(acc));
// Vargetter for symbol set variable. This rule wrapped symset_variable_acc
// Returns boost::shared_ptr<VarGetter<TSet> >
symset_variable
[Variables& vars]
returns [boost::shared_ptr<VarGetter<TSet> > op]
boost::shared_ptr<VariableAccessor<TSet> > symset_acc;
: symset_acc = symset_variable_acc [vars] {
op.reset(new VarGetter<TSet>(*symset_acc));
Paweł Kędzia
committed
// ----------------------------------------------------------------------------
Paweł Kędzia
committed
// Bool: $b:name
// This expression gets variable of Bool type from the scope's Variables.
// Creates one first if it's not there yet.
// Returns boost::shared_ptr<VariableAccessor<Bool> >
bool_variable_acc
[Variables& vars]
returns [boost::shared_ptr<VariableAccessor<Bool> > bool_acc]
Paweł Kędzia
committed
: BOOL_PREFIX n: SYMBOL {
vars.get_put<Bool>(str_token_rem_grav(n));
VariableAccessor<Bool> acc =
vars.create_accessor<Bool>(str_token_rem_grav(n));
bool_acc.reset(new VariableAccessor<Bool>(acc));
// Vargetter for bool variable. It is only wrapper for bool_variable_acc
// Returns boost::shared_ptr<VarGetter<Bool> >
bool_variable
[Variables& vars]
returns [boost::shared_ptr<VarGetter<Bool> > op]
boost::shared_ptr<VariableAccessor<Bool> > bool_acc;
: bool_acc = bool_variable_acc [vars] {
op.reset(new VarGetter<Bool>(*bool_acc));
// ----------------------------------------------------------------------------
// Match: $m:name
// This expression gets variable of Match type from the scope's Variables.
// Creates one first if it's not there yet.
// 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 variable. 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));
}
;
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Symbol set (tagset) operators
// Returns boost::shared_ptr<Function<TSet> >
///////////////////////////////////////////////////////////////////////////////
symset_operator
returns [boost::shared_ptr<Function<TSet> > ret]
: ret = symset_condition [scope]
| {LA(1)==SYMBOL && LA(2)==LBRACKET}? (ret = symset_getsymbol [scope])
| ret = symset_var_val [scope]
| ret = symset_class [scope]
| ret = symset_range [scope]
| ret = symset_catflt [scope]
| ret = symset_agrflt [scope]
| ret = symset_union [scope]
| ret = symset_intersection [scope]
//
| LPAREN ret = symset_operator [scope] RPAREN
// ----------------------------------------------------------------------------
// comma-separated symset operators
symset_operator_comma_sep
[ParsingScope& scope]
returns
[boost::shared_ptr<std::vector<boost::shared_ptr<Function<TSet> > > > ret_v]
{
boost::shared_ptr<Function<TSet> > pred;
ret_v.reset(
new std::vector<boost::shared_ptr<Function<TSet> > >
);
}
: pred = symset_operator [scope] {
ret_v->push_back(pred);
}
(
COMMA pred = symset_operator [scope] {
ret_v->push_back(pred);
}
)*
;
// ----------------------------------------------------------------------------
// Wrapper from Function<TSet> to Operator<TSet>
functional_operator_symset
[ParsingScope& scope]
returns [boost::shared_ptr<Operator<TSet> > op]
{
boost::shared_ptr<Function<TSet> > body;
}
: body = symset_operator [scope] {
op.reset(new Operator<TSet>(body, scope.variables()));
}
;
// ----------------------------------------------------------------------------
symset_var_val
returns [boost::shared_ptr<Function<TSet> > op]
: op = symset_variable [scope.variables()]
| op = symset_value [scope.tagset()]
// ----------------------------------------------------------------------------
// Condition of the symset value:
// if (Bool, TSet, TSet)
// ? TSet ? Bool : {}
symset_condition
returns [boost::shared_ptr<Function<TSet> > op]
boost::shared_ptr<Function<Bool> > test;
boost::shared_ptr<Function<TSet> > p_true, p_false;
: "if" LPAREN test = bool_operator [scope] COMMA
p_true = symset_operator [scope]
(COMMA p_false = symset_operator [scope])?
RPAREN {
Paweł Kędzia
committed
if (p_false) {
op.reset(new Conditional<TSet>(test, p_true, p_false));
Paweł Kędzia
committed
}
else {
op.reset(new Conditional<TSet>(test, p_true));
Paweł Kędzia
committed
}
}
Paweł Kędzia
committed
| Q_MARK
(p_true = symset_operator [scope])
Paweł Kędzia
committed
Q_MARK
(test = bool_operator [scope]) {
op.reset(new Conditional<TSet>(test, p_true));
Paweł Kędzia
committed
}
// ----------------------------------------------------------------------------
// GetSymbol operator may be cas, m1, f, sg...
// WARNING! This rule can throw ParserException! Be careful!
symset_getsymbol
returns [boost::shared_ptr<Function<TSet> > op]
{
Corpus2::Tag tag;
boost::shared_ptr<Wccl::Function<Position> > position;
}
: t: SYMBOL LBRACKET position = position_operator [scope] RBRACKET {
tag = scope.tagset().parse_symbol(str_token_rem_grav(t));
}
catch(Corpus2::TagParseError &e) {
throw(ParserException(e.info()));
}
op.reset(new Wccl::GetSymbols(tag, position));
}
;
// ----------------------------------------------------------------------------
// Class operator.
symset_class
returns [boost::shared_ptr<Function<TSet> > ret]
{
boost::shared_ptr<Function<Position> > pos;
}
: "class" LBRACKET pos = position_operator [scope] RBRACKET {
ret.reset(new GetWordClass(pos));
}
;
// ----------------------------------------------------------------------------
// Range operator: range(class, begin, end) or range({...}, begin, end)
returns [boost::shared_ptr<Function<TSet> > ret]
{
boost::shared_ptr<TSet> tset;
boost::shared_ptr<Function<Position> > p1, p2;
}
(tset = symset_literal [scope.tagset()] | tag_class: "class") COMMA
p1 = position_operator [scope] COMMA
p2 = position_operator [scope]
ret.reset(new GetSymbolsInRange(Corpus2::Tag::all_pos_mask, p1, p2));
ret.reset(new GetSymbolsInRange(tset->get_value(), p1, p2));
// ----------------------------------------------------------------------------
// Catflt operator
symset_catflt
returns [boost::shared_ptr<Function<TSet> > ret]
{
boost::shared_ptr<Function<TSet> > selector, mask;
boost::shared_ptr<Function<Position> > position;
}
: "catflt" LPAREN
position = position_operator [scope] COMMA
selector = symset_operator [scope] COMMA
mask = symset_operator [scope]
RPAREN {
ret.reset(new CatFilter(position, selector, mask));
}
;
// ----------------------------------------------------------------------------
// Agrflt operator
symset_agrflt
returns [boost::shared_ptr<Function<TSet> > ret]
{
boost::shared_ptr<Function<TSet> > attr, mask;
boost::shared_ptr<Function<Position> > lpos, rpos;
}
: "agrflt" LPAREN
lpos = position_operator [scope] COMMA
rpos = position_operator [scope] COMMA
attr = symset_operator [scope] COMMA
mask = symset_operator [scope]
ret.reset(new AgrFilter(lpos, rpos, attr, mask, scope.tagset()));
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
// ----------------------------------------------------------------------------
// Union operator
symset_union
[ParsingScope& scope]
returns [boost::shared_ptr<Function<TSet> > ret]
{
boost::shared_ptr< std::vector< boost::shared_ptr<Function<TSet> > > > sets;
}
: "union" LPAREN
sets = symset_operator_comma_sep [scope]
RPAREN {
ret.reset(new SetUnion<TSet>(sets));
}
;
// ----------------------------------------------------------------------------
// Intersection operator
symset_intersection
[ParsingScope& scope]
returns [boost::shared_ptr<Function<TSet> > ret]
{
boost::shared_ptr< std::vector< boost::shared_ptr<Function<TSet> > > > sets;
}
: "intersection" LPAREN
sets = symset_operator_comma_sep [scope]
RPAREN {
ret.reset(new SetIntersection<TSet>(sets));
}
;
///////////////////////////////////////////////////////////////////////////////
// Position operator
// Returns boost::shared_ptr<Function<Position> >
///////////////////////////////////////////////////////////////////////////////
position_operator
returns [boost::shared_ptr<Function<Position> > ret]
( ret = position_var_val [scope.variables()]
| ret = position_condition [scope]
| ret = position_first_token [scope]
| ret = position_last_token [scope]
| LPAREN ret = position_operator [scope] RPAREN
)
( // if there is SIGNED_INT after the position, it is actually a relative position
i: SIGNED_INT {
ret.reset(new RelativePosition(ret, token_ref_to_int(i)));
}
)?
;
// ----------------------------------------------------------------------------
// Wrapper from Function<Position> to Operator<Position>
functional_operator_position
[ParsingScope& scope]
returns [boost::shared_ptr<Operator<Position> > op]
{
boost::shared_ptr<Function<Position> > body;
}
: body = position_operator [scope] {
op.reset(new Operator<Position>(body, scope.variables()));
}
;
// ----------------------------------------------------------------------------
// Wrapper for position variable and position value
position_var_val
[Variables& vars]
returns [boost::shared_ptr<Function<Position> > ret]
: ret = position_value
| ret = position_variable [vars]
;
// ----------------------------------------------------------------------------
// Condition of the position value
// if (Bool, Position, Position)
// ? Position ? Bool : 0
position_condition
returns [boost::shared_ptr<Function<Position> > op]
{
boost::shared_ptr<Function<Bool> > test;
boost::shared_ptr<Function<Position> > p_true, p_false;
}
: "if" LPAREN test = bool_operator [scope] COMMA
p_true = position_operator [scope]
(COMMA p_false = position_operator [scope])?
RPAREN {
if (p_false) {
op.reset(new Conditional<Position>(test, p_true, p_false));
}
else {
op.reset(new Conditional<Position>(test, p_true));
}
}
| Q_MARK
p_true = position_operator [scope]
Q_MARK
test = bool_operator [scope] {
op.reset(new Conditional<Position>(test, p_true));
}
// ----------------------------------------------------------------------------
// Taking position of a first token in a match
// first(Match)
position_first_token [ParsingScope& scope]
returns [boost::shared_ptr<Function<Position> > ret]
{
boost::shared_ptr<Function<Match> > m;
}
: "first" LPAREN m = match_operator [scope] RPAREN {
ret.reset(new FirstToken(m));
}
;
// ----------------------------------------------------------------------------
// Taking position of a first token in a match
// last(Match)
position_last_token [ParsingScope& scope]
returns [boost::shared_ptr<Function<Position> > ret]
{
boost::shared_ptr<Function<Match> > m;
}
: "last" LPAREN m = match_operator [scope] RPAREN {
ret.reset(new LastToken(m));
}
;
///////////////////////////////////////////////////////////////////////////////
// Returns boost::shared_ptr<Function<StrSet> >
///////////////////////////////////////////////////////////////////////////////
strset_operator [ParsingScope& scope]
returns [boost::shared_ptr<Function<StrSet> > ret]
: ret = strset_orth [scope]
| ret = strset_base [scope]
| ret = strset_lower [scope]
| ret = strset_upper [scope]
| ret = strset_affix [scope]
| ret = strset_var_val [scope]
| ret = strset_condition [scope]
| ret = strset_union [scope]
| ret = strset_intersection [scope]
Adam Radziszewski
committed
| ret = strset_anninter [scope]
//
| LPAREN ret = strset_operator [scope] RPAREN
;
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
// ----------------------------------------------------------------------------
// comma-separated strset operators
strset_operator_comma_sep
[ParsingScope& scope]
returns
[boost::shared_ptr< std::vector<boost::shared_ptr<Function<StrSet> > > > ret_v]
{
boost::shared_ptr<Function<StrSet> > pred;
ret_v.reset(
new std::vector<boost::shared_ptr<Function<StrSet> > >
);
}
: pred = strset_operator [scope] {
ret_v->push_back(pred);
}
(
COMMA pred = strset_operator [scope] {
ret_v->push_back(pred);
}
)*
;
// ----------------------------------------------------------------------------
// Wrapper from Function<StrSet> to Operator<StrSet>
functional_operator_strset
[ParsingScope& scope]
returns [boost::shared_ptr<Operator<StrSet> > op]
{
boost::shared_ptr<Function<StrSet> > body;
}
: body = strset_operator [scope] {
op.reset(new Operator<StrSet>(body, scope.variables()));
}
;
// ----------------------------------------------------------------------------
// Orth operator.
strset_orth
returns [boost::shared_ptr<Function<StrSet> > ret]
boost::shared_ptr<Function<Position> > pos;
: "orth" LBRACKET pos = position_operator [scope] RBRACKET {
ret.reset(new GetOrth(pos));
// ----------------------------------------------------------------------------
// Base operator.
strset_base
returns [boost::shared_ptr<Function<StrSet> > ret]
boost::shared_ptr<Function<Position> > pos;
: "base" LBRACKET pos = position_operator [scope] RBRACKET {
// ----------------------------------------------------------------------------
// Lower operator.
strset_lower
returns [boost::shared_ptr<Function<StrSet> > ret]
boost::shared_ptr<Function<StrSet> > o_ret;
: "lower" LPAREN o_ret = strset_operator [scope] RPAREN {
ret.reset(new ToLower(o_ret));
// ----------------------------------------------------------------------------
// Upper operator.
strset_upper
returns [boost::shared_ptr<Function<StrSet> > ret]
boost::shared_ptr<Function<StrSet> > o_ret;
: "upper" LPAREN o_ret = strset_operator [scope] RPAREN {
ret.reset(new ToUpper(o_ret));
// ----------------------------------------------------------------------------
// Affix operator.
strset_affix
returns [boost::shared_ptr<Function<StrSet> > ret]
boost::shared_ptr<Function<StrSet> > o_ret;
: "affix" LPAREN
o_ret = strset_operator [scope] COMMA offset = number
RPAREN {
ret.reset(new Affix(o_ret, offset));
}
// ----------------------------------------------------------------------------
// A wrapper for strset value and strset variable
strset_var_val
returns [boost::shared_ptr<Function<StrSet> > op]
: op = strset_value
| op = strset_variable [scope.variables()]
// ----------------------------------------------------------------------------
// Condition of the strset value
// if (Bool, StrSet, StrSet)
// ? StrSet ? Bool : []
strset_condition
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])?
RPAREN {
Paweł Kędzia
committed
if (p_false) {
op.reset(new Conditional<StrSet>(test, p_true, p_false));
Paweł Kędzia
committed
}
else {
op.reset(new Conditional<StrSet>(test, p_true));
Paweł Kędzia
committed
}
Paweł Kędzia
committed
| Q_MARK
p_true = strset_operator [scope]
Paweł Kędzia
committed
Q_MARK
test = bool_operator [scope] {
op.reset(new Conditional<StrSet>(test, p_true));
Paweł Kędzia
committed
}
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
// ----------------------------------------------------------------------------
// Union operator, strset
strset_union
[ParsingScope& scope]
returns [boost::shared_ptr<Function<StrSet> > ret]
{
boost::shared_ptr<std::vector<boost::shared_ptr<Function<StrSet> > > > sets;
}
: "union" LPAREN
sets = strset_operator_comma_sep [scope]
RPAREN {
ret.reset(new SetUnion<StrSet>(sets));
}
;
// ----------------------------------------------------------------------------
// Intersection operator, strset
strset_intersection
[ParsingScope& scope]
returns [boost::shared_ptr<Function<StrSet> > ret]
{
boost::shared_ptr<std::vector<boost::shared_ptr<Function<StrSet> > > > sets;
}
: "intersection" LPAREN
sets = strset_operator_comma_sep [scope]
RPAREN {
ret.reset(new SetIntersection<StrSet>(sets));
}
;
Adam Radziszewski
committed
strset_anninter
[ParsingScope& scope]
returns [boost::shared_ptr<Function<StrSet> > op]
{
boost::shared_ptr<Function<Position> > pos;
boost::shared_ptr<Function<StrSet> > in_strs;
}
: "anninter"
LPAREN
pos = position_operator [scope]
COMMA
in_strs = strset_operator [scope]
RPAREN
{
op.reset(new AnnInter(pos, in_strs));
}
;
strset_lex
[ParsingScope& scope]
returns [boost::shared_ptr<Function<StrSet> > op]
{
boost::shared_ptr<Function<StrSet> > s;
}
: "lex" LPAREN s = strset_operator [scope] COMMA name : STRING RPAREN
{
op.reset(new LexTranslator(
s,
scope.lexicons().get_ptr(token_ref_to_std_string(name))));
}
exception catch [WcclError ex] {
throw ParserException(ex.what());
}
;
///////////////////////////////////////////////////////////////////////////////
// Returns boost::shared_ptr<Function<Bool> >
///////////////////////////////////////////////////////////////////////////////
bool_operator
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]
// setvar:
| ret = setvar_operator [scope]
// empty
| ret = empty_operator [scope]
// equal/in/inter:
| ret = equal_operator [scope]
| ret = in_operator [scope]
| ret = inter_operator [scope]
| ret = bool_iteration [scope]
// agreement
| ret = bool_agreement [scope]
//
| ret = bool_ann [scope]
| ret = bool_annsub [scope]
// singular/amb
| ret = bool_ambiguous [scope]
| ret = bool_singular [scope]
ilor
committed
// debug operators
| ret = debug_print_operator [scope]
| LPAREN ret = bool_operator [scope] RPAREN
// ----------------------------------------------------------------------------
// wrapper from Function<Bool> to Operator<Bool>
functional_operator_bool
[ParsingScope& scope]
returns [boost::shared_ptr<Operator<Bool> > op]
{
boost::shared_ptr<Function<Bool> > body;
}
: body = bool_operator [scope] {
op.reset(new Operator<Bool>(body, scope.variables()));
}
;
// ----------------------------------------------------------------------------
// comma-separated predicates (bool operators)
bool_operator_comma_sep
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 [scope] {
ret_v->push_back(pred);
}
(
COMMA pred = bool_operator [scope] {
ret_v->push_back(pred);
}
)*
// ----------------------------------------------------------------------------
// And operator.
bool_and
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));
// ----------------------------------------------------------------------------
// Or operator
bool_or
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));
// ----------------------------------------------------------------------------
// Nor/Not operator
bool_nor
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
returns [boost::shared_ptr<Function<Bool> > op]
: op = bool_value
| op = bool_variable [scope.variables()]
// ----------------------------------------------------------------------------
// Regex operator
bool_regex
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
returns [boost::shared_ptr<Function<Bool> > op]
{
boost::shared_ptr<Function<Position> > ret_pos;
}
: "inside" LPAREN ret_pos = position_operator [scope] RPAREN {
op.reset(new IsInside(ret_pos));
}
| "outside" LPAREN ret_pos = position_operator [scope] RPAREN {
op.reset(new IsOutside(ret_pos));
}
;
// ----------------------------------------------------------------------------
// if (Bool, Bool, Bool)
// ? Bool ? Bool : False
bool_condition
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]
Q_MARK
test = bool_operator [scope] {
op.reset(new Conditional<Bool>(test, p_true));
}
;
// ----------------------------------------------------------------------------
// Equal operator
equal_operator
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 [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] {
op.reset(new Equals<TSet>(t1, t2));
}
)
|
(strset_operator [scope]) =>
s1 = strset_operator [scope] COMMA
s2 = strset_operator [scope] {
op.reset(new Equals<StrSet>(s1, s2));
}
)
|
(
b1 = bool_operator [scope] COMMA
b2 = bool_operator [scope] {
op.reset(new Equals<Bool>(b1, b2));
// ----------------------------------------------------------------------------
// In operator
in_operator
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 [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));
;
// ----------------------------------------------------------------------------
// Inter operator
inter_operator
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 [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
returns [boost::shared_ptr<Function<Bool> > op]
{
boost::shared_ptr< Function<Match> > match_from;
boost::shared_ptr< Function<Match> > match_to;
}
: "ann" LPAREN
match_from = match_operator [scope] COMMA
(match_to = match_operator [scope] COMMA)?
ilor
committed
channel : STRING
ilor
committed
op.reset(new Ann(match_from, match_to, token_ref_to_std_string(channel)));
ilor
committed
op.reset(new Ann(match_from, token_ref_to_std_string(channel)));
// ----------------------------------------------------------------------------
// Annotation-sub operator.
bool_annsub
returns [boost::shared_ptr<Function<Bool> > op]
{
boost::shared_ptr< Function<Match> > match_from;
boost::shared_ptr< Function<Match> > match_to;
}
: "annsub" LPAREN
match_from = match_operator [scope] COMMA
(match_to = match_operator [scope] COMMA)?
ilor
committed
channel : STRING
ilor
committed
op.reset(new AnnSub(match_from, match_to, token_ref_to_std_string(channel)));
ilor
committed
op.reset(new AnnSub(match_from, token_ref_to_std_string(channel)));
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
// ----------------------------------------------------------------------------
// Ambiguity checking operator
bool_ambiguous
[ParsingScope& scope]
returns [boost::shared_ptr<Function<Bool> > ret]
{
boost::shared_ptr<Function<TSet> > tf;
boost::shared_ptr<Function<StrSet> > sf;
boost::shared_ptr<Function<Position> > pf;
}
: "ambiguous" LPAREN
(
(position_operator [scope]) =>
(
pf = position_operator [scope] {
ret.reset(new IsAmbiguous<Position>(pf));
}
)
|
(symset_operator [scope]) =>
(
tf = symset_operator [scope] {
ret.reset(new IsAmbiguous<TSet>(tf));
}
)
|
(strset_operator [scope]) =>
(
sf = strset_operator [scope] {
ret.reset(new IsAmbiguous<StrSet>(sf));
}
)
)
RPAREN
;
// ----------------------------------------------------------------------------
// Tag singularity checking operator
bool_singular
[ParsingScope& scope]
returns [boost::shared_ptr<Function<Bool> > ret]
{
boost::shared_ptr< Function<TSet> > v;
}
: "singular" LPAREN
v = symset_operator [scope]
RPAREN
{
ret.reset(new IsSingular(v, scope.tagset()));
}
;
ilor
committed
// ----------------------------------------------------------------------------
// Debug printing:
debug_print_operator
ilor
committed
returns [boost::shared_ptr<Function<Bool> > ret]
{
boost::shared_ptr<FunctionBase> v;
}
: "debug" LPAREN
(
(position_operator [scope]) =>
ilor
committed
(
v = position_operator [scope] {
ilor
committed
ret.reset(new DebugPrint(v));
}
)
|
(symset_operator [scope]) =>
ilor
committed
(
v = symset_operator [scope] {
ilor
committed
ret.reset(new DebugPrint(v));
}
)
|
(strset_operator [scope]) =>
ilor
committed
(
v = strset_operator [scope] {
ilor
committed
ret.reset(new DebugPrint(v));
}
)
|
ilor
committed
(
ilor
committed
ret.reset(new DebugPrint(v));
}
)
v = match_operator [scope] {
ret.reset(new DebugPrint(v));
}
)
ilor
committed
)
RPAREN
;
// ----------------------------------------------------------------------------
// Iterations:
bool_iteration
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));
}
| "skip" LPAREN
lpos = position_operator [scope] COMMA
pacc = position_variable_acc [scope.variables()] COMMA
expr = bool_operator [scope] COMMA
offset = number
RPAREN {
ret.reset(new Skip(lpos, *pacc, expr, offset));
}
// ----------------------------------------------------------------------------
// Agreement operator: agr, agrpp, wagr
bool_agreement
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()));
}
| "agrpp" LPAREN
lpos = position_operator [scope] COMMA
rpos = position_operator [scope] COMMA
expr = symset_operator [scope]
ret.reset(new PointAgreement(lpos, rpos, expr, scope.tagset()));
}
| "wagr" LPAREN
lpos = position_operator [scope] COMMA
rpos = position_operator [scope] COMMA
expr = symset_operator [scope]
ret.reset(new WeakAgreement(lpos, rpos, expr, scope.tagset()));
}
;
// ----------------------------------------------------------------------------
// Parse operator on L1 level
bool_phrase
: ret = bool_phrase_annotation [scope]
| ret = bool_phrase_iteration [scope]
;
// ----------------------------------------------------------------------------
// Annotation operator: phrase, phrase_beg, phrase_end, phrase_whole, phrase_pp
bool_phrase_annotation
returns [boost::shared_ptr<Function<Bool> > ret]
{
boost::shared_ptr<Function<Position> > lpos, rpos;
}
Loading full blame...