From 2f5ad00b6d2febef703acbd79ee99174f46673b1 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Thu, 18 Dec 2025 16:39:01 +0300 Subject: [PATCH] Add char literals --- libs/parser/rules/pslang.l | 8 ++++++++ libs/parser/rules/pslang.y | 3 +++ 2 files changed, 11 insertions(+) diff --git a/libs/parser/rules/pslang.l b/libs/parser/rules/pslang.l index 8a47dd0..c9f9852 100644 --- a/libs/parser/rules/pslang.l +++ b/libs/parser/rules/pslang.l @@ -88,6 +88,14 @@ f64 { return bp::make_f64(ctx.location); } [0-9]+\.[0-9]+ { return bp::make_lit_f32(yytext, ctx.location); } [0-9]+\.[0-9]+l { return bp::make_lit_f64(yytext, ctx.location); } +'.' { return bp::make_lit_char8(yytext[1], ctx.location); } +'\\n' { return bp::make_lit_char8(10, ctx.location); } +'\\t' { return bp::make_lit_char8(11, ctx.location); } +'\\r' { return bp::make_lit_char8(13, ctx.location); } +'\\\"' { return bp::make_lit_char8(22, ctx.location); } +'\\'' { return bp::make_lit_char8(27, ctx.location); } +'\\\\' { return bp::make_lit_char8(134, ctx.location); } + <> { return bp::make_end(ctx.location); } . { throw ::pslang::parser::parse_error("unexpected character \"" + std::string(yytext) + "\"", ctx.location); } diff --git a/libs/parser/rules/pslang.y b/libs/parser/rules/pslang.y index 67231dd..ab211f7 100644 --- a/libs/parser/rules/pslang.y +++ b/libs/parser/rules/pslang.y @@ -101,6 +101,8 @@ template %token lit_f32 %token lit_f64 +%token lit_char8 + %token name %token const @@ -310,6 +312,7 @@ literal | lit_u64 { $$ = parse_numeric_literal($1, ctx.location); } | lit_f32 { $$ = parse_numeric_literal($1, ctx.location); } | lit_f64 { $$ = parse_numeric_literal($1, ctx.location); } +| lit_char8 { $$ = ast::u8_literal{static_cast($1), ctx.location}; } ; %%