From c5ebf8b775134e85a8f78eeb58da339c2ceca55b Mon Sep 17 00:00:00 2001 From: WindSoilder Date: Thu, 24 Sep 2026 06:58:24 +0800 Subject: [PATCH 1/3] introduce a new PipeElement, unify code with grammar.md --- contributing/grammar.md | 18 +-- src/parser.rs | 238 ++++++++++++++++++++++++++++++++++------ src/resolver.rs | 3 + src/typechecker.rs | 3 + 4 files changed, 220 insertions(+), 42 deletions(-) diff --git a/contributing/grammar.md b/contributing/grammar.md index df8e40f..0e394b2 100644 --- a/contributing/grammar.md +++ b/contributing/grammar.md @@ -27,10 +27,12 @@ terminator → NEWLINE | ";" ; statement → declaration | loop_statement | flow_statement - | assignment - | pipeline ; - -pipeline → pipe_element (pipe pipe_element)* ; + | pipeline_or_expression_or_assignment; +pipeline_or_expression_or_assignment + → pipeline | pipe_element | assignment ; +pipeline_or_expression + → pipeline | pipe_element ; +pipeline → pipe_element (pipe pipe_element)+ ; pipe_element → expression_command redirection* ; pipe → "|" | "e>|" | "err>|" | "out+err>|" | "err+out>|" ; redirection → file_redirection expression ; @@ -49,8 +51,8 @@ declaration → let_decl | mut_decl | const_decl | def_decl | extern_decl | export_decl | export_env_decl | hide_decl | overlay_decl | plugin_use_decl ; -let_decl → "let" binding "=" pipeline ; -mut_decl → "mut" binding "=" pipeline ; +let_decl → "let" binding "=" pipeline_or_expression ; +mut_decl → "mut" binding "=" pipeline_or_expression ; const_decl → "const" binding "=" expression ; binding → variable_decl type_annotation? ; variable_decl → "$"? IDENTIFIER ; @@ -153,9 +155,9 @@ addition → multiply (("+" | "-") multiply)* ; multiply → power (("*" | "/" | "//" | "mod") power)* ; power → unary ("**" power)? ; // right-associative unary → ("not" | "+" | "-") unary | postfix ; -postfix → primary cell_path? ; +postfix → simple_expression cell_path? ; -primary → if_expression | try_expression | match_expression +simple_expression → if_expression | try_expression | match_expression | literal | variable | cell_path_literal | table | list | closure | record | block | subexpression ; subexpression → "(" statement_sequence? ")" ; diff --git a/src/parser.rs b/src/parser.rs index c66a2e0..8e7a987 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -81,11 +81,13 @@ impl InOutTypes { #[derive(Debug, Clone, PartialEq)] pub struct Call { pub parts: Vec, + pub has_caret: bool, + pub as_alias: bool, } impl Call { - pub fn new(parts: Vec) -> Self { - Self { parts } + pub fn new(parts: Vec, has_caret: bool, as_alias: bool) -> Self { + Self { parts, has_caret, as_alias } } } @@ -167,15 +169,20 @@ impl TypeArgs { #[derive(Debug, Clone, PartialEq)] pub struct Pipeline { pub nodes: Vec, + pub nexts: Vec, } impl Pipeline { - pub fn new(nodes: Vec) -> Self { + pub fn new(nodes: Vec, nexts: Vec) -> Self { debug_assert!( nodes.len() > 1, "a pipeline must contain at least 2 nodes, or else it's actually an expression" ); - Self { nodes } + debug_assert!( + nodes.len() == nexts.len() + 1, + "the number of nexts must be one less than the number of nodes" + ); + Self { nodes, nexts } } pub fn get_expressions(&self) -> &Vec { @@ -272,6 +279,11 @@ pub enum AstNode { Xor, Or, + // Pipe + Pipe, + OutErrPipe, + ErrPipe, + // Assignments Assignment, AddAssignment, @@ -398,6 +410,24 @@ pub enum AstNode { }, Match(MatchId), Statement(NodeId), + // Just an expression with redirection. + PipeElement { + expr: NodeId, + redirection: Option, + }, + // Redirections + OutRedirect { + target: NodeId, + append: bool, + }, + ErrRedirect { + target: NodeId, + append: bool, + }, + OutErrRedirect { + target: NodeId, + append: bool, + }, Garbage, } @@ -453,22 +483,98 @@ impl Parser { self.compiler } + // difference between expression and simple_expression: + // + // expression can be a math expression, while simple_expression is just a single value. pub fn expression(&mut self) -> NodeId { let _span = span!(); self.math_expression(false).get_node_id() } + fn is_redirection(&self) -> bool { + matches!( + self.tokens.peek_token(), + Token::OutGreaterThan + | Token::OutErrGreaterThan + | Token::ErrGreaterThan + | Token::ErrGreaterGreaterThan + | Token::OutGreaterGreaterThan + | Token::OutErrGreaterGreaterThan + ) + } + + fn redirection(&mut self) -> NodeId { + if self.is_redirection() { + let span_start = self.position(); + let redirection = self.tokens.peek_token(); + self.tokens.advance(); + let expression = self.expression(); + let span_end = self.position(); + let node = match redirection { + Token::OutGreaterThan => AstNode::OutRedirect { + target: expression, + append: false, + }, + Token::OutGreaterGreaterThan => AstNode::OutRedirect { + target: expression, + append: true, + }, + Token::ErrGreaterThan => AstNode::ErrRedirect { + target: expression, + append: false, + }, + Token::ErrGreaterGreaterThan => AstNode::ErrRedirect { + target: expression, + append: true, + }, + Token::OutErrGreaterThan => AstNode::OutErrRedirect { + target: expression, + append: false, + }, + Token::OutErrGreaterGreaterThan => AstNode::OutErrRedirect { + target: expression, + append: true, + }, + _ => unreachable!(), + }; + self.create_node(node, span_start, span_end) + } else { + self.error("expected redirection operator") + } + } + + fn pipe_element(&mut self) -> NodeId { + let start = self.position(); + let expression = self.expression(); + let redirection = if self.is_redirection() { + Some(self.redirection()) + } else { + None + }; + let end = self.position(); + self.create_node( + AstNode::PipeElement { + expr: expression, + redirection, + }, + start, + end, + ) + } + fn pipeline(&mut self, first_element: NodeId, span_start: usize) -> NodeId { - let mut expressions = vec![first_element]; - while self.is_pipe() { - self.pipe(); + let mut pipe_elements = vec![first_element]; + let mut nexts = vec![]; + while self.is_pipelike() { + let pipe = self.pipelike(); + nexts.push(pipe); // maybe a new time if self.is_newline() { self.tokens.advance() } - expressions.push(self.expression()); + pipe_elements.push(self.pipe_element()); } - self.compiler.pipelines.push(Pipeline::new(expressions)); + self.compiler.pipelines.push(Pipeline::new(pipe_elements, nexts)); let span_end = self.position(); self.create_node( AstNode::Pipeline(PipelineId(self.compiler.pipelines.len() - 1)), @@ -476,17 +582,33 @@ impl Parser { span_end, ) } + pub fn pipeline_or_expression_or_assignment(&mut self) -> NodeId { // get the first expression let _span = span!(); let span_start = self.position(); + // Because we check `assignment` first + // it's not good to invoke `pipe_elem` for pipeline element. let first = self.math_expression(true); - let first_id = first.get_node_id(); + let mut first_id = first.get_node_id(); if let AssignmentOrExpression::Assignment(_) = &first { return first_id; } + // additional check for redirection, because `match_expression` itself doesn't do this + if self.is_redirection() { + let redirection = self.redirection(); + let span_end = self.position(); + first_id = self.create_node( + AstNode::PipeElement { + expr: first_id, + redirection: Some(redirection), + }, + span_start, + span_end, + ); + } // pipeline with one element is an expression actually - if !self.is_pipe() { + if !self.is_pipelike() { return first_id; } self.pipeline(first_id, span_start) @@ -495,9 +617,9 @@ impl Parser { pub fn pipeline_or_expression(&mut self) -> NodeId { let _span = span!(); let span_start = self.position(); - let first_id = self.expression(); + let first_id = self.pipe_element(); // pipeline with one element is an expression actually. - if !self.is_pipe() { + if !self.is_pipelike() { return first_id; } self.pipeline(first_id, span_start) @@ -657,7 +779,7 @@ impl Parser { self.compiler.ast_nodes[node_id.0] = AstNode::String; node_id } - BarewordContext::Call => self.internal_call(), + BarewordContext::Call => self.call(false), }, }, _ => self.error("incomplete expression"), @@ -769,9 +891,18 @@ impl Parser { parts } - pub fn internal_call(&mut self) -> NodeId { + // In nushell, a call can be external call or internal call + // But during parsing stage, it's impossible to distinguish them + // so we just parse them as a call, and let the resolver to decide which one it is. + pub fn call(&mut self, as_alias: bool) -> NodeId { let _span = span!(); let span_start = self.position(); + let has_caret = if self.is_caret() { + self.tokens.advance(); + true + } else { + false + }; let mut parts = self.call_name(); // Arguments. @@ -787,7 +918,7 @@ impl Parser { let span_end = self.position(); - self.compiler.calls.push(Call::new(parts)); + self.compiler.calls.push(Call::new(parts, has_caret, as_alias)); self.create_node( AstNode::Call(CallId(self.compiler.calls.len() - 1)), span_start, @@ -795,6 +926,10 @@ impl Parser { ) } + pub fn is_caret(&self) -> bool { + self.tokens.peek_token() == Token::Caret + } + fn argument(&mut self) -> NodeId { match self.tokens.peek_token() { Token::DotDotDot => self.spread_expression(), @@ -1554,7 +1689,7 @@ impl Parser { return self.error("expected '@' to start an attribute"); } self.tokens.advance(); - self.internal_call() + self.call(false) } pub fn def_statement(&mut self, attributes: Option, span_start: usize) -> NodeId { @@ -1740,11 +1875,23 @@ impl Parser { let _span = span!(); let span_start = self.position(); + let code_body = self.statement_sequence(context); + self.compiler.blocks.push(Block::new(code_body)); + let span_end = self.position(); + + self.create_node( + AstNode::Block(BlockId(self.compiler.blocks.len() - 1)), + span_start, + span_end, + ) + } + + pub fn statement_sequence(&mut self, context: BlockContext) -> Vec { let mut code_body = vec![]; + if let BlockContext::Curlies = context { self.lcurly(); } - while self.has_tokens() { if self.is_rcurly() && context == BlockContext::Curlies { self.rcurly(); @@ -1837,15 +1984,7 @@ impl Parser { } } } - - self.compiler.blocks.push(Block::new(code_body)); - let span_end = self.position(); - - self.create_node( - AstNode::Block(BlockId(self.compiler.blocks.len() - 1)), - span_start, - span_end, - ) + code_body } pub fn while_statement(&mut self) -> NodeId { @@ -1946,13 +2085,16 @@ impl Parser { self.name() }; self.equals(); - let old_name = if self.is_string() { - self.string() - } else { - self.name() - }; - let span_end = self.get_span_end(old_name); - self.create_node(AstNode::Alias { new_name, old_name }, span_start, span_end) + let call = self.call(true); + let span_end = self.get_span_end(call); + self.create_node( + AstNode::Alias { + new_name, + old_name: call, + }, + span_start, + span_end, + ) } pub fn is_operator(&mut self) -> bool { @@ -2044,6 +2186,34 @@ impl Parser { self.tokens.peek_token() == Token::Pipe } + pub fn is_pipelike(&mut self) -> bool { + [ + Token::Pipe, + Token::ErrGreaterThanPipe, + Token::OutErrGreaterThanPipe, + ] + .contains(&self.tokens.peek_token()) + } + + pub fn pipelike(&mut self) -> NodeId { + if self.is_pipelike() { + let (token, span) = self.tokens.peek(); + self.tokens.advance(); + match token { + Token::Pipe => self.create_node(AstNode::Pipe, span.start, span.end), + Token::ErrGreaterThanPipe => { + self.create_node(AstNode::ErrPipe, span.start, span.end) + } + Token::OutErrGreaterThanPipe => { + self.create_node(AstNode::OutErrPipe, span.start, span.end) + } + _ => unreachable!(), + } + } else { + self.error("expected pipe-like operator") + } + } + pub fn is_dollar(&mut self) -> bool { self.tokens.peek_token() == Token::Dollar } diff --git a/src/resolver.rs b/src/resolver.rs index 5f56304..878b2f3 100644 --- a/src/resolver.rs +++ b/src/resolver.rs @@ -435,6 +435,9 @@ impl<'a> Resolver<'a> { self.resolve_node(in_ty); self.resolve_node(out_ty); } + AstNode::PipeElement { expr, redirection: _} => { + self.resolve_node(expr); + } AstNode::Pipeline(pipeline_id) => self.resolve_pipeline(pipeline_id), AstNode::PosParam { .. } => (/* seems unused for now */), AstNode::NamedValue { .. } => (/* seems unused for now */), diff --git a/src/typechecker.rs b/src/typechecker.rs index b653bfa..8f343cc 100644 --- a/src/typechecker.rs +++ b/src/typechecker.rs @@ -459,6 +459,9 @@ impl<'a> Typechecker<'a> { .last() .map_or(NONE_TYPE, |node_id| self.type_id_of(*node_id)) } + AstNode::PipeElement { expr, redirection: _ } => { + self.typecheck_expr(expr, expected) + } AstNode::Closure { params, block } => { // TODO: input/output types if let Some(params_node_id) = params { From 6d03f6d309a010471431fd4befe330b8ea7ec4ee Mon Sep 17 00:00:00 2001 From: WindSoilder Date: Thu, 24 Sep 2026 07:04:28 +0800 Subject: [PATCH 2/3] update snapshot --- ...nu_parser__test__node_output@alias.nu.snap | 24 +-- ...parser__test__node_output@closure3.nu.snap | 24 +-- ...w_nu_parser__test__node_output@for.nu.snap | 116 ++++++------ ...st__node_output@for_break_continue.nu.snap | 118 ++++++------ ...w_nu_parser__test__node_output@if_.nu.snap | 69 +++---- ...parser__test__node_output@if_oneof.nu.snap | 150 ++++++++-------- ...r__test__node_output@infer_complex.nu.snap | 93 +++++----- ...__test__node_output@infer_generics.nu.snap | 41 ++--- ...rser__test__node_output@infer_plus.nu.snap | 43 ++--- ..._nu_parser__test__node_output@let_.nu.snap | 40 +++-- ...er__test__node_output@let_mismatch.nu.snap | 169 ++++++++++-------- ..._nu_parser__test__node_output@loop.nu.snap | 60 ++++--- ...nu_parser__test__node_output@match.nu.snap | 51 +++--- ..._nu_parser__test__node_output@mut_.nu.snap | 98 +++++----- ...parser__test__node_output@pipeline.nu.snap | 42 +++-- ..._parser__test__node_output@reparse.nu.snap | 38 ++-- ...nu_parser__test__node_output@while.nu.snap | 51 +++--- 17 files changed, 650 insertions(+), 577 deletions(-) diff --git a/src/snapshots/new_nu_parser__test__node_output@alias.nu.snap b/src/snapshots/new_nu_parser__test__node_output@alias.nu.snap index 7e8b393..55bc1dd 100644 --- a/src/snapshots/new_nu_parser__test__node_output@alias.nu.snap +++ b/src/snapshots/new_nu_parser__test__node_output@alias.nu.snap @@ -6,24 +6,26 @@ input_file: tests/alias.nu ==== COMPILER ==== 0: String (6 to 19) ""fancy alias"" 1: Name (22 to 25) "foo" -2: Alias { new_name: NodeId(0), old_name: NodeId(1) } (0 to 25) -3: Name (27 to 32) "fancy" -4: Name (33 to 38) "alias" -5: Call(CallId(0)) (27 to 38) -6: Block(BlockId(0)) (0 to 39) +2: Call(CallId(0)) (22 to 25) +3: Alias { new_name: NodeId(0), old_name: NodeId(2) } (0 to 25) +4: Name (27 to 32) "fancy" +5: Name (33 to 38) "alias" +6: Call(CallId(1)) (27 to 38) +7: Block(BlockId(0)) (0 to 39) ==== SCOPE ==== -0: Frame Scope, node_id: NodeId(6) +0: Frame Scope, node_id: NodeId(7) decls: [ fancy alias: NodeId(0) ] ==== TYPES ==== 0: unknown 1: unknown -2: () -3: unknown -4: string -5: stream +2: unknown +3: () +4: unknown +5: string 6: stream +7: stream ==== IR ==== register_count: 0 file_count: 0 ==== IR ERRORS ==== -Error (NodeId 2): node Alias { new_name: NodeId(0), old_name: NodeId(1) } not suported yet +Error (NodeId 3): node Alias { new_name: NodeId(0), old_name: NodeId(2) } not suported yet diff --git a/src/snapshots/new_nu_parser__test__node_output@closure3.nu.snap b/src/snapshots/new_nu_parser__test__node_output@closure3.nu.snap index 595cd3a..e86da41 100644 --- a/src/snapshots/new_nu_parser__test__node_output@closure3.nu.snap +++ b/src/snapshots/new_nu_parser__test__node_output@closure3.nu.snap @@ -23,13 +23,14 @@ input_file: tests/closure3.nu 16: BinaryOp { lhs: NodeId(15), op: NodeId(13), rhs: NodeId(14) } (32 to 43) 17: Block(BlockId(0)) (32 to 43) 18: Closure { params: Some(NodeId(9)), block: NodeId(17) } (14 to 44) -19: Let { variable_name: NodeId(0), ty: None, initializer: NodeId(18), is_mutable: false } (0 to 44) -20: Name (46 to 52) "filter" -21: Variable (53 to 61) "$closure" -22: Call(CallId(0)) (46 to 61) -23: Block(BlockId(1)) (0 to 62) +19: PipeElement { expr: NodeId(18), redirection: None } (14 to 44) +20: Let { variable_name: NodeId(0), ty: None, initializer: NodeId(19), is_mutable: false } (0 to 44) +21: Name (46 to 52) "filter" +22: Variable (53 to 61) "$closure" +23: Call(CallId(0)) (46 to 61) +24: Block(BlockId(1)) (0 to 62) ==== SCOPE ==== -0: Frame Scope, node_id: NodeId(23) +0: Frame Scope, node_id: NodeId(24) variables: [ closure: NodeId(0) ] 1: Frame Scope, node_id: NodeId(17) variables: [ a: NodeId(1), b: NodeId(5) ] @@ -53,13 +54,14 @@ input_file: tests/closure3.nu 16: bool 17: bool 18: closure -19: () -20: unknown -21: closure -22: stream +19: closure +20: () +21: unknown +22: closure 23: stream +24: stream ==== IR ==== register_count: 0 file_count: 0 ==== IR ERRORS ==== -Error (NodeId 19): node Let { variable_name: NodeId(0), ty: None, initializer: NodeId(18), is_mutable: false } not suported yet +Error (NodeId 20): node Let { variable_name: NodeId(0), ty: None, initializer: NodeId(19), is_mutable: false } not suported yet diff --git a/src/snapshots/new_nu_parser__test__node_output@for.nu.snap b/src/snapshots/new_nu_parser__test__node_output@for.nu.snap index 7aa0cfd..a2051f4 100644 --- a/src/snapshots/new_nu_parser__test__node_output@for.nu.snap +++ b/src/snapshots/new_nu_parser__test__node_output@for.nu.snap @@ -1,85 +1,89 @@ --- source: src/test.rs -assertion_line: 77 expression: evaluate_example(path) input_file: tests/for.nu --- ==== COMPILER ==== 0: Variable (4 to 5) "x" 1: Int (8 to 9) "0" -2: Let { variable_name: NodeId(0), ty: None, initializer: NodeId(1), is_mutable: true } (0 to 9) -3: Variable (14 to 15) "i" -4: Int (20 to 21) "1" -5: Int (22 to 23) "2" -6: Int (24 to 25) "3" -7: List(ListId(0)) (19 to 25) -8: Variable (33 to 35) "$x" -9: Assignment (36 to 37) -10: Variable (38 to 40) "$x" -11: Plus (41 to 42) -12: Variable (43 to 45) "$i" -13: BinaryOp { lhs: NodeId(10), op: NodeId(11), rhs: NodeId(12) } (38 to 45) -14: BinaryOp { lhs: NodeId(8), op: NodeId(9), rhs: NodeId(13) } (33 to 45) -15: Block(BlockId(0)) (27 to 47) -16: For { variable: NodeId(3), range: NodeId(7), block: NodeId(15) } (10 to 47) -17: Variable (53 to 55) "$i" -18: Int (60 to 61) "4" -19: Int (62 to 63) "5" -20: Int (64 to 65) "6" -21: List(ListId(1)) (59 to 65) -22: Variable (73 to 75) "$x" -23: Assignment (76 to 77) -24: Variable (78 to 80) "$x" -25: Plus (81 to 82) -26: Variable (83 to 85) "$i" -27: BinaryOp { lhs: NodeId(24), op: NodeId(25), rhs: NodeId(26) } (78 to 85) -28: BinaryOp { lhs: NodeId(22), op: NodeId(23), rhs: NodeId(27) } (73 to 85) -29: Block(BlockId(1)) (67 to 87) -30: For { variable: NodeId(17), range: NodeId(21), block: NodeId(29) } (49 to 87) -31: Block(BlockId(2)) (0 to 88) +2: PipeElement { expr: NodeId(1), redirection: None } (8 to 9) +3: Let { variable_name: NodeId(0), ty: None, initializer: NodeId(2), is_mutable: true } (0 to 9) +4: Variable (14 to 15) "i" +5: Int (20 to 21) "1" +6: Int (22 to 23) "2" +7: Int (24 to 25) "3" +8: List(ListId(0)) (19 to 25) +9: Variable (33 to 35) "$x" +10: Assignment (36 to 37) +11: Variable (38 to 40) "$x" +12: Plus (41 to 42) +13: Variable (43 to 45) "$i" +14: BinaryOp { lhs: NodeId(11), op: NodeId(12), rhs: NodeId(13) } (38 to 45) +15: PipeElement { expr: NodeId(14), redirection: None } (38 to 45) +16: BinaryOp { lhs: NodeId(9), op: NodeId(10), rhs: NodeId(15) } (33 to 45) +17: Block(BlockId(0)) (27 to 47) +18: For { variable: NodeId(4), range: NodeId(8), block: NodeId(17) } (10 to 47) +19: Variable (53 to 55) "$i" +20: Int (60 to 61) "4" +21: Int (62 to 63) "5" +22: Int (64 to 65) "6" +23: List(ListId(1)) (59 to 65) +24: Variable (73 to 75) "$x" +25: Assignment (76 to 77) +26: Variable (78 to 80) "$x" +27: Plus (81 to 82) +28: Variable (83 to 85) "$i" +29: BinaryOp { lhs: NodeId(26), op: NodeId(27), rhs: NodeId(28) } (78 to 85) +30: PipeElement { expr: NodeId(29), redirection: None } (78 to 85) +31: BinaryOp { lhs: NodeId(24), op: NodeId(25), rhs: NodeId(30) } (73 to 85) +32: Block(BlockId(1)) (67 to 87) +33: For { variable: NodeId(19), range: NodeId(23), block: NodeId(32) } (49 to 87) +34: Block(BlockId(2)) (0 to 88) ==== SCOPE ==== -0: Frame Scope, node_id: NodeId(31) +0: Frame Scope, node_id: NodeId(34) variables: [ x: NodeId(0) ] -1: Frame Scope, node_id: NodeId(15) - variables: [ i: NodeId(3) ] -2: Frame Scope, node_id: NodeId(29) - variables: [ i: NodeId(17) ] +1: Frame Scope, node_id: NodeId(17) + variables: [ i: NodeId(4) ] +2: Frame Scope, node_id: NodeId(32) + variables: [ i: NodeId(19) ] ==== TYPES ==== 0: int 1: int -2: () -3: int +2: int +3: () 4: int 5: int 6: int -7: list -8: int -9: forbidden -10: int -11: forbidden -12: int +7: int +8: list +9: int +10: forbidden +11: int +12: forbidden 13: int -14: () -15: () +14: int +15: int 16: () -17: int -18: int +17: () +18: () 19: int 20: int -21: list +21: int 22: int -23: forbidden +23: list 24: int 25: forbidden 26: int -27: int -28: () -29: () -30: () +27: forbidden +28: int +29: int +30: int 31: () +32: () +33: () +34: () ==== IR ==== register_count: 0 file_count: 0 ==== IR ERRORS ==== -Error (NodeId 2): node Let { variable_name: NodeId(0), ty: None, initializer: NodeId(1), is_mutable: true } not suported yet - +Error (NodeId 3): node Let { variable_name: NodeId(0), ty: None, initializer: NodeId(2), is_mutable: true } not suported yet diff --git a/src/snapshots/new_nu_parser__test__node_output@for_break_continue.nu.snap b/src/snapshots/new_nu_parser__test__node_output@for_break_continue.nu.snap index b4d70f0..a7ba4a9 100644 --- a/src/snapshots/new_nu_parser__test__node_output@for_break_continue.nu.snap +++ b/src/snapshots/new_nu_parser__test__node_output@for_break_continue.nu.snap @@ -1,85 +1,87 @@ --- source: src/test.rs -assertion_line: 77 expression: evaluate_example(path) input_file: tests/for_break_continue.nu --- ==== COMPILER ==== 0: Variable (4 to 5) "x" 1: Int (8 to 9) "0" -2: Let { variable_name: NodeId(0), ty: None, initializer: NodeId(1), is_mutable: true } (0 to 9) -3: Variable (14 to 15) "i" -4: Int (20 to 21) "1" -5: Int (22 to 23) "2" -6: Int (24 to 25) "3" -7: List(ListId(0)) (19 to 25) -8: Variable (36 to 38) "$x" -9: GreaterThan (39 to 40) -10: Int (41 to 42) "2" -11: BinaryOp { lhs: NodeId(8), op: NodeId(9), rhs: NodeId(10) } (36 to 42) -12: Break (53 to 58) -13: Block(BlockId(0)) (43 to 64) -14: If { condition: NodeId(11), then_block: NodeId(13), else_block: None } (33 to 64) -15: Variable (73 to 75) "$i" -16: LessThan (76 to 77) -17: Int (78 to 79) "3" -18: BinaryOp { lhs: NodeId(15), op: NodeId(16), rhs: NodeId(17) } (73 to 79) -19: Continue (90 to 98) -20: Block(BlockId(1)) (80 to 104) -21: If { condition: NodeId(18), then_block: NodeId(20), else_block: None } (70 to 104) -22: Variable (110 to 112) "$x" -23: Assignment (113 to 114) -24: Variable (115 to 117) "$x" -25: Plus (118 to 119) -26: Variable (120 to 122) "$i" -27: BinaryOp { lhs: NodeId(24), op: NodeId(25), rhs: NodeId(26) } (115 to 122) -28: BinaryOp { lhs: NodeId(22), op: NodeId(23), rhs: NodeId(27) } (110 to 122) -29: Block(BlockId(2)) (27 to 124) -30: For { variable: NodeId(3), range: NodeId(7), block: NodeId(29) } (10 to 124) -31: Block(BlockId(3)) (0 to 124) +2: PipeElement { expr: NodeId(1), redirection: None } (8 to 9) +3: Let { variable_name: NodeId(0), ty: None, initializer: NodeId(2), is_mutable: true } (0 to 9) +4: Variable (14 to 15) "i" +5: Int (20 to 21) "1" +6: Int (22 to 23) "2" +7: Int (24 to 25) "3" +8: List(ListId(0)) (19 to 25) +9: Variable (36 to 38) "$x" +10: GreaterThan (39 to 40) +11: Int (41 to 42) "2" +12: BinaryOp { lhs: NodeId(9), op: NodeId(10), rhs: NodeId(11) } (36 to 42) +13: Break (53 to 58) +14: Block(BlockId(0)) (43 to 64) +15: If { condition: NodeId(12), then_block: NodeId(14), else_block: None } (33 to 64) +16: Variable (73 to 75) "$i" +17: LessThan (76 to 77) +18: Int (78 to 79) "3" +19: BinaryOp { lhs: NodeId(16), op: NodeId(17), rhs: NodeId(18) } (73 to 79) +20: Continue (90 to 98) +21: Block(BlockId(1)) (80 to 104) +22: If { condition: NodeId(19), then_block: NodeId(21), else_block: None } (70 to 104) +23: Variable (110 to 112) "$x" +24: Assignment (113 to 114) +25: Variable (115 to 117) "$x" +26: Plus (118 to 119) +27: Variable (120 to 122) "$i" +28: BinaryOp { lhs: NodeId(25), op: NodeId(26), rhs: NodeId(27) } (115 to 122) +29: PipeElement { expr: NodeId(28), redirection: None } (115 to 122) +30: BinaryOp { lhs: NodeId(23), op: NodeId(24), rhs: NodeId(29) } (110 to 122) +31: Block(BlockId(2)) (27 to 124) +32: For { variable: NodeId(4), range: NodeId(8), block: NodeId(31) } (10 to 124) +33: Block(BlockId(3)) (0 to 124) ==== SCOPE ==== -0: Frame Scope, node_id: NodeId(31) +0: Frame Scope, node_id: NodeId(33) variables: [ x: NodeId(0) ] -1: Frame Scope, node_id: NodeId(29) - variables: [ i: NodeId(3) ] -2: Frame Scope, node_id: NodeId(13) (empty) -3: Frame Scope, node_id: NodeId(20) (empty) +1: Frame Scope, node_id: NodeId(31) + variables: [ i: NodeId(4) ] +2: Frame Scope, node_id: NodeId(14) (empty) +3: Frame Scope, node_id: NodeId(21) (empty) ==== TYPES ==== 0: int 1: int -2: () -3: int +2: int +3: () 4: int 5: int 6: int -7: list -8: int -9: forbidden -10: int -11: bool -12: () +7: int +8: list +9: int +10: forbidden +11: int +12: bool 13: () 14: () -15: int -16: forbidden -17: int -18: bool -19: () +15: () +16: int +17: forbidden +18: int +19: bool 20: () 21: () -22: int -23: forbidden -24: int -25: forbidden -26: int +22: () +23: int +24: forbidden +25: int +26: forbidden 27: int -28: () -29: () +28: int +29: int 30: () 31: () +32: () +33: () ==== IR ==== register_count: 0 file_count: 0 ==== IR ERRORS ==== -Error (NodeId 2): node Let { variable_name: NodeId(0), ty: None, initializer: NodeId(1), is_mutable: true } not suported yet - +Error (NodeId 3): node Let { variable_name: NodeId(0), ty: None, initializer: NodeId(2), is_mutable: true } not suported yet diff --git a/src/snapshots/new_nu_parser__test__node_output@if_.nu.snap b/src/snapshots/new_nu_parser__test__node_output@if_.nu.snap index 6eada57..1384041 100644 --- a/src/snapshots/new_nu_parser__test__node_output@if_.nu.snap +++ b/src/snapshots/new_nu_parser__test__node_output@if_.nu.snap @@ -2,58 +2,59 @@ source: src/test.rs expression: evaluate_example(path) input_file: tests/if_.nu -snapshot_kind: text --- ==== COMPILER ==== 0: Variable (4 to 5) "x" 1: Int (8 to 11) "123" -2: Let { variable_name: NodeId(0), ty: None, initializer: NodeId(1), is_mutable: false } (0 to 11) -3: Variable (16 to 18) "$x" -4: LessThan (19 to 20) -5: Int (21 to 24) "100" -6: BinaryOp { lhs: NodeId(3), op: NodeId(4), rhs: NodeId(5) } (16 to 24) -7: Int (31 to 32) "5" -8: Block(BlockId(0)) (25 to 35) -9: Variable (43 to 45) "$x" -10: GreaterThan (46 to 47) -11: Int (48 to 51) "200" -12: BinaryOp { lhs: NodeId(9), op: NodeId(10), rhs: NodeId(11) } (43 to 51) -13: Int (58 to 59) "6" -14: Block(BlockId(1)) (52 to 62) -15: Int (73 to 74) "7" -16: Block(BlockId(2)) (67 to 76) -17: If { condition: NodeId(12), then_block: NodeId(14), else_block: Some(NodeId(16)) } (40 to 76) -18: If { condition: NodeId(6), then_block: NodeId(8), else_block: Some(NodeId(17)) } (13 to 76) -19: Block(BlockId(3)) (0 to 77) +2: PipeElement { expr: NodeId(1), redirection: None } (8 to 11) +3: Let { variable_name: NodeId(0), ty: None, initializer: NodeId(2), is_mutable: false } (0 to 11) +4: Variable (16 to 18) "$x" +5: LessThan (19 to 20) +6: Int (21 to 24) "100" +7: BinaryOp { lhs: NodeId(4), op: NodeId(5), rhs: NodeId(6) } (16 to 24) +8: Int (31 to 32) "5" +9: Block(BlockId(0)) (25 to 35) +10: Variable (43 to 45) "$x" +11: GreaterThan (46 to 47) +12: Int (48 to 51) "200" +13: BinaryOp { lhs: NodeId(10), op: NodeId(11), rhs: NodeId(12) } (43 to 51) +14: Int (58 to 59) "6" +15: Block(BlockId(1)) (52 to 62) +16: Int (73 to 74) "7" +17: Block(BlockId(2)) (67 to 76) +18: If { condition: NodeId(13), then_block: NodeId(15), else_block: Some(NodeId(17)) } (40 to 76) +19: If { condition: NodeId(7), then_block: NodeId(9), else_block: Some(NodeId(18)) } (13 to 76) +20: Block(BlockId(3)) (0 to 77) ==== SCOPE ==== -0: Frame Scope, node_id: NodeId(19) +0: Frame Scope, node_id: NodeId(20) variables: [ x: NodeId(0) ] -1: Frame Scope, node_id: NodeId(8) (empty) -2: Frame Scope, node_id: NodeId(14) (empty) -3: Frame Scope, node_id: NodeId(16) (empty) +1: Frame Scope, node_id: NodeId(9) (empty) +2: Frame Scope, node_id: NodeId(15) (empty) +3: Frame Scope, node_id: NodeId(17) (empty) ==== TYPES ==== 0: int 1: int -2: () -3: int -4: forbidden -5: int -6: bool -7: int +2: int +3: () +4: int +5: forbidden +6: int +7: bool 8: int 9: int -10: forbidden -11: int -12: bool -13: int +10: int +11: forbidden +12: int +13: bool 14: int 15: int 16: int 17: int 18: int 19: int +20: int ==== IR ==== register_count: 0 file_count: 0 ==== IR ERRORS ==== -Error (NodeId 2): node Let { variable_name: NodeId(0), ty: None, initializer: NodeId(1), is_mutable: false } not suported yet +Error (NodeId 3): node Let { variable_name: NodeId(0), ty: None, initializer: NodeId(2), is_mutable: false } not suported yet diff --git a/src/snapshots/new_nu_parser__test__node_output@if_oneof.nu.snap b/src/snapshots/new_nu_parser__test__node_output@if_oneof.nu.snap index d646193..a8729a0 100644 --- a/src/snapshots/new_nu_parser__test__node_output@if_oneof.nu.snap +++ b/src/snapshots/new_nu_parser__test__node_output@if_oneof.nu.snap @@ -6,92 +6,98 @@ input_file: tests/if_oneof.nu ==== COMPILER ==== 0: Variable (4 to 5) "x" 1: Int (8 to 11) "123" -2: Let { variable_name: NodeId(0), ty: None, initializer: NodeId(1), is_mutable: false } (0 to 11) -3: Variable (17 to 18) "z" -4: Name (20 to 25) "oneof" -5: Name (26 to 32) "string" -6: Type { name: NodeId(5), args: None, optional: false } (26 to 32) -7: Name (34 to 37) "int" -8: Type { name: NodeId(7), args: None, optional: false } (34 to 37) -9: TypeArgs(TypeArgsId(0)) (25 to 38) -10: Type { name: NodeId(4), args: Some(NodeId(9)), optional: false } (20 to 25) -11: Variable (44 to 46) "$x" -12: LessThan (47 to 48) -13: Int (49 to 51) "50" -14: BinaryOp { lhs: NodeId(11), op: NodeId(12), rhs: NodeId(13) } (44 to 51) -15: String (56 to 61) ""foo"" -16: Block(BlockId(0)) (52 to 64) -17: Int (73 to 76) "100" -18: Block(BlockId(1)) (69 to 78) -19: If { condition: NodeId(14), then_block: NodeId(16), else_block: Some(NodeId(18)) } (41 to 78) -20: Let { variable_name: NodeId(3), ty: Some(NodeId(10)), initializer: NodeId(19), is_mutable: false } (13 to 78) -21: Variable (118 to 119) "y" -22: Name (121 to 126) "oneof" -23: Name (127 to 130) "int" -24: Type { name: NodeId(23), args: None, optional: false } (127 to 130) -25: TypeArgs(TypeArgsId(1)) (126 to 131) -26: Type { name: NodeId(22), args: Some(NodeId(25)), optional: false } (121 to 126) -27: Variable (137 to 139) "$x" -28: LessThan (140 to 141) -29: Int (142 to 144) "50" -30: BinaryOp { lhs: NodeId(27), op: NodeId(28), rhs: NodeId(29) } (137 to 144) -31: Int (149 to 152) "100" -32: Block(BlockId(2)) (145 to 155) -33: Int (164 to 166) "10" -34: Block(BlockId(3)) (160 to 168) -35: If { condition: NodeId(30), then_block: NodeId(32), else_block: Some(NodeId(34)) } (134 to 168) -36: Let { variable_name: NodeId(21), ty: Some(NodeId(26)), initializer: NodeId(35), is_mutable: false } (114 to 168) -37: Variable (170 to 172) "$z" -38: Block(BlockId(4)) (0 to 173) +2: PipeElement { expr: NodeId(1), redirection: None } (8 to 11) +3: Let { variable_name: NodeId(0), ty: None, initializer: NodeId(2), is_mutable: false } (0 to 11) +4: Variable (17 to 18) "z" +5: Name (20 to 25) "oneof" +6: Name (26 to 32) "string" +7: Type { name: NodeId(6), args: None, optional: false } (26 to 32) +8: Name (34 to 37) "int" +9: Type { name: NodeId(8), args: None, optional: false } (34 to 37) +10: TypeArgs(TypeArgsId(0)) (25 to 38) +11: Type { name: NodeId(5), args: Some(NodeId(10)), optional: false } (20 to 25) +12: Variable (44 to 46) "$x" +13: LessThan (47 to 48) +14: Int (49 to 51) "50" +15: BinaryOp { lhs: NodeId(12), op: NodeId(13), rhs: NodeId(14) } (44 to 51) +16: String (56 to 61) ""foo"" +17: Block(BlockId(0)) (52 to 64) +18: Int (73 to 76) "100" +19: Block(BlockId(1)) (69 to 78) +20: If { condition: NodeId(15), then_block: NodeId(17), else_block: Some(NodeId(19)) } (41 to 78) +21: PipeElement { expr: NodeId(20), redirection: None } (41 to 78) +22: Let { variable_name: NodeId(4), ty: Some(NodeId(11)), initializer: NodeId(21), is_mutable: false } (13 to 78) +23: Variable (118 to 119) "y" +24: Name (121 to 126) "oneof" +25: Name (127 to 130) "int" +26: Type { name: NodeId(25), args: None, optional: false } (127 to 130) +27: TypeArgs(TypeArgsId(1)) (126 to 131) +28: Type { name: NodeId(24), args: Some(NodeId(27)), optional: false } (121 to 126) +29: Variable (137 to 139) "$x" +30: LessThan (140 to 141) +31: Int (142 to 144) "50" +32: BinaryOp { lhs: NodeId(29), op: NodeId(30), rhs: NodeId(31) } (137 to 144) +33: Int (149 to 152) "100" +34: Block(BlockId(2)) (145 to 155) +35: Int (164 to 166) "10" +36: Block(BlockId(3)) (160 to 168) +37: If { condition: NodeId(32), then_block: NodeId(34), else_block: Some(NodeId(36)) } (134 to 168) +38: PipeElement { expr: NodeId(37), redirection: None } (134 to 168) +39: Let { variable_name: NodeId(23), ty: Some(NodeId(28)), initializer: NodeId(38), is_mutable: false } (114 to 168) +40: Variable (170 to 172) "$z" +41: Block(BlockId(4)) (0 to 173) ==== SCOPE ==== -0: Frame Scope, node_id: NodeId(38) - variables: [ x: NodeId(0), y: NodeId(21), z: NodeId(3) ] -1: Frame Scope, node_id: NodeId(16) (empty) -2: Frame Scope, node_id: NodeId(18) (empty) -3: Frame Scope, node_id: NodeId(32) (empty) -4: Frame Scope, node_id: NodeId(34) (empty) +0: Frame Scope, node_id: NodeId(41) + variables: [ x: NodeId(0), y: NodeId(23), z: NodeId(4) ] +1: Frame Scope, node_id: NodeId(17) (empty) +2: Frame Scope, node_id: NodeId(19) (empty) +3: Frame Scope, node_id: NodeId(34) (empty) +4: Frame Scope, node_id: NodeId(36) (empty) ==== TYPES ==== 0: int 1: int -2: () -3: oneof -4: unknown +2: int +3: () +4: oneof 5: unknown -6: string -7: unknown -8: int -9: forbidden -10: oneof -11: int -12: forbidden -13: int -14: bool -15: string +6: unknown +7: string +8: unknown +9: int +10: forbidden +11: oneof +12: int +13: forbidden +14: int +15: bool 16: string -17: int +17: string 18: int -19: oneof -20: () -21: int -22: unknown -23: unknown -24: int -25: forbidden +19: int +20: oneof +21: oneof +22: () +23: int +24: unknown +25: unknown 26: int -27: int -28: forbidden +27: forbidden +28: int 29: int -30: bool +30: forbidden 31: int -32: int +32: bool 33: int 34: int 35: int -36: () -37: oneof -38: oneof +36: int +37: int +38: int +39: () +40: oneof +41: oneof ==== IR ==== register_count: 0 file_count: 0 ==== IR ERRORS ==== -Error (NodeId 2): node Let { variable_name: NodeId(0), ty: None, initializer: NodeId(1), is_mutable: false } not suported yet +Error (NodeId 3): node Let { variable_name: NodeId(0), ty: None, initializer: NodeId(2), is_mutable: false } not suported yet diff --git a/src/snapshots/new_nu_parser__test__node_output@infer_complex.nu.snap b/src/snapshots/new_nu_parser__test__node_output@infer_complex.nu.snap index 9403df4..6b3d410 100644 --- a/src/snapshots/new_nu_parser__test__node_output@infer_complex.nu.snap +++ b/src/snapshots/new_nu_parser__test__node_output@infer_complex.nu.snap @@ -73,32 +73,34 @@ input_file: tests/infer_complex.nu 66: Name (158 to 168) "mysterious" 67: Int (169 to 170) "0" 68: Call(CallId(0)) (158 to 170) -69: Let { variable_name: NodeId(65), ty: None, initializer: NodeId(68), is_mutable: false } (150 to 170) -70: Variable (175 to 176) "a" -71: Name (178 to 184) "record" -72: Name (185 to 186) "a" -73: Name (188 to 194) "number" -74: Type { name: NodeId(73), args: None, optional: false } (188 to 194) -75: PosParam { name: NodeId(72), ty: Some(NodeId(74)), custom_completion: None, default: None, is_optional: false } (185 to 194) -76: Params(ParamsId(7)) (184 to 195) -77: RecordType { fields: NodeId(76), optional: false } (178 to 196) -78: Name (198 to 199) "f" -79: String (202 to 203) "a" -80: Int (205 to 208) "123" -81: String (210 to 211) "b" -82: Variable (213 to 215) "$m" -83: Record(RecordId(0)) (200 to 218) -84: String (220 to 221) "a" -85: Float (223 to 227) "12.3" -86: String (229 to 230) "b" -87: String (232 to 237) ""foo"" -88: Record(RecordId(1)) (218 to 239) -89: Call(CallId(1)) (198 to 239) -90: Let { variable_name: NodeId(70), ty: Some(NodeId(77)), initializer: NodeId(89), is_mutable: false } (171 to 239) -91: Block(BlockId(2)) (0 to 240) +69: PipeElement { expr: NodeId(68), redirection: None } (158 to 170) +70: Let { variable_name: NodeId(65), ty: None, initializer: NodeId(69), is_mutable: false } (150 to 170) +71: Variable (175 to 176) "a" +72: Name (178 to 184) "record" +73: Name (185 to 186) "a" +74: Name (188 to 194) "number" +75: Type { name: NodeId(74), args: None, optional: false } (188 to 194) +76: PosParam { name: NodeId(73), ty: Some(NodeId(75)), custom_completion: None, default: None, is_optional: false } (185 to 194) +77: Params(ParamsId(7)) (184 to 195) +78: RecordType { fields: NodeId(77), optional: false } (178 to 196) +79: Name (198 to 199) "f" +80: String (202 to 203) "a" +81: Int (205 to 208) "123" +82: String (210 to 211) "b" +83: Variable (213 to 215) "$m" +84: Record(RecordId(0)) (200 to 218) +85: String (220 to 221) "a" +86: Float (223 to 227) "12.3" +87: String (229 to 230) "b" +88: String (232 to 237) ""foo"" +89: Record(RecordId(1)) (218 to 239) +90: Call(CallId(1)) (198 to 239) +91: PipeElement { expr: NodeId(90), redirection: None } (198 to 239) +92: Let { variable_name: NodeId(71), ty: Some(NodeId(78)), initializer: NodeId(91), is_mutable: false } (171 to 239) +93: Block(BlockId(2)) (0 to 240) ==== SCOPE ==== -0: Frame Scope, node_id: NodeId(91) - variables: [ a: NodeId(70), m: NodeId(65) ] +0: Frame Scope, node_id: NodeId(93) + variables: [ a: NodeId(71), m: NodeId(65) ] decls: [ f: NodeId(0), mysterious: NodeId(49) ] 1: Frame Scope, node_id: NodeId(47) variables: [ x: NodeId(4), y: NodeId(17) ] @@ -176,32 +178,33 @@ input_file: tests/infer_complex.nu 66: unknown 67: int 68: bottom -69: () -70: record -71: unknown +69: bottom +70: () +71: record 72: unknown 73: unknown -74: number -75: unknown +74: unknown +75: number 76: unknown -77: record -78: unknown +77: unknown +78: record 79: unknown -80: int -81: unknown -82: bottom -83: record -84: unknown -85: float -86: unknown -87: string -88: record -89: record -90: () -91: () +80: unknown +81: int +82: unknown +83: bottom +84: record +85: unknown +86: float +87: unknown +88: string +89: record +90: record +91: record +92: () +93: () ==== IR ==== register_count: 0 file_count: 0 ==== IR ERRORS ==== Error (NodeId 48): node Def { attributes: None, name: NodeId(0), type_params: Some(NodeId(3)), params: NodeId(30), in_out_types: Some(NodeId(45)), block: NodeId(47), env: false, wrapped: false } not suported yet - diff --git a/src/snapshots/new_nu_parser__test__node_output@infer_generics.nu.snap b/src/snapshots/new_nu_parser__test__node_output@infer_generics.nu.snap index 07f272f..9fcb730 100644 --- a/src/snapshots/new_nu_parser__test__node_output@infer_generics.nu.snap +++ b/src/snapshots/new_nu_parser__test__node_output@infer_generics.nu.snap @@ -25,19 +25,20 @@ input_file: tests/infer_generics.nu 18: Name (50 to 51) "T" 19: Type { name: NodeId(18), args: None, optional: false } (50 to 51) 20: Variable (54 to 56) "$x" -21: Let { variable_name: NodeId(17), ty: Some(NodeId(19)), initializer: NodeId(20), is_mutable: false } (43 to 56) -22: Variable (60 to 62) "$z" -23: List(ListId(0)) (59 to 62) -24: Block(BlockId(0)) (39 to 65) -25: Def { attributes: None, name: NodeId(0), type_params: Some(NodeId(2)), params: NodeId(7), in_out_types: Some(NodeId(16)), block: NodeId(24), env: false, wrapped: false } (0 to 65) -26: Name (67 to 68) "f" -27: Int (69 to 70) "1" -28: Call(CallId(0)) (67 to 70) -29: Block(BlockId(1)) (0 to 71) +21: PipeElement { expr: NodeId(20), redirection: None } (54 to 56) +22: Let { variable_name: NodeId(17), ty: Some(NodeId(19)), initializer: NodeId(21), is_mutable: false } (43 to 56) +23: Variable (60 to 62) "$z" +24: List(ListId(0)) (59 to 62) +25: Block(BlockId(0)) (39 to 65) +26: Def { attributes: None, name: NodeId(0), type_params: Some(NodeId(2)), params: NodeId(7), in_out_types: Some(NodeId(16)), block: NodeId(25), env: false, wrapped: false } (0 to 65) +27: Name (67 to 68) "f" +28: Int (69 to 70) "1" +29: Call(CallId(0)) (67 to 70) +30: Block(BlockId(1)) (0 to 71) ==== SCOPE ==== -0: Frame Scope, node_id: NodeId(29) +0: Frame Scope, node_id: NodeId(30) decls: [ f: NodeId(0) ] -1: Frame Scope, node_id: NodeId(24) +1: Frame Scope, node_id: NodeId(25) variables: [ x: NodeId(3), z: NodeId(17) ] type decls: [ T: NodeId(1) ] ==== TYPES ==== @@ -62,18 +63,18 @@ input_file: tests/infer_generics.nu 18: unknown 19: T 20: T -21: () -22: T -23: list +21: T +22: () +23: T 24: list -25: () -26: unknown -27: int -28: list +25: list +26: () +27: unknown +28: int 29: list +30: list ==== IR ==== register_count: 0 file_count: 0 ==== IR ERRORS ==== -Error (NodeId 25): node Def { attributes: None, name: NodeId(0), type_params: Some(NodeId(2)), params: NodeId(7), in_out_types: Some(NodeId(16)), block: NodeId(24), env: false, wrapped: false } not suported yet - +Error (NodeId 26): node Def { attributes: None, name: NodeId(0), type_params: Some(NodeId(2)), params: NodeId(7), in_out_types: Some(NodeId(16)), block: NodeId(25), env: false, wrapped: false } not suported yet diff --git a/src/snapshots/new_nu_parser__test__node_output@infer_plus.nu.snap b/src/snapshots/new_nu_parser__test__node_output@infer_plus.nu.snap index 6c867c2..fcb28c8 100644 --- a/src/snapshots/new_nu_parser__test__node_output@infer_plus.nu.snap +++ b/src/snapshots/new_nu_parser__test__node_output@infer_plus.nu.snap @@ -24,18 +24,19 @@ input_file: tests/infer_plus.nu 17: Name (56 to 66) "mysterious" 18: Int (67 to 68) "0" 19: Call(CallId(0)) (56 to 68) -20: Let { variable_name: NodeId(16), ty: None, initializer: NodeId(19), is_mutable: false } (48 to 68) -21: Variable (70 to 72) "$m" -22: Plus (73 to 74) -23: String (75 to 80) ""foo"" -24: BinaryOp { lhs: NodeId(21), op: NodeId(22), rhs: NodeId(23) } (70 to 80) -25: Variable (81 to 83) "$m" -26: Plus (84 to 85) -27: Int (86 to 89) "123" -28: BinaryOp { lhs: NodeId(25), op: NodeId(26), rhs: NodeId(27) } (81 to 89) -29: Block(BlockId(1)) (0 to 90) +20: PipeElement { expr: NodeId(19), redirection: None } (56 to 68) +21: Let { variable_name: NodeId(16), ty: None, initializer: NodeId(20), is_mutable: false } (48 to 68) +22: Variable (70 to 72) "$m" +23: Plus (73 to 74) +24: String (75 to 80) ""foo"" +25: BinaryOp { lhs: NodeId(22), op: NodeId(23), rhs: NodeId(24) } (70 to 80) +26: Variable (81 to 83) "$m" +27: Plus (84 to 85) +28: Int (86 to 89) "123" +29: BinaryOp { lhs: NodeId(26), op: NodeId(27), rhs: NodeId(28) } (81 to 89) +30: Block(BlockId(1)) (0 to 90) ==== SCOPE ==== -0: Frame Scope, node_id: NodeId(29) +0: Frame Scope, node_id: NodeId(30) variables: [ m: NodeId(16) ] decls: [ mysterious: NodeId(0) ] 1: Frame Scope, node_id: NodeId(14) @@ -62,21 +63,21 @@ input_file: tests/infer_plus.nu 17: unknown 18: int 19: bottom -20: () -21: bottom -22: forbidden -23: string +20: bottom +21: () +22: bottom +23: forbidden 24: string -25: bottom -26: forbidden -27: int -28: string +25: string +26: bottom +27: forbidden +28: int 29: string +30: string ==== TYPE ERRORS ==== -Error (NodeId 27): Expected string, got int +Error (NodeId 28): Expected string, got int ==== IR ==== register_count: 0 file_count: 0 ==== IR ERRORS ==== Error (NodeId 15): node Def { attributes: None, name: NodeId(0), type_params: Some(NodeId(2)), params: NodeId(7), in_out_types: Some(NodeId(13)), block: NodeId(14), env: false, wrapped: false } not suported yet - diff --git a/src/snapshots/new_nu_parser__test__node_output@let_.nu.snap b/src/snapshots/new_nu_parser__test__node_output@let_.nu.snap index 5ace565..840cfd8 100644 --- a/src/snapshots/new_nu_parser__test__node_output@let_.nu.snap +++ b/src/snapshots/new_nu_parser__test__node_output@let_.nu.snap @@ -2,38 +2,44 @@ source: src/test.rs expression: evaluate_example(path) input_file: tests/let_.nu -snapshot_kind: text --- ==== COMPILER ==== 0: Variable (4 to 5) "x" 1: Int (8 to 11) "123" -2: Let { variable_name: NodeId(0), ty: None, initializer: NodeId(1), is_mutable: false } (0 to 11) -3: Variable (13 to 15) "$x" -4: Variable (21 to 22) "x" -5: Int (25 to 28) "123" -6: Int (31 to 34) "456" -7: Pipeline(PipelineId(0)) (25 to 34) -8: Let { variable_name: NodeId(4), ty: None, initializer: NodeId(7), is_mutable: false } (17 to 34) -9: Variable (36 to 38) "$x" -10: Block(BlockId(0)) (0 to 39) +2: PipeElement { expr: NodeId(1), redirection: None } (8 to 11) +3: Let { variable_name: NodeId(0), ty: None, initializer: NodeId(2), is_mutable: false } (0 to 11) +4: Variable (13 to 15) "$x" +5: Variable (21 to 22) "x" +6: Int (25 to 28) "123" +7: PipeElement { expr: NodeId(6), redirection: None } (25 to 29) +8: Pipe (29 to 30) +9: Int (31 to 34) "456" +10: PipeElement { expr: NodeId(9), redirection: None } (31 to 34) +11: Pipeline(PipelineId(0)) (25 to 34) +12: Let { variable_name: NodeId(5), ty: None, initializer: NodeId(11), is_mutable: false } (17 to 34) +13: Variable (36 to 38) "$x" +14: Block(BlockId(0)) (0 to 39) ==== SCOPE ==== -0: Frame Scope, node_id: NodeId(10) - variables: [ x: NodeId(4) ] +0: Frame Scope, node_id: NodeId(14) + variables: [ x: NodeId(5) ] ==== TYPES ==== 0: int 1: int -2: () -3: int +2: int +3: () 4: int 5: int 6: int 7: int -8: () +8: unknown 9: int 10: int +11: int +12: () +13: int +14: int ==== IR ==== register_count: 0 file_count: 0 ==== IR ERRORS ==== -Error (NodeId 2): node Let { variable_name: NodeId(0), ty: None, initializer: NodeId(1), is_mutable: false } not suported yet - +Error (NodeId 3): node Let { variable_name: NodeId(0), ty: None, initializer: NodeId(2), is_mutable: false } not suported yet diff --git a/src/snapshots/new_nu_parser__test__node_output@let_mismatch.nu.snap b/src/snapshots/new_nu_parser__test__node_output@let_mismatch.nu.snap index 2eb1b05..72b4d31 100644 --- a/src/snapshots/new_nu_parser__test__node_output@let_mismatch.nu.snap +++ b/src/snapshots/new_nu_parser__test__node_output@let_mismatch.nu.snap @@ -8,96 +8,109 @@ input_file: tests/let_mismatch.nu 1: Name (7 to 13) "number" 2: Type { name: NodeId(1), args: None, optional: false } (7 to 13) 3: Int (16 to 18) "10" -4: Let { variable_name: NodeId(0), ty: Some(NodeId(2)), initializer: NodeId(3), is_mutable: false } (0 to 18) -5: Variable (32 to 33) "y" -6: Name (35 to 38) "any" -7: Type { name: NodeId(6), args: None, optional: false } (35 to 38) -8: String (41 to 47) ""spam"" -9: Let { variable_name: NodeId(5), ty: Some(NodeId(7)), initializer: NodeId(8), is_mutable: false } (28 to 47) -10: Variable (60 to 61) "z" -11: Name (63 to 69) "string" -12: Type { name: NodeId(11), args: None, optional: false } (63 to 69) -13: Int (72 to 75) "123" -14: Let { variable_name: NodeId(10), ty: Some(NodeId(12)), initializer: NodeId(13), is_mutable: false } (56 to 75) -15: Variable (91 to 92) "w" -16: Name (94 to 98) "list" -17: Name (99 to 103) "list" -18: Name (104 to 107) "int" -19: Type { name: NodeId(18), args: None, optional: false } (104 to 107) -20: TypeArgs(TypeArgsId(0)) (103 to 108) -21: Type { name: NodeId(17), args: Some(NodeId(20)), optional: false } (99 to 103) -22: TypeArgs(TypeArgsId(1)) (98 to 109) -23: Type { name: NodeId(16), args: Some(NodeId(22)), optional: false } (94 to 98) -24: String (116 to 119) "'a'" -25: List(ListId(0)) (114 to 120) -26: List(ListId(1)) (112 to 122) -27: Let { variable_name: NodeId(15), ty: Some(NodeId(23)), initializer: NodeId(26), is_mutable: false } (87 to 122) -28: Variable (128 to 129) "v" -29: Name (131 to 137) "record" -30: Name (138 to 139) "a" -31: Name (141 to 144) "int" -32: Type { name: NodeId(31), args: None, optional: false } (141 to 144) -33: PosParam { name: NodeId(30), ty: Some(NodeId(32)), custom_completion: None, default: None, is_optional: false } (138 to 144) -34: Params(ParamsId(0)) (137 to 145) -35: RecordType { fields: NodeId(34), optional: false } (131 to 146) -36: String (149 to 150) "a" -37: String (152 to 157) ""foo"" -38: Record(RecordId(0)) (148 to 158) -39: Let { variable_name: NodeId(28), ty: Some(NodeId(35)), initializer: NodeId(38), is_mutable: false } (124 to 158) -40: Block(BlockId(0)) (0 to 159) +4: PipeElement { expr: NodeId(3), redirection: None } (16 to 20) +5: Let { variable_name: NodeId(0), ty: Some(NodeId(2)), initializer: NodeId(4), is_mutable: false } (0 to 20) +6: Variable (32 to 33) "y" +7: Name (35 to 38) "any" +8: Type { name: NodeId(7), args: None, optional: false } (35 to 38) +9: String (41 to 47) ""spam"" +10: PipeElement { expr: NodeId(9), redirection: None } (41 to 48) +11: Let { variable_name: NodeId(6), ty: Some(NodeId(8)), initializer: NodeId(10), is_mutable: false } (28 to 48) +12: Variable (60 to 61) "z" +13: Name (63 to 69) "string" +14: Type { name: NodeId(13), args: None, optional: false } (63 to 69) +15: Int (72 to 75) "123" +16: PipeElement { expr: NodeId(15), redirection: None } (72 to 76) +17: Let { variable_name: NodeId(12), ty: Some(NodeId(14)), initializer: NodeId(16), is_mutable: false } (56 to 76) +18: Variable (91 to 92) "w" +19: Name (94 to 98) "list" +20: Name (99 to 103) "list" +21: Name (104 to 107) "int" +22: Type { name: NodeId(21), args: None, optional: false } (104 to 107) +23: TypeArgs(TypeArgsId(0)) (103 to 108) +24: Type { name: NodeId(20), args: Some(NodeId(23)), optional: false } (99 to 103) +25: TypeArgs(TypeArgsId(1)) (98 to 109) +26: Type { name: NodeId(19), args: Some(NodeId(25)), optional: false } (94 to 98) +27: String (116 to 119) "'a'" +28: List(ListId(0)) (114 to 120) +29: List(ListId(1)) (112 to 122) +30: PipeElement { expr: NodeId(29), redirection: None } (112 to 123) +31: Let { variable_name: NodeId(18), ty: Some(NodeId(26)), initializer: NodeId(30), is_mutable: false } (87 to 123) +32: Variable (128 to 129) "v" +33: Name (131 to 137) "record" +34: Name (138 to 139) "a" +35: Name (141 to 144) "int" +36: Type { name: NodeId(35), args: None, optional: false } (141 to 144) +37: PosParam { name: NodeId(34), ty: Some(NodeId(36)), custom_completion: None, default: None, is_optional: false } (138 to 144) +38: Params(ParamsId(0)) (137 to 145) +39: RecordType { fields: NodeId(38), optional: false } (131 to 146) +40: String (149 to 150) "a" +41: String (152 to 157) ""foo"" +42: Record(RecordId(0)) (148 to 158) +43: PipeElement { expr: NodeId(42), redirection: None } (148 to 158) +44: Let { variable_name: NodeId(32), ty: Some(NodeId(39)), initializer: NodeId(43), is_mutable: false } (124 to 158) +45: Block(BlockId(0)) (0 to 159) ==== SCOPE ==== -0: Frame Scope, node_id: NodeId(40) - variables: [ v: NodeId(28), w: NodeId(15), x: NodeId(0), y: NodeId(5), z: NodeId(10) ] +0: Frame Scope, node_id: NodeId(45) + variables: [ v: NodeId(32), w: NodeId(18), x: NodeId(0), y: NodeId(6), z: NodeId(12) ] ==== TYPES ==== 0: number 1: unknown 2: number 3: int -4: () -5: any -6: unknown -7: any -8: string -9: () +4: int +5: () +6: any +7: unknown +8: any +9: string 10: string -11: unknown +11: () 12: string -13: int -14: () -15: list> -16: unknown -17: unknown -18: unknown -19: int -20: forbidden -21: list -22: forbidden -23: list> -24: string -25: list -26: list> -27: () -28: record -29: unknown -30: unknown -31: unknown -32: int +13: unknown +14: string +15: int +16: int +17: () +18: list> +19: unknown +20: unknown +21: unknown +22: int +23: forbidden +24: list +25: forbidden +26: list> +27: string +28: list +29: list> +30: list> +31: () +32: record 33: unknown 34: unknown -35: record -36: unknown -37: string -38: record -39: () -40: () +35: unknown +36: int +37: unknown +38: unknown +39: record +40: unknown +41: string +42: record +43: record +44: () +45: () ==== TYPE ERRORS ==== -Error (NodeId 13): Expected string, got int -Error (NodeId 24): Expected int, got string -Error (NodeId 25): Expected list, got list -Error (NodeId 26): Expected list>, got list> -Error (NodeId 38): Expected record, got record +Error (NodeId 15): Expected string, got int +Error (NodeId 16): Expected string, got int +Error (NodeId 27): Expected int, got string +Error (NodeId 28): Expected list, got list +Error (NodeId 29): Expected list>, got list> +Error (NodeId 30): Expected list>, got list> +Error (NodeId 42): Expected record, got record +Error (NodeId 43): Expected record, got record ==== IR ==== register_count: 0 file_count: 0 ==== IR ERRORS ==== -Error (NodeId 4): node Let { variable_name: NodeId(0), ty: Some(NodeId(2)), initializer: NodeId(3), is_mutable: false } not suported yet +Error (NodeId 5): node Let { variable_name: NodeId(0), ty: Some(NodeId(2)), initializer: NodeId(4), is_mutable: false } not suported yet diff --git a/src/snapshots/new_nu_parser__test__node_output@loop.nu.snap b/src/snapshots/new_nu_parser__test__node_output@loop.nu.snap index 0e8bd92..a542862 100644 --- a/src/snapshots/new_nu_parser__test__node_output@loop.nu.snap +++ b/src/snapshots/new_nu_parser__test__node_output@loop.nu.snap @@ -6,46 +6,48 @@ input_file: tests/loop.nu ==== COMPILER ==== 0: Variable (4 to 5) "x" 1: Int (8 to 9) "0" -2: Let { variable_name: NodeId(0), ty: None, initializer: NodeId(1), is_mutable: true } (0 to 9) -3: Variable (24 to 26) "$x" -4: GreaterThan (27 to 28) -5: Int (29 to 31) "10" -6: BinaryOp { lhs: NodeId(3), op: NodeId(4), rhs: NodeId(5) } (24 to 31) -7: Break (42 to 47) -8: Block(BlockId(0)) (32 to 53) -9: If { condition: NodeId(6), then_block: NodeId(8), else_block: None } (21 to 53) -10: Variable (59 to 61) "$x" -11: AddAssignment (62 to 64) -12: Int (65 to 66) "1" -13: BinaryOp { lhs: NodeId(10), op: NodeId(11), rhs: NodeId(12) } (59 to 66) -14: Block(BlockId(1)) (15 to 68) -15: Loop { block: NodeId(14) } (10 to 68) -16: Block(BlockId(2)) (0 to 68) +2: PipeElement { expr: NodeId(1), redirection: None } (8 to 9) +3: Let { variable_name: NodeId(0), ty: None, initializer: NodeId(2), is_mutable: true } (0 to 9) +4: Variable (24 to 26) "$x" +5: GreaterThan (27 to 28) +6: Int (29 to 31) "10" +7: BinaryOp { lhs: NodeId(4), op: NodeId(5), rhs: NodeId(6) } (24 to 31) +8: Break (42 to 47) +9: Block(BlockId(0)) (32 to 53) +10: If { condition: NodeId(7), then_block: NodeId(9), else_block: None } (21 to 53) +11: Variable (59 to 61) "$x" +12: AddAssignment (62 to 64) +13: Int (65 to 66) "1" +14: BinaryOp { lhs: NodeId(11), op: NodeId(12), rhs: NodeId(13) } (59 to 66) +15: Block(BlockId(1)) (15 to 68) +16: Loop { block: NodeId(15) } (10 to 68) +17: Block(BlockId(2)) (0 to 68) ==== SCOPE ==== -0: Frame Scope, node_id: NodeId(16) +0: Frame Scope, node_id: NodeId(17) variables: [ x: NodeId(0) ] -1: Frame Scope, node_id: NodeId(14) (empty) -2: Frame Scope, node_id: NodeId(8) (empty) +1: Frame Scope, node_id: NodeId(15) (empty) +2: Frame Scope, node_id: NodeId(9) (empty) ==== TYPES ==== 0: int 1: int -2: () -3: int -4: forbidden -5: int -6: bool -7: () +2: int +3: () +4: int +5: forbidden +6: int +7: bool 8: () 9: () -10: int -11: forbidden -12: int -13: () +10: () +11: int +12: forbidden +13: int 14: () 15: () 16: () +17: () ==== IR ==== register_count: 0 file_count: 0 ==== IR ERRORS ==== -Error (NodeId 2): node Let { variable_name: NodeId(0), ty: None, initializer: NodeId(1), is_mutable: true } not suported yet +Error (NodeId 3): node Let { variable_name: NodeId(0), ty: None, initializer: NodeId(2), is_mutable: true } not suported yet diff --git a/src/snapshots/new_nu_parser__test__node_output@match.nu.snap b/src/snapshots/new_nu_parser__test__node_output@match.nu.snap index af11bc0..d988c54 100644 --- a/src/snapshots/new_nu_parser__test__node_output@match.nu.snap +++ b/src/snapshots/new_nu_parser__test__node_output@match.nu.snap @@ -1,34 +1,35 @@ --- source: src/test.rs -assertion_line: 77 expression: evaluate_example(path) input_file: tests/match.nu --- ==== COMPILER ==== 0: Variable (4 to 5) "x" 1: Int (8 to 9) "1" -2: Let { variable_name: NodeId(0), ty: None, initializer: NodeId(1), is_mutable: false } (0 to 9) -3: Variable (15 to 18) "foo" -4: Variable (27 to 29) "$x" -5: Int (34 to 35) "1" -6: String (39 to 44) ""one"" -7: Int (48 to 49) "2" -8: Variable (63 to 64) "w" -9: Int (67 to 68) "3" -10: Let { variable_name: NodeId(8), ty: None, initializer: NodeId(9), is_mutable: false } (59 to 68) -11: Int (73 to 74) "2" -12: Plus (75 to 76) -13: Variable (77 to 79) "$w" -14: BinaryOp { lhs: NodeId(11), op: NodeId(12), rhs: NodeId(13) } (73 to 79) -15: Block(BlockId(0)) (59 to 82) -16: Closure { params: None, block: NodeId(15) } (53 to 83) -17: Int (87 to 88) "3" -18: Null (92 to 96) -19: String (100 to 101) "_" -20: Garbage (106 to 107) -21: Match(MatchId(0)) (21 to 110) -22: Let { variable_name: NodeId(3), ty: None, initializer: NodeId(21), is_mutable: false } (11 to 110) -23: Block(BlockId(1)) (0 to 111) +2: PipeElement { expr: NodeId(1), redirection: None } (8 to 9) +3: Let { variable_name: NodeId(0), ty: None, initializer: NodeId(2), is_mutable: false } (0 to 9) +4: Variable (15 to 18) "foo" +5: Variable (27 to 29) "$x" +6: Int (34 to 35) "1" +7: String (39 to 44) ""one"" +8: Int (48 to 49) "2" +9: Variable (63 to 64) "w" +10: Int (67 to 68) "3" +11: PipeElement { expr: NodeId(10), redirection: None } (67 to 68) +12: Let { variable_name: NodeId(9), ty: None, initializer: NodeId(11), is_mutable: false } (59 to 68) +13: Int (73 to 74) "2" +14: Plus (75 to 76) +15: Variable (77 to 79) "$w" +16: BinaryOp { lhs: NodeId(13), op: NodeId(14), rhs: NodeId(15) } (73 to 79) +17: Block(BlockId(0)) (59 to 82) +18: Closure { params: None, block: NodeId(17) } (53 to 83) +19: Int (87 to 88) "3" +20: Null (92 to 96) +21: String (100 to 101) "_" +22: Garbage (106 to 107) +23: Match(MatchId(0)) (21 to 110) +24: PipeElement { expr: NodeId(23), redirection: None } (21 to 110) +25: Let { variable_name: NodeId(4), ty: None, initializer: NodeId(24), is_mutable: false } (11 to 110) +26: Block(BlockId(1)) (0 to 111) ==== COMPILER ERRORS ==== -Error (NodeId 20): use null instead of () - +Error (NodeId 22): use null instead of () diff --git a/src/snapshots/new_nu_parser__test__node_output@mut_.nu.snap b/src/snapshots/new_nu_parser__test__node_output@mut_.nu.snap index 208c8dd..09c5bef 100644 --- a/src/snapshots/new_nu_parser__test__node_output@mut_.nu.snap +++ b/src/snapshots/new_nu_parser__test__node_output@mut_.nu.snap @@ -2,70 +2,80 @@ source: src/test.rs expression: evaluate_example(path) input_file: tests/mut_.nu -snapshot_kind: text --- ==== COMPILER ==== 0: Variable (4 to 5) "x" 1: Name (7 to 10) "int" 2: Type { name: NodeId(1), args: None, optional: false } (7 to 10) 3: Int (13 to 16) "123" -4: Let { variable_name: NodeId(0), ty: Some(NodeId(2)), initializer: NodeId(3), is_mutable: true } (0 to 16) -5: Variable (18 to 20) "$x" -6: Assignment (21 to 22) -7: Int (23 to 24) "3" -8: Plus (25 to 26) -9: Int (27 to 30) "456" -10: BinaryOp { lhs: NodeId(7), op: NodeId(8), rhs: NodeId(9) } (23 to 30) -11: BinaryOp { lhs: NodeId(5), op: NodeId(6), rhs: NodeId(10) } (18 to 30) -12: Variable (36 to 37) "y" -13: Name (39 to 42) "int" -14: Type { name: NodeId(13), args: None, optional: false } (39 to 42) -15: Int (45 to 48) "123" -16: Int (51 to 54) "344" -17: Pipeline(PipelineId(0)) (45 to 54) -18: Let { variable_name: NodeId(12), ty: Some(NodeId(14)), initializer: NodeId(17), is_mutable: true } (32 to 54) -19: Variable (56 to 58) "$y" -20: Assignment (59 to 60) -21: Int (61 to 62) "3" -22: Plus (63 to 64) -23: Int (65 to 66) "1" -24: BinaryOp { lhs: NodeId(21), op: NodeId(22), rhs: NodeId(23) } (61 to 66) -25: BinaryOp { lhs: NodeId(19), op: NodeId(20), rhs: NodeId(24) } (56 to 66) -26: Block(BlockId(0)) (0 to 68) +4: PipeElement { expr: NodeId(3), redirection: None } (13 to 16) +5: Let { variable_name: NodeId(0), ty: Some(NodeId(2)), initializer: NodeId(4), is_mutable: true } (0 to 16) +6: Variable (18 to 20) "$x" +7: Assignment (21 to 22) +8: Int (23 to 24) "3" +9: Plus (25 to 26) +10: Int (27 to 30) "456" +11: BinaryOp { lhs: NodeId(8), op: NodeId(9), rhs: NodeId(10) } (23 to 30) +12: PipeElement { expr: NodeId(11), redirection: None } (23 to 30) +13: BinaryOp { lhs: NodeId(6), op: NodeId(7), rhs: NodeId(12) } (18 to 30) +14: Variable (36 to 37) "y" +15: Name (39 to 42) "int" +16: Type { name: NodeId(15), args: None, optional: false } (39 to 42) +17: Int (45 to 48) "123" +18: PipeElement { expr: NodeId(17), redirection: None } (45 to 49) +19: Pipe (49 to 50) +20: Int (51 to 54) "344" +21: PipeElement { expr: NodeId(20), redirection: None } (51 to 54) +22: Pipeline(PipelineId(0)) (45 to 54) +23: Let { variable_name: NodeId(14), ty: Some(NodeId(16)), initializer: NodeId(22), is_mutable: true } (32 to 54) +24: Variable (56 to 58) "$y" +25: Assignment (59 to 60) +26: Int (61 to 62) "3" +27: Plus (63 to 64) +28: Int (65 to 66) "1" +29: BinaryOp { lhs: NodeId(26), op: NodeId(27), rhs: NodeId(28) } (61 to 66) +30: PipeElement { expr: NodeId(29), redirection: None } (61 to 67) +31: BinaryOp { lhs: NodeId(24), op: NodeId(25), rhs: NodeId(30) } (56 to 67) +32: Block(BlockId(0)) (0 to 68) ==== SCOPE ==== -0: Frame Scope, node_id: NodeId(26) - variables: [ x: NodeId(0), y: NodeId(12) ] +0: Frame Scope, node_id: NodeId(32) + variables: [ x: NodeId(0), y: NodeId(14) ] ==== TYPES ==== 0: int 1: unknown 2: int 3: int -4: () -5: int -6: forbidden -7: int -8: forbidden -9: int +4: int +5: () +6: int +7: forbidden +8: int +9: forbidden 10: int -11: () +11: int 12: int -13: unknown +13: () 14: int -15: int +15: unknown 16: int 17: int -18: () -19: int -20: forbidden +18: int +19: unknown +20: int 21: int -22: forbidden -23: int +22: int +23: () 24: int -25: () -26: () +25: forbidden +26: int +27: forbidden +28: int +29: int +30: int +31: () +32: () ==== IR ==== register_count: 0 file_count: 0 ==== IR ERRORS ==== -Error (NodeId 4): node Let { variable_name: NodeId(0), ty: Some(NodeId(2)), initializer: NodeId(3), is_mutable: true } not suported yet - +Error (NodeId 5): node Let { variable_name: NodeId(0), ty: Some(NodeId(2)), initializer: NodeId(4), is_mutable: true } not suported yet diff --git a/src/snapshots/new_nu_parser__test__node_output@pipeline.nu.snap b/src/snapshots/new_nu_parser__test__node_output@pipeline.nu.snap index c45a045..dfb8dd5 100644 --- a/src/snapshots/new_nu_parser__test__node_output@pipeline.nu.snap +++ b/src/snapshots/new_nu_parser__test__node_output@pipeline.nu.snap @@ -2,33 +2,47 @@ source: src/test.rs expression: evaluate_example(path) input_file: tests/pipeline.nu -snapshot_kind: text --- ==== COMPILER ==== 0: Int (0 to 1) "1" -1: Int (4 to 5) "3" -2: Int (8 to 9) "5" -3: Pipeline(PipelineId(0)) (0 to 9) -4: Int (42 to 43) "1" -5: Int (46 to 47) "2" -6: Int (50 to 51) "3" -7: Pipeline(PipelineId(1)) (42 to 51) -8: Block(BlockId(0)) (0 to 52) +1: Pipe (2 to 3) +2: Int (4 to 5) "3" +3: PipeElement { expr: NodeId(2), redirection: None } (4 to 6) +4: Pipe (6 to 7) +5: Int (8 to 9) "5" +6: PipeElement { expr: NodeId(5), redirection: None } (8 to 9) +7: Pipeline(PipelineId(0)) (0 to 9) +8: Int (42 to 43) "1" +9: Pipe (44 to 45) +10: Int (46 to 47) "2" +11: PipeElement { expr: NodeId(10), redirection: None } (46 to 48) +12: Pipe (48 to 49) +13: Int (50 to 51) "3" +14: PipeElement { expr: NodeId(13), redirection: None } (50 to 51) +15: Pipeline(PipelineId(1)) (42 to 51) +16: Block(BlockId(0)) (0 to 52) ==== SCOPE ==== -0: Frame Scope, node_id: NodeId(8) (empty) +0: Frame Scope, node_id: NodeId(16) (empty) ==== TYPES ==== 0: int -1: int +1: unknown 2: int 3: int -4: int +4: unknown 5: int 6: int 7: int 8: int +9: unknown +10: int +11: int +12: unknown +13: int +14: int +15: int +16: int ==== IR ==== register_count: 0 file_count: 0 ==== IR ERRORS ==== -Error (NodeId 3): node Pipeline(PipelineId(0)) not suported yet - +Error (NodeId 7): node Pipeline(PipelineId(0)) not suported yet diff --git a/src/snapshots/new_nu_parser__test__node_output@reparse.nu.snap b/src/snapshots/new_nu_parser__test__node_output@reparse.nu.snap index 8ec903f..ffbcca4 100644 --- a/src/snapshots/new_nu_parser__test__node_output@reparse.nu.snap +++ b/src/snapshots/new_nu_parser__test__node_output@reparse.nu.snap @@ -11,16 +11,18 @@ input_file: tests/reparse.nu 4: Variable (13 to 15) "$a" 5: Block(BlockId(0)) (13 to 16) 6: Closure { params: Some(NodeId(3)), block: NodeId(5) } (8 to 17) -7: Let { variable_name: NodeId(0), ty: None, initializer: NodeId(6), is_mutable: false } (0 to 17) -8: Variable (22 to 23) "y" -9: String (28 to 29) "a" -10: String (31 to 32) "b" -11: Record(RecordId(0)) (26 to 34) -12: Let { variable_name: NodeId(8), ty: None, initializer: NodeId(11), is_mutable: false } (18 to 34) -13: Block(BlockId(1)) (0 to 34) +7: PipeElement { expr: NodeId(6), redirection: None } (8 to 17) +8: Let { variable_name: NodeId(0), ty: None, initializer: NodeId(7), is_mutable: false } (0 to 17) +9: Variable (22 to 23) "y" +10: String (28 to 29) "a" +11: String (31 to 32) "b" +12: Record(RecordId(0)) (26 to 34) +13: PipeElement { expr: NodeId(12), redirection: None } (26 to 34) +14: Let { variable_name: NodeId(9), ty: None, initializer: NodeId(13), is_mutable: false } (18 to 34) +15: Block(BlockId(1)) (0 to 34) ==== SCOPE ==== -0: Frame Scope, node_id: NodeId(13) - variables: [ x: NodeId(0), y: NodeId(8) ] +0: Frame Scope, node_id: NodeId(15) + variables: [ x: NodeId(0), y: NodeId(9) ] 1: Frame Scope, node_id: NodeId(5) variables: [ a: NodeId(1) ] ==== TYPES ==== @@ -31,15 +33,17 @@ input_file: tests/reparse.nu 4: unknown 5: unknown 6: closure -7: () -8: record -9: unknown -10: string -11: record -12: () -13: () +7: closure +8: () +9: record +10: unknown +11: string +12: record +13: record +14: () +15: () ==== IR ==== register_count: 0 file_count: 0 ==== IR ERRORS ==== -Error (NodeId 7): node Let { variable_name: NodeId(0), ty: None, initializer: NodeId(6), is_mutable: false } not suported yet +Error (NodeId 8): node Let { variable_name: NodeId(0), ty: None, initializer: NodeId(7), is_mutable: false } not suported yet diff --git a/src/snapshots/new_nu_parser__test__node_output@while.nu.snap b/src/snapshots/new_nu_parser__test__node_output@while.nu.snap index f3cc1b8..f797278 100644 --- a/src/snapshots/new_nu_parser__test__node_output@while.nu.snap +++ b/src/snapshots/new_nu_parser__test__node_output@while.nu.snap @@ -2,44 +2,45 @@ source: src/test.rs expression: evaluate_example(path) input_file: tests/while.nu -snapshot_kind: text --- ==== COMPILER ==== 0: Variable (4 to 5) "x" 1: Int (8 to 9) "0" -2: Let { variable_name: NodeId(0), ty: None, initializer: NodeId(1), is_mutable: true } (0 to 9) -3: Int (16 to 17) "1" -4: LessThan (18 to 19) -5: Int (20 to 21) "2" -6: BinaryOp { lhs: NodeId(3), op: NodeId(4), rhs: NodeId(5) } (16 to 21) -7: Variable (26 to 28) "$x" -8: AddAssignment (29 to 31) -9: Int (32 to 33) "1" -10: BinaryOp { lhs: NodeId(7), op: NodeId(8), rhs: NodeId(9) } (26 to 33) -11: Block(BlockId(0)) (22 to 35) -12: While { condition: NodeId(6), block: NodeId(11) } (10 to 35) -13: Block(BlockId(1)) (0 to 36) +2: PipeElement { expr: NodeId(1), redirection: None } (8 to 9) +3: Let { variable_name: NodeId(0), ty: None, initializer: NodeId(2), is_mutable: true } (0 to 9) +4: Int (16 to 17) "1" +5: LessThan (18 to 19) +6: Int (20 to 21) "2" +7: BinaryOp { lhs: NodeId(4), op: NodeId(5), rhs: NodeId(6) } (16 to 21) +8: Variable (26 to 28) "$x" +9: AddAssignment (29 to 31) +10: Int (32 to 33) "1" +11: BinaryOp { lhs: NodeId(8), op: NodeId(9), rhs: NodeId(10) } (26 to 33) +12: Block(BlockId(0)) (22 to 35) +13: While { condition: NodeId(7), block: NodeId(12) } (10 to 35) +14: Block(BlockId(1)) (0 to 36) ==== SCOPE ==== -0: Frame Scope, node_id: NodeId(13) +0: Frame Scope, node_id: NodeId(14) variables: [ x: NodeId(0) ] -1: Frame Scope, node_id: NodeId(11) (empty) +1: Frame Scope, node_id: NodeId(12) (empty) ==== TYPES ==== 0: int 1: int -2: () -3: int -4: forbidden -5: int -6: bool -7: int -8: forbidden -9: int -10: () +2: int +3: () +4: int +5: forbidden +6: int +7: bool +8: int +9: forbidden +10: int 11: () 12: () 13: () +14: () ==== IR ==== register_count: 0 file_count: 0 ==== IR ERRORS ==== -Error (NodeId 2): node Let { variable_name: NodeId(0), ty: None, initializer: NodeId(1), is_mutable: true } not suported yet +Error (NodeId 3): node Let { variable_name: NodeId(0), ty: None, initializer: NodeId(2), is_mutable: true } not suported yet From e6d4fb23bef3e688a2b6c19165c38f0aef408a93 Mon Sep 17 00:00:00 2001 From: WindSoilder Date: Thu, 24 Sep 2026 07:09:35 +0800 Subject: [PATCH 3/3] fmt code --- src/parser.rs | 14 +++++++++++--- src/resolver.rs | 5 ++++- src/typechecker.rs | 7 ++++--- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index 8e7a987..e9262c0 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -87,7 +87,11 @@ pub struct Call { impl Call { pub fn new(parts: Vec, has_caret: bool, as_alias: bool) -> Self { - Self { parts, has_caret, as_alias } + Self { + parts, + has_caret, + as_alias, + } } } @@ -574,7 +578,9 @@ impl Parser { } pipe_elements.push(self.pipe_element()); } - self.compiler.pipelines.push(Pipeline::new(pipe_elements, nexts)); + self.compiler + .pipelines + .push(Pipeline::new(pipe_elements, nexts)); let span_end = self.position(); self.create_node( AstNode::Pipeline(PipelineId(self.compiler.pipelines.len() - 1)), @@ -918,7 +924,9 @@ impl Parser { let span_end = self.position(); - self.compiler.calls.push(Call::new(parts, has_caret, as_alias)); + self.compiler + .calls + .push(Call::new(parts, has_caret, as_alias)); self.create_node( AstNode::Call(CallId(self.compiler.calls.len() - 1)), span_start, diff --git a/src/resolver.rs b/src/resolver.rs index 878b2f3..d5601b2 100644 --- a/src/resolver.rs +++ b/src/resolver.rs @@ -435,7 +435,10 @@ impl<'a> Resolver<'a> { self.resolve_node(in_ty); self.resolve_node(out_ty); } - AstNode::PipeElement { expr, redirection: _} => { + AstNode::PipeElement { + expr, + redirection: _, + } => { self.resolve_node(expr); } AstNode::Pipeline(pipeline_id) => self.resolve_pipeline(pipeline_id), diff --git a/src/typechecker.rs b/src/typechecker.rs index 8f343cc..334ba0a 100644 --- a/src/typechecker.rs +++ b/src/typechecker.rs @@ -459,9 +459,10 @@ impl<'a> Typechecker<'a> { .last() .map_or(NONE_TYPE, |node_id| self.type_id_of(*node_id)) } - AstNode::PipeElement { expr, redirection: _ } => { - self.typecheck_expr(expr, expected) - } + AstNode::PipeElement { + expr, + redirection: _, + } => self.typecheck_expr(expr, expected), AstNode::Closure { params, block } => { // TODO: input/output types if let Some(params_node_id) = params {