you may have noticed that the PREVIOUS language had very bad error MESSAGES. no one wants to see a REGULAR EXPRESSION in their error message. it's garbage. we need to give our number term a name.
this language bites off a number but it has a name when it appears in an error message.
TRANSLATED:
it's easy. make a new term called "with". it creates a new term based on a term you provide, and it OVERRIDES it with new methods.
class WithTerm {
constructor(term, overrides) {
const withTerm = Object.create(term)
Object.assign(withTerm, overrides)
return withTerm
}
}
then use it.
const numberTerm = new WithTerm(new RegExpTerm(/\d+/), {
name() {
return "number"
}
})
then use it.
function translate(text) {
return numberTerm.translate(text)
}
back to the dream