From bd810795c589a81e8939b53ad921f823e7133ee9 Mon Sep 17 00:00:00 2001 From: why Date: Tue, 13 May 2003 06:34:18 +0000 Subject: * lib/yaml/rubytypes.rb: object and struct loading * lib/yaml.rb: YAML::detect_implicit will discover typing for a Ruby string * ext/syck/: Fixed portable comments, misuse of NULL and methods without return VALUEs. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3784 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/syck/gram.c | 187 ++++++++++++++++++++---------------- ext/syck/handler.c | 16 ++-- ext/syck/implicit.c | 18 ++-- ext/syck/node.c | 24 ++--- ext/syck/rubyext.c | 205 ++++++++++++++++++++++----------------- ext/syck/syck.c | 45 ++++----- ext/syck/syck.h | 53 ++++++----- ext/syck/token.c | 259 +++++++++++++++++++++++++------------------------- lib/yaml.rb | 16 ++-- lib/yaml/rubytypes.rb | 13 +-- 10 files changed, 435 insertions(+), 401 deletions(-) diff --git a/ext/syck/gram.c b/ext/syck/gram.c index e1d0301c6c..91ebc6151a 100644 --- a/ext/syck/gram.c +++ b/ext/syck/gram.c @@ -229,16 +229,16 @@ union yyalloc /* YYFINAL -- State number of the termination state. */ #define YYFINAL 32 -#define YYLAST 132 +#define YYLAST 186 /* YYNTOKENS -- Number of terminals. */ #define YYNTOKENS 23 /* YYNNTS -- Number of nonterminals. */ #define YYNNTS 21 /* YYNRULES -- Number of rules. */ -#define YYNRULES 46 +#define YYNRULES 47 /* YYNRULES -- Number of states. */ -#define YYNSTATES 73 +#define YYNSTATES 78 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ #define YYUNDEFTOK 2 @@ -287,8 +287,8 @@ static const unsigned char yyprhs[] = 0, 0, 3, 5, 8, 9, 11, 13, 16, 18, 22, 24, 25, 27, 30, 32, 34, 37, 40, 42, 44, 47, 49, 51, 53, 55, 57, 61, 64, 66, - 70, 73, 77, 80, 82, 86, 90, 94, 96, 102, - 104, 108, 111, 115, 119, 122, 124 + 70, 73, 77, 80, 82, 86, 90, 96, 100, 102, + 108, 110, 114, 117, 121, 125, 128, 130 }; /* YYRHS -- A `-1'-separated list of the rules' RHS. */ @@ -303,10 +303,11 @@ static const yysigned_char yyrhs[] = -1, 14, 26, -1, 33, -1, 34, 29, 33, -1, 34, 29, -1, 17, 36, 18, -1, 17, 18, -1, 25, -1, 36, 21, 25, -1, 27, 40, 28, -1, - 30, 15, 26, -1, 38, -1, 22, 25, 29, 15, - 26, -1, 39, -1, 40, 29, 39, -1, 40, 29, - -1, 25, 15, 26, -1, 19, 43, 20, -1, 19, - 20, -1, 41, -1, 43, 21, 41, -1 + 27, 5, 29, 40, 28, -1, 30, 15, 26, -1, + 38, -1, 22, 25, 29, 15, 26, -1, 39, -1, + 40, 29, 39, -1, 40, 29, -1, 25, 15, 26, + -1, 19, 43, 20, -1, 19, 20, -1, 41, -1, + 43, 21, 41, -1 }; /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ @@ -315,8 +316,8 @@ static const unsigned short yyrline[] = 0, 44, 44, 48, 52, 58, 59, 60, 69, 77, 83, 84, 102, 103, 106, 109, 117, 122, 130, 143, 150, 155, 156, 157, 158, 159, 165, 171, 177, 181, - 186, 195, 199, 205, 209, 219, 225, 240, 241, 249, - 250, 255, 264, 272, 276, 282, 283 + 186, 195, 199, 205, 209, 219, 223, 230, 245, 246, + 254, 255, 260, 269, 277, 281, 287, 288 }; #endif @@ -353,8 +354,8 @@ static const unsigned char yyr1[] = 0, 23, 24, 24, 24, 25, 25, 25, 25, 25, 26, 26, 27, 27, 28, 29, 30, 30, 30, 30, 31, 31, 31, 31, 31, 31, 32, 33, 34, 34, - 34, 35, 35, 36, 36, 37, 38, 39, 39, 40, - 40, 40, 41, 42, 42, 43, 43 + 34, 35, 35, 36, 36, 37, 37, 38, 39, 39, + 40, 40, 40, 41, 42, 42, 43, 43 }; /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ @@ -363,8 +364,8 @@ static const unsigned char yyr2[] = 0, 2, 1, 2, 0, 1, 1, 2, 1, 3, 1, 0, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 1, 1, 1, 1, 3, 2, 1, 3, - 2, 3, 2, 1, 3, 3, 3, 1, 5, 1, - 3, 2, 3, 3, 2, 1, 3 + 2, 3, 2, 1, 3, 3, 5, 3, 1, 5, + 1, 3, 2, 3, 3, 2, 1, 3 }; /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state @@ -374,43 +375,43 @@ static const unsigned char yydefact[] = { 4, 0, 21, 0, 12, 0, 0, 0, 0, 2, 22, 23, 24, 25, 20, 0, 8, 0, 0, 18, - 19, 3, 0, 5, 6, 32, 33, 0, 44, 0, - 45, 0, 1, 0, 13, 11, 0, 0, 28, 0, - 37, 39, 0, 7, 16, 17, 0, 5, 31, 0, - 11, 43, 0, 10, 27, 0, 11, 15, 14, 26, - 30, 35, 41, 9, 34, 42, 46, 0, 36, 29, - 40, 11, 38 + 19, 3, 0, 5, 6, 32, 33, 0, 45, 0, + 46, 0, 1, 0, 13, 11, 0, 0, 28, 0, + 38, 40, 0, 7, 16, 0, 17, 0, 0, 5, + 31, 0, 11, 44, 0, 15, 0, 10, 27, 0, + 11, 14, 26, 30, 35, 42, 9, 34, 43, 47, + 0, 0, 37, 29, 41, 36, 11, 39 }; /* YYDEFGOTO[NTERM-NUM]. */ static const yysigned_char yydefgoto[] = { - -1, 7, 53, 54, 22, 59, 60, 23, 24, 10, + -1, 7, 57, 58, 22, 62, 56, 23, 24, 10, 38, 39, 11, 27, 12, 40, 41, 42, 30, 13, 31 }; /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing STATE-NUM. */ -#define YYPACT_NINF -49 -static const yysigned_char yypact[] = +#define YYPACT_NINF -45 +static const short yypact[] = { - 7, 113, -49, 97, -49, 80, 52, 15, 68, -49, - -49, -49, -49, -49, -49, 97, -49, 104, 88, -49, - -49, -49, 24, -49, -49, -49, -49, 19, -49, 4, - -49, 28, -49, 88, -49, 97, 97, 6, -49, 32, - -49, -49, 32, -49, -49, -49, 26, 6, -49, 97, - 97, -49, 97, -49, -49, 30, 97, -49, -49, -49, - 39, -49, 59, -49, -49, -49, -49, 47, -49, -49, - -49, 97, -49 + 156, 167, -45, 121, -45, 104, 76, 19, 92, -45, + -45, -45, -45, -45, -45, 121, -45, 151, 111, -45, + -45, -45, 56, -45, -45, -45, -45, 8, -45, 9, + -45, -3, -45, 39, -45, 121, 121, 12, -45, 18, + -45, -45, 18, -45, -45, 111, -45, 136, 22, 12, + -45, 121, 121, -45, 121, -45, 83, -45, -45, 24, + 121, -45, -45, 26, -45, 83, -45, -45, -45, -45, + 18, 23, -45, -45, -45, -45, 121, -45 }; /* YYPGOTO[NTERM-NUM]. */ static const yysigned_char yypgoto[] = { - -49, -49, -2, -48, 5, -35, 37, -8, 51, -49, - 10, -49, -49, -49, -49, -49, 16, -49, 25, -49, - -49 + -45, -45, -2, -44, 6, -27, -37, -8, 11, -45, + -22, -45, -45, -45, -45, -45, -23, -6, 0, -45, + -45 }; /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If @@ -420,38 +421,48 @@ static const yysigned_char yypgoto[] = #define YYTABLE_NINF -1 static const unsigned char yytable[] = { - 37, 21, 65, 26, 29, 8, 8, 61, 68, 44, - 45, 63, 1, 43, 47, 32, 2, 3, 4, 50, - 46, 56, 8, 72, 5, 44, 6, 15, 16, 17, - 18, 19, 20, 2, 55, 4, 34, 48, 35, 58, - 49, 5, 57, 6, 57, 58, 36, 64, 51, 52, - 29, 9, 14, 35, 37, 15, 16, 17, 18, 19, - 20, 2, 71, 4, 33, 18, 19, 20, 14, 5, - 69, 6, 28, 33, 18, 19, 20, 66, 70, 62, - 34, 36, 35, 15, 16, 17, 18, 19, 20, 2, - 36, 4, 67, 33, 18, 19, 20, 5, 25, 6, - 15, 16, 17, 18, 19, 20, 2, 0, 4, 17, - 18, 19, 20, 2, 5, 4, 6, 0, 1, 0, - 0, 5, 2, 6, 4, 0, 0, 0, 0, 0, - 5, 0, 6 + 37, 21, 63, 26, 29, 65, 8, 8, 68, 44, + 46, 9, 14, 43, 49, 64, 72, 53, 54, 32, + 48, 66, 71, 8, 52, 44, 50, 60, 14, 51, + 55, 61, 77, 65, 59, 61, 55, 44, 76, 44, + 35, 73, 74, 75, 45, 18, 19, 20, 37, 67, + 70, 55, 29, 8, 69, 0, 0, 37, 14, 15, + 16, 47, 18, 19, 20, 2, 0, 4, 34, 0, + 35, 0, 0, 5, 0, 6, 0, 0, 36, 15, + 16, 17, 18, 19, 20, 2, 0, 4, 45, 18, + 19, 20, 0, 5, 0, 6, 28, 33, 18, 19, + 20, 0, 0, 0, 34, 36, 35, 15, 16, 17, + 18, 19, 20, 2, 36, 4, 45, 18, 19, 20, + 0, 5, 25, 6, 15, 16, 17, 18, 19, 20, + 2, 0, 4, 0, 0, 0, 0, 0, 5, 0, + 6, 17, 18, 19, 20, 2, 0, 4, 55, 0, + 0, 0, 0, 5, 0, 6, 17, 18, 19, 20, + 2, 1, 4, 0, 0, 2, 3, 4, 5, 0, + 6, 0, 1, 5, 0, 6, 2, 0, 4, 0, + 0, 0, 0, 0, 5, 0, 6 }; static const yysigned_char yycheck[] = { - 8, 3, 50, 5, 6, 0, 1, 42, 56, 17, - 18, 46, 5, 15, 22, 0, 9, 10, 11, 15, - 22, 15, 17, 71, 17, 33, 19, 3, 4, 5, - 6, 7, 8, 9, 36, 11, 12, 18, 14, 13, - 21, 17, 12, 19, 12, 13, 22, 49, 20, 21, - 52, 0, 1, 14, 62, 3, 4, 5, 6, 7, - 8, 9, 15, 11, 5, 6, 7, 8, 17, 17, - 60, 19, 20, 5, 6, 7, 8, 52, 62, 42, - 12, 22, 14, 3, 4, 5, 6, 7, 8, 9, - 22, 11, 55, 5, 6, 7, 8, 17, 18, 19, - 3, 4, 5, 6, 7, 8, 9, -1, 11, 5, - 6, 7, 8, 9, 17, 11, 19, -1, 5, -1, - -1, 17, 9, 19, 11, -1, -1, -1, -1, -1, - 17, -1, 19 + 8, 3, 39, 5, 6, 42, 0, 1, 52, 17, + 18, 0, 1, 15, 22, 42, 60, 20, 21, 0, + 22, 48, 59, 17, 15, 33, 18, 15, 17, 21, + 12, 13, 76, 70, 36, 13, 12, 45, 15, 47, + 14, 63, 65, 70, 5, 6, 7, 8, 56, 51, + 56, 12, 54, 47, 54, -1, -1, 65, 47, 3, + 4, 5, 6, 7, 8, 9, -1, 11, 12, -1, + 14, -1, -1, 17, -1, 19, -1, -1, 22, 3, + 4, 5, 6, 7, 8, 9, -1, 11, 5, 6, + 7, 8, -1, 17, -1, 19, 20, 5, 6, 7, + 8, -1, -1, -1, 12, 22, 14, 3, 4, 5, + 6, 7, 8, 9, 22, 11, 5, 6, 7, 8, + -1, 17, 18, 19, 3, 4, 5, 6, 7, 8, + 9, -1, 11, -1, -1, -1, -1, -1, 17, -1, + 19, 5, 6, 7, 8, 9, -1, 11, 12, -1, + -1, -1, -1, 17, -1, 19, 5, 6, 7, 8, + 9, 5, 11, -1, -1, 9, 10, 11, 17, -1, + 19, -1, 5, 17, -1, 19, 9, -1, 11, -1, + -1, -1, -1, -1, 17, -1, 19 }; /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing @@ -462,10 +473,10 @@ static const unsigned char yystos[] = 32, 35, 37, 42, 31, 3, 4, 5, 6, 7, 8, 25, 27, 30, 31, 18, 25, 36, 20, 25, 41, 43, 0, 5, 12, 14, 22, 30, 33, 34, - 38, 39, 40, 25, 30, 30, 25, 30, 18, 21, - 15, 20, 21, 25, 26, 25, 15, 12, 13, 28, - 29, 28, 29, 28, 25, 26, 41, 29, 26, 33, - 39, 15, 26 + 38, 39, 40, 25, 30, 5, 30, 5, 25, 30, + 18, 21, 15, 20, 21, 12, 29, 25, 26, 25, + 15, 13, 28, 29, 28, 29, 28, 25, 26, 41, + 40, 29, 26, 33, 39, 28, 15, 26 }; #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__) @@ -1202,7 +1213,15 @@ yyreduce: break; case 36: -#line 226 "gram.y" +#line 224 "gram.y" + { + syck_add_transfer( yyvsp[-3].name, yyvsp[-1].nodeData, ((SyckParser *)parser)->taguri_expansion ); + yyval.nodeData = yyvsp[-1].nodeData; + } + break; + + case 37: +#line 231 "gram.y" { yyval.nodeData = syck_new_map( syck_hdlr_add_node( (SyckParser *)parser, yyvsp[-2].nodeData ), @@ -1210,8 +1229,8 @@ yyreduce: } break; - case 38: -#line 242 "gram.y" + case 39: +#line 247 "gram.y" { yyval.nodeData = syck_new_map( syck_hdlr_add_node( (SyckParser *)parser, yyvsp[-3].nodeData ), @@ -1219,23 +1238,23 @@ yyreduce: } break; - case 40: -#line 251 "gram.y" + case 41: +#line 256 "gram.y" { syck_map_update( yyvsp[-2].nodeData, yyvsp[0].nodeData ); yyval.nodeData = yyvsp[-2].nodeData; } break; - case 41: -#line 256 "gram.y" + case 42: +#line 261 "gram.y" { yyval.nodeData = yyvsp[-1].nodeData; } break; - case 42: -#line 265 "gram.y" + case 43: +#line 270 "gram.y" { yyval.nodeData = syck_new_map( syck_hdlr_add_node( (SyckParser *)parser, yyvsp[-2].nodeData ), @@ -1243,22 +1262,22 @@ yyreduce: } break; - case 43: -#line 273 "gram.y" + case 44: +#line 278 "gram.y" { yyval.nodeData = yyvsp[-1].nodeData; } break; - case 44: -#line 277 "gram.y" + case 45: +#line 282 "gram.y" { yyval.nodeData = syck_alloc_map(); } break; - case 46: -#line 284 "gram.y" + case 47: +#line 289 "gram.y" { syck_map_update( yyvsp[-2].nodeData, yyvsp[0].nodeData ); yyval.nodeData = yyvsp[-2].nodeData; @@ -1269,7 +1288,7 @@ yyreduce: } /* Line 1016 of /usr/local/share/bison/yacc.c. */ -#line 1273 "y.tab.c" +#line 1292 "y.tab.c" yyvsp -= yylen; yyssp -= yylen; @@ -1488,7 +1507,7 @@ yyreturn: } -#line 290 "gram.y" +#line 295 "gram.y" diff --git a/ext/syck/handler.c b/ext/syck/handler.c index c54ee0408e..7a914b5ad1 100644 --- a/ext/syck/handler.c +++ b/ext/syck/handler.c @@ -1,11 +1,11 @@ -// -// handler.h -// -// $Author$ -// $Date$ -// -// Copyright (C) 2003 why the lucky stiff -// +/* + * handler.h + * + * $Author$ + * $Date$ + * + * Copyright (C) 2003 why the lucky stiff + */ #include "syck.h" diff --git a/ext/syck/implicit.c b/ext/syck/implicit.c index c61a776cfb..d5d96a460c 100644 --- a/ext/syck/implicit.c +++ b/ext/syck/implicit.c @@ -1,13 +1,13 @@ -/* Generated by re2c 0.5 on Sat May 10 19:43:22 2003 */ +/* Generated by re2c 0.5 on Sun May 11 19:35:35 2003 */ #line 1 "implicit.re" -// -// implicit.re -// -// $Author$ -// $Date$ -// -// Copyright (C) 2003 why the lucky stiff -// +/* + * implicit.re + * + * $Author$ + * $Date$ + * + * Copyright (C) 2003 why the lucky stiff + */ #include "syck.h" diff --git a/ext/syck/node.c b/ext/syck/node.c index f009cc5884..182ffee98b 100644 --- a/ext/syck/node.c +++ b/ext/syck/node.c @@ -1,17 +1,17 @@ -// -// node.c -// -// $Author$ -// $Date$ -// -// Copyright (C) 2003 why the lucky stiff -// +/* + * node.c + * + * $Author$ + * $Date$ + * + * Copyright (C) 2003 why the lucky stiff + */ #include "syck.h" -// -// Node allocation functions -// +/* + * Node allocation functions + */ SyckNode * syck_alloc_node( enum syck_kind_tag type ) { @@ -19,7 +19,7 @@ syck_alloc_node( enum syck_kind_tag type ) s = S_ALLOC( SyckNode ); s->kind = type; - s->id = NULL; + s->id = 0; s->type_id = NULL; s->anchor = NULL; diff --git a/ext/syck/rubyext.c b/ext/syck/rubyext.c index 67cc9df174..835c35dcee 100644 --- a/ext/syck/rubyext.c +++ b/ext/syck/rubyext.c @@ -1,11 +1,11 @@ -// -// rubyext.c -// -// $Author$ -// $Date$ -// -// Copyright (C) 2003 why the lucky stiff -// +/* + * rubyext.c + * + * $Author$ + * $Date$ + * + * Copyright (C) 2003 why the lucky stiff + */ #include "ruby.h" #include "syck.h" @@ -19,9 +19,9 @@ static VALUE sym_model, sym_generic; static VALUE sym_scalar, sym_seq, sym_map; VALUE cParser, cLoader, cNode, oDefaultLoader; -// -// my private collection of numerical oddities. -// +/* + * my private collection of numerical oddities. + */ static double S_zero() { return 0.0; } static double S_one() { return 1.0; } static double S_inf() { return S_one() / S_zero(); } @@ -29,9 +29,9 @@ static double S_nan() { return S_zero() / S_zero(); } static VALUE syck_node_transform( VALUE ); -// -// read from io. -// +/* + * read from io. + */ long rb_syck_io_str_read( char *buf, SyckIoStr *str, long max_size, long skip ) { @@ -60,9 +60,9 @@ rb_syck_io_str_read( char *buf, SyckIoStr *str, long max_size, long skip ) return len; } -// -// determine: are we reading from a string or io? -// +/* + * determine: are we reading from a string or io? + */ void syck_parser_assign_io(parser, port) SyckParser *parser; @@ -85,9 +85,9 @@ syck_parser_assign_io(parser, port) } } -// -// Get value in hash by key, forcing an empty hash if nil. -// +/* + * Get value in hash by key, forcing an empty hash if nil. + */ VALUE syck_get_hash_aref(hsh, key) VALUE hsh, key; @@ -101,9 +101,9 @@ syck_get_hash_aref(hsh, key) return val; } -// -// creating timestamps -// +/* + * creating timestamps + */ SYMID rb_syck_mktime(str) char *str; @@ -145,10 +145,10 @@ rb_syck_mktime(str) return time; } -// -// {generic mode} node handler -// - Loads data into Node classes -// +/* + * {generic mode} node handler + * - Loads data into Node classes + */ SYMID rb_syck_parse_handler(p, n) SyckParser *p; @@ -204,10 +204,10 @@ rb_syck_parse_handler(p, n) return obj; } -// -// {native mode} node handler -// - Converts data into native Ruby types -// +/* + * {native mode} node handler + * - Converts data into native Ruby types + */ SYMID rb_syck_load_handler(p, n) SyckParser *p; @@ -327,9 +327,9 @@ rb_syck_load_handler(p, n) return obj; } -// -// friendly errors. -// +/* + * friendly errors. + */ void rb_syck_err_handler(p, msg) SyckParser *p; @@ -348,9 +348,9 @@ rb_syck_err_handler(p, msg) p->lineptr); } -// -// data loaded based on the model requested. -// +/* + * data loaded based on the model requested. + */ void syck_set_model( parser, model ) SyckParser *parser; @@ -372,9 +372,9 @@ syck_set_model( parser, model ) } } -// -// wrap syck_parse(). -// +/* + * wrap syck_parse(). + */ static VALUE rb_run_syck_parse(parser) SyckParser *parser; @@ -382,9 +382,9 @@ rb_run_syck_parse(parser) return syck_parse(parser); } -// -// free parser. -// +/* + * free parser. + */ static VALUE rb_syck_ensure(parser) SyckParser *parser; @@ -393,9 +393,9 @@ rb_syck_ensure(parser) return 0; } -// -// YAML::Syck::Parser.new -// +/* + * YAML::Syck::Parser.new + */ VALUE syck_parser_new(argc, argv, class) int argc; @@ -417,9 +417,9 @@ syck_parser_new(argc, argv, class) return pobj; } -// -// YAML::Syck::Parser.initialize( options ) -// +/* + * YAML::Syck::Parser.initialize( options ) + */ static VALUE syck_parser_initialize( self, options ) VALUE self, options; @@ -428,9 +428,9 @@ syck_parser_initialize( self, options ) return self; } -// -// YAML::Syck::Parser.load( IO or String ) -// +/* + * YAML::Syck::Parser.load( IO or String ) + */ VALUE syck_parser_load(argc, argv, self) int argc; @@ -454,7 +454,7 @@ syck_parser_load(argc, argv, self) } v = syck_parse( parser ); - if ( v == NULL ) + if ( v == 0 ) { return Qnil; } @@ -464,9 +464,9 @@ syck_parser_load(argc, argv, self) return v; } -// -// YAML::Syck::Parser.load_documents( IO or String ) { |doc| } -// +/* + * YAML::Syck::Parser.load_documents( IO or String ) { |doc| } + */ VALUE syck_parser_load_documents(argc, argv, self) int argc; @@ -497,9 +497,9 @@ syck_parser_load_documents(argc, argv, self) return Qnil; } -// -// YAML::Syck::Loader.initialize -// +/* + * YAML::Syck::Loader.initialize + */ static VALUE syck_loader_initialize( self ) VALUE self; @@ -516,9 +516,9 @@ syck_loader_initialize( self ) return self; } -// -// Add type family, used by add_*_type methods. -// +/* + * Add type family, used by add_*_type methods. + */ VALUE syck_loader_add_type_family( self, domain, type_re, proc ) VALUE self, domain, type_re, proc; @@ -528,11 +528,12 @@ syck_loader_add_type_family( self, domain, type_re, proc ) families = rb_iv_get(self, "@families"); domain_types = syck_get_hash_aref(families, domain); rb_hash_aset( domain_types, type_re, proc ); + return Qnil; } -// -// YAML::Syck::Loader.add_domain_type -// +/* + * YAML::Syck::Loader.add_domain_type + */ VALUE syck_loader_add_domain_type( argc, argv, self ) int argc; @@ -543,12 +544,13 @@ syck_loader_add_domain_type( argc, argv, self ) rb_scan_args(argc, argv, "2&", &domain, &type_re, &proc); syck_loader_add_type_family( self, domain, type_re, proc ); + return Qnil; } -// -// YAML::Syck::Loader.add_builtin_type -// +/* + * YAML::Syck::Loader.add_builtin_type + */ VALUE syck_loader_add_builtin_type( argc, argv, self ) int argc; @@ -559,11 +561,12 @@ syck_loader_add_builtin_type( argc, argv, self ) rb_scan_args(argc, argv, "1&", &type_re, &proc); syck_loader_add_type_family( self, rb_str_new2( YAML_DOMAIN ), type_re, proc ); + return Qnil; } -// -// YAML::Syck::Loader.add_ruby_type -// +/* + * YAML::Syck::Loader.add_ruby_type + */ VALUE syck_loader_add_ruby_type( argc, argv, self ) int argc; @@ -574,11 +577,12 @@ syck_loader_add_ruby_type( argc, argv, self ) rb_scan_args(argc, argv, "1&", &type_re, &proc); syck_loader_add_type_family( self, rb_str_new2( RUBY_DOMAIN ), type_re, proc ); + return Qnil; } -// -// YAML::Syck::Loader.add_private_type -// +/* + * YAML::Syck::Loader.add_private_type + */ VALUE syck_loader_add_private_type( argc, argv, self ) int argc; @@ -591,11 +595,30 @@ syck_loader_add_private_type( argc, argv, self ) priv_types = rb_iv_get(self, "@private_types"); rb_hash_aset( priv_types, type_re, proc ); + return Qnil; } -// -// iterator to search a type hash for a match. -// +/* + * YAML::Syck::Loader#detect + */ +VALUE +syck_loader_detect_implicit( self, val ) + VALUE self, val; +{ + char *type_id; + + if ( TYPE(val) == T_STRING ) + { + type_id = syck_match_implicit( RSTRING(val)->ptr, RSTRING(val)->len ); + return rb_str_new2( type_id ); + } + + return rb_str_new2( "" ); +} + +/* + * iterator to search a type hash for a match. + */ static VALUE transfer_find_i(entry, col) VALUE entry, col; @@ -611,9 +634,9 @@ transfer_find_i(entry, col) return Qnil; } -// -// YAML::Syck::Loader#transfer -// +/* + * YAML::Syck::Loader#transfer + */ VALUE syck_loader_transfer( self, type, val ) VALUE self, type, val; @@ -689,15 +712,16 @@ syck_loader_transfer( self, type, val ) return val; } -// -// YAML::Syck::Node.initialize -// +/* + * YAML::Syck::Node.initialize + */ VALUE syck_node_initialize( self, type_id, val ) VALUE self, type_id, val; { rb_iv_set( self, "@type_id", type_id ); rb_iv_set( self, "@value", val ); + return self; } VALUE @@ -708,6 +732,7 @@ syck_node_thash( entry, t ) key = rb_ary_entry( entry, 0 ); val = syck_node_transform( rb_ary_entry( rb_ary_entry( entry, 1 ), 1 ) ); rb_hash_aset( t, key, val ); + return Qnil; } VALUE @@ -716,11 +741,12 @@ syck_node_ahash( entry, t ) { VALUE val = syck_node_transform( entry ); rb_ary_push( t, val ); + return Qnil; } -// -// YAML::Syck::Node.transform -// +/* + * YAML::Syck::Node.transform + */ VALUE syck_node_transform( self ) VALUE self; @@ -745,9 +771,9 @@ syck_node_transform( self ) return rb_funcall( oDefaultLoader, rb_intern( "transfer" ), 2, type_id, t ); } -// -// Initialize Syck extension -// +/* + * Initialize Syck extension + */ void Init_syck() { @@ -778,6 +804,7 @@ Init_syck() rb_define_method( cLoader, "add_builtin_type", syck_loader_add_builtin_type, -1 ); rb_define_method( cLoader, "add_ruby_type", syck_loader_add_ruby_type, -1 ); rb_define_method( cLoader, "add_private_type", syck_loader_add_private_type, -1 ); + rb_define_method( cLoader, "detect_implicit", syck_loader_detect_implicit, 1 ); rb_define_method( cLoader, "transfer", syck_loader_transfer, 2 ); oDefaultLoader = rb_funcall( cLoader, rb_intern( "new" ), 0 ); diff --git a/ext/syck/syck.c b/ext/syck/syck.c index 8e16351692..180d40ba18 100644 --- a/ext/syck/syck.c +++ b/ext/syck/syck.c @@ -1,11 +1,11 @@ -// -// syck.c -// -// $Author$ -// $Date$ -// -// Copyright (C) 2003 why the lucky stiff -// +/* + * syck.c + * + * $Author$ + * $Date$ + * + * Copyright (C) 2003 why the lucky stiff + */ #include #include @@ -15,9 +15,9 @@ #define SYCK_YAML_MINOR 0 #define SYCK_BUFFERSIZE 262144 -// -// Custom assert -// +/* + * Custom assert + */ void syck_assert( char *file_name, unsigned line_num ) { @@ -36,9 +36,9 @@ syck_strndup( char *buf, long len ) S_MEMCPY( new, buf, char, len ); } -// -// Default IO functions -// +/* + * Default IO functions + */ long syck_io_file_read( char *buf, SyckIoFile *file, long max_size, long skip ) { @@ -109,7 +109,7 @@ syck_parser_reset_levels( SyckParser *p ) { p->lvl_idx = 1; p->levels[0].spaces = -1; - p->levels[0].domain = ""; // YAML_DOMAIN + "/"; + p->levels[0].domain = syck_strndup( "", 1 ); // YAML_DOMAIN + "/"; p->levels[0].status = syck_lvl_header; } @@ -135,9 +135,9 @@ syck_parser_reset_cursor( SyckParser *p ) p->force_token = 0; } -// -// Allocate the parser -// +/* + * Allocate the parser + */ SyckParser * syck_new_parser() { @@ -303,10 +303,7 @@ syck_parser_pop_level( SyckParser *p ) if ( p->lvl_idx <= 1 ) return; p->lvl_idx -= 1; - if ( p->levels[p->lvl_idx - 1].domain != p->levels[p->lvl_idx].domain ) - { - free( p->levels[p->lvl_idx].domain ); - } + free( p->levels[p->lvl_idx].domain ); } void @@ -321,7 +318,7 @@ syck_parser_add_level( SyckParser *p, int len, enum syck_level_status status ) ASSERT( len > p->levels[p->lvl_idx-1].spaces ); p->levels[p->lvl_idx].spaces = len; - p->levels[p->lvl_idx].domain = p->levels[p->lvl_idx-1].domain; + p->levels[p->lvl_idx].domain = syck_strndup( p->levels[p->lvl_idx-1].domain, strlen( p->levels[p->lvl_idx-1].domain ) ); p->levels[p->lvl_idx].status = status; p->lvl_idx += 1; } @@ -443,7 +440,7 @@ syck_parse( SyckParser *p ) ASSERT( p != NULL ); - p->root = NULL; + p->root = 0; syck_parser_reset_levels( p ); yyparse( p ); return p->root; diff --git a/ext/syck/syck.h b/ext/syck/syck.h index 6fdbea6849..bb4bf2fed9 100644 --- a/ext/syck/syck.h +++ b/ext/syck/syck.h @@ -1,11 +1,11 @@ -// -// syck.h -// -// $Author$ -// $Date$ -// -// Copyright (C) 2003 why the lucky stiff -// +/* + * syck.h + * + * $Author$ + * $Date$ + * + * Copyright (C) 2003 why the lucky stiff + */ #ifndef SYCK_H #define SYCK_H @@ -24,9 +24,9 @@ extern "C" { #endif -// -// Memory Allocation -// +/* + * Memory Allocation + */ #if defined(HAVE_ALLOCA_H) && !defined(__GNUC__) #include #endif @@ -65,9 +65,9 @@ extern "C" { #define NL_CHOMP 130 #define NL_KEEP 140 -// -// Node definitions -// +/* + * Node definitions + */ #define SYMID unsigned long typedef struct _syck_parser SyckParser; @@ -118,9 +118,9 @@ struct _syck_node { } data; }; -// -// Parser definitions -// +/* + * Parser definitions + */ typedef SYMID (*SyckNodeHandler)(SyckParser *, SyckNode *); typedef void (*SyckErrorHandler)(SyckParser *, char *); typedef long (*SyckIoFileRead)(char *, SyckIoFile *, long, long); @@ -135,6 +135,7 @@ enum syck_level_status { syck_lvl_header, syck_lvl_doc, syck_lvl_seq, + syck_lvl_map, syck_lvl_block, syck_lvl_str, syck_lvl_inline, @@ -190,9 +191,9 @@ struct _syck_parser { void *bonus; }; -// -// Handler prototypes -// +/* + * Handler prototypes + */ SYMID syck_hdlr_add_node( SyckParser *, SyckNode * ); SyckNode *syck_hdlr_add_anchor( SyckParser *, char *, SyckNode * ); SyckNode *syck_hdlr_add_alias( SyckParser *, char * ); @@ -207,9 +208,9 @@ void syck_fold_format( struct SyckStr *, int, int, int ); void try_tag_implicit( SyckNode *, int ); char *syck_match_implicit( char *, size_t ); -// -// API prototypes -// +/* + * API prototypes + */ char *syck_strndup( char *, long ); long syck_io_file_read( char *, SyckIoFile *, long, long ); long syck_io_str_read( char *, SyckIoStr *, long, long ); @@ -231,9 +232,9 @@ void syck_parser_init( SyckParser *, int ); SYMID syck_parse( SyckParser * ); void syck_default_error_handler( SyckParser *, char * ); -// -// Allocation prototypes -// +/* + * Allocation prototypes + */ SyckNode *syck_alloc_map(); SyckNode *syck_alloc_seq(); SyckNode *syck_alloc_str(); diff --git a/ext/syck/token.c b/ext/syck/token.c index 04c5bab860..5098cf53f3 100644 --- a/ext/syck/token.c +++ b/ext/syck/token.c @@ -1,25 +1,24 @@ -/* Generated by re2c 0.5 on Sat May 10 19:31:12 2003 */ +/* Generated by re2c 0.5 on Tue May 13 00:35:24 2003 */ #line 1 "token.re" -// -// token.re -// -// $Author$ -// $Date$ -// -// Copyright (C) 2003 why the lucky stiff -// - +/* + * token.re + * + * $Author$ + * $Date$ + * + * Copyright (C) 2003 why the lucky stiff + */ #include "syck.h" #include "gram.h" -// -// Allocate quoted strings in chunks -// +/* + * Allocate quoted strings in chunks + */ #define QUOTELEN 1024 -// -// They do my bidding... -// +/* + * They do my bidding... + */ #define YYCTYPE char #define YYCURSOR parser->cursor #define YYMARKER parser->marker @@ -30,33 +29,33 @@ #define YYLINE parser->linect #define YYFILL(n) syck_parser_read(parser) -// -// Repositions the cursor at `n' offset from the token start. -// Only works in `Header' and `Document' sections. -// +/* + * Repositions the cursor at `n' offset from the token start. + * Only works in `Header' and `Document' sections. + */ #define YYPOS(n) YYCURSOR = YYTOKEN + n -// -// Track line numbers -// +/* + * Track line numbers + */ #define NEWLINE(ptr) YYLINE++; YYLINEPTR = ptr + 1 -// -// I like seeing the level operations as macros... -// +/* + * I like seeing the level operations as macros... + */ #define ADD_LEVEL(len, status) syck_parser_add_level( parser, len, status ) #define POP_LEVEL() syck_parser_pop_level( parser ) #define CURRENT_LEVEL() syck_parser_current_level( parser ) -// -// Force a token next time around yylex() -// +/* + * Force a token next time around yylex() + */ #define FORCE_NEXT_TOKEN(tok) parser->force_token = tok; -// -// Nice little macro to ensure we're IOPENed to the current level. -// * Only use this macro in the "Document" section * -// +/* + * Nice little macro to ensure we're IOPENed to the current level. + * * Only use this macro in the "Document" section * + */ #define ENSURE_IOPEN(last_lvl, to_len, reset) \ if ( last_lvl->spaces < to_len ) \ { \ @@ -72,10 +71,10 @@ } \ } -// -// Nice little macro to ensure closure of levels. -// * Only use this macro in the "Document" section * -// +/* + * Nice little macro to ensure closure of levels. + * * Only use this macro in the "Document" section * + */ #define ENSURE_IEND(last_lvl, to_len) \ if ( last_lvl->spaces > to_len ) \ { \ @@ -84,10 +83,10 @@ return IEND; \ } -// -// Concatenates quoted string items and manages allocation -// to the quoted string -// +/* + * Concatenates quoted string items and manages allocation + * to the quoted string + */ #define QUOTECAT(s, c, i, l) \ { \ if ( i + 1 >= c ) \ @@ -99,10 +98,10 @@ s[i] = '\0'; \ } -// -// Tags a plain scalar with a transfer method -// * Use only in "Plain" section * -// +/* + * Tags a plain scalar with a transfer method + * * Use only in "Plain" section * + */ #define RETURN_IMPLICIT(fold) \ { \ SyckLevel *i_lvl = CURRENT_LEVEL(); \ @@ -118,9 +117,9 @@ return PLAIN; \ } -// -// Handles newlines, calculates indent -// +/* + * Handles newlines, calculates indent + */ #define GOBBLE_UP_INDENT( ict, start ) \ char *indent = start; \ NEWLINE(indent); \ @@ -142,9 +141,9 @@ ict = YYCURSOR - YYLINEPTR; \ } -// -// If an indent exists at the current level, back up. -// +/* + * If an indent exists at the current level, back up. + */ #define GET_TRUE_INDENT(indt_len) \ { \ SyckLevel *lvl_deep = CURRENT_LEVEL(); \ @@ -159,21 +158,21 @@ } \ } -// -// Argjh! I hate globals! Here for yyerror() only! -// +/* + * Argjh! I hate globals! Here for yyerror() only! + */ SyckParser *syck_parser_ptr = NULL; -// -// Accessory funcs later in this file. -// +/* + * Accessory funcs later in this file. + */ void eat_comments( SyckParser * ); -// -// My own re-entrant yylex() using re2c. -// You really get used to the limited regexp. -// It's really nice to not rely on backtracking and such. -// +/* + * My own re-entrant yylex() using re2c. + * You really get used to the limited regexp. + * It's really nice to not rely on backtracking and such. + */ int yylex( YYSTYPE *yylval, SyckParser *parser ) { @@ -190,7 +189,7 @@ yylex( YYSTYPE *yylval, SyckParser *parser ) return t; } -#line 206 +#line 205 if ( YYLINEPTR != YYCURSOR ) @@ -256,19 +255,19 @@ yy2: yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); if(yych == '-') goto yy15; yy3: -#line 247 +#line 246 { YYPOS(0); goto Document; } yy4: yych = *++YYCURSOR; yy5: -#line 233 +#line 232 { eat_comments( parser ); goto Header; } yy6: yych = *++YYCURSOR; yy7: -#line 237 +#line 236 { SyckLevel *lvl = CURRENT_LEVEL(); ENSURE_IEND(lvl, -1); return 0; @@ -276,7 +275,7 @@ yy7: yy8: yych = *++YYCURSOR; goto yy12; yy9: -#line 242 +#line 241 { int indt_len; GOBBLE_UP_INDENT( indt_len, YYTOKEN ); goto Header; @@ -308,7 +307,7 @@ yy18: ++YYCURSOR; yych = *YYCURSOR; yy19: if(yybm[0+yych] & 128) goto yy18; yy20: -#line 219 +#line 218 { SyckLevel *lvl = CURRENT_LEVEL(); if ( lvl->status == syck_lvl_header ) { @@ -328,7 +327,7 @@ yy21: ++YYCURSOR; yy22: if(yych == '\n') goto yy21; goto yy20; } -#line 251 +#line 250 Document: @@ -434,7 +433,7 @@ yy23: yy25: yych = *++YYCURSOR; goto yy77; yy26: -#line 265 +#line 264 { // Isolate spaces int indt_len; GOBBLE_UP_INDENT( indt_len, YYTOKEN ); @@ -451,7 +450,7 @@ yy26: } yy27: yych = *++YYCURSOR; yy28: -#line 280 +#line 279 { ENSURE_IOPEN(lvl, 0, 1); lvl = CURRENT_LEVEL(); ADD_LEVEL(lvl->spaces + 1, syck_lvl_inline); @@ -459,7 +458,7 @@ yy28: } yy29: yych = *++YYCURSOR; yy30: -#line 286 +#line 285 { POP_LEVEL(); return YYTOKEN[0]; } @@ -467,7 +466,7 @@ yy31: yych = *++YYCURSOR; if(yych == '\n') goto yy74; if(yych == ' ') goto yy71; yy32: -#line 335 +#line 334 { ENSURE_IOPEN(lvl, 0, 1); goto Plain; } @@ -485,15 +484,15 @@ yy35: yych = *++YYCURSOR; goto yy32; yy36: yych = *++YYCURSOR; yy37: -#line 312 +#line 311 { goto TransferMethod; } yy38: yych = *++YYCURSOR; yy39: -#line 314 +#line 313 { goto SingleQuote; } yy40: yych = *++YYCURSOR; yy41: -#line 316 +#line 315 { goto DoubleQuote; } yy42: yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); @@ -514,18 +513,18 @@ yy42: yyaccept = 0; } yy43: yych = *++YYCURSOR; yy44: -#line 325 +#line 324 { eat_comments( parser ); goto Document; } yy45: yych = *++YYCURSOR; goto yy51; yy46: -#line 329 +#line 328 { goto Document; } yy47: yych = *++YYCURSOR; yy48: -#line 331 +#line 330 { ENSURE_IEND(lvl, -1); return 0; } @@ -560,7 +559,7 @@ yy55: ++YYCURSOR; yych = *YYCURSOR; yy56: if(yych == ' ') goto yy55; yy57: -#line 318 +#line 317 { if ( *( YYCURSOR - 1 ) == '\n' ) { YYCURSOR--; @@ -577,7 +576,7 @@ yy60: ++YYCURSOR; yych = *YYCURSOR; yy61: if(yybm[0+yych] & 64) goto yy60; yy62: -#line 308 +#line 307 { yylval->name = syck_strndup( YYTOKEN + 1, YYCURSOR - YYTOKEN - 1 ); return ALIAS; } @@ -588,7 +587,7 @@ yy64: if(yych <= '-') goto yy65; if(yych == '`') goto yy65; if(yych <= 'z') goto yy63; yy65: -#line 304 +#line 303 { yylval->name = syck_strndup( YYTOKEN + 1, YYCURSOR - YYTOKEN - 1 ); return ANCHOR; } @@ -597,7 +596,7 @@ yy66: ++YYCURSOR; yych = *YYCURSOR; yy67: if(yych == ' ') goto yy66; yy68: -#line 294 +#line 293 { ENSURE_IOPEN(lvl, YYTOKEN - YYLINEPTR, 1); FORCE_NEXT_TOKEN(IOPEN); if ( *( YYCURSOR - 1 ) == '\n' ) @@ -617,7 +616,7 @@ yy71: ++YYCURSOR; yych = *YYCURSOR; yy72: if(yych == ' ') goto yy71; yy73: -#line 290 +#line 289 { YYPOS(1); return YYTOKEN[0]; } @@ -637,7 +636,7 @@ yy78: ++YYCURSOR; yy79: if(yybm[0+yych] & 128) goto yy78; goto yy26; } -#line 339 +#line 338 } @@ -705,14 +704,14 @@ yy83: yyaccept = 0; if(yych == '`') goto yy84; if(yych <= 'z') goto yy90; yy84: -#line 352 +#line 351 { YYCURSOR = YYTOKTMP; return DOCSEP; } yy85: yych = *++YYCURSOR; goto yy89; yy86: -#line 350 +#line 349 { goto Directive; } yy87: yych = *++YYCURSOR; goto yy84; @@ -734,10 +733,10 @@ yy93: ++YYCURSOR; yych = *YYCURSOR; yy94: if(yybm[0+yych] & 128) goto yy93; yy95: -#line 348 +#line 347 { goto Directive; } } -#line 355 +#line 354 } @@ -820,7 +819,7 @@ yy96: yy98: yych = *++YYCURSOR; goto yy122; yy99: -#line 375 +#line 374 { int indt_len; SyckLevel *lvl; char *tok = YYTOKTMP; @@ -839,11 +838,11 @@ yy100: yych = *++YYCURSOR; if(yych == '\n') goto yy119; if(yych == ' ') goto yy116; yy101: -#line 404 +#line 403 { goto Plain2; } yy102: yych = *++YYCURSOR; yy103: -#line 392 +#line 391 { if ( plvl->status != syck_lvl_inline ) goto Plain2; RETURN_IMPLICIT(multiLine); } @@ -853,18 +852,18 @@ yy104: yych = *++YYCURSOR; goto yy101; yy105: yych = *++YYCURSOR; yy106: -#line 396 +#line 395 { RETURN_IMPLICIT(multiLine); } yy107: yych = *++YYCURSOR; if(yych == '#') goto yy110; yy108: -#line 402 +#line 401 { goto Plain3; } yy109: yych = *++YYCURSOR; goto yy101; yy110: yych = *++YYCURSOR; yy111: -#line 398 +#line 397 { eat_comments( parser ); RETURN_IMPLICIT(multiLine); } @@ -883,7 +882,7 @@ yy116: ++YYCURSOR; yych = *YYCURSOR; yy117: if(yych == ' ') goto yy116; yy118: -#line 390 +#line 389 { RETURN_IMPLICIT(multiLine); } yy119: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); @@ -901,7 +900,7 @@ yy123: ++YYCURSOR; yy124: if(yybm[0+yych] & 128) goto yy123; goto yy99; } -#line 406 +#line 405 } @@ -966,7 +965,7 @@ yy125: yy127: yych = *++YYCURSOR; goto yy137; yy128: -#line 420 +#line 419 { int indt_len; int nl_count = 0; SyckLevel *lvl; @@ -1005,7 +1004,7 @@ yy128: yy129: yych = *++YYCURSOR; if(yych == '\'') goto yy134; yy130: -#line 460 +#line 459 { SyckLevel *lvl; SyckNode *n = syck_alloc_str(); lvl = CURRENT_LEVEL(); @@ -1023,13 +1022,13 @@ yy131: yych = *++YYCURSOR; goto yy130; yy132: yych = *++YYCURSOR; yy133: -#line 474 +#line 473 { QUOTECAT(qstr, qcapa, qidx, *(YYCURSOR - 1)); goto SingleQuote2; } yy134: yych = *++YYCURSOR; yy135: -#line 456 +#line 455 { QUOTECAT(qstr, qcapa, qidx, '\''); goto SingleQuote2; } @@ -1044,7 +1043,7 @@ yy138: ++YYCURSOR; yy139: if(yybm[0+yych] & 128) goto yy138; goto yy128; } -#line 478 +#line 477 } @@ -1114,7 +1113,7 @@ yy140: yy142: yych = *++YYCURSOR; goto yy158; yy143: -#line 496 +#line 495 { int indt_len; int nl_count = 0; SyckLevel *lvl; @@ -1186,13 +1185,13 @@ yy144: yyaccept = 0; } } yy145: -#line 571 +#line 570 { QUOTECAT(qstr, qcapa, qidx, *(YYCURSOR - 1)); goto DoubleQuote2; } yy146: yych = *++YYCURSOR; yy147: -#line 557 +#line 556 { SyckLevel *lvl; SyckNode *n = syck_alloc_str(); lvl = CURRENT_LEVEL(); @@ -1221,14 +1220,14 @@ yy152: YYCURSOR = YYMARKER; } yy153: yych = *++YYCURSOR; yy154: -#line 552 +#line 551 { keep_nl = 0; YYCURSOR--; goto DoubleQuote2; } yy155: yych = *++YYCURSOR; yy156: -#line 536 +#line 535 { char ch = *( YYCURSOR - 1 ); switch ( ch ) { @@ -1255,7 +1254,7 @@ yy159: ++YYCURSOR; yy160: if(yybm[0+yych] & 128) goto yy159; goto yy143; } -#line 575 +#line 574 } @@ -1316,7 +1315,7 @@ yy161: yy163:yy164: yych = *++YYCURSOR; goto yy172; yy165: -#line 584 +#line 583 { SyckLevel *lvl; YYCURSOR = YYTOKTMP; if ( YYCURSOR == YYTOKEN + 1 ) @@ -1331,14 +1330,14 @@ yy165: // if ( *(YYTOKEN + 1) == '^' ) { - yylval->name = S_ALLOC_N( char, YYCURSOR - YYTOKEN + strlen( lvl->domain ) ); + yylval->name = S_ALLOC_N( char, ( YYCURSOR - YYTOKEN ) + strlen( lvl->domain ) ); yylval->name[0] = '\0'; strcat( yylval->name, lvl->domain ); - strncat( yylval->name, YYTOKEN + 2, YYCURSOR - YYTOKEN - 2 ); + strncat( yylval->name, YYTOKEN + 2, ( YYCURSOR - YYTOKEN ) - 2 ); } else { - char *carat = YYTOKEN + 1; + char *carat = YYTOKEN; while ( (++carat) < YYCURSOR ) { if ( *carat == '^' ) @@ -1347,30 +1346,26 @@ yy165: if ( carat < YYCURSOR ) { - lvl->domain = syck_strndup( YYTOKEN + 1, carat - YYTOKEN - 1 ); - yylval->name = S_ALLOC_N( char, YYCURSOR - carat + strlen( lvl->domain ) ); + free( lvl->domain ); + lvl->domain = syck_strndup( YYTOKEN + 1, ( carat - YYTOKEN ) - 1 ); + yylval->name = S_ALLOC_N( char, ( YYCURSOR - carat ) + strlen( lvl->domain ) ); yylval->name[0] = '\0'; strcat( yylval->name, lvl->domain ); - strncat( yylval->name, carat + 1, YYCURSOR - carat - 1 ); + strncat( yylval->name, carat + 1, ( YYCURSOR - carat ) - 1 ); } else { - yylval->name = syck_strndup( YYTOKEN + 1, YYCURSOR - YYTOKEN - 1 ); + yylval->name = syck_strndup( YYTOKEN + 1, ( YYCURSOR - YYTOKEN ) - 1 ); } } - if ( *YYCURSOR == '\n' ) - { - FORCE_NEXT_TOKEN(IOPEN); - ADD_LEVEL(lvl->spaces, syck_lvl_doc); - } return TRANSFER; } yy166: yych = *++YYCURSOR; goto yy170; yy167: yych = *++YYCURSOR; yy168: -#line 634 +#line 629 { goto TransferMethod; } yy169: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); @@ -1383,7 +1378,7 @@ yy171: ++YYCURSOR; yy172: if(yybm[0+yych] & 128) goto yy171; goto yy165; } -#line 636 +#line 631 } @@ -1476,7 +1471,7 @@ yy173: yy175: yych = *++YYCURSOR; goto yy184; yy176: -#line 678 +#line 673 { int indt_len; GOBBLE_UP_INDENT( indt_len, YYTOKTMP ); lvl = CURRENT_LEVEL(); @@ -1509,7 +1504,7 @@ yy176: } yy177: yych = *++YYCURSOR; yy178: -#line 710 +#line 705 { lvl = CURRENT_LEVEL(); YYCURSOR--; yylval->nodeData = syck_new_str2( YYTOKEN, YYCURSOR - YYTOKEN ); @@ -1519,7 +1514,7 @@ yy178: } yy179: yych = *++YYCURSOR; yy180: -#line 718 +#line 713 { lvl = CURRENT_LEVEL(); if ( lvl->status != syck_lvl_block ) { @@ -1530,7 +1525,7 @@ yy180: } yy181: yych = *++YYCURSOR; yy182: -#line 727 +#line 722 { goto ScalarBlock2; } yy183: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); @@ -1543,7 +1538,7 @@ yy185: ++YYCURSOR; yy186: if(yybm[0+yych] & 128) goto yy185; goto yy176; } -#line 729 +#line 724 } @@ -1605,7 +1600,7 @@ yy187: goto yy192; yy189: yych = *++YYCURSOR; yy190: -#line 745 +#line 740 { SyckLevel *lvl = CURRENT_LEVEL(); YYCURSOR = tok; return; @@ -1614,7 +1609,7 @@ yy191: yych = *++YYCURSOR; goto yy195; yy192: yych = *++YYCURSOR; yy193: -#line 750 +#line 745 { goto Comment; } yy194: ++YYCURSOR; @@ -1623,7 +1618,7 @@ yy194: ++YYCURSOR; yy195: if(yybm[0+yych] & 128) goto yy194; goto yy190; } -#line 753 +#line 748 } @@ -1642,7 +1637,7 @@ yyerror( char *msg ) if ( syck_parser_ptr->error_handler == NULL ) syck_parser_ptr->error_handler = syck_default_error_handler; - syck_parser_ptr->root = NULL; + syck_parser_ptr->root = 0; (syck_parser_ptr->error_handler)(syck_parser_ptr, msg); } diff --git a/lib/yaml.rb b/lib/yaml.rb index 1b2a4ea81f..b5852b2257 100644 --- a/lib/yaml.rb +++ b/lib/yaml.rb @@ -104,18 +104,20 @@ module YAML @@loader.add_private_type( type_re, &transfer_proc ) end + # + # Detect typing of a string + # + def YAML.detect_implicit( val ) + @@loader.detect_implicit( val ) + end + # # Method to extract colon-seperated type and class, returning # the type and the constant of the class # def YAML.read_type_class( type, obj_class ) - type =~ /^([^:]+):(.+)/i - if $2 - type = $1 - $2.split( "::" ).each { |c| - obj_class = obj_class.const_get( c ) - } - end + scheme, domain, type, tclass = type.split( ':', 4 ) + tclass.split( "::" ).each { |c| obj_class = obj_class.const_get( c ) } if tclass return [ type, obj_class ] end diff --git a/lib/yaml/rubytypes.rb b/lib/yaml/rubytypes.rb index 727c31ca78..3d4992a29f 100644 --- a/lib/yaml/rubytypes.rb +++ b/lib/yaml/rubytypes.rb @@ -160,25 +160,18 @@ class Struct end YAML.add_ruby_type( 'struct' ) { |type, val| - type =~ /^struct:(\w+)/ if Hash === val - type = $1 - struct_type = nil - struct_def = [] - struct_name = "" - if $1.to_s.length > 1 - struct_name = $1[0..$1.length] - struct_def << struct_name - end + struct_type = nil # # Use existing Struct if it exists # begin - struct_type = Struct.const_get( struct_name ) + struct_name, struct_type = YAML.read_type_class( type, Struct ) rescue NameError end if not struct_type + struct_def = [ type.split( ':', 4 ).last ] struct_type = Struct.new( *struct_def.concat( val.keys.collect { |k| k.intern } ) ) end -- cgit v1.2.3