diff options
-rw-r--r-- | grammar.ron | 5 | ||||
-rw-r--r-- | src/parser/event_parser/grammar/items.rs | 9 | ||||
-rw-r--r-- | src/parser/event_parser/grammar/mod.rs | 7 | ||||
-rw-r--r-- | src/syntax_kinds.rs | 131 | ||||
-rw-r--r-- | tests/data/lexer/0011_keywords.rs | 2 | ||||
-rw-r--r-- | tests/data/lexer/0011_keywords.txt | 6 | ||||
-rw-r--r-- | tests/data/parser/ok/0007_extern_crate.rs | 2 | ||||
-rw-r--r-- | tests/data/parser/ok/0007_extern_crate.txt | 22 |
8 files changed, 122 insertions, 62 deletions
diff --git a/grammar.ron b/grammar.ron index 8418ed2a5..c475826e4 100644 --- a/grammar.ron +++ b/grammar.ron | |||
@@ -8,6 +8,9 @@ Grammar( | |||
8 | "impl", | 8 | "impl", |
9 | "true", | 9 | "true", |
10 | "false", | 10 | "false", |
11 | "as", | ||
12 | "extern", | ||
13 | "crate", | ||
11 | ], | 14 | ], |
12 | tokens: [ | 15 | tokens: [ |
13 | "ERROR", | 16 | "ERROR", |
@@ -67,8 +70,10 @@ Grammar( | |||
67 | "STRUCT_ITEM", | 70 | "STRUCT_ITEM", |
68 | "STRUCT_FIELD", | 71 | "STRUCT_FIELD", |
69 | "FN_ITEM", | 72 | "FN_ITEM", |
73 | "EXTERN_CRATE_ITEM", | ||
70 | "ATTR", | 74 | "ATTR", |
71 | "META_ITEM", | 75 | "META_ITEM", |
72 | "LITERAL", | 76 | "LITERAL", |
77 | "ALIAS", | ||
73 | ] | 78 | ] |
74 | ) \ No newline at end of file | 79 | ) \ No newline at end of file |
diff --git a/src/parser/event_parser/grammar/items.rs b/src/parser/event_parser/grammar/items.rs index 68b444b69..9b174679c 100644 --- a/src/parser/event_parser/grammar/items.rs +++ b/src/parser/event_parser/grammar/items.rs | |||
@@ -11,7 +11,7 @@ pub(super) fn mod_items(p: &mut Parser) { | |||
11 | 11 | ||
12 | fn item_first(p: &Parser) -> bool { | 12 | fn item_first(p: &Parser) -> bool { |
13 | match p.current() { | 13 | match p.current() { |
14 | STRUCT_KW | FN_KW => true, | 14 | STRUCT_KW | FN_KW | EXTERN_KW => true, |
15 | _ => false, | 15 | _ => false, |
16 | } | 16 | } |
17 | } | 17 | } |
@@ -41,7 +41,8 @@ fn item(p: &mut Parser) -> bool { | |||
41 | // || node_if(p, FN_KW, FN_ITEM, fn_item) | 41 | // || node_if(p, FN_KW, FN_ITEM, fn_item) |
42 | // || node_if(p, MOD_KW, MOD_ITEM, mod_item) | 42 | // || node_if(p, MOD_KW, MOD_ITEM, mod_item) |
43 | // || node_if(p, TYPE_KW, TYPE_ITEM, type_item) | 43 | // || node_if(p, TYPE_KW, TYPE_ITEM, type_item) |
44 | node_if(p, STRUCT_KW, STRUCT_ITEM, struct_item) | 44 | node_if(p, [EXTERN_KW, CRATE_KW], EXTERN_CRATE_ITEM, extern_crate_item) |
45 | || node_if(p, STRUCT_KW, STRUCT_ITEM, struct_item) | ||
45 | || node_if(p, FN_KW, FN_ITEM, fn_item) | 46 | || node_if(p, FN_KW, FN_ITEM, fn_item) |
46 | } | 47 | } |
47 | 48 | ||
@@ -50,6 +51,10 @@ fn struct_item(p: &mut Parser) { | |||
50 | && p.curly_block(|p| comma_list(p, EOF, struct_field)); | 51 | && p.curly_block(|p| comma_list(p, EOF, struct_field)); |
51 | } | 52 | } |
52 | 53 | ||
54 | fn extern_crate_item(p: &mut Parser) { | ||
55 | p.expect(IDENT) && alias(p) && p.expect(SEMI); | ||
56 | } | ||
57 | |||
53 | fn struct_field(p: &mut Parser) -> bool { | 58 | fn struct_field(p: &mut Parser) -> bool { |
54 | node_if(p, IDENT, STRUCT_FIELD, |p| { | 59 | node_if(p, IDENT, STRUCT_FIELD, |p| { |
55 | p.expect(COLON) && p.expect(IDENT); | 60 | p.expect(COLON) && p.expect(IDENT); |
diff --git a/src/parser/event_parser/grammar/mod.rs b/src/parser/event_parser/grammar/mod.rs index 78309aa83..dd1270eae 100644 --- a/src/parser/event_parser/grammar/mod.rs +++ b/src/parser/event_parser/grammar/mod.rs | |||
@@ -18,6 +18,13 @@ pub(crate) fn file(p: &mut Parser) { | |||
18 | fn visibility(_: &mut Parser) { | 18 | fn visibility(_: &mut Parser) { |
19 | } | 19 | } |
20 | 20 | ||
21 | fn alias(p: &mut Parser) -> bool { | ||
22 | node_if(p, AS_KW, ALIAS, |p| { | ||
23 | p.expect(IDENT); | ||
24 | }); | ||
25 | true //FIXME: return false if three are errors | ||
26 | } | ||
27 | |||
21 | fn node_if<F: FnOnce(&mut Parser), L: Lookahead>( | 28 | fn node_if<F: FnOnce(&mut Parser), L: Lookahead>( |
22 | p: &mut Parser, | 29 | p: &mut Parser, |
23 | first: L, | 30 | first: L, |
diff --git a/src/syntax_kinds.rs b/src/syntax_kinds.rs index b82a4f7f2..6db82051e 100644 --- a/src/syntax_kinds.rs +++ b/src/syntax_kinds.rs | |||
@@ -9,66 +9,71 @@ pub const TRAIT_KW: SyntaxKind = SyntaxKind(4); | |||
9 | pub const IMPL_KW: SyntaxKind = SyntaxKind(5); | 9 | pub const IMPL_KW: SyntaxKind = SyntaxKind(5); |
10 | pub const TRUE_KW: SyntaxKind = SyntaxKind(6); | 10 | pub const TRUE_KW: SyntaxKind = SyntaxKind(6); |
11 | pub const FALSE_KW: SyntaxKind = SyntaxKind(7); | 11 | pub const FALSE_KW: SyntaxKind = SyntaxKind(7); |
12 | pub const ERROR: SyntaxKind = SyntaxKind(8); | 12 | pub const AS_KW: SyntaxKind = SyntaxKind(8); |
13 | pub const IDENT: SyntaxKind = SyntaxKind(9); | 13 | pub const EXTERN_KW: SyntaxKind = SyntaxKind(9); |
14 | pub const UNDERSCORE: SyntaxKind = SyntaxKind(10); | 14 | pub const CRATE_KW: SyntaxKind = SyntaxKind(10); |
15 | pub const WHITESPACE: SyntaxKind = SyntaxKind(11); | 15 | pub const ERROR: SyntaxKind = SyntaxKind(11); |
16 | pub const INT_NUMBER: SyntaxKind = SyntaxKind(12); | 16 | pub const IDENT: SyntaxKind = SyntaxKind(12); |
17 | pub const FLOAT_NUMBER: SyntaxKind = SyntaxKind(13); | 17 | pub const UNDERSCORE: SyntaxKind = SyntaxKind(13); |
18 | pub const SEMI: SyntaxKind = SyntaxKind(14); | 18 | pub const WHITESPACE: SyntaxKind = SyntaxKind(14); |
19 | pub const COMMA: SyntaxKind = SyntaxKind(15); | 19 | pub const INT_NUMBER: SyntaxKind = SyntaxKind(15); |
20 | pub const DOT: SyntaxKind = SyntaxKind(16); | 20 | pub const FLOAT_NUMBER: SyntaxKind = SyntaxKind(16); |
21 | pub const DOTDOT: SyntaxKind = SyntaxKind(17); | 21 | pub const SEMI: SyntaxKind = SyntaxKind(17); |
22 | pub const DOTDOTDOT: SyntaxKind = SyntaxKind(18); | 22 | pub const COMMA: SyntaxKind = SyntaxKind(18); |
23 | pub const DOTDOTEQ: SyntaxKind = SyntaxKind(19); | 23 | pub const DOT: SyntaxKind = SyntaxKind(19); |
24 | pub const L_PAREN: SyntaxKind = SyntaxKind(20); | 24 | pub const DOTDOT: SyntaxKind = SyntaxKind(20); |
25 | pub const R_PAREN: SyntaxKind = SyntaxKind(21); | 25 | pub const DOTDOTDOT: SyntaxKind = SyntaxKind(21); |
26 | pub const L_CURLY: SyntaxKind = SyntaxKind(22); | 26 | pub const DOTDOTEQ: SyntaxKind = SyntaxKind(22); |
27 | pub const R_CURLY: SyntaxKind = SyntaxKind(23); | 27 | pub const L_PAREN: SyntaxKind = SyntaxKind(23); |
28 | pub const L_BRACK: SyntaxKind = SyntaxKind(24); | 28 | pub const R_PAREN: SyntaxKind = SyntaxKind(24); |
29 | pub const R_BRACK: SyntaxKind = SyntaxKind(25); | 29 | pub const L_CURLY: SyntaxKind = SyntaxKind(25); |
30 | pub const L_ANGLE: SyntaxKind = SyntaxKind(26); | 30 | pub const R_CURLY: SyntaxKind = SyntaxKind(26); |
31 | pub const R_ANGLE: SyntaxKind = SyntaxKind(27); | 31 | pub const L_BRACK: SyntaxKind = SyntaxKind(27); |
32 | pub const AT: SyntaxKind = SyntaxKind(28); | 32 | pub const R_BRACK: SyntaxKind = SyntaxKind(28); |
33 | pub const POUND: SyntaxKind = SyntaxKind(29); | 33 | pub const L_ANGLE: SyntaxKind = SyntaxKind(29); |
34 | pub const TILDE: SyntaxKind = SyntaxKind(30); | 34 | pub const R_ANGLE: SyntaxKind = SyntaxKind(30); |
35 | pub const QUESTION: SyntaxKind = SyntaxKind(31); | 35 | pub const AT: SyntaxKind = SyntaxKind(31); |
36 | pub const COLON: SyntaxKind = SyntaxKind(32); | 36 | pub const POUND: SyntaxKind = SyntaxKind(32); |
37 | pub const COLONCOLON: SyntaxKind = SyntaxKind(33); | 37 | pub const TILDE: SyntaxKind = SyntaxKind(33); |
38 | pub const DOLLAR: SyntaxKind = SyntaxKind(34); | 38 | pub const QUESTION: SyntaxKind = SyntaxKind(34); |
39 | pub const EQ: SyntaxKind = SyntaxKind(35); | 39 | pub const COLON: SyntaxKind = SyntaxKind(35); |
40 | pub const EQEQ: SyntaxKind = SyntaxKind(36); | 40 | pub const COLONCOLON: SyntaxKind = SyntaxKind(36); |
41 | pub const FAT_ARROW: SyntaxKind = SyntaxKind(37); | 41 | pub const DOLLAR: SyntaxKind = SyntaxKind(37); |
42 | pub const NEQ: SyntaxKind = SyntaxKind(38); | 42 | pub const EQ: SyntaxKind = SyntaxKind(38); |
43 | pub const EXCL: SyntaxKind = SyntaxKind(39); | 43 | pub const EQEQ: SyntaxKind = SyntaxKind(39); |
44 | pub const LIFETIME: SyntaxKind = SyntaxKind(40); | 44 | pub const FAT_ARROW: SyntaxKind = SyntaxKind(40); |
45 | pub const CHAR: SyntaxKind = SyntaxKind(41); | 45 | pub const NEQ: SyntaxKind = SyntaxKind(41); |
46 | pub const BYTE: SyntaxKind = SyntaxKind(42); | 46 | pub const EXCL: SyntaxKind = SyntaxKind(42); |
47 | pub const STRING: SyntaxKind = SyntaxKind(43); | 47 | pub const LIFETIME: SyntaxKind = SyntaxKind(43); |
48 | pub const RAW_STRING: SyntaxKind = SyntaxKind(44); | 48 | pub const CHAR: SyntaxKind = SyntaxKind(44); |
49 | pub const BYTE_STRING: SyntaxKind = SyntaxKind(45); | 49 | pub const BYTE: SyntaxKind = SyntaxKind(45); |
50 | pub const RAW_BYTE_STRING: SyntaxKind = SyntaxKind(46); | 50 | pub const STRING: SyntaxKind = SyntaxKind(46); |
51 | pub const PLUS: SyntaxKind = SyntaxKind(47); | 51 | pub const RAW_STRING: SyntaxKind = SyntaxKind(47); |
52 | pub const MINUS: SyntaxKind = SyntaxKind(48); | 52 | pub const BYTE_STRING: SyntaxKind = SyntaxKind(48); |
53 | pub const STAR: SyntaxKind = SyntaxKind(49); | 53 | pub const RAW_BYTE_STRING: SyntaxKind = SyntaxKind(49); |
54 | pub const SLASH: SyntaxKind = SyntaxKind(50); | 54 | pub const PLUS: SyntaxKind = SyntaxKind(50); |
55 | pub const CARET: SyntaxKind = SyntaxKind(51); | 55 | pub const MINUS: SyntaxKind = SyntaxKind(51); |
56 | pub const PERCENT: SyntaxKind = SyntaxKind(52); | 56 | pub const STAR: SyntaxKind = SyntaxKind(52); |
57 | pub const AMPERSAND: SyntaxKind = SyntaxKind(53); | 57 | pub const SLASH: SyntaxKind = SyntaxKind(53); |
58 | pub const PIPE: SyntaxKind = SyntaxKind(54); | 58 | pub const CARET: SyntaxKind = SyntaxKind(54); |
59 | pub const THIN_ARROW: SyntaxKind = SyntaxKind(55); | 59 | pub const PERCENT: SyntaxKind = SyntaxKind(55); |
60 | pub const COMMENT: SyntaxKind = SyntaxKind(56); | 60 | pub const AMPERSAND: SyntaxKind = SyntaxKind(56); |
61 | pub const DOC_COMMENT: SyntaxKind = SyntaxKind(57); | 61 | pub const PIPE: SyntaxKind = SyntaxKind(57); |
62 | pub const SHEBANG: SyntaxKind = SyntaxKind(58); | 62 | pub const THIN_ARROW: SyntaxKind = SyntaxKind(58); |
63 | pub const FILE: SyntaxKind = SyntaxKind(59); | 63 | pub const COMMENT: SyntaxKind = SyntaxKind(59); |
64 | pub const STRUCT_ITEM: SyntaxKind = SyntaxKind(60); | 64 | pub const DOC_COMMENT: SyntaxKind = SyntaxKind(60); |
65 | pub const STRUCT_FIELD: SyntaxKind = SyntaxKind(61); | 65 | pub const SHEBANG: SyntaxKind = SyntaxKind(61); |
66 | pub const FN_ITEM: SyntaxKind = SyntaxKind(62); | 66 | pub const FILE: SyntaxKind = SyntaxKind(62); |
67 | pub const ATTR: SyntaxKind = SyntaxKind(63); | 67 | pub const STRUCT_ITEM: SyntaxKind = SyntaxKind(63); |
68 | pub const META_ITEM: SyntaxKind = SyntaxKind(64); | 68 | pub const STRUCT_FIELD: SyntaxKind = SyntaxKind(64); |
69 | pub const LITERAL: SyntaxKind = SyntaxKind(65); | 69 | pub const FN_ITEM: SyntaxKind = SyntaxKind(65); |
70 | pub const EXTERN_CRATE_ITEM: SyntaxKind = SyntaxKind(66); | ||
71 | pub const ATTR: SyntaxKind = SyntaxKind(67); | ||
72 | pub const META_ITEM: SyntaxKind = SyntaxKind(68); | ||
73 | pub const LITERAL: SyntaxKind = SyntaxKind(69); | ||
74 | pub const ALIAS: SyntaxKind = SyntaxKind(70); | ||
70 | 75 | ||
71 | static INFOS: [SyntaxInfo; 66] = [ | 76 | static INFOS: [SyntaxInfo; 71] = [ |
72 | SyntaxInfo { name: "USE_KW" }, | 77 | SyntaxInfo { name: "USE_KW" }, |
73 | SyntaxInfo { name: "FN_KW" }, | 78 | SyntaxInfo { name: "FN_KW" }, |
74 | SyntaxInfo { name: "STRUCT_KW" }, | 79 | SyntaxInfo { name: "STRUCT_KW" }, |
@@ -77,6 +82,9 @@ static INFOS: [SyntaxInfo; 66] = [ | |||
77 | SyntaxInfo { name: "IMPL_KW" }, | 82 | SyntaxInfo { name: "IMPL_KW" }, |
78 | SyntaxInfo { name: "TRUE_KW" }, | 83 | SyntaxInfo { name: "TRUE_KW" }, |
79 | SyntaxInfo { name: "FALSE_KW" }, | 84 | SyntaxInfo { name: "FALSE_KW" }, |
85 | SyntaxInfo { name: "AS_KW" }, | ||
86 | SyntaxInfo { name: "EXTERN_KW" }, | ||
87 | SyntaxInfo { name: "CRATE_KW" }, | ||
80 | SyntaxInfo { name: "ERROR" }, | 88 | SyntaxInfo { name: "ERROR" }, |
81 | SyntaxInfo { name: "IDENT" }, | 89 | SyntaxInfo { name: "IDENT" }, |
82 | SyntaxInfo { name: "UNDERSCORE" }, | 90 | SyntaxInfo { name: "UNDERSCORE" }, |
@@ -132,9 +140,11 @@ static INFOS: [SyntaxInfo; 66] = [ | |||
132 | SyntaxInfo { name: "STRUCT_ITEM" }, | 140 | SyntaxInfo { name: "STRUCT_ITEM" }, |
133 | SyntaxInfo { name: "STRUCT_FIELD" }, | 141 | SyntaxInfo { name: "STRUCT_FIELD" }, |
134 | SyntaxInfo { name: "FN_ITEM" }, | 142 | SyntaxInfo { name: "FN_ITEM" }, |
143 | SyntaxInfo { name: "EXTERN_CRATE_ITEM" }, | ||
135 | SyntaxInfo { name: "ATTR" }, | 144 | SyntaxInfo { name: "ATTR" }, |
136 | SyntaxInfo { name: "META_ITEM" }, | 145 | SyntaxInfo { name: "META_ITEM" }, |
137 | SyntaxInfo { name: "LITERAL" }, | 146 | SyntaxInfo { name: "LITERAL" }, |
147 | SyntaxInfo { name: "ALIAS" }, | ||
138 | ]; | 148 | ]; |
139 | 149 | ||
140 | pub(crate) fn syntax_info(kind: SyntaxKind) -> &'static SyntaxInfo { | 150 | pub(crate) fn syntax_info(kind: SyntaxKind) -> &'static SyntaxInfo { |
@@ -151,6 +161,9 @@ pub(crate) fn ident_to_keyword(ident: &str) -> Option<SyntaxKind> { | |||
151 | "impl" => Some(IMPL_KW), | 161 | "impl" => Some(IMPL_KW), |
152 | "true" => Some(TRUE_KW), | 162 | "true" => Some(TRUE_KW), |
153 | "false" => Some(FALSE_KW), | 163 | "false" => Some(FALSE_KW), |
164 | "as" => Some(AS_KW), | ||
165 | "extern" => Some(EXTERN_KW), | ||
166 | "crate" => Some(CRATE_KW), | ||
154 | _ => None, | 167 | _ => None, |
155 | } | 168 | } |
156 | } | 169 | } |
diff --git a/tests/data/lexer/0011_keywords.rs b/tests/data/lexer/0011_keywords.rs index 1f4a4a74c..4adb1587e 100644 --- a/tests/data/lexer/0011_keywords.rs +++ b/tests/data/lexer/0011_keywords.rs | |||
@@ -1 +1 @@ | |||
fn use struct trait enum impl true false | fn use struct trait enum impl true false as extern crate | ||
diff --git a/tests/data/lexer/0011_keywords.txt b/tests/data/lexer/0011_keywords.txt index eded37084..bf8ceffd4 100644 --- a/tests/data/lexer/0011_keywords.txt +++ b/tests/data/lexer/0011_keywords.txt | |||
@@ -13,4 +13,10 @@ WHITESPACE 1 " " | |||
13 | TRUE_KW 4 "true" | 13 | TRUE_KW 4 "true" |
14 | WHITESPACE 1 " " | 14 | WHITESPACE 1 " " |
15 | FALSE_KW 5 "false" | 15 | FALSE_KW 5 "false" |
16 | WHITESPACE 1 " " | ||
17 | AS_KW 2 "as" | ||
18 | WHITESPACE 1 " " | ||
19 | EXTERN_KW 6 "extern" | ||
20 | WHITESPACE 1 " " | ||
21 | CRATE_KW 5 "crate" | ||
16 | WHITESPACE 1 "\n" | 22 | WHITESPACE 1 "\n" |
diff --git a/tests/data/parser/ok/0007_extern_crate.rs b/tests/data/parser/ok/0007_extern_crate.rs new file mode 100644 index 000000000..3ce336676 --- /dev/null +++ b/tests/data/parser/ok/0007_extern_crate.rs | |||
@@ -0,0 +1,2 @@ | |||
1 | extern crate foo; | ||
2 | extern crate foo as bar; | ||
diff --git a/tests/data/parser/ok/0007_extern_crate.txt b/tests/data/parser/ok/0007_extern_crate.txt new file mode 100644 index 000000000..902c80f7d --- /dev/null +++ b/tests/data/parser/ok/0007_extern_crate.txt | |||
@@ -0,0 +1,22 @@ | |||
1 | FILE@[0; 43) | ||
2 | EXTERN_CRATE_ITEM@[0; 18) | ||
3 | EXTERN_KW@[0; 6) | ||
4 | WHITESPACE@[6; 7) | ||
5 | CRATE_KW@[7; 12) | ||
6 | WHITESPACE@[12; 13) | ||
7 | IDENT@[13; 16) | ||
8 | SEMI@[16; 17) | ||
9 | WHITESPACE@[17; 18) | ||
10 | EXTERN_CRATE_ITEM@[18; 43) | ||
11 | EXTERN_KW@[18; 24) | ||
12 | WHITESPACE@[24; 25) | ||
13 | CRATE_KW@[25; 30) | ||
14 | WHITESPACE@[30; 31) | ||
15 | IDENT@[31; 34) | ||
16 | ALIAS@[34; 41) | ||
17 | WHITESPACE@[34; 35) | ||
18 | AS_KW@[35; 37) | ||
19 | WHITESPACE@[37; 38) | ||
20 | IDENT@[38; 41) | ||
21 | SEMI@[41; 42) | ||
22 | WHITESPACE@[42; 43) | ||