parser, compiler: Support Table Actions
Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
@@ -51,4 +51,21 @@ public struct Walker {
|
||||
}
|
||||
return Result.Ok(())
|
||||
}
|
||||
|
||||
public func try_map<T>(n: Int, onlyNamed: Bool = false, todo: (Node) -> Result<T>) -> ([T], [Error]) {
|
||||
var errors: [Error] = Array()
|
||||
var results: [T] = Array()
|
||||
|
||||
for currentChildIdx in currentChildIdx..<n {
|
||||
let currentChild = node.child(at: currentChildIdx)!
|
||||
if onlyNamed && !currentChild.isNamed {
|
||||
continue
|
||||
}
|
||||
switch todo(currentChild) {
|
||||
case .Ok(let r): results.append(r)
|
||||
case .Error(let e): errors.append(e)
|
||||
}
|
||||
}
|
||||
return (results, errors)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user