@@ -72,7 +72,6 @@ public class Variable: TypedIdentifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// The type for a P4 struct
|
/// The type for a P4 struct
|
||||||
public struct P4Struct: P4Type {
|
public struct P4Struct: P4Type {
|
||||||
|
|
||||||
@@ -247,7 +246,6 @@ public class P4StringValue: P4Value {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class Packet {
|
public class Packet {
|
||||||
public init() {}
|
public init() {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,7 +141,9 @@ extension Result: CustomStringConvertible {
|
|||||||
#externalMacro(module: "Macros", type: "UseOkResult")
|
#externalMacro(module: "Macros", type: "UseOkResult")
|
||||||
@freestanding(expression) public macro UseErrorResult<T>(_: Result<T>) -> Error =
|
@freestanding(expression) public macro UseErrorResult<T>(_: Result<T>) -> Error =
|
||||||
#externalMacro(module: "Macros", type: "UseErrorResult")
|
#externalMacro(module: "Macros", type: "UseErrorResult")
|
||||||
@freestanding(codeItem) public macro RequireNodeType<N, T>(node: N, type: String, nice_type_name: String) =
|
@freestanding(codeItem) public macro RequireNodeType<N, T>(
|
||||||
|
node: N, type: String, nice_type_name: String
|
||||||
|
) =
|
||||||
#externalMacro(module: "Macros", type: "RequireNodeType")
|
#externalMacro(module: "Macros", type: "RequireNodeType")
|
||||||
@freestanding(codeItem) public macro RequireNodesType<N, T>(
|
@freestanding(codeItem) public macro RequireNodesType<N, T>(
|
||||||
nodes: N, type: [String], nice_type_names: [String]
|
nodes: N, type: [String], nice_type_names: [String]
|
||||||
|
|||||||
@@ -184,8 +184,9 @@ extension SelectExpression: CompilableExpression {
|
|||||||
var kses: [KeysetExpression] = Array()
|
var kses: [KeysetExpression] = Array()
|
||||||
var kses_errors: [Error] = Array()
|
var kses_errors: [Error] = Array()
|
||||||
|
|
||||||
select_body_node.enumerateNamedChildren() { current_node in
|
select_body_node.enumerateNamedChildren { current_node in
|
||||||
let maybe_parsed_kse = KeysetExpression.compile(node: current_node, inTree: tree, withScopes: scopes)
|
let maybe_parsed_kse = KeysetExpression.compile(
|
||||||
|
node: current_node, inTree: tree, withScopes: scopes)
|
||||||
if case .Ok(let parsed_kse) = maybe_parsed_kse {
|
if case .Ok(let parsed_kse) = maybe_parsed_kse {
|
||||||
kses.append(parsed_kse as! KeysetExpression)
|
kses.append(parsed_kse as! KeysetExpression)
|
||||||
} else {
|
} else {
|
||||||
@@ -245,4 +246,3 @@ extension KeysetExpression: CompilableExpression {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -147,15 +147,22 @@ public struct Parser {
|
|||||||
node: Node, inTree tree: MutableTree, withScope scopes: LexicalScopes
|
node: Node, inTree tree: MutableTree, withScope scopes: LexicalScopes
|
||||||
) -> Result<(ParserTransitionStatement, LexicalScopes)> {
|
) -> Result<(ParserTransitionStatement, LexicalScopes)> {
|
||||||
|
|
||||||
#RequireNodeType<Node, (EvaluatableStatement, LexicalScopes)>(node: node, type: "parserTransitionStatement", nice_type_name: "parser transition statement")
|
#RequireNodeType<Node, (EvaluatableStatement, LexicalScopes)>(
|
||||||
|
node: node, type: "parserTransitionStatement", nice_type_name: "parser transition statement"
|
||||||
|
)
|
||||||
|
|
||||||
guard let tse_node = node.child(at: 1),
|
guard let tse_node = node.child(at: 1),
|
||||||
tse_node.nodeType! == "transitionSelectionExpression" else {
|
tse_node.nodeType! == "transitionSelectionExpression"
|
||||||
return .Error(ErrorOnNode(node: node, withError: "Could not find transition select expression"))
|
else {
|
||||||
|
return .Error(
|
||||||
|
ErrorOnNode(node: node, withError: "Could not find transition select expression"))
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let next_node = tse_node.child(at: 0) else {
|
guard let next_node = tse_node.child(at: 0) else {
|
||||||
return .Error(ErrorOnNode(node: node, withError: "Could not find the next token in a transition selection expression"))
|
return .Error(
|
||||||
|
ErrorOnNode(
|
||||||
|
node: node,
|
||||||
|
withError: "Could not find the next token in a transition selection expression"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the next node is an identifier, we have the simple form ...
|
// If the next node is an identifier, we have the simple form ...
|
||||||
@@ -179,7 +186,8 @@ public struct Parser {
|
|||||||
switch SelectExpression.compile(node: next_node, inTree: tree, withScopes: scopes)
|
switch SelectExpression.compile(node: next_node, inTree: tree, withScopes: scopes)
|
||||||
{
|
{
|
||||||
case .Ok(let tse):
|
case .Ok(let tse):
|
||||||
.Ok((ParserTransitionStatement(withTransitionExpression: tse! as! SelectExpression), scopes))
|
.Ok(
|
||||||
|
(ParserTransitionStatement(withTransitionExpression: tse! as! SelectExpression), scopes))
|
||||||
case .Error(let e): .Error(e)
|
case .Error(let e): .Error(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ extension BlockStatement: CompilableStatement {
|
|||||||
public static func Compile(
|
public static func Compile(
|
||||||
node: Node, inTree tree: MutableTree, withScopes scopes: LexicalScopes
|
node: Node, inTree tree: MutableTree, withScopes scopes: LexicalScopes
|
||||||
) -> Result<(EvaluatableStatement, LexicalScopes)> {
|
) -> Result<(EvaluatableStatement, LexicalScopes)> {
|
||||||
#RequireNodeType<Node, (EvaluatableStatement, LexicalScopes)>(node: node, type: "blockStatement", nice_type_name: "block statement")
|
#RequireNodeType<Node, (EvaluatableStatement, LexicalScopes)>(
|
||||||
|
node: node, type: "blockStatement", nice_type_name: "block statement")
|
||||||
|
|
||||||
var currentChildIdx = 0
|
var currentChildIdx = 0
|
||||||
var currentChildIdxSafe = 1
|
var currentChildIdxSafe = 1
|
||||||
@@ -91,7 +92,8 @@ extension ConditionalStatement: CompilableStatement {
|
|||||||
node: Node, inTree tree: MutableTree, withScopes scopes: LexicalScopes
|
node: Node, inTree tree: MutableTree, withScopes scopes: LexicalScopes
|
||||||
) -> Result<(EvaluatableStatement, LexicalScopes)> {
|
) -> Result<(EvaluatableStatement, LexicalScopes)> {
|
||||||
|
|
||||||
#RequireNodeType<Node, (EvaluatableStatement, LexicalScopes)>(node: node, type: "conditionalStatement", nice_type_name: "conditional statement")
|
#RequireNodeType<Node, (EvaluatableStatement, LexicalScopes)>(
|
||||||
|
node: node, type: "conditionalStatement", nice_type_name: "conditional statement")
|
||||||
|
|
||||||
let maybe_condition_expression = node.child(at: 2)
|
let maybe_condition_expression = node.child(at: 2)
|
||||||
guard let condition_expression = maybe_condition_expression,
|
guard let condition_expression = maybe_condition_expression,
|
||||||
@@ -158,7 +160,8 @@ extension VariableDeclarationStatement: CompilableStatement {
|
|||||||
node: Node, inTree tree: MutableTree, withScopes scopes: LexicalScopes
|
node: Node, inTree tree: MutableTree, withScopes scopes: LexicalScopes
|
||||||
) -> Result<(EvaluatableStatement, LexicalScopes)> {
|
) -> Result<(EvaluatableStatement, LexicalScopes)> {
|
||||||
|
|
||||||
#RequireNodeType<Node, (EvaluatableStatement, LexicalScopes)>(node: node, type: "variableDeclaration", nice_type_name: "variable declaration statement")
|
#RequireNodeType<Node, (EvaluatableStatement, LexicalScopes)>(
|
||||||
|
node: node, type: "variableDeclaration", nice_type_name: "variable declaration statement")
|
||||||
|
|
||||||
let maybe_typeref = node.child(at: 0)
|
let maybe_typeref = node.child(at: 0)
|
||||||
guard let typeref = maybe_typeref,
|
guard let typeref = maybe_typeref,
|
||||||
@@ -235,7 +238,8 @@ extension ExpressionStatement: CompilableStatement {
|
|||||||
public static func Compile(
|
public static func Compile(
|
||||||
node: Node, inTree tree: MutableTree, withScopes scopes: LexicalScopes
|
node: Node, inTree tree: MutableTree, withScopes scopes: LexicalScopes
|
||||||
) -> Result<(EvaluatableStatement, LexicalScopes)> {
|
) -> Result<(EvaluatableStatement, LexicalScopes)> {
|
||||||
#RequireNodeType<Node, (EvaluatableStatement, LexicalScopes)>(node: node, type: "expressionStatement", nice_type_name: "expression statement")
|
#RequireNodeType<Node, (EvaluatableStatement, LexicalScopes)>(
|
||||||
|
node: node, type: "expressionStatement", nice_type_name: "expression statement")
|
||||||
|
|
||||||
let _ = node.child(at: 0)
|
let _ = node.child(at: 0)
|
||||||
|
|
||||||
|
|||||||
@@ -46,10 +46,8 @@ public struct ParserStateDirectTransition: ParserStateInstance {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public var description: String {
|
public var description: String {
|
||||||
get {
|
|
||||||
return "Instance of \(currrent_state)"
|
return "Instance of \(currrent_state)"
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public let currrent_state: ParserState
|
public let currrent_state: ParserState
|
||||||
public let next_state_identifier: Identifier
|
public let next_state_identifier: Identifier
|
||||||
@@ -99,10 +97,8 @@ public struct ParserStateNoTransition: ParserStateInstance {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public var description: String {
|
public var description: String {
|
||||||
get {
|
|
||||||
return "Instance of \(currrent_state)"
|
return "Instance of \(currrent_state)"
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public let currrent_state: ParserState
|
public let currrent_state: ParserState
|
||||||
|
|
||||||
@@ -134,10 +130,8 @@ public struct ParserStateSelectTransition: ParserStateInstance {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public var description: String {
|
public var description: String {
|
||||||
get {
|
|
||||||
return "Instance of \(currrent_state)"
|
return "Instance of \(currrent_state)"
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public func execute(
|
public func execute(
|
||||||
program: Common.ProgramExecution
|
program: Common.ProgramExecution
|
||||||
@@ -252,7 +246,8 @@ extension ParserInstance: Compilable {
|
|||||||
|
|
||||||
public static func compile(_ parser: ToCompile) -> Result<Compiled> {
|
public static func compile(_ parser: ToCompile) -> Result<Compiled> {
|
||||||
return switch ParserStates.compile(parser.states) {
|
return switch ParserStates.compile(parser.states) {
|
||||||
case .Ok(let (start_state, states)): Result.Ok(ParserInstance(start: start_state, states: states))
|
case .Ok(let (start_state, states)):
|
||||||
|
Result.Ok(ParserInstance(start: start_state, states: states))
|
||||||
case .Error(let e): Result.Error(e)
|
case .Error(let e): Result.Error(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user