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,259 @@
|
|
1
|
+
/*
|
2
|
+
* yaml2byte.c
|
3
|
+
*
|
4
|
+
* $Author: nobu $
|
5
|
+
*
|
6
|
+
* Copyright (C) 2003 why the lucky stiff, clark evans
|
7
|
+
*
|
8
|
+
* WARNING WARNING WARNING --- THIS IS *NOT JUST* PLAYING
|
9
|
+
* ANYMORE! -- WHY HAS EMBRACED THIS AS THE REAL THING!
|
10
|
+
*/
|
11
|
+
#include "ruby/ruby.h"
|
12
|
+
#include <syck.h>
|
13
|
+
#include <assert.h>
|
14
|
+
#define YAMLBYTE_UTF8
|
15
|
+
#include "yamlbyte.h"
|
16
|
+
|
17
|
+
#include <stdio.h>
|
18
|
+
#define TRACE0(a) \
|
19
|
+
do { printf(a); printf("\n"); fflush(stdout); } while(0)
|
20
|
+
#define TRACE1(a,b) \
|
21
|
+
do { printf(a,b); printf("\n"); fflush(stdout); } while(0)
|
22
|
+
#define TRACE2(a,b,c) \
|
23
|
+
do { printf(a,b,c); printf("\n"); fflush(stdout); } while(0)
|
24
|
+
#define TRACE3(a,b,c,d) \
|
25
|
+
do { printf(a,b,c,d); printf("\n"); fflush(stdout); } while(0)
|
26
|
+
|
27
|
+
/* Reinvent the wheel... */
|
28
|
+
#define CHUNKSIZE 64
|
29
|
+
#define HASH ((long)0xCAFECAFE)
|
30
|
+
typedef struct {
|
31
|
+
long hash;
|
32
|
+
char *buffer;
|
33
|
+
long length;
|
34
|
+
long remaining;
|
35
|
+
int printed;
|
36
|
+
} bytestring_t;
|
37
|
+
bytestring_t *bytestring_alloc(void) {
|
38
|
+
bytestring_t *ret;
|
39
|
+
/*TRACE0("bytestring_alloc()");*/
|
40
|
+
ret = S_ALLOC(bytestring_t);
|
41
|
+
ret->hash = HASH;
|
42
|
+
ret->length = CHUNKSIZE;
|
43
|
+
ret->remaining = ret->length;
|
44
|
+
ret->buffer = S_ALLOC_N(char, ret->length + 1 );
|
45
|
+
ret->buffer[0] = 0;
|
46
|
+
ret->printed = 0;
|
47
|
+
return ret;
|
48
|
+
}
|
49
|
+
void bytestring_append(bytestring_t *str, char code,
|
50
|
+
char *start, char *finish)
|
51
|
+
{
|
52
|
+
long grow;
|
53
|
+
long length = 2; /* CODE + LF */
|
54
|
+
char *curr;
|
55
|
+
assert(str && HASH == str->hash);
|
56
|
+
/*TRACE0("bytestring_append()");*/
|
57
|
+
if(start) {
|
58
|
+
if(!finish)
|
59
|
+
finish = start + strlen(start);
|
60
|
+
length += (finish-start);
|
61
|
+
}
|
62
|
+
if(length > str->remaining) {
|
63
|
+
grow = (length - str->remaining) + CHUNKSIZE;
|
64
|
+
str->remaining += grow;
|
65
|
+
str->length += grow;
|
66
|
+
S_REALLOC_N( str->buffer, char, str->length + 1 );
|
67
|
+
assert(str->buffer);
|
68
|
+
}
|
69
|
+
curr = str->buffer + (str->length - str->remaining);
|
70
|
+
*curr = code;
|
71
|
+
curr += 1;
|
72
|
+
if(start)
|
73
|
+
while(start < finish)
|
74
|
+
*curr ++ = *start ++;
|
75
|
+
*curr = '\n';
|
76
|
+
curr += 1;
|
77
|
+
*curr = 0;
|
78
|
+
str->remaining = str->remaining - length;
|
79
|
+
assert( (str->buffer + str->length) - str->remaining );
|
80
|
+
}
|
81
|
+
void bytestring_extend(bytestring_t *str, bytestring_t *ext)
|
82
|
+
{
|
83
|
+
char *from;
|
84
|
+
char *curr;
|
85
|
+
char *stop;
|
86
|
+
long grow;
|
87
|
+
long length;
|
88
|
+
assert(str && HASH == str->hash);
|
89
|
+
assert(ext && HASH == ext->hash);
|
90
|
+
if(ext->printed) {
|
91
|
+
assert(ext->buffer[0] ==YAMLBYTE_ANCHOR);
|
92
|
+
curr = ext->buffer;
|
93
|
+
while( '\n' != *curr)
|
94
|
+
curr++;
|
95
|
+
bytestring_append(str, YAMLBYTE_ALIAS, ext->buffer + 1, curr);
|
96
|
+
} else {
|
97
|
+
ext->printed = 1;
|
98
|
+
length = (ext->length - ext->remaining);
|
99
|
+
if(length > str->remaining) {
|
100
|
+
grow = (length - str->remaining) + CHUNKSIZE;
|
101
|
+
str->remaining += grow;
|
102
|
+
str->length += grow;
|
103
|
+
S_REALLOC_N( str->buffer, char, str->length + 1 );
|
104
|
+
}
|
105
|
+
curr = str->buffer + (str->length - str->remaining);
|
106
|
+
from = ext->buffer;
|
107
|
+
stop = ext->buffer + length;
|
108
|
+
while( from < stop )
|
109
|
+
*curr ++ = *from ++;
|
110
|
+
*curr = 0;
|
111
|
+
str->remaining = str->remaining - length;
|
112
|
+
assert( (str->buffer + str->length) - str->remaining );
|
113
|
+
}
|
114
|
+
}
|
115
|
+
|
116
|
+
/* convert SyckNode into yamlbyte_buffer_t objects */
|
117
|
+
SYMID
|
118
|
+
syck_yaml2byte_handler(p, n)
|
119
|
+
SyckParser *p;
|
120
|
+
SyckNode *n;
|
121
|
+
{
|
122
|
+
SYMID oid;
|
123
|
+
long i;
|
124
|
+
char ch;
|
125
|
+
char nextcode;
|
126
|
+
char *start;
|
127
|
+
char *current;
|
128
|
+
char *finish;
|
129
|
+
bytestring_t *val = NULL;
|
130
|
+
bytestring_t *sav = NULL;
|
131
|
+
void *data;
|
132
|
+
/*TRACE0("syck_yaml2byte_handler()");*/
|
133
|
+
val = bytestring_alloc();
|
134
|
+
if(n->anchor) bytestring_append(val,YAMLBYTE_ANCHOR, n->anchor, NULL);
|
135
|
+
if ( n->type_id )
|
136
|
+
{
|
137
|
+
if ( p->taguri_expansion )
|
138
|
+
{
|
139
|
+
bytestring_append(val,YAMLBYTE_TRANSFER, n->type_id, NULL);
|
140
|
+
}
|
141
|
+
else
|
142
|
+
{
|
143
|
+
char *type_tag = S_ALLOC_N( char, strlen( n->type_id ) + 1 );
|
144
|
+
type_tag[0] = '\0';
|
145
|
+
strcat( type_tag, "!" );
|
146
|
+
strcat( type_tag, n->type_id );
|
147
|
+
bytestring_append( val, YAMLBYTE_TRANSFER, type_tag, NULL);
|
148
|
+
S_FREE(type_tag);
|
149
|
+
}
|
150
|
+
}
|
151
|
+
switch (n->kind)
|
152
|
+
{
|
153
|
+
case syck_str_kind:
|
154
|
+
nextcode = YAMLBYTE_SCALAR;
|
155
|
+
start = n->data.str->ptr;
|
156
|
+
finish = start + n->data.str->len - 1;
|
157
|
+
current = start;
|
158
|
+
/*TRACE2("SCALAR: %s %d", start, n->data.str->len); */
|
159
|
+
while(1) {
|
160
|
+
ch = *current;
|
161
|
+
if('\n' == ch || 0 == ch || current > finish) {
|
162
|
+
if(current >= start) {
|
163
|
+
bytestring_append(val, nextcode, start, current);
|
164
|
+
nextcode = YAMLBYTE_CONTINUE;
|
165
|
+
}
|
166
|
+
start = current + 1;
|
167
|
+
if(current > finish)
|
168
|
+
{
|
169
|
+
break;
|
170
|
+
}
|
171
|
+
else if('\n' == ch )
|
172
|
+
{
|
173
|
+
bytestring_append(val,YAMLBYTE_NEWLINE,NULL,NULL);
|
174
|
+
}
|
175
|
+
else if(0 == ch)
|
176
|
+
{
|
177
|
+
bytestring_append(val,YAMLBYTE_NULLCHAR,NULL,NULL);
|
178
|
+
}
|
179
|
+
else
|
180
|
+
{
|
181
|
+
assert("oops");
|
182
|
+
}
|
183
|
+
}
|
184
|
+
current += 1;
|
185
|
+
}
|
186
|
+
break;
|
187
|
+
case syck_seq_kind:
|
188
|
+
bytestring_append(val,YAMLBYTE_SEQUENCE,NULL,NULL);
|
189
|
+
for ( i = 0; i < n->data.list->idx; i++ )
|
190
|
+
{
|
191
|
+
oid = syck_seq_read( n, i );
|
192
|
+
if (syck_lookup_sym( p, oid, &data )) sav = data;
|
193
|
+
bytestring_extend(val, sav);
|
194
|
+
}
|
195
|
+
bytestring_append(val,YAMLBYTE_END_BRANCH,NULL,NULL);
|
196
|
+
break;
|
197
|
+
case syck_map_kind:
|
198
|
+
bytestring_append(val,YAMLBYTE_MAPPING,NULL,NULL);
|
199
|
+
for ( i = 0; i < n->data.pairs->idx; i++ )
|
200
|
+
{
|
201
|
+
oid = syck_map_read( n, map_key, i );
|
202
|
+
if (syck_lookup_sym( p, oid, &data )) sav = data;
|
203
|
+
bytestring_extend(val, sav);
|
204
|
+
oid = syck_map_read( n, map_value, i );
|
205
|
+
if (syck_lookup_sym( p, oid, &data )) sav = data;
|
206
|
+
bytestring_extend(val, sav);
|
207
|
+
}
|
208
|
+
bytestring_append(val,YAMLBYTE_END_BRANCH,NULL,NULL);
|
209
|
+
break;
|
210
|
+
}
|
211
|
+
oid = syck_add_sym( p, (char *) val );
|
212
|
+
/*TRACE1("Saving: %s", val->buffer );*/
|
213
|
+
return oid;
|
214
|
+
}
|
215
|
+
|
216
|
+
char *
|
217
|
+
syck_yaml2byte(char *yamlstr)
|
218
|
+
{
|
219
|
+
SYMID oid;
|
220
|
+
char *ret;
|
221
|
+
bytestring_t *sav;
|
222
|
+
void *data;
|
223
|
+
|
224
|
+
SyckParser *parser = syck_new_parser();
|
225
|
+
syck_parser_str_auto( parser, yamlstr, NULL );
|
226
|
+
syck_parser_handler( parser, syck_yaml2byte_handler );
|
227
|
+
syck_parser_error_handler( parser, NULL );
|
228
|
+
syck_parser_implicit_typing( parser, 1 );
|
229
|
+
syck_parser_taguri_expansion( parser, 1 );
|
230
|
+
oid = syck_parse( parser );
|
231
|
+
|
232
|
+
if ( syck_lookup_sym( parser, oid, &data ) ) {
|
233
|
+
sav = data;
|
234
|
+
ret = S_ALLOC_N( char, strlen( sav->buffer ) + 3 );
|
235
|
+
ret[0] = '\0';
|
236
|
+
strcat( ret, "D\n" );
|
237
|
+
strcat( ret, sav->buffer );
|
238
|
+
}
|
239
|
+
else
|
240
|
+
{
|
241
|
+
ret = NULL;
|
242
|
+
}
|
243
|
+
|
244
|
+
syck_free_parser( parser );
|
245
|
+
return ret;
|
246
|
+
}
|
247
|
+
|
248
|
+
#ifdef TEST_YBEXT
|
249
|
+
#include <stdio.h>
|
250
|
+
int main() {
|
251
|
+
char *yaml = "test: 1\nand: \"with new\\nline\\n\"\nalso: &3 three\nmore: *3";
|
252
|
+
printf("--- # YAML \n");
|
253
|
+
printf(yaml);
|
254
|
+
printf("\n...\n");
|
255
|
+
printf(syck_yaml2byte(yaml));
|
256
|
+
return 0;
|
257
|
+
}
|
258
|
+
#endif
|
259
|
+
|
@@ -0,0 +1,171 @@
|
|
1
|
+
/* yamlbyte.h
|
2
|
+
*
|
3
|
+
* The YAML bytecode "C" interface header file. See the YAML bytecode
|
4
|
+
* reference for bytecode sequence rules and for the meaning of each
|
5
|
+
* bytecode.
|
6
|
+
*/
|
7
|
+
|
8
|
+
#ifndef YAMLBYTE_H
|
9
|
+
#define YAMLBYTE_H
|
10
|
+
#include <stddef.h>
|
11
|
+
|
12
|
+
/* define what a character is */
|
13
|
+
typedef unsigned char yamlbyte_utf8_t;
|
14
|
+
typedef unsigned short yamlbyte_utf16_t;
|
15
|
+
#ifdef YAMLBYTE_UTF8
|
16
|
+
#ifdef YAMLBYTE_UTF16
|
17
|
+
#error Must only define YAMLBYTE_UTF8 or YAMLBYTE_UTF16
|
18
|
+
#endif
|
19
|
+
typedef yamlbyte_utf8_t yamlbyte_char_t;
|
20
|
+
#else
|
21
|
+
#ifdef YAMLBYTE_UTF16
|
22
|
+
typedef yamlbyte_utf16_t yamlbyte_char_t;
|
23
|
+
#else
|
24
|
+
#error Must define YAMLBYTE_UTF8 or YAMLBYTE_UTF16
|
25
|
+
#endif
|
26
|
+
#endif
|
27
|
+
|
28
|
+
/* specify list of bytecodes */
|
29
|
+
#define YAMLBYTE_FINISH ((yamlbyte_char_t) 0)
|
30
|
+
#define YAMLBYTE_DOCUMENT ((yamlbyte_char_t)'D')
|
31
|
+
#define YAMLBYTE_DIRECTIVE ((yamlbyte_char_t)'V')
|
32
|
+
#define YAMLBYTE_PAUSE ((yamlbyte_char_t)'P')
|
33
|
+
#define YAMLBYTE_MAPPING ((yamlbyte_char_t)'M')
|
34
|
+
#define YAMLBYTE_SEQUENCE ((yamlbyte_char_t)'Q')
|
35
|
+
#define YAMLBYTE_END_BRANCH ((yamlbyte_char_t)'E')
|
36
|
+
#define YAMLBYTE_SCALAR ((yamlbyte_char_t)'S')
|
37
|
+
#define YAMLBYTE_CONTINUE ((yamlbyte_char_t)'C')
|
38
|
+
#define YAMLBYTE_NEWLINE ((yamlbyte_char_t)'N')
|
39
|
+
#define YAMLBYTE_NULLCHAR ((yamlbyte_char_t)'Z')
|
40
|
+
#define YAMLBYTE_ANCHOR ((yamlbyte_char_t)'A')
|
41
|
+
#define YAMLBYTE_ALIAS ((yamlbyte_char_t)'R')
|
42
|
+
#define YAMLBYTE_TRANSFER ((yamlbyte_char_t)'T')
|
43
|
+
/* formatting bytecodes */
|
44
|
+
#define YAMLBYTE_COMMENT ((yamlbyte_char_t)'c')
|
45
|
+
#define YAMLBYTE_INDENT ((yamlbyte_char_t)'i')
|
46
|
+
#define YAMLBYTE_STYLE ((yamlbyte_char_t)'s')
|
47
|
+
/* other bytecodes */
|
48
|
+
#define YAMLBYTE_LINE_NUMBER ((yamlbyte_char_t)'#')
|
49
|
+
#define YAMLBYTE_WHOLE_SCALAR ((yamlbyte_char_t)'<')
|
50
|
+
#define YAMLBYTE_NOTICE ((yamlbyte_char_t)'!')
|
51
|
+
#define YAMLBYTE_SPAN ((yamlbyte_char_t)')')
|
52
|
+
#define YAMLBYTE_ALLOC ((yamlbyte_char_t)'@')
|
53
|
+
|
54
|
+
/* second level style bytecodes, ie "s>" */
|
55
|
+
#define YAMLBYTE_FLOW ((yamlbyte_char_t)'>')
|
56
|
+
#define YAMLBYTE_LITERAL ((yamlbyte_char_t)'|')
|
57
|
+
#define YAMLBYTE_BLOCK ((yamlbyte_char_t)'b')
|
58
|
+
#define YAMLBYTE_PLAIN ((yamlbyte_char_t)'p')
|
59
|
+
#define YAMLBYTE_INLINE_MAPPING ((yamlbyte_char_t)'{')
|
60
|
+
#define YAMLBYTE_INLINE_SEQUENCE ((yamlbyte_char_t)'[')
|
61
|
+
#define YAMLBYTE_SINGLE_QUOTED ((yamlbyte_char_t)39)
|
62
|
+
#define YAMLBYTE_DOUBLE_QUOTED ((yamlbyte_char_t)'"')
|
63
|
+
|
64
|
+
/*
|
65
|
+
* The "C" API has two variants, one based on instructions,
|
66
|
+
* with events delivered via pointers; and the other one
|
67
|
+
* is character based where one or more instructions are
|
68
|
+
* serialized into a buffer.
|
69
|
+
*
|
70
|
+
* Note: In the instruction based API, WHOLE_SCALAR does
|
71
|
+
* not have the '<here' marshalling stuff.
|
72
|
+
*/
|
73
|
+
|
74
|
+
typedef void * yamlbyte_consumer_t;
|
75
|
+
typedef void * yamlbyte_producer_t;
|
76
|
+
|
77
|
+
/* push and pull APIs need a way to communicate results */
|
78
|
+
typedef enum {
|
79
|
+
YAMLBYTE_OK = 0, /* proceed */
|
80
|
+
YAMLBYTE_E_MEMORY = 'M', /* could not allocate memory */
|
81
|
+
YAMLBYTE_E_READ = 'R', /* input stream read error */
|
82
|
+
YAMLBYTE_E_WRITE = 'W', /* output stream write error */
|
83
|
+
YAMLBYTE_E_OTHER = '?', /* some other error condition */
|
84
|
+
YAMLBYTE_E_PARSE = 'P', /* parse error, check bytecodes */
|
85
|
+
YAMLBYTE_MAX
|
86
|
+
} yamlbyte_result_t;
|
87
|
+
|
88
|
+
typedef const yamlbyte_char_t *yamlbyte_buff_t;
|
89
|
+
|
90
|
+
/*
|
91
|
+
* The "Instruction" API
|
92
|
+
*/
|
93
|
+
|
94
|
+
typedef struct yaml_instruction {
|
95
|
+
yamlbyte_char_t bytecode;
|
96
|
+
yamlbyte_buff_t start;
|
97
|
+
yamlbyte_buff_t finish; /* open range, *finish is _not_ part */
|
98
|
+
} *yamlbyte_inst_t;
|
99
|
+
|
100
|
+
/* producer pushes the instruction with one bytecode event to the
|
101
|
+
* consumer; if the consumer's result is not YAMLBYTE_OK, then
|
102
|
+
* the producer should stop */
|
103
|
+
typedef
|
104
|
+
yamlbyte_result_t
|
105
|
+
(*yamlbyte_push_t)(
|
106
|
+
yamlbyte_consumer_t self,
|
107
|
+
yamlbyte_inst_t inst
|
108
|
+
);
|
109
|
+
|
110
|
+
/* consumer pulls a bytecode instruction from the producer; in this
|
111
|
+
* case the instruction (and is buffer) are owned by the producer and
|
112
|
+
* will remain valid till the pull function is called once again;
|
113
|
+
* if the instruction is NULL, then there are no more results; and
|
114
|
+
* it is important to call the pull function till it returns NULL so
|
115
|
+
* that the producer can clean up its memory allocations */
|
116
|
+
typedef
|
117
|
+
yamlbyte_result_t
|
118
|
+
(*yamlbyte_pull_t)(
|
119
|
+
yamlbyte_producer_t self,
|
120
|
+
yamlbyte_inst_t *inst /* to be filled in by the producer */
|
121
|
+
);
|
122
|
+
|
123
|
+
/*
|
124
|
+
* Buffer based API
|
125
|
+
*/
|
126
|
+
|
127
|
+
/* producer pushes a null terminated buffer filled with one or more
|
128
|
+
* bytecode events to the consumer; if the consumer's result is not
|
129
|
+
* YAMLBYTE_OK, then the producer should stop */
|
130
|
+
typedef
|
131
|
+
yamlbyte_result_t
|
132
|
+
(*yamlbyte_pushbuff_t)(
|
133
|
+
yamlbyte_consumer_t self,
|
134
|
+
yamlbyte_buff_t buff
|
135
|
+
);
|
136
|
+
|
137
|
+
/* consumer pulls bytecode events from the producer; in this case
|
138
|
+
* the buffer is owned by the producer, and will remain valid till
|
139
|
+
* the pull function is called once again; if the buffer pointer
|
140
|
+
* is set to NULL, then there are no more results; it is important
|
141
|
+
* to call the pull function till it returns NULL so that the
|
142
|
+
* producer can clean up its memory allocations */
|
143
|
+
typedef
|
144
|
+
yamlbyte_result_t
|
145
|
+
(*yamlbyte_pullbuff_t)(
|
146
|
+
yamlbyte_producer_t self,
|
147
|
+
yamlbyte_buff_t *buff /* to be filled in by the producer */
|
148
|
+
);
|
149
|
+
|
150
|
+
/* convert a pull interface to a push interface; the reverse process
|
151
|
+
* requires threads and thus is language dependent */
|
152
|
+
#define YAMLBYTE_PULL2PUSH(pull,producer,push,consumer,result) \
|
153
|
+
do { \
|
154
|
+
yamlbyte_pullbuff_t _pull = (pull); \
|
155
|
+
yamlbyte_pushbuff_t _push = (push); \
|
156
|
+
yamlbyte_result_t _result = YAMLBYTE_OK; \
|
157
|
+
yamlbyte_producer_t _producer = (producer); \
|
158
|
+
yamlbyte_consumer_t _consumer = (consumer); \
|
159
|
+
while(1) { \
|
160
|
+
yamlbyte_buff_t buff = NULL; \
|
161
|
+
_result = _pull(_producer,&buff); \
|
162
|
+
if(YAMLBYTE_OK != result || NULL == buff) \
|
163
|
+
break; \
|
164
|
+
_result = _push(_consumer,buff); \
|
165
|
+
if(YAMLBYTE_OK != result) \
|
166
|
+
break; \
|
167
|
+
} \
|
168
|
+
(result) = _result; \
|
169
|
+
} while(0)
|
170
|
+
|
171
|
+
#endif
|
data/lib/rubysl/yaml/version.rb
CHANGED
data/lib/rubysl/yaml/yaml.rb
CHANGED
@@ -1,76 +1,122 @@
|
|
1
1
|
##
|
2
|
-
# The YAML module
|
3
|
-
# ruby. By default Psych is used but the old and unmaintained Syck may be
|
4
|
-
# chosen.
|
5
|
-
#
|
6
|
-
# See Psych or Syck for usage and documentation.
|
7
|
-
#
|
8
|
-
# To set the YAML engine to syck:
|
9
|
-
#
|
10
|
-
# YAML::ENGINE.yamler = 'syck'
|
11
|
-
#
|
12
|
-
# To set the YAML engine back to psych:
|
13
|
-
#
|
14
|
-
# YAML::ENGINE.yamler = 'psych'
|
15
|
-
|
16
|
-
module YAML
|
17
|
-
class EngineManager # :nodoc:
|
18
|
-
attr_reader :yamler
|
19
|
-
|
20
|
-
def initialize
|
21
|
-
@yamler = nil
|
22
|
-
end
|
2
|
+
# The YAML module is an alias of Psych, the YAML engine for Ruby.
|
23
3
|
|
24
|
-
|
25
|
-
|
26
|
-
end
|
4
|
+
begin
|
5
|
+
require 'psych'
|
27
6
|
|
28
|
-
|
29
|
-
|
7
|
+
module Psych
|
8
|
+
# For compatibility, deprecated
|
9
|
+
class EngineManager # :nodoc:
|
10
|
+
attr_reader :yamler # :nodoc:
|
30
11
|
|
31
|
-
|
12
|
+
def initialize # :nodoc:
|
13
|
+
@yamler = 'psych'
|
14
|
+
end
|
32
15
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
remove_method :to_yaml
|
37
|
-
alias :to_yaml :#{engine}_to_yaml
|
38
|
-
eorb
|
16
|
+
def syck? # :nodoc:
|
17
|
+
false
|
18
|
+
end
|
39
19
|
|
40
|
-
@yamler = engine
|
41
|
-
engine
|
42
20
|
end
|
21
|
+
|
22
|
+
ENGINE = EngineManager.new # :nodoc:
|
43
23
|
end
|
44
24
|
|
45
|
-
|
46
|
-
# Allows changing the current YAML engine. See YAML for details.
|
25
|
+
YAML = Psych # :nodoc:
|
47
26
|
|
48
|
-
|
49
|
-
end
|
27
|
+
rescue LoadError
|
50
28
|
|
51
|
-
if defined?(Psych)
|
52
|
-
engine = 'psych'
|
53
|
-
elsif defined?(Syck)
|
54
|
-
engine = 'syck'
|
55
|
-
else
|
56
29
|
begin
|
57
|
-
require '
|
58
|
-
|
30
|
+
require 'syck'
|
31
|
+
|
32
|
+
YAML = Syck
|
33
|
+
|
34
|
+
module YAML
|
35
|
+
|
36
|
+
# For compatibility, deprecated
|
37
|
+
class EngineManager # :nodoc:
|
38
|
+
attr_reader :yamler # :nodoc:
|
39
|
+
|
40
|
+
def initialize # :nodoc:
|
41
|
+
@yamler = 'syck'
|
42
|
+
end
|
43
|
+
|
44
|
+
def syck? # :nodoc:
|
45
|
+
true
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
ENGINE = EngineManager.new # :nodoc:
|
51
|
+
end
|
52
|
+
|
59
53
|
rescue LoadError
|
60
54
|
warn "#{caller[0]}:"
|
61
55
|
warn "It seems your ruby installation is missing psych (for YAML output)."
|
62
56
|
warn "To eliminate this warning, please install libyaml and reinstall your ruby."
|
63
|
-
|
64
|
-
engine = 'syck'
|
57
|
+
raise
|
65
58
|
end
|
66
59
|
end
|
67
60
|
|
68
|
-
|
69
|
-
|
70
|
-
|
61
|
+
# YAML Ain't Markup Language
|
62
|
+
#
|
63
|
+
# This module provides a Ruby interface for data serialization in YAML format.
|
64
|
+
#
|
65
|
+
# The underlying implementation is the libyaml wrapper Psych.
|
66
|
+
#
|
67
|
+
# == Usage
|
68
|
+
#
|
69
|
+
# Working with YAML can be very simple, for example:
|
70
|
+
#
|
71
|
+
# require 'yaml' # STEP ONE, REQUIRE YAML!
|
72
|
+
# # Parse a YAML string
|
73
|
+
# YAML.load("--- foo") #=> "foo"
|
74
|
+
#
|
75
|
+
# # Emit some YAML
|
76
|
+
# YAML.dump("foo") # => "--- foo\n...\n"
|
77
|
+
# { :a => 'b'}.to_yaml # => "---\n:a: b\n"
|
78
|
+
#
|
79
|
+
# == Security
|
80
|
+
#
|
81
|
+
# Do not use YAML to load untrusted data. Doing so is unsafe and could allow
|
82
|
+
# malicious input to execute arbitrary code inside your application. Please see
|
83
|
+
# doc/security.rdoc for more information.
|
84
|
+
#
|
85
|
+
# == History
|
86
|
+
#
|
87
|
+
# Syck was the original for YAML implementation in Ruby's standard library
|
88
|
+
# developed by why the lucky stiff.
|
89
|
+
#
|
90
|
+
# You can still use Syck, if you prefer, for parsing and emitting YAML, but you
|
91
|
+
# must install the 'syck' gem now in order to use it.
|
92
|
+
#
|
93
|
+
# In older Ruby versions, ie. <= 1.9, Syck is still provided, however it was
|
94
|
+
# completely removed with the release of Ruby 2.0.0.
|
95
|
+
#
|
96
|
+
# == More info
|
97
|
+
#
|
98
|
+
# For more advanced details on the implementation see Psych, and also check out
|
99
|
+
# http://yaml.org for spec details and other helpful information.
|
100
|
+
module YAML
|
101
|
+
# For compatibility, deprecated
|
102
|
+
class EngineManager # :nodoc:
|
103
|
+
# Psych is the default YAML implementation.
|
104
|
+
#
|
105
|
+
# This method is still present for compatibility.
|
106
|
+
#
|
107
|
+
# You may still use the Syck engine by installing
|
108
|
+
# the 'syck' gem and using the Syck constant.
|
109
|
+
def yamler= engine # :nodoc:
|
110
|
+
case engine
|
111
|
+
when 'syck'
|
112
|
+
@yamler = 'syck'
|
113
|
+
when 'psych'
|
114
|
+
@yamler = 'psych'
|
115
|
+
else
|
116
|
+
raise ArgumentError, "invalid YAML engine: #{engine}"
|
117
|
+
end
|
71
118
|
|
72
|
-
|
73
|
-
|
119
|
+
engine
|
120
|
+
end
|
121
|
+
end
|
74
122
|
end
|
75
|
-
|
76
|
-
YAML::ENGINE.yamler = engine
|