compiler: Refactor Language Element Tags
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
@@ -21,10 +21,10 @@ import TreeSitterExtensions
|
||||
import TreeSitterP4
|
||||
|
||||
extension CST.Declaration: Parsable {
|
||||
public typealias C = CST.AnDeclaration
|
||||
public typealias C = CST.Categories.Declaration
|
||||
public static func Parse(
|
||||
node: Node, withContext context: CSTCompilerContext
|
||||
) -> Result<CST.AnDeclaration> {
|
||||
) -> Result<CST.Categories.Declaration> {
|
||||
|
||||
// Be kind to our user -- if we are at a declaration node, dive into it!
|
||||
let declaration_node =
|
||||
@@ -34,7 +34,7 @@ extension CST.Declaration: Parsable {
|
||||
node
|
||||
}
|
||||
|
||||
let declaration_compilers: [String: any Parsable<CST.AnDeclaration>.Type] = [
|
||||
let declaration_compilers: [String: any Parsable<CST.Categories.Declaration>.Type] = [
|
||||
"function_declaration": CST.FunctionDeclaration.self,
|
||||
"control_declaration": CST.Control.self,
|
||||
//"type_declaration": AST.P4Struct.self,
|
||||
@@ -61,12 +61,12 @@ extension CST.Declaration: Parsable {
|
||||
extension CST.Declaration: ParsableStatement {}
|
||||
|
||||
extension CST.FunctionDeclaration: Parsable {
|
||||
public typealias C = CST.AnDeclaration
|
||||
public typealias C = CST.Categories.Declaration
|
||||
public static func Parse(
|
||||
node: SwiftTreeSitter.Node, withContext context: CSTCompilerContext
|
||||
) -> Common.Result<CST.AnDeclaration> {
|
||||
) -> Common.Result<CST.Categories.Declaration> {
|
||||
let function_declaration_node = node
|
||||
#RequireNodeType<Node, CST.AnDeclaration>(
|
||||
#RequireNodeType<Node, CST.Categories.Declaration>(
|
||||
node: function_declaration_node, type: "function_declaration",
|
||||
nice_type_name: "Function Declaration")
|
||||
|
||||
@@ -75,7 +75,7 @@ extension CST.FunctionDeclaration: Parsable {
|
||||
|
||||
#MustOr(
|
||||
result: current_node, thing: walker.getNext(),
|
||||
or: Result<CST.AnDeclaration>.Error(
|
||||
or: Result<CST.Categories.Declaration>.Error(
|
||||
ErrorWithLocation(
|
||||
sourceLocation: function_declaration_node.toSourceLocation(),
|
||||
withError: "Missing function declaration component")))
|
||||
@@ -88,7 +88,7 @@ extension CST.FunctionDeclaration: Parsable {
|
||||
walker.next()
|
||||
#MustOr(
|
||||
result: current_node, thing: walker.getNext(),
|
||||
or: Result<CST.AnDeclaration>.Error(
|
||||
or: Result<CST.Categories.Declaration>.Error(
|
||||
ErrorWithLocation(
|
||||
sourceLocation: function_declaration_node.toSourceLocation(),
|
||||
withError: "Missing function declaration component")))
|
||||
@@ -102,7 +102,7 @@ extension CST.FunctionDeclaration: Parsable {
|
||||
walker.next()
|
||||
#MustOr(
|
||||
result: current_node, thing: walker.getNext(),
|
||||
or: Result<CST.AnDeclaration>.Error(
|
||||
or: Result<CST.Categories.Declaration>.Error(
|
||||
ErrorWithLocation(
|
||||
sourceLocation: function_declaration_node.toSourceLocation(),
|
||||
withError: "Missing function declaration component")))
|
||||
@@ -227,19 +227,19 @@ extension CST.StructDeclaration: Parsable {
|
||||
}
|
||||
|
||||
extension CST.Parser: Parsable {
|
||||
public typealias C = CST.AnDeclaration
|
||||
public typealias C = CST.Categories.Declaration
|
||||
public static func Parse(
|
||||
node: Node, withContext context: CSTCompilerContext
|
||||
) -> Result<CST.AnDeclaration> {
|
||||
) -> Result<CST.Categories.Declaration> {
|
||||
let parser_node = node
|
||||
#RequireNodeType<Node, Result<CST.AnDeclaration>>(
|
||||
#RequireNodeType<Node, Result<CST.Categories.Declaration>>(
|
||||
node: parser_node, type: "parserDeclaration", nice_type_name: "parser declaration")
|
||||
var walker = Walker(node: parser_node)
|
||||
var current_node: Node? = .none
|
||||
|
||||
#MustOr(
|
||||
result: current_node, thing: walker.getNext(),
|
||||
or: Result<CST.AnDeclaration>.Error(
|
||||
or: Result<CST.Categories.Declaration>.Error(
|
||||
ErrorWithLocation(
|
||||
sourceLocation: parser_node.toSourceLocation(),
|
||||
withError: "Missing elements of parser declaration")))
|
||||
@@ -263,7 +263,7 @@ extension CST.Parser: Parsable {
|
||||
|
||||
#MustOr(
|
||||
result: type_node_child, thing: type_node_walker.getNext(),
|
||||
or: Result<CST.AnDeclaration>.Error(
|
||||
or: Result<CST.Categories.Declaration>.Error(
|
||||
ErrorWithLocation(
|
||||
sourceLocation: parser_node.toSourceLocation(),
|
||||
withError: "Missing elements of parser type in parser declaration")))
|
||||
@@ -279,7 +279,7 @@ extension CST.Parser: Parsable {
|
||||
type_node_walker.next()
|
||||
#MustOr(
|
||||
result: type_node_child, thing: type_node_walker.getNext(),
|
||||
or: Result<CST.AnDeclaration>.Error(
|
||||
or: Result<CST.Categories.Declaration>.Error(
|
||||
ErrorWithLocation(
|
||||
sourceLocation: type_node_child!.toSourceLocation(),
|
||||
withError: "Missing name in parser type declaration")))
|
||||
@@ -293,7 +293,7 @@ extension CST.Parser: Parsable {
|
||||
type_node_walker.next()
|
||||
#MustOr(
|
||||
result: type_node_child, thing: type_node_walker.getNext(),
|
||||
or: Result<CST.AnDeclaration>.Error(
|
||||
or: Result<CST.Categories.Declaration>.Error(
|
||||
ErrorWithLocation(
|
||||
sourceLocation: type_node_child!.toSourceLocation(),
|
||||
withError: "Missing parser parameters")))
|
||||
@@ -309,7 +309,7 @@ extension CST.Parser: Parsable {
|
||||
walker.next()
|
||||
#MustOr(
|
||||
result: current_node, thing: walker.getNext(),
|
||||
or: Result<CST.AnDeclaration>.Error(
|
||||
or: Result<CST.Categories.Declaration>.Error(
|
||||
ErrorWithLocation(
|
||||
sourceLocation: parser_node.toSourceLocation(),
|
||||
withError: "Missing parser declaration component")))
|
||||
@@ -317,7 +317,7 @@ extension CST.Parser: Parsable {
|
||||
walker.next()
|
||||
#MustOr(
|
||||
result: current_node, thing: walker.getNext(),
|
||||
or: Result<CST.AnDeclaration>.Error(
|
||||
or: Result<CST.Categories.Declaration>.Error(
|
||||
ErrorWithLocation(
|
||||
sourceLocation: parser_node.toSourceLocation(),
|
||||
withError: "Missing elements of parser declaration")))
|
||||
@@ -332,7 +332,7 @@ extension CST.Parser: Parsable {
|
||||
|
||||
#MustOr(
|
||||
result: current_node, thing: walker.getNext(),
|
||||
or: Result<CST.AnDeclaration>.Error(
|
||||
or: Result<CST.Categories.Declaration>.Error(
|
||||
ErrorWithLocation(
|
||||
sourceLocation: parser_node.toSourceLocation(),
|
||||
withError: "Missing body of parser declaration")))
|
||||
@@ -379,12 +379,12 @@ extension CST.Parser: Parsable {
|
||||
}
|
||||
|
||||
extension CST.Control: Parsable {
|
||||
public typealias C = CST.AnDeclaration
|
||||
public typealias C = CST.Categories.Declaration
|
||||
public static func Parse(
|
||||
node: SwiftTreeSitter.Node, withContext context: CSTCompilerContext
|
||||
) -> Common.Result<CST.AnDeclaration> {
|
||||
) -> Common.Result<CST.Categories.Declaration> {
|
||||
|
||||
#RequireNodeType<Node, Result<CST.AnDeclaration>>(
|
||||
#RequireNodeType<Node, Result<CST.Categories.Declaration>>(
|
||||
node: node, type: "control_declaration", nice_type_name: "control declaration")
|
||||
|
||||
var walker = Walker(node: node)
|
||||
@@ -393,7 +393,7 @@ extension CST.Control: Parsable {
|
||||
walker.next()
|
||||
#MustOr(
|
||||
result: current_node, thing: walker.getNext(),
|
||||
or: Result<CST.AnDeclaration>.Error(
|
||||
or: Result<CST.Categories.Declaration>.Error(
|
||||
ErrorWithLocation(
|
||||
sourceLocation: node.toSourceLocation(),
|
||||
withError: "Missing control declaration component")))
|
||||
@@ -409,7 +409,7 @@ extension CST.Control: Parsable {
|
||||
walker.next()
|
||||
#MustOr(
|
||||
result: current_node, thing: walker.getNext(),
|
||||
or: Result<CST.AnDeclaration>.Error(
|
||||
or: Result<CST.Categories.Declaration>.Error(
|
||||
ErrorWithLocation(
|
||||
sourceLocation: node.toSourceLocation(),
|
||||
withError: "Missing control declaration component")))
|
||||
@@ -426,7 +426,7 @@ extension CST.Control: Parsable {
|
||||
walker.next()
|
||||
#MustOr(
|
||||
result: current_node, thing: walker.getNext(),
|
||||
or: Result<CST.AnDeclaration>.Error(
|
||||
or: Result<CST.Categories.Declaration>.Error(
|
||||
ErrorWithLocation(
|
||||
sourceLocation: node.toSourceLocation(),
|
||||
withError: "Missing control declaration component")))
|
||||
@@ -873,10 +873,10 @@ extension CST.Table: Parsable {
|
||||
}
|
||||
|
||||
extension CST.ExternDeclaration: Parsable {
|
||||
public typealias C = CST.AnDeclaration
|
||||
public typealias C = CST.Categories.Declaration
|
||||
public static func Parse(
|
||||
node: SwiftTreeSitter.Node, withContext context: CSTCompilerContext
|
||||
) -> Result<CST.AnDeclaration> {
|
||||
) -> Result<CST.Categories.Declaration> {
|
||||
let extern_declaration_node = node
|
||||
#RequireNodeType<Node, CST.ExternDeclaration>(
|
||||
node: extern_declaration_node, type: "extern_declaration",
|
||||
@@ -1223,12 +1223,12 @@ extension CST.ArgumentList: Parsable {
|
||||
}
|
||||
|
||||
extension CST.Argument: Parsable {
|
||||
public typealias C = CST.AnExpression
|
||||
public typealias C = CST.Categories.Expression
|
||||
public static func Parse(
|
||||
node: SwiftTreeSitter.Node, withContext context: CSTCompilerContext
|
||||
) -> Common.Result<CST.AnExpression> {
|
||||
) -> Common.Result<CST.Categories.Expression> {
|
||||
let argument_node = node
|
||||
#RequireNodeType<Node, CST.AnExpression>(
|
||||
#RequireNodeType<Node, CST.Categories.Expression>(
|
||||
node: argument_node, type: "argument", nice_type_name: "argument")
|
||||
|
||||
let expression_node = node.child(at: 0)!
|
||||
|
||||
Reference in New Issue
Block a user