diff options
author | John Hodge <tpg@mutabah.net> | 2016-02-27 16:17:41 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-02-27 16:17:41 +0800 |
commit | 5e5b4a58dcedf8903b10f94f15fcaf4c306c9e3c (patch) | |
tree | bbd54c89279e13c307eeee5f693bf280a4a4e92e /src | |
parent | 85a756b47e55373497a20f1d19a7b4eec12ce928 (diff) | |
download | mrust-5e5b4a58dcedf8903b10f94f15fcaf4c306c9e3c.tar.gz |
Parse - Fix trailing commas in attributes, _.. pattern support in slices
Diffstat (limited to 'src')
-rw-r--r-- | src/parse/pattern.cpp | 8 | ||||
-rw-r--r-- | src/parse/root.cpp | 18 |
2 files changed, 16 insertions, 10 deletions
diff --git a/src/parse/pattern.cpp b/src/parse/pattern.cpp index d6b646b5..b8794dfd 100644 --- a/src/parse/pattern.cpp +++ b/src/parse/pattern.cpp @@ -260,6 +260,14 @@ AST::Pattern Parse_PatternReal_Slice(TokenStream& lex, bool is_refutable) GET_TOK(tok, lex); // TOK_DOUBLE_DOT } + else if( tok.type() == TOK_UNDERSCORE && lex.lookahead(0) == TOK_DOUBLE_DOT) { + if(is_trailing) + ERROR(lex.end_span(sp), E0000, "Multiple instances of .. in a slice pattern"); + rv_array.extra_bind = "_"; + is_trailing = true; + + GET_TOK(tok, lex); // TOK_DOUBLE_DOT + } else if( tok.type() == TOK_DOUBLE_DOT ) { if(is_trailing) ERROR(lex.end_span(sp), E0000, "Multiple instances of .. in a slice pattern"); diff --git a/src/parse/root.cpp b/src/parse/root.cpp index d3d19d82..231094a2 100644 --- a/src/parse/root.cpp +++ b/src/parse/root.cpp @@ -798,16 +798,14 @@ AST::MetaItem Parse_MetaItem(TokenStream& lex) return AST::MetaItem(name, tok.str());
case TOK_PAREN_OPEN: {
::std::vector<AST::MetaItem> items;
- if( LOOK_AHEAD(lex) != TOK_PAREN_CLOSE )
- {
- do {
- items.push_back(Parse_MetaItem(lex));
- } while(GET_TOK(tok, lex) == TOK_COMMA);
- CHECK_TOK(tok, TOK_PAREN_CLOSE);
- }
- else {
- GET_CHECK_TOK(tok, lex, TOK_PAREN_CLOSE);
- }
+ do {
+ if(LOOK_AHEAD(lex) == TOK_PAREN_CLOSE) {
+ GET_TOK(tok, lex);
+ break;
+ }
+ items.push_back(Parse_MetaItem(lex));
+ } while(GET_TOK(tok, lex) == TOK_COMMA);
+ CHECK_TOK(tok, TOK_PAREN_CLOSE);
return AST::MetaItem(name, items); }
default:
lex.putback(tok);
|