diff --git a/libwccl/parser/Parser.cpp b/libwccl/parser/Parser.cpp index 8d6cc0e43195bc57b06f0ccc9f0cae938ecd8d57..b713ae67c32644d43116adc4161e2baeffd28930 100644 --- a/libwccl/parser/Parser.cpp +++ b/libwccl/parser/Parser.cpp @@ -2,6 +2,9 @@ #include "ANTLRLexer.hpp" #include "ANTLRParser.hpp" +#include <antlr/NoViableAltException.hpp> +#include <antlr/MismatchedTokenException.hpp> + namespace Wccl { /** @@ -177,8 +180,19 @@ boost::shared_ptr<ANTLRParserResultBase> Parser::parseAnyOperator( ANTLRParser parser(lexer); try { result = parser.parse_symset_operator(tagset_); + } catch (antlr::MismatchedTokenException &e) { + errors << std::endl + << "(as tset ) " + << e.getFileLineColumnString() + << " " << e.getMessage(); + } catch(antlr::NoViableAltException &e) { + errors << std::endl + << "(as tset ) " + << e.getFileLineColumnString() + << " " << e.getMessage(); } catch (antlr::ANTLRException& e) { - errors << "(as tset) " << e.getMessage() << "\n"; + errors << std::endl + << "(as tset ) " << e.getMessage(); // ignore, try another type } } @@ -189,8 +203,19 @@ boost::shared_ptr<ANTLRParserResultBase> Parser::parseAnyOperator( ANTLRParser parser(lexer); try { result = parser.parse_strset_operator(tagset_); + } catch (antlr::MismatchedTokenException &e) { + errors << std::endl + << "(as strset ) " + << e.getFileLineColumnString() + << " " << e.getMessage(); + } catch(antlr::NoViableAltException &e) { + errors << std::endl + << "(as strset ) " + << e.getFileLineColumnString() + << " " << e.getMessage(); } catch (antlr::ANTLRException& e) { - errors << "(as strset) " << e.getMessage() << "\n"; + errors << std::endl + << "(as strset ) " << e.getMessage(); // ignore, try another type } } @@ -201,8 +226,19 @@ boost::shared_ptr<ANTLRParserResultBase> Parser::parseAnyOperator( ANTLRParser parser(lexer); try { result = parser.parse_bool_operator(tagset_); + } catch (antlr::MismatchedTokenException &e) { + errors << std::endl + << "(as bool ) " + << e.getFileLineColumnString() + << " " << e.getMessage(); + } catch(antlr::NoViableAltException &e) { + errors << std::endl + << "(as bool ) " + << e.getFileLineColumnString() + << " " << e.getMessage(); } catch (antlr::ANTLRException& e) { - errors << "(as predicate) " << e.getMessage() << "\n"; + errors << std::endl + << "(as bool ) " << e.getMessage(); // ignore, try another type } } @@ -213,8 +249,19 @@ boost::shared_ptr<ANTLRParserResultBase> Parser::parseAnyOperator( ANTLRParser parser(lexer); try { result = parser.parse_position_operator(tagset_); + } catch (antlr::MismatchedTokenException &e) { + errors << std::endl + << "(as position) " + << e.getFileLineColumnString() + << " " << e.getMessage() << std::endl; + } catch(antlr::NoViableAltException &e) { + errors << std::endl + << "(as position) " + << e.getFileLineColumnString() + << " " << e.getMessage() << std::endl; } catch (antlr::ANTLRException& e) { - errors << "(as position) " << e.getMessage() << "\n"; + errors << std::endl + << "(as position) " << e.getMessage() << std::endl; // ignore, try another type } } diff --git a/wcclparser/bool_main.cpp b/wcclparser/bool_main.cpp index e63a5c3f218b4d24874b018adba60a87f866b633..c1570b0192c50eeb7b63dc657797a782d51b54a4 100644 --- a/wcclparser/bool_main.cpp +++ b/wcclparser/bool_main.cpp @@ -1,7 +1,8 @@ #include <cstdlib> - -#include <libwccl/values/strset.h> +#include <libwccl/values/bool.h> #include <libwccl/parser/Parser.h> +#include <libwccl/parser/ANTLRParserResult.h> +#include <antlr/NoViableAltException.hpp> #include <antlr/MismatchedTokenException.hpp> // ---------------------------------------------------------------------------- @@ -50,30 +51,28 @@ int main() if ((retVal = retOp->op->apply(cx)).get()) { std::cerr << "Parsed expression: " << retVal->to_raw_string() - << std::endl; + << std::endl; } else { - std::cerr << "Problem while parsing -- " - << "haven't got StrSet object in boost::shared_ptr!" - << std::endl; + std::cerr << "Problem while parsing -- Bool is NULL!" << std::endl; } } else { std::cerr << "Problem while parsing -- " - << "haven't got Function<Wccl::StrSet> object in " - << "boost::shared_ptr!" << std::endl; + << "Function<Wccl::Bool> is NULL!" << std::endl; } } catch (antlr::MismatchedTokenException &e) { - std::cerr << e.getMessage() << std::endl; - } - catch (Wccl::InvalidVariableName &e) { + std::cerr << e.getFileLineColumnString() + << " " << e.getMessage() << std::endl; + } catch(antlr::NoViableAltException &e) { + std::cerr << e.getFileLineColumnString() + << " " << e.getMessage() << std::endl; + } catch (Wccl::InvalidVariableName &e) { std::cerr << "Wccl::InvalidVariableName" << std::endl; - } - catch (Wccl::VariableTypeMismatch &e) { + } catch (Wccl::VariableTypeMismatch &e) { std::cerr << "Wccl::VariableTypeMismatch" << std::endl; - } - catch (...) { + } catch (...) { std::cerr << "[N] Syntax error!" << std::endl; } } diff --git a/wcclparser/main.cpp b/wcclparser/main.cpp index 4df9c59eb70490eaab65c868df74a43be780caa8..41fd12a01309f286c5fd4397df7cb71134951192 100644 --- a/wcclparser/main.cpp +++ b/wcclparser/main.cpp @@ -11,6 +11,7 @@ #include <boost/program_options.hpp> #include <libcorpus2/io/xcesreader.h> +#include <antlr/NoViableAltException.hpp> #include <antlr/MismatchedTokenException.hpp> // ---------------------------------------------------------------------------- @@ -145,13 +146,17 @@ bool process_line(const std::string& line, Wccl::Parser& parser, << "parser returned NULL!" << std::endl; } } catch (antlr::MismatchedTokenException &e) { - std::cerr << e.getMessage() << std::endl; + std::cerr << e.getFileLineColumnString() + << " " << e.getMessage() << std::endl; + } catch(antlr::NoViableAltException &e) { + std::cerr << e.getFileLineColumnString() + << " " << e.getMessage() << std::endl; } catch (Wccl::InvalidVariableName &e) { std::cerr << "Wccl::InvalidVariableName " << e.info() << std::endl; } catch (Wccl::VariableTypeMismatch &e) { std::cerr << "Wccl::VariableTypeMismatch " << e.info() << std::endl; } catch (Wccl::WcclError& e) { - std::cerr << "Wccl::WcclError " << e.info() << std::endl; + std::cerr << "Wccl::WcclError:" << e.info() << std::endl; } catch (PwrNlp::PwrNlpError& e) { std::cerr << "PwrNlp::PwrNlpError " << e.info() << std::endl; } catch (antlr::ANTLRException& e) { diff --git a/wcclparser/strop_main.cpp b/wcclparser/strop_main.cpp index 96a837fc8eefa6b9b5eabef69688616dcd2dec49..13be60bd501fb89d186cdf3eb22b8f514ad2467f 100644 --- a/wcclparser/strop_main.cpp +++ b/wcclparser/strop_main.cpp @@ -1,9 +1,8 @@ #include <cstdlib> -#include <boost/shared_ptr.hpp> - #include <libwccl/values/strset.h> #include <libwccl/parser/Parser.h> #include <libwccl/parser/ANTLRParserResult.h> +#include <antlr/NoViableAltException.hpp> #include <antlr/MismatchedTokenException.hpp> // ---------------------------------------------------------------------------- @@ -54,21 +53,25 @@ int main() << std::endl; } else { - std::cerr << "Problem while parsing -- " - << "haven't got StrSet object in boost::shared_ptr!" - << std::endl; + std::cerr << "Problem while parsing -- StrSet is NULL!" << std::endl; } } else { std::cerr << "Problem while parsing -- " - << "haven't got Function<Wccl::StrSet> object in " - << "boost::shared_ptr!" << std::endl; + << "Function<Wccl::StrSet> is NULL!" << std::endl; } } catch (antlr::MismatchedTokenException &e) { - std::cerr << e.getMessage() << std::endl; - } - catch (...) { + std::cerr << e.getFileLineColumnString() + << " " << e.getMessage() << std::endl; + } catch(antlr::NoViableAltException &e) { + std::cerr << e.getFileLineColumnString() + << " " << e.getMessage() << std::endl; + } catch (Wccl::InvalidVariableName &e) { + std::cerr << "Wccl::InvalidVariableName" << std::endl; + } catch (Wccl::VariableTypeMismatch &e) { + std::cerr << "Wccl::VariableTypeMismatch" << std::endl; + } catch (...) { std::cerr << "[N] Syntax error!" << std::endl; } } diff --git a/wcclparser/tagset_main.cpp b/wcclparser/tagset_main.cpp index 7229a7319ffc517fc5df437906cd09205054e85f..ddfaaa49af18a7f0eb313866e500b4f4f2ca5fc9 100644 --- a/wcclparser/tagset_main.cpp +++ b/wcclparser/tagset_main.cpp @@ -1,13 +1,12 @@ #include <cstdlib> - -#include <libcorpus2/tagsetmanager.h> - #include <libwccl/values/tset.h> - #include <libwccl/parser/Parser.h> #include <libwccl/parser/ANTLRParserResult.h> +#include <antlr/NoViableAltException.hpp> #include <antlr/MismatchedTokenException.hpp> +#include <libcorpus2/tagsetmanager.h> + // ---------------------------------------------------------------------------- /** @@ -56,21 +55,25 @@ int main() << std::endl; } else { - std::cerr << "Problem while parsing -- " - << "haven't got StrSet object in boost::shared_ptr!" - << std::endl; + std::cerr << "Problem while parsing -- TSet is NULL!" << std::endl; } } else { std::cerr << "Problem while parsing -- " - << "haven't got Function<Wccl::StrSet> object in " - << "boost::shared_ptr!" << std::endl; + << "Function<Wccl::TSet> is NULL!" << std::endl; } } catch (antlr::MismatchedTokenException &e) { - std::cerr << e.getMessage() << std::endl; - } - catch (...) { + std::cerr << e.getFileLineColumnString() + << " " << e.getMessage() << std::endl; + } catch(antlr::NoViableAltException &e) { + std::cerr << e.getFileLineColumnString() + << " " << e.getMessage() << std::endl; + } catch (Wccl::InvalidVariableName &e) { + std::cerr << "Wccl::InvalidVariableName" << std::endl; + } catch (Wccl::VariableTypeMismatch &e) { + std::cerr << "Wccl::VariableTypeMismatch" << std::endl; + } catch (...) { std::cerr << "[N] Syntax error!" << std::endl; } }