let's give our terms names. it can be a static string this time.
/**
* @typedef {object} Term
* ...
* @property {string} name
*/
terms are ANONYMOUS by default.
Term.Default = {
//...
name: "anonymous term"
}
string terms are named after their string.
Term.string = (string) => ({
//...
name: `"${string}"`
})
we can update the default translate method to use the name in error MESSAGES.
Term.Default = {
//...
translate(text) {
const bites = this.bite(text)
if (bites.length === 0) {
throw new Error(`Expected ${this.name} but found '${text}'!`)
}
return bites.join("")
}
})
here it is in action.
back to the dream