More compact

This commit is contained in:
Aleksey Kladov 2020-04-09 18:08:54 +02:00
parent 6fd2a12495
commit 9285cbffb6
3 changed files with 240 additions and 1438 deletions

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -75,12 +75,7 @@ fn generate_tokens(kinds: KindsSrc<'_>, grammar: AstSrc<'_>) -> Result<String> {
} }
impl AstToken for #name { impl AstToken for #name {
fn can_cast(kind: SyntaxKind) -> bool { fn can_cast(kind: SyntaxKind) -> bool { kind == #kind }
match kind {
#kind => true,
_ => false,
}
}
fn cast(syntax: SyntaxToken) -> Option<Self> { fn cast(syntax: SyntaxToken) -> Option<Self> {
if Self::can_cast(syntax.kind()) { Some(Self { syntax }) } else { None } if Self::can_cast(syntax.kind()) { Some(Self { syntax }) } else { None }
} }
@ -243,10 +238,7 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: AstSrc<'_>) -> Result<String> {
impl AstNode for #name { impl AstNode for #name {
fn can_cast(kind: SyntaxKind) -> bool { fn can_cast(kind: SyntaxKind) -> bool {
match kind { kind == #kind
#kind => true,
_ => false,
}
} }
fn cast(syntax: SyntaxNode) -> Option<Self> { fn cast(syntax: SyntaxNode) -> Option<Self> {
if Self::can_cast(syntax.kind()) { Some(Self { syntax }) } else { None } if Self::can_cast(syntax.kind()) { Some(Self { syntax }) } else { None }