grammar,compiler: Add Support For Fixed-Width Integers
Distinguishing between signed and unsigned fixed-width integer types must still be done. Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
@@ -229,6 +229,38 @@ public struct SkipUnlessNodeType: CodeItemMacro {
|
||||
}
|
||||
}
|
||||
|
||||
public struct SkipUnlessNodesTypes: CodeItemMacro {
|
||||
public static func expansion(
|
||||
of node: some FreestandingMacroExpansionSyntax, in context: some MacroExpansionContext
|
||||
) throws -> [CodeBlockItemSyntax] {
|
||||
|
||||
let arguments = node.arguments.indices
|
||||
var arg_index = arguments.startIndex
|
||||
|
||||
let node_to_check = node.arguments[arg_index].expression
|
||||
|
||||
arg_index = arguments.index(after: arg_index)
|
||||
guard let expected_types = node.arguments[arg_index].expression.as(ArrayExprSyntax.self) else {
|
||||
throw MacroError(withMessage: "Node(s) to check must be in an array")
|
||||
}
|
||||
|
||||
arg_index = arguments.index(after: arg_index)
|
||||
|
||||
let ifs = expected_types.elements.map { l in
|
||||
"\(node_to_check).nodeType != \(l.expression)"
|
||||
}.joined(separator: " && ")
|
||||
|
||||
return [
|
||||
CodeBlockItemSyntax(
|
||||
"""
|
||||
if \(raw: ifs) {
|
||||
return Result.Ok(.none)
|
||||
}
|
||||
""")
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
public struct MustOr: CodeItemMacro {
|
||||
public static func expansion(
|
||||
of node: some FreestandingMacroExpansionSyntax, in context: some MacroExpansionContext
|
||||
@@ -261,6 +293,7 @@ public struct MustOr: CodeItemMacro {
|
||||
struct P4Macros: CompilerPlugin {
|
||||
var providingMacros: [Macro.Type] = [
|
||||
RequireResult.self, RequireErrorResult.self, UseOkResult.self, UseErrorResult.self,
|
||||
RequireNodeType.self, SkipUnlessNodeType.self, RequireNodesType.self, MustOr.self,
|
||||
RequireNodeType.self, SkipUnlessNodeType.self, SkipUnlessNodesTypes.self, RequireNodesType.self,
|
||||
MustOr.self,
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user