Giter Club home page Giter Club logo

edn-cpp's Introduction

edn-cpp

edn lib for c++.

##intro Useful for parsing edn. read returns an edn::EdnNode. There are three cases to consider:

  • If it is an atom (nil, symbol, keyword, bool, int, float, string, char) it will have a value property which is a string you can then cast/coerce how you please.

  • If it is a collection (list, map, vector, set) it will have a values property which is itself a list of edn::EdnNode items which you can then walk via what ever mechanism and do with them what you will.

  • If it is a tagged item you will have the raw tagname in the value property and then the values property will be a list containing the edn::EdnNode representing the tagname and another edn::EdnNode containing the value for the tag.

In general edn-cpp makes no assumptions about how you want to reify the data - it just guarantees you have well formed edn node(s) which you can handle how ever you like.

##using

#//define DEBUG
#include "edn.hpp"
#include <iostream>

using edn::EdnNode;
using edn::read;
using edn::pprint;

int main() {
	try {
		EdnNode someMap = read("{:some :map :with [a vector of symbols]}");
		std::cout << pprint(someMap) << std::endl;
	} catch (const char* e) {
		std::cout << "Error parsing: " << e << std::endl;
	}
}

will output:

{:some :map :with [a vector of symbols]}

And with debug uncommented:

<EdnMap {<EdnKeyword :some> <EdnKeyword :map> 
         <EdnKeyword :with> <EdnVector [<EdnSymbol a> 
                                        <EdnSymbol vector> 
                                        <EdnSymbol of> 
                                        <EdnSymbol symbols>]>}>

##debug If you define DEBUG you will see debug output when using pprint. This looks like:

<EdnMap {
  <EdnKeyword :x> <EdnKeyword :y> 
  <EdnKeyword :z> <EdnVector [<EdnInt 1> 
                              <EdnInt 2> 
                              <EdnInt 3> 
                              <EdnTagged #<EdnSymbol tagged/item> 
                                         <EdnString "cats-rabbits-bears">>]>}>

Which is nice when proving things are parsing as you expect.

##api list lex(string ednString)

EdnNode read(string ednString)

string pprint(EdnNode node)

bool validSymbol(string value)

bool validKeyword(string value)

bool validNil(string value)
	
bool validBool(string value)

bool validInt(string value)

bool validFloat(string value)

bool validChar(string value)

EdnNode handleAtom(EdnToken token)

EdnNode handleCollection(EdnToken token, list<EdnNode> values)

EdnNode handleTagged(EdnToken token, EdnNode value)

##structs EdnToken TokenType type int line string value

EdnNode
	EdnToken type
	int line
	string value         #used for atoms
	list<EdnNode> values #used for collections

##enums TokenType TokenString TokenAtom TokenParen

NodeType
	EdnNil
	EdnSymbol
	EdnKeyword
	EdnBool
	EdnInt
	EdnFloat
	EdnString
	EdnChar
	EdnList
	EdnVector
	EdnMap
	EdnSet
	EdnDiscard
	EdnTagged

##todo make pprint actually format as demonstrated above. Right now it is just a single string with out the indentation.

edn-cpp's People

Contributors

shaunxcode 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.