do refact and fix some issue

This commit is contained in:
bravomikekilo 2019-11-24 13:14:57 +08:00
parent 1ebfa908d5
commit adac4fc2f2
7 changed files with 72 additions and 60 deletions

View file

@ -173,10 +173,21 @@ fn ast_from_text<N: AstNode>(text: &str) -> N {
}
pub mod tokens {
use crate::{AstNode, Parse, SourceFile, SyntaxKind::*, SyntaxToken, T};
use crate::{AstNode, Parse, SourceFile, SyntaxKind, SyntaxKind::*, SyntaxToken, T};
use once_cell::sync::Lazy;
static SOURCE_FILE: Lazy<Parse<SourceFile>> = Lazy::new(|| SourceFile::parse(",\n; ;"));
static SOURCE_FILE: Lazy<Parse<SourceFile>> =
Lazy::new(|| SourceFile::parse("const C: () = (1 != 1, 2 == 2)\n;"));
pub fn op(op: SyntaxKind) -> SyntaxToken {
SOURCE_FILE
.tree()
.syntax()
.descendants_with_tokens()
.filter_map(|it| it.into_token())
.find(|it| it.kind() == op)
.unwrap()
}
pub fn comma() -> SyntaxToken {
SOURCE_FILE