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

"all" positions handling in wcclparser

parent a7d583e0
No related merge requests found
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <libwccl/values/strset.h>
#include <libwccl/parser/Parser.h>
......@@ -88,7 +90,8 @@ void libedit_read_loop(boost::function<bool (const std::string&)>& line_cb)
}
#endif
bool process_line(const std::string& line, Parser& parser, Wccl::SentenceContext& sc)
bool process_line(const std::string& line, Parser& parser,
Wccl::SentenceContext& sc, bool all_positions)
{
if (line.empty() || line == "exit" || line == "quit") {
return true;
......@@ -102,15 +105,28 @@ bool process_line(const std::string& line, Parser& parser, Wccl::SentenceContext
try {
retOp = parser.parseAnyOperator(line);
if (retOp) {
Wccl::FunExecContext cx(sc, retOp->variables);
retVal = retOp->get_op_base()->apply_internal(cx);
if (retVal) {
std::cerr << "Parsed expression: "
<< retVal->to_string(parser.tagset())
<< std::endl;
int pb, pe;
if (all_positions) {
pb = 0;
pe = sc.get_sentence().empty() ? 1 : sc.size();
} else {
std::cerr << "Problem while parsing -- "
<< "retVal is NULL!" << std::endl;
pb = sc.get_position();
pe = sc.get_position() + 1;
}
for (int i = pb; i < pe; ++i) {
sc.set_position(i);
Wccl::FunExecContext cx(sc,
boost::shared_ptr<Wccl::Variables>(retOp->variables->clone()));
retVal = retOp->get_op_base()->apply_internal(cx);
if (retVal) {
std::cerr << "[" << std::setw(2) << sc.get_position() << "] "
<< "Parsed expression: "
<< retVal->to_string(parser.tagset())
<< std::endl;
} else {
std::cerr << "Problem while parsing -- "
<< "retVal is NULL!" << std::endl;
}
}
} else {
std::cerr << "Problem while parsing -- "
......@@ -195,11 +211,12 @@ int main(int argc, char** argv)
sc.set_position(pos);
Parser parser(tagset);
if (!query.empty()) {
process_line(query, parser, sc);
process_line(query, parser, sc, position == "all");
return 0;
}
boost::function<bool (const std::string&)> f;
f = boost::bind(&process_line, _1, boost::ref(parser), boost::ref(sc));
f = boost::bind(&process_line, _1, boost::ref(parser), boost::ref(sc),
position == "all");
#ifdef HAVE_LIBEDIT
libedit_read_loop(f);
#else
......
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