From c1794a25c7dcecb008565ffe63623ea6cc007db5 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 18 Nov 2017 09:54:16 +0800 Subject: macro_rules - Support parsing if-elseif chains --- src/macro_rules/eval.cpp | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/macro_rules/eval.cpp b/src/macro_rules/eval.cpp index 05c02248..6344b26a 100644 --- a/src/macro_rules/eval.cpp +++ b/src/macro_rules/eval.cpp @@ -1325,17 +1325,35 @@ namespace consume_tt(lex); break; case TOK_RWORD_IF: - lex.consume(); - consume_expr(lex, true); - if( lex.next() != TOK_BRACE_OPEN ) - return false; - consume_tt(lex); - if( lex.next() == TOK_RWORD_ELSE ) + while(1) { + assert(lex.next() == TOK_RWORD_IF); lex.consume(); + if(lex.next() == TOK_RWORD_LET) + { + lex.consume(); + if( !consume_pat(lex) ) + return false; + if( lex.next() != TOK_EQUAL ) + return false; + lex.consume(); + } + if( !consume_expr(lex, true) ) + return false; if( lex.next() != TOK_BRACE_OPEN ) return false; consume_tt(lex); + if( lex.next() != TOK_RWORD_ELSE ) + break; + lex.consume(); + + if( lex.next() != TOK_RWORD_IF ) + { + if( lex.next() != TOK_BRACE_OPEN ) + return false; + consume_tt(lex); + break; + } } break; default: -- cgit v1.2.3