Initial Array Access Implementation

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
Will Hawkins
2026-03-13 09:41:04 -04:00
parent 1982fda677
commit 0b4db34177
10 changed files with 266 additions and 11 deletions
+12 -1
View File
@@ -24,6 +24,10 @@ import TreeSitterP4
public struct Program {
public static func Compile(_ source: String) -> Result<P4Lang.Program> {
return Program.Compile(source, withGlobalTypes: .none)
}
public static func Compile(_ source: String, withGlobalTypes globalTypes: LexicalScopes?) -> Result<P4Lang.Program> {
let maybe_parser = ConfigureP4Parser()
guard case .Ok(let p) = maybe_parser else {
@@ -45,6 +49,11 @@ public struct Program {
var errors: [Error] = Array()
// If the caller gave any global types, add them here.
if let globalTypes = globalTypes {
compilation_context = compilation_context.update(newNames: globalTypes)
}
result?.rootNode?.enumerateNamedChildren { declaration_node in
if declaration_node.nodeType != "declaration" {
return
@@ -185,7 +194,9 @@ public struct Program {
}
// Any of the types that are in the top-level scope should go into the program!
program.types = Array(compilation_context.names)
program.types = Array(compilation_context.names.map() { (_, v) in
v
})
return Result.Ok(program)
}
}