-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJSONLiteParser.m
More file actions
67 lines (52 loc) · 1.15 KB
/
JSONLiteParser.m
File metadata and controls
67 lines (52 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// JSONLite.m
// JSONLite
//
// Created by Niels Gabel on 10/17/13.
//
//
#import "JSONLiteParser.h"
#import "y.tab.h"
#import "lex-scanner.h"
@implementation JSONLiteParser
+(id)objectFromData:(NSData*)data error:(NSError**)error ;
{
// NSError * error = nil ;
id result = nil ;
if ( data.length > 0 )
{
yyscan_t scanner = NULL ;
BOOL ok = 0 == yylex_init(&scanner) ;
YY_BUFFER_STATE buffer = NULL ;
if ( ok )
{
NSMutableData * mutableData = [ data mutableCopy ] ;
[ mutableData appendBytes:&(uint32_t){0} length:sizeof( uint32_t ) ] ;
buffer = yy_scan_string( [ mutableData bytes ], scanner ) ;
[ mutableData release ] ;
ok = buffer != NULL ;
}
if ( ok )
{
// debug Bison:
// yydebug = 1 ;
// debug Flex:
// yyset_debug( 1, scanner) ;
/*BOOL success = 0 ==*/ yyparse( scanner, & result, error ) ;
// if ( success && result )
// {
// printf( "%s\n", [ [ result description ] UTF8String ] ) ;
// }
}
if ( scanner )
{
yylex_destroy(scanner);
}
}
return result ;
}
+(id)objectFromData:(NSData*)data
{
return [[ self class ] objectFromData:data error:NULL ] ;
}
@end