diff options
author | Aleksey Kladov <[email protected]> | 2018-01-13 08:55:03 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-01-13 08:55:03 +0000 |
commit | 29b2e0adcc35834dda2884222624bfcc268a3eff (patch) | |
tree | 0838a22c27bba0361dcde3660075175f243a4d7a | |
parent | f31d85860771b0c4c8d232d79e4a3489a051ba9d (diff) |
G: allow self & super in paths
-rw-r--r-- | grammar.ron | 1 | ||||
-rw-r--r-- | src/parser/event_parser/grammar/paths.rs | 13 | ||||
-rw-r--r-- | src/syntax_kinds.rs | 135 | ||||
-rw-r--r-- | tests/data/lexer/0011_keywords.rs | 3 | ||||
-rw-r--r-- | tests/data/lexer/0011_keywords.txt | 4 | ||||
-rw-r--r-- | tests/data/parser/err/0004_use_path_bad_segment.rs | 1 | ||||
-rw-r--r-- | tests/data/parser/err/0004_use_path_bad_segment.txt | 16 | ||||
-rw-r--r-- | tests/data/parser/ok/0012_visibility.txt | 2 | ||||
-rw-r--r-- | tests/data/parser/ok/0013_use_path_self_super.rs | 3 | ||||
-rw-r--r-- | tests/data/parser/ok/0013_use_path_self_super.txt | 50 |
10 files changed, 156 insertions, 72 deletions
diff --git a/grammar.ron b/grammar.ron index ed3af53e4..ca6299f23 100644 --- a/grammar.ron +++ b/grammar.ron | |||
@@ -15,6 +15,7 @@ Grammar( | |||
15 | "pub", | 15 | "pub", |
16 | "self", | 16 | "self", |
17 | "super", | 17 | "super", |
18 | "in", | ||
18 | ], | 19 | ], |
19 | tokens: [ | 20 | tokens: [ |
20 | "ERROR", | 21 | "ERROR", |
diff --git a/src/parser/event_parser/grammar/paths.rs b/src/parser/event_parser/grammar/paths.rs index 108545bc2..d6887a9ba 100644 --- a/src/parser/event_parser/grammar/paths.rs +++ b/src/parser/event_parser/grammar/paths.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | use super::*; | 1 | use super::*; |
2 | 2 | ||
3 | pub(crate) fn use_path(p: &mut Parser) { | 3 | pub(crate) fn use_path(p: &mut Parser) { |
4 | if !AnyOf(&[IDENT, COLONCOLON]).is_ahead(p) { | 4 | if !AnyOf(&[IDENT, SELF_KW, SUPER_KW, COLONCOLON]).is_ahead(p) { |
5 | return; | 5 | return; |
6 | } | 6 | } |
7 | let mut prev = p.mark(); | 7 | let mut prev = p.mark(); |
@@ -23,6 +23,15 @@ fn path_segment(p: &mut Parser, first: bool) { | |||
23 | if first { | 23 | if first { |
24 | p.eat(COLONCOLON); | 24 | p.eat(COLONCOLON); |
25 | } | 25 | } |
26 | p.expect(IDENT); | 26 | match p.current() { |
27 | IDENT | SELF_KW | SUPER_KW => { | ||
28 | p.bump(); | ||
29 | }, | ||
30 | _ => { | ||
31 | p.error() | ||
32 | .message("expected identifier") | ||
33 | .emit(); | ||
34 | } | ||
35 | }; | ||
27 | }) | 36 | }) |
28 | } \ No newline at end of file | 37 | } \ No newline at end of file |
diff --git a/src/syntax_kinds.rs b/src/syntax_kinds.rs index 84f1072b7..48f55fa97 100644 --- a/src/syntax_kinds.rs +++ b/src/syntax_kinds.rs | |||
@@ -16,73 +16,74 @@ pub const MOD_KW: SyntaxKind = SyntaxKind(11); | |||
16 | pub const PUB_KW: SyntaxKind = SyntaxKind(12); | 16 | pub const PUB_KW: SyntaxKind = SyntaxKind(12); |
17 | pub const SELF_KW: SyntaxKind = SyntaxKind(13); | 17 | pub const SELF_KW: SyntaxKind = SyntaxKind(13); |
18 | pub const SUPER_KW: SyntaxKind = SyntaxKind(14); | 18 | pub const SUPER_KW: SyntaxKind = SyntaxKind(14); |
19 | pub const ERROR: SyntaxKind = SyntaxKind(15); | 19 | pub const IN_KW: SyntaxKind = SyntaxKind(15); |
20 | pub const IDENT: SyntaxKind = SyntaxKind(16); | 20 | pub const ERROR: SyntaxKind = SyntaxKind(16); |
21 | pub const UNDERSCORE: SyntaxKind = SyntaxKind(17); | 21 | pub const IDENT: SyntaxKind = SyntaxKind(17); |
22 | pub const WHITESPACE: SyntaxKind = SyntaxKind(18); | 22 | pub const UNDERSCORE: SyntaxKind = SyntaxKind(18); |
23 | pub const INT_NUMBER: SyntaxKind = SyntaxKind(19); | 23 | pub const WHITESPACE: SyntaxKind = SyntaxKind(19); |
24 | pub const FLOAT_NUMBER: SyntaxKind = SyntaxKind(20); | 24 | pub const INT_NUMBER: SyntaxKind = SyntaxKind(20); |
25 | pub const SEMI: SyntaxKind = SyntaxKind(21); | 25 | pub const FLOAT_NUMBER: SyntaxKind = SyntaxKind(21); |
26 | pub const COMMA: SyntaxKind = SyntaxKind(22); | 26 | pub const SEMI: SyntaxKind = SyntaxKind(22); |
27 | pub const DOT: SyntaxKind = SyntaxKind(23); | 27 | pub const COMMA: SyntaxKind = SyntaxKind(23); |
28 | pub const DOTDOT: SyntaxKind = SyntaxKind(24); | 28 | pub const DOT: SyntaxKind = SyntaxKind(24); |
29 | pub const DOTDOTDOT: SyntaxKind = SyntaxKind(25); | 29 | pub const DOTDOT: SyntaxKind = SyntaxKind(25); |
30 | pub const DOTDOTEQ: SyntaxKind = SyntaxKind(26); | 30 | pub const DOTDOTDOT: SyntaxKind = SyntaxKind(26); |
31 | pub const L_PAREN: SyntaxKind = SyntaxKind(27); | 31 | pub const DOTDOTEQ: SyntaxKind = SyntaxKind(27); |
32 | pub const R_PAREN: SyntaxKind = SyntaxKind(28); | 32 | pub const L_PAREN: SyntaxKind = SyntaxKind(28); |
33 | pub const L_CURLY: SyntaxKind = SyntaxKind(29); | 33 | pub const R_PAREN: SyntaxKind = SyntaxKind(29); |
34 | pub const R_CURLY: SyntaxKind = SyntaxKind(30); | 34 | pub const L_CURLY: SyntaxKind = SyntaxKind(30); |
35 | pub const L_BRACK: SyntaxKind = SyntaxKind(31); | 35 | pub const R_CURLY: SyntaxKind = SyntaxKind(31); |
36 | pub const R_BRACK: SyntaxKind = SyntaxKind(32); | 36 | pub const L_BRACK: SyntaxKind = SyntaxKind(32); |
37 | pub const L_ANGLE: SyntaxKind = SyntaxKind(33); | 37 | pub const R_BRACK: SyntaxKind = SyntaxKind(33); |
38 | pub const R_ANGLE: SyntaxKind = SyntaxKind(34); | 38 | pub const L_ANGLE: SyntaxKind = SyntaxKind(34); |
39 | pub const AT: SyntaxKind = SyntaxKind(35); | 39 | pub const R_ANGLE: SyntaxKind = SyntaxKind(35); |
40 | pub const POUND: SyntaxKind = SyntaxKind(36); | 40 | pub const AT: SyntaxKind = SyntaxKind(36); |
41 | pub const TILDE: SyntaxKind = SyntaxKind(37); | 41 | pub const POUND: SyntaxKind = SyntaxKind(37); |
42 | pub const QUESTION: SyntaxKind = SyntaxKind(38); | 42 | pub const TILDE: SyntaxKind = SyntaxKind(38); |
43 | pub const COLON: SyntaxKind = SyntaxKind(39); | 43 | pub const QUESTION: SyntaxKind = SyntaxKind(39); |
44 | pub const COLONCOLON: SyntaxKind = SyntaxKind(40); | 44 | pub const COLON: SyntaxKind = SyntaxKind(40); |
45 | pub const DOLLAR: SyntaxKind = SyntaxKind(41); | 45 | pub const COLONCOLON: SyntaxKind = SyntaxKind(41); |
46 | pub const EQ: SyntaxKind = SyntaxKind(42); | 46 | pub const DOLLAR: SyntaxKind = SyntaxKind(42); |
47 | pub const EQEQ: SyntaxKind = SyntaxKind(43); | 47 | pub const EQ: SyntaxKind = SyntaxKind(43); |
48 | pub const FAT_ARROW: SyntaxKind = SyntaxKind(44); | 48 | pub const EQEQ: SyntaxKind = SyntaxKind(44); |
49 | pub const NEQ: SyntaxKind = SyntaxKind(45); | 49 | pub const FAT_ARROW: SyntaxKind = SyntaxKind(45); |
50 | pub const EXCL: SyntaxKind = SyntaxKind(46); | 50 | pub const NEQ: SyntaxKind = SyntaxKind(46); |
51 | pub const LIFETIME: SyntaxKind = SyntaxKind(47); | 51 | pub const EXCL: SyntaxKind = SyntaxKind(47); |
52 | pub const CHAR: SyntaxKind = SyntaxKind(48); | 52 | pub const LIFETIME: SyntaxKind = SyntaxKind(48); |
53 | pub const BYTE: SyntaxKind = SyntaxKind(49); | 53 | pub const CHAR: SyntaxKind = SyntaxKind(49); |
54 | pub const STRING: SyntaxKind = SyntaxKind(50); | 54 | pub const BYTE: SyntaxKind = SyntaxKind(50); |
55 | pub const RAW_STRING: SyntaxKind = SyntaxKind(51); | 55 | pub const STRING: SyntaxKind = SyntaxKind(51); |
56 | pub const BYTE_STRING: SyntaxKind = SyntaxKind(52); | 56 | pub const RAW_STRING: SyntaxKind = SyntaxKind(52); |
57 | pub const RAW_BYTE_STRING: SyntaxKind = SyntaxKind(53); | 57 | pub const BYTE_STRING: SyntaxKind = SyntaxKind(53); |
58 | pub const PLUS: SyntaxKind = SyntaxKind(54); | 58 | pub const RAW_BYTE_STRING: SyntaxKind = SyntaxKind(54); |
59 | pub const MINUS: SyntaxKind = SyntaxKind(55); | 59 | pub const PLUS: SyntaxKind = SyntaxKind(55); |
60 | pub const STAR: SyntaxKind = SyntaxKind(56); | 60 | pub const MINUS: SyntaxKind = SyntaxKind(56); |
61 | pub const SLASH: SyntaxKind = SyntaxKind(57); | 61 | pub const STAR: SyntaxKind = SyntaxKind(57); |
62 | pub const CARET: SyntaxKind = SyntaxKind(58); | 62 | pub const SLASH: SyntaxKind = SyntaxKind(58); |
63 | pub const PERCENT: SyntaxKind = SyntaxKind(59); | 63 | pub const CARET: SyntaxKind = SyntaxKind(59); |
64 | pub const AMPERSAND: SyntaxKind = SyntaxKind(60); | 64 | pub const PERCENT: SyntaxKind = SyntaxKind(60); |
65 | pub const PIPE: SyntaxKind = SyntaxKind(61); | 65 | pub const AMPERSAND: SyntaxKind = SyntaxKind(61); |
66 | pub const THIN_ARROW: SyntaxKind = SyntaxKind(62); | 66 | pub const PIPE: SyntaxKind = SyntaxKind(62); |
67 | pub const COMMENT: SyntaxKind = SyntaxKind(63); | 67 | pub const THIN_ARROW: SyntaxKind = SyntaxKind(63); |
68 | pub const DOC_COMMENT: SyntaxKind = SyntaxKind(64); | 68 | pub const COMMENT: SyntaxKind = SyntaxKind(64); |
69 | pub const SHEBANG: SyntaxKind = SyntaxKind(65); | 69 | pub const DOC_COMMENT: SyntaxKind = SyntaxKind(65); |
70 | pub const FILE: SyntaxKind = SyntaxKind(66); | 70 | pub const SHEBANG: SyntaxKind = SyntaxKind(66); |
71 | pub const STRUCT_ITEM: SyntaxKind = SyntaxKind(67); | 71 | pub const FILE: SyntaxKind = SyntaxKind(67); |
72 | pub const STRUCT_FIELD: SyntaxKind = SyntaxKind(68); | 72 | pub const STRUCT_ITEM: SyntaxKind = SyntaxKind(68); |
73 | pub const FN_ITEM: SyntaxKind = SyntaxKind(69); | 73 | pub const STRUCT_FIELD: SyntaxKind = SyntaxKind(69); |
74 | pub const EXTERN_CRATE_ITEM: SyntaxKind = SyntaxKind(70); | 74 | pub const FN_ITEM: SyntaxKind = SyntaxKind(70); |
75 | pub const ATTR: SyntaxKind = SyntaxKind(71); | 75 | pub const EXTERN_CRATE_ITEM: SyntaxKind = SyntaxKind(71); |
76 | pub const META_ITEM: SyntaxKind = SyntaxKind(72); | 76 | pub const ATTR: SyntaxKind = SyntaxKind(72); |
77 | pub const MOD_ITEM: SyntaxKind = SyntaxKind(73); | 77 | pub const META_ITEM: SyntaxKind = SyntaxKind(73); |
78 | pub const USE_ITEM: SyntaxKind = SyntaxKind(74); | 78 | pub const MOD_ITEM: SyntaxKind = SyntaxKind(74); |
79 | pub const PATH: SyntaxKind = SyntaxKind(75); | 79 | pub const USE_ITEM: SyntaxKind = SyntaxKind(75); |
80 | pub const PATH_SEGMENT: SyntaxKind = SyntaxKind(76); | 80 | pub const PATH: SyntaxKind = SyntaxKind(76); |
81 | pub const LITERAL: SyntaxKind = SyntaxKind(77); | 81 | pub const PATH_SEGMENT: SyntaxKind = SyntaxKind(77); |
82 | pub const ALIAS: SyntaxKind = SyntaxKind(78); | 82 | pub const LITERAL: SyntaxKind = SyntaxKind(78); |
83 | pub const VISIBILITY: SyntaxKind = SyntaxKind(79); | 83 | pub const ALIAS: SyntaxKind = SyntaxKind(79); |
84 | pub const VISIBILITY: SyntaxKind = SyntaxKind(80); | ||
84 | 85 | ||
85 | static INFOS: [SyntaxInfo; 80] = [ | 86 | static INFOS: [SyntaxInfo; 81] = [ |
86 | SyntaxInfo { name: "USE_KW" }, | 87 | SyntaxInfo { name: "USE_KW" }, |
87 | SyntaxInfo { name: "FN_KW" }, | 88 | SyntaxInfo { name: "FN_KW" }, |
88 | SyntaxInfo { name: "STRUCT_KW" }, | 89 | SyntaxInfo { name: "STRUCT_KW" }, |
@@ -98,6 +99,7 @@ static INFOS: [SyntaxInfo; 80] = [ | |||
98 | SyntaxInfo { name: "PUB_KW" }, | 99 | SyntaxInfo { name: "PUB_KW" }, |
99 | SyntaxInfo { name: "SELF_KW" }, | 100 | SyntaxInfo { name: "SELF_KW" }, |
100 | SyntaxInfo { name: "SUPER_KW" }, | 101 | SyntaxInfo { name: "SUPER_KW" }, |
102 | SyntaxInfo { name: "IN_KW" }, | ||
101 | SyntaxInfo { name: "ERROR" }, | 103 | SyntaxInfo { name: "ERROR" }, |
102 | SyntaxInfo { name: "IDENT" }, | 104 | SyntaxInfo { name: "IDENT" }, |
103 | SyntaxInfo { name: "UNDERSCORE" }, | 105 | SyntaxInfo { name: "UNDERSCORE" }, |
@@ -186,6 +188,7 @@ pub(crate) fn ident_to_keyword(ident: &str) -> Option<SyntaxKind> { | |||
186 | "pub" => Some(PUB_KW), | 188 | "pub" => Some(PUB_KW), |
187 | "self" => Some(SELF_KW), | 189 | "self" => Some(SELF_KW), |
188 | "super" => Some(SUPER_KW), | 190 | "super" => Some(SUPER_KW), |
191 | "in" => Some(IN_KW), | ||
189 | _ => None, | 192 | _ => None, |
190 | } | 193 | } |
191 | } | 194 | } |
diff --git a/tests/data/lexer/0011_keywords.rs b/tests/data/lexer/0011_keywords.rs index c5a58a205..aa729cdbd 100644 --- a/tests/data/lexer/0011_keywords.rs +++ b/tests/data/lexer/0011_keywords.rs | |||
@@ -1,2 +1 @@ | |||
1 | fn use struct trait enum impl true false as extern crate mod pub self super | fn use struct trait enum impl true false as extern crate mod pub self super in | |
2 | |||
diff --git a/tests/data/lexer/0011_keywords.txt b/tests/data/lexer/0011_keywords.txt index 248628f34..8a1f525ac 100644 --- a/tests/data/lexer/0011_keywords.txt +++ b/tests/data/lexer/0011_keywords.txt | |||
@@ -27,4 +27,6 @@ WHITESPACE 1 " " | |||
27 | SELF_KW 4 "self" | 27 | SELF_KW 4 "self" |
28 | WHITESPACE 1 " " | 28 | WHITESPACE 1 " " |
29 | SUPER_KW 5 "super" | 29 | SUPER_KW 5 "super" |
30 | WHITESPACE 2 "\n\n" | 30 | WHITESPACE 1 " " |
31 | IN_KW 2 "in" | ||
32 | WHITESPACE 1 "\n" | ||
diff --git a/tests/data/parser/err/0004_use_path_bad_segment.rs b/tests/data/parser/err/0004_use_path_bad_segment.rs new file mode 100644 index 000000000..060e65d06 --- /dev/null +++ b/tests/data/parser/err/0004_use_path_bad_segment.rs | |||
@@ -0,0 +1 @@ | |||
use foo::92; \ No newline at end of file | |||
diff --git a/tests/data/parser/err/0004_use_path_bad_segment.txt b/tests/data/parser/err/0004_use_path_bad_segment.txt new file mode 100644 index 000000000..241ee8562 --- /dev/null +++ b/tests/data/parser/err/0004_use_path_bad_segment.txt | |||
@@ -0,0 +1,16 @@ | |||
1 | FILE@[0; 12) | ||
2 | USE_ITEM@[0; 9) | ||
3 | USE_KW@[0; 3) | ||
4 | PATH@[3; 9) | ||
5 | PATH@[3; 7) | ||
6 | PATH_SEGMENT@[3; 7) | ||
7 | WHITESPACE@[3; 4) | ||
8 | IDENT@[4; 7) | ||
9 | COLONCOLON@[7; 9) | ||
10 | PATH_SEGMENT@[9; 9) | ||
11 | err: `expected identifier` | ||
12 | err: `expected SEMI` | ||
13 | ERROR@[9; 12) | ||
14 | err: `expected item` | ||
15 | INT_NUMBER@[9; 11) | ||
16 | SEMI@[11; 12) | ||
diff --git a/tests/data/parser/ok/0012_visibility.txt b/tests/data/parser/ok/0012_visibility.txt index 8324c48d5..0e091724d 100644 --- a/tests/data/parser/ok/0012_visibility.txt +++ b/tests/data/parser/ok/0012_visibility.txt | |||
@@ -58,7 +58,7 @@ FILE@[0; 98) | |||
58 | VISIBILITY@[66; 88) | 58 | VISIBILITY@[66; 88) |
59 | PUB_KW@[66; 69) | 59 | PUB_KW@[66; 69) |
60 | L_PAREN@[69; 70) | 60 | L_PAREN@[69; 70) |
61 | IDENT@[70; 72) | 61 | IN_KW@[70; 72) |
62 | PATH@[72; 86) | 62 | PATH@[72; 86) |
63 | PATH@[72; 81) | 63 | PATH@[72; 81) |
64 | PATH@[72; 76) | 64 | PATH@[72; 76) |
diff --git a/tests/data/parser/ok/0013_use_path_self_super.rs b/tests/data/parser/ok/0013_use_path_self_super.rs new file mode 100644 index 000000000..faf6a42c7 --- /dev/null +++ b/tests/data/parser/ok/0013_use_path_self_super.rs | |||
@@ -0,0 +1,3 @@ | |||
1 | use self::foo; | ||
2 | use super::super::bar; | ||
3 | use ::self::a::super::bar; | ||
diff --git a/tests/data/parser/ok/0013_use_path_self_super.txt b/tests/data/parser/ok/0013_use_path_self_super.txt new file mode 100644 index 000000000..90bbb9b2d --- /dev/null +++ b/tests/data/parser/ok/0013_use_path_self_super.txt | |||
@@ -0,0 +1,50 @@ | |||
1 | FILE@[0; 65) | ||
2 | USE_ITEM@[0; 15) | ||
3 | USE_KW@[0; 3) | ||
4 | PATH@[3; 13) | ||
5 | PATH@[3; 8) | ||
6 | PATH_SEGMENT@[3; 8) | ||
7 | WHITESPACE@[3; 4) | ||
8 | SELF_KW@[4; 8) | ||
9 | COLONCOLON@[8; 10) | ||
10 | PATH_SEGMENT@[10; 13) | ||
11 | IDENT@[10; 13) | ||
12 | SEMI@[13; 14) | ||
13 | WHITESPACE@[14; 15) | ||
14 | USE_ITEM@[15; 38) | ||
15 | USE_KW@[15; 18) | ||
16 | PATH@[18; 36) | ||
17 | PATH@[18; 31) | ||
18 | PATH@[18; 24) | ||
19 | PATH_SEGMENT@[18; 24) | ||
20 | WHITESPACE@[18; 19) | ||
21 | SUPER_KW@[19; 24) | ||
22 | COLONCOLON@[24; 26) | ||
23 | PATH_SEGMENT@[26; 31) | ||
24 | SUPER_KW@[26; 31) | ||
25 | COLONCOLON@[31; 33) | ||
26 | PATH_SEGMENT@[33; 36) | ||
27 | IDENT@[33; 36) | ||
28 | SEMI@[36; 37) | ||
29 | WHITESPACE@[37; 38) | ||
30 | USE_ITEM@[38; 65) | ||
31 | USE_KW@[38; 41) | ||
32 | PATH@[41; 63) | ||
33 | PATH@[41; 58) | ||
34 | PATH@[41; 51) | ||
35 | PATH@[41; 48) | ||
36 | PATH_SEGMENT@[41; 48) | ||
37 | WHITESPACE@[41; 42) | ||
38 | COLONCOLON@[42; 44) | ||
39 | SELF_KW@[44; 48) | ||
40 | COLONCOLON@[48; 50) | ||
41 | PATH_SEGMENT@[50; 51) | ||
42 | IDENT@[50; 51) | ||
43 | COLONCOLON@[51; 53) | ||
44 | PATH_SEGMENT@[53; 58) | ||
45 | SUPER_KW@[53; 58) | ||
46 | COLONCOLON@[58; 60) | ||
47 | PATH_SEGMENT@[60; 63) | ||
48 | IDENT@[60; 63) | ||
49 | SEMI@[63; 64) | ||
50 | WHITESPACE@[64; 65) | ||