Subscript syntax for Variables (#215)
* Implement variable indirect resolution * Add some tests * Changelog entry * Update documentation * Rework the syntax to use brackets instead of a $ * Move the lookup parser into it's own file * Add invalid syntax tests * Swift 3 support * Rename some things + extra test
This commit is contained in:
committed by
Ilya Puchka
parent
39ed9aa753
commit
2e18892f4c
@@ -50,8 +50,10 @@ public struct Variable : Equatable, Resolvable {
|
||||
self.variable = variable
|
||||
}
|
||||
|
||||
fileprivate func lookup() -> [String] {
|
||||
return variable.characters.split(separator: ".").map(String.init)
|
||||
// Split the lookup string and resolve references if possible
|
||||
fileprivate func lookup(_ context: Context) throws -> [String] {
|
||||
var keyPath = KeyPath(variable, in: context)
|
||||
return try keyPath.parse()
|
||||
}
|
||||
|
||||
/// Resolve the variable in the given context
|
||||
@@ -75,7 +77,7 @@ public struct Variable : Equatable, Resolvable {
|
||||
return bool
|
||||
}
|
||||
|
||||
for bit in lookup() {
|
||||
for bit in try lookup(context) {
|
||||
current = normalize(current)
|
||||
|
||||
if let context = current as? Context {
|
||||
|
||||
Reference in New Issue
Block a user