Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 70bbad1e975db46ab076f266d79eb6837e9500b7 @deanmao committed Apr 29, 2008
Showing with 657 additions and 0 deletions.
  1. +57 −0 Nukefile
  2. 0 README
  3. +15 −0 examples/example1.m
  4. +14 −0 examples/example2.nu
  5. +44 −0 nu/nusax.nu
  6. +29 −0 objc/NuSAX.h
  7. +286 −0 objc/NuSAX.m
  8. +70 −0 objc/XMLUtilities.h
  9. +112 −0 objc/XMLUtilities.m
  10. +30 −0 test/test_parse.nu
@@ -0,0 +1,57 @@
+(set platform "native")
+
+(case platform
+ ("iPhone"
+ (set PLATFORM "-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk")
+ (set @arch '("armv6"))
+ (set @cc "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.0"))
+ ("simulator"
+ (set PLATFORM "-isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.0.sdk")
+ (set @arch '("i386")))
+ ("native"
+ (set @cc "/Developer/usr/bin/gcc-4.2")
+ (set PLATFORM "")
+ (set @arch '("i386")))
+ (else nil))
+
+(set @cflags "-I /usr/include/libxml2 -g -ObjC -Iinclude -std=gnu99 #{PLATFORM} -mmacosx-version-min=10.5")
+
+(set @h_files (filelist "^objc/.*.h$"))
+(set @m_files (filelist "^objc/.*.m$"))
+(set @nu_files (filelist "^nu/.*nu$"))
+(set @frameworks '("Cocoa" "Nu"))
+(set @libs '("xml2"))
+
+(set @ldflags
+ ((list
+ ((@frameworks map: (do (framework) " -framework #{framework}")) join)
+ ((@libs map: (do (lib) " -l#{lib}")) join)
+ ((@lib_dirs map: (do (libdir) " -L#{libdir}")) join))
+ join))
+
+(set @framework "NuSAX")
+(set @framework_identifier "nu.programming.nusax")
+(set @framework_creator_code "????")
+
+(compilation-tasks)
+(framework-tasks)
+
+(task "framework" => "#{@framework_headers_dir}/NuSAX.h")
+
+(ifDarwin
+ (file "#{@framework_headers_dir}/NuSAX.h" => "objc/NuSAX.h" @framework_headers_dir is
+ (SH "cp objc/NuSAX.h #{@framework_headers_dir}")))
+
+(task "test" => "framework" is
+ (SH "nutest test/test_*.nu"))
+
+(task "default" => "framework")
+
+(task "clobber" => "clean" is
+ (SH "rm -f example1"))
+
+(task "install" => "framework" is
+ (SH "ditto #{@framework_dir} /Library/Frameworks/#{@framework_dir}"))
+
+(task "example" is
+ (SH "#{@cc} examples/example1.m -o example1 -lxml2 -I/usr/include/libxml2 -framework Cocoa -framework NuSAX"))
0 README
No changes.
@@ -0,0 +1,15 @@
+#import <Cocoa/Cocoa.h>
+#import <NuSAX/NuSAX.h>
+
+int main (int argc, char *argv[])
+{
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ NSError *parseError = nil;
+ NuSAX *streamingParser = [[NuSAX alloc] init];
+ id list = [streamingParser parseXML:"<fruits><apple version=\"2.0\" language=\"english\">blah</apple><orange>foo</orange></fruits>" parseError:&parseError];
+ // id list = [streamingParser parseXMLFileAtURL:[NSURL URLWithString:@"http://earthquake.usgs.gov/eqcenter/catalogs/eqs7day-M2.5.xml"] parseError:&parseError];
+ NSLog(@"xml: %@", [list stringValue]);
+
+ [pool release];
+}
@@ -0,0 +1,14 @@
+#!/usr/bin/env nush
+
+(load "NuSAX")
+(load "Cocoa")
+
+(set parser ((NuSAX alloc) init))
+(set x (parser parseXML:"<fruits><apple version=\"3.0\" language=\"english\">blah</apple><orange>foo</orange></fruits>"
+ parseError:nil))
+
+(puts "list form:")
+(puts x)
+
+(puts "xml form:")
+(puts (x toXml))
@@ -0,0 +1,44 @@
+;; Licensed under the Apache License, Version 2.0 (the "License");
+;; you may not use this file except in compliance with the License.
+;; You may obtain a copy of the License at
+;;
+;; http://www.apache.org/licenses/LICENSE-2.0
+;;
+;; Unless required by applicable law or agreed to in writing, software
+;; distributed under the License is distributed on an "AS IS" BASIS,
+;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+;; See the License for the specific language governing permissions and
+;; limitations under the License.
+
+(class NSArray
+ (imethod (id) join is
+ ((self select:(do (x) x)) componentsJoinedByString:"")))
+
+(class NSNull
+ (imethod (id) toXml is
+ (""))
+ (imethod (id) xmlAttr is
+ ("")))
+
+(class NSObject
+ (imethod (id) toXml is
+ (self stringValue)))
+
+(class NuCell
+ (imethod (id) join is
+ ((NSArray arrayWithList:self) join))
+
+ (imethod (id) xmlAttr is
+ (" #{(first (first self))}=\"#{(second (first self))}\"#{((rest self) xmlAttr)}"))
+
+ (imethod (id) toXml is
+ (if (== (self length) 2)
+ (then "<#{(first self)}#{((second self) xmlAttr)}></#{(first self)}>")
+ (else
+ (if (self 3)
+ (then "<#{(first self)}#{((second self) xmlAttr)}>#{(((rest (rest self)) map: (do (i) (i toXml))) join)}</#{(first self)}>")
+ (else "<#{(first self)}#{((second self) xmlAttr)}>#{((third self) toXml)}</#{(first self)}>"))))))
+
+(class NSString
+ (imethod (id) fromXml is
+ (((NuSAX alloc) init) parseXML:self parseError:nil)))
@@ -0,0 +1,29 @@
+/*
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#import <Foundation/Foundation.h>
+#import <libxml/xmlstring.h>
+
+@interface NuSAX : NSObject {
+
+@private
+ NSMutableArray *_processed;
+}
+
+@property (nonatomic, retain) NSMutableArray *processed;
+
+- (id) parseXML:(const char *)XMLString parseError:(NSError **)parseError;
+- (id) parseXMLFileAtURL:(NSURL *)URL parseError:(NSError **)error;
+
+@end
Oops, something went wrong.

0 comments on commit 70bbad1

Please sign in to comment.