findAmbiguities (not tested yet)

This commit is contained in:
Chipmunk 2022-12-01 16:12:23 -05:00
parent 0bc661110e
commit 428dcabe2f

View file

@ -33,7 +33,28 @@ class CommandNode {
}
}
// findAmbiguities (consumer) {}
findAmbiguities (consumer) {
const matches = new Set()
for (const child of Object.values(this.children)) {
for (const sibling of Object.values(this.children)) {
if (child === sibling) continue
for (const input of child.getExamples()) {
if (sibling.isValidInput(input)) {
matches.add(input)
}
}
if (matches.size > 0) {
consumer.ambiguous(this, child, sibling, matches)
matches = new Set()
}
}
child.findAmbiguities(consumer)
}
}
equals (that) {
if (this === that) return true