hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit a4abdd731792df1883a9c19bba919ce96d50e7b6
parent 24c7a700cc30f1a9fa27d82483efc5a5585d9607
Author: Drew DeVault <sir@cmpwn.com>
Date:   Thu, 15 Apr 2021 11:55:16 -0400

hare::unparse: fix str, rune constants

This still needs to escape them if they contain special characters.

Diffstat:
Mhare/parse/+test/expr.ha | 2+-
Mhare/unparse/expr.ha | 5++++-
2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/hare/parse/+test/expr.ha b/hare/parse/+test/expr.ha @@ -3,7 +3,7 @@ }; @test fn constant() void = { - roundtrip("export fn main() void = 2 + -4 + void + true;\n"); + roundtrip("export fn main() void = 2 + -4 + void + true + \"hello\" + '?';\n"); }; @test fn cast() void = { diff --git a/hare/unparse/expr.ha b/hare/unparse/expr.ha @@ -95,8 +95,11 @@ fn constant( ast::_null => fmt::fprint(out, "null"), b: bool => fmt::fprint(out, b), v: lex::value => fmt::fprint(out, match (v) { - v: (str | rune | i64 | u64 | f64) => v, void => abort(), + v: (i64 | u64 | f64) => v, + // TODO: Escape these: + s: str => return fmt::fprintf(out, "\"{}\"", s), + r: rune => return fmt::fprintf(out, "'{}'", r), }), ast::array_constant => abort(), // TODO ast::struct_constant => abort(), // TODO