%option noyywrap nounput noinput %{ #include "gen_parser.hpp" #include #include using bp = ::pslang::parser::bison::parser; #define YY_DECL bp::symbol_type yylex(::pslang::parser::context& ctx) #define YY_USER_ACTION ctx.location.move_columns(yyleng); %} %% %{ ctx.location.step(); %} [ ]+ { ctx.location.step(); } "//"[^\n]* { return bp::make_comment(ctx.location); } const { return bp::make_const(ctx.location); } let { return bp::make_let(ctx.location); } mut { return bp::make_mut(ctx.location); } if { return bp::make_if(ctx.location); } else { return bp::make_else(ctx.location); } while { return bp::make_while(ctx.location); } as { return bp::make_as(ctx.location); } func { return bp::make_func(ctx.location); } foreign { return bp::make_foreign(ctx.location); } return { return bp::make_return(ctx.location); } struct { return bp::make_struct(ctx.location); } true { return bp::make_true(ctx.location); } false { return bp::make_false(ctx.location); } unit { return bp::make_unit(ctx.location); } bool { return bp::make_bool(ctx.location); } i8 { return bp::make_i8(ctx.location); } u8 { return bp::make_u8(ctx.location); } i16 { return bp::make_i16(ctx.location); } u16 { return bp::make_u16(ctx.location); } i32 { return bp::make_i32(ctx.location); } u32 { return bp::make_u32(ctx.location); } i64 { return bp::make_i64(ctx.location); } u64 { return bp::make_u64(ctx.location); } f16 { return bp::make_f16(ctx.location); } f32 { return bp::make_f32(ctx.location); } f64 { return bp::make_f64(ctx.location); } [a-zA-Z_]+[a-zA-Z0-9_]* { return bp::make_name(yytext, ctx.location); } "\n" { auto old_location = ctx.location; ctx.location.move_lines(1); return bp::make_newline(old_location); } "\t" { return bp::make_indent(ctx.location); } "=" { return bp::make_assignment(ctx.location); } ":" { return bp::make_colon(ctx.location); } "," { return bp::make_comma(ctx.location); } "." { return bp::make_dot(ctx.location); } "(" { return bp::make_lparen(ctx.location); } ")" { return bp::make_rparen(ctx.location); } "[" { return bp::make_lbracket(ctx.location); } "]" { return bp::make_rbracket(ctx.location); } "+=" { return bp::make_plus_assignment(ctx.location); } "-=" { return bp::make_minus_assignment(ctx.location); } "*=" { return bp::make_asterisk_assignment(ctx.location); } "/=" { return bp::make_slash_assignment(ctx.location); } "%=" { return bp::make_percent_assignment(ctx.location); } "^=" { return bp::make_circumflex_assignment(ctx.location); } "&=" { return bp::make_ampersand_assignment(ctx.location); } "|=" { return bp::make_vertical_bar_assignment(ctx.location); } ">>=" { return bp::make_right_shift_assignment(ctx.location); } "<<=" { return bp::make_left_shift_assignment(ctx.location); } "+" { return bp::make_plus(ctx.location); } "-" { return bp::make_minus(ctx.location); } "*" { return bp::make_asterisk(ctx.location); } "/" { return bp::make_slash(ctx.location); } "%" { return bp::make_percent(ctx.location); } "&&" { return bp::make_double_ampersand(ctx.location); } "&" { return bp::make_ampersand(ctx.location); } "||" { return bp::make_double_vertical_bar(ctx.location); } "|" { return bp::make_vertical_bar(ctx.location); } "^" { return bp::make_circumflex(ctx.location); } "!" { return bp::make_exclamation(ctx.location); } "<<" { return bp::make_left_shift(ctx.location); } ">>" { return bp::make_right_shift(ctx.location); } "==" { return bp::make_equals(ctx.location); } "!=" { return bp::make_not_equals(ctx.location); } "<" { return bp::make_less(ctx.location); } ">" { return bp::make_greater(ctx.location); } "<=" { return bp::make_less_equals(ctx.location); } ">=" { return bp::make_greater_equals(ctx.location); } "->" { return bp::make_arrow(ctx.location); } [0-9]+b { return bp::make_lit_i8(yytext, ctx.location); } [0-9]+ub { return bp::make_lit_u8(yytext, ctx.location); } [0-9]+s { return bp::make_lit_i16(yytext, ctx.location); } [0-9]+us { return bp::make_lit_u16(yytext, ctx.location); } [0-9]+ { return bp::make_lit_i32(yytext, ctx.location); } [0-9]+u { return bp::make_lit_u32(yytext, ctx.location); } [0-9]+l { return bp::make_lit_i64(yytext, ctx.location); } [0-9]+ul { return bp::make_lit_u64(yytext, ctx.location); } [0-9]+\.[0-9]+ { return bp::make_lit_f32(yytext, ctx.location); } [0-9]+\.[0-9]+h { return bp::make_lit_f16(yytext, ctx.location); } [0-9]+\.[0-9]+d { return bp::make_lit_f64(yytext, ctx.location); } '\\0' { return bp::make_lit_char8(0, ctx.location); } '\\a' { return bp::make_lit_char8(7, ctx.location); } '\\b' { return bp::make_lit_char8(8, ctx.location); } '\\t' { return bp::make_lit_char8(9, ctx.location); } '\\n' { return bp::make_lit_char8(10, ctx.location); } '\\v' { return bp::make_lit_char8(11, ctx.location); } '\\f' { return bp::make_lit_char8(12, ctx.location); } '\\r' { return bp::make_lit_char8(13, ctx.location); } '\\e' { return bp::make_lit_char8(27, ctx.location); } '\\\"' { return bp::make_lit_char8(34, ctx.location); } '\\'' { return bp::make_lit_char8(39, ctx.location); } '\\?' { return bp::make_lit_char8(63, ctx.location); } '\\\\' { return bp::make_lit_char8(92, ctx.location); } '.' { return bp::make_lit_char8(yytext[1], ctx.location); } <> { return bp::make_end(ctx.location); } . { throw ::pslang::parser::parse_error("unexpected character \"" + std::string(yytext) + "\"", ctx.location); }