Files
gp4/Sources/P4Parser/Protocols.swift
T
Will Hawkins d22776b018 compiler: Refactor Language Element Tags
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
2026-06-15 21:16:52 -04:00

74 lines
2.4 KiB
Swift

// p4rse, Copyright 2026, Will Hawkins
//
// This file is part of p4rse.
//
// This file is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
import Common
import SwiftTreeSitter
import TreeSitterExtensions
import TreeSitterP4
/*
public protocol CompilableValue {
static func CompileValue(withValue value: String) -> Result<P4DataValue>
}
*/
public protocol MaybeParsableType {
static func MaybeParseType(
type: SwiftTreeSitter.Node, withContext: CSTCompilerContext
) -> Result<CST.Tipe>
}
public protocol ParsableType {
static func ParseType(
type: SwiftTreeSitter.Node, withContext: CSTCompilerContext
) -> Result<CST.Tipe>
}
public protocol ParsableExpression {
static func ParseExpression(
node: Node, withContext context: CSTCompilerContext
) -> Result<CST.Categories.Expression>
}
public protocol Parsable<C> {
associatedtype C
static func Parse(
node: Node, withContext context: CSTCompilerContext
) -> Result<C>
}
public protocol ParsableStatement {
static func ParseStatement(
node: Node, withContext context: CSTCompilerContext
) -> Result<CST.Categories.Statement>
}
public protocol CSTVisitor<T> {
associatedtype T
func visit(node: CST.BinaryOperatorExpression, driver: CSTVisitorDriver, context: T) -> Result<T>
func visit(node: CST.Literal, driver: CSTVisitorDriver, context: T) -> Result<T>
func visit(node: CST.Identifier, driver: CSTVisitorDriver, context: T) -> Result<T>
func visit(node: CST.Parser, driver: CSTVisitorDriver, context: T) -> Result<T>
func visit(
node: CST.ParserStateDirectTransition, driver: CSTVisitorDriver, context: T
) -> Result<T>
func visit(node: CST.ParserStateNoTransition, driver: CSTVisitorDriver, context: T) -> Result<T>
func visit(
node: CST.ParserStateSelectTransition, driver: CSTVisitorDriver, context: T
) -> Result<T>
}