rubysl-yaml 2.0.0 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +10 -3
- data/ext/rubysl/syck/bytecode.c +1165 -0
- data/ext/rubysl/syck/emitter.c +1247 -0
- data/ext/rubysl/syck/extconf.rb +5 -0
- data/ext/rubysl/syck/gram.c +1894 -0
- data/ext/rubysl/syck/gram.h +79 -0
- data/ext/rubysl/syck/handler.c +173 -0
- data/ext/rubysl/syck/implicit.c +2990 -0
- data/ext/rubysl/syck/node.c +407 -0
- data/ext/rubysl/syck/rubyext.c +2306 -0
- data/ext/rubysl/syck/syck.c +524 -0
- data/ext/rubysl/syck/syck.h +453 -0
- data/ext/rubysl/syck/token.c +2724 -0
- data/ext/rubysl/syck/yaml2byte.c +259 -0
- data/ext/rubysl/syck/yamlbyte.h +171 -0
- data/lib/rubysl/yaml/version.rb +1 -1
- data/lib/rubysl/yaml/yaml.rb +101 -55
- data/lib/syck.rb +491 -0
- data/lib/syck/baseemitter.rb +242 -0
- data/lib/syck/basenode.rb +227 -0
- data/lib/syck/constants.rb +45 -0
- data/lib/syck/encoding.rb +35 -0
- data/lib/syck/error.rb +34 -0
- data/lib/syck/loader.rb +14 -0
- data/lib/syck/rubytypes.rb +467 -0
- data/lib/syck/stream.rb +41 -0
- data/lib/syck/tag.rb +95 -0
- data/lib/syck/types.rb +192 -0
- data/lib/syck/yamlnode.rb +54 -0
- data/lib/syck/ypath.rb +54 -0
- data/lib/yaml/dbm.rb +78 -13
- data/lib/yaml/store.rb +5 -10
- data/rubysl-yaml.gemspec +2 -0
- metadata +56 -15
- data/lib/yaml/syck.rb +0 -53
@@ -0,0 +1,453 @@
|
|
1
|
+
/*
|
2
|
+
* syck.h
|
3
|
+
*
|
4
|
+
* $Author: naruse $
|
5
|
+
*
|
6
|
+
* Copyright (C) 2003 why the lucky stiff
|
7
|
+
*/
|
8
|
+
|
9
|
+
#ifndef SYCK_H
|
10
|
+
#define SYCK_H
|
11
|
+
|
12
|
+
#define SYCK_YAML_MAJOR 1
|
13
|
+
#define SYCK_YAML_MINOR 0
|
14
|
+
|
15
|
+
#define YAML_DOMAIN "yaml.org,2002"
|
16
|
+
|
17
|
+
#include <stdio.h>
|
18
|
+
#include <stdlib.h>
|
19
|
+
#include <ctype.h>
|
20
|
+
#include "ruby/st.h"
|
21
|
+
|
22
|
+
#if defined(__cplusplus)
|
23
|
+
extern "C" {
|
24
|
+
#endif
|
25
|
+
|
26
|
+
/*
|
27
|
+
* Memory Allocation
|
28
|
+
*/
|
29
|
+
#if defined(HAVE_ALLOCA_H) && !defined(__GNUC__)
|
30
|
+
#include <alloca.h>
|
31
|
+
#endif
|
32
|
+
|
33
|
+
#ifdef DEBUG
|
34
|
+
void syck_assert( const char *, unsigned, const char * );
|
35
|
+
# define ASSERT(f) \
|
36
|
+
(( f ) ? (void)0 : syck_assert( __FILE__, __LINE__, #f ))
|
37
|
+
#else
|
38
|
+
# define ASSERT(f) ((void)0)
|
39
|
+
#endif
|
40
|
+
|
41
|
+
#ifndef NULL
|
42
|
+
# define NULL (void *)0
|
43
|
+
#endif
|
44
|
+
|
45
|
+
#define ALLOC_CT 8
|
46
|
+
#define SYCK_BUFFERSIZE 4096
|
47
|
+
#define S_ALLOC_N(type,n) (type*)malloc(sizeof(type)*(n))
|
48
|
+
#define S_ALLOC(type) (type*)malloc(sizeof(type))
|
49
|
+
#define S_REALLOC_N(var,type,n) (var)=(type*)realloc((char*)(var),sizeof(type)*(n))
|
50
|
+
#define S_FREE(n) if (n) { free(n); n = NULL; }
|
51
|
+
|
52
|
+
#define S_ALLOCA_N(type,n) (type*)alloca(sizeof(type)*(n))
|
53
|
+
|
54
|
+
#define S_MEMZERO(p,type,n) memset((p), 0, sizeof(type)*(n))
|
55
|
+
#define S_MEMCPY(p1,p2,type,n) memcpy((p1), (p2), sizeof(type)*(n))
|
56
|
+
#define S_MEMMOVE(p1,p2,type,n) memmove((p1), (p2), sizeof(type)*(n))
|
57
|
+
#define S_MEMCMP(p1,p2,type,n) memcmp((p1), (p2), sizeof(type)*(n))
|
58
|
+
|
59
|
+
#define BLOCK_FOLD 10
|
60
|
+
#define BLOCK_LIT 20
|
61
|
+
#define BLOCK_PLAIN 30
|
62
|
+
#define NL_CHOMP 40
|
63
|
+
#define NL_KEEP 50
|
64
|
+
|
65
|
+
/*
|
66
|
+
* Node definitions
|
67
|
+
*/
|
68
|
+
#ifndef ST_DATA_T_DEFINED
|
69
|
+
typedef long st_data_t;
|
70
|
+
#endif
|
71
|
+
|
72
|
+
#define SYMID st_data_t
|
73
|
+
|
74
|
+
typedef struct _syck_node SyckNode;
|
75
|
+
|
76
|
+
enum syck_kind_tag {
|
77
|
+
syck_map_kind,
|
78
|
+
syck_seq_kind,
|
79
|
+
syck_str_kind
|
80
|
+
};
|
81
|
+
|
82
|
+
enum map_part {
|
83
|
+
map_key,
|
84
|
+
map_value
|
85
|
+
};
|
86
|
+
|
87
|
+
enum map_style {
|
88
|
+
map_none,
|
89
|
+
map_inline
|
90
|
+
};
|
91
|
+
|
92
|
+
enum seq_style {
|
93
|
+
seq_none,
|
94
|
+
seq_inline
|
95
|
+
};
|
96
|
+
|
97
|
+
enum scalar_style {
|
98
|
+
scalar_none,
|
99
|
+
scalar_1quote,
|
100
|
+
scalar_2quote,
|
101
|
+
scalar_fold,
|
102
|
+
scalar_literal,
|
103
|
+
scalar_plain
|
104
|
+
};
|
105
|
+
|
106
|
+
/*
|
107
|
+
* Node metadata struct
|
108
|
+
*/
|
109
|
+
struct _syck_node {
|
110
|
+
/* Symbol table ID */
|
111
|
+
SYMID id;
|
112
|
+
/* Underlying kind */
|
113
|
+
enum syck_kind_tag kind;
|
114
|
+
/* Fully qualified tag-uri for type */
|
115
|
+
char *type_id;
|
116
|
+
/* Anchor name */
|
117
|
+
char *anchor;
|
118
|
+
union {
|
119
|
+
/* Storage for map data */
|
120
|
+
struct SyckMap {
|
121
|
+
enum map_style style;
|
122
|
+
SYMID *keys;
|
123
|
+
SYMID *values;
|
124
|
+
long capa;
|
125
|
+
long idx;
|
126
|
+
} *pairs;
|
127
|
+
/* Storage for sequence data */
|
128
|
+
struct SyckSeq {
|
129
|
+
enum seq_style style;
|
130
|
+
SYMID *items;
|
131
|
+
long capa;
|
132
|
+
long idx;
|
133
|
+
} *list;
|
134
|
+
/* Storage for string data */
|
135
|
+
struct SyckStr {
|
136
|
+
enum scalar_style style;
|
137
|
+
char *ptr;
|
138
|
+
long len;
|
139
|
+
} *str;
|
140
|
+
} data;
|
141
|
+
/* Shortcut node */
|
142
|
+
void *shortcut;
|
143
|
+
};
|
144
|
+
|
145
|
+
/*
|
146
|
+
* Parser definitions
|
147
|
+
*/
|
148
|
+
typedef struct _syck_parser SyckParser;
|
149
|
+
typedef struct _syck_file SyckIoFile;
|
150
|
+
typedef struct _syck_str SyckIoStr;
|
151
|
+
typedef struct _syck_level SyckLevel;
|
152
|
+
|
153
|
+
typedef SYMID (*SyckNodeHandler)(SyckParser *, SyckNode *);
|
154
|
+
typedef void (*SyckErrorHandler)(SyckParser *, const char *);
|
155
|
+
typedef SyckNode * (*SyckBadAnchorHandler)(SyckParser *, char *);
|
156
|
+
typedef long (*SyckIoFileRead)(char *, SyckIoFile *, long, long);
|
157
|
+
typedef long (*SyckIoStrRead)(char *, SyckIoStr *, long, long);
|
158
|
+
|
159
|
+
enum syck_io_type {
|
160
|
+
syck_io_str,
|
161
|
+
syck_io_file
|
162
|
+
};
|
163
|
+
|
164
|
+
enum syck_parser_input {
|
165
|
+
syck_yaml_utf8,
|
166
|
+
syck_yaml_utf16,
|
167
|
+
syck_yaml_utf32,
|
168
|
+
syck_bytecode_utf8
|
169
|
+
};
|
170
|
+
|
171
|
+
enum syck_level_status {
|
172
|
+
syck_lvl_header,
|
173
|
+
syck_lvl_doc,
|
174
|
+
syck_lvl_open,
|
175
|
+
syck_lvl_seq,
|
176
|
+
syck_lvl_map,
|
177
|
+
syck_lvl_block,
|
178
|
+
syck_lvl_str,
|
179
|
+
syck_lvl_iseq,
|
180
|
+
syck_lvl_imap,
|
181
|
+
syck_lvl_end,
|
182
|
+
syck_lvl_pause,
|
183
|
+
syck_lvl_anctag,
|
184
|
+
syck_lvl_mapx,
|
185
|
+
syck_lvl_seqx
|
186
|
+
};
|
187
|
+
|
188
|
+
/*
|
189
|
+
* Parser structs
|
190
|
+
*/
|
191
|
+
struct _syck_file {
|
192
|
+
/* File pointer */
|
193
|
+
FILE *ptr;
|
194
|
+
/* Function which FILE -> buffer */
|
195
|
+
SyckIoFileRead read;
|
196
|
+
};
|
197
|
+
|
198
|
+
struct _syck_str {
|
199
|
+
/* String buffer pointers */
|
200
|
+
char *beg, *ptr, *end;
|
201
|
+
/* Function which string -> buffer */
|
202
|
+
SyckIoStrRead read;
|
203
|
+
};
|
204
|
+
|
205
|
+
struct _syck_level {
|
206
|
+
/* Indent */
|
207
|
+
int spaces;
|
208
|
+
/* Counts nodes emitted at this level, useful for parsing
|
209
|
+
* keys and pairs in bytecode */
|
210
|
+
int ncount;
|
211
|
+
/* Does node have anchors or tags? */
|
212
|
+
int anctag;
|
213
|
+
/* Domain prefixing at the given level */
|
214
|
+
char *domain;
|
215
|
+
/* Keeps a node status */
|
216
|
+
enum syck_level_status status;
|
217
|
+
};
|
218
|
+
|
219
|
+
struct _syck_parser {
|
220
|
+
/* Root node */
|
221
|
+
SYMID root, root_on_error;
|
222
|
+
/* Implicit typing flag */
|
223
|
+
int implicit_typing, taguri_expansion;
|
224
|
+
/* Scripting language function to handle nodes */
|
225
|
+
SyckNodeHandler handler;
|
226
|
+
/* Error handler */
|
227
|
+
SyckErrorHandler error_handler;
|
228
|
+
/* InvalidAnchor handler */
|
229
|
+
SyckBadAnchorHandler bad_anchor_handler;
|
230
|
+
/* Parser input type */
|
231
|
+
enum syck_parser_input input_type;
|
232
|
+
/* IO type */
|
233
|
+
enum syck_io_type io_type;
|
234
|
+
/* Custom buffer size */
|
235
|
+
size_t bufsize;
|
236
|
+
/* Buffer pointers */
|
237
|
+
char *buffer, *linectptr, *lineptr, *toktmp, *token, *cursor, *marker, *limit;
|
238
|
+
/* Line counter */
|
239
|
+
int linect;
|
240
|
+
/* Last token from yylex() */
|
241
|
+
int last_token;
|
242
|
+
/* Force a token upon next call to yylex() */
|
243
|
+
int force_token;
|
244
|
+
/* EOF flag */
|
245
|
+
int eof;
|
246
|
+
union {
|
247
|
+
SyckIoFile *file;
|
248
|
+
SyckIoStr *str;
|
249
|
+
} io;
|
250
|
+
/* Symbol table for anchors */
|
251
|
+
st_table *anchors, *bad_anchors;
|
252
|
+
/* Optional symbol table for SYMIDs */
|
253
|
+
st_table *syms;
|
254
|
+
/* Levels of indentation */
|
255
|
+
SyckLevel *levels;
|
256
|
+
int lvl_idx;
|
257
|
+
int lvl_capa;
|
258
|
+
/* Pointer for extension's use */
|
259
|
+
void *bonus;
|
260
|
+
};
|
261
|
+
|
262
|
+
/*
|
263
|
+
* Emitter definitions
|
264
|
+
*/
|
265
|
+
typedef struct _syck_emitter SyckEmitter;
|
266
|
+
typedef struct _syck_emitter_node SyckEmitterNode;
|
267
|
+
|
268
|
+
typedef void (*SyckOutputHandler)(SyckEmitter *, char *, long);
|
269
|
+
typedef void (*SyckEmitterHandler)(SyckEmitter *, st_data_t);
|
270
|
+
|
271
|
+
enum doc_stage {
|
272
|
+
doc_open,
|
273
|
+
doc_processing
|
274
|
+
};
|
275
|
+
|
276
|
+
/*
|
277
|
+
* Emitter struct
|
278
|
+
*/
|
279
|
+
struct _syck_emitter {
|
280
|
+
/* Headerless doc flag */
|
281
|
+
int headless;
|
282
|
+
/* Force header? */
|
283
|
+
int use_header;
|
284
|
+
/* Force version? */
|
285
|
+
int use_version;
|
286
|
+
/* Sort hash keys */
|
287
|
+
int sort_keys;
|
288
|
+
/* Anchor format */
|
289
|
+
char *anchor_format;
|
290
|
+
/* Explicit typing on all collections? */
|
291
|
+
int explicit_typing;
|
292
|
+
/* Best width on folded scalars */
|
293
|
+
int best_width;
|
294
|
+
/* Use literal[1] or folded[2] blocks on all text? */
|
295
|
+
enum scalar_style style;
|
296
|
+
/* Stage of written document */
|
297
|
+
enum doc_stage stage;
|
298
|
+
/* Level counter */
|
299
|
+
int level;
|
300
|
+
/* Default indentation */
|
301
|
+
int indent;
|
302
|
+
/* Object ignore ID */
|
303
|
+
SYMID ignore_id;
|
304
|
+
/* Symbol table for anchors */
|
305
|
+
st_table *markers, *anchors, *anchored;
|
306
|
+
/* Custom buffer size */
|
307
|
+
size_t bufsize;
|
308
|
+
/* Buffer */
|
309
|
+
char *buffer, *marker;
|
310
|
+
/* Absolute position of the buffer */
|
311
|
+
long bufpos;
|
312
|
+
/* Handler for emitter nodes */
|
313
|
+
SyckEmitterHandler emitter_handler;
|
314
|
+
/* Handler for output */
|
315
|
+
SyckOutputHandler output_handler;
|
316
|
+
/* Levels of indentation */
|
317
|
+
SyckLevel *levels;
|
318
|
+
int lvl_idx;
|
319
|
+
int lvl_capa;
|
320
|
+
/* Pointer for extension's use */
|
321
|
+
void *bonus;
|
322
|
+
};
|
323
|
+
|
324
|
+
/*
|
325
|
+
* Emitter node metadata struct
|
326
|
+
*/
|
327
|
+
struct _syck_emitter_node {
|
328
|
+
/* Node buffer position */
|
329
|
+
long pos;
|
330
|
+
/* Current indent */
|
331
|
+
long indent;
|
332
|
+
/* Collection? */
|
333
|
+
int is_shortcut;
|
334
|
+
};
|
335
|
+
|
336
|
+
/*
|
337
|
+
* Handler prototypes
|
338
|
+
*/
|
339
|
+
SYMID syck_hdlr_add_node( SyckParser *, SyckNode * );
|
340
|
+
SyckNode *syck_hdlr_add_anchor( SyckParser *, char *, SyckNode * );
|
341
|
+
void syck_hdlr_remove_anchor( SyckParser *, char * );
|
342
|
+
SyckNode *syck_hdlr_get_anchor( SyckParser *, char * );
|
343
|
+
void syck_add_transfer( char *, SyckNode *, int );
|
344
|
+
char *syck_xprivate( const char *, int );
|
345
|
+
char *syck_taguri( const char *, const char *, int );
|
346
|
+
int syck_tagcmp( const char *, const char * );
|
347
|
+
int syck_add_sym( SyckParser *, void * );
|
348
|
+
int syck_lookup_sym( SyckParser *, SYMID, void ** );
|
349
|
+
int syck_try_implicit( SyckNode * );
|
350
|
+
char *syck_type_id_to_uri( const char * );
|
351
|
+
void try_tag_implicit( SyckNode *, int );
|
352
|
+
const char *syck_match_implicit( const char *, size_t );
|
353
|
+
|
354
|
+
/*
|
355
|
+
* API prototypes
|
356
|
+
*/
|
357
|
+
char *syck_strndup( const char *, long );
|
358
|
+
long syck_io_file_read( char *, SyckIoFile *, long, long );
|
359
|
+
long syck_io_str_read( char *, SyckIoStr *, long, long );
|
360
|
+
char *syck_base64enc( char *, long );
|
361
|
+
char *syck_base64dec( char *, long );
|
362
|
+
SyckEmitter *syck_new_emitter(void);
|
363
|
+
SYMID syck_emitter_mark_node( SyckEmitter *, st_data_t );
|
364
|
+
void syck_emitter_ignore_id( SyckEmitter *, SYMID );
|
365
|
+
void syck_output_handler( SyckEmitter *, SyckOutputHandler );
|
366
|
+
void syck_emitter_handler( SyckEmitter *, SyckEmitterHandler );
|
367
|
+
void syck_free_emitter( SyckEmitter * );
|
368
|
+
void syck_emitter_clear( SyckEmitter * );
|
369
|
+
void syck_emitter_write( SyckEmitter *, const char *, long );
|
370
|
+
void syck_emitter_escape( SyckEmitter *, const char *, long );
|
371
|
+
void syck_emitter_flush( SyckEmitter *, long );
|
372
|
+
void syck_emit( SyckEmitter *, st_data_t );
|
373
|
+
void syck_emit_scalar( SyckEmitter *, const char *, enum scalar_style, int, int, char, const char *, long );
|
374
|
+
void syck_emit_1quoted( SyckEmitter *, int, const char *, long );
|
375
|
+
void syck_emit_2quoted( SyckEmitter *, int, const char *, long );
|
376
|
+
void syck_emit_folded( SyckEmitter *, int, char, const char *, long );
|
377
|
+
void syck_emit_literal( SyckEmitter *, char, const char *, long );
|
378
|
+
void syck_emit_seq( SyckEmitter *, const char *, enum seq_style );
|
379
|
+
void syck_emit_item( SyckEmitter *, st_data_t );
|
380
|
+
void syck_emit_map( SyckEmitter *, const char *, enum map_style );
|
381
|
+
void syck_emit_end( SyckEmitter * );
|
382
|
+
void syck_emit_tag( SyckEmitter *, const char *, const char * );
|
383
|
+
void syck_emit_indent( SyckEmitter * );
|
384
|
+
SyckLevel *syck_emitter_current_level( SyckEmitter * );
|
385
|
+
SyckLevel *syck_emitter_parent_level( SyckEmitter * );
|
386
|
+
void syck_emitter_pop_level( SyckEmitter * );
|
387
|
+
void syck_emitter_add_level( SyckEmitter *, int, enum syck_level_status );
|
388
|
+
void syck_emitter_reset_levels( SyckEmitter * );
|
389
|
+
SyckParser *syck_new_parser(void);
|
390
|
+
void syck_free_parser( SyckParser * );
|
391
|
+
void syck_parser_set_root_on_error( SyckParser *, SYMID );
|
392
|
+
void syck_parser_implicit_typing( SyckParser *, int );
|
393
|
+
void syck_parser_taguri_expansion( SyckParser *, int );
|
394
|
+
int syck_scan_scalar( int, const char *, long );
|
395
|
+
void syck_parser_handler( SyckParser *, SyckNodeHandler );
|
396
|
+
void syck_parser_error_handler( SyckParser *, SyckErrorHandler );
|
397
|
+
void syck_parser_bad_anchor_handler( SyckParser *, SyckBadAnchorHandler );
|
398
|
+
void syck_parser_set_input_type( SyckParser *, enum syck_parser_input );
|
399
|
+
void syck_parser_file( SyckParser *, FILE *, SyckIoFileRead );
|
400
|
+
void syck_parser_str( SyckParser *, char *, long, SyckIoStrRead );
|
401
|
+
void syck_parser_str_auto( SyckParser *, char *, SyckIoStrRead );
|
402
|
+
SyckLevel *syck_parser_current_level( SyckParser * );
|
403
|
+
void syck_parser_add_level( SyckParser *, int, enum syck_level_status );
|
404
|
+
void syck_parser_pop_level( SyckParser * );
|
405
|
+
void free_any_io( SyckParser * );
|
406
|
+
long syck_parser_read( SyckParser * );
|
407
|
+
long syck_parser_readlen( SyckParser *, long );
|
408
|
+
SYMID syck_parse( SyckParser * );
|
409
|
+
void syck_default_error_handler( SyckParser *, const char * );
|
410
|
+
SYMID syck_yaml2byte_handler( SyckParser *, SyckNode * );
|
411
|
+
char *syck_yaml2byte( char * );
|
412
|
+
|
413
|
+
/*
|
414
|
+
* Allocation prototypes
|
415
|
+
*/
|
416
|
+
SyckNode *syck_alloc_map(void);
|
417
|
+
SyckNode *syck_alloc_seq(void);
|
418
|
+
SyckNode *syck_alloc_str(void);
|
419
|
+
void syck_free_node( SyckNode * );
|
420
|
+
void syck_free_members( SyckNode * );
|
421
|
+
SyckNode *syck_new_str( const char *, enum scalar_style );
|
422
|
+
SyckNode *syck_new_str2( const char *, long, enum scalar_style );
|
423
|
+
void syck_replace_str( SyckNode *, char *, enum scalar_style );
|
424
|
+
void syck_replace_str2( SyckNode *, char *, long, enum scalar_style );
|
425
|
+
void syck_str_blow_away_commas( SyckNode * );
|
426
|
+
char *syck_str_read( SyckNode * );
|
427
|
+
SyckNode *syck_new_map( SYMID, SYMID );
|
428
|
+
void syck_map_empty( SyckNode * );
|
429
|
+
void syck_map_add( SyckNode *, SYMID, SYMID );
|
430
|
+
SYMID syck_map_read( SyckNode *, enum map_part, long );
|
431
|
+
void syck_map_assign( SyckNode *, enum map_part, long, SYMID );
|
432
|
+
long syck_map_count( SyckNode * );
|
433
|
+
void syck_map_update( SyckNode *, SyckNode * );
|
434
|
+
SyckNode *syck_new_seq( SYMID );
|
435
|
+
void syck_seq_empty( SyckNode * );
|
436
|
+
void syck_seq_add( SyckNode *, SYMID );
|
437
|
+
void syck_seq_assign( SyckNode *, long, SYMID );
|
438
|
+
SYMID syck_seq_read( SyckNode *, long );
|
439
|
+
long syck_seq_count( SyckNode * );
|
440
|
+
|
441
|
+
/*
|
442
|
+
* Lexer prototypes
|
443
|
+
*/
|
444
|
+
void syckerror( const char * );
|
445
|
+
int syckparse( void * );
|
446
|
+
union YYSTYPE;
|
447
|
+
int sycklex( union YYSTYPE *, SyckParser * );
|
448
|
+
|
449
|
+
#if defined(__cplusplus)
|
450
|
+
} /* extern "C" { */
|
451
|
+
#endif
|
452
|
+
|
453
|
+
#endif /* ifndef SYCK_H */
|