Getting ready for multiline scripts (#2737)

* WIP

* WIP

* WIP

* Tests are passing

* make parser more resilient

* lint
This commit is contained in:
Jonathan Turner
2020-11-10 05:27:07 +13:00
committed by GitHub
parent 0113661c81
commit 8df748463d
10 changed files with 570 additions and 471 deletions

View File

@ -23,15 +23,10 @@ impl NuCompleter {
use completion::engine::LocationType;
let nu_context: &EvaluationContext = context.as_ref();
let lite_block = match nu_parser::lite_parse(line, 0) {
Ok(block) => Some(block),
Err(result) => result.partial,
};
let (lite_block, _) = nu_parser::lite_parse(line, 0);
let locations = lite_block
.map(|block| nu_parser::classify_block(&block, &nu_context.registry))
.map(|block| completion::engine::completion_location(line, &block.block, pos))
.unwrap_or_default();
let classified_block = nu_parser::classify_block(&lite_block, &nu_context.registry);
let locations = completion::engine::completion_location(line, &classified_block.block, pos);
let matcher = nu_data::config::config(Tag::unknown())
.ok()

View File

@ -121,10 +121,10 @@ impl rustyline::validate::Validator for NuValidator {
) -> rustyline::Result<rustyline::validate::ValidationResult> {
let src = ctx.input();
let lite_result = nu_parser::lite_parse(src, 0);
let (_, err) = nu_parser::lite_parse(src, 0);
if let Err(err) = lite_result {
if let nu_errors::ParseErrorReason::Eof { .. } = err.cause.reason() {
if let Some(err) = err {
if let nu_errors::ParseErrorReason::Eof { .. } = err.reason() {
return Ok(rustyline::validate::ValidationResult::Incomplete);
}
}

View File

@ -25,22 +25,21 @@ impl Painter {
registry: &dyn SignatureRegistry,
palette: &P,
) -> Cow<'l, str> {
let lite_block = nu_parser::lite_parse(line, 0);
let (lb, err) = nu_parser::lite_parse(line, 0);
match lite_block {
Err(_) => Cow::Borrowed(line),
Ok(lb) => {
let classified = nu_parser::classify_block(&lb, registry);
if err.is_some() {
Cow::Borrowed(line)
} else {
let classified = nu_parser::classify_block(&lb, registry);
let shapes = nu_parser::shapes(&classified.block);
let mut painter = Painter::new(line);
let shapes = nu_parser::shapes(&classified.block);
let mut painter = Painter::new(line);
for shape in shapes {
painter.paint_shape(&shape, palette);
}
Cow::Owned(painter.into_string())
for shape in shapes {
painter.paint_shape(&shape, palette);
}
Cow::Owned(painter.into_string())
}
}