diff options
author | Aleksey Kladov <[email protected]> | 2018-02-10 11:00:23 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-02-10 11:00:23 +0000 |
commit | fc0a9e266b9d663b1eeca3963495c68ca3384be2 (patch) | |
tree | 324632ed4e19f1b2499d8d1be9b4bc631878a3ba | |
parent | c3b009b6d24225ad2add62fce8206918fceba3eb (diff) |
G: introduce names
-rw-r--r-- | grammar.ron | 2 | ||||
-rw-r--r-- | src/parser/grammar/items/mod.rs | 5 | ||||
-rw-r--r-- | src/parser/grammar/mod.rs | 12 | ||||
-rw-r--r-- | src/syntax_kinds.rs | 4 | ||||
-rw-r--r-- | tests/data/parser/inline/0005_extern_crate.txt | 5 | ||||
-rw-r--r-- | tests/data/parser/ok/0007_extern_crate.txt | 17 | ||||
-rw-r--r-- | tests/data/parser/ok/0015_use_tree.txt | 15 |
7 files changed, 42 insertions, 18 deletions
diff --git a/grammar.ron b/grammar.ron index c38bf654d..0130b7b37 100644 --- a/grammar.ron +++ b/grammar.ron | |||
@@ -118,5 +118,7 @@ Grammar( | |||
118 | "LIFETIME_PARAM", | 118 | "LIFETIME_PARAM", |
119 | "TYPE_PARAM", | 119 | "TYPE_PARAM", |
120 | "ABI", | 120 | "ABI", |
121 | "NAME", | ||
122 | "NAME_REF", | ||
121 | ] | 123 | ] |
122 | ) | 124 | ) |
diff --git a/src/parser/grammar/items/mod.rs b/src/parser/grammar/items/mod.rs index ffe86fa97..d671568b1 100644 --- a/src/parser/grammar/items/mod.rs +++ b/src/parser/grammar/items/mod.rs | |||
@@ -196,8 +196,9 @@ fn extern_crate_item(p: &mut Parser) { | |||
196 | p.bump(); | 196 | p.bump(); |
197 | assert!(p.at(CRATE_KW)); | 197 | assert!(p.at(CRATE_KW)); |
198 | p.bump(); | 198 | p.bump(); |
199 | 199 | name(p); | |
200 | p.expect(IDENT) && alias(p) && p.expect(SEMI); | 200 | alias(p); |
201 | p.expect(SEMI); | ||
201 | } | 202 | } |
202 | 203 | ||
203 | fn extern_block(p: &mut Parser) { | 204 | fn extern_block(p: &mut Parser) { |
diff --git a/src/parser/grammar/mod.rs b/src/parser/grammar/mod.rs index b949583ff..6e82d7c69 100644 --- a/src/parser/grammar/mod.rs +++ b/src/parser/grammar/mod.rs | |||
@@ -44,12 +44,22 @@ fn alias(p: &mut Parser) -> bool { | |||
44 | if p.at(AS_KW) { | 44 | if p.at(AS_KW) { |
45 | let alias = p.start(); | 45 | let alias = p.start(); |
46 | p.bump(); | 46 | p.bump(); |
47 | p.expect(IDENT); | 47 | name(p); |
48 | alias.complete(p, ALIAS); | 48 | alias.complete(p, ALIAS); |
49 | } | 49 | } |
50 | true //FIXME: return false if three are errors | 50 | true //FIXME: return false if three are errors |
51 | } | 51 | } |
52 | 52 | ||
53 | fn name(p: &mut Parser) { | ||
54 | if p.at(IDENT) { | ||
55 | let m = p.start(); | ||
56 | p.bump(); | ||
57 | m.complete(p, NAME); | ||
58 | } else { | ||
59 | p.error("expected a name"); | ||
60 | } | ||
61 | } | ||
62 | |||
53 | fn error_block(p: &mut Parser, message: &str) { | 63 | fn error_block(p: &mut Parser, message: &str) { |
54 | assert!(p.at(L_CURLY)); | 64 | assert!(p.at(L_CURLY)); |
55 | let err = p.start(); | 65 | let err = p.start(); |
diff --git a/src/syntax_kinds.rs b/src/syntax_kinds.rs index dc287f0f4..7450f9d6f 100644 --- a/src/syntax_kinds.rs +++ b/src/syntax_kinds.rs | |||
@@ -116,6 +116,8 @@ pub enum SyntaxKind { | |||
116 | LIFETIME_PARAM, | 116 | LIFETIME_PARAM, |
117 | TYPE_PARAM, | 117 | TYPE_PARAM, |
118 | ABI, | 118 | ABI, |
119 | NAME, | ||
120 | NAME_REF, | ||
119 | 121 | ||
120 | // Technical SyntaxKinds: they appear temporally during parsing, | 122 | // Technical SyntaxKinds: they appear temporally during parsing, |
121 | // but never end up in the final tree | 123 | // but never end up in the final tree |
@@ -239,6 +241,8 @@ impl SyntaxKind { | |||
239 | LIFETIME_PARAM => &SyntaxInfo { name: "LIFETIME_PARAM" }, | 241 | LIFETIME_PARAM => &SyntaxInfo { name: "LIFETIME_PARAM" }, |
240 | TYPE_PARAM => &SyntaxInfo { name: "TYPE_PARAM" }, | 242 | TYPE_PARAM => &SyntaxInfo { name: "TYPE_PARAM" }, |
241 | ABI => &SyntaxInfo { name: "ABI" }, | 243 | ABI => &SyntaxInfo { name: "ABI" }, |
244 | NAME => &SyntaxInfo { name: "NAME" }, | ||
245 | NAME_REF => &SyntaxInfo { name: "NAME_REF" }, | ||
242 | 246 | ||
243 | TOMBSTONE => &SyntaxInfo { name: "TOMBSTONE" }, | 247 | TOMBSTONE => &SyntaxInfo { name: "TOMBSTONE" }, |
244 | EOF => &SyntaxInfo { name: "EOF" }, | 248 | EOF => &SyntaxInfo { name: "EOF" }, |
diff --git a/tests/data/parser/inline/0005_extern_crate.txt b/tests/data/parser/inline/0005_extern_crate.txt index 07cc47875..cbdf5aba1 100644 --- a/tests/data/parser/inline/0005_extern_crate.txt +++ b/tests/data/parser/inline/0005_extern_crate.txt | |||
@@ -3,7 +3,8 @@ FILE@[0; 18) | |||
3 | EXTERN_KW@[0; 6) | 3 | EXTERN_KW@[0; 6) |
4 | WHITESPACE@[6; 7) | 4 | WHITESPACE@[6; 7) |
5 | CRATE_KW@[7; 12) | 5 | CRATE_KW@[7; 12) |
6 | WHITESPACE@[12; 13) | 6 | NAME@[12; 16) |
7 | IDENT@[13; 16) "foo" | 7 | WHITESPACE@[12; 13) |
8 | IDENT@[13; 16) "foo" | ||
8 | SEMI@[16; 17) | 9 | SEMI@[16; 17) |
9 | WHITESPACE@[17; 18) | 10 | WHITESPACE@[17; 18) |
diff --git a/tests/data/parser/ok/0007_extern_crate.txt b/tests/data/parser/ok/0007_extern_crate.txt index aff70131b..33ce2ae65 100644 --- a/tests/data/parser/ok/0007_extern_crate.txt +++ b/tests/data/parser/ok/0007_extern_crate.txt | |||
@@ -3,20 +3,23 @@ FILE@[0; 43) | |||
3 | EXTERN_KW@[0; 6) | 3 | EXTERN_KW@[0; 6) |
4 | WHITESPACE@[6; 7) | 4 | WHITESPACE@[6; 7) |
5 | CRATE_KW@[7; 12) | 5 | CRATE_KW@[7; 12) |
6 | WHITESPACE@[12; 13) | 6 | NAME@[12; 16) |
7 | IDENT@[13; 16) "foo" | 7 | WHITESPACE@[12; 13) |
8 | IDENT@[13; 16) "foo" | ||
8 | SEMI@[16; 17) | 9 | SEMI@[16; 17) |
9 | WHITESPACE@[17; 18) | 10 | WHITESPACE@[17; 18) |
10 | EXTERN_CRATE_ITEM@[18; 43) | 11 | EXTERN_CRATE_ITEM@[18; 43) |
11 | EXTERN_KW@[18; 24) | 12 | EXTERN_KW@[18; 24) |
12 | WHITESPACE@[24; 25) | 13 | WHITESPACE@[24; 25) |
13 | CRATE_KW@[25; 30) | 14 | CRATE_KW@[25; 30) |
14 | WHITESPACE@[30; 31) | 15 | NAME@[30; 35) |
15 | IDENT@[31; 34) "foo" | 16 | WHITESPACE@[30; 31) |
16 | ALIAS@[34; 41) | 17 | IDENT@[31; 34) "foo" |
17 | WHITESPACE@[34; 35) | 18 | WHITESPACE@[34; 35) |
19 | ALIAS@[35; 41) | ||
18 | AS_KW@[35; 37) | 20 | AS_KW@[35; 37) |
19 | WHITESPACE@[37; 38) | 21 | NAME@[37; 41) |
20 | IDENT@[38; 41) "bar" | 22 | WHITESPACE@[37; 38) |
23 | IDENT@[38; 41) "bar" | ||
21 | SEMI@[41; 42) | 24 | SEMI@[41; 42) |
22 | WHITESPACE@[42; 43) | 25 | WHITESPACE@[42; 43) |
diff --git a/tests/data/parser/ok/0015_use_tree.txt b/tests/data/parser/ok/0015_use_tree.txt index 10bdef5fe..28f5f789e 100644 --- a/tests/data/parser/ok/0015_use_tree.txt +++ b/tests/data/parser/ok/0015_use_tree.txt | |||
@@ -9,8 +9,9 @@ FILE@[0; 55) | |||
9 | WHITESPACE@[7; 8) | 9 | WHITESPACE@[7; 8) |
10 | ALIAS@[8; 14) | 10 | ALIAS@[8; 14) |
11 | AS_KW@[8; 10) | 11 | AS_KW@[8; 10) |
12 | WHITESPACE@[10; 11) | 12 | NAME@[10; 14) |
13 | IDENT@[11; 14) "bar" | 13 | WHITESPACE@[10; 11) |
14 | IDENT@[11; 14) "bar" | ||
14 | SEMI@[14; 15) | 15 | SEMI@[14; 15) |
15 | WHITESPACE@[15; 16) | 16 | WHITESPACE@[15; 16) |
16 | USE_ITEM@[16; 55) | 17 | USE_ITEM@[16; 55) |
@@ -29,8 +30,9 @@ FILE@[0; 55) | |||
29 | WHITESPACE@[27; 28) | 30 | WHITESPACE@[27; 28) |
30 | ALIAS@[28; 32) | 31 | ALIAS@[28; 32) |
31 | AS_KW@[28; 30) | 32 | AS_KW@[28; 30) |
32 | WHITESPACE@[30; 31) | 33 | NAME@[30; 32) |
33 | IDENT@[31; 32) "b" | 34 | WHITESPACE@[30; 31) |
35 | IDENT@[31; 32) "b" | ||
34 | COMMA@[32; 33) | 36 | COMMA@[32; 33) |
35 | USE_TREE@[33; 35) | 37 | USE_TREE@[33; 35) |
36 | WHITESPACE@[33; 34) | 38 | WHITESPACE@[33; 34) |
@@ -50,8 +52,9 @@ FILE@[0; 55) | |||
50 | WHITESPACE@[47; 48) | 52 | WHITESPACE@[47; 48) |
51 | ALIAS@[48; 52) | 53 | ALIAS@[48; 52) |
52 | AS_KW@[48; 50) | 54 | AS_KW@[48; 50) |
53 | WHITESPACE@[50; 51) | 55 | NAME@[50; 52) |
54 | IDENT@[51; 52) "x" | 56 | WHITESPACE@[50; 51) |
57 | IDENT@[51; 52) "x" | ||
55 | R_CURLY@[52; 53) | 58 | R_CURLY@[52; 53) |
56 | SEMI@[53; 54) | 59 | SEMI@[53; 54) |
57 | WHITESPACE@[54; 55) | 60 | WHITESPACE@[54; 55) |