yamltree.h (2282B)
1 /* 2 3 Copyright (C) 2016, David "Davee" Morgan 4 5 Permission is hereby granted, free of charge, to any person obtaining a 6 copy of this software and associated documentation files (the "Software"), 7 to deal in the Software without restriction, including without limitation 8 the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 and/or sell copies of the Software, and to permit persons to whom the 10 Software is furnished to do so, subject to the following conditions: 11 12 The above copyright notice and this permission notice shall be included in 13 all copies or substantial portions of the Software. 14 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 DEALINGS IN THE SOFTWARE. 22 23 */ 24 25 #ifndef YAMLTREE_H 26 #define YAMLTREE_H 27 28 #include <vita-toolchain-public.h> 29 #include <stdio.h> 30 31 typedef enum 32 { 33 NODE_SCALAR, 34 NODE_MAPPING, 35 NODE_SEQUENCE 36 } yaml_node_type; 37 38 typedef struct 39 { 40 size_t line; 41 size_t column; 42 } yaml_position; 43 44 typedef struct 45 { 46 const char *value; 47 size_t len; 48 } yaml_scalar; 49 50 typedef struct 51 { 52 size_t count; 53 struct yaml_node **nodes; 54 } yaml_sequence; 55 56 typedef struct 57 { 58 struct yaml_node *lhs; 59 struct yaml_node *rhs; 60 } yaml_node_pair; 61 62 typedef struct 63 { 64 size_t count; 65 yaml_node_pair **pairs; 66 } yaml_mapping; 67 68 typedef struct yaml_node 69 { 70 yaml_position position; 71 yaml_node_type type; 72 union 73 { 74 yaml_scalar scalar; 75 yaml_mapping mapping; 76 yaml_sequence sequence; 77 } data; 78 } yaml_node; 79 80 typedef yaml_node yaml_document; 81 82 typedef struct 83 { 84 size_t count; 85 yaml_document **docs; 86 } yaml_tree; 87 88 typedef struct 89 { 90 char *problem; 91 } yaml_error; 92 93 VITA_TOOLCHAIN_PUBLIC yaml_tree *parse_yaml_stream(FILE *input, yaml_error *error); 94 VITA_TOOLCHAIN_PUBLIC void free_yaml_tree(yaml_tree *tree); 95 VITA_TOOLCHAIN_PUBLIC const char *node_type_str(yaml_node *node); 96 97 #endif // YAMLTREE_H