feat(parser): strip leading stop-words (at, the, a, an) from noun phrase
Allows `look at lamp`, `examine the letter`, `take a key`, `take an oil lamp`. Stop-words are only removed from the head of the noun phrase, not from anywhere in the middle. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -59,6 +59,9 @@ const VERB_ONLY_VERBS = new Set<string>(['look', 'inventory', 'wait'])
|
||||
/** Two-word verb prefixes (e.g. "pick up X"). */
|
||||
const TWO_WORD_VERBS = ['pick up']
|
||||
|
||||
/** Leading stop-words stripped from the noun phrase before matching. */
|
||||
const STOP_WORDS = new Set(['at', 'the', 'a', 'an'])
|
||||
|
||||
function tokenize(input: string): string[] {
|
||||
return input.trim().toLowerCase().split(/\s+/).filter(Boolean)
|
||||
}
|
||||
@@ -126,6 +129,11 @@ export function parse(rawInput: string, ctx: ParserContext): ParsedCommand {
|
||||
return { kind: 'unknown', raw: trimmed, reason: 'unknown-verb' }
|
||||
}
|
||||
|
||||
// Strip leading stop-words from the noun phrase (e.g. "at", "the", "a", "an").
|
||||
while (rest.length > 0 && STOP_WORDS.has(rest[0]!)) {
|
||||
rest = rest.slice(1)
|
||||
}
|
||||
|
||||
if (rest.length === 0) {
|
||||
if (VERB_ONLY_VERBS.has(verb)) {
|
||||
return { kind: 'verb-only', verb: verb as 'look' | 'inventory' | 'wait' }
|
||||
|
||||
Reference in New Issue
Block a user