forked from argotorg/fe
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpath.rs
More file actions
46 lines (42 loc) · 1.15 KB
/
Copy pathpath.rs
File metadata and controls
46 lines (42 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use crate::SyntaxKind;
use super::{define_scope, token_stream::TokenStream, Parser};
define_scope! {
#[doc(hidden)]
pub PathScope,
Path,
Inheritance(Colon2)
}
impl super::Parse for PathScope {
fn parse<S: TokenStream>(&mut self, parser: &mut Parser<S>) {
parser.set_newline_as_trivia(false);
parser.parse(PathSegmentScope::default(), None);
while parser.bump_if(SyntaxKind::Colon2) {
parser.parse(PathSegmentScope::default(), None);
}
}
}
define_scope! {
PathSegmentScope,
PathSegment,
Inheritance
}
impl super::Parse for PathSegmentScope {
fn parse<S: TokenStream>(&mut self, parser: &mut Parser<S>) {
match parser.current_kind() {
Some(kind) if is_path_segment(kind) => {
parser.bump();
}
_ => parser.error_and_recover("expected path segment", None),
}
}
}
pub(super) fn is_path_segment(kind: SyntaxKind) -> bool {
matches!(
kind,
SyntaxKind::SelfTypeKw
| SyntaxKind::SelfKw
| SyntaxKind::IngotKw
| SyntaxKind::SuperKw
| SyntaxKind::Ident
)
}