Move atom edit to libsyntax2

This commit is contained in:
Aleksey Kladov 2018-08-25 12:44:26 +03:00
parent 87cd57d56a
commit 32c8ea9307
3 changed files with 35 additions and 27 deletions

View file

@ -64,7 +64,7 @@ impl File {
validate_block_structure(root.borrowed());
File { root }
}
pub fn parse(text: &str) -> Self {
pub fn parse(text: &str) -> File {
let tokens = tokenize(&text);
let (root, errors) = parser_impl::parse::<yellow::GreenBuilder>(text, &tokens);
File::new(root, errors)
@ -112,3 +112,23 @@ fn validate_block_structure(root: SyntaxNodeRef) {
}
}
}
#[derive(Debug, Clone)]
pub struct AtomEdit {
pub delete: TextRange,
pub insert: String,
}
impl AtomEdit {
pub fn replace(range: TextRange, replace_with: String) -> AtomEdit {
AtomEdit { delete: range, insert: replace_with }
}
pub fn delete(range: TextRange) -> AtomEdit {
AtomEdit::replace(range, String::new())
}
pub fn insert(offset: TextUnit, text: String) -> AtomEdit {
AtomEdit::replace(TextRange::offset_len(offset, 0.into()), text)
}
}