Adding location (line and column) to error report.
This commit is contained in:
parent
95cc9d4966
commit
effa74c2ff
|
@ -9,6 +9,8 @@ static void meta(const char *);
|
||||||
|
|
||||||
using namespace monicelli;
|
using namespace monicelli;
|
||||||
typedef Parser::token token;
|
typedef Parser::token token;
|
||||||
|
|
||||||
|
#define YY_USER_ACTION location->begin.columns(yyleng);
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%option ecs stack warn c++
|
%option ecs stack warn c++
|
||||||
|
@ -158,7 +160,11 @@ CHAR [a-zA-Z_]
|
||||||
return token::CASE_END;
|
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})* {
|
{CHAR}({DIGIT}|{CHAR})* {
|
||||||
|
|
|
@ -380,11 +380,11 @@ simple_expression:
|
||||||
#include "Scanner.hpp"
|
#include "Scanner.hpp"
|
||||||
|
|
||||||
void Parser::error(const location_type& loc, const std::string &message) {
|
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;
|
std::cerr << ": " << message << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int yylex(Parser::semantic_type *lval, Parser::location_type *loc, Scanner &scanner) {
|
static int yylex(Parser::semantic_type *lval, Parser::location_type *loc, Scanner &scanner) {
|
||||||
return scanner.yylex(lval);
|
return scanner.yylex(lval, loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,16 +11,18 @@ namespace monicelli {
|
||||||
|
|
||||||
class Scanner: public yyFlexLexer {
|
class Scanner: public yyFlexLexer {
|
||||||
public:
|
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;
|
this->lval = lval;
|
||||||
|
location = loc;
|
||||||
return yylex();
|
return yylex();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int yylex();
|
int yylex();
|
||||||
Parser::semantic_type *lval;
|
Parser::semantic_type *lval;
|
||||||
|
Parser::location_type *location;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // monicelli
|
} // monicelli
|
||||||
|
|
Reference in New Issue
Block a user