Refactor Library And Start Runtime

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
Will Hawkins
2026-01-20 07:10:58 -05:00
parent 45a8baa323
commit 4bec71dcf4
11 changed files with 472 additions and 65 deletions
+43
View File
@@ -0,0 +1,43 @@
import Foundation
import P4
import SwiftTreeSitter
import Testing
import TreeSitter
import TreeSitterP4
@testable import Parser
@Test func test_simple_runtime() async throws {
let simple_parser_declaration = """
parser simple() {
state start {
true;
transition reject;
}
}
"""
let program = try #require(Parser.Program(simple_parser_declaration))
let runtime = P4.ParserRuntime()
#expect(runtime.run(program: program.parsers[0], input: P4.Packet()) == P4.Result.Ok)
}
@Test func test_simple_runtime_no_start_state() async throws {
let simple_parser_declaration = """
parser simple() {
state tart {
true;
transition reject;
}
}
"""
let program = try #require(Parser.Program(simple_parser_declaration))
#expect(
P4.ParserRuntime().run(program: program.parsers[0], input: P4.Packet())
== Result.Error(Error(withMessage: "Could not find the start state")))
}