Skip to content

TapeParser

Namespace: Hex1b.Automation

Assembly: Hex1b.dll

Parses VHS v0.11.0 Tape syntax into an editable document without executing instructions.

csharp
public sealed class TapeParser

Inheritance

ObjectTapeParser

Constructors

TapeParser(TapeParserOptions?)

Creates a parser and snapshots its syntax-extension registrations.

Parameters:

csharp
public TapeParser(TapeParserOptions? options = null)

Methods

Parse(string, string?)

Parses Tape content without opening files or executing instructions.

Parameters:

  • text (String): The Tape content, never a filename.
  • sourceName (String): An optional source label for diagnostics.

Returns: TapeDocument

The parsed document.

csharp
public TapeDocument Parse(string text, string? sourceName = null)

ParseAsync(FileInfo, CancellationToken)

Opens, reads, and closes a UTF-8 Tape file, using its full path as the source label.

Parameters:

Returns: Task<TapeDocument>

The parsed document.

csharp
public Task<TapeDocument> ParseAsync(FileInfo file, CancellationToken cancellationToken = default)

ParseAsync(Stream, string?, CancellationToken)

Reads UTF-8 Tape content from the current stream position through EOF, leaving the stream open.

Parameters:

  • stream (Stream): The readable stream, which need not support seeking.
  • sourceName (String): An optional source label.
  • cancellationToken (CancellationToken): The cancellation token.

Returns: Task<TapeDocument>

The parsed document.

csharp
public Task<TapeDocument> ParseAsync(Stream stream, string? sourceName = null, CancellationToken cancellationToken = default)

ParseAsync(TextReader, string?, CancellationToken)

Reads Tape content through EOF, leaving the reader open even on failure or cancellation.

Parameters:

Returns: Task<TapeDocument>

The parsed document.

csharp
public Task<TapeDocument> ParseAsync(TextReader reader, string? sourceName = null, CancellationToken cancellationToken = default)

TryParse(string, out TapeDocument?, out IReadOnlyList<TapeDiagnostic>, string?)

Attempts to parse Tape content and returns all reported diagnostics.

Parameters:

Returns: Boolean

True when no error diagnostics were reported.

csharp
public bool TryParse(string text, out TapeDocument? document, out IReadOnlyList<TapeDiagnostic> diagnostics, string? sourceName = null)

TryParse(string, out TapeDocument?, string?)

Attempts to parse Tape content.

Parameters:

  • text (String): The Tape content.
  • document (TapeDocument): The document on success, or null on syntax failure.
  • sourceName (String): An optional source label.

Returns: Boolean

True when parsing succeeds.

csharp
public bool TryParse(string text, out TapeDocument? document, string? sourceName = null)

Remarks

Syntax follows upstream c073383b5de0b1f57bf514113029c306bc986539. Source instructions remain AST nodes; only the explicit FileInfo overload opens a source file. Numeric conversion, output support, executable lookup, and source expansion are execution concerns. UTF-8 byte-order marks are preserved as source characters and rejected by the pinned grammar.

Examples

csharp
using Hex1b.Automation;

var parser = new TapeParser();
var document = parser.Parse("Type 'hello' Enter Sleep 500ms", "example");
foreach (var command in document.Commands)
    Console.WriteLine(command);

Released under the MIT License.