Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,11 @@ parser/

// Evaluator module structure
evaluator/
├── mod.rs // Main evaluation engine
├── tests.rs // Evaluator tests
├── mod.rs // Public interface: EvaluationContext, RuleMatch, re-exports
├── tests.rs // Unit tests for EvaluationContext and RuleMatch
├── engine/ // Core evaluation engine submodule
│ ├── mod.rs // evaluate_single_rule, evaluate_rules, evaluate_rules_with_config
│ └── tests.rs // Engine unit tests
├── types.rs // Type interpretation with endianness
├── strength.rs // Strength modifier application
├── offset/ // Offset resolution submodule
Expand Down
3 changes: 2 additions & 1 deletion docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ libmagic-rs/
│ │ └── grammar.rs # nom-based parsing combinators
│ │
│ ├── evaluator/ # Rule evaluation engine
│ │ ├── mod.rs # Main evaluation logic, EvaluationContext
│ │ ├── mod.rs # Public API surface with re-exports, EvaluationContext, RuleMatch
│ │ ├── engine.rs # Core evaluation logic (evaluate_single_rule, evaluate_rules, evaluate_rules_with_config)
│ │ ├── offset.rs # Offset resolution
│ │ ├── types.rs # Type reading with bounds checking
│ │ ├── operators.rs # Comparison operations
Expand Down
7 changes: 6 additions & 1 deletion docs/src/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ The evaluator executes magic rules against file buffers to identify file types.

**Structure:**

- `mod.rs`: Main evaluation engine with `EvaluationContext` and `RuleMatch`
- `mod.rs`: Public API surface (~720 lines) with `EvaluationContext`, `RuleMatch` types, and re-exports
- `engine/`: Core evaluation engine submodule
- `mod.rs`: `evaluate_single_rule`, `evaluate_rules`, and `evaluate_rules_with_config` functions
- `tests.rs`: Engine unit tests
- `types.rs`: Type interpretation with endianness handling and signedness coercion
- `offset/`: Offset resolution submodule
- `mod.rs`: Dispatcher (`resolve_offset`) and re-exports
Expand All @@ -139,6 +142,8 @@ The evaluator executes magic rules against file buffers to identify file types.
- `comparison.rs`: `compare_values`, `apply_less_than`/`greater_than`/`less_equal`/`greater_equal`
- `bitwise.rs`: `apply_bitwise_and`, `apply_bitwise_and_mask`, `apply_bitwise_xor`, `apply_bitwise_not`

**Organization Note:** The evaluator module was refactored to split a monolithic 2,638-line `mod.rs` into focused submodules, keeping the public API surface in `mod.rs` and moving core evaluation logic to `engine/mod.rs`. This maintains the same public API through re-exports (no breaking changes) while improving code organization and staying within the 500-600 line module guideline.

**Implemented Features:**

- ✅ **Hierarchical Evaluation**: Parent rules must match before children
Expand Down
17 changes: 15 additions & 2 deletions docs/src/evaluator.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,22 @@ File Buffer → Offset Resolution → Type Reading → Operator Application →
Memory Map Context State Endian Handling Match Logic Hierarchical
```

## Module Organization

The evaluator module is organized into focused submodules:

- **`evaluator/engine/mod.rs`** - Core evaluation logic (`evaluate_single_rule`, `evaluate_rules`, `evaluate_rules_with_config`)
- **`evaluator/mod.rs`** - Public API surface (types, context, re-exports)
- **`evaluator/offset/mod.rs`** - Offset resolution
- **`evaluator/operators/mod.rs`** - Operator application
- **`evaluator/types.rs`** - Type reading and coercion
- **`evaluator/strength.rs`** - Rule strength calculation

From a public API perspective, all types and functions are imported from the `evaluator` module as before -- the internal organization is transparent to library users.

## Core Components

### EvaluationContext (`evaluator/mod.rs`)
### EvaluationContext

Maintains state during rule processing:

Expand All @@ -49,7 +62,7 @@ Note: Fields are private; use accessor methods like `current_offset()`, `recursi
- `timeout_ms()` - Query configured timeout
- `reset()` - Reset context state for reuse

### RuleMatch (`evaluator/mod.rs`)
### RuleMatch

Represents a successful rule match:

Expand Down
Loading
Loading