topmark.pipeline.steps.scanner ¶
Scanner for detecting and extracting structured TopMark headers from source files.
This module is part of the TopMark pipeline steps and provides logic to detect and extract structured header blocks from a file's contents. It interacts with a registered HeaderProcessor to locate the presence and boundaries of a header block in a file and to parse the fields defined within that header.
The scanner itself is file format agnostic and relies on the HeaderProcessor to handle
format-specific parsing. It operates on a ProcessingContext that already exposes the file
image via ctx.views.image (see FileImageView). The scanner updates the context with a
topmark.pipeline.views.HeaderView that contains the header range, extracted lines,
a reconstructed header block, and parsed key-value fields.
ScannerStep ¶
Bases: BaseStep
Detect and parse TopMark headers from the file image.
Uses the active HeaderProcessor to locate header bounds and parse fields into
a HeaderView. Leaves unrelated axes untouched.
Preconditions
- The context is not halted.
ctx.views.imageis available (set by ReaderStep).ctx.header_processoris set.- ReaderStep set
ContentStatus.OK.
Axes written
- header
Sets
- HeaderStatus: {PENDING, MISSING, EMPTY, DETECTED, MALFORMED, MALFORMED_SOME_FIELDS, MALFORMED_ALL_FIELDS}
Source code in src/topmark/pipeline/steps/scanner.py
may_proceed ¶
Determine if processing can proceed to the scan step.
Processing can proceed if all of the following apply:
- A header processor is available (ctx.header_processor is not None), meaning:
- The file was successfully resolved (ctx.status.resolve is RESOLVED)
- The file type was resolved (ctx.file_type is not None)
- The file type is registered to a header processor
- ReaderStep set ContentStatus.OK
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
ProcessingContext
|
The processing context for the current file. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if processing can proceed to the scanner step, False otherwise. |
Source code in src/topmark/pipeline/steps/scanner.py
run ¶
Detect and extract a TopMark header from the file image.
Behavior with discriminated HeaderBounds:
- NONE → mark HeaderStatus.MISSING and return.
- MALFORMED → build a minimal HeaderView (when possible), set
HeaderStatus.MALFORMED, attach a diagnostic hint, and stop flow.
- SPAN → slice the span, build HeaderView, parse fields, and set
one of {DETECTED, EMPTY, MALFORMED_SOME_FIELDS, MALFORMED_ALL_FIELDS}.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
ProcessingContext
|
Processing context with the file image and a header processor. |
required |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the header processor is not defined, or if the exclusive start and end indexes are undefined or invalid. |
Mutations
ProcessingContext: The same context updated with:
- ctx.views.header: a HeaderView containing range/lines/block/mapping
- ctx.status.header: one of {MISSING, EMPTY, DETECTED, MALFORMED,
MALFORMED_SOME_FIELDS, MALFORMED_ALL_FIELDS}
Source code in src/topmark/pipeline/steps/scanner.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | |
hint ¶
Attach header detection hints (non-binding).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
ProcessingContext
|
The processing context. |
required |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the context contains an unexpected header status value. |