%{
#include <lexer_base.h>
#include <charconv>
#include "parser.h"

using token = yy::Parser::token;

#undef YY_DECL
#define YY_DECL int Scanner::yylex(Scanner::value_type *out, Scanner::location_type *loc)

#define yyterminate() return token::END
#define YY_USER_ACTION loc->step(); loc->columns(yyleng);
%}

%option debug noyywrap nodefault c++
%option yyclass="Scanner"

%%
[0-9]+("."[0-9]+)? { double d; std::from_chars(yytext, yytext + yyleng, d); *out = d; return token::NUM; };
[a-zA-Z_][a-zA-Z0-9_]* { *out = std::string{yytext, (std::string::size_type)yyleng}; return token::IDENT; }
"(" return token::LBRACE;
")" return token::RBRACE;
"-" return token::MINUS;
"+" return token::PLUS;
"*" return token::MUL;
"/" return token::DIV;
"=" return token::EQUAL;
[ \t\r\n]+ ;

%%
