diff options
author | John Hodge <tpg@mutabah.net> | 2016-09-09 13:14:31 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-09-09 13:14:31 +0800 |
commit | 5edfaaba2e48c04bc17185b1367ba60df3ed8677 (patch) | |
tree | 17bd3a4ffc82890ae5115a7850494c3b6fe6dc94 /src/macro_rules/parse.cpp | |
parent | f4492fe0363ec0aee12391219559d616f75f662e (diff) | |
download | mrust-5edfaaba2e48c04bc17185b1367ba60df3ed8677.tar.gz |
macro_rules - Fix printing, some better comments and debug
Diffstat (limited to 'src/macro_rules/parse.cpp')
-rw-r--r-- | src/macro_rules/parse.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/macro_rules/parse.cpp b/src/macro_rules/parse.cpp index ad536adb..cd8aefd2 100644 --- a/src/macro_rules/parse.cpp +++ b/src/macro_rules/parse.cpp @@ -354,6 +354,9 @@ bool patterns_are_same(const Span& sp, const MacroPatEnt& left, const MacroPatEn if( is_token_expr(left.tok.type()) ) ERROR(sp, E0000, "Incompatible macro fragments " << right << " used with " << left); return false; + // TODO: Allow a loop starting with an expr? + // - Consume, add split based on loop condition or next arm + // - Possible problem with binding levels. case MacroPatEnt::PAT_EXPR: return true; default: @@ -446,6 +449,7 @@ MacroRulesPtr Parse_MacroRules(TokenStream& lex) break; } } + DEBUG("- " << rules.size() << " rules"); MacroRulesPatFrag root_frag; ::std::vector<MacroRulesArm> rule_arms; @@ -464,8 +468,11 @@ MacroRulesPtr Parse_MacroRules(TokenStream& lex) { Span sp(pat.tok.get_pos()); + // If the current position is the end of the current fragment: if( frag_ofs == cur_frag->m_pats_ents.size() ) { + // But this fragment is incomplete (doesn't end a pattern, or split) if( cur_frag->m_pattern_end == ~0u && cur_frag->m_next_frags.size() == 0 ) { + // Keep pushing onto the end cur_frag->m_pats_ents.push_back( pat ); frag_ofs += 1; } @@ -489,6 +496,7 @@ MacroRulesPtr Parse_MacroRules(TokenStream& lex) frag_ofs = 1; } } + // TODO: If `:expr` and `$( :expr)` are seen, split _after_ the :expr else if( ! patterns_are_same(sp, cur_frag->m_pats_ents[frag_ofs], pat) ) { // Difference, split the block. auto new_frag = split_fragment_at(*cur_frag, frag_ofs); |