Adding location (line and column) to error report.

This commit is contained in:
Stefano Sanfilippo 2014-11-28 20:02:41 +01:00
parent 95cc9d4966
commit effa74c2ff
3 changed files with 13 additions and 5 deletions

View File

@ -9,6 +9,8 @@ static void meta(const char *);
using namespace monicelli;
typedef Parser::token token;
#define YY_USER_ACTION location->begin.columns(yyleng);
%}
%option ecs stack warn c++
@ -158,7 +160,11 @@ CHAR [a-zA-Z_]
return token::CASE_END;
}
<INITIAL,shift>[ \t\f\v\n\r] {
<INITIAL,shift>"\n" {
location->begin.lines();
}
<INITIAL,shift>[ \t\f\v\r] {
}
{CHAR}({DIGIT}|{CHAR})* {

View File

@ -380,11 +380,11 @@ simple_expression:
#include "Scanner.hpp"
void Parser::error(const location_type& loc, const std::string &message) {
std::cerr << "At " << loc.begin.line << "," << loc.begin.column;
std::cerr << "line " << loc.begin.line << ", col " << loc.begin.column;
std::cerr << ": " << message << std::endl;
}
static int yylex(Parser::semantic_type *lval, Parser::location_type *loc, Scanner &scanner) {
return scanner.yylex(lval);
return scanner.yylex(lval, loc);
}

View File

@ -11,16 +11,18 @@ namespace monicelli {
class Scanner: public yyFlexLexer {
public:
Scanner(std::istream &in): yyFlexLexer(&in), lval(nullptr) {}
Scanner(std::istream &in): yyFlexLexer(&in) {}
int yylex(Parser::semantic_type *lval) {
int yylex(Parser::semantic_type *lval, Parser::location_type *loc) {
this->lval = lval;
location = loc;
return yylex();
}
private:
int yylex();
Parser::semantic_type *lval;
Parser::location_type *location;
};
} // monicelli