Skip to content

Commit

Permalink
Merge branch 'SiegeLord/rust_updates'
Browse files Browse the repository at this point in the history
  • Loading branch information
b4n committed Apr 2, 2014
2 parents 16d9bbb + e4c6aa3 commit e94d162
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 18 deletions.
2 changes: 1 addition & 1 deletion data/filetypes.rust
Expand Up @@ -22,7 +22,7 @@ lexerror=error

[keywords]
# all items must be in one line
primary=alignof as be box break const continue do else enum extern false fn for if impl in let __log_level loop match mod mut offsetof once priv proc pub pure ref return self sizeof static struct super trait true type typeof unsafe unsized use while yield
primary=alignof as be box break const continue crate do else enum extern false fn for if impl in let loop match mod mut offsetof once priv proc pub pure ref return self sizeof static struct super trait true type typeof unsafe unsized use while yield
secondary=bool char f32 f64 i16 i32 i64 i8 int str u16 u32 u64 u8 uint
tertiary=Self

Expand Down
61 changes: 47 additions & 14 deletions tagmanager/ctags/rust.c
Expand Up @@ -67,6 +67,7 @@ typedef enum {
TOKEN_IDENT,
TOKEN_LSHIFT,
TOKEN_RSHIFT,
TOKEN_RARROW,
TOKEN_EOF
} tokenType;

Expand Down Expand Up @@ -129,6 +130,9 @@ static void writeCurTokenToStr (lexerState *lexer, vString *out_str)
case TOKEN_RSHIFT:
vStringCatS(out_str, ">>");
break;
case TOKEN_RARROW:
vStringCatS(out_str, "->");
break;
default:
vStringPut(out_str, (char) lexer->cur_token);
}
Expand Down Expand Up @@ -356,6 +360,11 @@ static int advanceToken (lexerState *lexer, boolean skip_whitspace)
advanceNChar(lexer, 2);
return lexer->cur_token = TOKEN_LSHIFT;
}
else if (lexer->cur_c == '-' && lexer->next_c == '>')
{
advanceNChar(lexer, 2);
return lexer->cur_token = TOKEN_RARROW;
}
else
{
int c = lexer->cur_c;
Expand Down Expand Up @@ -706,10 +715,31 @@ static void parseStructOrEnum (lexerState *lexer, vString *scope, int parent_kin
vString *field_name = vStringNew();
while (lexer->cur_token != TOKEN_EOF)
{
int goal_tokens2[] = {'}', ','};
/* Skip attributes. Format:
* #[..] or #![..]
* */
if (lexer->cur_token == '#')
{
advanceToken(lexer, TRUE);
if (lexer->cur_token == '!')
advanceToken(lexer, TRUE);
if (lexer->cur_token == '[')
{
/* It's an attribute, skip it. */
skipUntil(lexer, NULL, 0);
}
else
{
/* Something's up with this field, skip to the next one */
skipUntil(lexer, goal_tokens2, 2);
continue;
}
}
if (lexer->cur_token == TOKEN_IDENT)
{
int goal_tokens2[] = {'}', ','};
if (strcmp(lexer->token_str->buffer, "priv") == 0)
if (strcmp(lexer->token_str->buffer, "priv") == 0
|| strcmp(lexer->token_str->buffer, "pub") == 0)
{
advanceToken(lexer, TRUE);
if (lexer->cur_token != TOKEN_IDENT)
Expand Down Expand Up @@ -746,19 +776,22 @@ static void skipMacro (lexerState *lexer)
int minus_token = 0;

advanceToken(lexer, TRUE);
if (lexer->cur_token == '(')
{
plus_token = '(';
minus_token = ')';
}
else if (lexer->cur_token == '{')
{
plus_token = '{';
minus_token = '}';
}
else
switch (lexer->cur_token)
{
return;
case '(':
plus_token = '(';
minus_token = ')';
break;
case '{':
plus_token = '{';
minus_token = '}';
break;
case '[':
plus_token = '[';
minus_token = ']';
break;
default:
return;
}

while (lexer->cur_token != TOKEN_EOF)
Expand Down
29 changes: 27 additions & 2 deletions tests/ctags/test_input.rs
Expand Up @@ -2,9 +2,23 @@
#[feature(globs)];
#[feature(macro_rules)];
use std::*;
use std::io::stdio::println;
use test_input2::*;
mod test_input2;

pub struct A
{
foo: fn() -> int,
bar: int
}

pub struct B
{
#[cfg(test)]
foo: int,
bar: int
}

/*
* fn ignored_in_comment() {}
*/
Expand All @@ -18,15 +32,18 @@ mod test_input2;

static size: uint = 1;

#[cfg(test)]
struct S1 {
only_field: [int, ..size]
priv only_field: [int, ..size]
}

macro_rules! test_macro
{
() => {1}
}

macro_rules! ignore (($($x:tt)*) => (()))

fn yada(a:int,c:Foo,b:test_input2::fruit::SomeStruct) -> ~str {
a.to_str()
}
Expand All @@ -43,6 +60,14 @@ fn main() {
(
fn ignored_inside_macro() {}
)
ignore!
[
fn ignored_inside_macro() {}
]
ignore!
{
fn ignored_inside_macro() {}
}

let _ = "fn ignored_in_string() {}
";
Expand All @@ -64,7 +89,7 @@ struct Foo2 {
}

impl Foo {
fn my_method(&self,_:int){ print("my_method of foo");}
fn my_method(&self,_:int){ println("my_method of foo");}
}

enum Animal {
Expand Down
7 changes: 7 additions & 0 deletions tests/ctags/test_input.rs.tags
@@ -1,5 +1,7 @@
# format=tagmanager
A�2048�0
Animal�2�0
B�2048�0
Bar�2048�0
Baz�2048�0
DoZ�32�0
Expand All @@ -16,10 +18,15 @@ a_anteater
a_bear�4�Animal�0
a_cat�4�Animal�0
a_dog�4�Animal�0
bar�8�A�0
bar�8�B�0
do_z�128�(&self)�DoZ�0
do_z�128�(&self)�Foo�0
foo�8�A�0
foo�8�B�0
foo_field_1�8�Foo�0
gfunc�16�<X:Testable+DoZ>(x:&X)�0
ignore�65536�0
main�16�()�0
my_method�128�(&self,_:int)�Foo�0
nested�16�()�main�0
Expand Down
6 changes: 5 additions & 1 deletion tests/ctags/test_input2.rs
@@ -1,3 +1,5 @@
use std::io::stdio::println;

pub fn foo_bar_test_func(apples:fruit::SomeStruct,(oranges,lemon):(int,int))->int{
let some_var_name=2*oranges;
let a=SomeLongStructName{v:0};
Expand All @@ -8,7 +10,9 @@ pub fn foo_bar_test_func(apples:fruit::SomeStruct,(oranges,lemon):(int,int))->in

pub mod fruit {
pub struct SomeStruct{
red_value:int,green_value:int,blue_value:int
pub red_value: int,
pub green_value: int,
pub blue_value: int
}
}

Expand Down

0 comments on commit e94d162

Please sign in to comment.