mirror of
https://github.com/nushell/nushell.git
synced 2025-04-14 16:28:17 +02:00
* Moves off of draining between filters. Instead, the sink will pull on the stream, and will drain element-wise. This moves the whole stream to being lazy. * Adds ctrl-c support and connects it into some of the key points where we pull on the stream. If a ctrl-c is detect, we immediately halt pulling on the stream and return to the prompt. * Moves away from having a SourceMap where anchor locations are stored. Now AnchorLocation is kept directly in the Tag. * To make this possible, split tag and span. Span is largely used in the parser and is copyable. Tag is now no longer copyable.
50 lines
1.7 KiB
Rust
50 lines
1.7 KiB
Rust
use crate::parser::hir::syntax_shape::{
|
|
color_syntax, expand_syntax, ColorSyntax, ExpandContext, ExpressionListShape, TokenNode,
|
|
};
|
|
use crate::parser::{hir, hir::TokensIterator, Delimiter, FlatShape};
|
|
use crate::prelude::*;
|
|
|
|
pub fn expand_delimited_square(
|
|
children: &Vec<TokenNode>,
|
|
span: Span,
|
|
context: &ExpandContext,
|
|
) -> Result<hir::Expression, ShellError> {
|
|
let mut tokens = TokensIterator::new(&children, span, false);
|
|
|
|
let list = expand_syntax(&ExpressionListShape, &mut tokens, context);
|
|
|
|
Ok(hir::Expression::list(list?, Tag { span, anchor: None }))
|
|
}
|
|
|
|
pub fn color_delimited_square(
|
|
(open, close): (Span, Span),
|
|
children: &Vec<TokenNode>,
|
|
span: Span,
|
|
context: &ExpandContext,
|
|
shapes: &mut Vec<Spanned<FlatShape>>,
|
|
) {
|
|
shapes.push(FlatShape::OpenDelimiter(Delimiter::Square).spanned(open));
|
|
let mut tokens = TokensIterator::new(&children, span, false);
|
|
let _list = color_syntax(&ExpressionListShape, &mut tokens, context, shapes);
|
|
shapes.push(FlatShape::CloseDelimiter(Delimiter::Square).spanned(close));
|
|
}
|
|
|
|
#[derive(Debug, Copy, Clone)]
|
|
pub struct DelimitedShape;
|
|
|
|
impl ColorSyntax for DelimitedShape {
|
|
type Info = ();
|
|
type Input = (Delimiter, Span, Span);
|
|
fn color_syntax<'a, 'b>(
|
|
&self,
|
|
(delimiter, open, close): &(Delimiter, Span, Span),
|
|
token_nodes: &'b mut TokensIterator<'a>,
|
|
context: &ExpandContext,
|
|
shapes: &mut Vec<Spanned<FlatShape>>,
|
|
) -> Self::Info {
|
|
shapes.push(FlatShape::OpenDelimiter(*delimiter).spanned(*open));
|
|
color_syntax(&ExpressionListShape, token_nodes, context, shapes);
|
|
shapes.push(FlatShape::CloseDelimiter(*delimiter).spanned(*close));
|
|
}
|
|
}
|