Git Product home page Git Product logo

nin-jin-tree.d's Introduction

Tree

Simple fast compact user-readable binary-safe extensible structural format.

Build Status

more - better JSON XML YAML INI Tree
Readability 3 1 4 5 5
Edit-friendly 3 1 4 5 5
Deep hierarchy 3 3 3 1 5
Simple to implement 3 2 1 5 5
Performance 3 1 1 5 5
Size 3 1 4 5 5
Streaming 0 0 5 5 5
Binary-safe 2 0 0 0 5
Universality 4 3 3 1 5
Prevalence 5 5 3 3 1
Text editors support 5 5 3 5 3
Languages support 4 5 3 5 2

Short description

Structural-nodes represents as names that can not contain [\s\n\\]. Example of structural nodes:

first-level second-level third-level
first-level
	first-of-second-level third-level
	second-of-second-level

Indents must use tabs, lines must use unix line ends.

Data-nodes represents as raw data between [\\] and [\n] characters. Example

\hello
\world
\
	\hello
	\world

In one line may be any count of structural-nodes, but only one data-node at the end.

article
	title \Hello world
	description
		\This is demo of tree-format
		\Cool! Is not it? :-)

Reference Implementation

Grammar using grammar.tree language

Tree based languages

More examples.

Online sandbox

Performances

IDE support

Other implementations

Similar formats

D API

Parsing

    string data = cast(string) read( "path/to/file.tree" ); // read from file
    Tree tree = new Tree( data , "http://example.org/source/uri" ); // parse to tree

Simple queries

    Tree userNames = tree.select( "user name" ); // returns name-nodes
    Tree userNamesValues = tree.select( "user name " ); // returns value-nodes

Node info

    string name = userNames[0].name; // get node name
    string stringValue = userNames[0].value; // get value as string with "\n" as delimiter
    uint intValue =  userNames[0].value!uint; // get value converted from string to another type

    Tree[] childs = tree.childs; // get child nodes array
    string baseUri = tree.baseUri; // get base uri like "http://example.org/source/uri"
    size_t row = tree.row; // get row in source stream
    size_t col = tree.col; // get column in source stream
    string uri = tree.uri; // get uri like "http://example.org/source/uri#3:2"

Nodes creation

	Tree values = Tree.Values( "foo\nbar" , [] );
	Tree name = Tree.Name( "name" , values );
	Tree list = Tree.List( [ name , name ] );
	Tree firstLineName = name.clone( [ name[0] );

Serialization

    string data = tree.toString(); // returns string representation of tree
    tree.pipe( stdout ); // prints tree to output buffer

Benchmarks

void main() {
	
	import std.datetime.stopwatch, std.json, jin.tree, std.stdio, std.file;
	
	string dataTree = cast(string) read( "formats/sample.tree" );
	string dataJson = cast(string) read( "formats/sample.json" );
	
	Tree tree;
	JSONValue json;
	
	void measureTree() {
    	tree = new Tree( dataTree , "formats/sample.tree" );
	}
	
	void measureJson() {
    	json = parseJSON( dataJson );
	}
	
	auto res = benchmark!( measureTree, measureJson )(100);
	
	res.writeln;
}
rdmd source/bench --build=release

Parse

jin.tree std.json
204 ms 372 ms

nin-jin-tree.d's People

Contributors

dunemaster avatar nin--jin avatar nin-jin avatar osv avatar

Stargazers

 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.