/* Generated by re2c 0.5 on Tue Oct 14 13:56:32 2003 */
#line 1 "bytecode.re"
/*
 * bytecode.re
 *
 * $Author: knu $
 * $Date: 2003/10/19 19:21:34 $
 *
 * Copyright (C) 2003 why the lucky stiff
 */
#include "syck.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

/*
 * 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_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 163


    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;
	if(yych <= '\000')	goto yy2;
	if(yych == 'D')	goto yy3;
	goto yy5;
yy2:	YYCURSOR = YYMARKER;
	switch(yyaccept){
	case 0:	goto yy4;
	}
yy3:	yyaccept = 0;
	yych = *(YYMARKER = ++YYCURSOR);
	if(yych == '\n')	goto yy6;
	if(yych == '\r')	goto yy8;
yy4:
#line 189
	{   YYPOS(0);
            goto Document;
        }
yy5:	yych = *++YYCURSOR;
	goto yy4;
yy6:	yych = *++YYCURSOR;
yy7:
#line 177
	{   if ( lvl->status == syck_lvl_header )
            {
                goto Directive;
            }
            else
            {
                ENSURE_YAML_IEND(lvl, -1);
                YYPOS(0);
                return 0;
            }
        }
yy8:	yych = *++YYCURSOR;
	if(yych == '\n')	goto yy6;
	goto yy2;
}
#line 193


    lvl->status = syck_lvl_doc;

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;
	if(yych <= 'E'){
		if(yych <= '\r'){
			if(yych <= '\t'){
				if(yych <= '\000')	goto yy30;
			} else {
				if(yych <= '\n')	goto yy27;
				if(yych >= '\r')	goto yy29;
			}
		} else {
			if(yych <= 'A'){
				if(yych >= 'A')	goto yy19;
			} else {
				if(yych <= 'C')	goto yy11;
				if(yych <= 'D')	goto yy12;
				goto yy16;
			}
		}
	} else {
		if(yych <= 'Q'){
			if(yych <= 'M'){
				if(yych >= 'M')	goto yy14;
			} else {
				if(yych <= 'O')	goto yy11;
				if(yych <= 'P')	goto yy13;
				goto yy15;
			}
		} else {
			if(yych <= 'T'){
				if(yych <= 'R')	goto yy21;
				if(yych <= 'S')	goto yy17;
				goto yy23;
			} else {
				if(yych == 'c')	goto yy25;
			}
		}
	}
yy11:yy12:	yych = *++YYCURSOR;
	if(yych == '\n')	goto yy41;
	if(yych == '\r')	goto yy44;
	goto yy11;
yy13:	yych = *++YYCURSOR;
	if(yych == '\n')	goto yy41;
	if(yych == '\r')	goto yy43;
	goto yy11;
yy14:	yych = *++YYCURSOR;
	if(yych == '\n')	goto yy38;
	if(yych == '\r')	goto yy40;
	goto yy11;
yy15:	yych = *++YYCURSOR;
	if(yych == '\n')	goto yy35;
	if(yych == '\r')	goto yy37;
	goto yy11;
yy16:	yych = *++YYCURSOR;
	if(yych == '\n')	goto yy32;
	if(yych == '\r')	goto yy34;
	goto yy11;
yy17:	yych = *++YYCURSOR;
yy18:
#line 243
	{   ADD_BYTE_LEVEL(lvl, lvl->spaces + 1, syck_lvl_str); 
            goto Scalar;
        }
yy19:	yych = *++YYCURSOR;
yy20:
#line 247
	{   ADD_BYTE_LEVEL(lvl, lvl->spaces + 1, syck_lvl_open);
            sycklval->name = get_inline( parser );
            syck_hdlr_remove_anchor( parser, sycklval->name );
            return YAML_ANCHOR;
        }
yy21:	yych = *++YYCURSOR;
yy22:
#line 253
	{   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 260
	{   sycklval->name = get_inline( parser );
            if ( sycklval->name[0] == '!' )
            {
                S_MEMCPY( sycklval->name, sycklval->name + 1, char, strlen( sycklval->name ) );
            }
            return YAML_TAGURI;
        }
yy25:	yych = *++YYCURSOR;
yy26:
#line 268
	{   goto Comment; }
yy27:	yych = *++YYCURSOR;
yy28:
#line 270
	{   if ( lvl->status == syck_lvl_seq )
            {
                return YAML_INDENT; 
            }
            else if ( lvl->status == syck_lvl_map )
            {
                lvl->ncount++;
                if ( lvl->ncount % 2 == 1 ) return ':';
                else                        return YAML_INDENT;
            }
            goto Document;
        }
yy29:	yych = *++YYCURSOR;
	if(yych == '\n')	goto yy27;
	goto yy11;
yy30:	yych = *++YYCURSOR;
yy31:
#line 283
	{   ENSURE_YAML_IEND(lvl, -1);
            YYPOS(0);
            return 0;
        }
yy32:	yych = *++YYCURSOR;
yy33:
#line 222
	{   POP_LEVEL();
            lvl = CURRENT_LEVEL();
            if ( lvl->status == syck_lvl_seq )
            {
                FORCE_NEXT_TOKEN(YAML_INDENT);   
            }
            else if ( lvl->status == syck_lvl_map )
            {
                lvl->ncount++;
                if ( lvl->ncount % 2 == 1 )
                {
                    FORCE_NEXT_TOKEN(':');
                }
                else
                {
                    FORCE_NEXT_TOKEN(YAML_INDENT);
                }
            }
            return YAML_IEND;
        }
yy34:	yych = *++YYCURSOR;
	if(yych == '\n')	goto yy32;
	goto yy11;
yy35:	yych = *++YYCURSOR;
yy36:
#line 218
	{   ADD_BYTE_LEVEL(lvl, lvl->spaces + 1, syck_lvl_seq);
            return YAML_IOPEN;
        }
yy37:	yych = *++YYCURSOR;
	if(yych == '\n')	goto yy35;
	goto yy11;
yy38:	yych = *++YYCURSOR;
yy39:
#line 214
	{   ADD_BYTE_LEVEL(lvl, lvl->spaces + 1, syck_lvl_map); 
            return YAML_IOPEN;
        }
yy40:	yych = *++YYCURSOR;
	if(yych == '\n')	goto yy38;
	goto yy11;
yy41:	yych = *++YYCURSOR;
yy42:
#line 209
	{   ENSURE_YAML_IEND(lvl, -1);
                YYPOS(0);
                return 0;
            }
yy43:	yych = *++YYCURSOR;
	if(yych == '\n')	goto yy41;
	goto yy11;
yy44:	yych = *++YYCURSOR;
	if(yych == '\n')	goto yy41;
	goto yy11;
}
#line 288


    }

Directive:
    {
        YYTOKTMP = YYCURSOR;

{
	YYCTYPE yych;
	unsigned int yyaccept;
	goto yy45;
yy46:	++YYCURSOR;
yy45:
	if((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
	yych = *YYCURSOR;
	if(yych <= '\000')	goto yy47;
	if(yych == 'V')	goto yy48;
	goto yy50;
yy47:	YYCURSOR = YYMARKER;
	switch(yyaccept){
	case 0:	goto yy49;
	}
yy48:	yyaccept = 0;
	yych = *(YYMARKER = ++YYCURSOR);
	if(yych <= '-')	goto yy49;
	if(yych == '`')	goto yy49;
	if(yych <= 'z')	goto yy51;
yy49:
#line 300
	{   YYCURSOR = YYTOKTMP;
               return YAML_DOCSEP;
           }
yy50:	yych = *++YYCURSOR;
	goto yy49;
yy51:	++YYCURSOR;
	if(YYLIMIT == YYCURSOR) YYFILL(1);
	yych = *YYCURSOR;
yy52:	if(yych <= ':'){
		if(yych <= '-')	goto yy47;
		if(yych <= '9')	goto yy51;
	} else {
		if(yych == '`')	goto yy47;
		if(yych <= 'z')	goto yy51;
		goto yy47;
	}
yy53:	yych = *++YYCURSOR;
	if(yych <= '-')	goto yy47;
	if(yych == '`')	goto yy47;
	if(yych >= '{')	goto yy47;
yy54:	++YYCURSOR;
	if(YYLIMIT == YYCURSOR) YYFILL(1);
	yych = *YYCURSOR;
yy55:	if(yych <= '\r'){
		if(yych == '\n')	goto yy56;
		if(yych <= '\f')	goto yy47;
		goto yy58;
	} else {
		if(yych <= '_'){
			if(yych <= '-')	goto yy47;
			goto yy54;
		} else {
			if(yych <= '`')	goto yy47;
			if(yych <= 'z')	goto yy54;
			goto yy47;
		}
	}
yy56:	yych = *++YYCURSOR;
yy57:
#line 298
	{   goto Directive; }
yy58:	yych = *++YYCURSOR;
	if(yych == '\n')	goto yy56;
	goto yy47;
}
#line 303


    }

Comment:
    {
        YYTOKTMP = YYCURSOR;

{
	YYCTYPE yych;
	unsigned int yyaccept;
	goto yy59;
yy60:	++YYCURSOR;
yy59:
	if((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
	yych = *YYCURSOR;
	if(yych <= '\n'){
		if(yych <= '\000')	goto yy61;
		if(yych <= '\t')	goto yy66;
		goto yy62;
	} else {
		if(yych == '\r')	goto yy64;
		goto yy66;
	}
yy61:yy62:	yych = *++YYCURSOR;
yy63:
#line 313
	{   goto Document; }
yy64:	yych = *++YYCURSOR;
	if(yych == '\n')	goto yy67;
yy65:
#line 315
	{   goto Comment; }
yy66:	yych = *++YYCURSOR;
	goto yy65;
yy67:	yych = *++YYCURSOR;
	goto yy63;
}
#line 317


    }

Scalar:
    {
    int idx = 0;
    int cap = 100;
    char *str = S_ALLOC_N( char, cap );
    char *tok;

Scalar2:
    tok = YYCURSOR;

{
	YYCTYPE yych;
	unsigned int yyaccept;
	goto yy68;
yy69:	++YYCURSOR;
yy68:
	if((YYLIMIT - YYCURSOR) < 3) YYFILL(3);
	yych = *YYCURSOR;
	if(yych <= '\n'){
		if(yych <= '\000')	goto yy74;
		if(yych <= '\t')	goto yy76;
	} else {
		if(yych == '\r')	goto yy72;
		goto yy76;
	}
yy70:	yych = *++YYCURSOR;
	if(yych <= 'M'){
		if(yych == 'C')	goto yy78;
	} else {
		if(yych <= 'N')	goto yy80;
		if(yych == 'Z')	goto yy83;
	}
yy71:
#line 356
	{   YYCURSOR = tok;
            goto ScalarEnd; 
        }
yy72:	yych = *++YYCURSOR;
	if(yych == '\n')	goto yy77;
yy73:
#line 364
	{   CAT(str, cap, idx, tok[0]);
            goto Scalar2; 
        }
yy74:	yych = *++YYCURSOR;
yy75:
#line 360
	{   YYCURSOR = tok;
            goto ScalarEnd;
        }
yy76:	yych = *++YYCURSOR;
	goto yy73;
yy77:	yych = *++YYCURSOR;
	if(yych <= 'M'){
		if(yych != 'C')	goto yy71;
	} else {
		if(yych <= 'N')	goto yy80;
		if(yych == 'Z')	goto yy83;
		goto yy71;
	}
yy78:	yych = *++YYCURSOR;
yy79:
#line 333
	{   goto Scalar2; }
yy80:	++YYCURSOR;
	if(YYLIMIT == YYCURSOR) YYFILL(1);
	yych = *YYCURSOR;
yy81:	if(yych <= '/')	goto yy82;
	if(yych <= '9')	goto yy80;
yy82:
#line 335
	{   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 352
	{   CAT(str, cap, idx, '\0');
            goto Scalar2; 
        }
}
#line 368


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;

Inline:
    {
        tok = YYCURSOR;

{
	YYCTYPE yych;
	unsigned int yyaccept;
	goto yy85;
yy86:	++YYCURSOR;
yy85:
	if((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
	yych = *YYCURSOR;
	if(yych <= '\n'){
		if(yych <= '\000')	goto yy91;
		if(yych <= '\t')	goto yy93;
	} else {
		if(yych == '\r')	goto yy89;
		goto yy93;
	}
yy87:	yych = *++YYCURSOR;
yy88:
#line 401
	{   return str; }
yy89:	yych = *++YYCURSOR;
	if(yych == '\n')	goto yy94;
yy90:
#line 407
	{   CAT(str, cap, idx, tok[0]);
                goto Inline; 
            }
yy91:	yych = *++YYCURSOR;
yy92:
#line 403
	{   YYCURSOR = tok;
                return str;
            }
yy93:	yych = *++YYCURSOR;
	goto yy90;
yy94:	yych = *++YYCURSOR;
	goto yy88;
}
#line 411


    }

}

