Implement reparsing for remaining blocks

This commit is contained in:
darksv 2018-09-10 20:14:09 +02:00
parent 4f64709666
commit 64d07c1bd4
9 changed files with 93 additions and 28 deletions

View file

@ -287,7 +287,7 @@ fn match_expr(p: &mut Parser) -> CompletedMarker {
m.complete(p, MATCH_EXPR) m.complete(p, MATCH_EXPR)
} }
fn match_arm_list(p: &mut Parser) { pub(crate) fn match_arm_list(p: &mut Parser) {
assert!(p.at(L_CURLY)); assert!(p.at(L_CURLY));
let m = p.start(); let m = p.start();
p.eat(L_CURLY); p.eat(L_CURLY);

View file

@ -2,6 +2,7 @@ mod atom;
use super::*; use super::*;
pub(super) use self::atom::{literal, LITERAL_FIRST}; pub(super) use self::atom::{literal, LITERAL_FIRST};
pub(crate) use self::atom::match_arm_list;
const EXPR_FIRST: TokenSet = LHS_FIRST; const EXPR_FIRST: TokenSet = LHS_FIRST;
@ -419,7 +420,7 @@ fn path_expr(p: &mut Parser, r: Restrictions) -> CompletedMarker {
// S { x, y: 32, }; // S { x, y: 32, };
// S { x, y: 32, ..Default::default() }; // S { x, y: 32, ..Default::default() };
// } // }
fn named_field_list(p: &mut Parser) { pub(crate) fn named_field_list(p: &mut Parser) {
assert!(p.at(L_CURLY)); assert!(p.at(L_CURLY));
let m = p.start(); let m = p.start();
p.bump(); p.bump();

View file

@ -5,7 +5,12 @@ mod traits;
mod use_item; mod use_item;
use super::*; use super::*;
pub(crate) use self::nominal::named_field_def_list; pub(crate) use self::{
expressions::{named_field_list, match_arm_list},
nominal::{enum_variant_list, named_field_def_list},
traits::{trait_item_list, impl_item_list},
use_item::use_tree_list,
};
// test mod_contents // test mod_contents
// fn foo() {} // fn foo() {}
@ -223,7 +228,7 @@ fn extern_crate_item(p: &mut Parser) {
p.expect(SEMI); p.expect(SEMI);
} }
fn extern_item_list(p: &mut Parser) { pub(crate) fn extern_item_list(p: &mut Parser) {
assert!(p.at(L_CURLY)); assert!(p.at(L_CURLY));
let m = p.start(); let m = p.start();
p.bump(); p.bump();
@ -295,7 +300,7 @@ fn type_def(p: &mut Parser) {
p.expect(SEMI); p.expect(SEMI);
} }
fn mod_item(p: &mut Parser) { pub(crate) fn mod_item(p: &mut Parser) {
assert!(p.at(MOD_KW)); assert!(p.at(MOD_KW));
p.bump(); p.bump();
@ -307,7 +312,7 @@ fn mod_item(p: &mut Parser) {
} }
} }
fn mod_item_list(p: &mut Parser) { pub(crate) fn mod_item_list(p: &mut Parser) {
assert!(p.at(L_CURLY)); assert!(p.at(L_CURLY));
let m = p.start(); let m = p.start();
p.bump(); p.bump();
@ -343,7 +348,7 @@ pub(super) fn macro_call_after_excl(p: &mut Parser) -> BlockLike {
flavor flavor
} }
pub(super) fn token_tree(p: &mut Parser) { pub(crate) fn token_tree(p: &mut Parser) {
let closing_paren_kind = match p.current() { let closing_paren_kind = match p.current() {
L_CURLY => R_CURLY, L_CURLY => R_CURLY,
L_PAREN => R_PAREN, L_PAREN => R_PAREN,

View file

@ -51,7 +51,7 @@ pub(super) fn enum_def(p: &mut Parser) {
} }
} }
fn enum_variant_list(p: &mut Parser) { pub(crate) fn enum_variant_list(p: &mut Parser) {
assert!(p.at(L_CURLY)); assert!(p.at(L_CURLY));
let m = p.start(); let m = p.start();
p.bump(); p.bump();

View file

@ -25,7 +25,7 @@ pub(super) fn trait_def(p: &mut Parser) {
// fn foo() {} // fn foo() {}
// fn bar(&self); // fn bar(&self);
// } // }
fn trait_item_list(p: &mut Parser) { pub(crate) fn trait_item_list(p: &mut Parser) {
assert!(p.at(L_CURLY)); assert!(p.at(L_CURLY));
let m = p.start(); let m = p.start();
p.bump(); p.bump();
@ -74,7 +74,7 @@ pub(super) fn impl_item(p: &mut Parser) {
// fn foo() {} // fn foo() {}
// fn bar(&self) {} // fn bar(&self) {}
// } // }
fn impl_item_list(p: &mut Parser) { pub(crate) fn impl_item_list(p: &mut Parser) {
assert!(p.at(L_CURLY)); assert!(p.at(L_CURLY));
let m = p.start(); let m = p.start();
p.bump(); p.bump();

View file

@ -53,7 +53,7 @@ fn use_tree(p: &mut Parser) {
m.complete(p, USE_TREE); m.complete(p, USE_TREE);
} }
fn use_tree_list(p: &mut Parser) { pub(crate) fn use_tree_list(p: &mut Parser) {
assert!(p.at(L_CURLY)); assert!(p.at(L_CURLY));
let m = p.start(); let m = p.start();
p.bump(); p.bump();

View file

@ -37,8 +37,21 @@ use {
SyntaxKind::{self, *}, SyntaxKind::{self, *},
}; };
pub(crate) use self::{ pub(crate) use self::{
expressions::block, expressions::{
items::named_field_def_list, block,
},
items::{
enum_variant_list,
extern_item_list,
impl_item_list,
match_arm_list,
mod_item_list,
named_field_def_list,
named_field_list,
token_tree,
trait_item_list,
use_tree_list,
},
}; };
pub(crate) fn root(p: &mut Parser) { pub(crate) fn root(p: &mut Parser) {

View file

@ -144,6 +144,21 @@ fn find_reparsable_node(node: SyntaxNodeRef, range: TextRange) -> Option<(Syntax
let res = match node.kind() { let res = match node.kind() {
BLOCK => grammar::block, BLOCK => grammar::block,
NAMED_FIELD_DEF_LIST => grammar::named_field_def_list, NAMED_FIELD_DEF_LIST => grammar::named_field_def_list,
NAMED_FIELD_LIST => grammar::named_field_list,
ENUM_VARIANT_LIST => grammar::enum_variant_list,
MATCH_ARM_LIST => grammar::match_arm_list,
USE_TREE_LIST => grammar::use_tree_list,
EXTERN_ITEM_LIST => grammar::extern_item_list,
TOKEN_TREE => grammar::token_tree,
ITEM_LIST => {
let parent = node.parent().unwrap();
match parent.kind() {
IMPL_ITEM => grammar::impl_item_list,
TRAIT_DEF => grammar::trait_item_list,
MODULE => grammar::mod_item_list,
_ => return None,
}
},
_ => return None, _ => return None,
}; };
Some(res) Some(res)

View file

@ -23,21 +23,6 @@ fn lexer_tests() {
}) })
} }
#[test]
fn parser_tests() {
dir_tests(&["parser/inline", "parser/ok", "parser/err"], |text| {
let file = File::parse(text);
dump_tree(file.syntax())
})
}
#[test]
fn parser_fuzz_tests() {
for (_, text) in collect_tests(&["parser/fuzz-failures"]) {
check_fuzz_invariants(&text)
}
}
#[test] #[test]
fn reparse_test() { fn reparse_test() {
fn do_check(before: &str, replace_with: &str) { fn do_check(before: &str, replace_with: &str) {
@ -73,6 +58,52 @@ fn foo {
<|>92<|>; <|>92<|>;
} }
", "62"); ", "62");
do_check(r"
mod foo {
fn <|><|>
}
", "bar");
do_check(r"
trait Foo {
type <|>Foo<|>;
}
", "Output");
do_check(r"
impl IntoIterator<Item=i32> for Foo {
f<|><|>
}
", "n next(");
do_check(r"
use a::b::{foo,<|>,bar<|>};
", "baz");
do_check(r"
pub enum A {
Foo<|><|>
}
", "\nBar;\n");
do_check(r"
foo!{a, b<|><|> d}
", ", c[3]");
do_check(r"
extern {
fn<|>;<|>
}
", " exit(code: c_int)");
}
#[test]
fn parser_tests() {
dir_tests(&["parser/inline", "parser/ok", "parser/err"], |text| {
let file = File::parse(text);
dump_tree(file.syntax())
})
}
#[test]
fn parser_fuzz_tests() {
for (_, text) in collect_tests(&["parser/fuzz-failures"]) {
check_fuzz_invariants(&text)
}
} }