@motioneffector/parser
v1.0.0
Published
Text adventure command parser for natural language game input
Maintainers
Readme
@motioneffector/parser
A natural language command parser for text adventures and interactive fiction.
Features
- Natural Language Parsing - Understands common text adventure commands
- Default Vocabulary - Ships with 30+ verbs and directions
- Custom Vocabulary - Extend or replace with game-specific commands
- Smart Resolution - Pluggable resolver connects to your game state
- Disambiguation - Handles multiple matching objects gracefully
- Pronoun Tracking - Automatic "it" reference management
- Partial Matching - "exa lamp" matches "examine lamp"
- Position Tracking - Token positions for error reporting
Quick Start
import { createParser } from '@motioneffector/parser'
// Create parser with entity resolver
const parser = createParser({
resolver: (noun, adjectives, scope) => {
// Look up entities from your game state
return [{ id: 'lamp-1', name: 'brass lamp' }]
}
})
// Parse player input
const result = parser.parse('get lamp')
if (result.type === 'command') {
console.log(`Verb: ${result.command.verb}`) // "GET"
console.log(`Subject: ${result.command.subject?.id}`) // "lamp-1"
}Testing & Validation
- Comprehensive test suite - 371 unit tests covering core functionality
- Fuzz tested - Randomized input testing to catch edge cases
- Strict TypeScript - Full type coverage with no
anytypes - Zero dependencies - No supply chain risk
License
MIT © motioneffector
