Skip to content

Commit 648cbe2

Browse files
committed
rust: Add support for constant parsing
1 parent 05e6ab4 commit 648cbe2

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

Units/parser-rust.r/rust-test_input.d/expected.tags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Foo input.rs /^impl Foo {$/;" c
1212
Foo input.rs /^impl Testable for Foo {$/;" c
1313
Foo input.rs /^struct Foo{foo_field_1:isize}$/;" s
1414
Foo2 input.rs /^struct Foo2 {$/;" s
15+
N input.rs /^const N: usize = 10;$/;" C
1516
ParametrizedTrait input.rs /^trait ParametrizedTrait<T> {$/;" i
1617
S1 input.rs /^struct S1 {$/;" s
1718
SomeStruct input.rs /^ pub struct SomeStruct;$/;" s module:test_input2

Units/parser-rust.r/rust-test_input.d/input.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ fn array_param(arr: [[u32; 3]; 4])
6363
*/
6464

6565
static size: usize = 1;
66+
const N: usize = 10;
6667

6768
#[cfg(test)]
6869
struct S1 {

parsers/rust.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ typedef enum {
4343
K_FIELD,
4444
K_VARIANT,
4545
K_METHOD,
46+
K_CONST,
4647
K_NONE
4748
} RustKind;
4849

@@ -59,6 +60,7 @@ static kindDefinition rustKinds[] = {
5960
{true, 'm', "field", "A struct field"},
6061
{true, 'e', "enumerator", "An enum variant"},
6162
{true, 'P', "method", "A method"},
63+
{true, 'C', "constant", "A constant"},
6264
};
6365

6466
typedef enum {
@@ -725,6 +727,18 @@ static void parseStatic (lexerState *lexer, vString *scope, int parent_kind)
725727
addTag(lexer->token_str, NULL, K_STATIC, lexer->line, lexer->pos, scope, parent_kind);
726728
}
727729

730+
/* Const format:
731+
* "const" <ident>
732+
*/
733+
static void parseConst (lexerState *lexer, vString *scope, int parent_kind)
734+
{
735+
advanceToken(lexer, true);
736+
if (lexer->cur_token != TOKEN_IDENT)
737+
return;
738+
739+
addTag(lexer->token_str, NULL, K_CONST, lexer->line, lexer->pos, scope, parent_kind);
740+
}
741+
728742
/* Type format:
729743
* "type" <ident>
730744
*/
@@ -918,6 +932,10 @@ static void parseBlock (lexerState *lexer, bool delim, int kind, vString *scope)
918932
{
919933
parseStatic(lexer, scope, kind);
920934
}
935+
else if(strcmp(vStringValue(lexer->token_str), "const") == 0)
936+
{
937+
parseConst(lexer, scope, kind);
938+
}
921939
else if(strcmp(vStringValue(lexer->token_str), "trait") == 0)
922940
{
923941
parseTrait(lexer, scope, kind);

0 commit comments

Comments
 (0)