Skip to content
Snippets Groups Projects
Commit f6af1524 authored by ilor's avatar ilor
Browse files

add parsing of position operators

parent 773fffa0
Branches
No related tags found
No related merge requests found
......@@ -108,6 +108,36 @@ boost::shared_ptr<ANTLRParserResult<Wccl::TSet> > Parser::parseSymSetOperator(
return parser.parse_sym_set_operator(tagset_);
}
// ----------------------------------------------------------------------------
/**
* @desc Parse a position operator contained in a std::string. Converts the
* string to a stream and calls parseSymSetOperator with it
* @arg str operator string
* @return the parsed operator via a shared pointer
*/
boost::shared_ptr<ANTLRParserResult<Wccl::Position> > Parser::parsePositionOperator(
const std::string& str) const
{
std::stringstream ss (std::stringstream::in | std::stringstream::out);
ss << str;
return this->parsePositionOperator(ss);
}
/**
* @desc Parse a position operator. Runs parse_sym_set_operator rule
* in the parser grammar.
* @arg istr input stream with the operator
* @return the parsed operator via a shared pointer
*/
boost::shared_ptr<ANTLRParserResult<Wccl::Position> > Parser::parsePositionOperator(
std::istream& istr) const
{
ANTLRLexer lexer(istr);
ANTLRParser parser(lexer);
return parser.parse_position_operator(tagset_);
}
// ----------------------------------------------------------------------------
/**
* @desc Parse any operator contained in a std::string. Converts the string to
......@@ -174,6 +204,18 @@ boost::shared_ptr<ANTLRParserResultBase> Parser::parseAnyOperator(
// ignore, try another type
}
}
if (!result) {
ss.clear();
ss.seekg(0, std::ios::beg);
ANTLRLexer lexer(ss);
ANTLRParser parser(lexer);
try {
result = parser.parse_position_operator(tagset_);
} catch (antlr::ANTLRException& e) {
errors << "(as position) " << e.getMessage() << "\n";
// ignore, try another type
}
}
if (!result) {
throw ParserException(errors.str());
}
......
......@@ -45,6 +45,13 @@ public:
boost::shared_ptr<ANTLRParserResult<Wccl::TSet> >
parseSymSetOperator(std::istream&) const;
// ---------------------------------------------------------------------------
// methods for parsing position operators
boost::shared_ptr<ANTLRParserResult<Wccl::Position> >
parsePositionOperator(const std::string&) const;
boost::shared_ptr<ANTLRParserResult<Wccl::Position> >
parsePositionOperator(std::istream&) const;
// ---------------------------------------------------------------------------
// methods for parsing any operators
boost::shared_ptr<ANTLRParserResultBase>
......
......@@ -147,6 +147,21 @@ parse_sym_set_operator
}
;
// ----------------------------------------------------------------------------
// Rules for parsing position operators
// Returns boost::shared_ptr<Wccl::Function<Wccl::Position> >
parse_position_operator
[const Corpus2::Tagset &tagset]
returns [boost::shared_ptr<ANTLRParserResult<Wccl::Position> > res]
{
res.reset(new ANTLRParserResult<Wccl::Position>());
boost::shared_ptr<Wccl::Function<Wccl::Position> > op;
}
: op = position_operators [tagset, *res->variables.get()] {
res->op = op;
}
;
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// VALUES
......@@ -265,7 +280,7 @@ position_literal
val.reset(new Wccl::Position(Wccl::Position(Wccl::Position::Nowhere)));
}
;
// Constat position value
// Constant position value
// Returns boost::shared_ptr<Wccl::Constant<Wccl::Position> >
position_value
returns [boost::shared_ptr<Wccl::Constant<Wccl::Position> > val]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment