fix: trace expr
This commit is contained in:
		
							parent
							
								
									2edfd33594
								
							
						
					
					
						commit
						69fdee9f7e
					
				|  | @ -34,13 +34,12 @@ pub fn parser<'a>( | ||||||
|                 .map_with_span(UntypedExpr::fail), |                 .map_with_span(UntypedExpr::fail), | ||||||
|         ))), |         ))), | ||||||
|         just(Token::Trace) |         just(Token::Trace) | ||||||
|             .ignore_then(clause(expression.clone()).or_not().ignored().rewind()) |  | ||||||
|             .ignore_then(choice((string::hybrid(), expression.clone()))) |             .ignore_then(choice((string::hybrid(), expression.clone()))) | ||||||
|             .then(sequence.clone()) |             .then(sequence.clone().or_not()) | ||||||
|             .map_with_span(|(text, then_), span| UntypedExpr::Trace { |             .map_with_span(|(text, then_), span| UntypedExpr::Trace { | ||||||
|                 kind: TraceKind::Trace, |                 kind: TraceKind::Trace, | ||||||
|                 location: span, |                 location: span, | ||||||
|                 then: Box::new(then_), |                 then: Box::new(then_.unwrap_or_else(|| UntypedExpr::todo(None, span))), | ||||||
|                 text: Box::new(text), |                 text: Box::new(text), | ||||||
|             }), |             }), | ||||||
|     )) |     )) | ||||||
|  | @ -86,6 +85,24 @@ mod tests { | ||||||
|         ); |         ); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     #[test] | ||||||
|  |     fn todo_empty() { | ||||||
|  |         assert_expr!( | ||||||
|  |             r#" | ||||||
|  |             todo | ||||||
|  |             "#
 | ||||||
|  |         ); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     #[test] | ||||||
|  |     fn todo_expr() { | ||||||
|  |         assert_expr!( | ||||||
|  |             r#" | ||||||
|  |             todo string.join(["foo", "bar"]) | ||||||
|  |             "#
 | ||||||
|  |         ); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     #[test] |     #[test] | ||||||
|     fn fail_expr() { |     fn fail_expr() { | ||||||
|         assert_expr!( |         assert_expr!( | ||||||
|  | @ -106,6 +123,16 @@ mod tests { | ||||||
| 
 | 
 | ||||||
|     #[test] |     #[test] | ||||||
|     fn trace_expr() { |     fn trace_expr() { | ||||||
|  |         assert_expr!( | ||||||
|  |             r#" | ||||||
|  |             trace string.join(["foo", "bar"]) | ||||||
|  |             a | ||||||
|  |             "#
 | ||||||
|  |         ); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     #[test] | ||||||
|  |     fn trace_expr_todo() { | ||||||
|         assert_expr!( |         assert_expr!( | ||||||
|             r#" |             r#" | ||||||
|             trace some_var 
 |             trace some_var 
 | ||||||
|  | @ -7,7 +7,7 @@ pub mod assignment; | ||||||
| mod block; | mod block; | ||||||
| pub(crate) mod bytearray; | pub(crate) mod bytearray; | ||||||
| mod chained; | mod chained; | ||||||
| mod fail_todo; | mod fail_todo_trace; | ||||||
| mod if_else; | mod if_else; | ||||||
| mod int; | mod int; | ||||||
| mod list; | mod list; | ||||||
|  | @ -23,7 +23,7 @@ pub use anonymous_function::parser as anonymous_function; | ||||||
| pub use block::parser as block; | pub use block::parser as block; | ||||||
| pub use bytearray::parser as bytearray; | pub use bytearray::parser as bytearray; | ||||||
| pub use chained::parser as chained; | pub use chained::parser as chained; | ||||||
| pub use fail_todo::parser as fail_todo; | pub use fail_todo_trace::parser as fail_todo_trace; | ||||||
| pub use if_else::parser as if_else; | pub use if_else::parser as if_else; | ||||||
| pub use int::parser as int; | pub use int::parser as int; | ||||||
| pub use list::parser as list; | pub use list::parser as list; | ||||||
|  | @ -43,7 +43,7 @@ pub fn parser( | ||||||
| ) -> impl Parser<Token, UntypedExpr, Error = ParseError> + '_ { | ) -> impl Parser<Token, UntypedExpr, Error = ParseError> + '_ { | ||||||
|     recursive(|expression| { |     recursive(|expression| { | ||||||
|         choice(( |         choice(( | ||||||
|             fail_todo(expression.clone(), sequence.clone()), |             fail_todo_trace(expression.clone(), sequence.clone()), | ||||||
|             pure_expression(sequence, expression), |             pure_expression(sequence, expression), | ||||||
|         )) |         )) | ||||||
|     }) |     }) | ||||||
|  |  | ||||||
|  | @ -1,34 +1,14 @@ | ||||||
| use chumsky::prelude::*; | use chumsky::prelude::*; | ||||||
| 
 | 
 | ||||||
| use crate::{ | use crate::{ | ||||||
|     ast::TraceKind, |  | ||||||
|     expr::UntypedExpr, |     expr::UntypedExpr, | ||||||
|     parser::{ |     parser::{error::ParseError, token::Token}, | ||||||
|         error::ParseError, |  | ||||||
|         expr::{block::parser as block, string}, |  | ||||||
|         token::Token, |  | ||||||
|     }, |  | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| pub fn parser() -> impl Parser<Token, UntypedExpr, Error = ParseError> { | pub fn parser() -> impl Parser<Token, UntypedExpr, Error = ParseError> { | ||||||
|     recursive(|sequence| { |     recursive(|sequence| { | ||||||
|         choice(( |  | ||||||
|             // just(Token::Trace)
 |  | ||||||
|             //     .ignore_then(choice((
 |  | ||||||
|             //         string::hybrid(),
 |  | ||||||
|             //         block(sequence.clone()),
 |  | ||||||
|             //         sequence.clone(),
 |  | ||||||
|             //     )))
 |  | ||||||
|             //     .then(sequence.clone())
 |  | ||||||
|             //     .map_with_span(|(text, then_), span| UntypedExpr::Trace {
 |  | ||||||
|             //         kind: TraceKind::Trace,
 |  | ||||||
|             //         location: span,
 |  | ||||||
|             //         then: Box::new(then_),
 |  | ||||||
|             //         text: Box::new(text),
 |  | ||||||
|             //     }),
 |  | ||||||
|         super::parser(sequence.clone()) |         super::parser(sequence.clone()) | ||||||
|             .then(sequence.repeated()) |             .then(sequence.repeated()) | ||||||
|                 .foldl(|current, next| current.append_in_sequence(next)), |             .foldl(|current, next| current.append_in_sequence(next)) | ||||||
|         )) |  | ||||||
|     }) |     }) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,12 +1,12 @@ | ||||||
| --- | --- | ||||||
| source: crates/aiken-lang/src/parser/expr/fail_todo.rs | source: crates/aiken-lang/src/parser/expr/fail_todo_trace.rs | ||||||
| description: "Code:\n\nfail @\"foo\"\n" | description: "Code:\n\nfail @\"foo\"\n" | ||||||
| --- | --- | ||||||
| Trace { | Trace { | ||||||
|     kind: Error, |     kind: Error, | ||||||
|     location: 0..11, |     location: 5..11, | ||||||
|     then: ErrorTerm { |     then: ErrorTerm { | ||||||
|         location: 0..11, |         location: 5..11, | ||||||
|     }, |     }, | ||||||
|     text: String { |     text: String { | ||||||
|         location: 5..11, |         location: 5..11, | ||||||
|  |  | ||||||
|  | @ -1,12 +1,12 @@ | ||||||
| --- | --- | ||||||
| source: crates/aiken-lang/src/parser/expr/fail_todo.rs | source: crates/aiken-lang/src/parser/expr/fail_todo_trace.rs | ||||||
| description: "Code:\n\nfail \"foo\"\n" | description: "Code:\n\nfail \"foo\"\n" | ||||||
| --- | --- | ||||||
| Trace { | Trace { | ||||||
|     kind: Error, |     kind: Error, | ||||||
|     location: 0..10, |     location: 5..10, | ||||||
|     then: ErrorTerm { |     then: ErrorTerm { | ||||||
|         location: 0..10, |         location: 5..10, | ||||||
|     }, |     }, | ||||||
|     text: String { |     text: String { | ||||||
|         location: 5..10, |         location: 5..10, | ||||||
|  |  | ||||||
|  | @ -0,0 +1,15 @@ | ||||||
|  | --- | ||||||
|  | source: crates/aiken-lang/src/parser/expr/fail_todo_trace.rs | ||||||
|  | description: "Code:\n\nfail\n" | ||||||
|  | --- | ||||||
|  | Trace { | ||||||
|  |     kind: Error, | ||||||
|  |     location: 1..2, | ||||||
|  |     then: ErrorTerm { | ||||||
|  |         location: 1..2, | ||||||
|  |     }, | ||||||
|  |     text: String { | ||||||
|  |         location: 1..2, | ||||||
|  |         value: "aiken::error", | ||||||
|  |     }, | ||||||
|  | } | ||||||
|  | @ -1,22 +1,14 @@ | ||||||
| --- | --- | ||||||
| source: crates/aiken-lang/src/parser/expr/fail_todo.rs | source: crates/aiken-lang/src/parser/expr/fail_todo_trace.rs | ||||||
| description: "Code:\n\nfail str.join([@\"Some string \", some_params, @\" some string\"], @\"\")\n" | description: "Code:\n\nfail str.join([@\"Some string \", some_params, @\" some string\"], @\"\")\n" | ||||||
| --- | --- | ||||||
| Sequence { |  | ||||||
|     location: 0..67, |  | ||||||
|     expressions: [ |  | ||||||
| Trace { | Trace { | ||||||
|     kind: Error, |     kind: Error, | ||||||
|             location: 0..4, |     location: 5..67, | ||||||
|     then: ErrorTerm { |     then: ErrorTerm { | ||||||
|                 location: 0..4, |         location: 5..67, | ||||||
|     }, |     }, | ||||||
|             text: String { |     text: Call { | ||||||
|                 location: 0..4, |  | ||||||
|                 value: "aiken::error", |  | ||||||
|             }, |  | ||||||
|         }, |  | ||||||
|         Call { |  | ||||||
|         arguments: [ |         arguments: [ | ||||||
|             CallArg { |             CallArg { | ||||||
|                 label: None, |                 label: None, | ||||||
|  | @ -59,5 +51,4 @@ Sequence { | ||||||
|         }, |         }, | ||||||
|         location: 5..67, |         location: 5..67, | ||||||
|     }, |     }, | ||||||
|     ], |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,12 +1,12 @@ | ||||||
| --- | --- | ||||||
| source: crates/aiken-lang/src/parser/expr/error_todo.rs | source: crates/aiken-lang/src/parser/expr/fail_todo_trace.rs | ||||||
| description: "Code:\n\ntodo @\"foo\"\n" | description: "Code:\n\ntodo @\"foo\"\n" | ||||||
| --- | --- | ||||||
| Trace { | Trace { | ||||||
|     kind: Todo, |     kind: Todo, | ||||||
|     location: 0..11, |     location: 5..11, | ||||||
|     then: ErrorTerm { |     then: ErrorTerm { | ||||||
|         location: 0..11, |         location: 5..11, | ||||||
|     }, |     }, | ||||||
|     text: String { |     text: String { | ||||||
|         location: 5..11, |         location: 5..11, | ||||||
|  |  | ||||||
|  | @ -0,0 +1,15 @@ | ||||||
|  | --- | ||||||
|  | source: crates/aiken-lang/src/parser/expr/fail_todo_trace.rs | ||||||
|  | description: "Code:\n\ntodo\n" | ||||||
|  | --- | ||||||
|  | Trace { | ||||||
|  |     kind: Todo, | ||||||
|  |     location: 1..2, | ||||||
|  |     then: ErrorTerm { | ||||||
|  |         location: 1..2, | ||||||
|  |     }, | ||||||
|  |     text: String { | ||||||
|  |         location: 1..2, | ||||||
|  |         value: "aiken::todo", | ||||||
|  |     }, | ||||||
|  | } | ||||||
|  | @ -0,0 +1,52 @@ | ||||||
|  | --- | ||||||
|  | source: crates/aiken-lang/src/parser/expr/fail_todo_trace.rs | ||||||
|  | description: "Code:\n\ntodo string.join([\"foo\", \"bar\"])\n" | ||||||
|  | --- | ||||||
|  | Trace { | ||||||
|  |     kind: Todo, | ||||||
|  |     location: 5..32, | ||||||
|  |     then: ErrorTerm { | ||||||
|  |         location: 5..32, | ||||||
|  |     }, | ||||||
|  |     text: Call { | ||||||
|  |         arguments: [ | ||||||
|  |             CallArg { | ||||||
|  |                 label: None, | ||||||
|  |                 location: 17..31, | ||||||
|  |                 value: List { | ||||||
|  |                     location: 17..31, | ||||||
|  |                     elements: [ | ||||||
|  |                         ByteArray { | ||||||
|  |                             location: 18..23, | ||||||
|  |                             bytes: [ | ||||||
|  |                                 102, | ||||||
|  |                                 111, | ||||||
|  |                                 111, | ||||||
|  |                             ], | ||||||
|  |                             preferred_format: Utf8String, | ||||||
|  |                         }, | ||||||
|  |                         ByteArray { | ||||||
|  |                             location: 25..30, | ||||||
|  |                             bytes: [ | ||||||
|  |                                 98, | ||||||
|  |                                 97, | ||||||
|  |                                 114, | ||||||
|  |                             ], | ||||||
|  |                             preferred_format: Utf8String, | ||||||
|  |                         }, | ||||||
|  |                     ], | ||||||
|  |                     tail: None, | ||||||
|  |                 }, | ||||||
|  |             }, | ||||||
|  |         ], | ||||||
|  |         fun: FieldAccess { | ||||||
|  |             location: 5..16, | ||||||
|  |             label: "join", | ||||||
|  |             container: Var { | ||||||
|  |                 location: 5..11, | ||||||
|  |                 name: "string", | ||||||
|  |             }, | ||||||
|  |         }, | ||||||
|  |         location: 5..32, | ||||||
|  |     }, | ||||||
|  | } | ||||||
|  | @ -1,12 +1,12 @@ | ||||||
| --- | --- | ||||||
| source: crates/aiken-lang/src/parser/expr/error_todo.rs | source: crates/aiken-lang/src/parser/expr/fail_todo_trace.rs | ||||||
| description: "Code:\n\ntodo \"foo\"\n" | description: "Code:\n\ntodo \"foo\"\n" | ||||||
| --- | --- | ||||||
| Trace { | Trace { | ||||||
|     kind: Todo, |     kind: Todo, | ||||||
|     location: 0..10, |     location: 5..10, | ||||||
|     then: ErrorTerm { |     then: ErrorTerm { | ||||||
|         location: 0..10, |         location: 5..10, | ||||||
|     }, |     }, | ||||||
|     text: String { |     text: String { | ||||||
|         location: 5..10, |         location: 5..10, | ||||||
|  |  | ||||||
|  | @ -0,0 +1,53 @@ | ||||||
|  | --- | ||||||
|  | source: crates/aiken-lang/src/parser/expr/fail_todo_trace.rs | ||||||
|  | description: "Code:\n\ntrace string.join([\"foo\", \"bar\"])\na\n" | ||||||
|  | --- | ||||||
|  | Trace { | ||||||
|  |     kind: Trace, | ||||||
|  |     location: 0..35, | ||||||
|  |     then: Var { | ||||||
|  |         location: 34..35, | ||||||
|  |         name: "a", | ||||||
|  |     }, | ||||||
|  |     text: Call { | ||||||
|  |         arguments: [ | ||||||
|  |             CallArg { | ||||||
|  |                 label: None, | ||||||
|  |                 location: 18..32, | ||||||
|  |                 value: List { | ||||||
|  |                     location: 18..32, | ||||||
|  |                     elements: [ | ||||||
|  |                         ByteArray { | ||||||
|  |                             location: 19..24, | ||||||
|  |                             bytes: [ | ||||||
|  |                                 102, | ||||||
|  |                                 111, | ||||||
|  |                                 111, | ||||||
|  |                             ], | ||||||
|  |                             preferred_format: Utf8String, | ||||||
|  |                         }, | ||||||
|  |                         ByteArray { | ||||||
|  |                             location: 26..31, | ||||||
|  |                             bytes: [ | ||||||
|  |                                 98, | ||||||
|  |                                 97, | ||||||
|  |                                 114, | ||||||
|  |                             ], | ||||||
|  |                             preferred_format: Utf8String, | ||||||
|  |                         }, | ||||||
|  |                     ], | ||||||
|  |                     tail: None, | ||||||
|  |                 }, | ||||||
|  |             }, | ||||||
|  |         ], | ||||||
|  |         fun: FieldAccess { | ||||||
|  |             location: 6..17, | ||||||
|  |             label: "join", | ||||||
|  |             container: Var { | ||||||
|  |                 location: 6..12, | ||||||
|  |                 name: "string", | ||||||
|  |             }, | ||||||
|  |         }, | ||||||
|  |         location: 6..33, | ||||||
|  |     }, | ||||||
|  | } | ||||||
|  | @ -0,0 +1,23 @@ | ||||||
|  | --- | ||||||
|  | source: crates/aiken-lang/src/parser/expr/fail_todo_trace.rs | ||||||
|  | description: "Code:\n\ntrace some_var \n" | ||||||
|  | --- | ||||||
|  | Trace { | ||||||
|  |     kind: Trace, | ||||||
|  |     location: 0..14, | ||||||
|  |     then: Trace { | ||||||
|  |         kind: Todo, | ||||||
|  |         location: 0..14, | ||||||
|  |         then: ErrorTerm { | ||||||
|  |             location: 0..14, | ||||||
|  |         }, | ||||||
|  |         text: String { | ||||||
|  |             location: 0..14, | ||||||
|  |             value: "aiken::todo", | ||||||
|  |         }, | ||||||
|  |     }, | ||||||
|  |     text: Var { | ||||||
|  |         location: 6..14, | ||||||
|  |         name: "some_var", | ||||||
|  |     }, | ||||||
|  | } | ||||||
|  | @ -26,12 +26,12 @@ When { | ||||||
|             guard: None, |             guard: None, | ||||||
|             then: Trace { |             then: Trace { | ||||||
|                 kind: Todo, |                 kind: Todo, | ||||||
|                 location: 28..32, |                 location: 35..39, | ||||||
|                 then: ErrorTerm { |                 then: ErrorTerm { | ||||||
|                     location: 28..32, |                     location: 35..39, | ||||||
|                 }, |                 }, | ||||||
|                 text: String { |                 text: String { | ||||||
|                     location: 28..32, |                     location: 35..39, | ||||||
|                     value: "aiken::todo", |                     value: "aiken::todo", | ||||||
|                 }, |                 }, | ||||||
|             }, |             }, | ||||||
|  | @ -53,12 +53,12 @@ When { | ||||||
|             guard: None, |             guard: None, | ||||||
|             then: Trace { |             then: Trace { | ||||||
|                 kind: Todo, |                 kind: Todo, | ||||||
|                 location: 47..51, |                 location: 52..53, | ||||||
|                 then: ErrorTerm { |                 then: ErrorTerm { | ||||||
|                     location: 47..51, |                     location: 52..53, | ||||||
|                 }, |                 }, | ||||||
|                 text: String { |                 text: String { | ||||||
|                     location: 47..51, |                     location: 52..53, | ||||||
|                     value: "aiken::todo", |                     value: "aiken::todo", | ||||||
|                 }, |                 }, | ||||||
|             }, |             }, | ||||||
|  |  | ||||||
|  | @ -26,12 +26,12 @@ When { | ||||||
|             guard: None, |             guard: None, | ||||||
|             then: Trace { |             then: Trace { | ||||||
|                 kind: Error, |                 kind: Error, | ||||||
|                 location: 28..32, |                 location: 33..34, | ||||||
|                 then: ErrorTerm { |                 then: ErrorTerm { | ||||||
|                     location: 28..32, |                     location: 33..34, | ||||||
|                 }, |                 }, | ||||||
|                 text: String { |                 text: String { | ||||||
|                     location: 28..32, |                     location: 33..34, | ||||||
|                     value: "aiken::error", |                     value: "aiken::error", | ||||||
|                 }, |                 }, | ||||||
|             }, |             }, | ||||||
|  |  | ||||||
|  | @ -46,9 +46,9 @@ When { | ||||||
|             guard: None, |             guard: None, | ||||||
|             then: Trace { |             then: Trace { | ||||||
|                 kind: Todo, |                 kind: Todo, | ||||||
|                 location: 47..68, |                 location: 52..68, | ||||||
|                 then: ErrorTerm { |                 then: ErrorTerm { | ||||||
|                     location: 47..68, |                     location: 52..68, | ||||||
|                 }, |                 }, | ||||||
|                 text: String { |                 text: String { | ||||||
|                     location: 52..68, |                     location: 52..68, | ||||||
|  |  | ||||||
|  | @ -0,0 +1,8 @@ | ||||||
|  | --- | ||||||
|  | source: crates/aiken-lang/src/tests/format.rs | ||||||
|  | description: "Code:\n\nfn foo() {\n  fail some_var\n}\n" | ||||||
|  | --- | ||||||
|  | fn foo() { | ||||||
|  |   fail some_var | ||||||
|  | } | ||||||
|  | 
 | ||||||
		Loading…
	
		Reference in New Issue
	
	 rvcas
						rvcas