@@ -72,7 +72,7 @@ public struct Scopes<T>: CustomStringConvertible {
|
|||||||
var counter = 0
|
var counter = 0
|
||||||
for s in scopes {
|
for s in scopes {
|
||||||
result += "Scope #\(counter):\n\(s)\n"
|
result += "Scope #\(counter):\n\(s)\n"
|
||||||
counter += 1;
|
counter += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -124,6 +124,6 @@ public struct RequireErrorResult: ExpressionMacro {
|
|||||||
@main
|
@main
|
||||||
struct P4Macros: CompilerPlugin {
|
struct P4Macros: CompilerPlugin {
|
||||||
var providingMacros: [Macro.Type] = [
|
var providingMacros: [Macro.Type] = [
|
||||||
RequireResult.self, RequireErrorResult.self, UseOkResult.self, UseErrorResult.self
|
RequireResult.self, RequireErrorResult.self, UseOkResult.self, UseErrorResult.self,
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,8 @@ extension ParserAssignmentStatement: CompilableStatement {
|
|||||||
ErrorOnNode(node: node, withError: "Missing rvalue in assignment statement"))
|
ErrorOnNode(node: node, withError: "Missing rvalue in assignment statement"))
|
||||||
}
|
}
|
||||||
|
|
||||||
let maybe_parsed_rvalue = Expression.Compile(node: rvalue_node, inTree: tree, withScopes: scopes)
|
let maybe_parsed_rvalue = Expression.Compile(
|
||||||
|
node: rvalue_node, inTree: tree, withScopes: scopes)
|
||||||
guard case Result.Ok(let rvalue) = maybe_parsed_rvalue else {
|
guard case Result.Ok(let rvalue) = maybe_parsed_rvalue else {
|
||||||
return Result.Error(maybe_parsed_rvalue.error()!)
|
return Result.Error(maybe_parsed_rvalue.error()!)
|
||||||
}
|
}
|
||||||
@@ -289,7 +290,9 @@ public struct Parser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return switch TransitionSelectExpression.Compile(node: node, inTree: tree, withScope: scopes) {
|
return
|
||||||
|
switch TransitionSelectExpression.Compile(node: node, inTree: tree, withScope: scopes)
|
||||||
|
{
|
||||||
case .Ok((let tse, _)):
|
case .Ok((let tse, _)):
|
||||||
.Ok((ParserTransitionStatement(withTransitionExpression: tse), scopes))
|
.Ok((ParserTransitionStatement(withTransitionExpression: tse), scopes))
|
||||||
case .Error(let e): .Error(e)
|
case .Error(let e): .Error(e)
|
||||||
|
|||||||
@@ -57,7 +57,9 @@ extension BlockStatement: CompilableStatement {
|
|||||||
}
|
}
|
||||||
currentChild = node.child(at: currentChildIdx)
|
currentChild = node.child(at: currentChildIdx)
|
||||||
if currentChild!.nodeType == "statements" {
|
if currentChild!.nodeType == "statements" {
|
||||||
switch Parser.Statements.Compile(node: currentChild!, inTree: tree, withLexicalScopes: scopes.enter()) {
|
switch Parser.Statements.Compile(
|
||||||
|
node: currentChild!, inTree: tree, withLexicalScopes: scopes.enter())
|
||||||
|
{
|
||||||
case .Ok(let (parsed_statements, parsed_scopes)):
|
case .Ok(let (parsed_statements, parsed_scopes)):
|
||||||
new_scopes = parsed_scopes
|
new_scopes = parsed_scopes
|
||||||
statements = parsed_statements
|
statements = parsed_statements
|
||||||
@@ -112,7 +114,8 @@ extension ConditionalStatement: CompilableStatement {
|
|||||||
thens.nodeType == "statement"
|
thens.nodeType == "statement"
|
||||||
else {
|
else {
|
||||||
return Result.Error(
|
return Result.Error(
|
||||||
ErrorOnNode(node: node, withError: "Did not find then statement block for conditional statement"))
|
ErrorOnNode(
|
||||||
|
node: node, withError: "Did not find then statement block for conditional statement"))
|
||||||
}
|
}
|
||||||
|
|
||||||
guard
|
guard
|
||||||
@@ -175,7 +178,8 @@ extension VariableDeclarationStatement: CompilableStatement {
|
|||||||
typeref.nodeType == "typeRef"
|
typeref.nodeType == "typeRef"
|
||||||
else {
|
else {
|
||||||
return Result.Error(
|
return Result.Error(
|
||||||
ErrorOnNode(node: node, withError: "Did not find type name for variable declaration statement"))
|
ErrorOnNode(
|
||||||
|
node: node, withError: "Did not find type name for variable declaration statement"))
|
||||||
}
|
}
|
||||||
|
|
||||||
let maybe_variablename = node.child(at: 1)
|
let maybe_variablename = node.child(at: 1)
|
||||||
@@ -183,7 +187,8 @@ extension VariableDeclarationStatement: CompilableStatement {
|
|||||||
variablename.nodeType == "identifier"
|
variablename.nodeType == "identifier"
|
||||||
else {
|
else {
|
||||||
return Result.Error(
|
return Result.Error(
|
||||||
ErrorOnNode(node: node, withError: "Did not find identifier name for variable declaration statement"))
|
ErrorOnNode(
|
||||||
|
node: node, withError: "Did not find identifier name for variable declaration statement"))
|
||||||
}
|
}
|
||||||
|
|
||||||
let maybe_rvalue = node.childCount > 3 ? node.child(at: 3) : .none
|
let maybe_rvalue = node.childCount > 3 ? node.child(at: 3) : .none
|
||||||
@@ -191,7 +196,9 @@ extension VariableDeclarationStatement: CompilableStatement {
|
|||||||
rvalue.nodeType == "expression"
|
rvalue.nodeType == "expression"
|
||||||
else {
|
else {
|
||||||
return Result.Error(
|
return Result.Error(
|
||||||
ErrorOnNode(node: node, withError: "Did not find initial value expression for variable declaration statement"))
|
ErrorOnNode(
|
||||||
|
node: node,
|
||||||
|
withError: "Did not find initial value expression for variable declaration statement"))
|
||||||
}
|
}
|
||||||
|
|
||||||
guard
|
guard
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ public struct Parser: P4Type {
|
|||||||
|
|
||||||
public func findStartState() -> ParserState? {
|
public func findStartState() -> ParserState? {
|
||||||
for state in states.states {
|
for state in states.states {
|
||||||
if state.state == Identifier(name:"start") {
|
if state.state == Identifier(name: "start") {
|
||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user