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
52 lines (46 loc) · 1.36 KB
/
Copy pathpath.rs
File metadata and controls
52 lines (46 loc) · 1.36 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
47
48
49
50
51
52
use crate::{ParseError, SyntaxKind};
use super::{define_scope, token_stream::TokenStream, Parser};
define_scope! {
#[doc(hidden)]
pub PathScope,
Path,
(Colon2)
}
impl super::Parse for PathScope {
type Error = ParseError;
fn parse<S: TokenStream>(&mut self, parser: &mut Parser<S>) -> Result<(), Self::Error> {
parser.set_newline_as_trivia(false);
parser.parse(PathSegmentScope::default())?;
while parser.bump_if(SyntaxKind::Colon2) {
parser.parse(PathSegmentScope::default())?;
}
Ok(())
}
}
define_scope! { PathSegmentScope, PathSegment }
impl super::Parse for PathSegmentScope {
type Error = ParseError;
fn parse<S: TokenStream>(&mut self, parser: &mut Parser<S>) -> Result<(), Self::Error> {
match parser.current_kind() {
Some(kind) if is_path_segment(kind) => {
parser.bump();
Ok(())
}
_ => Err(ParseError::expected(
&[SyntaxKind::PathSegment],
None,
parser.end_of_prev_token,
)),
}
}
}
pub(super) fn is_path_segment(kind: SyntaxKind) -> bool {
matches!(
kind,
SyntaxKind::SelfTypeKw
| SyntaxKind::SelfKw
| SyntaxKind::IngotKw
| SyntaxKind::SuperKw
| SyntaxKind::Ident
)
}