Sha256: 8eefe93d4c841bf97c25f0c4300d5e3807ba56f552e1c817caaf302e84b6c4e9

Contents?: true

Size: 1.98 KB

Versions: 9

Compression:

Stored size: 1.98 KB

Contents

#import "GHAstNode.h"

#import "GHToken.h"
#import "GHParser.h"

@interface GHAstNode ()

@property (nonatomic, assign) GHRuleType    ruleType;

@end

@implementation GHAstNode
{
    NSMutableDictionary<NSNumber *, NSMutableArray<NSObject *> *> * subitems;
}

@synthesize ruleType;

- (id)initWithRuleType:(GHRuleType)theRuleType
{
    if (self = [super init])
    {
        ruleType = theRuleType;
        subitems = [[NSMutableDictionary<NSNumber *, NSMutableArray<NSObject *> *> alloc] init];
    }
    return self;
}

- (GHToken *)tokenWithType:(GHTokenType)theTokenType
{
    return [self singleWithRuleType: (GHRuleType)theTokenType];
}

- (NSArray<GHToken *> *)tokensWithType:(GHTokenType)theTokenType
{
    return (NSArray<GHToken *> *)[self itemsWithRuleType: (GHRuleType)theTokenType];
}

- (id)singleWithRuleType:(GHRuleType)theRuleType
{
    return [[self itemsWithRuleType: theRuleType] firstObject];
}

- (NSArray<NSObject *> *)itemsWithRuleType:(GHRuleType)theRuleType
{
    NSArray<NSObject *> * items = subitems[@(theRuleType)];
    if (items)
        return items;
    
    return [[NSArray<NSObject *> alloc] init];
}

- (void)setSingleWithRuleType:(GHRuleType)theRuleType value:(NSObject *)theValue
{
    NSMutableArray<NSObject *> * valueArray = [[NSMutableArray<NSObject *> alloc] initWithObjects: theValue ? theValue : [NSNull null], nil];
    
    subitems[@(theRuleType)] = valueArray;
}

- (void)addRange:(GHRuleType)theRuleType values:(NSArray<NSObject *> *)theValues
{
    for (id value in theValues)
    {
        [self addObject: value withRuleType: theRuleType];
    }
}

- (void)addObject:(NSObject *)theObject withRuleType:(GHRuleType)theRuleType
{
    NSMutableArray<NSObject *> * items = subitems[@(theRuleType)];
    if (!items)
    {
        items = [[NSMutableArray<NSObject *> alloc] init];
        subitems[@(theRuleType)] = items;
    }
    [items addObject: theObject ? theObject : [NSNull null]];
}

@end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
xcfit-2.0.6 XCFit/Classes/Cucumberish/Dependencies/Gherkin/GHAstNode.m
xcfit-0.9.0 XCFitDemo/XCFitDemoCucumberishTests/Cucumberish/Dependencies/Gherkin/GHAstNode.m
xcfit-0.8.0 XCFitDemo/XCFitDemoCucumberishTests/Cucumberish/Dependencies/Gherkin/GHAstNode.m
xcfit-0.7.0 XCFitDemo/XCFitDemoCucumberishTests/Cucumberish/Dependencies/Gherkin/GHAstNode.m
xcfit-0.6.0 XCFitDemo/XCFitDemoCucumberishTests/Cucumberish/Dependencies/Gherkin/GHAstNode.m
xcfit-0.5.0 XCFitDemo/XCFitDemoCucumberishTests/Cucumberish/Dependencies/Gherkin/GHAstNode.m
xcfit-0.4.0 XCFitDemo/XCFitDemoCucumberishTests/Cucumberish/Dependencies/Gherkin/GHAstNode.m
xcfit-0.3.0 XCFitDemo/XCFitDemoCucumberishTests/Cucumberish/Dependencies/Gherkin/GHAstNode.m
xcfit-0.2.0 XCFitDemo/XCFitDemoCucumberishTests/Cucumberish/Dependencies/Gherkin/GHAstNode.m