store reference to token when parsing range variable
This commit is contained in:
@@ -148,7 +148,7 @@ public class TokenParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public func compileResolvable(_ token: String, containedIn containingToken: Token) throws -> Resolvable {
|
public func compileResolvable(_ token: String, containedIn containingToken: Token) throws -> Resolvable {
|
||||||
return try RangeVariable(token, parser: self)
|
return try RangeVariable(token, parser: self, containedIn: containingToken)
|
||||||
?? compileFilter(token, containedIn: containingToken)
|
?? compileFilter(token, containedIn: containingToken)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public struct Variable : Equatable, Resolvable {
|
|||||||
|
|
||||||
// Split the lookup string and resolve references if possible
|
// Split the lookup string and resolve references if possible
|
||||||
fileprivate func lookup(_ context: Context) throws -> [String] {
|
fileprivate func lookup(_ context: Context) throws -> [String] {
|
||||||
var keyPath = KeyPath(variable, in: context)
|
let keyPath = KeyPath(variable, in: context)
|
||||||
return try keyPath.parse()
|
return try keyPath.parse()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,6 +138,7 @@ public struct RangeVariable: Resolvable {
|
|||||||
public let from: Resolvable
|
public let from: Resolvable
|
||||||
public let to: Resolvable
|
public let to: Resolvable
|
||||||
|
|
||||||
|
@available(*, deprecated, message: "Use init?(_:parser:containedIn:)")
|
||||||
public init?(_ token: String, parser: TokenParser) throws {
|
public init?(_ token: String, parser: TokenParser) throws {
|
||||||
let components = token.components(separatedBy: "...")
|
let components = token.components(separatedBy: "...")
|
||||||
guard components.count == 2 else {
|
guard components.count == 2 else {
|
||||||
@@ -148,6 +149,16 @@ public struct RangeVariable: Resolvable {
|
|||||||
self.to = try parser.compileFilter(components[1])
|
self.to = try parser.compileFilter(components[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public init?(_ token: String, parser: TokenParser, containedIn containingToken: Token) throws {
|
||||||
|
let components = token.components(separatedBy: "...")
|
||||||
|
guard components.count == 2 else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
self.from = try parser.compileFilter(components[0], containedIn: containingToken)
|
||||||
|
self.to = try parser.compileFilter(components[1], containedIn: containingToken)
|
||||||
|
}
|
||||||
|
|
||||||
public func resolve(_ context: Context) throws -> Any? {
|
public func resolve(_ context: Context) throws -> Any? {
|
||||||
let fromResolved = try from.resolve(context)
|
let fromResolved = try from.resolve(context)
|
||||||
let toResolved = try to.resolve(context)
|
let toResolved = try to.resolve(context)
|
||||||
|
|||||||
@@ -292,7 +292,9 @@ func testVariable() {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
func makeVariable(_ token: String) throws -> RangeVariable? {
|
func makeVariable(_ token: String) throws -> RangeVariable? {
|
||||||
return try RangeVariable(token, parser: TokenParser(tokens: [], environment: context.environment))
|
let token = Token.variable(value: token, at: .unknown)
|
||||||
|
let parser = TokenParser(tokens: [token], environment: context.environment)
|
||||||
|
return try RangeVariable(token.contents, parser: parser, containedIn: token)
|
||||||
}
|
}
|
||||||
|
|
||||||
$0.it("can resolve closed range as array") {
|
$0.it("can resolve closed range as array") {
|
||||||
|
|||||||
Reference in New Issue
Block a user