Implement concat macro

This commit is contained in:
Edwin Cheng 2020-03-02 14:05:15 +08:00
parent 0d55454073
commit 1465cc0c4f
10 changed files with 305 additions and 77 deletions

View file

@ -219,7 +219,7 @@ fn unroot(n: SyntaxNode) -> SyntaxNode {
}
pub mod tokens {
use crate::{AstNode, Parse, SourceFile, SyntaxKind::*, SyntaxToken, T};
use crate::{ast, AstNode, Parse, SourceFile, SyntaxKind::*, SyntaxToken, T};
use once_cell::sync::Lazy;
pub(super) static SOURCE_FILE: Lazy<Parse<SourceFile>> =
@ -251,6 +251,12 @@ pub mod tokens {
sf.syntax().first_child_or_token().unwrap().into_token().unwrap()
}
pub fn literal(text: &str) -> SyntaxToken {
assert_eq!(text.trim(), text);
let lit: ast::Literal = super::ast_from_text(&format!("fn f() {{ let _ = {}; }}", text));
lit.syntax().first_child_or_token().unwrap().into_token().unwrap()
}
pub fn single_newline() -> SyntaxToken {
SOURCE_FILE
.tree()