Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 113 lines (69 sloc) 2.45 kB
ee99867 @ccgus oh geeze
authored
1 #import <Cocoa/Cocoa.h>
2 #import "JSTListener.h"
3 #import "JSTalk.h"
dbbb75c @ccgus Fixed some imports, and JSTTextView's line numbers can no longer be c…
authored
4 #import "JSCocoaController.h"
ee99867 @ccgus oh geeze
authored
5
eb90eec @ccgus Added a REPL to the jstalk command line tool. I'm going to try and c…
authored
6 BOOL JSCErrorHandlerExitOnError = YES;
1a4ff63 Added support for some sort of JSTalk envirnoment vars, which you can…
August Mueller authored
7
8 @interface JSCErrorHandler : NSObject {
9
10 }
11 @end
12
13 @implementation JSCErrorHandler
14
eb90eec @ccgus Added a REPL to the jstalk command line tool. I'm going to try and c…
authored
15 - (void)JSCocoa:(JSCocoaController*)controller hadError:(NSString*)error onLineNumber:(NSInteger)lineNumber atSourceURL:(id)url {
1a4ff63 Added support for some sort of JSTalk envirnoment vars, which you can…
August Mueller authored
16
eb90eec @ccgus Added a REPL to the jstalk command line tool. I'm going to try and c…
authored
17 printf("Error line %d, %s\n", (int)lineNumber, [[error description] UTF8String]);
1a4ff63 Added support for some sort of JSTalk envirnoment vars, which you can…
August Mueller authored
18
eb90eec @ccgus Added a REPL to the jstalk command line tool. I'm going to try and c…
authored
19 if (JSCErrorHandlerExitOnError) {
20 exit(1);
21 }
1a4ff63 Added support for some sort of JSTalk envirnoment vars, which you can…
August Mueller authored
22 }
23
24
25 @end
26
27
eb90eec @ccgus Added a REPL to the jstalk command line tool. I'm going to try and c…
authored
28 void runREPL(JSTalk *t) {
29
30 // thanks http://tlrobinson.net/blog/2008/10/10/command-line-interpreter-and-repl-for-jscocoa/ !
31
32 JSCErrorHandlerExitOnError = NO;
33
34 while (1) {
35 char buffer[1024];
36
37 printf("js> ");
38
39 if (fgets(buffer, 1024, stdin) == NULL) {
40 exit(0);
41 }
42
43 NSString *s = [[NSString alloc] initWithUTF8String:buffer];
44
45 id o = [t executeString:s];
46
47 if (o) {
48 printf("%s\n", [[o description] UTF8String]);
49 }
50
51 [s release];
52
53 }
54
55
56 }
57
1a4ff63 Added support for some sort of JSTalk envirnoment vars, which you can…
August Mueller authored
58
ee99867 @ccgus oh geeze
authored
59 int main(int argc, char *argv[]) {
60
61 NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
eb90eec @ccgus Added a REPL to the jstalk command line tool. I'm going to try and c…
authored
62
1a4ff63 Added support for some sort of JSTalk envirnoment vars, which you can…
August Mueller authored
63 JSCErrorHandler *eh = [[[JSCErrorHandler alloc] init] autorelease];
64
ee99867 @ccgus oh geeze
authored
65 JSTalk *t = [[[JSTalk alloc] init] autorelease];
66
1a4ff63 Added support for some sort of JSTalk envirnoment vars, which you can…
August Mueller authored
67 JSCocoaController *jsController = [t jsController];
68 jsController.delegate = eh;
69
1a90c9a @ccgus Got rid of the -e arg for the jstalk REPL. Seems alright to just dro…
authored
70 if (argc < 2) {
eb90eec @ccgus Added a REPL to the jstalk command line tool. I'm going to try and c…
authored
71 runREPL(t);
72 exit(0);
73 }
74
1a90c9a @ccgus Got rid of the -e arg for the jstalk REPL. Seems alright to just dro…
authored
75
224637f @ccgus command line arg improvements.
authored
76 NSString *source = 0x00;
1a90c9a @ccgus Got rid of the -e arg for the jstalk REPL. Seems alright to just dro…
authored
77 NSString *arg = [NSString stringWithUTF8String:argv[1]];
eb90eec @ccgus Added a REPL to the jstalk command line tool. I'm going to try and c…
authored
78
224637f @ccgus command line arg improvements.
authored
79 if ([arg isEqualToString:@"-e"] && argc == 3) {
80 source = [NSString stringWithUTF8String:argv[2]];
81 }
82 else {
83 source = [NSString stringWithContentsOfFile:arg encoding:NSUTF8StringEncoding error:nil];
84 }
85
86
87 if (!source) {
1a90c9a @ccgus Got rid of the -e arg for the jstalk REPL. Seems alright to just dro…
authored
88 printf("usage: %s <path to file>\n", argv[0]);
89 exit(0);
90 }
91
eb90eec @ccgus Added a REPL to the jstalk command line tool. I'm going to try and c…
authored
92 [t.env setObject:[NSURL fileURLWithPath:arg] forKey:@"scriptURL"];
1a4ff63 Added support for some sort of JSTalk envirnoment vars, which you can…
August Mueller authored
93
224637f @ccgus command line arg improvements.
authored
94 if ([source hasPrefix:@"#!"]) {
ee99867 @ccgus oh geeze
authored
95
224637f @ccgus command line arg improvements.
authored
96 NSRange r = [source rangeOfString:@"\n"];
ee99867 @ccgus oh geeze
authored
97
98 if (r.location != NSNotFound) {
224637f @ccgus command line arg improvements.
authored
99 source = [source substringFromIndex:r.location];
ee99867 @ccgus oh geeze
authored
100 }
101 }
102
224637f @ccgus command line arg improvements.
authored
103 id o = [t executeString:source];
104
105 if (o) {
106 printf("%s\n", [[o description] UTF8String]);
107 }
ee99867 @ccgus oh geeze
authored
108
109 [pool release];
1a4ff63 Added support for some sort of JSTalk envirnoment vars, which you can…
August Mueller authored
110
111 return 0;
ee99867 @ccgus oh geeze
authored
112 }
Something went wrong with that request. Please try again.