Skip to content

Commit

Permalink
Merge pull request #2612 from simias/fix/rust-array-param
Browse files Browse the repository at this point in the history
Rust: allow arrays in function parameters
  • Loading branch information
masatake authored Aug 9, 2020
2 parents c77c95a + 2920975 commit 3292b1f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions Units/parser-rust.r/rust-test_input.d/expected.tags
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ a_anteater input.rs /^ a_anteater(isize),$/;" e enum:Animal
a_bear input.rs /^ a_bear(isize),$/;" e enum:Animal
a_cat input.rs /^ a_cat(isize),$/;" e enum:Animal
a_dog input.rs /^ a_dog(isize),$/;" e enum:Animal
array_param input.rs /^fn array_param(arr: [[u32; 3]; 4])$/;" f signature:(arr: [[u32; 3]; 4])
bar input.rs /^ bar: isize$/;" m struct:A
bar input.rs /^ bar: isize$/;" m struct:B
do_z input.rs /^ fn do_z(&self) {$/;" P implementation:Foo signature:(&self)
Expand Down
4 changes: 4 additions & 0 deletions Units/parser-rust.r/rust-test_input.d/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ pub fn where_foo<T>(a: T) where T: Send
{
}

fn array_param(arr: [[u32; 3]; 4])
{
}

/*
* fn ignored_in_comment() {}
*/
Expand Down
19 changes: 16 additions & 3 deletions parsers/rust.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ static void parseFn (lexerState *lexer, vString *scope, int parent_kind)
unsigned long line;
MIOPos pos;
int paren_level = 0;
int bracket_level = 0;
bool found_paren = false;
bool valid_signature = true;

Expand All @@ -545,9 +546,13 @@ static void parseFn (lexerState *lexer, vString *scope, int parent_kind)

/* HACK: This is a bit coarse as far as what tag entry means by
* 'arglist'... */
while (lexer->cur_token != '{' && lexer->cur_token != ';')
while (lexer->cur_token != '{')
{
if (lexer->cur_token == '}')
if (lexer->cur_token == ';' && bracket_level == 0)
{
break;
}
else if (lexer->cur_token == '}')
{
valid_signature = false;
break;
Expand All @@ -566,6 +571,14 @@ static void parseFn (lexerState *lexer, vString *scope, int parent_kind)
break;
}
}
else if (lexer->cur_token == '[')
{
bracket_level++;
}
else if (lexer->cur_token == ']')
{
bracket_level--;
}
else if (lexer->cur_token == TOKEN_EOF)
{
valid_signature = false;
Expand All @@ -574,7 +587,7 @@ static void parseFn (lexerState *lexer, vString *scope, int parent_kind)
writeCurTokenToStr(lexer, arg_list);
advanceToken(lexer, false);
}
if (!found_paren || paren_level != 0)
if (!found_paren || paren_level != 0 || bracket_level != 0)
valid_signature = false;

if (valid_signature)
Expand Down

0 comments on commit 3292b1f

Please sign in to comment.