Coder Social home page Coder Social logo

texttree's Introduction

TextTree

TextTree is a grammar for describing very simple hierarchical text data and a C++ library that can load (but not yet save) such data.

The structure is simple. There is only one kind of node. Each node contains a text string and any number of child nodes. Thats all!

Examples

Dictionary

object(
  key1(value1)
  key2(value2)
  key3(value3))

Here object is a node with three children. The text of each child acts as the key and the child of the key contains the value.

Parenthesis are omitted be skipped after each value because they are empty anyway. The strings are written in unquoted style becase there are no spaces. Without these tricks it would look like this instead.

"object"(
  "key1"("value1"())
  "key2"("value2"())
  "key3"("value3"()))

Lists

list(10 20 30)

In this example list contains three child nodes. If we want to have a list of strings that may contain spaces just write like this instead:

list("value 1" "value 2" "value 3")

Grammar

elements = { node }
node     = text [ list ]
text     = unquoted | quoted
list     = '(' elements ')'
unquoted = ? any characters except space or parenthesis ?
quoted   = '"' ? any characters with \" or \\ as escapes ? '"'

Library

The library uses C++11 and intends to use modern C++ idioms.

The library contains a parser that generates events to a parser_delegate. The parser_delegate may be subclassed to create custom data structures or do streaming parsing. There is also one parser_delegate implementation called tree_builder that builds a hiearchy of node objects. tree_builder also comes with a few helper functions to make loading files really simple:

Example

#include <texttree/tree_builder.hpp>

tt::node_ptr node = tt::load_file("myfile.txt");

Building with CMake

If you use CMake and want to include the library in your code you can put the source code in your project tree (see Working with submodules to learn how to do it with Git) and write something like the following at proper places in your CMakeLists.txt

set(TEXTTREE_ROOT ...)                           # Path to TextTree root directory
add_subdirectory(${TEXTTREE_ROOT}/src)           # Run TextTree's CMake file
include_directories(${TEXTTREE_ROOT}/src)        # Path to headers
target_link_libraries(your_application texttree) # Link with texttree library

If you want to run the unit tests then you should build the root CMakeFile.txt instead. TextTree uses the Google testing framework which you must build separately. Then pass -DCMAKE_INCLUDE_PATH=path to gtest headers and -DCMAKE_LIBRARY_PATH=path to gtest libraries to cmake when generating the makefiles.

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.