Ignore:
Timestamp:
07/21/06 09:50:32 (8 years ago)
Author:
xi
Message:

Refactor internal and external API.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libyaml/trunk/include/yaml.h

    r202 r208  
    148148} yaml_scalar_style_t; 
    149149 
    150  
    151150/** Sequence styles. */ 
    152151typedef enum { 
     
    162161 
    163162    YAML_BLOCK_MAPPING_STYLE, 
    164     YAML_FLOW_MAPPING_STYLE 
     163    YAML_FLOW_MAPPING_STYLE, 
     164    YAML_FLOW_SET_MAPPING_STYLE 
    165165} yaml_mapping_style_t; 
    166166 
     
    174174/** Token types. */ 
    175175typedef enum { 
     176    YAML_NO_TOKEN, 
     177 
    176178    YAML_STREAM_START_TOKEN, 
    177179    YAML_STREAM_END_TOKEN, 
     
    233235            /** The tag handle. */ 
    234236            yaml_char_t *handle; 
    235  
    236237            /** The tag suffix. */ 
    237238            yaml_char_t *suffix; 
     
    240241        /** The scalar value (for @c YAML_SCALAR_TOKEN). */ 
    241242        struct { 
    242  
    243243            /** The scalar value. */ 
    244244            yaml_char_t *value; 
    245  
    246245            /** The length of the scalar value. */ 
    247246            size_t length; 
    248  
    249247            /** The scalar style. */ 
    250248            yaml_scalar_style_t style; 
     
    255253            /** The major version number. */ 
    256254            int major; 
    257  
    258255            /** The minor version number. */ 
    259256            int minor; 
     
    264261            /** The tag handle. */ 
    265262            yaml_char_t *handle; 
    266  
    267263            /** The tag prefix. */ 
    268264            yaml_char_t *prefix; 
    269265        } tag_directive; 
     266 
    270267    } data; 
    271268 
    272269    /** The beginning of the token. */ 
    273270    yaml_mark_t start_mark; 
    274  
    275271    /** The end of the token. */ 
    276272    yaml_mark_t end_mark; 
     
    279275 
    280276/** 
    281  * Create a new token without assigning any data. 
    282  * 
    283  * This function can be used for constructing indicator tokens: 
    284  * @c YAML_DOCUMENT_START, @c YAML_DOCUMENT_END, 
    285  * @c YAML_BLOCK_SEQUENCE_START_TOKEN, @c YAML_BLOCK_MAPPING_START_TOKEN, 
    286  * @c YAML_BLOCK_END_TOKEN, 
    287  * @c YAML_FLOW_SEQUENCE_START_TOKEN, @c YAML_FLOW_SEQUENCE_END_TOKEN, 
    288  * @c YAML_FLOW_MAPPING_START_TOKEN, @c YAML_FLOW_MAPPING_END_TOKEN, 
    289  * @c YAML_BLOCK_ENTRY_TOKEN, @c YAML_FLOW_ENTRY_TOKEN, 
    290  * @c YAML_KEY_TOKEN, @c YAML_VALUE_TOKEN. 
    291  * 
    292  * @param[in]   type        The token type. 
    293  * @param[in]   start_mark  The beginning of the token. 
    294  * @param[in]   end_mark    The end of the token. 
    295  * 
    296  * @returns A new token object, or @c NULL on error. 
    297  */ 
    298  
    299 YAML_DECLARE(yaml_token_t *) 
    300 yaml_token_new(yaml_token_type_t type, 
    301         yaml_mark_t start_mark, yaml_mark_t end_mark); 
    302  
    303 /** 
    304  * Create a new @c YAML_STREAM_START_TOKEN token with the specified encoding. 
    305  * 
    306  * @param[in]   encoding    The stream encoding. 
    307  * @param[in]   start_mark  The beginning of the token. 
    308  * @param[in]   end_mark    The end of the token. 
    309  * 
    310  * @returns A new token object, or @c NULL on error. 
    311  */ 
    312  
    313 YAML_DECLARE(yaml_token_t *) 
    314 yaml_stream_start_token_new(yaml_encoding_t encoding, 
    315         yaml_mark_t start_mark, yaml_mark_t end_mark); 
    316  
    317 /** 
    318  * Create a new @c YAML_STREAM_END_TOKEN token. 
    319  * 
    320  * @param[in]   start_mark  The beginning of the token. 
    321  * @param[in]   end_mark    The end of the token. 
    322  * 
    323  * @returns A new token object, or @c NULL on error. 
    324  */ 
    325  
    326 YAML_DECLARE(yaml_token_t *) 
    327 yaml_stream_end_token_new(yaml_mark_t start_mark, yaml_mark_t end_mark); 
    328  
    329 /** 
    330  * Create a new @c YAML_VERSION_DIRECTIVE_TOKEN token with the specified 
    331  * version numbers. 
    332  * 
    333  * @param[in]   major       The major version number. 
    334  * @param[in]   minor       The minor version number. 
    335  * @param[in]   start_mark  The beginning of the token. 
    336  * @param[in]   end_mark    The end of the token. 
    337  * 
    338  * @returns A new token object, or @c NULL on error. 
    339  */ 
    340  
    341 YAML_DECLARE(yaml_token_t *) 
    342 yaml_version_directive_token_new(int major, int minor, 
    343         yaml_mark_t start_mark, yaml_mark_t end_mark); 
    344  
    345 /** 
    346  * Create a new @c YAML_TAG_DIRECTIVE_TOKEN token with the specified tag 
    347  * handle and prefix. 
    348  * 
    349  * Note that the @a handle and the @a prefix pointers will be freed by 
    350  * the token descructor. 
    351  * 
    352  * @param[in]   handle      The tag handle. 
    353  * @param[in]   prefix      The tag prefix. 
    354  * @param[in]   start_mark  The beginning of the token. 
    355  * @param[in]   end_mark    The end of the token. 
    356  * 
    357  * @returns A new token object, or @c NULL on error. 
    358  */ 
    359  
    360 YAML_DECLARE(yaml_token_t *) 
    361 yaml_tag_directive_token_new(yaml_char_t *handle, yaml_char_t *prefix, 
    362         yaml_mark_t start_mark, yaml_mark_t end_mark); 
    363  
    364 /** 
    365  * Create a new @c YAML_ALIAS_TOKEN token with the specified anchor. 
    366  * 
    367  * Note that the @a anchor pointer will be freed by the token descructor. 
    368  * 
    369  * @param[in]   anchor      The anchor. 
    370  * @param[in]   start_mark  The beginning of the token. 
    371  * @param[in]   end_mark    The end of the token. 
    372  * 
    373  * @returns A new token object, or @c NULL on error. 
    374  */ 
    375  
    376 YAML_DECLARE(yaml_token_t *) 
    377 yaml_alias_token_new(yaml_char_t *anchor, 
    378         yaml_mark_t start_mark, yaml_mark_t end_mark); 
    379  
    380 /** 
    381  * Create a new @c YAML_ANCHOR_TOKEN token with the specified anchor. 
    382  * 
    383  * Note that the @a anchor pointer will be freed by the token descructor. 
    384  * 
    385  * @param[in]   anchor      The anchor. 
    386  * @param[in]   start_mark  The beginning of the token. 
    387  * @param[in]   end_mark    The end of the token. 
    388  * 
    389  * @returns A new token object, or @c NULL on error. 
    390  */ 
    391  
    392 YAML_DECLARE(yaml_token_t *) 
    393 yaml_anchor_token_new(yaml_char_t *anchor, 
    394         yaml_mark_t start_mark, yaml_mark_t end_mark); 
    395  
    396 /** 
    397  * Create a new @c YAML_TAG_TOKEN token with the specified tag handle and 
    398  * suffix. 
    399  * 
    400  * Note that the @a handle and the @a suffix pointers will be freed by 
    401  * the token descructor. 
    402  * 
    403  * @param[in]   handle      The tag handle. 
    404  * @param[in]   suffix      The tag suffix. 
    405  * @param[in]   start_mark  The beginning of the token. 
    406  * @param[in]   end_mark    The end of the token. 
    407  * 
    408  * @returns A new token object, or @c NULL on error. 
    409  */ 
    410  
    411 YAML_DECLARE(yaml_token_t *) 
    412 yaml_tag_token_new(yaml_char_t *handle, yaml_char_t *suffix, 
    413         yaml_mark_t start_mark, yaml_mark_t end_mark); 
    414  
    415 /** 
    416  * Create a new @c YAML_SCALAR_TOKEN token with the specified scalar value, 
    417  * length, and style. 
    418  * 
    419  * Note that the scalar value may contain the @c NUL character, therefore 
    420  * the value length is also required.  The scalar value always ends with 
    421  * @c NUL. 
    422  * 
    423  * Note that the @a value pointer will be freed by the token descructor. 
    424  * 
    425  * @param[in]   value       The scalar value. 
    426  * @param[in]   length      The value length. 
    427  * @param[in]   style       The scalar style. 
    428  * @param[in]   start_mark  The beginning of the token. 
    429  * @param[in]   end_mark    The end of the token. 
    430  * 
    431  * @returns A new token object, or @c NULL on error. 
    432  */ 
    433  
    434 YAML_DECLARE(yaml_token_t *) 
    435 yaml_scalar_token_new(yaml_char_t *value, size_t length, 
    436         yaml_scalar_style_t style, 
    437         yaml_mark_t start_mark, yaml_mark_t end_mark); 
    438  
    439 /** 
    440  * Destroy a token object. 
     277 * Free any memory allocated for a token object. 
    441278 * 
    442279 * @param[in]   token   A token object. 
     
    455292/** Event types. */ 
    456293typedef enum { 
     294    YAML_NO_EVENT, 
     295 
    457296    YAML_STREAM_START_EVENT, 
    458297    YAML_STREAM_END_EVENT, 
     
    490329            /** The version directive. */ 
    491330            yaml_version_directive_t *version_directive; 
     331 
    492332            /** The list of tag directives. */ 
    493             yaml_tag_directive_t **tag_directives; 
     333            struct { 
     334                /** The beginning of the tag directives list. */ 
     335                yaml_tag_directive_t *start; 
     336                /** The end of the tag directives list. */ 
     337                yaml_tag_directive_t *end; 
     338            } tag_directives; 
     339 
    494340            /** Is the document indicator implicit? */ 
    495341            int implicit; 
     
    554400    /** The beginning of the token. */ 
    555401    yaml_mark_t start_mark; 
    556  
    557402    /** The end of the token. */ 
    558403    yaml_mark_t end_mark; 
     404 
    559405} yaml_event_t; 
    560406 
    561407/** 
    562  * Create a new @c YAML_STREAM_START_EVENT event. 
    563  * 
    564  * @param[in]   encoding    The stream encoding. 
    565  * @param[in]   start_mark  The beginning of the event. 
    566  * @param[in]   end_mark    The end of the event. 
    567  * 
    568  * @returns A new event object, or @c NULL on error. 
    569  */ 
    570  
    571 YAML_DECLARE(yaml_event_t *) 
    572 yaml_stream_start_event_new(yaml_encoding_t encoding, 
    573         yaml_mark_t start_mark, yaml_mark_t end_mark); 
    574  
    575 /** 
    576  * Create a new @c YAML_STREAM_END_TOKEN event. 
    577  * 
    578  * @param[in]   start_mark  The beginning of the event. 
    579  * @param[in]   end_mark    The end of the event. 
    580  * 
    581  * @returns A new event object, or @c NULL on error. 
    582  */ 
    583  
    584 YAML_DECLARE(yaml_event_t *) 
    585 yaml_stream_end_event_new(yaml_mark_t start_mark, yaml_mark_t end_mark); 
    586  
    587 /** 
    588  * Create a new @c YAML_DOCUMENT_START_EVENT event. 
    589  * 
    590  * @param[in]   version_directive   The version directive or @c NULL. 
    591  * @param[in]   tag_directives      A list of tag directives or @c NULL. 
    592  * @param[in]   implicit            Is the document indicator present? 
    593  * @param[in]   start_mark          The beginning of the event. 
    594  * @param[in]   end_mark            The end of the event. 
    595  * 
    596  * @returns A new event object, or @c NULL on error. 
    597  */ 
    598  
    599 YAML_DECLARE(yaml_event_t *) 
    600 yaml_document_start_event_new(yaml_version_directive_t *version_directive, 
    601         yaml_tag_directive_t **tag_directives, int implicit, 
    602         yaml_mark_t start_mark, yaml_mark_t end_mark); 
    603  
    604 /** 
    605  * Create a new @c YAML_DOCUMENT_END_EVENT event. 
    606  * 
    607  * @param[in]   implicit    Is the document end indicator present? 
    608  * @param[in]   start_mark  The beginning of the event. 
    609  * @param[in]   end_mark    The end of the event. 
    610  * 
    611  * @returns A new event object, or @c NULL on error. 
    612  */ 
    613  
    614 YAML_DECLARE(yaml_event_t *) 
    615 yaml_document_end_event_new(int implicit, 
    616         yaml_mark_t start_mark, yaml_mark_t end_mark); 
    617  
    618 /** 
    619  * Create a new @c YAML_ALIAS_EVENT event. 
    620  * 
    621  * @param[in]   anchor      The anchor value. 
    622  * @param[in]   start_mark  The beginning of the event. 
    623  * @param[in]   end_mark    The end of the event. 
    624  * 
    625  * @returns A new event object, or @c NULL on error. 
    626  */ 
    627  
    628 YAML_DECLARE(yaml_event_t *) 
    629 yaml_alias_event_new(yaml_char_t *anchor, 
    630         yaml_mark_t start_mark, yaml_mark_t end_mark); 
    631  
    632 /** 
    633  * Create a new @c YAML_SCALAR_EVENT event. 
    634  * 
    635  * @param[in]   anchor          The anchor value or @c NULL. 
    636  * @param[in]   tag             The tag value or @c NULL. 
    637  * @param[in]   value           The scalar value. 
    638  * @param[in]   length          The length of the scalar value. 
    639  * @param[in]   plain_implicit  Is the tag optional for the plain style? 
    640  * @param[in]   quoted_implicit Is the tag optional for any non-plain style? 
    641  * @param[in]   style           The scalar style. 
    642  * @param[in]   start_mark      The beginning of the event. 
    643  * @param[in]   end_mark        The end of the event. 
    644  * 
    645  * @returns A new event object, or @c NULL on error. 
    646  */ 
    647  
    648 YAML_DECLARE(yaml_event_t *) 
    649 yaml_scalar_event_new(yaml_char_t *anchor, yaml_char_t *tag, 
    650         yaml_char_t *value, size_t length, 
    651         int plain_implicit, int quoted_implicit, 
    652         yaml_scalar_style_t style, 
    653         yaml_mark_t start_mark, yaml_mark_t end_mark); 
    654  
    655 /** 
    656  * Create a new @c YAML_SEQUENCE_START_EVENT event. 
    657  * 
    658  * @param[in]   anchor      The anchor value or @c NULL. 
    659  * @param[in]   tag         The tag value or @c NULL. 
    660  * @param[in]   implicit    Is the tag optional? 
    661  * @param[in]   style       The sequence style. 
    662  * @param[in]   start_mark  The beginning of the event. 
    663  * @param[in]   end_mark    The end of the event. 
    664  * 
    665  * @returns A new event object, or @c NULL on error. 
    666  */ 
    667  
    668 YAML_DECLARE(yaml_event_t *) 
    669 yaml_sequence_start_event_new(yaml_char_t *anchor, yaml_char_t *tag, 
    670         int implicit, yaml_sequence_style_t style, 
    671         yaml_mark_t start_mark, yaml_mark_t end_mark); 
    672  
    673 /** 
    674  * Create a new @c YAML_SEQUENCE_END_EVENT event. 
    675  * 
    676  * @param[in]   start_mark  The beginning of the event. 
    677  * @param[in]   end_mark    The end of the event. 
    678  * 
    679  * @returns A new event object, or @c NULL on error. 
    680  */ 
    681  
    682 YAML_DECLARE(yaml_event_t *) 
    683 yaml_sequence_end_event_new(yaml_mark_t start_mark, yaml_mark_t end_mark); 
    684  
    685 /** 
    686  * Create a new @c YAML_MAPPING_START_EVENT event. 
    687  * 
    688  * @param[in]   anchor      The anchor value or @c NULL. 
    689  * @param[in]   tag         The tag value or @c NULL. 
    690  * @param[in]   implicit    Is the tag optional? 
    691  * @param[in]   style       The mapping style. 
    692  * @param[in]   start_mark  The beginning of the event. 
    693  * @param[in]   end_mark    The end of the event. 
    694  * 
    695  * @returns A new event object, or @c NULL on error. 
    696  */ 
    697  
    698 YAML_DECLARE(yaml_event_t *) 
    699 yaml_mapping_start_event_new(yaml_char_t *anchor, yaml_char_t *tag, 
    700         int implicit, yaml_mapping_style_t style, 
    701         yaml_mark_t start_mark, yaml_mark_t end_mark); 
    702  
    703 /** 
    704  * Create a new @c YAML_MAPPING_END_EVENT event. 
    705  * 
    706  * @param[in]   start_mark  The beginning of the event. 
    707  * @param[in]   end_mark    The end of the event. 
    708  * 
    709  * @returns A new event object, or @c NULL on error. 
    710  */ 
    711  
    712 YAML_DECLARE(yaml_event_t *) 
    713 yaml_mapping_end_event_new(yaml_mark_t start_mark, yaml_mark_t end_mark); 
    714  
    715 /** 
    716  * Destroy an event object. 
     408 * Free any memory allocated for an event object. 
    717409 * 
    718410 * @param[in]   event   An event object. 
     
    751443 
    752444/** 
    753  * This structure holds a string input specified by 
    754  * @c yaml_parser_set_input_string. 
     445 * This structure holds information about a potential simple key. 
    755446 */ 
    756447 
    757448typedef struct { 
    758     /** The string start pointer. */ 
    759     unsigned char *start; 
    760  
    761     /** The string end pointer. */ 
    762     unsigned char *end; 
    763  
    764     /** The string current position. */ 
    765     unsigned char *current; 
    766 } yaml_string_input_t; 
    767  
    768 /** 
    769  * This structure holds information about a potential simple key. 
    770  */ 
    771  
    772 typedef struct { 
     449    /** Is a simple key possible? */ 
     450    int possible; 
     451 
    773452    /** Is a simple key required? */ 
    774453    int required; 
     
    776455    /** The number of the token. */ 
    777456    size_t token_number; 
    778  
    779     /** The position index. */ 
    780     size_t index; 
    781  
    782     /** The position line. */ 
    783     size_t line; 
    784  
    785     /** The position column. */ 
    786     size_t column; 
    787457 
    788458    /** The position mark. */ 
     
    794464 */ 
    795465typedef enum { 
    796     YAML_PARSE_END_STATE, 
    797466    YAML_PARSE_STREAM_START_STATE, 
    798467    YAML_PARSE_IMPLICIT_DOCUMENT_START_STATE, 
     
    817486    YAML_PARSE_FLOW_MAPPING_KEY_STATE, 
    818487    YAML_PARSE_FLOW_MAPPING_VALUE_STATE, 
    819     YAML_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE 
     488    YAML_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE, 
     489    YAML_PARSE_END_STATE 
    820490} yaml_parser_state_t; 
    821491 
     
    836506    /** Error type. */ 
    837507    yaml_error_type_t error; 
    838  
    839508    /** Error description. */ 
    840509    const char *problem; 
    841  
    842510    /** The byte about which the problem occured. */ 
    843511    size_t problem_offset; 
    844  
    845512    /** The problematic value (@c -1 is none). */ 
    846513    int problem_value; 
    847  
    848514    /** The problem position. */ 
    849515    yaml_mark_t problem_mark; 
    850  
    851516    /** The error context. */ 
    852517    const char *context; 
    853  
    854518    /** The context position. */ 
    855519    yaml_mark_t context_mark; 
     
    870534    void *read_handler_data; 
    871535 
     536    /** Standard (string or file) input data. */ 
     537    union { 
     538        /** String input data. */ 
     539        struct { 
     540            /** The string start pointer. */ 
     541            unsigned char *start; 
     542            /** The string end pointer. */ 
     543            unsigned char *end; 
     544            /** The string current position. */ 
     545            unsigned char *current; 
     546        } string; 
     547 
     548        /** File input data. */ 
     549        FILE *file; 
     550    } input; 
     551 
    872552    /** EOF flag */ 
    873553    int eof; 
    874554 
    875     /** The pointer to the beginning of the working buffer. */ 
    876     yaml_char_t *buffer; 
    877  
    878     /** The pointer to the end of the working buffer. */ 
    879     yaml_char_t *buffer_end; 
    880  
    881     /** The pointer to the current character in the working buffer. */ 
    882     yaml_char_t *pointer; 
    883  
    884     /** The number of unread characters in the working buffer. */ 
     555    /** The working buffer. */ 
     556    struct { 
     557        /* The beginning of the buffer. */ 
     558        yaml_char_t *start; 
     559        /* The end of the buffer. */ 
     560        yaml_char_t *end; 
     561        /* The current position of the buffer. */ 
     562        yaml_char_t *pointer; 
     563        /* The last filled position of the buffer. */ 
     564        yaml_char_t *last; 
     565    } buffer; 
     566 
     567    /* The number of unread characters in the buffer. */ 
    885568    size_t unread; 
    886569 
    887     /** The pointer to the beginning of the raw buffer. */ 
    888     unsigned char *raw_buffer; 
    889  
    890     /** The pointer to the current character in the raw buffer. */ 
    891     unsigned char *raw_pointer; 
    892  
    893     /** The number of unread bytes in the raw buffer. */ 
    894     size_t raw_unread; 
     570    /** The raw buffer. */ 
     571    struct { 
     572        /** The beginning of the buffer. */ 
     573        unsigned char *start; 
     574        /** The end of the buffer. */ 
     575        unsigned char *end; 
     576        /** The current position of the buffer. */ 
     577        unsigned char *pointer; 
     578        /** The last filled position of the buffer. */ 
     579        unsigned char *last; 
     580    } raw_buffer; 
    895581 
    896582    /** The input encoding. */ 
     
    900586    size_t offset; 
    901587 
    902     /** The index of the current position (in characters). */ 
    903     size_t index; 
    904  
    905     /** The line of the current position (starting from @c 0). */ 
    906     size_t line; 
    907  
    908     /** The column of the current position (starting from @c 0). */ 
    909     size_t column; 
    910  
    911     /* String input structure. */ 
    912     yaml_string_input_t string_input; 
     588    /** The mark of the current position. */ 
     589    yaml_mark_t mark; 
    913590 
    914591    /** 
     
    930607    int flow_level; 
    931608 
    932     /** The tokens queue, which contains the current produced tokens. */ 
    933     yaml_token_t **tokens; 
    934  
    935     /** The size of the tokens queue. */ 
    936     size_t tokens_size; 
    937  
    938     /** The head of the tokens queue. */ 
    939     size_t tokens_head; 
    940  
    941     /** The tail of the tokens queue. */ 
    942     size_t tokens_tail; 
    943  
    944     /** The number of tokens fetched from the tokens queue. */ 
     609    /** The tokens queue. */ 
     610    struct { 
     611        /** The beginning of the tokens queue. */ 
     612        yaml_token_t *start; 
     613        /** The end of the tokens queue. */ 
     614        yaml_token_t *end; 
     615        /** The head of the tokens queue. */ 
     616        yaml_token_t *head; 
     617        /** The tail of the tokens queue. */ 
     618        yaml_token_t *tail; 
     619    } tokens; 
     620 
     621    /** The number of tokens fetched from the queue. */ 
    945622    size_t tokens_parsed; 
    946623 
    947     /** The stack of indentation levels. */ 
    948     int *indents; 
    949  
    950     /** The size of the indents stack. */ 
    951     size_t indents_size; 
    952  
    953     /** The number of items in the indents stack. */ 
    954     size_t indents_length; 
     624    /* Does the tokens queue contain a token ready for dequeueing. */ 
     625    int token_available; 
     626 
     627    /** The indentation levels stack. */ 
     628    struct { 
     629        /** The beginning of the stack. */ 
     630        int *start; 
     631        /** The end of the stack. */ 
     632        int *end; 
     633        /** The top of the stack. */ 
     634        int *top; 
     635    } indents; 
    955636 
    956637    /** The current indentation level. */ 
     
    960641    int simple_key_allowed; 
    961642 
    962     /** The stack of potential simple keys. */ 
    963     yaml_simple_key_t **simple_keys; 
    964  
    965     /** The size of the simple keys stack. */ 
    966     size_t simple_keys_size; 
     643    /** The stack of simple keys. */ 
     644    struct { 
     645        /** The beginning of the stack. */ 
     646        yaml_simple_key_t *start; 
     647        /** The end of the stack. */ 
     648        yaml_simple_key_t *end; 
     649        /** The top of the stack. */ 
     650        yaml_simple_key_t *top; 
     651    } simple_keys; 
    967652 
    968653    /** 
     
    976661 
    977662    /** The parser states stack. */ 
    978     yaml_parser_state_t *states; 
    979  
    980     /** The size of the parser states stack. */ 
    981     size_t states_size; 
    982  
    983     /** The number of items in the parser states stack. */ 
    984     size_t states_length; 
     663    struct { 
     664        /** The beginning of the stack. */ 
     665        yaml_parser_state_t *start; 
     666        /** The end of the stack. */ 
     667        yaml_parser_state_t *end; 
     668        /** The top of the stack. */ 
     669        yaml_parser_state_t *top; 
     670    } states; 
    985671 
    986672    /** The current parser state. */ 
     
    988674 
    989675    /** The stack of marks. */ 
    990     yaml_mark_t *marks; 
    991  
    992     /** The size of the marks stack. */ 
    993     size_t marks_size; 
    994  
    995     /** The number of items in the marks stack. */ 
    996     size_t marks_length; 
    997  
    998     /** The current event. */ 
    999     yaml_event_t *current_event; 
    1000  
    1001     /** The YAML version directive. */ 
    1002     yaml_version_directive_t *version_directive; 
     676    struct { 
     677        /** The beginning of the stack. */ 
     678        yaml_mark_t *start; 
     679        /** The end of the stack. */ 
     680        yaml_mark_t *end; 
     681        /** The top of the stack. */ 
     682        yaml_mark_t *top; 
     683    } marks; 
    1003684 
    1004685    /** The list of TAG directives. */ 
    1005     yaml_tag_directive_t **tag_directives; 
    1006  
    1007     /** The size of the TAG directives list. */ 
    1008     size_t tag_directives_size; 
    1009  
    1010     /** The number of items in the TAG directives list. */ 
    1011     size_t tag_directives_length; 
     686    struct { 
     687        /** The beginning of the list. */ 
     688        yaml_tag_directive_t *start; 
     689        /** The end of the list. */ 
     690        yaml_tag_directive_t *end; 
     691        /** The top of the list. */ 
     692        yaml_tag_directive_t *top; 
     693    } tag_directives; 
    1012694 
    1013695    /** 
     
    1018700 
    1019701/** 
    1020  * Create a new parser. 
     702 * Initialize a parser. 
    1021703 * 
    1022704 * This function creates a new parser object.  An application is responsible 
    1023705 * for destroying the object using the @c yaml_parser_delete function. 
    1024706 * 
    1025  * @returns A new parser object; @c NULL on error. 
    1026  */ 
    1027  
    1028 YAML_DECLARE(yaml_parser_t *) 
    1029 yaml_parser_new(void); 
     707 * @param[in]   parser  An empty parser object. 
     708 * 
     709 * @returns #c 1 if the function succeeded, @c 0 on error. 
     710 */ 
     711 
     712YAML_DECLARE(int) 
     713yaml_parser_initialize(yaml_parser_t *parser); 
    1030714 
    1031715/** 
     
    1091775 
    1092776/** 
    1093  * Get the next token. 
    1094  * 
    1095  * The token is removed from the internal token queue and the application is 
    1096  * responsible for destroing the token object. 
     777 * Scan the input stream and produce the next token. 
     778 * 
     779 * Call the function subsequently to produce a sequence of tokens corresponding 
     780 * to the input stream.  The initial token has the type 
     781 * @c YAML_STREAM_START_TOKEN while the ending token has the type 
     782 * @c YAML_STREAM_END_TOKEN. 
     783 * 
     784 * An application is responsible for freeing any buffers associated with the 
     785 * produced token object using the @c yaml_token_delete function. 
     786 * 
     787 * An application must not alternate the calls of @c yaml_parser_scan with the 
     788 * calls of @c yaml_parser_parse. Doing this will break the parser. 
    1097789 * 
    1098790 * @param[in]   parser      A parser object. 
    1099  * 
    1100  * @returns A token object, or @c NULL on error. 
    1101  */ 
    1102  
    1103 YAML_DECLARE(yaml_token_t *) 
    1104 yaml_parser_get_token(yaml_parser_t *parser); 
    1105  
    1106 /** 
    1107  * Peek the next token. 
    1108  * 
    1109  * The token is not removed from the internal token queue and will be returned 
    1110  * again on a subsequent call of @c yaml_parser_get_token or 
    1111  * @c yaml_parser_peek_token. The application should not destroy the token 
    1112  * object. 
     791 * @param[in]   token       An empty token object. 
     792 * 
     793 * @returns @c 1 if the function succeeded, @c 0 on error. 
     794 */ 
     795 
     796YAML_DECLARE(int) 
     797yaml_parser_scan(yaml_parser_t *parser, yaml_token_t *token); 
     798 
     799/** 
     800 * Parse the input stream and produce the next parsing event. 
     801 * 
     802 * Call the function subsequently to produce a sequence of events corresponding 
     803 * to the input stream.  The initial event has the type 
     804 * @c YAML_STREAM_START_EVENT while the ending event has the type 
     805 * @c YAML_STREAM_END_EVENT. 
     806 * 
     807 * An application is responsible for freeing any buffers associated with the 
     808 * produced event object using the @c yaml_event_delete function. 
     809 * 
     810 * An application must not alternate the calls of @c yaml_parser_scan with the 
     811 * calls of @c yaml_parser_parse. Doing this will break the parser. 
    1113812 * 
    1114813 * @param[in]   parser      A parser object. 
    1115  * 
    1116  * @returns A token object, or @c NULL on error. 
    1117  */ 
    1118  
    1119 YAML_DECLARE(yaml_token_t *) 
    1120 yaml_parser_peek_token(yaml_parser_t *parser); 
    1121  
    1122 /** 
    1123  * Get the next event. 
    1124  * 
    1125  * The application is responsible for destroing the event object. 
    1126  * 
    1127  * @param[in]   parser      A parser object. 
    1128  * 
    1129  * @returns An event object, or @c NULL on error. 
    1130  */ 
    1131  
    1132 YAML_DECLARE(yaml_event_t *) 
    1133 yaml_parser_get_event(yaml_parser_t *parser); 
    1134  
    1135 /** 
    1136  * Peek the next event. 
    1137  * 
    1138  * The event will be returned again on a subsequent call of 
    1139  * @c yaml_parser_get_event or @c yaml_parser_peek_event.  The application 
    1140  * should not destroy the event object. 
    1141  * 
    1142  * @param[in]   parser      A parser object. 
    1143  * 
    1144  * @returns An event object, or @c NULL on error. 
    1145  */ 
    1146  
    1147 YAML_DECLARE(yaml_event_t *) 
    1148 yaml_parser_peek_event(yaml_parser_t *parser); 
     814 * @param[in]   event       An empty event object. 
     815 * 
     816 * @returns @c 1 if the function succeeded, @c 0 on error. 
     817 */ 
     818 
     819YAML_DECLARE(int) 
     820yaml_parser_parse(yaml_parser_t *parser, yaml_event_t *event); 
    1149821 
    1150822/** @} */ 
     
    1153825typedef struct { 
    1154826} yaml_emitter_t; 
     827 
     828YAML_DECLARE(int) 
     829yaml_emitter_emit(yaml_emitter_t *emitter, yaml_event_t *event); 
     830 
     831YAML_DECLARE(int) 
     832yaml_emitter_emit_stream_start(yaml_emitter_t *emitter, 
     833        yaml_encoding_t encoding); 
     834 
    1155835*/ 
    1156  
    1157 /** 
    1158  * @defgroup internal Internal Definitions 
    1159  * @{ 
    1160  */ 
    1161  
    1162 /** 
    1163  * Allocate a dynamic memory block. 
    1164  * 
    1165  * @param[in]   size    Size of a memory block, \c 0 is valid. 
    1166  * 
    1167  * @returns @c yaml_malloc returns a pointer to a newly allocated memory block, 
    1168  * or @c NULL if it failed. 
    1169  */ 
    1170  
    1171 YAML_DECLARE(void *) 
    1172 yaml_malloc(size_t size); 
    1173  
    1174 /** 
    1175  * Reallocate a dynamic memory block. 
    1176  * 
    1177  * @param[in]   ptr     A pointer to an existing memory block, \c NULL is 
    1178  *                      valid. 
    1179  * @param[in]   size    A size of a new block, \c 0 is valid. 
    1180  * 
    1181  * @returns @c yaml_realloc returns a pointer to a reallocated memory block, 
    1182  * or @c NULL if it failed. 
    1183  */ 
    1184  
    1185 YAML_DECLARE(void *) 
    1186 yaml_realloc(void *ptr, size_t size); 
    1187  
    1188 /** 
    1189  * Free a dynamic memory block. 
    1190  * 
    1191  * @param[in]   ptr     A pointer to an existing memory block, \c NULL is 
    1192  *                      valid. 
    1193  */ 
    1194  
    1195 YAML_DECLARE(void) 
    1196 yaml_free(void *ptr); 
    1197  
    1198 /** The initial size for various buffers. */ 
    1199  
    1200 #define YAML_DEFAULT_SIZE   16 
    1201  
    1202 /** The size of the raw buffer. */ 
    1203  
    1204 #define YAML_RAW_BUFFER_SIZE 16384 
    1205  
    1206 /** 
    1207  * The size of the buffer. 
    1208  * 
    1209  * We allocate enough space for decoding the whole raw buffer. 
    1210  */ 
    1211  
    1212 #define YAML_BUFFER_SIZE    (YAML_RAW_BUFFER_SIZE*3) 
    1213  
    1214 /** 
    1215  * Ensure that the buffer contains at least @a length characters. 
    1216  * 
    1217  * @param[in]   parser  A parser object. 
    1218  * @param[in]   length  The number of characters in the buffer. 
    1219  * 
    1220  * @returns @c 1 on success, @c 0 on error. 
    1221  */ 
    1222  
    1223 YAML_DECLARE(int) 
    1224 yaml_parser_update_buffer(yaml_parser_t *parser, size_t length); 
    1225  
    1226 /** @} */ 
    1227  
    1228836 
    1229837#ifdef __cplusplus 
Note: See TracChangeset for help on using the changeset viewer.