Fork of daniellemaywood.uk/gleam — Wasm codegen work
2

Configure Feed

Select the types of activity you want to include in your feed.

parse echo messages

+763 -17
+26 -17
compiler-core/src/parse.rs
··· 526 526 } 527 527 } 528 528 529 - Some((start, Token::Todo, mut end)) => { 529 + Some((start, Token::Todo, end)) => { 530 530 self.advance(); 531 - let mut message = None; 532 - if self.maybe_one(&Token::As).is_some() { 533 - let msg_expr = self.expect_expression_unit(ExpressionUnitContext::Other)?; 534 - end = msg_expr.location().end; 535 - message = Some(Box::new(msg_expr)); 536 - } 531 + let message = self.maybe_parse_as_message()?; 532 + let end = message.as_ref().map_or(end, |m| m.location().end); 537 533 UntypedExpr::Todo { 538 534 location: SrcSpan { start, end }, 539 535 kind: TodoKind::Keyword, ··· 541 537 } 542 538 } 543 539 544 - Some((start, Token::Panic, mut end)) => { 540 + Some((start, Token::Panic, end)) => { 545 541 self.advance(); 546 - let mut label = None; 547 - if self.maybe_one(&Token::As).is_some() { 548 - let msg_expr = self.expect_expression_unit(ExpressionUnitContext::Other)?; 549 - end = msg_expr.location().end; 550 - label = Some(Box::new(msg_expr)); 551 - } 542 + let message = self.maybe_parse_as_message()?; 543 + let end = message.as_ref().map_or(end, |m| m.location().end); 552 544 UntypedExpr::Panic { 553 545 location: SrcSpan { start, end }, 554 - message: label, 546 + message, 555 547 } 556 548 } 557 549 ··· 560 552 if context == ExpressionUnitContext::FollowingPipe { 561 553 // If an echo is used as a step in a pipeline (`|> echo`) 562 554 // then it cannot be followed by an expression. 555 + let message = self.maybe_parse_as_message()?; 556 + let end = message.as_ref().map_or(end, |m| m.location().end); 563 557 UntypedExpr::Echo { 564 558 location: SrcSpan { start, end }, 565 559 expression: None, 566 - message: todo!(), 560 + message, 567 561 } 568 562 } else { 569 563 // Otherwise it must be followed by an expression. ··· 574 568 // tolerant like everything else. 575 569 let expression = self.parse_expression()?; 576 570 let end = expression.as_ref().map_or(end, |e| e.location().end); 571 + 572 + let message = self.maybe_parse_as_message()?; 573 + let end = message.as_ref().map_or(end, |m| m.location().end); 574 + 577 575 UntypedExpr::Echo { 578 576 location: SrcSpan { start, end }, 579 577 expression: expression.map(Box::new), 580 - message: todo!(), 578 + message, 581 579 } 582 580 } 583 581 } ··· 1032 1030 pattern, 1033 1031 annotation, 1034 1032 })) 1033 + } 1034 + 1035 + fn maybe_parse_as_message(&mut self) -> Result<Option<Box<UntypedExpr>>, ParseError> { 1036 + let message = if self.maybe_one(&Token::As).is_some() { 1037 + let expression = self.expect_expression_unit(ExpressionUnitContext::Other)?; 1038 + Some(Box::new(expression)) 1039 + } else { 1040 + None 1041 + }; 1042 + 1043 + Ok(message) 1035 1044 } 1036 1045 1037 1046 // An assignment, with `Let` already consumed
+59
compiler-core/src/parse/snapshots/gleam_core__parse__tests__echo_with_assert_and_message_1.snap
··· 1 + --- 2 + source: compiler-core/src/parse/tests.rs 3 + expression: assert 1 == echo 2 as this_belongs_to_echo 4 + --- 5 + [ 6 + Assert( 7 + Assert { 8 + location: SrcSpan { 9 + start: 0, 10 + end: 42, 11 + }, 12 + value: BinOp { 13 + location: SrcSpan { 14 + start: 7, 15 + end: 42, 16 + }, 17 + name: Eq, 18 + name_location: SrcSpan { 19 + start: 9, 20 + end: 11, 21 + }, 22 + left: Int { 23 + location: SrcSpan { 24 + start: 7, 25 + end: 8, 26 + }, 27 + value: "1", 28 + int_value: 1, 29 + }, 30 + right: Echo { 31 + location: SrcSpan { 32 + start: 12, 33 + end: 42, 34 + }, 35 + expression: Some( 36 + Int { 37 + location: SrcSpan { 38 + start: 17, 39 + end: 18, 40 + }, 41 + value: "2", 42 + int_value: 2, 43 + }, 44 + ), 45 + message: Some( 46 + Var { 47 + location: SrcSpan { 48 + start: 22, 49 + end: 42, 50 + }, 51 + name: "this_belongs_to_echo", 52 + }, 53 + ), 54 + }, 55 + }, 56 + message: None, 57 + }, 58 + ), 59 + ]
+39
compiler-core/src/parse/snapshots/gleam_core__parse__tests__echo_with_assert_and_message_2.snap
··· 1 + --- 2 + source: compiler-core/src/parse/tests.rs 3 + expression: assert echo True as this_belongs_to_echo 4 + --- 5 + [ 6 + Assert( 7 + Assert { 8 + location: SrcSpan { 9 + start: 0, 10 + end: 40, 11 + }, 12 + value: Echo { 13 + location: SrcSpan { 14 + start: 7, 15 + end: 40, 16 + }, 17 + expression: Some( 18 + Var { 19 + location: SrcSpan { 20 + start: 12, 21 + end: 16, 22 + }, 23 + name: "True", 24 + }, 25 + ), 26 + message: Some( 27 + Var { 28 + location: SrcSpan { 29 + start: 20, 30 + end: 40, 31 + }, 32 + name: "this_belongs_to_echo", 33 + }, 34 + ), 35 + }, 36 + message: None, 37 + }, 38 + ), 39 + ]
+67
compiler-core/src/parse/snapshots/gleam_core__parse__tests__echo_with_assert_and_messages_1.snap
··· 1 + --- 2 + source: compiler-core/src/parse/tests.rs 3 + expression: assert 1 == echo 2 as this_belongs_to_echo as this_belongs_to_assert 4 + --- 5 + [ 6 + Assert( 7 + Assert { 8 + location: SrcSpan { 9 + start: 0, 10 + end: 68, 11 + }, 12 + value: BinOp { 13 + location: SrcSpan { 14 + start: 7, 15 + end: 42, 16 + }, 17 + name: Eq, 18 + name_location: SrcSpan { 19 + start: 9, 20 + end: 11, 21 + }, 22 + left: Int { 23 + location: SrcSpan { 24 + start: 7, 25 + end: 8, 26 + }, 27 + value: "1", 28 + int_value: 1, 29 + }, 30 + right: Echo { 31 + location: SrcSpan { 32 + start: 12, 33 + end: 42, 34 + }, 35 + expression: Some( 36 + Int { 37 + location: SrcSpan { 38 + start: 17, 39 + end: 18, 40 + }, 41 + value: "2", 42 + int_value: 2, 43 + }, 44 + ), 45 + message: Some( 46 + Var { 47 + location: SrcSpan { 48 + start: 22, 49 + end: 42, 50 + }, 51 + name: "this_belongs_to_echo", 52 + }, 53 + ), 54 + }, 55 + }, 56 + message: Some( 57 + Var { 58 + location: SrcSpan { 59 + start: 46, 60 + end: 68, 61 + }, 62 + name: "this_belongs_to_assert", 63 + }, 64 + ), 65 + }, 66 + ), 67 + ]
+47
compiler-core/src/parse/snapshots/gleam_core__parse__tests__echo_with_assert_and_messages_2.snap
··· 1 + --- 2 + source: compiler-core/src/parse/tests.rs 3 + expression: assert echo True as this_belongs_to_echo as this_belongs_to_assert 4 + --- 5 + [ 6 + Assert( 7 + Assert { 8 + location: SrcSpan { 9 + start: 0, 10 + end: 66, 11 + }, 12 + value: Echo { 13 + location: SrcSpan { 14 + start: 7, 15 + end: 40, 16 + }, 17 + expression: Some( 18 + Var { 19 + location: SrcSpan { 20 + start: 12, 21 + end: 16, 22 + }, 23 + name: "True", 24 + }, 25 + ), 26 + message: Some( 27 + Var { 28 + location: SrcSpan { 29 + start: 20, 30 + end: 40, 31 + }, 32 + name: "this_belongs_to_echo", 33 + }, 34 + ), 35 + }, 36 + message: Some( 37 + Var { 38 + location: SrcSpan { 39 + start: 44, 40 + end: 66, 41 + }, 42 + name: "this_belongs_to_assert", 43 + }, 44 + ), 45 + }, 46 + ), 47 + ]
+67
compiler-core/src/parse/snapshots/gleam_core__parse__tests__echo_with_assert_and_messages_3.snap
··· 1 + --- 2 + source: compiler-core/src/parse/tests.rs 3 + expression: assert echo 1 == 2 as this_belongs_to_echo as this_belongs_to_assert 4 + --- 5 + [ 6 + Assert( 7 + Assert { 8 + location: SrcSpan { 9 + start: 0, 10 + end: 68, 11 + }, 12 + value: Echo { 13 + location: SrcSpan { 14 + start: 7, 15 + end: 42, 16 + }, 17 + expression: Some( 18 + BinOp { 19 + location: SrcSpan { 20 + start: 12, 21 + end: 18, 22 + }, 23 + name: Eq, 24 + name_location: SrcSpan { 25 + start: 14, 26 + end: 16, 27 + }, 28 + left: Int { 29 + location: SrcSpan { 30 + start: 12, 31 + end: 13, 32 + }, 33 + value: "1", 34 + int_value: 1, 35 + }, 36 + right: Int { 37 + location: SrcSpan { 38 + start: 17, 39 + end: 18, 40 + }, 41 + value: "2", 42 + int_value: 2, 43 + }, 44 + }, 45 + ), 46 + message: Some( 47 + Var { 48 + location: SrcSpan { 49 + start: 22, 50 + end: 42, 51 + }, 52 + name: "this_belongs_to_echo", 53 + }, 54 + ), 55 + }, 56 + message: Some( 57 + Var { 58 + location: SrcSpan { 59 + start: 46, 60 + end: 68, 61 + }, 62 + name: "this_belongs_to_assert", 63 + }, 64 + ), 65 + }, 66 + ), 67 + ]
+60
compiler-core/src/parse/snapshots/gleam_core__parse__tests__echo_with_complex_expression.snap
··· 1 + --- 2 + source: compiler-core/src/parse/tests.rs 3 + expression: "echo wibble as { this <> complex }" 4 + --- 5 + [ 6 + Expression( 7 + Echo { 8 + location: SrcSpan { 9 + start: 0, 10 + end: 34, 11 + }, 12 + expression: Some( 13 + Var { 14 + location: SrcSpan { 15 + start: 5, 16 + end: 11, 17 + }, 18 + name: "wibble", 19 + }, 20 + ), 21 + message: Some( 22 + Block { 23 + location: SrcSpan { 24 + start: 15, 25 + end: 34, 26 + }, 27 + statements: [ 28 + Expression( 29 + BinOp { 30 + location: SrcSpan { 31 + start: 17, 32 + end: 32, 33 + }, 34 + name: Concatenate, 35 + name_location: SrcSpan { 36 + start: 22, 37 + end: 24, 38 + }, 39 + left: Var { 40 + location: SrcSpan { 41 + start: 17, 42 + end: 21, 43 + }, 44 + name: "this", 45 + }, 46 + right: Var { 47 + location: SrcSpan { 48 + start: 25, 49 + end: 32, 50 + }, 51 + name: "complex", 52 + }, 53 + }, 54 + ), 55 + ], 56 + }, 57 + ), 58 + }, 59 + ), 60 + ]
+60
compiler-core/src/parse/snapshots/gleam_core__parse__tests__echo_with_let_assert_and_message.snap
··· 1 + --- 2 + source: compiler-core/src/parse/tests.rs 3 + expression: let assert 1 = echo 2 as this_belongs_to_echo 4 + --- 5 + [ 6 + Assignment( 7 + Assignment { 8 + location: SrcSpan { 9 + start: 0, 10 + end: 45, 11 + }, 12 + value: Echo { 13 + location: SrcSpan { 14 + start: 15, 15 + end: 45, 16 + }, 17 + expression: Some( 18 + Int { 19 + location: SrcSpan { 20 + start: 20, 21 + end: 21, 22 + }, 23 + value: "2", 24 + int_value: 2, 25 + }, 26 + ), 27 + message: Some( 28 + Var { 29 + location: SrcSpan { 30 + start: 25, 31 + end: 45, 32 + }, 33 + name: "this_belongs_to_echo", 34 + }, 35 + ), 36 + }, 37 + pattern: Int { 38 + location: SrcSpan { 39 + start: 11, 40 + end: 12, 41 + }, 42 + value: "1", 43 + int_value: 1, 44 + }, 45 + kind: Assert { 46 + location: SrcSpan { 47 + start: 0, 48 + end: 10, 49 + }, 50 + assert_keyword_start: 4, 51 + message: None, 52 + }, 53 + compiled_case: CompiledCase { 54 + tree: Fail, 55 + subject_variables: [], 56 + }, 57 + annotation: None, 58 + }, 59 + ), 60 + ]
+68
compiler-core/src/parse/snapshots/gleam_core__parse__tests__echo_with_let_assert_and_messages.snap
··· 1 + --- 2 + source: compiler-core/src/parse/tests.rs 3 + expression: let assert 1 = echo 1 as this_belongs_to_echo as this_belongs_to_assert 4 + --- 5 + [ 6 + Assignment( 7 + Assignment { 8 + location: SrcSpan { 9 + start: 0, 10 + end: 71, 11 + }, 12 + value: Echo { 13 + location: SrcSpan { 14 + start: 15, 15 + end: 45, 16 + }, 17 + expression: Some( 18 + Int { 19 + location: SrcSpan { 20 + start: 20, 21 + end: 21, 22 + }, 23 + value: "1", 24 + int_value: 1, 25 + }, 26 + ), 27 + message: Some( 28 + Var { 29 + location: SrcSpan { 30 + start: 25, 31 + end: 45, 32 + }, 33 + name: "this_belongs_to_echo", 34 + }, 35 + ), 36 + }, 37 + pattern: Int { 38 + location: SrcSpan { 39 + start: 11, 40 + end: 12, 41 + }, 42 + value: "1", 43 + int_value: 1, 44 + }, 45 + kind: Assert { 46 + location: SrcSpan { 47 + start: 0, 48 + end: 10, 49 + }, 50 + assert_keyword_start: 4, 51 + message: Some( 52 + Var { 53 + location: SrcSpan { 54 + start: 49, 55 + end: 71, 56 + }, 57 + name: "this_belongs_to_assert", 58 + }, 59 + ), 60 + }, 61 + compiled_case: CompiledCase { 62 + tree: Fail, 63 + subject_variables: [], 64 + }, 65 + annotation: None, 66 + }, 67 + ), 68 + ]
+24
compiler-core/src/parse/snapshots/gleam_core__parse__tests__echo_with_no_expressions_after_it_but_a_message.snap
··· 1 + --- 2 + source: compiler-core/src/parse/tests.rs 3 + expression: echo as message 4 + --- 5 + [ 6 + Expression( 7 + Echo { 8 + location: SrcSpan { 9 + start: 0, 10 + end: 15, 11 + }, 12 + expression: None, 13 + message: Some( 14 + Var { 15 + location: SrcSpan { 16 + start: 8, 17 + end: 15, 18 + }, 19 + name: "message", 20 + }, 21 + ), 22 + }, 23 + ), 24 + ]
+32
compiler-core/src/parse/snapshots/gleam_core__parse__tests__echo_with_panic_and_message.snap
··· 1 + --- 2 + source: compiler-core/src/parse/tests.rs 3 + expression: "echo panic as \"a\"" 4 + --- 5 + [ 6 + Expression( 7 + Echo { 8 + location: SrcSpan { 9 + start: 0, 10 + end: 17, 11 + }, 12 + expression: Some( 13 + Panic { 14 + location: SrcSpan { 15 + start: 5, 16 + end: 17, 17 + }, 18 + message: Some( 19 + String { 20 + location: SrcSpan { 21 + start: 14, 22 + end: 17, 23 + }, 24 + value: "a", 25 + }, 26 + ), 27 + }, 28 + ), 29 + message: None, 30 + }, 31 + ), 32 + ]
+40
compiler-core/src/parse/snapshots/gleam_core__parse__tests__echo_with_panic_and_messages.snap
··· 1 + --- 2 + source: compiler-core/src/parse/tests.rs 3 + expression: "echo panic as \"a\" as \"b\"" 4 + --- 5 + [ 6 + Expression( 7 + Echo { 8 + location: SrcSpan { 9 + start: 0, 10 + end: 24, 11 + }, 12 + expression: Some( 13 + Panic { 14 + location: SrcSpan { 15 + start: 5, 16 + end: 17, 17 + }, 18 + message: Some( 19 + String { 20 + location: SrcSpan { 21 + start: 14, 22 + end: 17, 23 + }, 24 + value: "a", 25 + }, 26 + ), 27 + }, 28 + ), 29 + message: Some( 30 + String { 31 + location: SrcSpan { 32 + start: 21, 33 + end: 24, 34 + }, 35 + value: "b", 36 + }, 37 + ), 38 + }, 39 + ), 40 + ]
+32
compiler-core/src/parse/snapshots/gleam_core__parse__tests__echo_with_simple_expression_1.snap
··· 1 + --- 2 + source: compiler-core/src/parse/tests.rs 3 + expression: echo wibble as message 4 + --- 5 + [ 6 + Expression( 7 + Echo { 8 + location: SrcSpan { 9 + start: 0, 10 + end: 22, 11 + }, 12 + expression: Some( 13 + Var { 14 + location: SrcSpan { 15 + start: 5, 16 + end: 11, 17 + }, 18 + name: "wibble", 19 + }, 20 + ), 21 + message: Some( 22 + Var { 23 + location: SrcSpan { 24 + start: 15, 25 + end: 22, 26 + }, 27 + name: "message", 28 + }, 29 + ), 30 + }, 31 + ), 32 + ]
+32
compiler-core/src/parse/snapshots/gleam_core__parse__tests__echo_with_simple_expression_2.snap
··· 1 + --- 2 + source: compiler-core/src/parse/tests.rs 3 + expression: "echo wibble as \"message\"" 4 + --- 5 + [ 6 + Expression( 7 + Echo { 8 + location: SrcSpan { 9 + start: 0, 10 + end: 24, 11 + }, 12 + expression: Some( 13 + Var { 14 + location: SrcSpan { 15 + start: 5, 16 + end: 11, 17 + }, 18 + name: "wibble", 19 + }, 20 + ), 21 + message: Some( 22 + String { 23 + location: SrcSpan { 24 + start: 15, 25 + end: 24, 26 + }, 27 + value: "message", 28 + }, 29 + ), 30 + }, 31 + ), 32 + ]
+40
compiler-core/src/parse/snapshots/gleam_core__parse__tests__panic_with_echo_and_message.snap
··· 1 + --- 2 + source: compiler-core/src/parse/tests.rs 3 + expression: panic as echo wibble as message 4 + --- 5 + [ 6 + Expression( 7 + Panic { 8 + location: SrcSpan { 9 + start: 0, 10 + end: 31, 11 + }, 12 + message: Some( 13 + Echo { 14 + location: SrcSpan { 15 + start: 9, 16 + end: 31, 17 + }, 18 + expression: Some( 19 + Var { 20 + location: SrcSpan { 21 + start: 14, 22 + end: 20, 23 + }, 24 + name: "wibble", 25 + }, 26 + ), 27 + message: Some( 28 + Var { 29 + location: SrcSpan { 30 + start: 24, 31 + end: 31, 32 + }, 33 + name: "message", 34 + }, 35 + ), 36 + }, 37 + ), 38 + }, 39 + ), 40 + ]
+70
compiler-core/src/parse/tests.rs
··· 474 474 } 475 475 476 476 #[test] 477 + fn echo_with_simple_expression_1() { 478 + assert_parse!("echo wibble as message"); 479 + } 480 + 481 + #[test] 482 + fn echo_with_simple_expression_2() { 483 + assert_parse!("echo wibble as \"message\""); 484 + } 485 + 486 + #[test] 487 + fn echo_with_complex_expression() { 488 + assert_parse!("echo wibble as { this <> complex }"); 489 + } 490 + 491 + #[test] 477 492 fn echo_with_no_expressions_after_it() { 478 493 assert_parse!("echo"); 479 494 } 480 495 481 496 #[test] 497 + fn echo_with_no_expressions_after_it_but_a_message() { 498 + assert_parse!("echo as message"); 499 + } 500 + 501 + #[test] 482 502 fn echo_with_block() { 483 503 assert_parse!("echo { 1 + 1 }"); 484 504 } ··· 510 530 } 511 531 512 532 #[test] 533 + fn panic_with_echo_and_message() { 534 + assert_parse!("panic as echo wibble as message"); 535 + } 536 + 537 + #[test] 513 538 fn echo_with_panic() { 514 539 assert_parse!("echo panic as \"a\""); 540 + } 541 + 542 + #[test] 543 + fn echo_with_panic_and_message() { 544 + assert_parse!("echo panic as \"a\""); 545 + } 546 + 547 + #[test] 548 + fn echo_with_panic_and_messages() { 549 + assert_parse!("echo panic as \"a\" as \"b\""); 550 + } 551 + 552 + #[test] 553 + fn echo_with_assert_and_message_1() { 554 + assert_parse!("assert 1 == echo 2 as this_belongs_to_echo"); 555 + } 556 + 557 + #[test] 558 + fn echo_with_assert_and_message_2() { 559 + assert_parse!("assert echo True as this_belongs_to_echo"); 560 + } 561 + 562 + #[test] 563 + fn echo_with_assert_and_messages_1() { 564 + assert_parse!("assert 1 == echo 2 as this_belongs_to_echo as this_belongs_to_assert"); 565 + } 566 + 567 + #[test] 568 + fn echo_with_assert_and_messages_2() { 569 + assert_parse!("assert echo True as this_belongs_to_echo as this_belongs_to_assert"); 570 + } 571 + 572 + #[test] 573 + fn echo_with_assert_and_messages_3() { 574 + assert_parse!("assert echo 1 == 2 as this_belongs_to_echo as this_belongs_to_assert"); 575 + } 576 + 577 + #[test] 578 + fn echo_with_let_assert_and_message() { 579 + assert_parse!("let assert 1 = echo 2 as this_belongs_to_echo"); 580 + } 581 + 582 + #[test] 583 + fn echo_with_let_assert_and_messages() { 584 + assert_parse!("let assert 1 = echo 1 as this_belongs_to_echo as this_belongs_to_assert"); 515 585 } 516 586 517 587 #[test]