Source

Silver / Classes / Parser / SVToken.h

Full commit
//
//  SVToken.h
//  SV
//
//  Created by Michael Tindal on 6/4/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>

#define STCFRetain() [[NSString alloc] initWithBytes:ts length:(te-ts) encoding:NSUTF8StringEncoding]
#define TK(I) CFRetain([SVToken token:I data:STCFRetain()])
#define TK_(I,D) CFRetain([SVToken token:I data:D])
#define KW(T)  Parse(context.parser, TK_ ## T, TK(TK_ ## T), context);
#define SYM(T) Parse(context.parser, TK_ ## T, TK(TK_ ## T), context);
#define SYM_(T) Parse(context.parser, TK_ ## T, TK(TK_ ## T), context)
#define TOK(T)  Parse(context.parser, TK_ ## T, TK(TK_ ## T), context);
#define NUM() Parse(context.parser,TK_NUMBER,TK_(TK_NUMBER,[NSNumber numberWithFloat:[STCFRetain() floatValue]]),context);
#define HEX() unsigned result; [[NSScanner scannerWithString:STCFRetain()] scanHexInt:&result]; \
        Parse(context.parser,TK_NUMBER,TK_(TK_NUMBER,[NSNumber numberWithUnsignedInt:result]),context);
#define STRING() NSString* str = STCFRetain(); \
        Parse(context.parser,TK_STRING,TK_(TK_STRING,[str substringWithRange:NSMakeRange(1,[str length]-2)]),context);
#define REGEX() NSString* str = STCFRetain(); \
        Parse(context.parser,TK_REGEX,TK_(TK_REGEX,[str substringWithRange:NSMakeRange(2,[str length]-3)]),context);
#define SYMBOL() Parse(context.parser,TK_SYMBOL,TK(TK_SYMBOL),context);
#define OP() Parse(context.parser,TK_OP,TK(TK_OP),context);
#define RI() NSString* str = STCFRetain(); \
        Parse(context.parser,TK_RAWIDENTIFIER,TK_(TK_RAWIDENTIFIER,[str substringWithRange:NSMakeRange(2,[str length]-4)]),context);

@interface SVToken : NSObject {
    @private
    NSUInteger token_;
    id data_;
}

+ (SVToken *) token:(NSUInteger)token data:(id)data;

- (id) initWithToken:(NSUInteger)token data:(id)data;

@property NSUInteger token;
@property (retain) id tokenData;
@end