Type alias Token<PROBLEM>

Token<PROBLEM>: {
    problem: PROBLEM;
    value: string;
}

With the simpler Parser module, you could just say symbol(",") and parse all the commas you wanted. But now that we have a custom type for our problems, we have to specify that as well. So anywhere you just used a string in the simpler module, you now use a Token<Problem> in the advanced module:

Example

 enum Problem {
ExpectingComma,
ExpectingListEnd
}

const comma = Token(",", Problem.ExpectingComma)

const listEnd = Token("]", Problem.ExpectingListEnd)

You can be creative with your custom type. Maybe you want a lot of detail. Maybe you want looser categories. It is a custom type. Do what makes sense for you!

See

Type Parameters

  • PROBLEM

Type declaration

  • problem: PROBLEM
  • value: string