i3config_v2 library
i3config — PetitParser implementation with source position tracking
This library provides a robust parser and processor for i3/Sway configuration files using the PetitParser framework.
Usage
import 'package:i3config/i3config.dart';
// Parse with automatic position tracking
final config = Config.parse(configContent);
// Access source position information
for (final statement in config.statements) {
if (statement.span != null) {
print('Statement at line ${statement.span!.start.line + 1}');
print('Source: "${statement.span!.text}"');
}
}
// Use the state machine processor
final processor = ConfigProcessor();
await processor.process(config);
Features
- Source Position Tracking: Every parsed element includes optional
SourceSpaninformation showing its exact location in source - Enhanced Error Reporting: Detailed error messages with suggestions
- Type-Safe AST: Sealed classes for better pattern matching
- Visitor Pattern: Built-in visitor support for AST traversal
- Extensible Handlers: Plugin architecture for custom processing
- State Machine: Advanced processing pipeline with configurable states
- Variable Expansion: Dynamic variable resolution with scoping
- String Interpolation: Double-quoted strings support
$variablereferences
Classes
- ArrayValue
-
Array value:
["a", "b", "c"] - Assignment
-
Assignment statement:
variable = valueorvariable += value - AssignmentProcessingState
- State for processing assignments.
- BareArg
- Bare argument (unquoted value)
- BaseBlockHandler
- Base class for block handlers with built-in child processing.
-
BaseCommandHandler<
T> - Base class for command handlers with built-in value expansion.
- Block
-
Block statement:
{ ... }with optional type and identifier - BlockHandler
- Handler for specific block types.
- BlockHandlerRegistry
-
Registry interface for registering commands and sub-block handlers
within a block handler's
registerScopedCommandsmethod. - BlockProcessingState
- State for processing blocks.
- BlockReference
-
Dotted-path block reference, e.g.
bar.main.position. - Command
- Generic command statement
- CommandHandler
- Handler for specific command types.
- CommandProcessingState
- State for processing commands.
- Comment
- Comment element
- Config
- Root configuration container.
- ConfigElement
- Base class for all configuration elements.
- ConfigFormatter
- Formats an i3 config AST back to formatted config text.
- ConfigProcessor
- Main configuration processor that orchestrates the state machine.
-
ConfigVisitor<
T> - Base visitor interface for processing configuration elements.
- Context
- Context object that holds processing state and configuration.
- Criterion
-
Criterion for criteria blocks:
key=value - ErrorHandler
- Error handler for processing errors.
- FileSystem
- Abstract filesystem for reading configuration files.
- FormatterOptions
- Options for configuring the ConfigFormatter.
- I3Config
- InitialState
- Initial processing state.
- InterpolatedString
-
Double-quoted string with variable interpolation, e.g.
"base/$dir/config". - KeyPart
- Key part for bindings (symbolic or code)
- ParseFailure
- Failed parse result.
- Parser
- Main parser class for i3/Sway configuration files.
- ParseResult
- Result of a parsing operation.
- ParseSuccess
- Successful parse result.
- PhysicalFileSystem
-
Default FileSystem implementation backed by
dart:io. - ProcessorState
- Base state for the configuration processor.
- Quoted
- Quoted string value
- SetCommandHandler
- Built-in handler for 'set' commands (global variable assignment).
- Statement
- Base class for all statements.
- Value
- Base class for all values
- ValueSegment
- Segment inside an interpolated string.
- ValueSegmentLiteral
- Literal text segment inside an InterpolatedString.
- ValueSegmentVariableReference
- Variable reference segment inside an InterpolatedString.
- VariableRef
-
Variable reference:
$variable - VirtualFileSystem
- Virtual filesystem for testing imports.
Enums
- AssignmentOperator
- Assignment operators for i3 config variables
Mixins
- DefaultChildProcessing
- Provides default automatic child processing. Mix this in for standard sequential processing (most common case).
- ValueExpander
- Mixin that provides value expansion utility for handlers.
Extensions
- CommandValueExtraction on Command
- Extension on Command for ergonomic value extraction.
- ManualProcessing on ConfigProcessor
- Extension to provide manual element processing for custom block handlers.
Properties
- vfs → VirtualFileSystem
-
Global test virtual filesystem instance.
final
Functions
-
buildBlockHierarchy(
Config config) → void - Build block hierarchy by establishing parent-child relationships.
Exceptions / Errors
- ParseError
- Parse error with location information