Explorer

definy.text-expect

description
Skip spaces and read text exactly
type
Fn(source: Record{text: String, bytes: List<Number>}, index: Number, text: String) -> Union{#ok(Record{value: String, next: Number}), #error(String)}
expression
fn(source$0, index$1, text$2) =>
  let start$3 = @definy.text-skip(source: $0, index: $1);
  let end$4 = @core.plus(left: $3, right: @core.string-length(value: $2));
  match @core.equal(
      left: @core.string-slice(value: $0.text, start: $3, end: @std.min(a: $4, b: @core.string-length(value: $0.text))),
      right: $2
    ) {
    true =>
      #ok({value: $2, next: $4}),
    false =>
      #error(@definy.text-error(message: @std.string-join(items: ["expected '", $2, "'"], separator: ""), index: $3))
  }
visibility
public
definy.text-expect (project definy, branch main, snapshot l0VFjJZP174d8CbZWFoujAGTYjgsQu4uTq5uWCZaXgo)
id: Zv5Urvt11b6tjDuOaCVjl92jwA5qTODiHHBukRlMHGg
content hash: iTDT6G06Y4KCE8a6-xjIo-5BwVvZthqC6y97joZdNGI