#include <cstdlib>

#include <libwccl/values/strset.h>
#include <libwccl/parser/Parser.h>

// ----------------------------------------------------------------------------

/**
 * @desc It's simple command line tester for testing predicates
 */

int main()
{
  std::string str_in;
  Corpus2::Tagset tagset;
	Parser parser(tagset);

	boost::shared_ptr<Wccl::Bool> retValue;
	boost::shared_ptr<Wccl::Function<Wccl::Bool> > retOp;
	boost::shared_ptr<Corpus2::Sentence> sentence;
	Wccl::SentenceContext sc(sentence);

  while (1) {
    std::cerr << "Enter a string predicates expression: ";

    getline(std::cin, str_in);

    if (str_in == "clear" || str_in == "cls") {
      if (system("clear")) {
        //  
      }
    }
		else if (str_in == "exit" || str_in == "quit") {
			break;
		}
    else {
			try {
	      retOp = parser.parsePredicate(str_in);

				if (retOp.get()) {
						std::cerr 
							<< "Parsed expression: " 
							<< (retValue = retOp->apply(sc))->to_raw_string()
							<< std::endl;
				}
				else {
					std::cerr << "Problem while parsing -- haven't got Function<Wccl::StrSet> object in boost::shared_ptr!" << std::endl;
				}
			}
			catch (antlr::MismatchedTokenException &e) {
				std::cerr << "Mismatch token exception!" << std::endl;
			}
			/*
			catch (antlr::TokenStreamRecognitionException &e) {
				std::cerr << "[2] Syntax error!" << std::endl;
			}
			*/
			catch (...) {
				std::cerr << "[N] Syntax error!" << std::endl;
			}
    }
  }

  return 0;
}