const P = require("parsimmon");
const FileShape = P.regexp(/[^\n\r]+/)
.sepBy(P.newline)
// I think this is easier if you read all the lines at once and then process
// them with an `.assert` call
.assert((lines) => {
console.log(lines);
return lines.every((line) => line.length === 9);
})
.desc("all lines are 9 characters long");
const FileContents = P.regexp(/[a-z-]+/)
// Separate each line
.sepBy(P.newline)
// Remove the "blank" line at the end caused by trailing newlines in files
.trim(P.optWhitespace);
const FileParser = P.lookahead(FileShape).then(FileContents);
FileParser.parse(`\
aaaa-bbbb
cccc-dddd-1111
eeee-ffff
gggg-hhhh
`);
This error message above seems wrong. It should be an error message from `FileContents`, but we appear to be getting an error message from deep within FileShape