summaryrefslogtreecommitdiff
path: root/ext/syck
diff options
context:
space:
mode:
authorwhy <why@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-05-16 16:09:41 +0000
committerwhy <why@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-05-16 16:09:41 +0000
commitb02b4bb04831671c77dbd55eaf7e77e1629c03b5 (patch)
tree8311ecba8628f181bc0ce9e4d91dd34298a62b49 /ext/syck
parentc16bdcc5e1c10fa873e35c7e0b184f7f99340786 (diff)
* lib/yaml.rb: removed fallback to pure Ruby parser.
* lib/yaml/baseemitter.rb (indent_text): was forcing a mod value of zero at times, which kept some blocks from getting indentation. * lib/yaml/baseemitter.rb (node_text): rewriting folded scalars. * ext/syck/syck.h: reports style of scalars now, be they plain, block single-, or double-quoted. * ext/syck/syck.c: ditto. * ext/syck/gram.c: ditto. * ext/syck/node.c: ditto. * ext/syck/token.c: ditto. * ext/syck/rubyext.c (yaml_org_handler): symbols loaded only if scalar style is plain. * ext/syck/rubyext.c (yaml_org_handler): some empty strings were loaded as symbols. * test/yaml/test_yaml.rb (test_perl_regexp): updated test to match new regexp serialization. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@6334 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/syck')
-rw-r--r--ext/syck/MANIFEST1
-rw-r--r--ext/syck/gram.c2
-rw-r--r--ext/syck/gram.h2
-rw-r--r--ext/syck/node.c8
-rw-r--r--ext/syck/rubyext.c28
-rw-r--r--ext/syck/syck.h13
-rw-r--r--ext/syck/token.c132
7 files changed, 98 insertions, 88 deletions
diff --git a/ext/syck/MANIFEST b/ext/syck/MANIFEST
index bb126fa..d1e7ef4 100644
--- a/ext/syck/MANIFEST
+++ b/ext/syck/MANIFEST
@@ -1,4 +1,5 @@
MANIFEST
+depend
extconf.rb
bytecode.c
emitter.c
diff --git a/ext/syck/gram.c b/ext/syck/gram.c
index 0e01695..cf97516 100644
--- a/ext/syck/gram.c
+++ b/ext/syck/gram.c
@@ -99,7 +99,7 @@
#define YYLEX_PARAM parser
#define NULL_NODE(parser, node) \
- SyckNode *node = syck_new_str( "" ); \
+ SyckNode *node = syck_new_str( "", scalar_plain ); \
if ( ((SyckParser *)parser)->taguri_expansion == 1 ) \
{ \
node->type_id = syck_taguri( YAML_DOMAIN, "null", 4 ); \
diff --git a/ext/syck/gram.h b/ext/syck/gram.h
index d1e577b..4c0e199 100644
--- a/ext/syck/gram.h
+++ b/ext/syck/gram.h
@@ -63,7 +63,7 @@
#ifndef YYSTYPE
-#line 23 "gram.y"
+#line 33 "gram.y"
typedef union {
SYMID nodeId;
SyckNode *nodeData;
diff --git a/ext/syck/node.c b/ext/syck/node.c
index 86c4086..500ede2 100644
--- a/ext/syck/node.c
+++ b/ext/syck/node.c
@@ -83,6 +83,7 @@ syck_alloc_str()
s = S_ALLOC( struct SyckStr );
s->len = 0;
s->ptr = NULL;
+ s->style = scalar_none;
n = syck_alloc_node( syck_str_kind );
n->data.str = s;
@@ -91,19 +92,20 @@ syck_alloc_str()
}
SyckNode *
-syck_new_str( char *str )
+syck_new_str( char *str, enum scalar_style style )
{
- return syck_new_str2( str, strlen( str ) );
+ return syck_new_str2( str, strlen( str ), style );
}
SyckNode *
-syck_new_str2( char *str, long len )
+syck_new_str2( char *str, long len, enum scalar_style style )
{
SyckNode *n;
n = syck_alloc_str();
n->data.str->ptr = S_ALLOC_N( char, len + 1 );
n->data.str->len = len;
+ n->data.str->style = style;
memcpy( n->data.str->ptr, str, len );
n->data.str->ptr[len] = '\0';
diff --git a/ext/syck/rubyext.c b/ext/syck/rubyext.c
index d7219ef..3cd63ee 100644
--- a/ext/syck/rubyext.c
+++ b/ext/syck/rubyext.c
@@ -15,33 +15,25 @@
typedef struct RVALUE {
union {
+#if 0
struct {
unsigned long flags; /* always 0 for freed obj */
struct RVALUE *next;
} free;
+#endif
struct RBasic basic;
struct RObject object;
struct RClass klass;
- struct RFloat flonum;
- struct RString string;
+ /*struct RFloat flonum;*/
+ /*struct RString string;*/
struct RArray array;
- struct RRegexp regexp;
+ /*struct RRegexp regexp;*/
struct RHash hash;
- struct RData data;
+ /*struct RData data;*/
struct RStruct rstruct;
- struct RBignum bignum;
- struct RFile file;
-#if 0
- struct RNode node;
- struct RMatch match;
- struct RVarmap varmap;
- struct SCOPE scope;
-#endif
+ /*struct RBignum bignum;*/
+ /*struct RFile file;*/
} as;
-#ifdef GC_DEBUG
- char *file;
- int line;
-#endif
} RVALUE;
typedef struct {
@@ -558,7 +550,9 @@ yaml_org_handler( n, ref )
{
obj = rb_funcall( cDefaultKey, s_new, 0 );
}
- else if ( strncmp( n->data.str->ptr, ":", 1 ) == 0 )
+ else if ( n->data.str->style == scalar_plain &&
+ n->data.str->len > 1 &&
+ strncmp( n->data.str->ptr, ":", 1 ) == 0 )
{
obj = rb_funcall( oDefaultLoader, s_transfer, 2,
rb_str_new2( "ruby/sym" ),
diff --git a/ext/syck/syck.h b/ext/syck/syck.h
index 60c06c0..51604b4 100644
--- a/ext/syck/syck.h
+++ b/ext/syck/syck.h
@@ -84,6 +84,14 @@ enum map_part {
map_value
};
+enum scalar_style {
+ scalar_none,
+ scalar_plain,
+ scalar_1quote,
+ scalar_2quote,
+ scalar_block
+};
+
/*
* Node metadata struct
*/
@@ -112,6 +120,7 @@ struct _syck_node {
} *list;
/* Storage for string data */
struct SyckStr {
+ enum scalar_style style;
char *ptr;
long len;
} *str;
@@ -367,8 +376,8 @@ SyckNode *syck_alloc_seq();
SyckNode *syck_alloc_str();
void syck_free_node( SyckNode * );
void syck_free_members( SyckNode * );
-SyckNode *syck_new_str( char * );
-SyckNode *syck_new_str2( char *, long );
+SyckNode *syck_new_str( char *, enum scalar_style );
+SyckNode *syck_new_str2( char *, long, enum scalar_style );
void syck_str_blow_away_commas( SyckNode * );
char *syck_str_read( SyckNode * );
SyckNode *syck_new_map( SYMID, SYMID );
diff --git a/ext/syck/token.c b/ext/syck/token.c
index 5874c27..ac9986f 100644
--- a/ext/syck/token.c
+++ b/ext/syck/token.c
@@ -1,4 +1,4 @@
-/* Generated by re2c 0.5 on Tue Nov 25 12:10:28 2003 */
+/* Generated by re2c 0.5 on Thu May 13 01:45:26 2004 */
#line 1 "token.re"
/*
* token.re
@@ -122,6 +122,7 @@
YYCURSOR = YYTOKEN; \
n->data.str->ptr = qstr; \
n->data.str->len = qidx; \
+ n->data.str->style = scalar_plain; \
sycklval->nodeData = n; \
if ( parser->implicit_typing == 1 ) \
{ \
@@ -140,6 +141,7 @@
n->type_id = syck_strndup( "str", 3 ); \
n->data.str->ptr = qstr; \
n->data.str->len = qidx; \
+ n->data.str->style = scalar_block; \
if ( qidx > 0 ) \
{ \
if ( nlDoWhat != NL_KEEP ) \
@@ -257,7 +259,7 @@ sycklex_yaml_utf8( YYSTYPE *sycklval, SyckParser *parser )
return t;
}
-#line 276
+#line 278
if ( YYLINEPTR != YYCURSOR )
@@ -294,7 +296,7 @@ yy2: yyaccept = 0;
default: goto yy3;
}
yy3:
-#line 335
+#line 337
{ YYPOS(0);
goto Document;
}
@@ -306,13 +308,13 @@ yy4: yyaccept = 0;
}
yy5: yych = *++YYCURSOR;
yy6:
-#line 317
+#line 319
{ eat_comments( parser );
goto Header;
}
yy7: yych = *++YYCURSOR;
yy8:
-#line 321
+#line 323
{ SyckLevel *lvl = CURRENT_LEVEL();
ENSURE_YAML_IEND(lvl, -1);
YYPOS(0);
@@ -322,7 +324,7 @@ yy9: yyaccept = 1;
yych = *(YYMARKER = ++YYCURSOR);
goto yy18;
yy10:
-#line 327
+#line 329
{ GOBBLE_UP_YAML_INDENT( doc_level, YYTOKEN );
goto Header;
}
@@ -334,7 +336,7 @@ yy11: yych = *++YYCURSOR;
yy12: yych = *++YYCURSOR;
goto yy16;
yy13:
-#line 331
+#line 333
{ doc_level = YYCURSOR - YYLINEPTR;
goto Header;
}
@@ -382,7 +384,7 @@ yy22: yych = *++YYCURSOR;
}
yy23: yych = *++YYCURSOR;
yy24:
-#line 303
+#line 305
{ SyckLevel *lvl = CURRENT_LEVEL();
if ( lvl->status == syck_lvl_header )
{
@@ -422,7 +424,7 @@ yy29: yych = *++YYCURSOR;
}
yy30: yych = *++YYCURSOR;
yy31:
-#line 289
+#line 291
{ SyckLevel *lvl = CURRENT_LEVEL();
if ( lvl->status == syck_lvl_header )
{
@@ -449,7 +451,7 @@ yy34: yych = *++YYCURSOR;
default: goto yy20;
}
}
-#line 339
+#line 341
Document:
@@ -492,7 +494,7 @@ yy37: yyaccept = 0;
yych = *(YYMARKER = ++YYCURSOR);
goto yy90;
yy38:
-#line 353
+#line 355
{ /* Isolate spaces */
int indt_len;
GOBBLE_UP_YAML_INDENT( indt_len, YYTOKEN );
@@ -520,13 +522,13 @@ yy39: yych = *++YYCURSOR;
default: goto yy40;
}
yy40:
-#line 445
+#line 447
{ ENSURE_YAML_IOPEN(lvl, doc_level, 1);
goto Plain;
}
yy41: yych = *++YYCURSOR;
yy42:
-#line 375
+#line 377
{ ENSURE_YAML_IOPEN(lvl, doc_level, 1);
lvl = CURRENT_LEVEL();
ADD_LEVEL(lvl->spaces + 1, syck_lvl_inline);
@@ -534,7 +536,7 @@ yy42:
}
yy43: yych = *++YYCURSOR;
yy44:
-#line 381
+#line 383
{ POP_LEVEL();
return YYTOKEN[0];
}
@@ -684,16 +686,16 @@ yy48: yych = *++YYCURSOR;
}
yy49: yych = *++YYCURSOR;
yy50:
-#line 419
+#line 421
{ goto TransferMethod; }
yy51: yych = *++YYCURSOR;
yy52:
-#line 421
+#line 423
{ ENSURE_YAML_IOPEN(lvl, doc_level, 1);
goto SingleQuote; }
yy53: yych = *++YYCURSOR;
yy54:
-#line 424
+#line 426
{ ENSURE_YAML_IOPEN(lvl, doc_level, 1);
goto DoubleQuote; }
yy55: yyaccept = 1;
@@ -716,18 +718,18 @@ yy55: yyaccept = 1;
}
yy56: yych = *++YYCURSOR;
yy57:
-#line 434
+#line 436
{ eat_comments( parser );
goto Document;
}
yy58: yych = *++YYCURSOR;
goto yy64;
yy59:
-#line 438
+#line 440
{ goto Document; }
yy60: yych = *++YYCURSOR;
yy61:
-#line 440
+#line 442
{ ENSURE_YAML_IEND(lvl, -1);
YYPOS(0);
return 0;
@@ -767,7 +769,7 @@ yy67: YYCURSOR = YYMARKER;
}
yy68: yych = *++YYCURSOR;
yy69:
-#line 427
+#line 429
{ if ( is_newline( YYCURSOR - 1 ) )
{
YYCURSOR--;
@@ -853,7 +855,7 @@ yy74: switch(yych){
default: goto yy75;
}
yy75:
-#line 414
+#line 416
{ ENSURE_YAML_IOPEN(lvl, doc_level, 1);
sycklval->name = syck_strndup( YYTOKEN + 1, YYCURSOR - YYTOKEN - 1 );
return YAML_ALIAS;
@@ -925,7 +927,7 @@ yy77: switch(yych){
default: goto yy78;
}
yy78:
-#line 403
+#line 405
{ sycklval->name = syck_strndup( YYTOKEN + 1, YYCURSOR - YYTOKEN - 1 );
/*
@@ -938,7 +940,7 @@ yy78:
}
yy79: yych = *++YYCURSOR;
yy80:
-#line 389
+#line 391
{ ENSURE_YAML_IOPEN(lvl, YYTOKEN - YYLINEPTR, 1);
FORCE_NEXT_TOKEN(YAML_IOPEN);
if ( is_newline( YYCURSOR ) || is_newline( YYCURSOR - 1 ) )
@@ -966,7 +968,7 @@ yy83: yych = *++YYCURSOR;
}
yy84: yych = *++YYCURSOR;
yy85:
-#line 385
+#line 387
{ YYPOS(1);
return YYTOKEN[0];
}
@@ -999,7 +1001,7 @@ yy91: ++YYCURSOR;
default: goto yy67;
}
}
-#line 449
+#line 451
}
@@ -1106,14 +1108,14 @@ yy95: yyaccept = 0;
default: goto yy96;
}
yy96:
-#line 462
+#line 464
{ YYCURSOR = YYTOKTMP;
return YAML_DOCSEP;
}
yy97: yych = *++YYCURSOR;
goto yy101;
yy98:
-#line 460
+#line 462
{ goto Directive; }
yy99: yych = *++YYCURSOR;
goto yy96;
@@ -1365,10 +1367,10 @@ yy106: switch(yych){
default: goto yy107;
}
yy107:
-#line 458
+#line 460
{ goto Directive; }
}
-#line 465
+#line 467
}
@@ -1412,7 +1414,7 @@ yy110: yyaccept = 0;
yych = *(YYMARKER = ++YYCURSOR);
goto yy136;
yy111:
-#line 488
+#line 490
{ int indt_len, nl_count = 0;
SyckLevel *lvl;
char *tok = YYTOKEN;
@@ -1450,7 +1452,7 @@ yy112: yych = *++YYCURSOR;
default: goto yy113;
}
yy113:
-#line 542
+#line 544
{ QUOTECATS(qstr, qcapa, qidx, YYTOKEN, YYCURSOR - YYTOKEN);
goto Plain2;
}
@@ -1464,7 +1466,7 @@ yy114: yyaccept = 1;
}
yy115: yych = *++YYCURSOR;
yy116:
-#line 522
+#line 524
{ if ( plvl->status != syck_lvl_inline )
{
if ( *(YYCURSOR - 1) == ' ' || is_newline( YYCURSOR - 1 ) )
@@ -1490,17 +1492,17 @@ yy118: yych = *++YYCURSOR;
default: goto yy119;
}
yy119:
-#line 540
+#line 542
{ goto Plain3; }
yy120: yych = *++YYCURSOR;
yy121:
-#line 538
+#line 540
{ RETURN_IMPLICIT(); }
yy122: yych = *++YYCURSOR;
goto yy113;
yy123: yych = *++YYCURSOR;
yy124:
-#line 534
+#line 536
{ eat_comments( parser );
RETURN_IMPLICIT();
}
@@ -1525,7 +1527,7 @@ yy129: YYCURSOR = YYMARKER;
}
yy130: yych = *++YYCURSOR;
yy131:
-#line 520
+#line 522
{ RETURN_IMPLICIT(); }
yy132: ++YYCURSOR;
if(YYLIMIT == YYCURSOR) YYFILL(1);
@@ -1556,7 +1558,7 @@ yy137: ++YYCURSOR;
default: goto yy129;
}
}
-#line 546
+#line 548
}
@@ -1588,7 +1590,7 @@ yy140: yyaccept = 0;
yych = *(YYMARKER = ++YYCURSOR);
goto yy151;
yy141:
-#line 560
+#line 562
{ int indt_len;
int nl_count = 0;
SyckLevel *lvl;
@@ -1630,7 +1632,7 @@ yy142: yych = *++YYCURSOR;
default: goto yy143;
}
yy143:
-#line 615
+#line 618
{ QUOTECAT(qstr, qcapa, qidx, *(YYCURSOR - 1));
goto SingleQuote2;
}
@@ -1640,7 +1642,7 @@ yy144: yych = *++YYCURSOR;
default: goto yy145;
}
yy145:
-#line 600
+#line 602
{ SyckLevel *lvl;
SyckNode *n = syck_alloc_str();
lvl = CURRENT_LEVEL();
@@ -1652,6 +1654,7 @@ yy145:
n->type_id = syck_strndup( "str", 3 );
n->data.str->ptr = qstr;
n->data.str->len = qidx;
+ n->data.str->style = scalar_1quote;
sycklval->nodeData = n;
return YAML_PLAIN;
}
@@ -1661,7 +1664,7 @@ yy147: yych = *++YYCURSOR;
goto yy143;
yy148: yych = *++YYCURSOR;
yy149:
-#line 596
+#line 598
{ QUOTECAT(qstr, qcapa, qidx, '\'');
goto SingleQuote2;
}
@@ -1686,7 +1689,7 @@ yy153: YYCURSOR = YYMARKER;
case 0: goto yy141;
}
}
-#line 619
+#line 622
}
@@ -1723,7 +1726,7 @@ yy156: yyaccept = 0;
yych = *(YYMARKER = ++YYCURSOR);
goto yy178;
yy157:
-#line 637
+#line 640
{ int indt_len;
int nl_count = 0;
SyckLevel *lvl;
@@ -1769,7 +1772,7 @@ yy158: yych = *++YYCURSOR;
default: goto yy159;
}
yy159:
-#line 711
+#line 715
{ QUOTECAT(qstr, qcapa, qidx, *(YYCURSOR - 1));
goto DoubleQuote2;
}
@@ -1787,7 +1790,7 @@ yy160: yyaccept = 1;
}
yy161: yych = *++YYCURSOR;
yy162:
-#line 696
+#line 699
{ SyckLevel *lvl;
SyckNode *n = syck_alloc_str();
lvl = CURRENT_LEVEL();
@@ -1799,6 +1802,7 @@ yy162:
n->type_id = syck_strndup( "str", 3 );
n->data.str->ptr = qstr;
n->data.str->len = qidx;
+ n->data.str->style = scalar_2quote;
sycklval->nodeData = n;
return YAML_PLAIN;
}
@@ -1822,7 +1826,7 @@ yy167: YYCURSOR = YYMARKER;
}
yy168: yych = *++YYCURSOR;
yy169:
-#line 691
+#line 694
{ keep_nl = 0;
YYCURSOR--;
goto DoubleQuote2;
@@ -1858,7 +1862,7 @@ yy171: yych = *++YYCURSOR;
}
yy172: yych = *++YYCURSOR;
yy173:
-#line 677
+#line 680
{ char ch = *( YYCURSOR - 1 );
QUOTECAT(qstr, qcapa, qidx, escape_seq( ch ));
goto DoubleQuote2;
@@ -1889,7 +1893,7 @@ yy174: yych = *++YYCURSOR;
}
yy175: yych = *++YYCURSOR;
yy176:
-#line 682
+#line 685
{ long ch;
char *chr_text = syck_strndup( YYTOKEN, 4 );
chr_text[0] = '0';
@@ -1915,7 +1919,7 @@ yy179: ++YYCURSOR;
default: goto yy167;
}
}
-#line 715
+#line 719
}
@@ -1950,7 +1954,7 @@ yy182: YYCURSOR = YYMARKER;
}
yy183: yych = *++YYCURSOR;
yy184:
-#line 729
+#line 733
{ SyckLevel *lvl;
YYCURSOR = YYTOKTMP;
if ( YYCURSOR == YYTOKEN + 1 )
@@ -2008,7 +2012,7 @@ yy186: yych = *++YYCURSOR;
default: goto yy187;
}
yy187:
-#line 796
+#line 800
{ QUOTECAT(qstr, qcapa, qidx, *(YYCURSOR - 1));
goto TransferMethod2;
}
@@ -2049,7 +2053,7 @@ yy190: yych = *++YYCURSOR;
}
yy191: yych = *++YYCURSOR;
yy192:
-#line 782
+#line 786
{ char ch = *( YYCURSOR - 1 );
QUOTECAT(qstr, qcapa, qidx, escape_seq( ch ));
goto TransferMethod2;
@@ -2080,7 +2084,7 @@ yy193: yych = *++YYCURSOR;
}
yy194: yych = *++YYCURSOR;
yy195:
-#line 787
+#line 791
{ long ch;
char *chr_text = syck_strndup( YYTOKTMP, 4 );
chr_text[0] = '0';
@@ -2099,7 +2103,7 @@ yy198: switch(yych){
default: goto yy184;
}
}
-#line 801
+#line 805
}
@@ -2165,7 +2169,7 @@ yy201: yyaccept = 0;
yych = *(YYMARKER = ++YYCURSOR);
goto yy220;
yy202:
-#line 848
+#line 852
{ char *pacer;
char *tok = YYTOKEN;
int indt_len = 0, nl_count = 0, fold_nl = 0, nl_begin = 0;
@@ -2237,13 +2241,13 @@ yy203: yych = *++YYCURSOR;
default: goto yy204;
}
yy204:
-#line 953
+#line 957
{ QUOTECAT(qstr, qcapa, qidx, *YYTOKEN);
goto ScalarBlock2;
}
yy205: yych = *++YYCURSOR;
yy206:
-#line 915
+#line 919
{ lvl = CURRENT_LEVEL();
if ( lvl->status != syck_lvl_block )
{
@@ -2258,7 +2262,7 @@ yy206:
}
yy207: yych = *++YYCURSOR;
yy208:
-#line 929
+#line 933
{ YYCURSOR--;
POP_LEVEL();
RETURN_YAML_BLOCK();
@@ -2290,7 +2294,7 @@ yy213: yych = *++YYCURSOR;
}
yy214: yych = *++YYCURSOR;
yy215:
-#line 934
+#line 938
{ if ( YYTOKEN == YYLINEPTR )
{
if ( blockType == BLOCK_FOLD )
@@ -2338,7 +2342,7 @@ yy221: ++YYCURSOR;
default: goto yy212;
}
}
-#line 958
+#line 962
}
@@ -2369,7 +2373,7 @@ yy222:
}
yy224: yych = *++YYCURSOR;
yy225:
-#line 974
+#line 978
{ YYCURSOR = YYTOKEN;
return;
}
@@ -2382,7 +2386,7 @@ yy227: yych = *++YYCURSOR;
default: goto yy228;
}
yy228:
-#line 978
+#line 982
{ goto Comment;
}
yy229: yych = *++YYCURSOR;
@@ -2408,7 +2412,7 @@ yy233: YYCURSOR = YYMARKER;
case 0: goto yy225;
}
}
-#line 981
+#line 985
}