From d7cd1cfdc413f0a317c399fc31884d7e94674b7b Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 30 Oct 2016 19:17:35 +0800 Subject: Expand concat! - Fix a few edge cases --- src/expand/concat.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/expand/concat.cpp b/src/expand/concat.cpp index 71c7e262..c15be18b 100644 --- a/src/expand/concat.cpp +++ b/src/expand/concat.cpp @@ -1,4 +1,9 @@ /* + * MRustC - Rust Compiler + * - By John Hodge (Mutabah/thePowersGang) + * + * expand/concat.cpp + * - concat! handler */ #include #include "../parse/common.hpp" @@ -20,6 +25,11 @@ class CConcatExpander: ::std::string rv; do { + if( LOOK_AHEAD(lex) == TOK_EOF ) { + GET_TOK(tok, lex); + break ; + } + auto v = Parse_Expr0(lex); DEBUG("concat - v=" << *v); Expand_BareExpr(crate, mod, v); @@ -29,12 +39,25 @@ class CConcatExpander: rv += vp->m_value; } else if( auto* vp = dynamic_cast(v.get()) ) + { + if( vp->m_datatype == CORETYPE_CHAR ) { + rv += Codepoint { static_cast(vp->m_value) }; + } + else { + rv += FMT(vp->m_value); + } + } + else if( auto* vp = dynamic_cast(v.get()) ) { rv += FMT(vp->m_value); } + else if( auto* vp = dynamic_cast(v.get()) ) + { + rv += (vp->m_value ? "true" : "false"); + } else { - ERROR(sp, E0000, "Unexpected expression type"); + ERROR(sp, E0000, "Unexpected expression type in concat! argument"); } } while( GET_TOK(tok, lex) == TOK_COMMA ); if( tok.type() != TOK_EOF ) -- cgit v1.2.3