two

we need to bite more than one term at a time.

this language bites off "pasta" and then "gang".

TRANSLATED:



to do this, we make a term for biting "two" terms. it takes those terms as ARGUMENTS.

class TwoTerm extends Term {
	constructor(term1, term2) {
		super()
		this.term1 = term1
		this.term2 = term2
	}
}

we give it a name.

class TwoTerm extends Term {
	//...
	name() {
		return `${this.term1.name()} then ${this.term2.name()}`
	}
}

we bite off the first term. if that works, we bite off the second term from the remaining tail.

class TwoTerm extends Term {
	//...
	bite(text) {
		const [bite1, tail1] = this.term1.eat(text)
		if (bite1 === null) {
			return null
		}
		
		const bite2 = this.term2.bite(tail1)
		if (bite2 === null) {
			return null
		}
		return bite1 + bite2
	}
}

that's it!

back to the dream