Giter Club home page Giter Club logo

yoml's Introduction

YOML - a DOM-like interface to YAML

YOML is a DOM-like interface to YAML, implemented as a wrapper around libyaml.

It is a header-only library. Just include the .h files to use the library.

#include "yoml.h" /* defines the structures */
#include "yoml-parser.h" /* defines the parser */

static yoml_t *parse_file(FILE *fp)
{
  yaml_parser_t parser;
  yoml_t *doc;

  yaml_parser_initialize(&parser);
  yaml_parser_set_input_file(&parser, fp);

  doc = yoml_parse_document(&parser, NULL);

  yaml_parser_delete(&parser);

  return doc;
}

static void dump_node(yoml_t *node, int indent)
{
  size_t i;

  switch (node->type) {
  case YOML_TYPE_SCALAR:
    printf("%*s[SCALAR] %s\n", indent, "", node->data.scalar);
    break;
  case YOML_TYPE_SEQUENCE:
    printf("%*s[SEQUENCE] (size:%zu)\n", indent, "", node->data.sequence.size);
    for (i = 0; i != node->data.sequence.size; ++i)
      dump_node(node->data.sequence.elements[i], indent + 2);
    break;
  case YOML_TYPE_MAPPING:
    printf("%*s[MAPPING] (size:%zu)\n", indent, "", node->data.mapping.size);
    indent += 2;
    for (i = 0; i != node->data.mapping.size; ++i) {
      printf("%*s[KEY]\n", indent, "");
      dump_node(node->data.mapping.elements[i].key, indent + 2);
      printf("%*s[VALUE]\n", indent, "");
      dump_node(node->data.mapping.elements[i].value, indent + 2);
    }
    indent -= 2;
    break;
  }
}

static void dump_file(FILE *fp)
{
  yoml_t *doc = parse_file(fp);

  if (doc == NULL) {
    fprintf(stderr, "parse error!\n"); /* error info can be obtained from yaml_parser_t */
    return;
  }

  dump_node(doc, 0);
  yoml_free(doc);
}

yoml's People

Contributors

kazuho avatar i110 avatar miyagawa avatar velavokr avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.