| 51 | } |
| 52 | |
| 53 | pub(crate) macro bind_parser($format:ident; fn $name:ident($parser:ident)) { |
| 54 | // this could also be a function, but then you run into issues with lifetimes, so this is easier |
| 55 | fn $name(source: &str) -> (String, Info) { |
| 56 | let heap = Heap::new(); |
| 57 | let mut spans = SpanTable::new(SourceId::new_unchecked(0x00)); |
| 58 | let parent = spans.insert(Span { |
| 59 | range: TextRange::up_to(TextSize::of(source)), |
| 60 | pointer: None, |
| 61 | }, SpanAncestors::EMPTY); |
| 62 | |
| 63 | let context = Context { |
| 64 | heap: &heap, |
| 65 | spans: &mut spans, |
| 66 | parent, |
| 67 | }; |
| 68 | |
| 69 | let input = Stateful { |
| 70 | input: LocatingSlice::new(source), |
| 71 | state: context, |
| 72 | }; |
| 73 | |
| 74 | let result = $parser::<ContextError>.parse(input); |
| 75 | match result { |
| 76 | Ok(ident) => ( |
| 77 | format_result!($format; ident), |
| 78 | Info { |
| 79 | kind: ResultKind::Ok, |
| 80 | }, |
| 81 | ), |
| 82 | Err(error) => ( |
| 83 | error.to_string(), |
| 84 | Info { |
| 85 | kind: ResultKind::Err, |
| 86 | }, |
| 87 | ), |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | pub(crate) macro assert_parse($parser:ident, $source:expr, $description:literal) {{ |
| 93 | let (result, info) = $parser($source); |