Changeset 263

Show
Ignore:
Timestamp:
12/27/07 07:05:17 (4 years ago)
Author:
xi
Message:

Completed the first phase of API refactoring.

Location:
libyaml/trunk
Files:
10 modified

Legend:

Unmodified
Added
Removed
  • libyaml/trunk/src/api.c

    r261 r263  
    173173 
    174174    memset(parser, 0, sizeof(yaml_parser_t)); 
    175     if (!BUFFER_INIT(parser, parser->raw_input, RAW_INPUT_BUFFER_CAPACITY)) 
     175    if (!STRING_INIT(parser, parser->raw_input, RAW_INPUT_BUFFER_CAPACITY)) 
    176176        goto error; 
    177     if (!BUFFER_INIT(parser, parser->input, INPUT_BUFFER_CAPACITY)) 
     177    if (!STRING_INIT(parser, parser->input, INPUT_BUFFER_CAPACITY)) 
    178178        goto error; 
    179179    if (!QUEUE_INIT(parser, parser->tokens, INITIAL_QUEUE_CAPACITY)) 
     
    207207    assert(parser); /* Non-NULL parser object expected. */ 
    208208 
    209     BUFFER_DEL(parser, parser->raw_input); 
    210     BUFFER_DEL(parser, parser->input); 
     209    STRING_DEL(parser, parser->raw_input); 
     210    STRING_DEL(parser, parser->input); 
    211211    while (!QUEUE_EMPTY(parser, parser->tokens)) { 
    212212        yaml_token_destroy(&DEQUEUE(parser, parser->tokens)); 
     
    358358 
    359359    memset(emitter, 0, sizeof(yaml_emitter_t)); 
    360     if (!BUFFER_INIT(emitter, emitter->output, OUTPUT_BUFFER_CAPACITY)) 
     360    if (!STRING_INIT(emitter, emitter->output, OUTPUT_BUFFER_CAPACITY)) 
    361361        goto error; 
    362     if (!BUFFER_INIT(emitter, emitter->raw_output, RAW_OUTPUT_BUFFER_CAPACITY)) 
     362    if (!STRING_INIT(emitter, emitter->raw_output, RAW_OUTPUT_BUFFER_CAPACITY)) 
    363363        goto error; 
    364364    if (!STACK_INIT(emitter, emitter->states, INITIAL_STACK_CAPACITY)) 
     
    388388    assert(emitter);    /* Non-NULL emitter object expected. */ 
    389389 
    390     BUFFER_DEL(emitter, emitter->output); 
    391     BUFFER_DEL(emitter, emitter->raw_output); 
     390    STRING_DEL(emitter, emitter->output); 
     391    STRING_DEL(emitter, emitter->raw_output); 
    392392    STACK_DEL(emitter, emitter->states); 
    393393    while (!QUEUE_EMPTY(emitter, emitter->events)) { 
  • libyaml/trunk/src/dumper.c

    r238 r263  
    11 
    22#include "yaml_private.h" 
     3 
     4#if 0 
    35 
    46/* 
     
    393395} 
    394396 
     397#endif 
     398 
  • libyaml/trunk/src/emitter.c

    r241 r263  
    77 
    88#define FLUSH(emitter)                                                          \ 
    9     ((emitter->buffer.pointer+5 < emitter->buffer.end)                          \ 
     9    ((emitter->output.pointer+5 < emitter->output.capacity)                     \ 
    1010     || yaml_emitter_flush(emitter)) 
    1111 
     
    1616#define PUT(emitter,value)                                                      \ 
    1717    (FLUSH(emitter)                                                             \ 
    18      && (*(emitter->buffer.pointer++) = (yaml_char_t)(value),                   \ 
     18     && (JOIN_OCTET(emitter->output,(yaml_char_t)(value)),                      \ 
    1919         emitter->column ++,                                                    \ 
    2020         1)) 
     
    2727    (FLUSH(emitter)                                                             \ 
    2828     && ((emitter->line_break == YAML_CR_BREAK ?                                \ 
    29              (*(emitter->buffer.pointer++) = (yaml_char_t) '\r') :              \ 
     29             JOIN_OCTET(emitter->output, (yaml_char_t) '\r') :                  \ 
    3030          emitter->line_break == YAML_LN_BREAK ?                                \ 
    31              (*(emitter->buffer.pointer++) = (yaml_char_t) '\n') :              \ 
     31             JOIN_OCTET(emitter->output, (yaml_char_t) '\n') :                  \ 
    3232          emitter->line_break == YAML_CRLN_BREAK ?                              \ 
    33              (*(emitter->buffer.pointer++) = (yaml_char_t) '\r',                \ 
    34               *(emitter->buffer.pointer++) = (yaml_char_t) '\n') : 0),          \ 
     33             (JOIN_OCTET(emitter->output, (yaml_char_t) '\r'),                  \ 
     34              JOIN_OCTET(emitter->output, (yaml_char_t) '\n')) : 0),            \ 
    3535         emitter->column = 0,                                                   \ 
    3636         emitter->line ++,                                                      \ 
     
    4343#define WRITE(emitter,string)                                                   \ 
    4444    (FLUSH(emitter)                                                             \ 
    45      && (COPY(emitter->buffer,string),                                          \ 
     45     && (COPY(emitter->output,string),                                          \ 
    4646         emitter->column ++,                                                    \ 
    4747         1)) 
     
    5757          string.pointer ++,                                                    \ 
    5858          1) :                                                                  \ 
    59          (COPY(emitter->buffer,string),                                         \ 
     59         (COPY(emitter->output,string),                                         \ 
    6060          emitter->column = 0,                                                  \ 
    6161          emitter->line ++,                                                     \ 
     
    7474 
    7575static int 
    76 yaml_emitter_set_emitter_error(yaml_emitter_t *emitter, const char *problem); 
    77  
    78 static int 
    7976yaml_emitter_need_more_events(yaml_emitter_t *emitter); 
    8077 
     
    136133static int 
    137134yaml_emitter_emit_node(yaml_emitter_t *emitter, yaml_event_t *event, 
    138         int root, int sequence, int mapping, int simple_key); 
     135        int is_root, int is_sequence, int is_mapping, int is_simple_key); 
    139136 
    140137static int 
     
    262259 
    263260/* 
    264  * Set an emitter error and return 0. 
    265  */ 
    266  
    267 static int 
    268 yaml_emitter_set_emitter_error(yaml_emitter_t *emitter, const char *problem) 
    269 { 
    270     emitter->error = YAML_EMITTER_ERROR; 
    271     emitter->problem = problem; 
    272  
    273     return 0; 
    274 } 
    275  
    276 /* 
    277261 * Emit an event. 
    278262 */ 
     
    287271 
    288272    while (!yaml_emitter_need_more_events(emitter)) { 
    289         if (!yaml_emitter_analyze_event(emitter, emitter->events.head)) 
    290             return 0; 
    291         if (!yaml_emitter_state_machine(emitter, emitter->events.head)) 
     273        if (!yaml_emitter_analyze_event(emitter, 
     274                    emitter->events.list + emitter->events.head)) 
     275            return 0; 
     276        if (!yaml_emitter_state_machine(emitter, 
     277                    emitter->events.list + emitter->events.head)) 
    292278            return 0; 
    293279        yaml_event_delete(&DEQUEUE(emitter, emitter->events)); 
     
    311297    int level = 0; 
    312298    int accumulate = 0; 
    313     yaml_event_t *event; 
     299    size_t idx; 
    314300 
    315301    if (QUEUE_EMPTY(emitter, emitter->events)) 
    316302        return 1; 
    317303 
    318     switch (emitter->events.head->type) { 
     304    switch (emitter->events.list[emitter->events.head].type) { 
    319305        case YAML_DOCUMENT_START_EVENT: 
    320306            accumulate = 1; 
     
    333319        return 0; 
    334320 
    335     for (event = emitter->events.head; event != emitter->events.tail; event ++) { 
     321    for (idx = emitter->events.head; idx < emitter->events.tail; idx ++) { 
     322        yaml_event_t *event = emitter->events.list+idx; 
    336323        switch (event->type) { 
    337324            case YAML_STREAM_START_EVENT: 
     
    365352        yaml_tag_directive_t value, int allow_duplicates) 
    366353{ 
    367     yaml_tag_directive_t *tag_directive; 
     354    int idx; 
    368355    yaml_tag_directive_t copy = { NULL, NULL }; 
    369356 
    370     for (tag_directive = emitter->tag_directives.start; 
    371             tag_directive != emitter->tag_directives.top; tag_directive ++) { 
     357    for (idx = 0; idx < emitter->tag_directives.length; idx ++) { 
     358        yaml_tag_directive_t *tag_directive = emitter->tag_directives.list+idx; 
    372359        if (strcmp((char *)value.handle, (char *)tag_directive->handle) == 0) { 
    373360            if (allow_duplicates) 
    374361                return 1; 
    375             return yaml_emitter_set_emitter_error(emitter, 
    376                     "duplicate %TAG directive"); 
     362            return EMITTER_ERROR_INIT(emitter, "duplicate %TAG directive"); 
    377363        } 
    378364    } 
     
    381367    copy.prefix = yaml_strdup(value.prefix); 
    382368    if (!copy.handle || !copy.prefix) { 
    383         emitter->error = YAML_MEMORY_ERROR; 
     369        MEMORY_ERROR_INIT(emitter); 
    384370        goto error; 
    385371    } 
     
    478464 
    479465        case YAML_EMIT_END_STATE: 
    480             return yaml_emitter_set_emitter_error(emitter, 
     466            return EMITTER_ERROR_INIT(emitter, 
    481467                    "expected nothing after STREAM-END"); 
    482468 
     
    527513        emitter->line = 0; 
    528514        emitter->column = 0; 
    529         emitter->whitespace = 1; 
    530         emitter->indention = 1; 
     515        emitter->is_whitespace = 1; 
     516        emitter->is_indention = 1; 
    531517 
    532518        if (emitter->encoding != YAML_UTF8_ENCODING) { 
     
    540526    } 
    541527 
    542     return yaml_emitter_set_emitter_error(emitter, 
    543             "expected STREAM-START"); 
     528    return EMITTER_ERROR_INIT(emitter, "expected STREAM-START"); 
    544529} 
    545530 
     
    560545        }; 
    561546        yaml_tag_directive_t *tag_directive; 
    562         int implicit; 
     547        int is_implicit; 
     548        int idx; 
    563549 
    564550        if (event->data.document_start.version_directive) { 
     
    568554        } 
    569555 
    570         for (tag_directive = event->data.document_start.tag_directives.start; 
    571                 tag_directive != event->data.document_start.tag_directives.end; 
    572                 tag_directive ++) { 
     556        for (idx = 0; idx < event->data.document_start.tag_directives.length; idx++) { 
     557            tag_directive = event->data.document_start.tag_directives.list+idx; 
    573558            if (!yaml_emitter_analyze_tag_directive(emitter, *tag_directive)) 
    574559                return 0; 
     
    583568        } 
    584569 
    585         implicit = event->data.document_start.implicit; 
    586         if (!first || emitter->canonical) { 
    587             implicit = 0; 
     570        is_implicit = event->data.document_start.is_implicit; 
     571        if (!first || emitter->is_canonical) { 
     572            is_implicit = 0; 
    588573        } 
    589574 
    590575        if (event->data.document_start.version_directive) { 
    591             implicit = 0; 
     576            is_implicit = 0; 
    592577            if (!yaml_emitter_write_indicator(emitter, "%YAML", 1, 0, 0)) 
    593578                return 0; 
     
    598583        } 
    599584         
    600         if (event->data.document_start.tag_directives.start 
    601                 != event->data.document_start.tag_directives.end) { 
    602             implicit = 0; 
    603             for (tag_directive = event->data.document_start.tag_directives.start; 
    604                     tag_directive != event->data.document_start.tag_directives.end; 
    605                     tag_directive ++) { 
     585        if (event->data.document_start.tag_directives.length) { 
     586            is_implicit = 0; 
     587            for (idx = 0; idx < event->data.document_start.tag_directives.length; 
     588                    idx++) { 
     589                tag_directive = event->data.document_start.tag_directives.list+idx; 
    606590                if (!yaml_emitter_write_indicator(emitter, "%TAG", 1, 0, 0)) 
    607591                    return 0; 
     
    618602 
    619603        if (yaml_emitter_check_empty_document(emitter)) { 
    620             implicit = 0; 
    621         } 
    622  
    623         if (!implicit) { 
     604            is_implicit = 0; 
     605        } 
     606 
     607        if (!is_implicit) { 
    624608            if (!yaml_emitter_write_indent(emitter)) 
    625609                return 0; 
    626610            if (!yaml_emitter_write_indicator(emitter, "---", 1, 0, 0)) 
    627611                return 0; 
    628             if (emitter->canonical) { 
     612            if (emitter->is_canonical) { 
    629613                if (!yaml_emitter_write_indent(emitter)) 
    630614                    return 0; 
     
    647631    } 
    648632 
    649     return yaml_emitter_set_emitter_error(emitter, 
    650             "expected DOCUMENT-START or STREAM-END"); 
     633    return EMITTER_ERROR_INIT(emitter, "expected DOCUMENT-START or STREAM-END"); 
    651634} 
    652635 
     
    677660        if (!yaml_emitter_write_indent(emitter)) 
    678661            return 0; 
    679         if (!event->data.document_end.implicit) { 
     662        if (!event->data.document_end.is_implicit) { 
    680663            if (!yaml_emitter_write_indicator(emitter, "...", 1, 0, 0)) 
    681664                return 0; 
     
    698681    } 
    699682 
    700     return yaml_emitter_set_emitter_error(emitter, 
    701             "expected DOCUMENT-END"); 
     683    return EMITTER_ERROR_INIT(emitter, "expected DOCUMENT-END"); 
    702684} 
    703685 
     
    724706        emitter->flow_level --; 
    725707        emitter->indent = POP(emitter, emitter->indents); 
    726         if (emitter->canonical && !first) { 
     708        if (emitter->is_canonical && !first) { 
    727709            if (!yaml_emitter_write_indicator(emitter, ",", 0, 0, 0)) 
    728710                return 0; 
     
    742724    } 
    743725 
    744     if (emitter->canonical || emitter->column > emitter->best_width) { 
     726    if (emitter->is_canonical || emitter->column > emitter->best_width) { 
    745727        if (!yaml_emitter_write_indent(emitter)) 
    746728            return 0; 
     
    773755        emitter->flow_level --; 
    774756        emitter->indent = POP(emitter, emitter->indents); 
    775         if (emitter->canonical && !first) { 
     757        if (emitter->is_canonical && !first) { 
    776758            if (!yaml_emitter_write_indicator(emitter, ",", 0, 0, 0)) 
    777759                return 0; 
     
    790772            return 0; 
    791773    } 
    792     if (emitter->canonical || emitter->column > emitter->best_width) { 
     774    if (emitter->is_canonical || emitter->column > emitter->best_width) { 
    793775        if (!yaml_emitter_write_indent(emitter)) 
    794776            return 0; 
    795777    } 
    796778 
    797     if (!emitter->canonical && yaml_emitter_check_simple_key(emitter)) 
     779    if (!emitter->is_canonical && yaml_emitter_check_simple_key(emitter)) 
    798780    { 
    799781        if (!PUSH(emitter, emitter->states, 
     
    828810    } 
    829811    else { 
    830         if (emitter->canonical || emitter->column > emitter->best_width) { 
     812        if (emitter->is_canonical || emitter->column > emitter->best_width) { 
    831813            if (!yaml_emitter_write_indent(emitter)) 
    832814                return 0; 
     
    851833    { 
    852834        if (!yaml_emitter_increase_indent(emitter, 0, 
    853                     (emitter->mapping_context && !emitter->indention))) 
     835                    (emitter->is_mapping_context && !emitter->is_indention))) 
    854836            return 0; 
    855837    } 
     
    950932static int 
    951933yaml_emitter_emit_node(yaml_emitter_t *emitter, yaml_event_t *event, 
    952         int root, int sequence, int mapping, int simple_key) 
    953 { 
    954     emitter->root_context = root; 
    955     emitter->sequence_context = sequence; 
    956     emitter->mapping_context = mapping; 
    957     emitter->simple_key_context = simple_key; 
     934        int is_root, int is_sequence, int is_mapping, int is_simple_key) 
     935{ 
     936    emitter->is_root_context = is_root; 
     937    emitter->is_sequence_context = is_sequence; 
     938    emitter->is_mapping_context = is_mapping; 
     939    emitter->is_simple_key_context = is_simple_key; 
    958940 
    959941    switch (event->type) 
     
    972954 
    973955        default: 
    974             return yaml_emitter_set_emitter_error(emitter, 
     956            return EMITTER_ERROR_INIT(emitter, 
    975957                    "expected SCALAR, SEQUENCE-START, MAPPING-START, or ALIAS"); 
    976958    } 
     
    10281010        return 0; 
    10291011 
    1030     if (emitter->flow_level || emitter->canonical 
     1012    if (emitter->flow_level || emitter->is_canonical 
    10311013            || event->data.sequence_start.style == YAML_FLOW_SEQUENCE_STYLE 
    10321014            || yaml_emitter_check_empty_sequence(emitter)) { 
     
    10521034        return 0; 
    10531035 
    1054     if (emitter->flow_level || emitter->canonical 
     1036    if (emitter->flow_level || emitter->is_canonical 
    10551037            || event->data.mapping_start.style == YAML_FLOW_MAPPING_STYLE 
    10561038            || yaml_emitter_check_empty_mapping(emitter)) { 
     
    10841066        return 0; 
    10851067 
    1086     return (emitter->events.head[0].type == YAML_SEQUENCE_START_EVENT 
    1087             && emitter->events.head[1].type == YAML_SEQUENCE_END_EVENT); 
     1068    return (emitter->events.list[emitter->events.head].type 
     1069                            == YAML_SEQUENCE_START_EVENT && 
     1070            emitter->events.list[emitter->events.head+1].type 
     1071                            == YAML_SEQUENCE_END_EVENT); 
    10881072} 
    10891073 
     
    10981082        return 0; 
    10991083 
    1100     return (emitter->events.head[0].type == YAML_MAPPING_START_EVENT 
    1101             && emitter->events.head[1].type == YAML_MAPPING_END_EVENT); 
     1084    return (emitter->events.list[emitter->events.head].type 
     1085                            == YAML_MAPPING_START_EVENT && 
     1086            emitter->events.list[emitter->events.head+1].type 
     1087                            == YAML_MAPPING_END_EVENT); 
    11021088} 
    11031089 
     
    11091095yaml_emitter_check_simple_key(yaml_emitter_t *emitter) 
    11101096{ 
    1111     yaml_event_t *event = emitter->events.head; 
     1097    yaml_event_t *event = emitter->events.list + emitter->events.head; 
    11121098    size_t length = 0; 
    11131099 
     
    11191105 
    11201106        case YAML_SCALAR_EVENT: 
    1121             if (emitter->scalar_data.multiline) 
     1107            if (emitter->scalar_data.is_multiline) 
    11221108                return 0; 
    11231109            length += emitter->anchor_data.anchor_length 
     
    11631149    int no_tag = (!emitter->tag_data.handle && !emitter->tag_data.suffix); 
    11641150 
    1165     if (no_tag && !event->data.scalar.plain_implicit 
    1166             && !event->data.scalar.quoted_implicit) { 
    1167         return yaml_emitter_set_emitter_error(emitter, 
     1151    if (no_tag && !event->data.scalar.is_plain_implicit 
     1152            && !event->data.scalar.is_quoted_implicit) { 
     1153        return EMITTER_ERROR_INIT(emitter, 
    11681154                "neither tag nor implicit flags are specified"); 
    11691155    } 
     
    11721158        style = YAML_PLAIN_SCALAR_STYLE; 
    11731159 
    1174     if (emitter->canonical) 
     1160    if (emitter->is_canonical) 
    11751161        style = YAML_DOUBLE_QUOTED_SCALAR_STYLE; 
    11761162 
    1177     if (emitter->simple_key_context && emitter->scalar_data.multiline) 
     1163    if (emitter->is_simple_key_context && emitter->scalar_data.is_multiline) 
    11781164        style = YAML_DOUBLE_QUOTED_SCALAR_STYLE; 
    11791165 
    11801166    if (style == YAML_PLAIN_SCALAR_STYLE) 
    11811167    { 
    1182         if ((emitter->flow_level && !emitter->scalar_data.flow_plain_allowed) 
    1183                 || (!emitter->flow_level && !emitter->scalar_data.block_plain_allowed)) 
     1168        if ((emitter->flow_level && !emitter->scalar_data.is_flow_plain_allowed) 
     1169                || (!emitter->flow_level && !emitter->scalar_data.is_block_plain_allowed)) 
    11841170            style = YAML_SINGLE_QUOTED_SCALAR_STYLE; 
    11851171        if (!emitter->scalar_data.length 
    1186                 && (emitter->flow_level || emitter->simple_key_context)) 
     1172                && (emitter->flow_level || emitter->is_simple_key_context)) 
    11871173            style = YAML_SINGLE_QUOTED_SCALAR_STYLE; 
    1188         if (no_tag && !event->data.scalar.plain_implicit) 
     1174        if (no_tag && !event->data.scalar.is_plain_implicit) 
    11891175            style = YAML_SINGLE_QUOTED_SCALAR_STYLE; 
    11901176    } 
     
    11921178    if (style == YAML_SINGLE_QUOTED_SCALAR_STYLE) 
    11931179    { 
    1194         if (!emitter->scalar_data.single_quoted_allowed) 
     1180        if (!emitter->scalar_data.is_single_quoted_allowed) 
    11951181            style = YAML_DOUBLE_QUOTED_SCALAR_STYLE; 
    11961182    } 
     
    11981184    if (style == YAML_LITERAL_SCALAR_STYLE || style == YAML_FOLDED_SCALAR_STYLE) 
    11991185    { 
    1200         if (!emitter->scalar_data.block_allowed 
    1201                 || emitter->flow_level || emitter->simple_key_context) 
     1186        if (!emitter->scalar_data.is_block_allowed 
     1187                || emitter->flow_level || emitter->is_simple_key_context) 
    12021188            style = YAML_DOUBLE_QUOTED_SCALAR_STYLE; 
    12031189    } 
    12041190 
    1205     if (no_tag && !event->data.scalar.quoted_implicit 
     1191    if (no_tag && !event->data.scalar.is_quoted_implicit 
    12061192            && style != YAML_PLAIN_SCALAR_STYLE) 
    12071193    { 
     
    12261212 
    12271213    if (!yaml_emitter_write_indicator(emitter, 
    1228                 (emitter->anchor_data.alias ? "*" : "&"), 1, 0, 0)) 
     1214                (emitter->anchor_data.is_alias ? "*" : "&"), 1, 0, 0)) 
    12291215        return 0; 
    12301216 
     
    12801266            return yaml_emitter_write_plain_scalar(emitter, 
    12811267                    emitter->scalar_data.value, emitter->scalar_data.length, 
    1282                     !emitter->simple_key_context); 
     1268                    !emitter->is_simple_key_context); 
    12831269 
    12841270        case YAML_SINGLE_QUOTED_SCALAR_STYLE: 
    12851271            return yaml_emitter_write_single_quoted_scalar(emitter, 
    12861272                    emitter->scalar_data.value, emitter->scalar_data.length, 
    1287                     !emitter->simple_key_context); 
     1273                    !emitter->is_simple_key_context); 
    12881274 
    12891275        case YAML_DOUBLE_QUOTED_SCALAR_STYLE: 
    12901276            return yaml_emitter_write_double_quoted_scalar(emitter, 
    12911277                    emitter->scalar_data.value, emitter->scalar_data.length, 
    1292                     !emitter->simple_key_context); 
     1278                    !emitter->is_simple_key_context); 
    12931279 
    12941280        case YAML_LITERAL_SCALAR_STYLE: 
     
    13161302{ 
    13171303    if (version_directive.major != 1 || version_directive.minor != 1) { 
    1318         return yaml_emitter_set_emitter_error(emitter, 
    1319                 "incompatible %YAML directive"); 
     1304        return EMITTER_ERROR_INIT(emitter, "incompatible %YAML directive"); 
    13201305    } 
    13211306 
     
    13361321            strlen((char *)tag_directive.prefix)); 
    13371322 
    1338     if (handle.start == handle.end) { 
    1339         return yaml_emitter_set_emitter_error(emitter, 
    1340                 "tag handle must not be empty"); 
    1341     } 
    1342  
    1343     if (handle.start[0] != '!') { 
    1344         return yaml_emitter_set_emitter_error(emitter, 
    1345                 "tag handle must start with '!'"); 
    1346     } 
    1347  
    1348     if (handle.end[-1] != '!') { 
    1349         return yaml_emitter_set_emitter_error(emitter, 
    1350                 "tag handle must end with '!'"); 
     1323    if (!handle.capacity) { 
     1324        return EMITTER_ERROR_INIT(emitter, "tag handle must not be empty"); 
     1325    } 
     1326 
     1327    if (handle.buffer[0] != '!') { 
     1328        return EMITTER_ERROR_INIT(emitter, "tag handle must start with '!'"); 
     1329    } 
     1330 
     1331    if (handle.buffer[handle.capacity-1] != '!') { 
     1332        return EMITTER_ERROR_INIT(emitter, "tag handle must end with '!'"); 
    13511333    } 
    13521334 
    13531335    handle.pointer ++; 
    13541336 
    1355     while (handle.pointer < handle.end-1) { 
     1337    while (handle.pointer < handle.capacity-1) { 
    13561338        if (!IS_ALPHA(handle)) { 
    1357             return yaml_emitter_set_emitter_error(emitter, 
     1339            return EMITTER_ERROR_INIT(emitter, 
    13581340                    "tag handle must contain alphanumerical characters only"); 
    13591341        } 
     
    13611343    } 
    13621344 
    1363     if (prefix.start == prefix.end) { 
    1364         return yaml_emitter_set_emitter_error(emitter, 
    1365                 "tag prefix must not be empty"); 
     1345    if (!prefix.capacity) { 
     1346        return EMITTER_ERROR_INIT(emitter, "tag prefix must not be empty"); 
    13661347    } 
    13671348 
     
    13751356static int 
    13761357yaml_emitter_analyze_anchor(yaml_emitter_t *emitter, 
    1377         yaml_char_t *anchor, int alias) 
     1358        yaml_char_t *anchor, int is_alias) 
    13781359{ 
    13791360    yaml_string_t string = STRING(anchor, strlen((char *)anchor)); 
    13801361 
    1381     if (string.start == string.end) { 
    1382         return yaml_emitter_set_emitter_error(emitter, alias ? 
     1362    if (!string.capacity) { 
     1363        return EMITTER_ERROR_INIT(emitter, is_alias ? 
    13831364                "alias value must not be empty" : 
    13841365                "anchor value must not be empty"); 
    13851366    } 
    13861367 
    1387     while (string.pointer != string.end) { 
     1368    while (string.pointer < string.capacity) { 
    13881369        if (!IS_ALPHA(string)) { 
    1389             return yaml_emitter_set_emitter_error(emitter, alias ? 
     1370            return EMITTER_ERROR_INIT(emitter, is_alias ? 
    13901371                    "alias value must contain alphanumerical characters only" : 
    13911372                    "anchor value must contain alphanumerical characters only"); 
     
    13941375    } 
    13951376 
    1396     emitter->anchor_data.anchor = string.start; 
    1397     emitter->anchor_data.anchor_length = string.end - string.start; 
    1398     emitter->anchor_data.alias = alias; 
     1377    emitter->anchor_data.anchor = string.buffer; 
     1378    emitter->anchor_data.anchor_length = string.capacity; 
     1379    emitter->anchor_data.is_alias = is_alias; 
    13991380 
    14001381    return 1; 
     
    14101391{ 
    14111392    yaml_string_t string = STRING(tag, strlen((char *)tag)); 
    1412     yaml_tag_directive_t *tag_directive; 
    1413  
    1414     if (string.start == string.end) { 
    1415         return yaml_emitter_set_emitter_error(emitter, 
    1416                 "tag value must not be empty"); 
    1417     } 
    1418  
    1419     for (tag_directive = emitter->tag_directives.start; 
    1420             tag_directive != emitter->tag_directives.top; tag_directive ++) { 
     1393    size_t idx; 
     1394 
     1395    if (!string.capacity) { 
     1396        return EMITTER_ERROR_INIT(emitter, "tag value must not be empty"); 
     1397    } 
     1398 
     1399    for (idx = 0; idx < emitter->tag_directives.length; idx ++) { 
     1400        yaml_tag_directive_t *tag_directive = emitter->tag_directives.list+idx; 
    14211401        size_t prefix_length = strlen((char *)tag_directive->prefix); 
    1422         if (prefix_length < (size_t)(string.end - string.start) 
    1423                 && strncmp((char *)tag_directive->prefix, (char *)string.start, 
     1402        if (prefix_length < string.capacity 
     1403                && strncmp((char *)tag_directive->prefix, (char *)string.buffer, 
    14241404                    prefix_length) == 0) 
    14251405        { 
     
    14271407            emitter->tag_data.handle_length = 
    14281408                strlen((char *)tag_directive->handle); 
    1429             emitter->tag_data.suffix = string.start + prefix_length; 
    1430             emitter->tag_data.suffix_length = 
    1431                 (string.end - string.start) - prefix_length; 
     1409            emitter->tag_data.suffix = string.buffer + prefix_length; 
     1410            emitter->tag_data.suffix_length = string.capacity - prefix_length; 
    14321411            return 1; 
    14331412        } 
    14341413    } 
    14351414 
    1436     emitter->tag_data.suffix = string.start; 
    1437     emitter->tag_data.suffix_length = string.end - string.start; 
     1415    emitter->tag_data.suffix = string.buffer; 
     1416    emitter->tag_data.suffix_length = string.capacity; 
    14381417 
    14391418    return 1; 
     
    14741453    emitter->scalar_data.length = length; 
    14751454 
    1476     if (string.start == string.end) 
    1477     { 
    1478         emitter->scalar_data.multiline = 0; 
    1479         emitter->scalar_data.flow_plain_allowed = 0; 
    1480         emitter->scalar_data.block_plain_allowed = 1; 
    1481         emitter->scalar_data.single_quoted_allowed = 1; 
    1482         emitter->scalar_data.block_allowed = 0; 
     1455    if (!string.capacity) 
     1456    { 
     1457        emitter->scalar_data.is_multiline = 0; 
     1458        emitter->scalar_data.is_flow_plain_allowed = 0; 
     1459        emitter->scalar_data.is_block_plain_allowed = 1; 
     1460        emitter->scalar_data.is_single_quoted_allowed = 1; 
     1461        emitter->scalar_data.is_block_allowed = 0; 
    14831462 
    14841463        return 1; 
     
    14981477    followed_by_space = IS_BLANKZ_AT(string, WIDTH(string)); 
    14991478 
    1500     while (string.pointer != string.end) 
    1501     { 
    1502         if (string.start == string.pointer) 
     1479    while (string.pointer < string.capacity) 
     1480    { 
     1481        if (!string.pointer) 
    15031482        { 
    15041483            if (CHECK(string, '#') || CHECK(string, ',') 
     
    15481527 
    15491528        if (!IS_PRINTABLE(string) 
    1550                 || (!IS_ASCII(string) && !emitter->unicode)) { 
     1529                || (!IS_ASCII(string) && !emitter->is_unicode)) { 
    15511530            special_characters = 1; 
    15521531        } 
     
    15591538        { 
    15601539            spaces = 1; 
    1561             if (string.start == string.pointer) { 
     1540            if (!string.pointer) { 
    15621541                leading = 1; 
    15631542            } 
     
    15701549            } 
    15711550            breaks = 1; 
    1572             if (string.start == string.pointer) { 
     1551            if (!string.pointer) { 
    15731552                leading = 1; 
    15741553            } 
     
    16051584        } 
    16061585 
    1607         if ((spaces || breaks) && string.pointer == string.end-1) 
     1586        if ((spaces || breaks) && string.pointer == string.capacity-1) 
    16081587        { 
    16091588            if (spaces && breaks) { 
     
    16261605        preceeded_by_space = IS_BLANKZ(string); 
    16271606        MOVE(string); 
    1628         if (string.pointer != string.end) { 
     1607        if (string.pointer < string.capacity) { 
    16291608            followed_by_space = IS_BLANKZ_AT(string, WIDTH(string)); 
    16301609        } 
    16311610    } 
    16321611 
    1633     emitter->scalar_data.multiline = line_breaks; 
    1634  
    1635     emitter->scalar_data.flow_plain_allowed = 1; 
    1636     emitter->scalar_data.block_plain_allowed = 1; 
    1637     emitter->scalar_data.single_quoted_allowed = 1; 
    1638     emitter->scalar_data.block_allowed = 1; 
     1612    emitter->scalar_data.is_multiline = line_breaks; 
     1613 
     1614    emitter->scalar_data.is_flow_plain_allowed = 1; 
     1615    emitter->scalar_data.is_block_plain_allowed = 1; 
     1616    emitter->scalar_data.is_single_quoted_allowed = 1; 
     1617    emitter->scalar_data.is_block_allowed = 1; 
    16391618 
    16401619    if (leading_spaces || leading_breaks || trailing_spaces) { 
    1641         emitter->scalar_data.flow_plain_allowed = 0; 
    1642         emitter->scalar_data.block_plain_allowed = 0; 
    1643         emitter->scalar_data.block_allowed = 0; 
     1620        emitter->scalar_data.is_flow_plain_allowed = 0; 
     1621        emitter->scalar_data.is_block_plain_allowed = 0; 
     1622        emitter->scalar_data.is_block_allowed = 0; 
    16441623    } 
    16451624 
    16461625    if (trailing_breaks) { 
    1647         emitter->scalar_data.flow_plain_allowed = 0; 
    1648         emitter->scalar_data.block_plain_allowed = 0; 
     1626        emitter->scalar_data.is_flow_plain_allowed = 0; 
     1627        emitter->scalar_data.is_block_plain_allowed = 0; 
    16491628    } 
    16501629 
    16511630    if (inline_breaks_spaces) { 
    1652         emitter->scalar_data.flow_plain_allowed = 0; 
    1653         emitter->scalar_data.block_plain_allowed = 0; 
    1654         emitter->scalar_data.single_quoted_allowed = 0; 
     1631        emitter->scalar_data.is_flow_plain_allowed = 0; 
     1632        emitter->scalar_data.is_block_plain_allowed = 0; 
     1633        emitter->scalar_data.is_single_quoted_allowed = 0; 
    16551634    } 
    16561635 
    16571636    if (mixed_breaks_spaces || special_characters) { 
    1658         emitter->scalar_data.flow_plain_allowed = 0; 
    1659         emitter->scalar_data.block_plain_allowed = 0; 
    1660         emitter->scalar_data.single_quoted_allowed = 0; 
    1661         emitter->scalar_data.block_allowed = 0; 
     1637        emitter->scalar_data.is_flow_plain_allowed = 0; 
     1638        emitter->scalar_data.is_block_plain_allowed = 0; 
     1639        emitter->scalar_data.is_single_quoted_allowed = 0; 
     1640        emitter->scalar_data.is_block_allowed = 0; 
    16621641    } 
    16631642 
    16641643    if (line_breaks) { 
    1665         emitter->scalar_data.flow_plain_allowed = 0; 
    1666         emitter->scalar_data.block_plain_allowed = 0; 
     1644        emitter->scalar_data.is_flow_plain_allowed = 0; 
     1645        emitter->scalar_data.is_block_plain_allowed = 0; 
    16671646    } 
    16681647 
    16691648    if (flow_indicators) { 
    1670         emitter->scalar_data.flow_plain_allowed = 0; 
     1649        emitter->scalar_data.is_flow_plain_allowed = 0; 
    16711650    } 
    16721651 
    16731652    if (block_indicators) { 
    1674         emitter->scalar_data.block_plain_allowed = 0; 
     1653        emitter->scalar_data.is_block_plain_allowed = 0; 
    16751654    } 
    16761655 
     
    17091688                    return 0; 
    17101689            } 
    1711             if (event->data.scalar.tag && (emitter->canonical || 
    1712                         (!event->data.scalar.plain_implicit 
    1713                          && !event->data.scalar.quoted_implicit))) { 
     1690            if (event->data.scalar.tag && (emitter->is_canonical || 
     1691                        (!event->data.scalar.is_plain_implicit 
     1692                         && !event->data.scalar.is_quoted_implicit))) { 
    17141693                if (!yaml_emitter_analyze_tag(emitter, event->data.scalar.tag)) 
    17151694                    return 0; 
     
    17261705                    return 0; 
    17271706            } 
    1728             if (event->data.sequence_start.tag && (emitter->canonical || 
    1729                         !event->data.sequence_start.implicit)) { 
     1707            if (event->data.sequence_start.tag && (emitter->is_canonical || 
     1708                        !event->data.sequence_start.is_implicit)) { 
    17301709                if (!yaml_emitter_analyze_tag(emitter, 
    17311710                            event->data.sequence_start.tag)) 
     
    17401719                    return 0; 
    17411720            } 
    1742             if (event->data.mapping_start.tag && (emitter->canonical || 
    1743                         !event->data.mapping_start.implicit)) { 
     1721            if (event->data.mapping_start.tag && (emitter->is_canonical || 
     1722                        !event->data.mapping_start.is_implicit)) { 
    17441723                if (!yaml_emitter_analyze_tag(emitter, 
    17451724                            event->data.mapping_start.tag)) 
     
    17621741    if (!FLUSH(emitter)) return 0; 
    17631742 
    1764     *(emitter->buffer.pointer++) = (yaml_char_t) '\xEF'; 
    1765     *(emitter->buffer.pointer++) = (yaml_char_t) '\xBB'; 
    1766     *(emitter->buffer.pointer++) = (yaml_char_t) '\xBF'; 
     1743    JOIN_OCTET(emitter->output, (yaml_char_t) '\xEF'); 
     1744    JOIN_OCTET(emitter->output, (yaml_char_t) '\xBB'); 
     1745    JOIN_OCTET(emitter->output, (yaml_char_t) '\xBF'); 
    17671746 
    17681747    return 1; 
     
    17741753    int indent = (emitter->indent >= 0) ? emitter->indent : 0; 
    17751754 
    1776     if (!emitter->indention || emitter->column > indent 
    1777             || (emitter->column == indent && !emitter->whitespace)) { 
     1755    if (!emitter->is_indention || emitter->column > indent 
     1756            || (emitter->column == indent && !emitter->is_whitespace)) { 
    17781757        if (!PUT_BREAK(emitter)) return 0; 
    17791758    } 
     
    17831762    } 
    17841763 
    1785     emitter->whitespace = 1; 
    1786     emitter->indention = 1; 
     1764    emitter->is_whitespace = 1; 
     1765    emitter->is_indention = 1; 
    17871766 
    17881767    return 1; 
     
    17961775    yaml_string_t string = STRING((yaml_char_t *)indicator, strlen(indicator)); 
    17971776 
    1798     if (need_whitespace && !emitter->whitespace) { 
     1777    if (need_whitespace && !emitter->is_whitespace) { 
    17991778        if (!PUT(emitter, ' ')) return 0; 
    18001779    } 
    18011780 
    1802     while (string.pointer != string.end) { 
     1781    while (string.pointer < string.capacity) { 
    18031782        if (!WRITE(emitter, string)) return 0; 
    18041783    } 
    18051784 
    1806     emitter->whitespace = is_whitespace; 
    1807     emitter->indention = (emitter->indention && is_indention); 
     1785    emitter->is_whitespace = is_whitespace; 
     1786    emitter->is_indention = (emitter->is_indention && is_indention); 
    18081787 
    18091788    return 1; 
     
    18161795    yaml_string_t string = STRING(value, length); 
    18171796 
    1818     while (string.pointer != string.end) { 
     1797    while (string.pointer < string.capacity) { 
    18191798        if (!WRITE(emitter, string)) return 0; 
    18201799    } 
    18211800 
    1822     emitter->whitespace = 0; 
    1823     emitter->indention = 0; 
     1801    emitter->is_whitespace = 0; 
     1802    emitter->is_indention = 0; 
    18241803 
    18251804    return 1; 
     
    18321811    yaml_string_t string = STRING(value, length); 
    18331812 
    1834     if (!emitter->whitespace) { 
     1813    if (!emitter->is_whitespace) { 
    18351814        if (!PUT(emitter, ' ')) return 0; 
    18361815    } 
    18371816 
    1838     while (string.pointer != string.end) { 
     1817    while (string.pointer < string.capacity) { 
    18391818        if (!WRITE(emitter, string)) return 0; 
    18401819    } 
    18411820 
    1842     emitter->whitespace = 0; 
    1843     emitter->indention = 0; 
     1821    emitter->is_whitespace = 0; 
     1822    emitter->is_indention = 0; 
    18441823 
    18451824    return 1; 
     
    18531832    yaml_string_t string = STRING(value, length); 
    18541833 
    1855     if (need_whitespace && !emitter->whitespace) { 
     1834    if (need_whitespace && !emitter->is_whitespace) { 
    18561835        if (!PUT(emitter, ' ')) return 0; 
    18571836    } 
    18581837 
    1859     while (string.pointer != string.end) { 
     1838    while (string.pointer < string.capacity) { 
    18601839        if (IS_ALPHA(string) 
    18611840                || CHECK(string, ';') || CHECK(string, '/') 
     
    18751854            unsigned int value; 
    18761855            while (width --) { 
    1877                 value = *(string.pointer++); 
     1856                value = OCTET(string); 
     1857                string.pointer ++; 
    18781858                if (!PUT(emitter, '%')) return 0; 
    18791859                if (!PUT(emitter, (value >> 4) 
     
    18871867    } 
    18881868 
    1889     emitter->whitespace = 0; 
    1890     emitter->indention = 0; 
     1869    emitter->is_whitespace = 0; 
     1870    emitter->is_indention = 0; 
    18911871 
    18921872    return 1; 
     
    19011881    int breaks = 0; 
    19021882 
    1903     if (!emitter->whitespace) { 
     1883    if (!emitter->is_whitespace) { 
    19041884        if (!PUT(emitter, ' ')) return 0; 
    19051885    } 
    19061886 
    1907     while (string.pointer != string.end) 
     1887    while (string.pointer < string.capacity) 
    19081888    { 
    19091889        if (IS_SPACE(string)) 
     
    19261906            } 
    19271907            if (!WRITE_BREAK(emitter, string)) return 0; 
    1928             emitter->indention = 1; 
     1908            emitter->is_indention = 1; 
    19291909            breaks = 1; 
    19301910        } 
     
    19351915            } 
    19361916            if (!WRITE(emitter, string)) return 0; 
    1937             emitter->indention = 0; 
     1917            emitter->is_indention = 0; 
    19381918            spaces = 0; 
    19391919            breaks = 0; 
     
    19411921    } 
    19421922 
    1943     emitter->whitespace = 0; 
    1944     emitter->indention = 0; 
     1923    emitter->is_whitespace = 0; 
     1924    emitter->is_indention = 0; 
    19451925 
    19461926    return 1; 
     
    19581938        return 0; 
    19591939 
    1960     while (string.pointer != string.end) 
     1940    while (string.pointer < string.capacity) 
    19611941    { 
    19621942        if (IS_SPACE(string)) 
     
    19641944            if (allow_breaks && !spaces 
    19651945                    && emitter->column > emitter->best_width 
    1966                     && string.pointer != string.start 
    1967                     && string.pointer != string.end - 1 
     1946                    && string.pointer != 0 
     1947                    && string.pointer != string.capacity - 1 
    19681948                    && !IS_SPACE_AT(string, 1)) { 
    19691949                if (!yaml_emitter_write_indent(emitter)) return 0; 
     
    19811961            } 
    19821962            if (!WRITE_BREAK(emitter, string)) return 0; 
    1983             emitter->indention = 1; 
     1963            emitter->is_indention = 1; 
    19841964            breaks = 1; 
    19851965        } 
     
    19931973            } 
    19941974            if (!WRITE(emitter, string)) return 0; 
    1995             emitter->indention = 0; 
     1975            emitter->is_indention = 0; 
    19961976            spaces = 0; 
    19971977            breaks = 0; 
     
    20021982        return 0; 
    20031983 
    2004     emitter->whitespace = 0; 
    2005     emitter->indention = 0; 
     1984    emitter->is_whitespace = 0; 
     1985    emitter->is_indention = 0; 
    20061986 
    20071987    return 1; 
     
    20181998        return 0; 
    20191999 
    2020     while (string.pointer != string.end) 
    2021     { 
    2022         if (!IS_PRINTABLE(string) || (!emitter->unicode && !IS_ASCII(string)) 
     2000    while (string.pointer < string.capacity) 
     2001    { 
     2002        if (!IS_PRINTABLE(string) || (!emitter->is_unicode && !IS_ASCII(string)) 
    20232003                || IS_BOM(string) || IS_BREAK(string) 
    20242004                || CHECK(string, '"') || CHECK(string, '\\')) 
     
    20272007            unsigned int width; 
    20282008            unsigned int value; 
    2029             int k; 
    2030  
    2031             octet = string.pointer[0]; 
     2009            int idx; 
     2010 
     2011            octet = OCTET(string); 
    20322012            width = (octet & 0x80) == 0x00 ? 1 : 
    20332013                    (octet & 0xE0) == 0xC0 ? 2 : 
     
    20382018                    (octet & 0xF0) == 0xE0 ? octet & 0x0F : 
    20392019                    (octet & 0xF8) == 0xF0 ? octet & 0x07 : 0; 
    2040             for (k = 1; k < (int)width; k ++) { 
    2041                 octet = string.pointer[k]; 
     2020            for (idx = 1; idx < width; idx ++) { 
     2021                octet = OCTET_AT(string, idx); 
    20422022                value = (value << 6) + (octet & 0x3F); 
    20432023            } 
     
    21212101                        width = 8; 
    21222102                    } 
    2123                     for (k = (width-1)*4; k >= 0; k -= 4) { 
    2124                         int digit = (value >> k) & 0x0F; 
     2103                    for (idx = (width-1)*4; idx >= 0; idx -= 4) { 
     2104                        int digit = (value >> idx) & 0x0F; 
    21252105                        if (!PUT(emitter, digit + (digit < 10 ? '0' : 'A'-10))) 
    21262106                            return 0; 
     
    21332113            if (allow_breaks && !spaces 
    21342114                    && emitter->column > emitter->best_width 
    2135                     && string.pointer != string.start 
    2136                     && string.pointer != string.end - 1) { 
     2115                    && string.pointer != 0 
     2116                    && string.pointer != string.capacity - 1) { 
    21372117                if (!yaml_emitter_write_indent(emitter)) return 0; 
    21382118                if (IS_SPACE_AT(string, 1)) { 
     
    21562136        return 0; 
    21572137 
    2158     emitter->whitespace = 0; 
    2159     emitter->indention = 0; 
     2138    emitter->is_whitespace = 0; 
     2139    emitter->is_indention = 0; 
    21602140 
    21612141    return 1; 
     
    21662146        yaml_string_t string) 
    21672147{ 
    2168     string.pointer = string.end; 
    2169     if (string.start == string.pointer) 
     2148    string.pointer = string.capacity; 
     2149    if (!string.pointer) 
    21702150        return -1; 
    21712151    do { 
    21722152        string.pointer --; 
    2173     } while ((*string.pointer & 0xC0) == 0x80); 
     2153    } while ((OCTET(string) & 0xC0) == 0x80); 
    21742154    if (!IS_BREAK(string)) 
    21752155        return -1; 
    2176     if (string.start == string.pointer) 
     2156    if (!string.pointer) 
    21772157        return 0; 
    21782158    do { 
    21792159        string.pointer --; 
    2180     } while ((*string.pointer & 0xC0) == 0x80); 
     2160    } while ((OCTET(string) & 0xC0) == 0x80); 
    21812161    if (!IS_BREAK(string)) 
    21822162        return 0; 
     
    21992179        return 0; 
    22002180 
    2201     while (string.pointer != string.end) 
     2181    while (string.pointer < string.capacity) 
    22022182    { 
    22032183        if (IS_BREAK(string)) 
    22042184        { 
    22052185            if (!WRITE_BREAK(emitter, string)) return 0; 
    2206             emitter->indention = 1; 
     2186            emitter->is_indention = 1; 
    22072187            breaks = 1; 
    22082188        } 
     
    22132193            } 
    22142194            if (!WRITE(emitter, string)) return 0; 
    2215             emitter->indention = 0; 
     2195            emitter->is_indention = 0; 
    22162196            breaks = 0; 
    22172197        } 
     
    22362216        return 0; 
    22372217 
    2238     while (string.pointer != string.end) 
     2218    while (string.pointer < string.capacity) 
    22392219    { 
    22402220        if (IS_BREAK(string)) 
     
    22502230            } 
    22512231            if (!WRITE_BREAK(emitter, string)) return 0; 
    2252             emitter->indention = 1; 
     2232            emitter->is_indention = 1; 
    22532233            breaks = 1; 
    22542234        } 
     
    22672247                if (!WRITE(emitter, string)) return 0; 
    22682248            } 
    2269             emitter->indention = 0; 
     2249            emitter->is_indention = 0; 
    22702250            breaks = 0; 
    22712251        } 
  • libyaml/trunk/src/loader.c

    r243 r263  
    11 
    22#include "yaml_private.h" 
     3 
     4#if 0 
    35 
    46/* 
     
    429431} 
    430432 
     433#endif 
     434 
  • libyaml/trunk/src/parser.c

    r250 r263  
    4747 
    4848#define PEEK_TOKEN(parser)                                                      \ 
    49     ((parser->token_available || yaml_parser_fetch_more_tokens(parser)) ?       \ 
    50         parser->tokens.head : NULL) 
     49    ((parser->is_token_available || yaml_parser_fetch_more_tokens(parser)) ?    \ 
     50        parser->tokens.list + parser->tokens.head : NULL) 
    5151 
    5252/* 
     
    5555 
    5656#define SKIP_TOKEN(parser)                                                      \ 
    57     (parser->token_available = 0,                                               \ 
     57    (parser->is_token_available = 0,                                            \ 
    5858     parser->tokens_parsed ++,                                                  \ 
    59      parser->stream_end_produced =                                              \ 
    60         (parser->tokens.head->type == YAML_STREAM_END_TOKEN),                   \ 
     59     parser->is_stream_end_produced =                                           \ 
     60        (parser->tokens.list[parser->tokens.head].type == YAML_STREAM_END_TOKEN),   \ 
    6161     parser->tokens.head ++) 
    6262 
     
    6969 
    7070/* 
    71  * Error handling. 
    72  */ 
    73  
    74 static int 
    75 yaml_parser_set_parser_error(yaml_parser_t *parser, 
    76         const char *problem, yaml_mark_t problem_mark); 
    77  
    78 static int 
    79 yaml_parser_set_parser_error_context(yaml_parser_t *parser, 
    80         const char *context, yaml_mark_t context_mark, 
    81         const char *problem, yaml_mark_t problem_mark); 
    82  
    83 /* 
    8471 * State functions. 
    8572 */ 
     
    156143yaml_parser_process_directives(yaml_parser_t *parser, 
    157144        yaml_version_directive_t **version_directive_ref, 
    158         yaml_tag_directive_t **tag_directives_start_ref, 
    159         yaml_tag_directive_t **tag_directives_end_ref); 
     145        yaml_tag_directive_t **tag_directives_list_ref, 
     146        size_t *tag_directives_length_ref, 
     147        size_t *tag_directives_capacity_ref); 
    160148 
    161149static int 
     
    179167    /* No events after the end of the stream or error. */ 
    180168 
    181     if (parser->stream_end_produced || parser->error || 
    182             parser->state == YAML_PARSE_END_STATE) { 
     169    if (parser->is_stream_end_produced || parser->error.type 
     170            || parser->state == YAML_PARSE_END_STATE) { 
    183171        return 1; 
    184172    } 
     
    188176    return yaml_parser_state_machine(parser, event); 
    189177} 
    190  
    191 /* 
    192  * Set parser error. 
    193  */ 
    194  
    195 static int 
    196 yaml_parser_set_parser_error(yaml_parser_t *parser, 
    197         const char *problem, yaml_mark_t problem_mark) 
    198 { 
    199     parser->error = YAML_PARSER_ERROR; 
    200     parser->problem = problem; 
    201     parser->problem_mark = problem_mark; 
    202  
    203     return 0; 
    204 } 
    205  
    206 static int 
    207 yaml_parser_set_parser_error_context(yaml_parser_t *parser, 
    208         const char *context, yaml_mark_t context_mark, 
    209         const char *problem, yaml_mark_t problem_mark) 
    210 { 
    211     parser->error = YAML_PARSER_ERROR; 
    212     parser->context = context; 
    213     parser->context_mark = context_mark; 
    214     parser->problem = problem; 
    215     parser->problem_mark = problem_mark; 
    216  
    217     return 0; 
    218 } 
    219  
    220178 
    221179/* 
     
    319277 
    320278    if (token->type != YAML_STREAM_START_TOKEN) { 
    321         return yaml_parser_set_parser_error(parser, 
     279        return PARSER_ERROR_INIT(parser, 
    322280                "did not found expected <stream-start>", token->start_mark); 
    323281    } 
     
    346304    yaml_version_directive_t *version_directive = NULL; 
    347305    struct { 
    348         yaml_tag_directive_t *start; 
    349         yaml_tag_directive_t *end; 
    350     } tag_directives = { NULL, NULL }; 
     306        yaml_tag_directive_t *list; 
     307        size_t length; 
     308        size_t capacity; 
     309    } tag_directives = { NULL, 0, 0 }; 
    351310 
    352311    token = PEEK_TOKEN(parser); 
     
    371330            token->type != YAML_STREAM_END_TOKEN) 
    372331    { 
    373         if (!yaml_parser_process_directives(parser, NULL, NULL, NULL)) 
     332        if (!yaml_parser_process_directives(parser, NULL, NULL, NULL, NULL)) 
    374333            return 0; 
    375334        if (!PUSH(parser, parser->states, YAML_PARSE_DOCUMENT_END_STATE)) 
    376335            return 0; 
    377336        parser->state = YAML_PARSE_BLOCK_NODE_STATE; 
    378         DOCUMENT_START_EVENT_INIT(*event, NULL, NULL, NULL, 1, 
     337        DOCUMENT_START_EVENT_INIT(*event, NULL, NULL, 0, 0, 1, 
    379338                token->start_mark, token->start_mark); 
    380339        return 1; 
     
    388347        start_mark = token->start_mark; 
    389348        if (!yaml_parser_process_directives(parser, &version_directive, 
    390                     &tag_directives.start, &tag_directives.end)) 
     349                    &tag_directives.list, &tag_directives.length, 
     350                    &tag_directives.capacity)) 
    391351            return 0; 
    392352        token = PEEK_TOKEN(parser); 
    393353        if (!token) goto error; 
    394354        if (token->type != YAML_DOCUMENT_START_TOKEN) { 
    395             yaml_parser_set_parser_error(parser, 
     355            PARSER_ERROR_INIT(parser, 
    396356                    "did not found expected <document start>", token->start_mark); 
    397357            goto error; 
     
    402362        end_mark = token->end_mark; 
    403363        DOCUMENT_START_EVENT_INIT(*event, version_directive, 
    404                 tag_directives.start, tag_directives.end, 0, 
     364                tag_directives.list, tag_directives.length, 
     365                tag_directives.capacity, 0, 
    405366                start_mark, end_mark); 
    406367        SKIP_TOKEN(parser); 
    407368        version_directive = NULL; 
    408         tag_directives.start = tag_directives.end = NULL; 
     369        tag_directives.list = NULL; 
     370        tag_directives.length = tag_directives.capacity = 0; 
    409371        return 1; 
    410372    } 
     
    422384error: 
    423385    yaml_free(version_directive); 
    424     while (tag_directives.start != tag_directives.end) { 
    425         yaml_free(tag_directives.end[-1].handle); 
    426         yaml_free(tag_directives.end[-1].prefix); 
    427         tag_directives.end --; 
    428     } 
    429     yaml_free(tag_directives.start); 
     386    while (!STACK_EMPTY(parser, tag_directives)) { 
     387        yaml_tag_directive_t tag_directive = POP(parser, tag_directives); 
     388        yaml_free(tag_directive.handle); 
     389        yaml_free(tag_directive.prefix); 
     390    } 
     391    STACK_DEL(parser, tag_directives); 
    430392    return 0; 
    431393} 
     
    599561            } 
    600562            else { 
    601                 yaml_tag_directive_t *tag_directive; 
    602                 for (tag_directive = parser->tag_directives.start; 
    603                         tag_directive != parser->tag_directives.top; 
    604                         tag_directive ++) { 
     563                int idx; 
     564                for (idx = 0; idx < parser->tag_directives.length; idx++) { 
     565                    yaml_tag_directive_t *tag_directive = parser->tag_directives.list + idx; 
    605566                    if (strcmp((char *)tag_directive->handle, (char *)tag_handle) == 0) { 
    606567                        size_t prefix_len = strlen((char *)tag_directive->prefix); 
     
    608569                        tag = yaml_malloc(prefix_len+suffix_len+1); 
    609570                        if (!tag) { 
    610                             parser->error = YAML_MEMORY_ERROR; 
     571                            MEMORY_ERROR_INIT(parser); 
    611572                            goto error; 
    612573                        } 
     
    621582                } 
    622583                if (!tag) { 
    623                     yaml_parser_set_parser_error_context(parser, 
     584                    PARSER_ERROR_WITH_CONTEXT_INIT(parser, 
    624585                            "while parsing a node", start_mark, 
    625586                            "found undefined tag handle", tag_mark); 
     
    688649                yaml_char_t *value = yaml_malloc(1); 
    689650                if (!value) { 
    690                     parser->error = YAML_MEMORY_ERROR; 
     651                    MEMORY_ERROR_INIT(parser); 
    691652                    goto error; 
    692653                } 
     
    699660            } 
    700661            else { 
    701                 yaml_parser_set_parser_error_context(parser, 
     662                PARSER_ERROR_WITH_CONTEXT_INIT(parser, 
    702663                        (block ? "while parsing a block node" 
    703664                         : "while parsing a flow node"), start_mark, 
     
    770731    else 
    771732    { 
    772         return yaml_parser_set_parser_error_context(parser, 
     733        return PARSER_ERROR_WITH_CONTEXT_INIT(parser, 
    773734                "while parsing a block collection", POP(parser, parser->marks), 
    774735                "did not found expected '-' indicator", token->start_mark); 
     
    880841    else 
    881842    { 
    882         return yaml_parser_set_parser_error_context(parser, 
     843        return PARSER_ERROR_WITH_CONTEXT_INIT(parser, 
    883844                "while parsing a block mapping", POP(parser, parser->marks), 
    884845                "did not found expected key", token->start_mark); 
     
    974935            } 
    975936            else { 
    976                 return yaml_parser_set_parser_error_context(parser, 
     937                return PARSER_ERROR_WITH_CONTEXT_INIT(parser, 
    977938                        "while parsing a flow sequence", POP(parser, parser->marks), 
    978939                        "did not found expected ',' or ']'", token->start_mark); 
     
    11261087            } 
    11271088            else { 
    1128                 return yaml_parser_set_parser_error_context(parser, 
     1089                return PARSER_ERROR_WITH_CONTEXT_INIT(parser, 
    11291090                        "while parsing a flow mapping", POP(parser, parser->marks), 
    11301091                        "did not found expected ',' or '}'", token->start_mark); 
     
    12151176    value = yaml_malloc(1); 
    12161177    if (!value) { 
    1217         parser->error = YAML_MEMORY_ERROR; 
    1218         return 0; 
     1178        return MEMORY_ERROR_INIT(parser); 
    12191179    } 
    12201180    value[0] = '\0'; 
     
    12331193yaml_parser_process_directives(yaml_parser_t *parser, 
    12341194        yaml_version_directive_t **version_directive_ref, 
    1235         yaml_tag_directive_t **tag_directives_start_ref, 
    1236         yaml_tag_directive_t **tag_directives_end_ref) 
     1195        yaml_tag_directive_t **tag_directives_list_ref, 
     1196        size_t *tag_directives_length_ref, 
     1197        size_t *tag_directives_capacity_ref) 
    12371198{ 
    12381199    yaml_tag_directive_t default_tag_directives[] = { 
     
    12441205    yaml_version_directive_t *version_directive = NULL; 
    12451206    struct { 
    1246         yaml_tag_directive_t *start; 
    1247         yaml_tag_directive_t *end; 
    1248         yaml_tag_directive_t *top; 
    1249     } tag_directives = { NULL, NULL, NULL }; 
    1250     yaml_token_t *token; 
    1251  
    1252     if (!STACK_INIT(parser, tag_directives, INITIAL_STACK_SIZE)) 
     1207        yaml_tag_directive_t *list; 
     1208        size_t length; 
     1209        size_t capacity; 
     1210    } tag_directives = { NULL, 0, 0 }; 
     1211    yaml_token_t *token; 
     1212 
     1213    if (!STACK_INIT(parser, tag_directives, INITIAL_STACK_CAPACITY)) 
    12531214        goto error; 
    12541215 
     
    12611222        if (token->type == YAML_VERSION_DIRECTIVE_TOKEN) { 
    12621223            if (version_directive) { 
    1263                 yaml_parser_set_parser_error(parser, 
     1224                PARSER_ERROR_INIT(parser, 
    12641225                        "found duplicate %YAML directive", token->start_mark); 
    12651226                goto error; 
     
    12671228            if (token->data.version_directive.major != 1 
    12681229                    || token->data.version_directive.minor != 1) { 
    1269                 yaml_parser_set_parser_error(parser, 
     1230                PARSER_ERROR_INIT(parser, 
    12701231                        "found incompatible YAML document", token->start_mark); 
    12711232                goto error; 
     
    12731234            version_directive = yaml_malloc(sizeof(yaml_version_directive_t)); 
    12741235            if (!version_directive) { 
    1275                 parser->error = YAML_MEMORY_ERROR; 
     1236                MEMORY_ERROR_INIT(parser); 
    12761237                goto error; 
    12771238            } 
     
    13071268        *version_directive_ref = version_directive; 
    13081269    } 
    1309     if (tag_directives_start_ref) { 
     1270    if (tag_directives_list_ref) { 
    13101271        if (STACK_EMPTY(parser, tag_directives)) { 
    1311             *tag_directives_start_ref = *tag_directives_end_ref = NULL; 
     1272            *tag_directives_list_ref = NULL; 
     1273            *tag_directives_length_ref = 0; 
     1274            *tag_directives_capacity_ref = 0; 
    13121275            STACK_DEL(parser, tag_directives); 
    13131276        } 
    13141277        else { 
    1315             *tag_directives_start_ref = tag_directives.start; 
    1316             *tag_directives_end_ref = tag_directives.top; 
     1278            *tag_directives_list_ref = tag_directives.list; 
     1279            *tag_directives_length_ref = tag_directives.length; 
     1280            *tag_directives_capacity_ref = tag_directives.capacity; 
    13171281        } 
    13181282    } 
     
    13441308    yaml_tag_directive_t *tag_directive; 
    13451309    yaml_tag_directive_t copy = { NULL, NULL }; 
    1346  
    1347     for (tag_directive = parser->tag_directives.start; 
    1348             tag_directive != parser->tag_directives.top; tag_directive ++) { 
     1310    int idx; 
     1311 
     1312    for (idx = 0; idx < parser->tag_directives.length; idx++) { 
     1313        yaml_tag_directive_t *tag_directive = parser->tag_directives.list + idx; 
    13491314        if (strcmp((char *)value.handle, (char *)tag_directive->handle) == 0) { 
    13501315            if (allow_duplicates) 
    13511316                return 1; 
    1352             return yaml_parser_set_parser_error(parser, 
     1317            return PARSER_ERROR_INIT(parser, 
    13531318                    "found duplicate %TAG directive", mark); 
    13541319        } 
     
    13581323    copy.prefix = yaml_strdup(value.prefix); 
    13591324    if (!copy.handle || !copy.prefix) { 
    1360         parser->error = YAML_MEMORY_ERROR; 
     1325        MEMORY_ERROR_INIT(parser); 
    13611326        goto error; 
    13621327    } 
  • libyaml/trunk/src/reader.c

    r262 r263  
    3636    /* Ensure that we had enough bytes in the raw buffer. */ 
    3737 
    38     while (!parser->is_eof && parser->raw_input.length < 3) { 
     38    while (!parser->is_eof && parser->raw_input.capacity < 3) { 
    3939        if (!yaml_parser_update_raw_buffer(parser)) { 
    4040            return 0; 
     
    4444    /* Determine the encoding. */ 
    4545 
    46     if (parser->raw_input.length >= 2 
     46    if (parser->raw_input.capacity >= 2 
    4747            && !memcmp(parser->raw_input.buffer, BOM_UTF16LE, 2)) { 
    4848        parser->encoding = YAML_UTF16LE_ENCODING; 
     
    5050        parser->offset = 2; 
    5151    } 
    52     else if (parser->raw_input.length >= 2 
     52    else if (parser->raw_input.capacity >= 2 
    5353            && !memcmp(parser->raw_input.buffer, BOM_UTF16BE, 2)) { 
    5454        parser->encoding = YAML_UTF16BE_ENCODING; 
     
    5656        parser->offset = 2; 
    5757    } 
    58     else if (parser->raw_input.length >= 3 
     58    else if (parser->raw_input.capacity >= 3 
    5959            && !memcmp(parser->raw_input.buffer, BOM_UTF8, 3)) { 
    6060        parser->encoding = YAML_UTF8_ENCODING; 
     
    8181 
    8282    if (parser->raw_input.pointer == 0 && 
    83             parser->raw_input.length == parser->raw_input.capacity) 
     83            parser->raw_input.capacity == RAW_INPUT_BUFFER_CAPACITY) 
    8484        return 1; 
    8585 
     
    9292 
    9393    if (parser->raw_input.pointer > 0 && 
    94             parser->raw_input.pointer < parser->raw_input.length) { 
     94            parser->raw_input.pointer < parser->raw_input.capacity) { 
    9595        memmove(parser->raw_input.buffer, 
    9696                parser->raw_input.buffer + parser->raw_input.pointer, 
    97                 parser->raw_input.length - parser->raw_input.pointer); 
    98     } 
     97                parser->raw_input.capacity - parser->raw_input.pointer); 
     98    } 
     99    parser->raw_input.capacity -= parser->raw_input.pointer; 
    99100    parser->raw_input.pointer = 0; 
    100101 
     
    102103 
    103104    if (!parser->reader(parser->reader_data, 
    104                 parser->raw_input.buffer + parser->raw_input.length, 
    105                 parser->raw_input.capacity - parser->raw_input.length, 
     105                parser->raw_input.buffer + parser->raw_input.capacity, 
     106                RAW_INPUT_BUFFER_CAPACITY - parser->raw_input.capacity, 
    106107                &length)) { 
    107108        return READER_ERROR_INIT(parser, "Input error", parser->offset); 
    108109    } 
    109     parser->raw_input.length += length; 
     110    parser->raw_input.capacity += length; 
    110111    if (!length) { 
    111112        parser->is_eof = 1; 
     
    125126yaml_parser_update_buffer(yaml_parser_t *parser, size_t length) 
    126127{ 
     128    size_t old_capacity; 
     129 
    127130    assert(parser->reader); /* Read handler must be set. */ 
    128131 
    129132    /* If the EOF flag is set and the raw buffer is empty, do nothing. */ 
    130133 
    131     if (parser->is_eof && parser->raw_input.pointer == parser->raw_input.length) 
     134    if (parser->is_eof && parser->raw_input.pointer == parser->raw_input.capacity) 
    132135        return 1; 
    133136 
     
    147150 
    148151    if (parser->input.pointer > 0 && 
    149             parser->input.pointer < parser->input.length) { 
     152            parser->input.pointer < parser->input.capacity) { 
    150153        memmove(parser->input.buffer, 
    151154                parser->input.buffer + parser->input.pointer, 
    152                 parser->input.length - parser->input.pointer); 
    153         parser->input.length -= parser->input.pointer; 
    154         parser->input.pointer = 0; 
    155     } 
    156     else if (parser->input.pointer == parser->input.length) { 
    157         parser->input.pointer = parser->input.length = 0; 
    158     } 
     155                parser->input.capacity - parser->input.pointer); 
     156        parser->input.capacity -= parser->input.pointer; 
     157    } 
     158    else if (parser->input.pointer == parser->input.capacity) { 
     159        parser->input.capacity = 0; 
     160    } 
     161 
     162    /* Set the pointer to the end of the buffer. */ 
     163 
     164    parser->input.pointer = parser->input.capacity; 
    159165 
    160166    /* Fill the buffer until it has enough characters. */ 
     
    168174        /* Decode the raw buffer. */ 
    169175 
    170         while (parser->raw_input.pointer != parser->raw_input.length) 
     176        while (parser->raw_input.pointer != parser->raw_input.capacity) 
    171177        { 
    172             unsigned char *raw_buffer = 
    173                 parser->raw_input.buffer + parser->raw_input.pointer; 
    174178            size_t raw_unread = 
    175                 parser->raw_input.length - parser->raw_input.pointer; 
     179                parser->raw_input.capacity - parser->raw_input.pointer; 
    176180            unsigned int value = 0, value2 = 0; 
    177181            int is_incomplete = 0; 
     
    179183            unsigned int width = 0; 
    180184            int low, high; 
    181             size_t k; 
     185            size_t idx; 
    182186 
    183187            /* Decode the next character. */ 
     
    209213                    /* Determine the length of the UTF-8 sequence. */ 
    210214 
    211                     octet = *raw_buffer; 
     215                    octet = OCTET(parser->raw_input); 
    212216                    width = (octet & 0x80) == 0x00 ? 1 : 
    213217                            (octet & 0xE0) == 0xC0 ? 2 : 
     
    243247                    /* Check and decode the trailing octets. */ 
    244248 
    245                     for (k = 1; k < width; k ++) 
     249                    for (idx = 1; idx < width; idx ++) 
    246250                    { 
    247                         octet = raw_buffer[k]; 
     251                        octet = OCTET_AT(parser->raw_input, idx); 
    248252 
    249253                        /* Check if the octet is valid. */ 
     
    252256                            return DECODER_ERROR_INIT(parser, 
    253257                                    "Invalid trailing UTF-8 octet", 
    254                                     parser->offset+k, octet); 
     258                                    parser->offset+idx, octet); 
    255259 
    256260                        /* Decode the octet. */ 
     
    324328                    /* Get the character. */ 
    325329 
    326                     value = raw_buffer[low] + (raw_buffer[high] << 8); 
     330                    value = OCTET_AT(parser->raw_input, low) 
     331                        + (OCTET_AT(parser->raw_input, high) << 8); 
    327332 
    328333                    /* Check for unexpected low surrogate area. */ 
     
    353358                        /* Get the next character. */ 
    354359 
    355                         value2 = raw_buffer[low+2] + (raw_buffer[high+2] << 8); 
     360                        value2 = OCTET_AT(parser->raw_input, low+2) 
     361                            + (OCTET_AT(parser->raw_input, high+2) << 8); 
    356362 
    357363                        /* Check for a low surrogate area. */ 
     
    407413            /* 0000 0000-0000 007F -> 0xxxxxxx */ 
    408414            if (value <= 0x7F) { 
    409                 parser->input.buffer[parser->input.length++] = value; 
     415                JOIN_OCTET(parser->input, value); 
    410416            } 
    411417            /* 0000 0080-0000 07FF -> 110xxxxx 10xxxxxx */ 
    412418            else if (value <= 0x7FF) { 
    413                 parser->input.buffer[parser->input.length++] = 0xC0 + (value >> 6); 
    414                 parser->input.buffer[parser->input.length++] = 0x80 + (value & 0x3F); 
     419                JOIN_OCTET(parser->input, 0xC0 + (value >> 6)); 
     420                JOIN_OCTET(parser->input, 0x80 + (value & 0x3F)); 
    415421            } 
    416422            /* 0000 0800-0000 FFFF -> 1110xxxx 10xxxxxx 10xxxxxx */ 
    417423            else if (value <= 0xFFFF) { 
    418                 parser->input.buffer[parser->input.length++] = 0xE0 + (value >> 12); 
    419                 parser->input.buffer[parser->input.length++] = 0x80 + ((value >> 6) & 0x3F); 
    420                 parser->input.buffer[parser->input.length++] = 0x80 + (value & 0x3F); 
     424                JOIN_OCTET(parser->input, 0xE0 + (value >> 12)); 
     425                JOIN_OCTET(parser->input, 0x80 + ((value >> 6) & 0x3F)); 
     426                JOIN_OCTET(parser->input, 0x80 + (value & 0x3F)); 
    421427            } 
    422428            /* 0001 0000-0010 FFFF -> 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */ 
    423429            else { 
    424                 parser->input.buffer[parser->input.length++] = 0xF0 + (value >> 18); 
    425                 parser->input.buffer[parser->input.length++] = 0x80 + ((value >> 12) & 0x3F); 
    426                 parser->input.buffer[parser->input.length++] = 0x80 + ((value >> 6) & 0x3F); 
    427                 parser->input.buffer[parser->input.length++] = 0x80 + (value & 0x3F); 
     430                JOIN_OCTET(parser->input, 0xF0 + (value >> 18)); 
     431                JOIN_OCTET(parser->input, 0x80 + ((value >> 12) & 0x3F)); 
     432                JOIN_OCTET(parser->input, 0x80 + ((value >> 6) & 0x3F)); 
     433                JOIN_OCTET(parser->input, 0x80 + (value & 0x3F)); 
    428434            } 
    429435 
     
    431437        } 
    432438 
    433         /* On EOF, put NUL into the buffer and return. */ 
     439        /* On EOF, put NUL into the buffer and stop. */ 
    434440 
    435441        if (parser->is_eof) { 
    436             parser->input.buffer[parser->input.length++] = '\0'; 
     442            JOIN_OCTET(parser->input, '\0'); 
    437443            parser->unread ++; 
    438             return 1; 
     444            break; 
    439445        } 
    440446 
    441447    } 
     448    /* Swap the pointer with the end of the buffer. */ 
     449 
     450    old_capacity = parser->input.capacity; 
     451    parser->input.capacity = parser->input.pointer; 
     452    parser->input.pointer = old_capacity; 
    442453 
    443454    return 1; 
  • libyaml/trunk/src/scanner.c

    r243 r263  
    496496      parser->mark.column ++,                                                   \ 
    497497      parser->unread --,                                                        \ 
    498       parser->buffer.pointer += WIDTH(parser->buffer)) 
     498      parser->input.pointer += WIDTH(parser->input)) 
    499499 
    500500#define SKIP_LINE(parser)                                                       \ 
    501      (IS_CRLF(parser->buffer) ?                                                 \ 
     501     (IS_CRLF(parser->input) ?                                                  \ 
    502502      (parser->mark.index += 2,                                                 \ 
    503503       parser->mark.column = 0,                                                 \ 
    504504       parser->mark.line ++,                                                    \ 
    505505       parser->unread -= 2,                                                     \ 
    506        parser->buffer.pointer += 2) :                                           \ 
    507       IS_BREAK(parser->buffer) ?                                                \ 
     506       parser->input.pointer += 2) :                                            \ 
     507      IS_BREAK(parser->input) ?                                                 \ 
    508508      (parser->mark.index ++,                                                   \ 
    509509       parser->mark.column = 0,                                                 \ 
    510510       parser->mark.line ++,                                                    \ 
    511511       parser->unread --,                                                       \ 
    512        parser->buffer.pointer += WIDTH(parser->buffer)) : 0) 
     512       parser->input.pointer += WIDTH(parser->input)) : 0) 
    513513 
    514514/* 
     
    518518#define READ(parser,string)                                                     \ 
    519519     (STRING_EXTEND(parser,string) ?                                            \ 
    520          (COPY(string,parser->buffer),                                          \ 
     520         (COPY(string,parser->input),                                           \ 
    521521          parser->mark.index ++,                                                \ 
    522522          parser->mark.column ++,                                               \ 
     
    530530#define READ_LINE(parser,string)                                                \ 
    531531    (STRING_EXTEND(parser,string) ?                                             \ 
    532     (((CHECK_AT(parser->buffer,'\r',0)                                          \ 
    533        && CHECK_AT(parser->buffer,'\n',1)) ?        /* CR LF -> LF */           \ 
    534      (*((string).pointer++) = (yaml_char_t) '\n',                               \ 
    535       parser->buffer.pointer += 2,                                              \ 
     532    (((CHECK_AT(parser->input,'\r',0)                                           \ 
     533       && CHECK_AT(parser->input,'\n',1)) ?         /* CR LF -> LF */           \ 
     534     (JOIN_OCTET(string, (yaml_char_t) '\n'),                                   \ 
     535      parser->input.pointer += 2,                                               \ 
    536536      parser->mark.index += 2,                                                  \ 
    537537      parser->mark.column = 0,                                                  \ 
    538538      parser->mark.line ++,                                                     \ 
    539539      parser->unread -= 2) :                                                    \ 
    540      (CHECK_AT(parser->buffer,'\r',0)                                           \ 
    541       || CHECK_AT(parser->buffer,'\n',0)) ?         /* CR|LF -> LF */           \ 
    542      (*((string).pointer++) = (yaml_char_t) '\n',                               \ 
    543       parser->buffer.pointer ++,                                                \ 
     540     (CHECK_AT(parser->input,'\r',0)                                            \ 
     541      || CHECK_AT(parser->input,'\n',0)) ?          /* CR|LF -> LF */           \ 
     542     (JOIN_OCTET(string,(yaml_char_t) '\n'),                                    \ 
     543      parser->input.pointer ++,                                                 \ 
    544544      parser->mark.index ++,                                                    \ 
    545545      parser->mark.column = 0,                                                  \ 
    546546      parser->mark.line ++,                                                     \ 
    547547      parser->unread --) :                                                      \ 
    548      (CHECK_AT(parser->buffer,'\xC2',0)                                         \ 
    549       && CHECK_AT(parser->buffer,'\x85',1)) ?       /* NEL -> LF */             \ 
    550      (*((string).pointer++) = (yaml_char_t) '\n',                               \ 
    551       parser->buffer.pointer += 2,                                              \ 
     548     (CHECK_AT(parser->input,'\xC2',0)                                          \ 
     549      && CHECK_AT(parser->input,'\x85',1)) ?        /* NEL -> LF */             \ 
     550     (JOIN_OCTET(string,(yaml_char_t) '\n'),                                    \ 
     551      parser->input.pointer += 2,                                               \ 
    552552      parser->mark.index ++,                                                    \ 
    553553      parser->mark.column = 0,                                                  \ 
    554554      parser->mark.line ++,                                                     \ 
    555555      parser->unread --) :                                                      \ 
    556      (CHECK_AT(parser->buffer,'\xE2',0) &&                                      \ 
    557       CHECK_AT(parser->buffer,'\x80',1) &&                                      \ 
    558       (CHECK_AT(parser->buffer,'\xA8',2) ||                                     \ 
    559        CHECK_AT(parser->buffer,'\xA9',2))) ?        /* LS|PS -> LS|PS */        \ 
    560      (*((string).pointer++) = *(parser->buffer.pointer++),                      \ 
    561       *((string).pointer++) = *(parser->buffer.pointer++),                      \ 
    562       *((string).pointer++) = *(parser->buffer.pointer++),                      \ 
     556     (CHECK_AT(parser->input,'\xE2',0) &&                                       \ 
     557      CHECK_AT(parser->input,'\x80',1) &&                                       \ 
     558      (CHECK_AT(parser->input,'\xA8',2) ||                                      \ 
     559       CHECK_AT(parser->input,'\xA9',2))) ?         /* LS|PS -> LS|PS */        \ 
     560     (COPY_OCTET(string,parser->input),                                         \ 
     561      COPY_OCTET(string,parser->input),                                         \ 
     562      COPY_OCTET(string,parser->input),                                         \ 
    563563      parser->mark.index ++,                                                    \ 
    564564      parser->mark.column = 0,                                                  \ 
     
    575575 
    576576/* 
    577  * Error handling. 
    578  */ 
    579  
    580 static int 
    581 yaml_parser_set_scanner_error(yaml_parser_t *parser, const char *context, 
    582         yaml_mark_t context_mark, const char *problem); 
    583  
    584 /* 
    585577 * High-level token API. 
    586578 */ 
     
    751743    /* No tokens after STREAM-END or error. */ 
    752744 
    753     if (parser->stream_end_produced || parser->error) { 
     745    if (parser->is_stream_end_produced || parser->error.type) { 
    754746        return 1; 
    755747    } 
     
    757749    /* Ensure that the tokens queue contains enough tokens. */ 
    758750 
    759     if (!parser->token_available) { 
     751    if (!parser->is_token_available) { 
    760752        if (!yaml_parser_fetch_more_tokens(parser)) 
    761753            return 0; 
     
    765757     
    766758    *token = DEQUEUE(parser, parser->tokens); 
    767     parser->token_available = 0; 
     759    parser->is_token_available = 0; 
    768760    parser->tokens_parsed ++; 
    769761 
    770762    if (token->type == YAML_STREAM_END_TOKEN) { 
    771         parser->stream_end_produced = 1; 
    772     } 
    773  
    774     return 1; 
    775 } 
    776  
    777 /* 
    778  * Set the scanner error and return 0. 
    779  */ 
    780  
    781 static int 
    782 yaml_parser_set_scanner_error(yaml_parser_t *parser, const char *context, 
    783         yaml_mark_t context_mark, const char *problem) 
    784 { 
    785     parser->error = YAML_SCANNER_ERROR; 
    786     parser->context = context; 
    787     parser->context_mark = context_mark; 
    788     parser->problem = problem; 
    789     parser->problem_mark = parser->mark; 
    790  
    791     return 0; 
     763        parser->is_stream_end_produced = 1; 
     764    } 
     765 
     766    return 1; 
    792767} 
    793768 
     
    820795        else 
    821796        { 
    822             yaml_simple_key_t *simple_key; 
     797            size_t idx; 
    823798 
    824799            /* Check if any potential simple key may occupy the head position. */ 
     
    827802                return 0; 
    828803 
    829             for (simple_key = parser->simple_keys.start; 
    830                     simple_key != parser->simple_keys.top; simple_key++) { 
    831                 if (simple_key->possible 
     804            for (idx = 0; idx < parser->simple_keys.length; idx++) { 
     805                yaml_simple_key_t *simple_key  = parser->simple_keys.list + idx; 
     806                if (simple_key->is_possible 
    832807                        && simple_key->token_number == parser->tokens_parsed) { 
    833808                    need_more_tokens = 1; 
     
    848823    } 
    849824 
    850     parser->token_available = 1; 
     825    parser->is_token_available = 1; 
    851826 
    852827    return 1; 
     
    860835yaml_parser_fetch_next_token(yaml_parser_t *parser) 
    861836{ 
     837    yaml_mark_t start_mark = parser->mark; 
     838 
    862839    /* Ensure that the buffer is initialized. */ 
    863840 
     
    867844    /* Check if we just started scanning.  Fetch STREAM-START then. */ 
    868845 
    869     if (!parser->stream_start_produced) 
     846    if (!parser->is_stream_start_produced) 
    870847        return yaml_parser_fetch_stream_start(parser); 
    871848 
     
    895872    /* Is it the end of the stream? */ 
    896873 
    897     if (IS_Z(parser->buffer)) 
     874    if (IS_Z(parser->input)) 
    898875        return yaml_parser_fetch_stream_end(parser); 
    899876 
    900877    /* Is it a directive? */ 
    901878 
    902     if (parser->mark.column == 0 && CHECK(parser->buffer, '%')) 
     879    if (parser->mark.column == 0 && CHECK(parser->input, '%')) 
    903880        return yaml_parser_fetch_directive(parser); 
    904881 
     
    906883 
    907884    if (parser->mark.column == 0 
    908             && CHECK_AT(parser->buffer, '-', 0) 
    909             && CHECK_AT(parser->buffer, '-', 1) 
    910             && CHECK_AT(parser->buffer, '-', 2) 
    911             && IS_BLANKZ_AT(parser->buffer, 3)) 
     885            && CHECK_AT(parser->input, '-', 0) 
     886            && CHECK_AT(parser->input, '-', 1) 
     887            && CHECK_AT(parser->input, '-', 2) 
     888            && IS_BLANKZ_AT(parser->input, 3)) 
    912889        return yaml_parser_fetch_document_indicator(parser, 
    913890                YAML_DOCUMENT_START_TOKEN); 
     
    916893 
    917894    if (parser->mark.column == 0 
    918             && CHECK_AT(parser->buffer, '.', 0) 
    919             && CHECK_AT(parser->buffer, '.', 1) 
    920             && CHECK_AT(parser->buffer, '.', 2) 
    921             && IS_BLANKZ_AT(parser->buffer, 3)) 
     895            && CHECK_AT(parser->input, '.', 0) 
     896            && CHECK_AT(parser->input, '.', 1) 
     897            && CHECK_AT(parser->input, '.', 2) 
     898            && IS_BLANKZ_AT(parser->input, 3)) 
    922899        return yaml_parser_fetch_document_indicator(parser, 
    923900                YAML_DOCUMENT_END_TOKEN); 
     
    925902    /* Is it the flow sequence start indicator? */ 
    926903 
    927     if (CHECK(parser->buffer, '[')) 
     904    if (CHECK(parser->input, '[')) 
    928905        return yaml_parser_fetch_flow_collection_start(parser, 
    929906                YAML_FLOW_SEQUENCE_START_TOKEN); 
     
    931908    /* Is it the flow mapping start indicator? */ 
    932909 
    933     if (CHECK(parser->buffer, '{')) 
     910    if (CHECK(parser->input, '{')) 
    934911        return yaml_parser_fetch_flow_collection_start(parser, 
    935912                YAML_FLOW_MAPPING_START_TOKEN); 
     
    937914    /* Is it the flow sequence end indicator? */ 
    938915 
    939     if (CHECK(parser->buffer, ']')) 
     916    if (CHECK(parser->input, ']')) 
    940917        return yaml_parser_fetch_flow_collection_end(parser, 
    941918                YAML_FLOW_SEQUENCE_END_TOKEN); 
     
    943920    /* Is it the flow mapping end indicator? */ 
    944921 
    945     if (CHECK(parser->buffer, '}')) 
     922    if (CHECK(parser->input, '}')) 
    946923        return yaml_parser_fetch_flow_collection_end(parser, 
    947924                YAML_FLOW_MAPPING_END_TOKEN); 
     
    949926    /* Is it the flow entry indicator? */ 
    950927 
    951     if (CHECK(parser->buffer, ',')) 
     928    if (CHECK(parser->input, ',')) 
    952929        return yaml_parser_fetch_flow_entry(parser); 
    953930 
    954931    /* Is it the block entry indicator? */ 
    955932 
    956     if (CHECK(parser->buffer, '-') && IS_BLANKZ_AT(parser->buffer, 1)) 
     933    if (CHECK(parser->input, '-') && IS_BLANKZ_AT(parser->input, 1)) 
    957934        return yaml_parser_fetch_block_entry(parser); 
    958935 
    959936    /* Is it the key indicator? */ 
    960937 
    961     if (CHECK(parser->buffer, '?') 
    962             && (parser->flow_level || IS_BLANKZ_AT(parser->buffer, 1))) 
     938    if (CHECK(parser->input, '?') 
     939            && (parser->flow_level || IS_BLANKZ_AT(parser->input, 1))) 
    963940        return yaml_parser_fetch_key(parser); 
    964941 
    965942    /* Is it the value indicator? */ 
    966943 
    967     if (CHECK(parser->buffer, ':') 
    968             && (parser->flow_level || IS_BLANKZ_AT(parser->buffer, 1))) 
     944    if (CHECK(parser->input, ':') 
     945            && (parser->flow_level || IS_BLANKZ_AT(parser->input, 1))) 
    969946        return yaml_parser_fetch_value(parser); 
    970947 
    971948    /* Is it an alias? */ 
    972949 
    973     if (CHECK(parser->buffer, '*')) 
     950    if (CHECK(parser->input, '*')) 
    974951        return yaml_parser_fetch_anchor(parser, YAML_ALIAS_TOKEN); 
    975952 
    976953    /* Is it an anchor? */ 
    977954 
    978     if (CHECK(parser->buffer, '&')) 
     955    if (CHECK(parser->input, '&')) 
    979956        return yaml_parser_fetch_anchor(parser, YAML_ANCHOR_TOKEN); 
    980957 
    981958    /* Is it a tag? */ 
    982959 
    983     if (CHECK(parser->buffer, '!')) 
     960    if (CHECK(parser->input, '!')) 
    984961        return yaml_parser_fetch_tag(parser); 
    985962 
    986963    /* Is it a literal scalar? */ 
    987964 
    988     if (CHECK(parser->buffer, '|') && !parser->flow_level) 
     965    if (CHECK(parser->input, '|') && !parser->flow_level) 
    989966        return yaml_parser_fetch_block_scalar(parser, 1); 
    990967 
    991968    /* Is it a folded scalar? */ 
    992969 
    993     if (CHECK(parser->buffer, '>') && !parser->flow_level) 
     970    if (CHECK(parser->input, '>') && !parser->flow_level) 
    994971        return yaml_parser_fetch_block_scalar(parser, 0); 
    995972 
    996973    /* Is it a single-quoted scalar? */ 
    997974 
    998     if (CHECK(parser->buffer, '\'')) 
     975    if (CHECK(parser->input, '\'')) 
    999976        return yaml_parser_fetch_flow_scalar(parser, 1); 
    1000977 
    1001978    /* Is it a double-quoted scalar? */ 
    1002979 
    1003     if (CHECK(parser->buffer, '"')) 
     980    if (CHECK(parser->input, '"')) 
    1004981        return yaml_parser_fetch_flow_scalar(parser, 0); 
    1005982 
     
    10231000     */ 
    10241001 
    1025     if (!(IS_BLANKZ(parser->buffer) || CHECK(parser->buffer, '-') 
    1026                 || CHECK(parser->buffer, '?') || CHECK(parser->buffer, ':') 
    1027                 || CHECK(parser->buffer, ',') || CHECK(parser->buffer, '[') 
    1028                 || CHECK(parser->buffer, ']') || CHECK(parser->buffer, '{') 
    1029                 || CHECK(parser->buffer, '}') || CHECK(parser->buffer, '#') 
    1030                 || CHECK(parser->buffer, '&') || CHECK(parser->buffer, '*') 
    1031                 || CHECK(parser->buffer, '!') || CHECK(parser->buffer, '|') 
    1032                 || CHECK(parser->buffer, '>') || CHECK(parser->buffer, '\'') 
    1033                 || CHECK(parser->buffer, '"') || CHECK(parser->buffer, '%') 
    1034                 || CHECK(parser->buffer, '@') || CHECK(parser->buffer, '`')) || 
    1035             (CHECK(parser->buffer, '-') && !IS_BLANK_AT(parser->buffer, 1)) || 
     1002    if (!(IS_BLANKZ(parser->input) || CHECK(parser->input, '-') 
     1003                || CHECK(parser->input, '?') || CHECK(parser->input, ':') 
     1004                || CHECK(parser->input, ',') || CHECK(parser->input, '[') 
     1005                || CHECK(parser->input, ']') || CHECK(parser->input, '{') 
     1006                || CHECK(parser->input, '}') || CHECK(parser->input, '#') 
     1007                || CHECK(parser->input, '&') || CHECK(parser->input, '*') 
     1008                || CHECK(parser->input, '!') || CHECK(parser->input, '|') 
     1009                || CHECK(parser->input, '>') || CHECK(parser->input, '\'') 
     1010                || CHECK(parser->input, '"') || CHECK(parser->input, '%') 
     1011                || CHECK(parser->input, '@') || CHECK(parser->input, '`')) || 
     1012            (CHECK(parser->input, '-') && !IS_BLANK_AT(parser->input, 1)) || 
    10361013            (!parser->flow_level && 
    1037              (CHECK(parser->buffer, '?') || CHECK(parser->buffer, ':')) 
    1038              && !IS_BLANKZ_AT(parser->buffer, 1))) 
     1014             (CHECK(parser->input, '?') || CHECK(parser->input, ':')) 
     1015             && !IS_BLANKZ_AT(parser->input, 1))) 
    10391016        return yaml_parser_fetch_plain_scalar(parser); 
    10401017 
     
    10431020     */ 
    10441021 
    1045     return yaml_parser_set_scanner_error(parser, 
    1046             "while scanning for the next token", parser->mark, 
    1047             "found character that cannot start any token"); 
     1022    return SCANNER_ERROR_WITH_CONTEXT_INIT(parser, 
     1023            "while scanning for the next token", start_mark, 
     1024            "found character that cannot start any token", parser->mark); 
    10481025} 
    10491026 
     
    10561033yaml_parser_stale_simple_keys(yaml_parser_t *parser) 
    10571034{ 
    1058     yaml_simple_key_t *simple_key; 
     1035    size_t idx; 
    10591036 
    10601037    /* Check for a potential simple key for each flow level. */ 
    10611038 
    1062     for (simple_key = parser->simple_keys.start; 
    1063             simple_key != parser->simple_keys.top; simple_key ++) 
     1039    for (idx = 0; idx < parser->simple_keys.length; idx ++) 
    10641040    { 
     1041        yaml_simple_key_t *simple_key = parser->simple_keys.list + idx; 
     1042 
    10651043        /* 
    10661044         * The specification requires that a simple key 
     
    10701048         */ 
    10711049 
    1072         if (simple_key->possible 
     1050        if (simple_key->is_possible 
    10731051                && (simple_key->mark.line < parser->mark.line 
    10741052                    || simple_key->mark.index+1024 < parser->mark.index)) { 
     
    10761054            /* Check if the potential simple key to be removed is required. */ 
    10771055 
    1078             if (simple_key->required) { 
    1079                 return yaml_parser_set_scanner_error(parser, 
     1056            if (simple_key->is_required) { 
     1057                return SCANNER_ERROR_WITH_CONTEXT_INIT(parser, 
    10801058                        "while scanning a simple key", simple_key->mark, 
    1081                         "could not found expected ':'"); 
     1059                        "could not found expected ':'", parser->mark); 
    10821060            } 
    10831061 
    1084             simple_key->possible = 0; 
     1062            simple_key->is_possible = 0; 
    10851063        } 
    10861064    } 
     
    11031081     */ 
    11041082 
    1105     int required = (!parser->flow_level 
     1083    int is_required = (!parser->flow_level 
    11061084            && parser->indent == (int)parser->mark.column); 
    11071085 
     
    11111089     */ 
    11121090 
    1113     assert(parser->simple_key_allowed || !required);    /* Impossible. */ 
     1091    assert(parser->is_simple_key_allowed || !is_required);  /* Impossible. */ 
    11141092 
    11151093    /* 
     
    11171095     */ 
    11181096 
    1119     if (parser->simple_key_allowed) 
     1097    if (parser->is_simple_key_allowed) 
    11201098    { 
    1121         yaml_simple_key_t simple_key = { 1, required, 
     1099        yaml_simple_key_t simple_key = { 1, is_required, 
    11221100            parser->tokens_parsed + parser->tokens.tail - parser->tokens.head, 
    11231101            { 0, 0, 0 } }; 
     
    11261104        if (!yaml_parser_remove_simple_key(parser)) return 0; 
    11271105 
    1128         *(parser->simple_keys.top-1) = simple_key; 
     1106        parser->simple_keys.list[parser->simple_keys.length-1] = simple_key; 
    11291107    } 
    11301108 
     
    11391117yaml_parser_remove_simple_key(yaml_parser_t *parser) 
    11401118{ 
    1141     yaml_simple_key_t *simple_key = parser->simple_keys.top-1; 
    1142  
    1143     if (simple_key->possible) 
     1119    yaml_simple_key_t *simple_key = 
     1120        parser->simple_keys.list + parser->simple_keys.length - 1; 
     1121 
     1122    if (simple_key->is_possible) 
    11441123    { 
    11451124        /* If the key is required, it is an error. */ 
    11461125 
    1147         if (simple_key->required) { 
    1148             return yaml_parser_set_scanner_error(parser, 
     1126        if (simple_key->is_required) { 
     1127            return SCANNER_ERROR_WITH_CONTEXT_INIT(parser, 
    11491128                    "while scanning a simple key", simple_key->mark, 
    1150                     "could not found expected ':'"); 
     1129                    "could not found expected ':'", parser->mark); 
    11511130        } 
    11521131    } 
     
    11541133    /* Remove the key from the stack. */ 
    11551134 
    1156     simple_key->possible = 0; 
     1135    simple_key->is_possible = 0; 
    11571136 
    11581137    return 1; 
     
    13021281    /* A simple key is allowed at the beginning of the stream. */ 
    13031282 
    1304     parser->simple_key_allowed = 1; 
     1283    parser->is_simple_key_allowed = 1; 
    13051284 
    13061285    /* We have started. */ 
    13071286 
    1308     parser->stream_start_produced = 1; 
     1287    parser->is_stream_start_produced = 1; 
    13091288 
    13101289    /* Create the STREAM-START token and append it to the queue. */ 
     
    13451324        return 0; 
    13461325 
    1347     parser->simple_key_allowed = 0; 
     1326    parser->is_simple_key_allowed = 0; 
    13481327 
    13491328    /* Create the STREAM-END token and append it to the queue. */ 
     
    13761355        return 0; 
    13771356 
    1378     parser->simple_key_allowed = 0; 
     1357    parser->is_simple_key_allowed = 0; 
    13791358 
    13801359    /* Create the YAML-DIRECTIVE or TAG-DIRECTIVE token. */ 
     
    14141393        return 0; 
    14151394 
    1416     parser->simple_key_allowed = 0; 
     1395    parser->is_simple_key_allowed = 0; 
    14171396 
    14181397    /* Consume the token. */ 
     
    14611440    /* A simple key may follow the indicators '[' and '{'. */ 
    14621441 
    1463     parser->simple_key_allowed = 1; 
     1442    parser->is_simple_key_allowed = 1; 
    14641443 
    14651444    /* Consume the token. */ 
     
    15041483    /* No simple keys after the indicators ']' and '}'. */ 
    15051484 
    1506     parser->simple_key_allowed = 0; 
     1485    parser->is_simple_key_allowed = 0; 
    15071486 
    15081487    /* Consume the token. */ 
     
    15411520    /* Simple keys are allowed after ','. */ 
    15421521 
    1543     parser->simple_key_allowed = 1; 
     1522    parser->is_simple_key_allowed = 1; 
    15441523 
    15451524    /* Consume the token. */ 
     
    15751554        /* Check if we are allowed to start a new entry. */ 
    15761555 
    1577         if (!parser->simple_key_allowed) { 
    1578             return yaml_parser_set_scanner_error(parser, NULL, parser->mark, 
    1579                     "block sequence entries are not allowed in this context"); 
     1556        if (!parser->is_simple_key_allowed) { 
     1557            return SCANNER_ERROR_INIT(parser, 
     1558                    "block sequence entries are not allowed in this context", 
     1559                    parser->mark); 
    15801560        } 
    15811561 
     
    16021582    /* Simple keys are allowed after '-'. */ 
    16031583 
    1604     parser->simple_key_allowed = 1; 
     1584    parser->is_simple_key_allowed = 1; 
    16051585 
    16061586    /* Consume the token. */ 
     
    16361616        /* Check if we are allowed to start a new key (not nessesary simple). */ 
    16371617 
    1638         if (!parser->simple_key_allowed) { 
    1639             return yaml_parser_set_scanner_error(parser, NULL, parser->mark, 
    1640                     "mapping keys are not allowed in this context"); 
     1618        if (!parser->is_simple_key_allowed) { 
     1619            return SCANNER_ERROR_INIT(parser, 
     1620                    "mapping keys are not allowed in this context", parser->mark); 
    16411621        } 
    16421622 
     
    16551635    /* Simple keys are allowed after '?' in the block context. */ 
    16561636 
    1657     parser->simple_key_allowed = (!parser->flow_level); 
     1637    parser->is_simple_key_allowed = (!parser->flow_level); 
    16581638 
    16591639    /* Consume the token. */ 
     
    16821662    yaml_mark_t start_mark, end_mark; 
    16831663    yaml_token_t token; 
    1684     yaml_simple_key_t *simple_key = parser->simple_keys.top-1; 
     1664    yaml_simple_key_t *simple_key = 
     1665        parser->simple_keys.list + parser->simple_keys.length - 1; 
    16851666 
    16861667    /* Have we found a simple key? */ 
    16871668 
    1688     if (simple_key->possible) 
     1669    if (simple_key->is_possible) 
    16891670    { 
    16901671 
     
    17061687        /* Remove the simple key. */ 
    17071688 
    1708         simple_key->possible = 0; 
     1689        simple_key->is_possible = 0; 
    17091690 
    17101691        /* A simple key cannot follow another simple key. */ 
    17111692 
    1712         parser->simple_key_allowed = 0; 
     1693        parser->is_simple_key_allowed = 0; 
    17131694    } 
    17141695    else 
     
    17221703            /* Check if we are allowed to start a complex value. */ 
    17231704 
    1724             if (!parser->simple_key_allowed) { 
    1725                 return yaml_parser_set_scanner_error(parser, NULL, parser->mark, 
    1726                         "mapping values are not allowed in this context"); 
     1705            if (!parser->is_simple_key_allowed) { 
     1706                return SCANNER_ERROR_INIT(parser, 
     1707                        "mapping values are not allowed in this context", 
     1708                        parser->mark); 
    17271709            } 
    17281710 
     
    17361718        /* Simple keys after ':' are allowed in the block context. */ 
    17371719 
    1738         parser->simple_key_allowed = (!parser->flow_level); 
     1720        parser->is_simple_key_allowed = (!parser->flow_level); 
    17391721    } 
    17401722 
     
    17711753    /* A simple key cannot follow an anchor or an alias. */ 
    17721754 
    1773     parser->simple_key_allowed = 0; 
     1755    parser->is_simple_key_allowed = 0; 
    17741756 
    17751757    /* Create the ALIAS or ANCHOR token and append it to the queue. */ 
     
    18011783    /* A simple key cannot follow a tag. */ 
    18021784 
    1803     parser->simple_key_allowed = 0;