1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/ext/syck/bytecode.c
why 52e0ab245a * ext/syck/bytecode.c: turn off default implicit typing.
* ext/syck/implicit.c: detect base60 integers.

* ext/syck/rubyext.c: handle base60, as well as hex and octal
  with commas.  implicit typing of ruby symbols.

* test/yaml/test_yaml.rb: add test.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5452 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-01-12 22:55:09 +00:00

1109 lines
20 KiB
C

/* Generated by re2c 0.5 on Mon Jan 12 11:40:10 2004 */
#line 1 "bytecode.re"
/*
* bytecode.re
*
* $Author$
* $Date$
*
* Copyright (C) 2003 why the lucky stiff
*/
#include "syck.h"
#include "ruby.h"
#include "gram.h"
#define QUOTELEN 128
/*
* They do my bidding...
*/
#define YYCTYPE char
#define YYCURSOR parser->cursor
#define YYMARKER parser->marker
#define YYLIMIT parser->limit
#define YYTOKEN parser->token
#define YYTOKTMP parser->toktmp
#define YYLINEPTR parser->lineptr
#define YYLINECTPTR parser->linectptr
#define YYLINE parser->linect
#define YYFILL(n) syck_parser_read(parser)
extern SyckParser *syck_parser_ptr;
char *get_inline( SyckParser *parser );
/*
* 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
*/
#define CHK_NL(ptr) if ( *( ptr - 1 ) == '\n' && ptr > YYLINECTPTR ) { YYLINEPTR = ptr; YYLINE++; YYLINECTPTR = YYLINEPTR; }
/*
* 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 sycklex()
*/
#define FORCE_NEXT_TOKEN(tok) parser->force_token = tok;
/*
* Adding levels in bytecode requires us to make sure
* we've got all our tokens worked out.
*/
#define ADD_BYTE_LEVEL(lvl, len, s ) \
switch ( lvl->status ) \
{ \
case syck_lvl_seq: \
lvl->ncount++; \
ADD_LEVEL(len, syck_lvl_open); \
YYPOS(0); \
return '-'; \
\
case syck_lvl_map: \
lvl->ncount++; \
ADD_LEVEL(len, s); \
break; \
\
case syck_lvl_open: \
lvl->status = s; \
break; \
\
default: \
ADD_LEVEL(len, s); \
break; \
}
/*
* Nice little macro to ensure we're YAML_IOPENed to the current level.
* * Only use this macro in the "Document" section *
*/
#define ENSURE_YAML_IOPEN(last_lvl, lvl_type, to_len, reset) \
if ( last_lvl->spaces < to_len ) \
{ \
if ( last_lvl->status == syck_lvl_inline ) \
{ \
goto Document; \
} \
else \
{ \
ADD_LEVEL( to_len, lvl_type ); \
if ( reset == 1 ) YYPOS(0); \
return YAML_IOPEN; \
} \
}
/*
* Nice little macro to ensure closure of levels.
* * Only use this macro in the "Document" section *
*/
#define ENSURE_YAML_IEND(last_lvl, to_len) \
if ( last_lvl->spaces > to_len ) \
{ \
syck_parser_pop_level( parser ); \
YYPOS(0); \
return YAML_IEND; \
}
/*
* Concatenates string items and manages allocation
* to the string
*/
#define CAT(s, c, i, l) \
{ \
if ( i + 1 >= c ) \
{ \
c += QUOTELEN; \
S_REALLOC_N( s, char, c ); \
} \
s[i++] = l; \
s[i] = '\0'; \
}
/*
* Parser for standard YAML Bytecode [UTF-8]
*/
int
sycklex_bytecode_utf8( YYSTYPE *sycklval, SyckParser *parser )
{
SyckLevel *lvl;
int doc_level = 0;
syck_parser_ptr = parser;
if ( YYCURSOR == NULL )
{
syck_parser_read( parser );
}
if ( parser->force_token != 0 )
{
int t = parser->force_token;
parser->force_token = 0;
return t;
}
#line 173
lvl = CURRENT_LEVEL();
if ( lvl->status == syck_lvl_doc )
{
goto Document;
}
Header:
YYTOKEN = YYCURSOR;
{
YYCTYPE yych;
unsigned int yyaccept;
goto yy0;
yy1: ++YYCURSOR;
yy0:
if((YYLIMIT - YYCURSOR) < 3) YYFILL(3);
yych = *YYCURSOR;
switch(yych){
case '\000': goto yy2;
case 'D': goto yy3;
default: goto yy5;
}
yy2: YYCURSOR = YYMARKER;
switch(yyaccept){
case 0: goto yy4;
}
yy3: yyaccept = 0;
yych = *(YYMARKER = ++YYCURSOR);
switch(yych){
case '\n': goto yy6;
case '\r': goto yy8;
default: goto yy4;
}
yy4:
#line 200
{ YYPOS(0);
goto Document;
}
yy5: yych = *++YYCURSOR;
goto yy4;
yy6: yych = *++YYCURSOR;
yy7:
#line 187
{ if ( lvl->status == syck_lvl_header )
{
CHK_NL(YYCURSOR);
goto Directive;
}
else
{
ENSURE_YAML_IEND(lvl, -1);
YYPOS(0);
return 0;
}
}
yy8: yych = *++YYCURSOR;
switch(yych){
case '\n': goto yy6;
default: goto yy2;
}
}
#line 204
Document:
{
lvl = CURRENT_LEVEL();
if ( lvl->status == syck_lvl_header )
{
lvl->status = syck_lvl_doc;
}
YYTOKEN = YYCURSOR;
{
YYCTYPE yych;
unsigned int yyaccept;
goto yy9;
yy10: ++YYCURSOR;
yy9:
if((YYLIMIT - YYCURSOR) < 3) YYFILL(3);
yych = *YYCURSOR;
switch(yych){
case '\000': goto yy30;
case '\n': goto yy27;
case '\r': goto yy29;
case 'A': goto yy19;
case 'D': goto yy12;
case 'E': goto yy16;
case 'M': goto yy14;
case 'P': goto yy13;
case 'Q': goto yy15;
case 'R': goto yy21;
case 'S': goto yy17;
case 'T': goto yy23;
case 'c': goto yy25;
default: goto yy11;
}
yy11:yy12: yych = *++YYCURSOR;
switch(yych){
case '\n': goto yy41;
case '\r': goto yy44;
default: goto yy11;
}
yy13: yych = *++YYCURSOR;
switch(yych){
case '\n': goto yy41;
case '\r': goto yy43;
default: goto yy11;
}
yy14: yych = *++YYCURSOR;
switch(yych){
case '\n': goto yy38;
case '\r': goto yy40;
default: goto yy11;
}
yy15: yych = *++YYCURSOR;
switch(yych){
case '\n': goto yy35;
case '\r': goto yy37;
default: goto yy11;
}
yy16: yych = *++YYCURSOR;
switch(yych){
case '\n': goto yy32;
case '\r': goto yy34;
default: goto yy11;
}
yy17: yych = *++YYCURSOR;
yy18:
#line 289
{ ADD_BYTE_LEVEL(lvl, lvl->spaces + 1, syck_lvl_str);
goto Scalar;
}
yy19: yych = *++YYCURSOR;
yy20:
#line 293
{ ADD_BYTE_LEVEL(lvl, lvl->spaces + 1, syck_lvl_open);
sycklval->name = get_inline( parser );
syck_hdlr_remove_anchor( parser, sycklval->name );
CHK_NL(YYCURSOR);
return YAML_ANCHOR;
}
yy21: yych = *++YYCURSOR;
yy22:
#line 300
{ ADD_BYTE_LEVEL(lvl, lvl->spaces + 1, syck_lvl_str);
sycklval->name = get_inline( parser );
POP_LEVEL();
if ( *( YYCURSOR - 1 ) == '\n' ) YYCURSOR--;
return YAML_ALIAS;
}
yy23: yych = *++YYCURSOR;
yy24:
#line 307
{ char *qstr;
ADD_BYTE_LEVEL(lvl, lvl->spaces + 1, syck_lvl_open);
qstr = get_inline( parser );
CHK_NL(YYCURSOR);
if ( qstr[0] == '!' )
{
int qidx = strlen( qstr );
if ( qstr[1] == '\0' )
{
free( qstr );
return YAML_ITRANSFER;
}
lvl = CURRENT_LEVEL();
/*
* URL Prefixing
*/
if ( qstr[1] == '^' )
{
sycklval->name = S_ALLOC_N( char, qidx + strlen( lvl->domain ) );
sycklval->name[0] = '\0';
strcat( sycklval->name, lvl->domain );
strncat( sycklval->name, qstr + 2, qidx - 2 );
free( qstr );
}
else
{
char *carat = qstr + 1;
char *qend = qstr + qidx;
while ( (++carat) < qend )
{
if ( *carat == '^' )
break;
}
if ( carat < qend )
{
free( lvl->domain );
lvl->domain = syck_strndup( qstr + 1, carat - ( qstr + 1 ) );
sycklval->name = S_ALLOC_N( char, ( qend - carat ) + strlen( lvl->domain ) );
sycklval->name[0] = '\0';
strcat( sycklval->name, lvl->domain );
strncat( sycklval->name, carat + 1, ( qend - carat ) - 1 );
free( qstr );
}
else
{
sycklval->name = S_ALLOC_N( char, strlen( qstr ) );
sycklval->name[0] = '\0';
S_MEMCPY( sycklval->name, qstr + 1, char, strlen( qstr ) );
free( qstr );
}
}
return YAML_TRANSFER;
}
sycklval->name = qstr;
return YAML_TAGURI;
}
yy25: yych = *++YYCURSOR;
yy26:
#line 367
{ goto Comment; }
yy27: yych = *++YYCURSOR;
yy28:
#line 369
{ CHK_NL(YYCURSOR);
if ( lvl->status == syck_lvl_seq )
{
return YAML_INDENT;
}
else if ( lvl->status == syck_lvl_map )
{
if ( lvl->ncount % 2 == 1 ) return ':';
else return YAML_INDENT;
}
goto Document;
}
yy29: yych = *++YYCURSOR;
switch(yych){
case '\n': goto yy27;
default: goto yy11;
}
yy30: yych = *++YYCURSOR;
yy31:
#line 382
{ ENSURE_YAML_IEND(lvl, -1);
YYPOS(0);
return 0;
}
yy32: yych = *++YYCURSOR;
yy33:
#line 253
{ if ( lvl->status == syck_lvl_seq && lvl->ncount == 0 )
{
lvl->ncount++;
YYPOS(0);
FORCE_NEXT_TOKEN( ']' );
return '[';
}
else if ( lvl->status == syck_lvl_map && lvl->ncount == 0 )
{
lvl->ncount++;
YYPOS(0);
FORCE_NEXT_TOKEN( '}' );
return '{';
}
POP_LEVEL();
lvl = CURRENT_LEVEL();
if ( lvl->status == syck_lvl_seq )
{
FORCE_NEXT_TOKEN(YAML_INDENT);
}
else if ( lvl->status == syck_lvl_map )
{
if ( lvl->ncount % 2 == 1 )
{
FORCE_NEXT_TOKEN(':');
}
else
{
FORCE_NEXT_TOKEN(YAML_INDENT);
}
}
CHK_NL(YYCURSOR);
return YAML_IEND;
}
yy34: yych = *++YYCURSOR;
switch(yych){
case '\n': goto yy32;
default: goto yy11;
}
yy35: yych = *++YYCURSOR;
yy36:
#line 238
{ int complex = 0;
if ( lvl->ncount % 2 == 0 && ( lvl->status == syck_lvl_map || lvl->status == syck_lvl_seq ) )
{
complex = 1;
}
ADD_BYTE_LEVEL(lvl, lvl->spaces + 1, syck_lvl_seq);
CHK_NL(YYCURSOR);
if ( complex )
{
FORCE_NEXT_TOKEN( YAML_IOPEN );
return '?';
}
return YAML_IOPEN;
}
yy37: yych = *++YYCURSOR;
switch(yych){
case '\n': goto yy35;
default: goto yy11;
}
yy38: yych = *++YYCURSOR;
yy39:
#line 223
{ int complex = 0;
if ( lvl->ncount % 2 == 0 && ( lvl->status == syck_lvl_map || lvl->status == syck_lvl_seq ) )
{
complex = 1;
}
ADD_BYTE_LEVEL(lvl, lvl->spaces + 1, syck_lvl_map);
CHK_NL(YYCURSOR);
if ( complex )
{
FORCE_NEXT_TOKEN( YAML_IOPEN );
return '?';
}
return YAML_IOPEN;
}
yy40: yych = *++YYCURSOR;
switch(yych){
case '\n': goto yy38;
default: goto yy11;
}
yy41: yych = *++YYCURSOR;
yy42:
#line 218
{ ENSURE_YAML_IEND(lvl, -1);
YYPOS(0);
return 0;
}
yy43: yych = *++YYCURSOR;
switch(yych){
case '\n': goto yy41;
default: goto yy11;
}
yy44: yych = *++YYCURSOR;
switch(yych){
case '\n': goto yy41;
default: goto yy11;
}
}
#line 387
}
Directive:
{
YYTOKEN = YYCURSOR;
{
YYCTYPE yych;
unsigned int yyaccept;
goto yy45;
yy46: ++YYCURSOR;
yy45:
if((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
yych = *YYCURSOR;
switch(yych){
case '\000': goto yy47;
case 'V': goto yy48;
default: goto yy50;
}
yy47: YYCURSOR = YYMARKER;
switch(yyaccept){
case 0: goto yy49;
}
yy48: yyaccept = 0;
yych = *(YYMARKER = ++YYCURSOR);
switch(yych){
case '.':
case '/':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case ':':
case ';':
case '<':
case '=':
case '>':
case '?':
case '@':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '[':
case '\\':
case ']':
case '^':
case '_': case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z': goto yy51;
default: goto yy49;
}
yy49:
#line 400
{ YYCURSOR = YYTOKEN;
return YAML_DOCSEP;
}
yy50: yych = *++YYCURSOR;
goto yy49;
yy51: ++YYCURSOR;
if(YYLIMIT == YYCURSOR) YYFILL(1);
yych = *YYCURSOR;
yy52: switch(yych){
case '.':
case '/':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9': case ';':
case '<':
case '=':
case '>':
case '?':
case '@':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '[':
case '\\':
case ']':
case '^':
case '_': case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z': goto yy51;
case ':': goto yy53;
default: goto yy47;
}
yy53: yych = *++YYCURSOR;
switch(yych){
case '.':
case '/':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case ':':
case ';':
case '<':
case '=':
case '>':
case '?':
case '@':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '[':
case '\\':
case ']':
case '^':
case '_': case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z': goto yy54;
default: goto yy47;
}
yy54: ++YYCURSOR;
if(YYLIMIT == YYCURSOR) YYFILL(1);
yych = *YYCURSOR;
yy55: switch(yych){
case '\n': goto yy56;
case '\r': goto yy58;
case '.':
case '/':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case ':':
case ';':
case '<':
case '=':
case '>':
case '?':
case '@':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '[':
case '\\':
case ']':
case '^':
case '_': case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z': goto yy54;
default: goto yy47;
}
yy56: yych = *++YYCURSOR;
yy57:
#line 397
{ CHK_NL(YYCURSOR);
goto Directive; }
yy58: yych = *++YYCURSOR;
switch(yych){
case '\n': goto yy56;
default: goto yy47;
}
}
#line 403
}
Comment:
{
YYTOKEN = YYCURSOR;
{
YYCTYPE yych;
unsigned int yyaccept;
goto yy59;
yy60: ++YYCURSOR;
yy59:
if((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
yych = *YYCURSOR;
switch(yych){
case '\000': goto yy61;
case '\n': goto yy62;
case '\r': goto yy64;
default: goto yy66;
}
yy61:yy62: yych = *++YYCURSOR;
yy63:
#line 413
{ CHK_NL(YYCURSOR);
goto Document; }
yy64: yych = *++YYCURSOR;
switch(yych){
case '\n': goto yy67;
default: goto yy65;
}
yy65:
#line 416
{ goto Comment; }
yy66: yych = *++YYCURSOR;
goto yy65;
yy67: yych = *++YYCURSOR;
goto yy63;
}
#line 418
}
Scalar:
{
int idx = 0;
int cap = 100;
char *str = S_ALLOC_N( char, cap );
char *tok;
str[0] = '\0';
Scalar2:
tok = YYCURSOR;
{
YYCTYPE yych;
unsigned int yyaccept;
goto yy68;
yy69: ++YYCURSOR;
yy68:
if((YYLIMIT - YYCURSOR) < 3) YYFILL(3);
yych = *YYCURSOR;
switch(yych){
case '\000': goto yy74;
case '\n': goto yy70;
case '\r': goto yy72;
default: goto yy76;
}
yy70: yych = *++YYCURSOR;
switch(yych){
case 'C': goto yy78;
case 'N': goto yy80;
case 'Z': goto yy83;
default: goto yy71;
}
yy71:
#line 462
{ YYCURSOR = tok;
goto ScalarEnd;
}
yy72: yych = *++YYCURSOR;
switch(yych){
case '\n': goto yy77;
default: goto yy73;
}
yy73:
#line 470
{ CAT(str, cap, idx, tok[0]);
goto Scalar2;
}
yy74: yych = *++YYCURSOR;
yy75:
#line 466
{ YYCURSOR = tok;
goto ScalarEnd;
}
yy76: yych = *++YYCURSOR;
goto yy73;
yy77: yych = *++YYCURSOR;
switch(yych){
case 'C': goto yy78;
case 'N': goto yy80;
case 'Z': goto yy83;
default: goto yy71;
}
yy78: yych = *++YYCURSOR;
yy79:
#line 436
{ CHK_NL(tok+1);
goto Scalar2; }
yy80: ++YYCURSOR;
if(YYLIMIT == YYCURSOR) YYFILL(1);
yych = *YYCURSOR;
yy81: switch(yych){
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9': goto yy80;
default: goto yy82;
}
yy82:
#line 439
{ CHK_NL(tok+1);
if ( tok + 2 < YYCURSOR )
{
char *count = tok + 2;
int total = strtod( count, NULL );
int i;
for ( i = 0; i < total; i++ )
{
CAT(str, cap, idx, '\n');
}
}
else
{
CAT(str, cap, idx, '\n');
}
goto Scalar2;
}
yy83: yych = *++YYCURSOR;
yy84:
#line 457
{ CHK_NL(tok+1);
CAT(str, cap, idx, '\0');
goto Scalar2;
}
}
#line 474
ScalarEnd:
{
SyckNode *n = syck_alloc_str();
n->data.str->ptr = str;
n->data.str->len = idx;
sycklval->nodeData = n;
POP_LEVEL();
if ( parser->implicit_typing == 1 )
{
try_tag_implicit( sycklval->nodeData, parser->taguri_expansion );
}
return YAML_PLAIN;
}
}
}
char *
get_inline( SyckParser *parser )
{
int idx = 0;
int cap = 100;
char *str = S_ALLOC_N( char, cap );
char *tok;
str[0] = '\0';
Inline:
{
tok = YYCURSOR;
{
YYCTYPE yych;
unsigned int yyaccept;
goto yy85;
yy86: ++YYCURSOR;
yy85:
if((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
yych = *YYCURSOR;
switch(yych){
case '\000': goto yy91;
case '\n': goto yy87;
case '\r': goto yy89;
default: goto yy93;
}
yy87: yych = *++YYCURSOR;
yy88:
#line 509
{ CHK_NL(YYCURSOR);
return str; }
yy89: yych = *++YYCURSOR;
switch(yych){
case '\n': goto yy94;
default: goto yy90;
}
yy90:
#line 516
{ CAT(str, cap, idx, tok[0]);
goto Inline;
}
yy91: yych = *++YYCURSOR;
yy92:
#line 512
{ YYCURSOR = tok;
return str;
}
yy93: yych = *++YYCURSOR;
goto yy90;
yy94: yych = *++YYCURSOR;
goto yy88;
}
#line 520
}
}