mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-08-28 14:37:04 +00:00
Added missing getters in CPExpression. Added a type: argument to FunctionExpression initializer used by subclasses to init super with their own type. Fixed evaluation with bindings dictionary in CPExpression_variable. Allow values in bindings to be a constant or an expression (per cocoa). Tests: added tests for subqueryExpressions, for variableExpression evaluation where the value in the bindings dictionary can be either a constant or another expression. Parsing a simple variable expression works (e.g. '$x = 12'), parsing a variable in a combined path (e.g. '$x.path = 12' won't yet.
50 lines
1.1 KiB
Plaintext
50 lines
1.1 KiB
Plaintext
|
|
@import "CPExpression.j"
|
|
@import <Foundation/CPString.j>
|
|
@import <Foundation/CPKeyValueCoding.j>
|
|
@import "CPExpression_function.j"
|
|
|
|
@implementation CPExpression_keypath : CPExpression_function
|
|
{
|
|
}
|
|
|
|
- (id)initWithKeyPath:(CPString)keyPath
|
|
{
|
|
return [self initWithOperand:[CPExpression expressionForEvaluatedObject] andKeyPath:keyPath];
|
|
}
|
|
|
|
- (id)initWithOperand:(CPExpression)operand andKeyPath:(CPString)keyPath
|
|
{
|
|
var arg = [CPExpression expressionForConstantValue:keyPath];
|
|
// Cocoa: if it's a direct path selector is valueForKey:
|
|
self = [super initWithTarget:operand selector:@selector(valueForKeyPath:) arguments:[arg] type:CPKeyPathExpressionType];
|
|
|
|
return self;
|
|
}
|
|
|
|
- (BOOL)isEqual:(id)object
|
|
{
|
|
if (object === self)
|
|
return YES;
|
|
|
|
return ([object keyPath] == [self keyPath]); //If it appears that parsing generates nested keypaths with different targets and same keyPath, comparing -keyPath won't work.
|
|
}
|
|
|
|
- (CPExpression)pathExpression
|
|
{
|
|
return [[self arguments] objectAtIndex:0];
|
|
}
|
|
|
|
- (CPString)keyPath
|
|
{
|
|
return [[self pathExpression] constantValue];
|
|
}
|
|
|
|
- (CPString)description
|
|
{
|
|
return [self keyPath];
|
|
}
|
|
|
|
@end
|
|
|