diff --git a/Monicelli.lpp b/Monicelli.lpp index e3117e4..e09df54 100644 --- a/Monicelli.lpp +++ b/Monicelli.lpp @@ -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; } -[ \t\f\v\n\r] { +"\n" { + location->begin.lines(); +} + +[ \t\f\v\r] { } {CHAR}({DIGIT}|{CHAR})* { diff --git a/Monicelli.ypp b/Monicelli.ypp index 1ffe09a..28cca53 100644 --- a/Monicelli.ypp +++ b/Monicelli.ypp @@ -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); } diff --git a/Scanner.hpp b/Scanner.hpp index cde50e3..99baa25 100644 --- a/Scanner.hpp +++ b/Scanner.hpp @@ -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