• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

README.mdH A D14-Dec-20203.1 KiB12988

edn-cpp.originH A D14-Dec-2020138 32

edn.hppH A D14-Dec-202012.1 KiB452373

example.cppH A D14-Dec-2020340 1714

repl.cppH A D14-Dec-2020558 2724

README.md

1edn-cpp
2=======
3
4edn lib for c++.
5
6##intro
7Useful for parsing [edn](http://github.com/edn-format/edn). read returns an `edn::EdnNode`. There are three cases to consider:
8
9* 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.
10
11* 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.
12
13* 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.
14
15In 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.
16
17
18##using
19
20	#//define DEBUG
21	#include "edn.hpp"
22	#include <iostream>
23
24	using edn::EdnNode;
25	using edn::read;
26	using edn::pprint;
27
28	int main() {
29		try {
30			EdnNode someMap = read("{:some :map :with [a vector of symbols]}");
31			std::cout << pprint(someMap) << std::endl;
32		} catch (const char* e) {
33			std::cout << "Error parsing: " << e << std::endl;
34		}
35	}
36
37will output:
38
39	{:some :map :with [a vector of symbols]}
40
41And with debug uncommented:
42
43	<EdnMap {<EdnKeyword :some> <EdnKeyword :map>
44	         <EdnKeyword :with> <EdnVector [<EdnSymbol a>
45	                                        <EdnSymbol vector>
46	                                        <EdnSymbol of>
47	                                        <EdnSymbol symbols>]>}>
48
49##debug
50If you define DEBUG you will see debug output when using pprint. This looks like:
51
52	<EdnMap {
53	  <EdnKeyword :x> <EdnKeyword :y>
54	  <EdnKeyword :z> <EdnVector [<EdnInt 1>
55	                              <EdnInt 2>
56	                              <EdnInt 3>
57	                              <EdnTagged #<EdnSymbol tagged/item>
58	                                         <EdnString "cats-rabbits-bears">>]>}>
59
60Which is nice when proving things are parsing as you expect.
61
62##api
63
64	list<EdnToken> lex(string ednString)
65
66	EdnNode read(string ednString)
67
68	string pprint(EdnNode node)
69
70	bool validSymbol(string value)
71
72	bool validKeyword(string value)
73
74	bool validNil(string value)
75
76	bool validBool(string value)
77
78	bool validInt(string value)
79
80	bool validFloat(string value)
81
82	bool validChar(string value)
83
84	EdnNode handleAtom(EdnToken token)
85
86	EdnNode handleCollection(EdnToken token, list<EdnNode> values)
87
88	EdnNode handleTagged(EdnToken token, EdnNode value)
89
90##structs
91
92	EdnToken
93		TokenType type
94		int line
95		string value
96
97	EdnNode
98		EdnToken type
99		int line
100		string value         #used for atoms
101		list<EdnNode> values #used for collections
102
103##enums
104
105	TokenType
106		TokenString
107		TokenAtom
108		TokenParen
109
110	NodeType
111		EdnNil
112		EdnSymbol
113		EdnKeyword
114		EdnBool
115		EdnInt
116		EdnFloat
117		EdnString
118		EdnChar
119		EdnList
120		EdnVector
121		EdnMap
122		EdnSet
123		EdnDiscard
124		EdnTagged
125
126
127##todo
128make pprint actually format as demonstrated above. Right now it is just a single string with out the indentation.
129