Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 166 lines (135 sloc) 6.702 kb
05eedb5 @itod initial add
authored
1 // Copyright 2010 Todd Ditchendorf
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #import "PKJSToken.h"
16 #import "PKJSUtils.h"
17 #import <ParseKit/PKToken.h>
18
19 #pragma mark -
20 #pragma mark Methods
21
22 static JSValueRef PKToken_toString(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef *ex) {
23 PKPreconditionInstaceOf(PKToken_class, "toString");
24 PKToken *data = JSObjectGetPrivate(this);
25 return PKNSStringToJSValue(ctx, [data debugDescription], ex);
26 }
27
28 #pragma mark -
29 #pragma mark Properties
30
31 static JSValueRef PKToken_getTokenType(JSContextRef ctx, JSObjectRef this, JSStringRef propName, JSValueRef *ex) {
32 PKToken *data = JSObjectGetPrivate(this);
33 return JSValueMakeNumber(ctx, data.tokenType);
34 }
35
36 static JSValueRef PKToken_getStringValue(JSContextRef ctx, JSObjectRef this, JSStringRef propName, JSValueRef *ex) {
37 PKToken *data = JSObjectGetPrivate(this);
38 return PKNSStringToJSValue(ctx, data.stringValue, ex);
39 }
40
41 static JSValueRef PKToken_getFloatValue(JSContextRef ctx, JSObjectRef this, JSStringRef propName, JSValueRef *ex) {
42 PKToken *data = JSObjectGetPrivate(this);
43 return JSValueMakeNumber(ctx, data.floatValue);
44 }
45
46 static JSValueRef PKToken_getIsNumber(JSContextRef ctx, JSObjectRef this, JSStringRef propName, JSValueRef *ex) {
47 PKToken *data = JSObjectGetPrivate(this);
48 return JSValueMakeBoolean(ctx, data.isNumber);
49 }
50
51 static JSValueRef PKToken_getIsSymbol(JSContextRef ctx, JSObjectRef this, JSStringRef propName, JSValueRef *ex) {
52 PKToken *data = JSObjectGetPrivate(this);
53 return JSValueMakeBoolean(ctx, data.isSymbol);
54 }
55
56 static JSValueRef PKToken_getIsWord(JSContextRef ctx, JSObjectRef this, JSStringRef propName, JSValueRef *ex) {
57 PKToken *data = JSObjectGetPrivate(this);
58 return JSValueMakeBoolean(ctx, data.isWord);
59 }
60
61 static JSValueRef PKToken_getIsQuotedString(JSContextRef ctx, JSObjectRef this, JSStringRef propName, JSValueRef *ex) {
62 PKToken *data = JSObjectGetPrivate(this);
63 return JSValueMakeBoolean(ctx, data.isQuotedString);
64 }
65
66 static JSValueRef PKToken_getIsWhitespace(JSContextRef ctx, JSObjectRef this, JSStringRef propName, JSValueRef *ex) {
67 PKToken *data = JSObjectGetPrivate(this);
68 return JSValueMakeBoolean(ctx, data.isWhitespace);
69 }
70
71 static JSValueRef PKToken_getIsComment(JSContextRef ctx, JSObjectRef this, JSStringRef propName, JSValueRef *ex) {
72 PKToken *data = JSObjectGetPrivate(this);
73 return JSValueMakeBoolean(ctx, data.isComment);
74 }
75
76 static JSValueRef PKToken_getIsDelimitedString(JSContextRef ctx, JSObjectRef this, JSStringRef propName, JSValueRef *ex) {
77 PKToken *data = JSObjectGetPrivate(this);
78 return JSValueMakeBoolean(ctx, data.isDelimitedString);
79 }
80
81 #pragma mark -
82 #pragma mark Initializer/Finalizer
83
84 static void PKToken_initialize(JSContextRef ctx, JSObjectRef this) {
85
86 }
87
88 static void PKToken_finalize(JSObjectRef this) {
89 PKToken *data = (PKToken *)JSObjectGetPrivate(this);
90 [data autorelease];
91 }
92
93 static JSStaticFunction PKToken_staticFunctions[] = {
94 { "toString", PKToken_toString, kJSPropertyAttributeDontDelete },
95 { 0, 0, 0 }
96 };
97
98 static JSStaticValue PKToken_staticValues[] = {
99 { "tokenType", PKToken_getTokenType, NULL, kJSPropertyAttributeDontDelete|kJSPropertyAttributeReadOnly }, // Number
100 { "stringValue", PKToken_getStringValue, NULL, kJSPropertyAttributeDontDelete|kJSPropertyAttributeReadOnly }, // String
101 { "floatValue", PKToken_getFloatValue, NULL, kJSPropertyAttributeDontDelete|kJSPropertyAttributeReadOnly }, // Number
102 { "isNumber", PKToken_getIsNumber, NULL, kJSPropertyAttributeDontDelete|kJSPropertyAttributeReadOnly }, // Boolean
103 { "isSymbol", PKToken_getIsSymbol, NULL, kJSPropertyAttributeDontDelete|kJSPropertyAttributeReadOnly }, // Boolean
104 { "isWord", PKToken_getIsWord, NULL, kJSPropertyAttributeDontDelete|kJSPropertyAttributeReadOnly }, // Boolean
105 { "isQuotedString", PKToken_getIsQuotedString, NULL, kJSPropertyAttributeDontDelete|kJSPropertyAttributeReadOnly }, // Boolean
106 { "isWhitespace", PKToken_getIsWhitespace, NULL, kJSPropertyAttributeDontDelete|kJSPropertyAttributeReadOnly }, // Boolean
107 { "isComment", PKToken_getIsComment, NULL, kJSPropertyAttributeDontDelete|kJSPropertyAttributeReadOnly }, // Boolean
108 { "isDelimitedString", PKToken_getIsDelimitedString, NULL, kJSPropertyAttributeDontDelete|kJSPropertyAttributeReadOnly }, // Boolean
109 { 0, 0, 0, 0 }
110 };
111
112 #pragma mark -
113 #pragma mark Class Methods
114
115 // JSObjectCallAsFunctionCallback
116 //JSValueRef PKToken_EOFToken(JSContextRef ctx, JSObjectRef function, JSObjectRef this, size_t argc, const JSValueRef argv[], JSValueRef *ex) {
117 // static JSValueRef eof = NULL;
118 // if (!eof) {
119 // eof = PKToken_new(ctx, [PKToken EOFToken]);
120 // JSValueProtect(ctx, eof); // is this necessary/appropriate?
121 // }
122 // return eof;
123 //}
124
125 #pragma mark -
126 #pragma mark Class Properties
127
128 JSValueRef PKToken_getEOFToken(JSContextRef ctx) {
129 static JSObjectRef eof = NULL;
130 if (!eof) {
131 eof = PKToken_new(ctx, [PKToken EOFToken]);
132 }
133 return eof;
134 }
135
136 #pragma mark -
137 #pragma mark Public
138
139 JSClassRef PKToken_class(JSContextRef ctx) {
140 static JSClassRef jsClass = NULL;
141 if (!jsClass) {
142 JSClassDefinition def = kJSClassDefinitionEmpty;
143 def.staticFunctions = PKToken_staticFunctions;
144 def.staticValues = PKToken_staticValues;
145 def.initialize = PKToken_initialize;
146 def.finalize = PKToken_finalize;
147 jsClass = JSClassCreate(&def);
148 }
149 return jsClass;
150 }
151
152 JSObjectRef PKToken_new(JSContextRef ctx, void *data) {
153 return JSObjectMake(ctx, PKToken_class(ctx), data);
154 }
155
156 JSObjectRef PKToken_construct(JSContextRef ctx, JSObjectRef constructor, size_t argc, const JSValueRef argv[], JSValueRef *ex) {
157 PKPreconditionConstructorArgc(3, "PKToken");
158
eb778c5 @itod merging changes from Google Code SVN repo
authored
159 PKFloat tokenType = JSValueToNumber(ctx, argv[0], NULL);
05eedb5 @itod initial add
authored
160 NSString *stringValue = PKJSValueGetNSString(ctx, argv[1], ex);
eb778c5 @itod merging changes from Google Code SVN repo
authored
161 PKFloat floatValue = JSValueToNumber(ctx, argv[2], NULL);
05eedb5 @itod initial add
authored
162
163 PKToken *data = [[PKToken alloc] initWithTokenType:tokenType stringValue:stringValue floatValue:floatValue];
164 return PKToken_new(ctx, data);
165 }
Something went wrong with that request. Please try again.