|
Libecoli 0.11.1
Extensible COmmand LIne library
|
Libecoli is an Extensible COmmand LIne library written in C that provides a modular, composable framework for building interactive command line interfaces with dynamic completion, contextual help, and parsing capabilities.
Project page: https://github.com/rjarry/libecoli
A grammar is built by composing Grammar nodes into a directed graph. Each node type matches specific input patterns:
The Parse nodes API validates input against a grammar and produces a parse tree. Each node in the tree references the grammar node that matched it and the tokens it consumed. Use ec_pnode_find() to locate specific nodes by their identifier and extract matched values.
The Complete API generates completion suggestions for partial input. Completions are grouped by the grammar node that produced them and can be filtered by type (full match, partial match, or unknown).
The Editline API provides a complete interactive command line with:
See the Examples page for complete working examples demonstrating grammar construction, completion, readline integration, custom node types, and dynamic completion from runtime data.
| Node Type | Description |
|---|---|
| String node | Matches a specific literal string |
| Integer node | Matches signed integers with range/base constraints |
| Regex node | Matches input against a POSIX extended regex |
| File node | Matches and completes filesystem paths |
| Any node | Matches any single token |
| Empty node | Matches zero tokens (always succeeds) |
| None node | Matches nothing (always fails) |
| Space node | Matches whitespace |
| Node Type | Description |
|---|---|
| Sequence node | Matches children in strict order |
| Or node | Matches any one of its children |
| Many node | Matches a child repeatedly (with min/max) |
| Option node | Makes a child optional |
| Subset node | Matches any subset of children in any order |
| Node Type | Description |
|---|---|
| Command node | Parses commands using a format string syntax |
| Expression node | Parses expressions with operators and precedence |
| Dynamic node | Builds grammar dynamically at parse time |
| Dynamic list node | Matches names from a runtime-generated list |
| Condition node | Conditionally matches based on an expression |
| Once node | Prevents a child from matching more than once |
| Bypass node | Pass-through node for building graph loops |
| Node Type | Description |
|---|---|
| Shell lexer node | Shell-like tokenization with quotes and escapes |
| Regex lexer node | Regex-based tokenization |
Libecoli powers the CLI of several production systems including the grout graph router and 6WIND's Virtual Service Router. These projects demonstrate patterns such as: