Skip to content

Terminals cannot be constructed from sequences with skip nodes #20

Description

@Theodus

The example below shows a program that expects to construct the Header and Body terminals from sequences containing skipped input. However, the program instead given an error like.

1: >ID_8867
   ^
   expected at least one element

I suspect that the implementation is unable to construct terminals from multiple non-contiguous substrings. This should either be fixed, or an error message should be presented that the grammar is malformed.

use "peg"

actor Main
  new create(env: Env) =>
    let input = ">ID_8867\nGATTACA\nACATTAG\n"
    let src = Source.from_string(input, "text")
    match recover val FastaParser().parse(src) end
    | (_, let ast: AST) =>
      env.out.print(recover Printer(ast) end)
    | (let offset: USize, let r: Parser val) =>
      let e = recover val SyntaxError(src, offset, r) end
      env.out.writev(PegFormatError.console(e))
    else
      env.out.print("wat")
    end

primitive FastaParser
  fun apply(): Parser val =>
    recover
      let id = (R('A', 'z') / L("_") / R('0', '9').many1()).many1()
      let header = (L(">") * id * L("\n")).term(Header)
      let body = ((L("A") / L("T") / L("G") / L("C")).many1() * -L("\n")).many().term(Body)
      let records = (header * body).many1()
      records
    end

primitive Header is Label fun text(): String => "Header"
primitive Body is Label fun text(): String => "Body"

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions