Compare commits

..

436 Commits

Author SHA1 Message Date
beder 8d2c2ae3fb Closed branch new-api (since we're going to make it a separate repository).
The new API will now be found in the repository yaml-cpp.new-api
2012-05-19 15:03:29 -05:00
beder 39171cf060 Fixed explicitly qualifying iterator type for gcc 2012-05-14 22:18:46 -05:00
beder b20e0a5e54 Switched all new API runtime_error exceptions to exceptions that derive from YAML::Exception 2012-05-14 22:12:31 -05:00
beder cfb7d46246 Added test for BOOST_FOREACH on a map 2012-05-08 12:30:02 -05:00
beder adc0e7e7e9 Tweaked node iterator tests 2012-05-08 12:27:04 -05:00
beder bd9103f44a Added node iterator tests 2012-05-08 12:23:37 -05:00
beder 485afcb633 Added proper typedefs for BOOST_FOREACH to work 2012-05-08 12:20:28 -05:00
beder b1a1f8ce2d Patched signed -> unsigned warning (issue 98) 2012-02-14 10:11:44 -06:00
beder d50fbf59d7 Fixed warning about binary's shadowing members functions 2012-01-25 17:40:16 -06:00
beder 8d0ee05dbe Renamed append -> push_back (to play nice with STL algorithms 2012-01-21 12:11:40 -06:00
beder 5647711578 Added != for Binary 2012-01-21 02:02:24 -06:00
beder 2731f862a5 Added convert<> specialization for Binary 2012-01-21 01:54:54 -06:00
beder e17734de33 Renamed the base64 methods, and switched the EncodeBase64 one to return a string (to make it easy to use elsewhere) 2012-01-21 01:33:49 -06:00
beder b66197bdf4 Refactored the base64 binary to its own space with a unified class that (will) be used for parsing (in addition to emitting) 2012-01-21 01:18:37 -06:00
beder 41a7f7a026 Moved including boost headers to after the project's headers 2012-01-21 00:22:34 -06:00
beder 8d658bbf61 Patched for issue 142 for MSVC 2012-01-21 00:15:01 -06:00
beder b0b0c191b9 Flattened the src directory, and added back yaml.h (since it used to be generated) 2012-01-21 00:06:32 -06:00
beder 90f48fd035 Began new-api branch, and removed all traces of the old api from this branch 2012-01-20 23:36:08 -06:00
beder 9403ac04fa Fixed hex and oct emitting (it now adds the 0x or 0 prefix) 2012-01-13 00:00:11 -06:00
beder b266447d2e Added test for new API octal/hex conversion 2012-01-12 23:55:15 -06:00
beder 88540cc96a Fixed double -> int conversion (now throws) for old API 2012-01-12 23:52:51 -06:00
beder 60fa4d7f63 Updated new API conversion to handle nan/inf and to throw when the conversion didn't use the entire string (e.g., parsing 1.2 as an integer) 2012-01-12 23:49:05 -06:00
beder 924bb8b00e Added default parameters for the as<> function (new API) 2012-01-12 01:03:31 -06:00
beder f3446cbcea Added LoadFile and LoadAllFromFile (new API) 2012-01-11 21:31:01 -06:00
beder 2dbcc58912 Fixed bug in parsing escaped newline (it was being clipped like a regular newline) 2012-01-11 17:55:27 -06:00
beder 29859af6c0 Removed some extra stuff in the comment/newline in flow map tests, which really should be illegal (since implicit keys can't span multiple lines). It would be impossible to fix if we keep the immediate-output we're doing now - the only way to prevent it would be to hold on to a key's text until we got to the value token to make sure it could be an implicit key 2012-01-11 17:06:27 -06:00
beder e4838f0933 Fixed signed/unsigned mismatch with the new precision code 2012-01-11 16:50:06 -06:00
beder 8123b27c09 Added parsing emitter tests with the new API, two fail 2012-01-11 16:41:13 -06:00
beder 2d166d1733 Disallowed a plain scalar with just a dash 2012-01-11 16:39:24 -06:00
beder 8f948b8f37 Added float/double precision setters 2012-01-11 14:34:04 -06:00
beder 537063f907 Added explicit conversion from an iterator value to a Node. This conversion was always allowed (since the iterator value is derived from Node, but since Node has a templated constructor, that would take precedence over the derived-to-base conversion. This didn't seem to be a problem in gcc or clang, but MSVC seems to have trouble. (new API) 2012-01-11 13:58:18 -06:00
beder d2f5a6086a Added boost find/includes to the new API CMake instructions 2012-01-11 13:19:31 -06:00
beder c82122ba36 Fixed compiler error in iterator_base friend forward declaration in node on clang (and I hope MSVC), plus warnings on clang 2012-01-07 01:42:21 -06:00
beder 569a0461f2 Fixed assignment with an empty node (new API) - a segfault that only showed up in debuggable 2011-12-20 22:19:54 -06:00
beder 66980da9d2 Added overload for emitting unsigned char 2011-11-14 17:00:28 -06:00
beder c6e5ad350b Added single character emitting 2011-11-14 16:23:14 -06:00
beder fe5fcbb84e Added missing includes (iostream) for the tests 2011-11-13 16:12:39 -06:00
beder c4b3b5e52e Added (unspecified-type) bool conversions for Node (new API) 2011-11-13 16:05:42 -06:00
beder 50b6a02907 Set the default operator >> to not compile unless there is a scalar conversion, so it doesn't interfere with user-defined types 2011-11-01 17:19:03 -05:00
beder a853a7a14d Fixed emitter bug with colon at the end of a scalar in a flow collection 2011-10-31 19:16:17 -05:00
beder e4e410af5b Switched the utf bom checking to putback in the stream (instead of keeping a secondary buffer), which fixes a bug when there's only one ascii character 2011-10-20 22:29:41 -05:00
beder df9bcd5f12 Fixed typo in computing private headers (no effect on the build, just for the project files) 2011-10-20 21:50:47 -05:00
beder a6961e8dae Added parser test for single char input (that fails) 2011-10-20 13:53:27 -05:00
beder b204169c65 Fixed broken includes when using the old api 2011-10-18 15:13:10 -05:00
beder b9a708d5b3 Fixed installation (we now install the whole include header tree) 2011-10-18 14:55:31 -05:00
beder 692347fd97 Added a .hgignore file that ignores the generated yaml.h 2011-10-18 14:48:07 -05:00
beder 488c3d6cef Fixed the #ifdefs for the api stuff 2011-10-18 14:47:35 -05:00
beder 075f8449f8 Couldn't get the copy command to work for yaml.h, so switched to configure_file 2011-10-18 14:43:48 -05:00
beder 482c0afe2f Split the yaml.h file into new/old API, which we'll then copy to yaml.h at build time (so the right one gets installed) 2011-10-18 00:16:51 -05:00
beder 3663d5f24b Merged with the main branch, which just updated version count to 0.2.7 2011-09-18 00:26:18 -05:00
beder 0db8182839 Updated old api spectests with common spec examples 2011-09-17 23:57:40 -05:00
beder 0c50a9d861 Set the default build to the old API, and removed the duplicate spec test implementation for the old api 2011-09-17 23:46:48 -05:00
beder 4260b3460f Moved conversion.cpp to the old api, where it belongs 2011-09-14 01:49:06 -05:00
beder 36086448d2 Added bool conversions 2011-09-14 01:48:36 -05:00
beder f21c96188d Added tag release-0.2.7 for changeset d0bed6918076 2011-09-14 01:23:25 -05:00
beder 138b2f4733 Bumped version to 0.2.7 2011-09-14 01:23:15 -05:00
beder 4e6418ff12 Added Dump() 2011-09-13 14:49:00 -05:00
beder 0a1022a526 Added tags to Node emitter output 2011-09-13 14:47:33 -05:00
beder 2798b20b31 Finished adding old spec tests 2011-09-13 14:31:00 -05:00
beder 183ba98d03 Switched YAML::Parse to YAML::Load, and added LoadAll 2011-09-13 14:24:47 -05:00
beder d899562ba1 Added 7.x and 8.x tests with tags - all that's left is multiple docs in stream 2011-09-13 14:20:32 -05:00
beder de3377459a Added 6.x tests with tags 2011-09-13 14:18:00 -05:00
beder c314860e00 Added IsNull, IsScalar, IsSequence, IsMap functions, so you don't have to query Type() 2011-09-13 14:10:27 -05:00
beder d2a10e3d53 Copied 2.x tests with tags 2011-09-13 14:07:22 -05:00
beder 8dcd96dbd2 Added tags to Node 2011-09-13 14:00:47 -05:00
beder 535f81a387 Added a convert<> specialization for YAML::_Null (so you can say node[YAML::Null]) 2011-09-13 02:03:56 -05:00
beder e61826e5a2 Copied over the 8.x tests that don't have tags 2011-09-13 01:56:44 -05:00
beder 367d2f9112 Copied over the 7.x tests that don't have tags 2011-09-13 01:46:42 -05:00
beder 4e90ee6201 Copied over the 6.x tests that don't have tags 2011-09-13 01:36:27 -05:00
beder cec996ef81 Copied over the 5.x tests 2011-09-13 01:28:32 -05:00
beder ef892a15b7 Copied over all the 2.x tests that are (a) single doc and (b) don't have tags 2011-09-13 01:23:30 -05:00
beder 7f283a3a38 Factored out spec examples, and sketched skeleton for spec tests for new API 2011-09-12 22:55:37 -05:00
beder 2b6f31dd0d Added temp variable tests 2011-09-12 22:09:16 -05:00
beder 78ebd14551 Switched Node::operator=(const Node&) to *not* force itself to create its node first (since we're just assigning them) 2011-09-12 22:05:43 -05:00
beder 04152dae8f Switched the node_ref to *always* create its data (since now the Node itself doesn't always create itself) 2011-09-12 22:03:11 -05:00
beder 14955a2a63 Set the pimpl node in Node to be optional, so we don't create unnecessary guys every time you call Node tmp = foo[value]; 2011-09-12 21:59:47 -05:00
beder a2aa5a2f75 Fixed NodeBuilder bug when an alias was in a map - we weren't pushing that guy as a key 2011-09-12 14:24:27 -05:00
beder b8cc21eb3c Fixed new API node key/value insertion in NodeBuilder (it was using the wrong condition on when it had added a key already) 2011-09-12 13:25:41 -05:00
beder ad95934844 Added failing self-reference tests 2011-09-12 12:48:51 -05:00
beder 95f763f466 Added two alias tests 2011-09-12 12:42:23 -05:00
beder f38e38df09 Implemented std::map decode (and fixed bug in the Node iterator - the reference_type should be just a plain value, since it's created on-the-fly) 2011-09-12 00:29:39 -05:00
beder cf240daf63 Added reading/writing std::list 2011-09-11 23:18:19 -05:00
beder 2a71e8868b Added reading/writing std::vector 2011-09-11 23:14:52 -05:00
beder cf5695e320 Removed the (unimplemented) operator <, and added operator == (in place of is()) for nodes 2011-09-11 22:56:04 -05:00
beder 30ce282198 Added mutable operator[] for integral types (you can only grow the sequence if you specify the *next* element) 2011-09-11 22:51:49 -05:00
beder 4dd9f036d3 Implemented operator[] specialization, but only const (should the sequence be mutable?) 2011-09-11 21:51:04 -05:00
beder e8210b476c Started specialization for operator[] for integers 2011-09-11 21:32:47 -05:00
beder d8955fc52c Set the map iterator to filter over undefined items 2011-09-11 19:44:27 -05:00
beder d4e5a3ea93 Added failing map iterator count test 2011-09-11 17:36:08 -05:00
beder c8fc3c9592 Implemented the map size computation 2011-09-11 17:16:26 -05:00
beder 9c6bd61398 Switched the implementation of maps from list<pair> to map (but just pointer comparison) 2011-09-11 16:56:38 -05:00
beder ad28ffc6f8 Added computing and caching the sequence size 2011-09-11 16:21:36 -05:00
beder 73a47d1c1c Added some small map tests 2011-09-11 16:02:31 -05:00
beder bb1a816a3a Added dependency management (to cause nodes to become defined if their children do) 2011-09-11 15:59:53 -05:00
beder a9914342e0 Added a few simple node tests, and the sequence one doesn't pass (let's work now) 2011-09-10 23:31:12 -05:00
beder 10d712d060 Started Node tests (for the new API Node) 2011-09-10 23:22:30 -05:00
beder 4bbe984bdc Fixed up the old API stuff, and removed the util/value (since it's no longer needed) 2011-09-10 23:11:28 -05:00
beder fb538c9490 Set up util/parse for the new API 2011-09-10 23:03:02 -05:00
beder 2851f5f8c9 Fixed minor things that used the old API, compiles/links/runs\! 2011-09-10 22:59:27 -05:00
beder 24c55b434a Added stubs for spec and parser tests with the new API 2011-09-10 18:05:35 -05:00
beder 7cdf684ae6 Moved old api tests to subfolder 2011-09-10 18:02:07 -05:00
beder e905b74232 Major switch from Value -> Node. The library compiles with the new API, but tests are still oldies, and don't compile 2011-09-10 17:57:23 -05:00
beder 8fd372b0db Start of moving Value -> Node and Node -> old API Node (with a #define toggle) 2011-09-10 17:18:15 -05:00
beder 33a71151ca Added helper emitter functions, but we have a problem: YAML::Value is already a manipulator 2011-09-10 16:50:44 -05:00
beder 59ce694ca3 Implemented value events emitter 2011-09-10 16:23:18 -05:00
beder b3086ac260 Fixed node iterator 2011-09-10 14:36:10 -05:00
beder c12a03473e New iterators work\! 2011-09-10 14:16:50 -05:00
beder 89f87d855d Updated the node/value classes with the new iterators, they compile until we try to instantiate anything 2011-09-10 14:11:42 -05:00
beder 81243c87d4 Finished the main iterator stuff, now have to hook it to the nodes/values 2011-09-10 14:06:49 -05:00
beder f809206baa Halfway towards factoring out a node_iterator, and then building iterator on top of it 2011-09-10 13:20:22 -05:00
beder dcf9309ea8 Started emitting events for Values 2011-09-10 12:42:42 -05:00
beder b8e9b52af7 Implemented sugar Parse() functions 2011-09-09 23:40:19 -05:00
beder 8185fa48f1 Implemented (untested) the value builder 2011-09-09 23:28:21 -05:00
beder 91a3f020ff Map iterator works\! 2011-09-09 19:25:11 -05:00
beder f0ae0254d4 Sequence iterator works\! 2011-09-09 19:22:17 -05:00
beder b35a332fdd Switched iterators to typedef's, with a bit of finagling so we can forward-declare them 2011-09-09 19:07:37 -05:00
beder f60fb95ab6 Base iterator stuff compiles :) 2011-09-09 18:46:37 -05:00
beder 9de9ac7e7e Started writing new iterators 2011-09-09 16:17:59 -05:00
beder 603c726811 Made the 'data' member optional in node_ref - it's only created on-demand, so we don't waste extra memory every time we do Value tmp = v; 2011-09-09 14:26:55 -05:00
beder 8e52497d96 Switched value = otherValue to assign the actual nodes after setting the reference (so that tmp = foo['bar']; tmp = other; is the same as foo['bar'] = other;) 2011-09-09 14:02:18 -05:00
beder 7a1e47e03f Added append() 2011-09-09 02:51:35 -05:00
beder 255a392eb9 Switched operator[] access to node reference equality, not node equality 2011-09-09 02:39:36 -05:00
beder e32b3cd93f Switched memory to using shared nodes, and node_data to keep only naked node pointers, not shared nodes (to break the cycle, and we don't need weak pointers because their memory is guaranteed to exist, via 'memory') 2011-09-09 02:29:17 -05:00
beder 37cd3bd53c Added half of the std::map conversion (we don't have reading from Values yet) 2011-09-08 02:10:04 -05:00
beder c080478444 Added back the streamable conversions 2011-09-08 02:05:03 -05:00
beder bb2eafc387 Switched convert to a templated struct that can be specialized (so we can partially specialize it) 2011-09-08 02:02:15 -05:00
beder 21fbb461c0 Added streamable conversions 2011-09-08 00:48:40 -05:00
beder 3b0cc619b2 Implemented conversion for std::string, including a bypass-accessor to the scalar value 2011-09-07 15:49:01 -05:00
beder a9c7f8cc5a Set the 'memory' to only store node_refs, not nodes 2011-09-07 14:56:04 -05:00
beder 82fa4e71db Implemented is() 2011-09-07 14:46:25 -05:00
beder 980fb59d4b Added (another) layer - now 'node_ref' is between node and node_data, and it decrees whether nodes are identical 2011-09-07 14:44:18 -05:00
beder 75f3a36547 Implemented map get(), and it would work (I think) if we implemented convert() for strings 2011-09-07 03:36:50 -05:00
beder 2d75a631e2 Set up map searching by templated key 2011-09-07 03:21:24 -05:00
beder 7a3f425720 Reorganized so that we don't have cyclic include problems 2011-09-07 02:59:58 -05:00
beder 6fa53f9714 Implemented map access by already-existing node 2011-09-07 02:39:59 -05:00
beder a07642f156 Started implementing node_data 2011-09-07 00:45:28 -05:00
beder 555cfae28d Compiles/links assignment to string 2011-09-07 00:20:23 -05:00
beder 74ffe6a61b Value stuff compiles/links with lots of placeholder functions 2011-09-07 00:12:24 -05:00
beder 57617cc5cc Sketched more of the implementation 2011-09-06 23:11:38 -05:00
beder 40605b78c7 Moved the value header to its own subfolder 2011-09-06 16:06:46 -05:00
beder 1d7e6a6589 Sketched out interface for YAML::Value 2011-09-06 01:43:15 -05:00
beder d6811c42a8 Merged from trunk 2011-09-06 01:10:27 -05:00
beder ae14042031 Added notes about the two failing tests - that they're (I think) bugs in the YAML spec 2011-09-06 01:05:14 -05:00
beder 126dfdb155 Switched YAML::Binary interface to use unsigned chars, not chars 2011-09-06 00:39:31 -05:00
beder a8fdb1718d Added overload for operator [] for char * (non-const version) 2011-09-06 00:32:53 -05:00
beder ec3a9ecbf0 Fixed empty string emitter bug (it now with auto-quote it 2011-09-06 00:24:10 -05:00
beder ced351dec8 Switched the 'pragma once' to only happen on MSVC, or gcc >= 3.4 (it was causing trouble on the sun compiler) 2011-09-06 00:16:03 -05:00
beder f56d453050 Added api sketch 2011-09-04 19:50:08 -05:00
beder 44bee0b8ad Added .hgeol for native eols 2011-08-24 02:59:58 -05:00
convert-repo 301db885ea update tags 2011-08-24 13:44:56 +00:00
jbeder b5eaeac0b0 Removed ATOMIC_TYPE, an old enum that wasn't used any more 2011-08-22 21:37:51 +00:00
jbeder 088401fa88 Added test for anchor/alias in flow 2011-08-04 21:50:04 +00:00
jbeder a1fc9d8d88 Forced a newline after any comments 2011-08-04 21:47:57 +00:00
jbeder dae85e28e2 Included <cstddef> for NULL 2011-08-04 18:47:37 +00:00
jbeder 7f9aa35edb Fixed negative infinity parsing 2011-07-10 18:29:44 +00:00
jbeder 9ec2b96b19 Added parsing .inf and .nan (and friend) 2011-07-10 16:27:40 +00:00
jbeder ede50424ef Fixed includedir for the .pc.cmake file 2011-05-29 02:17:49 +00:00
jbeder ee446d00ea Added emitting std::set (and refactored the stl emitters a bit) 2011-05-18 21:07:25 +00:00
jbeder f7bee99fa3 Added include <cstdlib> for using 'NULL' (apparently gcc 4.6 is more strict) 2011-05-03 21:55:49 +00:00
jbeder 2402c4d7e9 Set version to 0.2.6 2011-03-30 01:33:02 +00:00
jbeder 95d05dcfa5 Switched project label to use 'nicer' suffix (e.g., md instead of /MD) 2011-03-21 23:03:01 +00:00
jbeder e468dd7d38 Added eol-style=native prop to missing files 2011-03-17 02:06:10 +00:00
jbeder e1f27488d1 Fixed mixed line endings 2011-03-17 02:04:34 +00:00
jbeder 509ba0d640 Marked Parser, Emitter, Node, Iterator, Mark, and Null for exporting to a DLL. It appears to work properly, although VS gives me lots of warning C4251 since I didn't export all data members of each of the above classes.
It seems that it's not necessary to export those members (as long as you can't access them), and most of them are STL instances, which apparently cause lots of problems for DLLs. (For example, you simply can't export instances of std::map; see http://support.microsoft.com/kb/168958.)
2011-03-16 02:31:30 +00:00
jbeder 4941d8ff75 Set eol-style to native for all sources 2011-03-16 01:13:41 +00:00
jbeder d1221b4456 Added option to disable compilation of contrib code 2011-03-16 01:10:57 +00:00
jbeder 9d83747162 Removed comparison/implicit conversion operators for Node, and renamed Node::Read<T>() to Node::to<T>() 2011-03-15 05:49:56 +00:00
jbeder 2ad6f06df5 Added newline at the end 2011-03-10 00:23:15 +00:00
jbeder 0f0bd2bf2d Updated for error in spec test 2011-03-04 04:19:34 +00:00
jbeder ddfbad6c7f Added spec tests through chapter 8, all new ones pass except 8.21, which I think is wrong 2011-03-04 04:14:08 +00:00
jbeder 1132c8df21 Fixed folding bug (detecting indentation, example 8.2), and clipping/stripping empty strings (example 8.6) 2011-03-04 02:26:59 +00:00
jbeder cee0974abd Refactored parse.cpp so that VS doesn't complain, added MinSizeRel build setting, and fixed numbering in the spec tests 2011-03-03 20:01:32 +00:00
jbeder 5b1ca74376 Added explicit doc start/end tokens for the emitter, and set it so that if you try to write after you've already written a full doc, it writes a doc start and continues 2011-03-03 09:26:12 +00:00
jbeder 77d20873dc Removed the default --- at the start of all emitter output 2011-03-03 08:57:00 +00:00
jbeder f5b09d3ec6 Switched the scanner list of owned indent markers to a ptr_vector 2011-03-03 08:34:30 +00:00
jbeder 06eae35c31 Switched the emitter state's stack of groups to a ptr_stack 2011-03-03 08:11:14 +00:00
jbeder bbb19cf5c0 Added parsing of output to emitter tests 2011-03-03 08:04:30 +00:00
jbeder bf2bb91dc6 Compressed the sequence-of-maps emitting (got rid of the unnecessary newline) - issue 61 2011-03-03 03:37:54 +00:00
jbeder 9419d411f8 Set the precision of emitting float/double to 15 2011-03-03 02:38:35 +00:00
jbeder 6f7995d27e Merged r444:449 from the node refactoring branch to the trunk 2011-03-03 00:19:26 +00:00
jbeder e6c1007043 Tiny formatting change in CMake file 2011-03-02 21:09:38 +00:00
jbeder f1f983764f Removed the old, unsupported Visual Studio files (just build with CMake) 2011-03-02 21:03:03 +00:00
jbeder 152e48f0d0 Prettied up the bool formatting code 2011-03-02 20:59:39 +00:00
jbeder 396e3309de Refactored bool emitting to make it 1) correct for the short bool form and 2) not barf on early versions of VS 2011-03-02 20:55:05 +00:00
jbeder c6e085524a Included 'mark.h' in the graphbuilder so that its method for removing the unused param warning (casting to void) compiles on VS 2011-03-02 20:30:54 +00:00
jbeder 142a4bca9b Flipped the include guard and the pragma, and don't use the pragma for early versions of gcc (< 3.4) 2011-03-02 06:11:41 +00:00
jbeder f4d2f11d2c Small changes to eliminate compiler warnings for 'nite' in issue 83 2011-03-02 05:29:46 +00:00
jbeder fb3b491734 Moved the local structs from Emitter::Write(bool) to an anonymous namespace in the hopes that Visual Studio <= 2003 will be happy 2011-03-02 05:21:25 +00:00
jbeder 357cd1e122 Fixed 'long long' error in VS 2002, issue 90 2011-03-02 05:15:36 +00:00
jbeder 898d29d9b7 Merged the debuggable branch's CMakeLists.txt (and added a build for RelWithDebInfo) - note that the options are only for gcc 2011-03-02 05:02:01 +00:00
jbeder 7b6e87277d Merged contrib folders from the graphbuilder-api branch, including the recursive search in CMakeLists.txt 2011-03-02 04:48:04 +00:00
jbeder 0823af5369 Merged CMakeLists.txt from issue 87 - now it's cleaner, and supports Windows much better 2011-03-02 04:37:55 +00:00
jbeder 3192d29e66 Switched exception constants to const char * const (from const std::string) so we don't have to construct them all in every translation unit, and switched the exception class to derive from std::runtime_error (so it handles what() for us) 2011-03-02 04:12:57 +00:00
jbeder 3f6254822d Included cstddef to stream.h 2011-02-05 22:28:08 +00:00
jbeder 9e345650e1 Added Anchor() regex (so that we're not just using Alphanumeric to match anchors), but it's still not 100% right (it shouldn't allow non-printable characters, e.g.). Also fixed a test that was broken along these lines (if a colon immediately follows an anchor, it's part of the anchor) 2011-01-31 17:47:20 +00:00
jbeder 7fd040c311 Fixed emitting colon at end of scalar bug 2010-12-03 21:52:04 +00:00
jbeder 6f6e096316 Added long long types to the emitter 2010-11-15 01:46:33 +00:00
jbeder 6e06857bf9 Updated Visual Studio project file. 2010-11-09 19:59:25 +00:00
jbeder 8c913c8ce4 Refactored tags so we can emit secondary tags (and named local tags) 2010-10-28 23:06:16 +00:00
jbeder 24dc58b68d Implemented binary emitting without the binary tag 2010-10-28 21:53:54 +00:00
jbeder d6e56a0941 Refactored emitter so that it emits the : for an implicit key right away 2010-10-22 04:19:01 +00:00
jbeder cb8eee46f0 Added more tests for the newline, and disallowed newlines after implicit block keys 2010-10-22 03:53:33 +00:00
jbeder 59745a4cff Added YAML::Newline manipulator for the emitter 2010-10-21 22:02:29 +00:00
jbeder 7bad58ba47 Merged the extra tests from other-tags into the trunk (forgot last commit) 2010-10-19 06:51:54 +00:00
jbeder 973ce78fe1 Merged the other-tags branch into the trunk (this wasn't an rX:Y merge, since the branch wasn't branched directly from the head of the trunk) 2010-10-19 06:46:55 +00:00
jbeder 59d126f5b0 Updated CMake iPhone settings 2010-10-18 21:35:34 +00:00
jbeder 2d3722db85 Made emitter noncopyable, which should fix any auto_ptr warnings 2010-10-18 07:24:42 +00:00
jbeder 91944e4538 Fixed the rest of the includes to explicitly state yaml-cpp/ 2010-10-18 07:22:53 +00:00
jbeder 7e511c41ad Forgot to add the new header location to the project (not important for compiling, but it is for the various generators) 2010-10-18 07:09:07 +00:00
jbeder 2a256f2870 Moved all the includes to a subfolder yaml-cpp so they don't interfere with other libraries' includes 2010-10-18 07:05:53 +00:00
jbeder 12d2beda29 Merged r366:387 from the jbeder-event-api branch 2010-10-18 06:45:03 +00:00
jbeder 78db8b02c8 Fixed missing header 2010-05-01 20:05:15 +00:00
jbeder d99cb95d2d Tagged version 0.2.5 2010-03-15 19:25:02 +00:00
jbeder 11903da3fb Added overloads for parsing stl maps and vectors 2010-03-15 04:25:17 +00:00
jbeder e58f0f31b7 Set alias nodes to return the tag of their anchor 2010-03-15 04:10:36 +00:00
jbeder 8080400cb6 Disabled those warnings in the release version of the .svn too. 2010-03-03 05:33:07 +00:00
jbeder b869aab8e1 Updated to remove most of the warnings in Visual Studio. (There's still the one about all control paths returning a value left.) Fixed one warning (when an istream converts to void * to then convert to bool), and disabled three. 2010-03-03 05:30:06 +00:00
jbeder 3720ceb57b Added newline to install and license files 2009-12-21 20:35:27 +00:00
jbeder 6d37c370ba Added missing include 2009-12-02 05:59:18 +00:00
jbeder ac3d95f499 Added test for duplicate key 2009-12-02 01:29:16 +00:00
jbeder f4b81e7349 Fixed leak when adding duplicate keys (and actually changed the behavior - now we take the first instance, not the last) 2009-12-02 01:01:45 +00:00
jbeder 8f0f0d62a7 Refactored emitter operator << overloads to not template them, so it's easier to overload for pointer types 2009-11-17 20:21:22 +00:00
jbeder bbf510d6cc Refactored the traits a bit, and added displaying the key to string and numeric key not found errors 2009-11-12 17:00:12 +00:00
jbeder 7b33c7c4b4 Small bug from switching static initialized regexes to lazy ones 2009-11-12 05:45:47 +00:00
jbeder 63cc5adefd Replaced conversion macros with SFINAE 2009-11-10 21:23:52 +00:00
jbeder 71489e5abf Overloaded more integral types for emitting 2009-11-06 03:24:12 +00:00
jbeder 472bb80c9c Fixed the return value of the integral conversion functions, and also unset the dec flag so it reads other bases (just a temporary fix, since we're officially supposed to read binary too) 2009-11-06 03:13:54 +00:00
jbeder ca79c3da7f Switched the Exp:: regexes to functions that lazily evaluate their regexes 2009-11-04 22:56:59 +00:00
jbeder fea35e3e8f Fixed silly bug in node cloning 2009-10-30 20:29:14 +00:00
jbeder a55970c879 Added some block scalar tests (with errors) 2009-10-30 18:16:26 +00:00
jbeder 4dd1b19e51 Updated the Visual Studio solution for the new files/renaming. 2009-10-30 04:52:13 +00:00
jbeder b1f143cfaf Fixed bug with block maps with null value (the next key was being read as the value) 2009-10-30 01:06:19 +00:00
jbeder c3f222e4d9 Fixed the whitespace tracking when we escape a newline in a double-quoted string 2009-10-29 22:55:50 +00:00
jbeder e8beb6c98f Fixed mistake in test 2009-10-29 22:39:53 +00:00
jbeder 08ac48518f Refactored the compact map notation, which made it easy to implement explicit keys for compact maps 2009-10-29 22:09:50 +00:00
jbeder 7c4a8dad85 Added case for parsing a compact key: value pair in a flow sequence with a null key 2009-10-29 22:01:01 +00:00
jbeder 011a608b5a Implemented adjacent key:value pairs when the key is JSON-like 2009-10-29 21:05:48 +00:00
jbeder 72dceba671 Added test 2009-10-29 20:45:20 +00:00
jbeder 5618157a1e Added flow collection tests 2009-10-29 20:35:07 +00:00
jbeder 72413bafd4 Added ability to read compact maps in a flow sequence 2009-10-29 19:41:46 +00:00
jbeder cccbddb54c Merged r295:305 from the tags branch to the trunk 2009-10-29 15:48:06 +00:00
jbeder 4f74f805c2 Removed crt stuff (we can do memory leak checking in Linux easier) 2009-10-27 14:55:01 +00:00
jbeder 3d24383686 Removed unused test yaml file 2009-10-27 14:48:01 +00:00
jbeder 5986307b8e Now actually removed yaml-reader 2009-10-27 14:47:08 +00:00
jbeder d3b00fa6c5 Reverted yaml-reader name change 2009-10-27 14:45:14 +00:00
jbeder 50b026a3a9 Renamed yaml-reader test (try 2) 2009-10-27 14:39:48 +00:00
jbeder 7d5988401e Renamed yaml-reader test 2009-10-27 14:38:53 +00:00
jbeder 47628bf25e Tagged version 0.2.4 2009-10-25 20:27:31 +00:00
jbeder 52e3e0a4aa Updated the CMake globbing so it only compiles sources starting with a lowercase letter (apparently Mac OS auto-generates files looking like ._whatever and it was trying to compile those too) 2009-10-25 18:01:48 +00:00
jbeder 770466d5d4 Tagged version 0.2.3 2009-10-22 21:55:44 +00:00
jbeder 9ee348d62e Small refactoring 2009-10-22 21:51:32 +00:00
jbeder 2b2fca758c Switch to flow map when emitting an empty block map 2009-10-22 14:21:12 +00:00
jbeder 2022379cf4 Switch to flow sequence when emitting an empty sequence 2009-10-22 14:17:12 +00:00
jbeder 68df40c1dc Fixed bug in plain scalar folding 2009-10-20 14:47:16 +00:00
jbeder 0bf5b133e1 Added a bunch of tests, simplified the testing code 2009-10-20 14:43:24 +00:00
jbeder 9a28c9178e Merged r270:HEAD of the emitting-unicode branch 2009-10-19 23:31:11 +00:00
jbeder ae937a31d2 Fixed little bug in parser commit 2009-10-19 22:42:30 +00:00
jbeder afc7c1088d Added default constructor to Parser, and cleaned it up a bit 2009-10-19 22:40:46 +00:00
jbeder dd29c8181a Update CMakeLists.txt to append, not overwrite CMAKE_CXX_FLAGS 2009-10-19 22:32:26 +00:00
jbeder 06b8d4bacf Patched for optional building of tests and tools 2009-10-12 05:21:00 +00:00
jbeder 41a776b397 Refactored the UTF-8 emitting 2009-10-08 21:05:56 +00:00
jbeder 15d5b2b533 Fixed the emitter unicode output 2009-10-07 06:46:05 +00:00
jbeder fb443b3056 Updated signature of Parser::GetNextDocument (issue 45) 2009-09-29 18:25:11 +00:00
jbeder 60fce621e8 Modified old gcc version patch so it still uses the new Node::Read in Visual Studio. Also broke up the \uNNNN characters in the spec tests into \xNN-type strings. 2009-09-16 05:31:28 +00:00
jbeder a20141bca7 Patched for gcc version <= 3.3 (just fall back to original version of Node::Read) 2009-09-16 04:01:40 +00:00
jbeder d957634c25 Tagged version 0.2.2 2009-09-09 01:37:23 +00:00
jbeder 7b889b9f35 Cleaned up the read template overloads (per litb's update); it seems the old version didn't compile in VS2008. Also updated the VS project files. 2009-09-08 20:57:18 +00:00
jbeder 246d8993d2 More tests, found bug in implicit keys in flow sequence 2009-09-08 05:35:39 +00:00
jbeder e4540f2c2a Fixed flow folding, and made the separation slightly cleaner (but the whole scanscalar thing could use a major refactoring) 2009-09-08 05:24:06 +00:00
jbeder 1d52e03750 Tests through 6.29, skipping directives and tags 2009-09-08 04:16:45 +00:00
jbeder d38c4e6026 (Actually) fixed the folding newline bug, but it's a bit messy, and we don't accurately make the distinction between block folding and flow folding 2009-09-07 23:29:04 +00:00
jbeder afe01a86bd Fixed newlines in folded scalars bug 2009-09-07 22:48:32 +00:00
jbeder 994e6af8e0 Simplified testing output 2009-09-07 22:17:02 +00:00
jbeder d15ce26b58 Fixed bugs with tab as non-content whitespace 2009-09-07 17:12:45 +00:00
jbeder a725d4b190 Fixed bugs in escape characters (both parsing and emitting) 2009-09-07 16:31:23 +00:00
jbeder 315205298a Fixed error in test 2009-09-07 06:56:05 +00:00
jbeder e1a112a761 Fixed last newline of folded scalar bug 2009-09-07 06:54:38 +00:00
jbeder 21232e3bef Fixed bug in trailing newlines of plain scalars 2009-09-07 06:42:03 +00:00
jbeder 90be7e75c2 Added spec tests (minus tags, directives, and BOM) up through example 5.12 - this exposed an error in line folding 2009-09-07 06:35:37 +00:00
jbeder bdf6008dea Added spec tests through example 2.13 2009-09-06 22:17:53 +00:00
jbeder 21c87d4961 Tagged release 0.2.1 for patch with complex keys 2009-09-06 22:02:59 +00:00
jbeder e67e6e19f9 Fixed bug with complex keys (and simplified the parsing for flow maps) 2009-09-06 21:52:56 +00:00
jbeder fe47783b5f Refactored the operator >> and Node::Read default functions, as well as the conversion functions, to more easily read new types as keys (this uncovered an error, in example 2.11 of the spec) 2009-09-06 20:52:45 +00:00
jbeder dbcf401cbd Added spec tests through 2.10 2009-09-06 17:02:24 +00:00
jbeder 2fe7e8d525 Added templated casting to nodes, as well as operator == and != (for quick checks, especially to help in testing). Implemented size() on a map node to return the number of key/value pairs (as in std::map) 2009-09-06 15:54:11 +00:00
jbeder 44750974e7 Updated the CMake file for 0.2.0 release, and added install.txt 2009-09-05 23:05:39 +00:00
jbeder f21456972c Allowed solo entries in a flow map to be read as keys with null value 2009-09-05 22:42:01 +00:00
jbeder ba472cc9a3 Finished refactoring of simple keys so that they can refer to multiple tokens at a single level 2009-09-05 03:49:38 +00:00
jbeder a2f2ab8426 Refactored simple keys so that validating doesn't require popping indents, and so popping indents (and adding the end map) is independent of when we validate the simple key 2009-09-05 02:51:09 +00:00
jbeder 6594941d24 Moved token enums into Token scope 2009-09-05 02:28:11 +00:00
jbeder a926fefe0d Started implementing spec tests 2009-09-03 14:27:03 +00:00
jbeder f7a47e9f9f Fixed bug with omitted keys/values in a flow map 2009-09-02 21:39:57 +00:00
jbeder 2e859413e7 Added more explicit doc indicator tests 2009-08-26 16:23:58 +00:00
jbeder aadc5052bc Fixed bug with explicit doc start introduced in last commit 2009-08-26 16:15:27 +00:00
jbeder 3c35ab1e42 Added CMake option to build for the iphone 2009-08-24 23:43:53 +00:00
jbeder 4457b7dd5b Removed the implicit sequence code (since it's not used any more) 2009-08-24 22:58:47 +00:00
jbeder c7ed85a4ac Fixed bug in anchors with no content. This involved refactoring the 'implicit sequence' concept (where a map and a sequence start on the same indent, but we read the sequence as more indented since the '-' is visually an indent). 2009-08-24 22:56:54 +00:00
jbeder fc22d55b53 Added Node::Clone function 2009-08-24 20:10:42 +00:00
jbeder 8fcd09f30b Cleaned up 2009-08-24 18:23:20 +00:00
jbeder 2c4a7cf58c Removed the std::wstring conversion 2009-08-22 00:25:37 +00:00
jbeder 770d6de545 Converted indexing to std::size_t, and fixed the Node templated overloads to properly index any index type (determining what is an index type is a bit of a hack - it should be is_convertible<T, std::size_t> (I think), but I just explicitly wrote down a list) 2009-08-19 20:58:07 +00:00
jbeder c45372e2f3 Added 'yaml-cpp: ' to the exception messages 2009-08-19 05:09:12 +00:00
jbeder d1c888f57a Added templated Read() function that creates the output variable itself (so you don't need to have a temp variable) 2009-08-19 03:37:19 +00:00
jbeder c456eab7cd Fixed out-of-bounds memory access 2009-07-31 18:26:42 +00:00
jbeder 952f72233e Added IsNull function 2009-07-31 05:07:21 +00:00
jbeder cb2b5783fa Fixed null key/value bug, added tests 2009-07-30 06:49:09 +00:00
jbeder 49265fa12b Fixed empty scalar in sequence bug 2009-07-30 05:54:40 +00:00
jbeder c043b9c64b Added support for emitting and represeting null 2009-07-30 04:42:27 +00:00
jbeder a2bd317397 Added header file inclusion guards 2009-07-29 22:27:20 +00:00
jbeder 4725c4fabb Forgot to add mark.h 2009-07-27 04:14:19 +00:00
jbeder 7e26c711cf Collected pos, line, and column into a Mark struct 2009-07-27 02:56:18 +00:00
jbeder 25b5e9fec1 Fixed hex output in emitter (should be always two hex chars) 2009-07-26 07:57:22 +00:00
jbeder c4e1446dff Fixed bug in emitting null nodes 2009-07-26 07:42:50 +00:00
jbeder d0870b4112 Fixed the Exception::what() function 2009-07-26 01:37:21 +00:00
jbeder 27055f178f Fixed bug with simple keys that are quoted scalars 2009-07-25 18:58:41 +00:00
jbeder ab7c8b0df0 Fixed yaml-cpp.pc file (with prefix) 2009-07-25 18:03:58 +00:00
jbeder 94cb26ae59 Fixed location of yaml-cpp.pc file 2009-07-24 06:18:46 +00:00
jbeder e6a26ef104 Updated visual studio project, and fixed a VS warning 2009-07-20 20:18:59 +00:00
jbeder f8440aa0e5 Patched to read into std::wstring 2009-07-15 20:47:51 +00:00
jbeder fd5bf7c29a Cosmetic change to .pc.cmake file 2009-07-15 20:38:25 +00:00
jbeder 64a5687656 Added support for pkgconfig 2009-07-15 20:37:11 +00:00
jbeder ba787edee4 Added FindValue to more easily read optional keys in a map 2009-07-12 02:59:23 +00:00
jbeder a48191c970 Added emitting for a YAML::Node (instead of the ad-hoc std::ostream overload) so it'll actually emit valid YAML always 2009-07-10 23:39:14 +00:00
jbeder 689c5fa7b7 Added check for extra compiler flags if using gcc 2009-07-10 17:26:39 +00:00
jbeder 10b5961f3c Set up the parse utility program to read from standard input if no file is specified 2009-07-10 04:25:11 +00:00
jbeder 6752e25bcd (Finally) overrode Exception::what()\n 2009-07-10 04:17:30 +00:00
jbeder ae89793c28 Applied patch to build and version a shared library 2009-07-10 03:52:05 +00:00
jbeder 616eafc3c1 Fixed warnings to compile on gcc with -Wall -pedantic -Wextra 2009-07-10 03:30:04 +00:00
jbeder 907960850b Clarified some copy/assignment issues with the stream/streamcharsource. 2009-07-10 03:20:16 +00:00
jbeder 4ba713bf43 Updated the visual studio project with some of the utf changes 2009-07-10 03:15:08 +00:00
jbeder e7f1ca7fb1 Merged utf branch changes r178:187 into the trunk 2009-07-10 03:10:03 +00:00
jbeder aa959e6705 Fixed bug that didn't allow multiple docs in a stream (using only "---") 2009-06-25 03:05:09 +00:00
jbeder 8aefb675a2 Patched CMake file to allow flexibility in build (in particular to allow shared lib build) 2009-06-12 04:28:36 +00:00
jbeder ed8f016c1f Updated the nested RegEx classes so they don't need to also take an std::string 2009-06-01 03:42:16 +00:00
jbeder 6e1fc798e1 Updated yaml-reader CMake file 2009-05-31 06:39:08 +00:00
jbeder ec578d45f1 Switched from loading test files to testing specific parsing constructs. The tests don't fully cover the span (eventually I'll add more, maybe), but there's a bunch there.
More to the point, the yaml-reader program doesn't do any file IO, so it doesn't require a specific working directory.
2009-05-31 06:36:01 +00:00
jbeder f2ed49f720 Patch - added testing 2009-05-30 02:41:27 +00:00
jbeder f09e4497b6 Set eol-style to native on all of the new files 2009-05-30 02:29:47 +00:00
jbeder 2fdf2475bb Patched - removed unnecessary CMake statements 2009-05-29 22:58:14 +00:00
jbeder ade7e7cd18 Patched - install target 2009-05-29 22:55:59 +00:00
jbeder b444913576 Patch to simplify CMakeLists.txt files 2009-05-29 22:48:25 +00:00
jbeder c150e9945c Patch for gcc -Wall (order of initialization) 2009-05-29 22:36:52 +00:00
jbeder 51457eece9 Changed the way we read different types of scalars.
It's better organized now, I think - nodes only offer a single main way of getting the fundamental scalar (as a string), and now we can specialize a single template to read specific types.
2009-05-23 23:51:01 +00:00
jbeder 0c34137d84 Updated Visual Studio project for the emitter. 2009-05-23 22:58:05 +00:00
jbeder 947356a64a Changed output library directory to /lib (in the source directory) - this makes more sense 2009-05-23 17:11:19 +00:00
jbeder fcab73a9b6 Added emitter headers to yaml.h 2009-05-22 22:23:57 +00:00
jbeder 7dd29ee5db Replaced direct emitter writing with an accessor to a C-string 2009-05-22 22:21:01 +00:00
jbeder 3e41edd30e Restructured CMake file to include headers, and to be better organized 2009-05-22 22:11:21 +00:00
jbeder e6617e3273 Removed excessive stderr logging 2009-05-22 21:56:45 +00:00
jbeder cba20711b0 Merged emitter branch into trunk, changes r105:r151 2009-05-22 21:52:31 +00:00
jbeder 5abf31b991 Merged aliases branch into trunk, changes r100:150 2009-05-22 21:48:05 +00:00
jbeder 7297387015 Fixed several bugs from the new file i/o setup.
In particular:
1. Windows CR/LF weren't read properly (issue #11)
2. Scanning wasn't reading EOF properly
3. Documents may be empty (this was old, I think)
Also fixed some VS2008 warnings on /W4.
2009-02-07 07:57:13 +00:00
jbeder 855d0d60df Switched to reading the entire file into a buffer at the start.\nThis speeds it up a TON (like 100x). 2009-02-01 20:48:43 +00:00
jbeder e9512a5ac8 Included <cstdio> for gcc-4.4 (issue 9) 2009-01-27 21:08:40 +00:00
jbeder 4e2e644c35 Included <cstring> for strcmp 2009-01-27 20:16:30 +00:00
jbeder d44502c979 Applied patch for gcc -Wall 2009-01-15 17:12:13 +00:00
jbeder 6434b4f0c8 Re-added the throw() specification to ~Exception(), and also to ~TypedKeyNotFound(); I suppose this'll fix the gcc compiler error. 2009-01-01 23:59:37 +00:00
jbeder 4cebe50a9f Removed throw() specifier in Exception (I don't remember putting it in). This may solve a gcc error (I haven't tested it yet) or it may break it further. 2009-01-01 20:14:32 +00:00
jbeder 51ea36e444 Added a templated derived exception to KeyNotFound so that you can figure out *which* key wasn't found. 2009-01-01 02:40:18 +00:00
jbeder ad2b9fbaaf Fixed tag output bug 2008-11-20 04:12:31 +00:00
jbeder 4b45a7185a Replaced a pointer-centered try/catch block with std::auto_ptr 2008-11-20 03:41:40 +00:00
jbeder 27da48bac2 Added line/column data for nodes so they can give better invalid scalar exceptions. 2008-11-18 04:20:07 +00:00
jbeder 09d2858dc0 Added line/column data for nodes so they can give better invalid scalar exceptions. 2008-11-18 04:19:50 +00:00
jbeder d1ef1e8ef1 Added more natural ways to parse boolean values (based on the YAML spec).
(Thanks to Vadim Zeitlin)
2008-09-25 00:15:40 +00:00
jbeder bf01059c38 Added Read() functions for Node that return true/false, so we can easily check if a read is successful without throwing.
But we still have operator >> that throws on failure.
2008-09-24 23:29:00 +00:00
jbeder ecba08e240 Fixed infinite loop bug having to do with simple keys when we hit an unexpected EOF. 2008-09-24 22:45:04 +00:00
jbeder d51888bc7e Fixed a problem where you lose the exception type on rethrow. 2008-09-23 21:13:23 +00:00
jbeder 0b6edc6cfe Made Node non-copyable. 2008-09-19 02:44:49 +00:00
jbeder 1d92deff31 2008-09-11 03:49:52 +00:00
jbeder c44b8e601e 2008-09-11 03:48:04 +00:00
jbeder b43f827188 Set the eol style to native for all files. 2008-09-03 22:20:39 +00:00
jbeder 859ac5e520 Fixed some gcc warnings. 2008-09-03 22:19:27 +00:00
jbeder 7f2c3591e3 Unified line endings. 2008-09-03 22:17:17 +00:00
jbeder a57a5748f8 Added the license.txt file describing the MIT license. 2008-09-03 04:37:06 +00:00
jbeder aa25fadf94 Fixed struct vs. class disparity. 2008-08-07 03:37:16 +00:00
jbeder 2d93b6ce58 Added CMake scripts for other platforms\nFixed some bugs that gcc complained about\nFixed CR/LF vs LF bug 2008-08-07 03:30:56 +00:00
beder 2601f5fd49 2008-07-31 19:41:11 +00:00
beder 89ed418b83 Small changes in the iterator code.
Changed the public interface of Scanner to resemble an STL container.
2008-07-23 04:38:18 +00:00
beder 57255a9898 Switched the Iterator implementation to a dedicated helper class (to hide the specific implementation, since it's pretty messy and may change). 2008-07-21 02:54:39 +00:00
beder 557f81e622 Replaced the queue of Token pointers with values.
We were getting memory leaks (as told by the CRT detectors, which I also added), and there's really no reason (as long as we're careful) to use pointers there.
2008-07-20 05:02:01 +00:00
beder f4e522490f Moved the testing source to the yaml-reader folder. 2008-07-14 05:18:25 +00:00
beder 2ffc7dc6ac Set the yaml-reader project to link to the yamlcpp library. 2008-07-14 05:08:46 +00:00
beder 11eb40e636 Added a static library project 'yamlcpp' to the solution. 2008-07-14 05:03:38 +00:00
beder ef8e9415f8 Renamed the solution yamlcpp. 2008-07-14 04:51:47 +00:00
beder 4c1c0977ab 2008-07-14 04:37:58 +00:00
beder 516637fcdc Moved all code to src/ and include/ directories. 2008-07-14 04:33:30 +00:00
beder e6aeb45d09 Switched from moving the cursor forward (in Regex) to ignoring (this handles newlines properly).
Updated some of the character-in-scalar rules.
2008-07-10 00:23:25 +00:00
beder 0b2e0dd32b Centralized the error messages to one location. 2008-07-08 20:31:48 +00:00
beder 84bcdda342 Removed the (unused) 'required' flag from simple keys (the parser should take care of this, not the scanner). 2008-07-08 18:34:26 +00:00
beder 5d5651861d Added some exceptions for directives. 2008-07-08 06:06:24 +00:00
beder 2f5c19fa00 Combined the myriad ScannerExceptions and ParserExceptions to a single ParserException class that has a message and a line/column position in the file where the error occurred. 2008-07-08 05:48:38 +00:00
beder 1acc0e4982 Added a (recursive) ordering, so we have a canonical output that we can compare. 2008-07-06 00:06:36 +00:00
beder 3cad5a2ed0 Wrote some tests, but they don't work because it doesn't output maps in a canonical form. 2008-07-05 19:00:58 +00:00
beder ba97c9f719 Rewrote the output so that it emits correct YAML.
Fixed a bug in the last newline of a block folded scalar.
2008-07-05 05:28:23 +00:00
beder 5feaef3748 2008-07-04 22:57:52 +00:00
beder c4c873733b Removed the document class (since it's really just a root node, and that's it). 2008-07-04 22:56:43 +00:00
beder 99a9aaa591 Specialized the overloaded [] operator for int/unsigned, and added a size() function, so that you can iterate through a sequence node like a vector. 2008-07-02 21:41:54 +00:00
beder 620c322df5 Added some parser exceptions. 2008-07-02 05:00:32 +00:00
beder 807045bc14 Overloaded the iterator's -> operator. 2008-07-02 01:32:19 +00:00
beder b4b287c4e9 Added an iterator class that can iterate through both sequence and map nodes. 2008-07-02 01:22:39 +00:00
beder 81ff4946ae Fixed opening newline bug for block scalars. 2008-07-01 06:34:55 +00:00
beder 8eb50fe9d0 Tags, anchors, and aliases are all parsed now. 2008-07-01 06:28:10 +00:00
beder 104da5c244 Added parsing of anchors, aliases, and tags (still no semantics yet).
Fixed a silly bug in the simple key pushing (queues are FIFO!).
2008-07-01 01:17:10 +00:00
beder d41503da5a Finished parsing of basic data types (scalar, sequence, map). 2008-06-30 23:57:58 +00:00
beder 146122f455 Renamed the stream member functions get() and eat(). 2008-06-30 22:34:10 +00:00
beder 17533e22da Instead of deriving different tokens from a base Token class, we now use an enumerated TOKEN_TYPE to distinguish types. This is so we don't have to cast all the time when parsing the resulting token stream.
Also, removed start/end stream tokens.
2008-06-30 21:47:21 +00:00
beder 2a7e20a315 Started the parser. 2008-06-30 06:51:22 +00:00
beder 795df7224b Added a peek token command (for the parser to use). 2008-06-30 06:21:12 +00:00
beder a93584b065 Added directives and tags. 2008-06-30 04:22:41 +00:00
beder b58c0c94e4 Moved the three scalar token scanning functions back to scantoken.cpp, so scanscalar.cpp now only has the main scalar scanning function.
Renamed ScanScalarInfo to ScanScalarParams.
2008-06-30 01:38:32 +00:00
beder 67250833b8 Mostly finished refactoring the scalar scanning. 2008-06-30 01:31:23 +00:00
beder 4de9cb48a5 Moved scalar scanning-related parameters to a struct.
Renamed the valid/possible tokens to a single variable status with enums valid, invalid, and unverified.
2008-06-29 17:39:33 +00:00
beder 6efc5614ec Moved the input stream, together with line/column info, into its own class, which allowed some other stuff just to pass the stream, and not have to be a member of Scanner. 2008-06-29 06:32:13 +00:00
beder 8dfb5c0ea8 Refactored common scalar scanning code (from plain, quoted, and block) to one function. 2008-06-29 05:45:41 +00:00
beder 3c56fd49eb Moved the scalar-related functions to their own file. 2008-06-29 03:11:25 +00:00
beder 45dfc719e1 2008-06-29 00:33:34 +00:00
beder ab27b9781e Small refactoring. 2008-06-28 22:05:51 +00:00
beder 34cd7177cd 2008-06-28 20:09:49 +00:00
beder 566916ba19 Added folded and literal scalars. 2008-06-28 20:08:21 +00:00
beder 1a96548fa5 Fixed complex keys. 2008-06-28 17:32:10 +00:00
beder b1c60706d7 Moved the simple key validation to before each token scan (plus at newlines of scalars). 2008-06-28 16:46:37 +00:00
beder 70afd130ad Added simple keys.
There's a bug (and question): should we test simple keys' validity BEFORE stuff or AFTER stuff?
2008-06-28 06:36:59 +00:00
beder fb9176a054 Added quoted scalars (with escaping).
Refactored some common whitespace-parsing code in scanning both scalars.
Implemented the flow collection tokens.
2008-06-27 23:11:46 +00:00
beder ba132b01bc Small plain scalar scanning fixes. 2008-06-27 20:54:43 +00:00
beder 10c4a2687f Split off the specific regular expressions, and the specialized token-scanning functions, into their own files. 2008-06-27 19:13:03 +00:00
beder aad36b8c47 Added stream input to the regular expressions, greatly simplifying the usage (in particular, we no longer have to specify the number of characters to be checked). 2008-06-27 19:07:30 +00:00
beder bb4bc8c4ae Wrote a simplified regular expression parser to make life easier (it only does single matches; i.e., no one-or-more matches, etc.).
Fixed some of the whitespace/line break matching.
2008-06-27 08:20:41 +00:00
beder 20dba9cd75 The plain scalar scanner is almost done (and it scans a simple list correctly).
Also messed around with multiple character peeking on the input, and got something working.
2008-06-27 00:18:52 +00:00
beder c7274ff2e8 More simple scalar scanning. 2008-06-26 22:00:39 +00:00
beder 2040e4de8b Continued working on scanner.
We're now using exceptions for errors, and scanning/pushing tokens is exception-safe (using a set of "limbo tokens").
2008-06-26 19:30:11 +00:00
beder 4b33531240 Started the scanner. 2008-06-26 09:05:28 +00:00
beder e6977cbe4e Beginning of first attempt to parse.
Will be completely wiped, I think, in favor of a Scanner (to tokens), then Parser mechanism.
2008-06-26 06:49:50 +00:00
beder 2d0f324529 Preliminary setup - basic data structures are there. 2008-06-25 23:00:18 +00:00
beder ffaf6a19ca 2008-06-25 22:46:18 +00:00
beder 0134c553a5 2008-06-25 22:45:08 +00:00
beder f959a475b7 2008-06-25 22:44:44 +00:00
43 changed files with 1056 additions and 14232 deletions
+1
View File
@@ -1 +1,2 @@
syntax: glob
+30 -53
View File
@@ -8,11 +8,10 @@
#include "yaml-cpp/dll.h"
#include "yaml-cpp/binary.h"
#include "yaml-cpp/emitterdef.h"
#include "yaml-cpp/emittermanip.h"
#include "yaml-cpp/ostream.h"
#include "yaml-cpp/noncopyable.h"
#include "yaml-cpp/null.h"
#include "yaml-cpp/ostream_wrapper.h"
#include <memory>
#include <string>
#include <sstream>
@@ -25,12 +24,11 @@ namespace YAML
{
public:
Emitter();
explicit Emitter(std::ostream& stream);
~Emitter();
// output
const char *c_str() const;
std::size_t size() const;
unsigned size() const;
// state checking
bool good() const;
@@ -62,7 +60,7 @@ namespace YAML
Emitter& Write(const _Anchor& anchor);
Emitter& Write(const _Tag& tag);
Emitter& Write(const _Comment& comment);
Emitter& Write(const _Null& n);
Emitter& Write(const _Null& null);
Emitter& Write(const Binary& binary);
template <typename T>
@@ -72,51 +70,39 @@ namespace YAML
Emitter& WriteStreamable(T value);
private:
void PreWriteIntegralType(std::stringstream& str);
void PreWriteStreamable(std::stringstream& str);
void PostWriteIntegralType(const std::stringstream& str);
void PostWriteStreamable(const std::stringstream& str);
template<typename T> void SetStreamablePrecision(std::stringstream&) {}
unsigned GetFloatPrecision() const;
unsigned GetDoublePrecision() const;
void PrepareIntegralStream(std::stringstream& stream) const;
void StartedScalar();
private:
void PreAtomicWrite();
bool GotoNextPreAtomicState();
void PostAtomicWrite();
void EmitSeparationIfNecessary();
void EmitBeginDoc();
void EmitEndDoc();
void EmitBeginSeq();
void EmitEndSeq();
void EmitBeginMap();
void EmitEndMap();
void EmitKey();
void EmitValue();
void EmitNewline();
void EmitKindTag();
void EmitTag(bool verbatim, const _Tag& tag);
void PrepareNode(EmitterNodeType::value child);
void PrepareTopNode(EmitterNodeType::value child);
void FlowSeqPrepareNode(EmitterNodeType::value child);
void BlockSeqPrepareNode(EmitterNodeType::value child);
void FlowMapPrepareNode(EmitterNodeType::value child);
void FlowMapPrepareLongKey(EmitterNodeType::value child);
void FlowMapPrepareLongKeyValue(EmitterNodeType::value child);
void FlowMapPrepareSimpleKey(EmitterNodeType::value child);
void FlowMapPrepareSimpleKeyValue(EmitterNodeType::value child);
void BlockMapPrepareNode(EmitterNodeType::value child);
void BlockMapPrepareLongKey(EmitterNodeType::value child);
void BlockMapPrepareLongKeyValue(EmitterNodeType::value child);
void BlockMapPrepareSimpleKey(EmitterNodeType::value child);
void BlockMapPrepareSimpleKeyValue(EmitterNodeType::value child);
void SpaceOrIndentTo(bool requireSpace, unsigned indent);
const char *ComputeFullBoolName(bool b) const;
bool CanEmitNewline() const;
private:
std::auto_ptr<EmitterState> m_pState;
ostream_wrapper m_stream;
ostream m_stream;
std::auto_ptr <EmitterState> m_pState;
};
template <typename T>
@@ -125,15 +111,10 @@ namespace YAML
if(!good())
return *this;
PrepareNode(EmitterNodeType::Scalar);
std::stringstream stream;
PrepareIntegralStream(stream);
stream << value;
m_stream << stream.str();
StartedScalar();
std::stringstream str;
PreWriteIntegralType(str);
str << value;
PostWriteIntegralType(str);
return *this;
}
@@ -143,28 +124,24 @@ namespace YAML
if(!good())
return *this;
PrepareNode(EmitterNodeType::Scalar);
std::stringstream stream;
SetStreamablePrecision<T>(stream);
stream << value;
m_stream << stream.str();
StartedScalar();
std::stringstream str;
PreWriteStreamable(str);
SetStreamablePrecision<T>(str);
str << value;
PostWriteStreamable(str);
return *this;
}
template<>
inline void Emitter::SetStreamablePrecision<float>(std::stringstream& stream)
inline void Emitter::SetStreamablePrecision<float>(std::stringstream& str)
{
stream.precision(GetFloatPrecision());
str.precision(GetFloatPrecision());
}
template<>
inline void Emitter::SetStreamablePrecision<double>(std::stringstream& stream)
inline void Emitter::SetStreamablePrecision<double>(std::stringstream& str)
{
stream.precision(GetDoublePrecision());
str.precision(GetDoublePrecision());
}
// overloads of insertion
-13
View File
@@ -1,13 +0,0 @@
#ifndef EMITTERDEF_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define EMITTERDEF_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
namespace YAML
{
struct EmitterNodeType { enum value { None, Property, Scalar, FlowSeq, BlockSeq, FlowMap, BlockMap }; };
}
#endif // EMITTERDEF_H_62B23520_7C8E_11DE_8A39_0800200C9A66
+9 -18
View File
@@ -61,7 +61,6 @@ namespace YAML
const char * const BAD_DEREFERENCE = "bad dereference";
const char * const BAD_SUBSCRIPT = "operator[] call on a scalar";
const char * const BAD_PUSHBACK = "appending to a non-sequence";
const char * const BAD_INSERT = "inserting in a non-convertible-to-map";
const char * const UNMATCHED_GROUP_TAG = "unmatched group tag";
const char * const UNEXPECTED_END_SEQ = "unexpected end sequence token";
@@ -70,7 +69,10 @@ namespace YAML
const char * const INVALID_ANCHOR = "invalid anchor";
const char * const INVALID_ALIAS = "invalid alias";
const char * const INVALID_TAG = "invalid tag";
const char * const BAD_FILE = "bad file";
const char * const EXPECTED_KEY_TOKEN = "expected key token";
const char * const EXPECTED_VALUE_TOKEN = "expected value token";
const char * const UNEXPECTED_KEY_TOKEN = "unexpected key token";
const char * const UNEXPECTED_VALUE_TOKEN = "unexpected value token";
template <typename T>
inline const std::string KEY_NOT_FOUND_WITH_KEY(const T&, typename disable_if<is_numeric<T> >::type * = 0) {
@@ -152,7 +154,7 @@ namespace YAML
class BadConversion: public RepresentationException {
public:
BadConversion()
: RepresentationException(Mark::null_mark(), ErrorMsg::BAD_CONVERSION) {}
: RepresentationException(Mark::null(), ErrorMsg::BAD_CONVERSION) {}
};
template<typename T>
@@ -165,37 +167,26 @@ namespace YAML
class BadDereference: public RepresentationException {
public:
BadDereference()
: RepresentationException(Mark::null_mark(), ErrorMsg::BAD_DEREFERENCE) {}
: RepresentationException(Mark::null(), ErrorMsg::BAD_DEREFERENCE) {}
};
class BadSubscript: public RepresentationException {
public:
BadSubscript()
: RepresentationException(Mark::null_mark(), ErrorMsg::BAD_SUBSCRIPT) {}
: RepresentationException(Mark::null(), ErrorMsg::BAD_SUBSCRIPT) {}
};
class BadPushback: public RepresentationException {
public:
BadPushback()
: RepresentationException(Mark::null_mark(), ErrorMsg::BAD_PUSHBACK) {}
: RepresentationException(Mark::null(), ErrorMsg::BAD_PUSHBACK) {}
};
class BadInsert: public RepresentationException {
public:
BadInsert()
: RepresentationException(Mark::null_mark(), ErrorMsg::BAD_INSERT) {}
};
class EmitterException: public Exception {
public:
EmitterException(const std::string& msg_)
: Exception(Mark::null_mark(), msg_) {}
: Exception(Mark::null(), msg_) {}
};
class BadFile: public Exception {
public:
BadFile(): Exception(Mark::null_mark(), ErrorMsg::BAD_FILE) {}
};
}
#endif // EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
+1 -1
View File
@@ -13,7 +13,7 @@ namespace YAML
struct YAML_CPP_API Mark {
Mark(): pos(0), line(0), column(0) {}
static const Mark null_mark() { return Mark(-1, -1, -1); }
static const Mark null() { return Mark(-1, -1, -1); }
int pos;
int line, column;
+1 -16
View File
@@ -128,7 +128,7 @@ namespace YAML
static Node encode(const std::map<K, V>& rhs) {
Node node(NodeType::Map);
for(typename std::map<K, V>::const_iterator it=rhs.begin();it!=rhs.end();++it)
node.force_insert(it->first, it->second);
node[it->first] = it->second;
return node;
}
@@ -138,12 +138,7 @@ namespace YAML
rhs.clear();
for(const_iterator it=node.begin();it!=node.end();++it)
#if defined(__GNUC__) && __GNUC__ < 4
//workaround for GCC 3:
rhs[it->first.template as<K>()] = it->second.template as<V>();
#else
rhs[it->first.as<K>()] = it->second.as<V>();
#endif
return true;
}
};
@@ -164,12 +159,7 @@ namespace YAML
rhs.clear();
for(const_iterator it=node.begin();it!=node.end();++it)
#if defined(__GNUC__) && __GNUC__ < 4
//workaround for GCC 3:
rhs.push_back(it->template as<T>());
#else
rhs.push_back(it->as<T>());
#endif
return true;
}
};
@@ -190,12 +180,7 @@ namespace YAML
rhs.clear();
for(const_iterator it=node.begin();it!=node.end();++it)
#if defined(__GNUC__) && __GNUC__ < 4
//workaround for GCC 3:
rhs.push_back(it->template as<T>());
#else
rhs.push_back(it->as<T>());
#endif
return true;
}
};
-21
View File
@@ -118,27 +118,6 @@ namespace YAML
return false;
}
// map
template<typename Key, typename Value>
inline void node_data::force_insert(const Key& key, const Value& value, shared_memory_holder pMemory)
{
switch(m_type) {
case NodeType::Map:
break;
case NodeType::Undefined:
case NodeType::Null:
case NodeType::Sequence:
convert_to_map(pMemory);
break;
case NodeType::Scalar:
throw BadInsert();
}
node& k = convert_to_node(key, pMemory);
node& v = convert_to_node(value, pMemory);
insert_map_pair(k, v);
}
template<typename T>
inline bool node_data::equals(node& node, const T& rhs, shared_memory_holder pMemory)
-4
View File
@@ -115,10 +115,6 @@ namespace YAML
}
bool remove(node& key, shared_memory_holder pMemory) { return m_pRef->remove(key, pMemory); }
// map
template<typename Key, typename Value>
void force_insert(const Key& key, const Value& value, shared_memory_holder pMemory){ m_pRef->force_insert(key, value, pMemory); }
private:
shared_node_ref m_pRef;
typedef std::set<node *> nodes;
-4
View File
@@ -56,10 +56,6 @@ namespace YAML
node& get(node& key, shared_memory_holder pMemory) const;
node& get(node& key, shared_memory_holder pMemory);
bool remove(node& key, shared_memory_holder pMemory);
// map
template<typename Key, typename Value>
void force_insert(const Key& key, const Value& value, shared_memory_holder pMemory);
public:
static std::string empty_scalar;
-4
View File
@@ -55,10 +55,6 @@ namespace YAML
node& get(node& key, shared_memory_holder pMemory) const { return static_cast<const node_data&>(*m_pData).get(key, pMemory); }
node& get(node& key, shared_memory_holder pMemory) { return m_pData->get(key, pMemory); }
bool remove(node& key, shared_memory_holder pMemory) { return m_pData->remove(key, pMemory); }
// map
template<typename Key, typename Value>
void force_insert(const Key& key, const Value& value, shared_memory_holder pMemory) { m_pData->force_insert(key, value, pMemory); }
private:
shared_node_data m_pData;
+37 -64
View File
@@ -15,7 +15,7 @@
namespace YAML
{
inline Node::Node(): m_pNode(NULL)
inline Node::Node(): m_pNode(0)
{
}
@@ -123,7 +123,7 @@ namespace YAML
return node.Scalar();
}
};
// access functions
template<typename T>
inline const T Node::as() const
@@ -168,11 +168,6 @@ namespace YAML
return *this;
}
inline void Node::clear()
{
m_pNode = NULL;
}
template<typename T>
inline void Node::Assign(const T& rhs)
{
@@ -229,7 +224,7 @@ namespace YAML
m_pMemory->merge(*rhs.m_pMemory);
m_pNode = rhs.m_pNode;
}
// size/iterator
inline std::size_t Node::size() const
{
@@ -272,57 +267,12 @@ namespace YAML
m_pMemory->merge(*rhs.m_pMemory);
}
// helpers for indexing
namespace detail {
template<typename T>
struct to_value_t {
explicit to_value_t(const T& t_): t(t_) {}
const T& t;
typedef const T& return_type;
const T& operator()() const { return t; }
};
template<>
struct to_value_t<const char*> {
explicit to_value_t(const char *t_): t(t_) {}
const char *t;
typedef std::string return_type;
const std::string operator()() const { return t; }
};
template<>
struct to_value_t<char*> {
explicit to_value_t(char *t_): t(t_) {}
const char *t;
typedef std::string return_type;
const std::string operator()() const { return t; }
};
template<std::size_t N>
struct to_value_t<char [N]> {
explicit to_value_t(const char *t_): t(t_) {}
const char *t;
typedef std::string return_type;
const std::string operator()() const { return t; }
};
// converts C-strings to std::strings so they can be copied
template<typename T>
inline typename to_value_t<T>::return_type to_value(const T& t) {
return to_value_t<T>(t)();
}
}
// indexing
template<typename Key>
inline const Node Node::operator[](const Key& key) const
{
EnsureNodeExists();
detail::node& value = static_cast<const detail::node&>(*m_pNode).get(detail::to_value(key), m_pMemory);
detail::node& value = static_cast<const detail::node&>(*m_pNode).get(key, m_pMemory);
return Node(value, m_pMemory);
}
@@ -330,7 +280,7 @@ namespace YAML
inline Node Node::operator[](const Key& key)
{
EnsureNodeExists();
detail::node& value = m_pNode->get(detail::to_value(key), m_pMemory);
detail::node& value = m_pNode->get(key, m_pMemory);
return Node(value, m_pMemory);
}
@@ -338,7 +288,7 @@ namespace YAML
inline bool Node::remove(const Key& key)
{
EnsureNodeExists();
return m_pNode->remove(detail::to_value(key), m_pMemory);
return m_pNode->remove(key, m_pMemory);
}
inline const Node Node::operator[](const Node& key) const
@@ -363,16 +313,39 @@ namespace YAML
key.EnsureNodeExists();
return m_pNode->remove(*key.m_pNode, m_pMemory);
}
// map
template<typename Key, typename Value>
inline void Node::force_insert(const Key& key, const Value& value)
{
EnsureNodeExists();
m_pNode->force_insert(detail::to_value(key), detail::to_value(value), m_pMemory);
}
inline const Node Node::operator[](const char *key) const
{
return operator[](std::string(key));
}
inline Node Node::operator[](const char *key)
{
return operator[](std::string(key));
}
inline bool Node::remove(const char *key)
{
return remove(std::string(key));
}
inline const Node Node::operator[](char *key) const
{
return operator[](static_cast<const char *>(key));
}
inline Node Node::operator[](char *key)
{
return operator[](static_cast<const char *>(key));
}
inline bool Node::remove(char *key)
{
return remove(static_cast<const char *>(key));
}
// free functions
inline bool operator==(const Node& lhs, const Node& rhs)
{
return lhs.is(rhs);
+9 -8
View File
@@ -56,8 +56,7 @@ namespace YAML
bool is(const Node& rhs) const;
template<typename T> Node& operator=(const T& rhs);
Node& operator=(const Node& rhs);
void clear();
// size/iterator
std::size_t size() const;
@@ -79,11 +78,15 @@ namespace YAML
const Node operator[](const Node& key) const;
Node operator[](const Node& key);
bool remove(const Node& key);
// map
template<typename Key, typename Value>
void force_insert(const Key& key, const Value& value);
const Node operator[](const char *key) const;
Node operator[](const char *key);
bool remove(const char *key);
const Node operator[](char *key) const;
Node operator[](char *key);
bool remove(char *key);
private:
explicit Node(detail::node& node, detail::shared_memory_holder pMemory);
@@ -102,8 +105,6 @@ namespace YAML
};
bool operator==(const Node& lhs, const Node& rhs);
Node Clone(const Node& node);
template<typename T>
struct convert;
+40
View File
@@ -0,0 +1,40 @@
#ifndef OSTREAM_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define OSTREAM_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include <string>
namespace YAML
{
class ostream
{
public:
ostream();
~ostream();
void reserve(unsigned size);
void put(char ch);
const char *str() const { return m_buffer; }
unsigned row() const { return m_row; }
unsigned col() const { return m_col; }
unsigned pos() const { return m_pos; }
private:
char *m_buffer;
unsigned m_pos;
unsigned m_size;
unsigned m_row, m_col;
};
ostream& operator << (ostream& out, const char *str);
ostream& operator << (ostream& out, const std::string& str);
ostream& operator << (ostream& out, char ch);
}
#endif // OSTREAM_H_62B23520_7C8E_11DE_8A39_0800200C9A66
-69
View File
@@ -1,69 +0,0 @@
#ifndef OSTREAM_WRAPPER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define OSTREAM_WRAPPER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
#pragma once
#endif
#include <string>
#include <vector>
namespace YAML
{
class ostream_wrapper
{
public:
ostream_wrapper();
explicit ostream_wrapper(std::ostream& stream);
~ostream_wrapper();
void write(const std::string& str);
void write(const char *str, std::size_t size);
void set_comment() { m_comment = true; }
const char *str() const {
if(m_pStream) {
return 0;
} else {
m_buffer[m_pos] = '\0';
return &m_buffer[0];
}
}
std::size_t row() const { return m_row; }
std::size_t col() const { return m_col; }
std::size_t pos() const { return m_pos; }
bool comment() const { return m_comment; }
private:
void update_pos(char ch);
private:
mutable std::vector<char> m_buffer;
std::ostream *m_pStream;
std::size_t m_pos;
std::size_t m_row, m_col;
bool m_comment;
};
template<std::size_t N>
inline ostream_wrapper& operator << (ostream_wrapper& stream, const char (&str)[N]) {
stream.write(str, N-1);
return stream;
}
inline ostream_wrapper& operator << (ostream_wrapper& stream, const std::string& str) {
stream.write(str);
return stream;
}
inline ostream_wrapper& operator << (ostream_wrapper& stream, char ch) {
stream.write(&ch, 1);
return stream;
}
}
#endif // OSTREAM_WRAPPER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
+5 -1
View File
@@ -14,8 +14,10 @@
namespace YAML
{
struct Directives;
struct Mark;
struct Token;
class EventHandler;
class Node;
class Scanner;
class YAML_CPP_API Parser: private noncopyable
@@ -29,7 +31,9 @@ namespace YAML
void Load(std::istream& in);
bool HandleNextDocument(EventHandler& eventHandler);
bool GetNextDocument(Node& document); // old API only
void PrintTokens(std::ostream& out);
private:
+2 -1
View File
@@ -15,8 +15,9 @@ namespace YAML
std::ostream& operator << (std::ostream& out, const Node& node)
{
Emitter emitter(out);
Emitter emitter;
emitter << node;
out << emitter.c_str();
return out;
}
+529 -598
View File
File diff suppressed because it is too large Load Diff
+71 -171
View File
@@ -4,8 +4,11 @@
namespace YAML
{
EmitterState::EmitterState(): m_isGood(true), m_curIndent(0), m_hasAnchor(false), m_hasTag(false), m_hasNonContent(false), m_docCount(0)
EmitterState::EmitterState(): m_isGood(true), m_curIndent(0), m_requiresSoftSeparation(false), m_requiresHardSeparation(false)
{
// start up
m_stateStack.push(ES_WAITING_FOR_DOC);
// set default global manipulators
m_charset.set(EmitNonAscii);
m_strFmt.set(Auto);
@@ -32,111 +35,21 @@ namespace YAML
// . Only the ones that make sense will be accepted
void EmitterState::SetLocalValue(EMITTER_MANIP value)
{
SetOutputCharset(value, FmtScope::Local);
SetStringFormat(value, FmtScope::Local);
SetBoolFormat(value, FmtScope::Local);
SetBoolCaseFormat(value, FmtScope::Local);
SetBoolLengthFormat(value, FmtScope::Local);
SetIntFormat(value, FmtScope::Local);
SetFlowType(GroupType::Seq, value, FmtScope::Local);
SetFlowType(GroupType::Map, value, FmtScope::Local);
SetMapKeyFormat(value, FmtScope::Local);
SetOutputCharset(value, LOCAL);
SetStringFormat(value, LOCAL);
SetBoolFormat(value, LOCAL);
SetBoolCaseFormat(value, LOCAL);
SetBoolLengthFormat(value, LOCAL);
SetIntFormat(value, LOCAL);
SetFlowType(GT_SEQ, value, LOCAL);
SetFlowType(GT_MAP, value, LOCAL);
SetMapKeyFormat(value, LOCAL);
}
void EmitterState::SetAnchor()
{
m_hasAnchor = true;
}
void EmitterState::SetTag()
{
m_hasTag = true;
}
void EmitterState::SetNonContent()
{
m_hasNonContent = true;
}
void EmitterState::SetLongKey()
{
assert(!m_groups.empty());
if(m_groups.empty())
return;
assert(m_groups.top().type == GroupType::Map);
m_groups.top().longKey = true;
}
void EmitterState::ForceFlow()
{
assert(!m_groups.empty());
if(m_groups.empty())
return;
m_groups.top().flowType = FlowType::Flow;
}
void EmitterState::StartedNode()
{
if(m_groups.empty()) {
m_docCount++;
} else {
m_groups.top().childCount++;
if(m_groups.top().childCount % 2 == 0)
m_groups.top().longKey = false;
}
m_hasAnchor = false;
m_hasTag = false;
m_hasNonContent = false;
}
EmitterNodeType::value EmitterState::NextGroupType(GroupType::value type) const
{
if(type == GroupType::Seq) {
if(GetFlowType(type) == Block)
return EmitterNodeType::BlockSeq;
else
return EmitterNodeType::FlowSeq;
} else {
if(GetFlowType(type) == Block)
return EmitterNodeType::BlockMap;
else
return EmitterNodeType::FlowMap;
}
// can't happen
assert(false);
return EmitterNodeType::None;
}
void EmitterState::StartedDoc()
{
m_hasAnchor = false;
m_hasTag = false;
m_hasNonContent = false;
}
void EmitterState::EndedDoc()
{
m_hasAnchor = false;
m_hasTag = false;
m_hasNonContent = false;
}
void EmitterState::StartedScalar()
{
StartedNode();
ClearModifiedSettings();
}
void EmitterState::StartedGroup(GroupType::value type)
void EmitterState::BeginGroup(GROUP_TYPE type)
{
StartedNode();
const int lastGroupIndent = (m_groups.empty() ? 0 : m_groups.top().indent);
m_curIndent += lastGroupIndent;
unsigned lastIndent = (m_groups.empty() ? 0 : m_groups.top().indent);
m_curIndent += lastIndent;
std::auto_ptr<Group> pGroup(new Group(type));
@@ -144,23 +57,17 @@ namespace YAML
pGroup->modifiedSettings = m_modifiedSettings;
// set up group
if(GetFlowType(type) == Block)
pGroup->flowType = FlowType::Block;
else
pGroup->flowType = FlowType::Flow;
pGroup->flow = GetFlowType(type);
pGroup->indent = GetIndent();
pGroup->usingLongKey = (GetMapKeyFormat() == LongKey ? true : false);
m_groups.push(pGroup);
}
void EmitterState::EndedGroup(GroupType::value type)
void EmitterState::EndGroup(GROUP_TYPE type)
{
if(m_groups.empty()) {
if(type == GroupType::Seq)
return SetError(ErrorMsg::UNEXPECTED_END_SEQ);
else
return SetError(ErrorMsg::UNEXPECTED_END_MAP);
}
if(m_groups.empty())
return SetError(ErrorMsg::UNMATCHED_GROUP_TAG);
// get rid of the current group
{
@@ -177,57 +84,49 @@ namespace YAML
// some global settings that we changed may have been overridden
// by a local setting we just popped, so we need to restore them
m_globalModifiedSettings.restore();
ClearModifiedSettings();
}
EmitterNodeType::value EmitterState::CurGroupNodeType() const
{
if(m_groups.empty())
return EmitterNodeType::None;
return m_groups.top().NodeType();
}
GroupType::value EmitterState::CurGroupType() const
GROUP_TYPE EmitterState::GetCurGroupType() const
{
return m_groups.empty() ? GroupType::None : m_groups.top().type;
if(m_groups.empty())
return GT_NONE;
return m_groups.top().type;
}
FlowType::value EmitterState::CurGroupFlowType() const
FLOW_TYPE EmitterState::GetCurGroupFlowType() const
{
return m_groups.empty() ? FlowType::None : m_groups.top().flowType;
if(m_groups.empty())
return FT_NONE;
return (m_groups.top().flow == Flow ? FT_FLOW : FT_BLOCK);
}
bool EmitterState::CurrentlyInLongKey()
{
if(m_groups.empty())
return false;
return m_groups.top().usingLongKey;
}
void EmitterState::StartLongKey()
{
if(!m_groups.empty())
m_groups.top().usingLongKey = true;
}
void EmitterState::StartSimpleKey()
{
if(!m_groups.empty())
m_groups.top().usingLongKey = false;
}
int EmitterState::CurGroupIndent() const
{
return m_groups.empty() ? 0 : m_groups.top().indent;
}
std::size_t EmitterState::CurGroupChildCount() const
{
return m_groups.empty() ? m_docCount : m_groups.top().childCount;
}
bool EmitterState::CurGroupLongKey() const
{
return m_groups.empty() ? false : m_groups.top().longKey;
}
int EmitterState::LastIndent() const
{
if(m_groups.size() <= 1)
return 0;
return m_curIndent - m_groups.top(-1).indent;
}
void EmitterState::ClearModifiedSettings()
{
m_modifiedSettings.clear();
}
bool EmitterState::SetOutputCharset(EMITTER_MANIP value, FmtScope::value scope)
bool EmitterState::SetOutputCharset(EMITTER_MANIP value, FMT_SCOPE scope)
{
switch(value) {
case EmitNonAscii:
@@ -239,7 +138,7 @@ namespace YAML
}
}
bool EmitterState::SetStringFormat(EMITTER_MANIP value, FmtScope::value scope)
bool EmitterState::SetStringFormat(EMITTER_MANIP value, FMT_SCOPE scope)
{
switch(value) {
case Auto:
@@ -253,7 +152,7 @@ namespace YAML
}
}
bool EmitterState::SetBoolFormat(EMITTER_MANIP value, FmtScope::value scope)
bool EmitterState::SetBoolFormat(EMITTER_MANIP value, FMT_SCOPE scope)
{
switch(value) {
case OnOffBool:
@@ -266,7 +165,7 @@ namespace YAML
}
}
bool EmitterState::SetBoolLengthFormat(EMITTER_MANIP value, FmtScope::value scope)
bool EmitterState::SetBoolLengthFormat(EMITTER_MANIP value, FMT_SCOPE scope)
{
switch(value) {
case LongBool:
@@ -278,7 +177,7 @@ namespace YAML
}
}
bool EmitterState::SetBoolCaseFormat(EMITTER_MANIP value, FmtScope::value scope)
bool EmitterState::SetBoolCaseFormat(EMITTER_MANIP value, FMT_SCOPE scope)
{
switch(value) {
case UpperCase:
@@ -291,7 +190,7 @@ namespace YAML
}
}
bool EmitterState::SetIntFormat(EMITTER_MANIP value, FmtScope::value scope)
bool EmitterState::SetIntFormat(EMITTER_MANIP value, FMT_SCOPE scope)
{
switch(value) {
case Dec:
@@ -304,16 +203,16 @@ namespace YAML
}
}
bool EmitterState::SetIndent(unsigned value, FmtScope::value scope)
bool EmitterState::SetIndent(unsigned value, FMT_SCOPE scope)
{
if(value <= 1)
if(value == 0)
return false;
_Set(m_indent, value, scope);
return true;
}
bool EmitterState::SetPreCommentIndent(unsigned value, FmtScope::value scope)
bool EmitterState::SetPreCommentIndent(unsigned value, FMT_SCOPE scope)
{
if(value == 0)
return false;
@@ -322,7 +221,7 @@ namespace YAML
return true;
}
bool EmitterState::SetPostCommentIndent(unsigned value, FmtScope::value scope)
bool EmitterState::SetPostCommentIndent(unsigned value, FMT_SCOPE scope)
{
if(value == 0)
return false;
@@ -331,29 +230,30 @@ namespace YAML
return true;
}
bool EmitterState::SetFlowType(GroupType::value groupType, EMITTER_MANIP value, FmtScope::value scope)
bool EmitterState::SetFlowType(GROUP_TYPE groupType, EMITTER_MANIP value, FMT_SCOPE scope)
{
switch(value) {
case Block:
case Flow:
_Set(groupType == GroupType::Seq ? m_seqFmt : m_mapFmt, value, scope);
_Set(groupType == GT_SEQ ? m_seqFmt : m_mapFmt, value, scope);
return true;
default:
return false;
}
}
EMITTER_MANIP EmitterState::GetFlowType(GroupType::value groupType) const
EMITTER_MANIP EmitterState::GetFlowType(GROUP_TYPE groupType) const
{
// force flow style if we're currently in a flow
if(CurGroupFlowType() == FlowType::Flow)
FLOW_TYPE flowType = GetCurGroupFlowType();
if(flowType == FT_FLOW)
return Flow;
// otherwise, go with what's asked of us
return (groupType == GroupType::Seq ? m_seqFmt.get() : m_mapFmt.get());
// otherwise, go with what's asked of use
return (groupType == GT_SEQ ? m_seqFmt.get() : m_mapFmt.get());
}
bool EmitterState::SetMapKeyFormat(EMITTER_MANIP value, FmtScope::value scope)
bool EmitterState::SetMapKeyFormat(EMITTER_MANIP value, FMT_SCOPE scope)
{
switch(value) {
case Auto:
@@ -365,7 +265,7 @@ namespace YAML
}
}
bool EmitterState::SetFloatPrecision(int value, FmtScope::value scope)
bool EmitterState::SetFloatPrecision(int value, FMT_SCOPE scope)
{
if(value < 0 || value > std::numeric_limits<float>::digits10)
return false;
@@ -373,7 +273,7 @@ namespace YAML
return true;
}
bool EmitterState::SetDoublePrecision(int value, FmtScope::value scope)
bool EmitterState::SetDoublePrecision(int value, FMT_SCOPE scope)
{
if(value < 0 || value > std::numeric_limits<double>::digits10)
return false;
+108 -81
View File
@@ -8,20 +8,71 @@
#include "ptr_stack.h"
#include "setting.h"
#include "yaml-cpp/emitterdef.h"
#include "yaml-cpp/emittermanip.h"
#include <cassert>
#include <vector>
#include <stack>
#include <memory>
#include <stdexcept>
namespace YAML
{
struct FmtScope { enum value { Local, Global }; };
struct GroupType { enum value { None, Seq, Map }; };
struct FlowType { enum value { None, Flow, Block }; };
enum FMT_SCOPE {
LOCAL,
GLOBAL
};
enum GROUP_TYPE {
GT_NONE,
GT_SEQ,
GT_MAP
};
enum FLOW_TYPE {
FT_NONE,
FT_FLOW,
FT_BLOCK
};
enum NODE_STATE {
NS_START,
NS_READY_FOR_ATOM,
NS_END
};
enum EMITTER_STATE {
ES_WAITING_FOR_DOC,
ES_WRITING_DOC,
ES_DONE_WITH_DOC,
// block seq
ES_WAITING_FOR_BLOCK_SEQ_ENTRY,
ES_WRITING_BLOCK_SEQ_ENTRY,
ES_DONE_WITH_BLOCK_SEQ_ENTRY,
// flow seq
ES_WAITING_FOR_FLOW_SEQ_ENTRY,
ES_WRITING_FLOW_SEQ_ENTRY,
ES_DONE_WITH_FLOW_SEQ_ENTRY,
// block map
ES_WAITING_FOR_BLOCK_MAP_ENTRY,
ES_WAITING_FOR_BLOCK_MAP_KEY,
ES_WRITING_BLOCK_MAP_KEY,
ES_DONE_WITH_BLOCK_MAP_KEY,
ES_WAITING_FOR_BLOCK_MAP_VALUE,
ES_WRITING_BLOCK_MAP_VALUE,
ES_DONE_WITH_BLOCK_MAP_VALUE,
// flow map
ES_WAITING_FOR_FLOW_MAP_ENTRY,
ES_WAITING_FOR_FLOW_MAP_KEY,
ES_WRITING_FLOW_MAP_KEY,
ES_DONE_WITH_FLOW_MAP_KEY,
ES_WAITING_FOR_FLOW_MAP_VALUE,
ES_WRITING_FLOW_MAP_VALUE,
ES_DONE_WITH_FLOW_MAP_VALUE
};
class EmitterState
{
public:
@@ -33,81 +84,76 @@ namespace YAML
const std::string GetLastError() const { return m_lastError; }
void SetError(const std::string& error) { m_isGood = false; m_lastError = error; }
// node handling
void SetAnchor();
void SetTag();
void SetNonContent();
void SetLongKey();
void ForceFlow();
void StartedDoc();
void EndedDoc();
void StartedScalar();
void StartedGroup(GroupType::value type);
void EndedGroup(GroupType::value type);
// main state of the machine
EMITTER_STATE GetCurState() const { return m_stateStack.top(); }
void SwitchState(EMITTER_STATE state) { PopState(); PushState(state); }
void PushState(EMITTER_STATE state) { m_stateStack.push(state); }
void PopState() { m_stateStack.pop(); }
void SetLocalValue(EMITTER_MANIP value);
// group handling
void BeginGroup(GROUP_TYPE type);
void EndGroup(GROUP_TYPE type);
GROUP_TYPE GetCurGroupType() const;
FLOW_TYPE GetCurGroupFlowType() const;
int GetCurIndent() const { return m_curIndent; }
bool CurrentlyInLongKey();
void StartLongKey();
void StartSimpleKey();
EmitterNodeType::value NextGroupType(GroupType::value type) const;
EmitterNodeType::value CurGroupNodeType() const;
GroupType::value CurGroupType() const;
FlowType::value CurGroupFlowType() const;
int CurGroupIndent() const;
std::size_t CurGroupChildCount() const;
bool CurGroupLongKey() const;
int LastIndent() const;
int CurIndent() const { return m_curIndent; }
bool HasAnchor() const { return m_hasAnchor; }
bool HasTag() const { return m_hasTag; }
bool HasBegunNode() const { return m_hasAnchor || m_hasTag || m_hasNonContent; }
bool HasBegunContent() const { return m_hasAnchor || m_hasTag; }
bool RequiresSoftSeparation() const { return m_requiresSoftSeparation; }
bool RequiresHardSeparation() const { return m_requiresHardSeparation; }
void RequireSoftSeparation() { m_requiresSoftSeparation = true; }
void RequireHardSeparation() { m_requiresSoftSeparation = true; m_requiresHardSeparation = true; }
void ForceHardSeparation() { m_requiresSoftSeparation = false; }
void UnsetSeparation() { m_requiresSoftSeparation = false; m_requiresHardSeparation = false; }
void ClearModifiedSettings();
// formatters
void SetLocalValue(EMITTER_MANIP value);
bool SetOutputCharset(EMITTER_MANIP value, FmtScope::value scope);
bool SetOutputCharset(EMITTER_MANIP value, FMT_SCOPE scope);
EMITTER_MANIP GetOutputCharset() const { return m_charset.get(); }
bool SetStringFormat(EMITTER_MANIP value, FmtScope::value scope);
bool SetStringFormat(EMITTER_MANIP value, FMT_SCOPE scope);
EMITTER_MANIP GetStringFormat() const { return m_strFmt.get(); }
bool SetBoolFormat(EMITTER_MANIP value, FmtScope::value scope);
bool SetBoolFormat(EMITTER_MANIP value, FMT_SCOPE scope);
EMITTER_MANIP GetBoolFormat() const { return m_boolFmt.get(); }
bool SetBoolLengthFormat(EMITTER_MANIP value, FmtScope::value scope);
bool SetBoolLengthFormat(EMITTER_MANIP value, FMT_SCOPE scope);
EMITTER_MANIP GetBoolLengthFormat() const { return m_boolLengthFmt.get(); }
bool SetBoolCaseFormat(EMITTER_MANIP value, FmtScope::value scope);
bool SetBoolCaseFormat(EMITTER_MANIP value, FMT_SCOPE scope);
EMITTER_MANIP GetBoolCaseFormat() const { return m_boolCaseFmt.get(); }
bool SetIntFormat(EMITTER_MANIP value, FmtScope::value scope);
bool SetIntFormat(EMITTER_MANIP value, FMT_SCOPE scope);
EMITTER_MANIP GetIntFormat() const { return m_intFmt.get(); }
bool SetIndent(unsigned value, FmtScope::value scope);
bool SetIndent(unsigned value, FMT_SCOPE scope);
int GetIndent() const { return m_indent.get(); }
bool SetPreCommentIndent(unsigned value, FmtScope::value scope);
bool SetPreCommentIndent(unsigned value, FMT_SCOPE scope);
int GetPreCommentIndent() const { return m_preCommentIndent.get(); }
bool SetPostCommentIndent(unsigned value, FmtScope::value scope);
bool SetPostCommentIndent(unsigned value, FMT_SCOPE scope);
int GetPostCommentIndent() const { return m_postCommentIndent.get(); }
bool SetFlowType(GroupType::value groupType, EMITTER_MANIP value, FmtScope::value scope);
EMITTER_MANIP GetFlowType(GroupType::value groupType) const;
bool SetFlowType(GROUP_TYPE groupType, EMITTER_MANIP value, FMT_SCOPE scope);
EMITTER_MANIP GetFlowType(GROUP_TYPE groupType) const;
bool SetMapKeyFormat(EMITTER_MANIP value, FmtScope::value scope);
bool SetMapKeyFormat(EMITTER_MANIP value, FMT_SCOPE scope);
EMITTER_MANIP GetMapKeyFormat() const { return m_mapKeyFmt.get(); }
bool SetFloatPrecision(int value, FmtScope::value scope);
bool SetFloatPrecision(int value, FMT_SCOPE scope);
unsigned GetFloatPrecision() const { return m_floatPrecision.get(); }
bool SetDoublePrecision(int value, FmtScope::value scope);
bool SetDoublePrecision(int value, FMT_SCOPE scope);
unsigned GetDoublePrecision() const { return m_doublePrecision.get(); }
private:
template <typename T>
void _Set(Setting<T>& fmt, T value, FmtScope::value scope);
void StartedNode();
void _Set(Setting<T>& fmt, T value, FMT_SCOPE scope);
private:
// basic state ok?
@@ -115,6 +161,8 @@ namespace YAML
std::string m_lastError;
// other state
std::stack<EMITTER_STATE> m_stateStack;
Setting<EMITTER_MANIP> m_charset;
Setting<EMITTER_MANIP> m_strFmt;
Setting<EMITTER_MANIP> m_boolFmt;
@@ -133,50 +181,29 @@ namespace YAML
SettingChanges m_globalModifiedSettings;
struct Group {
explicit Group(GroupType::value type_): type(type_), indent(0), childCount(0), longKey(false) {}
Group(GROUP_TYPE type_): type(type_), usingLongKey(false), indent(0) {}
GroupType::value type;
FlowType::value flowType;
GROUP_TYPE type;
EMITTER_MANIP flow;
bool usingLongKey;
int indent;
std::size_t childCount;
bool longKey;
SettingChanges modifiedSettings;
EmitterNodeType::value NodeType() const {
if(type == GroupType::Seq) {
if(flowType == FlowType::Flow)
return EmitterNodeType::FlowSeq;
else
return EmitterNodeType::BlockSeq;
} else {
if(flowType == FlowType::Flow)
return EmitterNodeType::FlowMap;
else
return EmitterNodeType::BlockMap;
}
// can't get here
assert(false);
return EmitterNodeType::None;
}
};
ptr_stack<Group> m_groups;
unsigned m_curIndent;
bool m_hasAnchor;
bool m_hasTag;
bool m_hasNonContent;
std::size_t m_docCount;
bool m_requiresSoftSeparation;
bool m_requiresHardSeparation;
};
template <typename T>
void EmitterState::_Set(Setting<T>& fmt, T value, FmtScope::value scope) {
void EmitterState::_Set(Setting<T>& fmt, T value, FMT_SCOPE scope) {
switch(scope) {
case FmtScope::Local:
case LOCAL:
m_modifiedSettings.push(fmt.set(value));
break;
case FmtScope::Global:
case GLOBAL:
fmt.set(value);
m_globalModifiedSettings.push(fmt.set(value)); // this pushes an identity set, so when we restore,
// it restores to the value here, and not the previous one
+53 -99
View File
@@ -107,7 +107,7 @@ namespace YAML
return true;
}
void WriteCodePoint(ostream_wrapper& out, int codePoint) {
void WriteCodePoint(ostream& out, int codePoint) {
if (codePoint < 0 || codePoint > 0x10FFFF) {
codePoint = REPLACEMENT_CHARACTER;
}
@@ -128,12 +128,12 @@ namespace YAML
}
}
bool IsValidPlainScalar(const std::string& str, FlowType::value flowType, bool allowOnlyAscii) {
bool IsValidPlainScalar(const std::string& str, bool inFlow, bool allowOnlyAscii) {
if(str.empty())
return false;
// first check the start
const RegEx& start = (flowType == FlowType::Flow ? Exp::PlainScalarInFlow() : Exp::PlainScalar());
const RegEx& start = (inFlow ? Exp::PlainScalarInFlow() : Exp::PlainScalar());
if(!start.Matches(str))
return false;
@@ -142,7 +142,7 @@ namespace YAML
return false;
// then check until something is disallowed
const RegEx& disallowed = (flowType == FlowType::Flow ? Exp::EndScalarInFlow() : Exp::EndScalar())
const RegEx& disallowed = (inFlow ? Exp::EndScalarInFlow() : Exp::EndScalar())
|| (Exp::BlankOrBreak() + Exp::Comment())
|| Exp::NotPrintable()
|| Exp::Utf8_ByteOrderMark()
@@ -152,7 +152,7 @@ namespace YAML
while(buffer) {
if(disallowed.Matches(buffer))
return false;
if(allowOnlyAscii && (0x80 <= static_cast<unsigned char>(buffer[0])))
if(allowOnlyAscii && (0x7F < static_cast<unsigned char>(buffer[0])))
return false;
++buffer;
}
@@ -160,53 +160,30 @@ namespace YAML
return true;
}
bool IsValidSingleQuotedScalar(const std::string& str, bool escapeNonAscii)
{
// TODO: check for non-printable characters?
for(std::size_t i=0;i<str.size();i++) {
if(escapeNonAscii && (0x80 <= static_cast<unsigned char>(str[i])))
return false;
if(str[i] == '\n')
return false;
}
return true;
}
bool IsValidLiteralScalar(const std::string& str, FlowType::value flowType, bool escapeNonAscii)
{
if(flowType == FlowType::Flow)
return false;
// TODO: check for non-printable characters?
for(std::size_t i=0;i<str.size();i++) {
if(escapeNonAscii && (0x80 <= static_cast<unsigned char>(str[i])))
return false;
}
return true;
}
void WriteDoubleQuoteEscapeSequence(ostream_wrapper& out, int codePoint) {
void WriteDoubleQuoteEscapeSequence(ostream& out, int codePoint) {
static const char hexDigits[] = "0123456789abcdef";
out << "\\";
char escSeq[] = "\\U00000000";
int digits = 8;
if(codePoint < 0xFF) {
out << "x";
if (codePoint < 0xFF) {
escSeq[1] = 'x';
digits = 2;
} else if(codePoint < 0xFFFF) {
out << "u";
} else if (codePoint < 0xFFFF) {
escSeq[1] = 'u';
digits = 4;
} else {
out << "U";
digits = 8;
}
}
// Write digits into the escape sequence
for (; digits > 0; --digits)
out << hexDigits[(codePoint >> (4 * (digits - 1))) & 0xF];
int i = 2;
for (; digits > 0; --digits, ++i) {
escSeq[i] = hexDigits[(codePoint >> (4 * (digits - 1))) & 0xF];
}
escSeq[i] = 0; // terminate with NUL character
out << escSeq;
}
bool WriteAliasName(ostream_wrapper& out, const std::string& str) {
bool WriteAliasName(ostream& out, const std::string& str) {
int codePoint;
for(std::string::const_iterator i = str.begin();
GetNextCodePointAndAdvance(codePoint, i, str.end());
@@ -221,31 +198,16 @@ namespace YAML
}
}
StringFormat::value ComputeStringFormat(const std::string& str, EMITTER_MANIP strFormat, FlowType::value flowType, bool escapeNonAscii)
{
switch(strFormat) {
case Auto:
if(IsValidPlainScalar(str, flowType, escapeNonAscii))
return StringFormat::Plain;
return StringFormat::DoubleQuoted;
case SingleQuoted:
if(IsValidSingleQuotedScalar(str, escapeNonAscii))
return StringFormat::SingleQuoted;
return StringFormat::DoubleQuoted;
case DoubleQuoted:
return StringFormat::DoubleQuoted;
case Literal:
if(IsValidLiteralScalar(str, flowType, escapeNonAscii))
return StringFormat::Literal;
return StringFormat::DoubleQuoted;
default:
break;
}
return StringFormat::DoubleQuoted;
}
bool WriteSingleQuotedString(ostream_wrapper& out, const std::string& str)
bool WriteString(ostream& out, const std::string& str, bool inFlow, bool escapeNonAscii)
{
if(IsValidPlainScalar(str, inFlow, escapeNonAscii)) {
out << str;
return true;
} else
return WriteDoubleQuotedString(out, str, escapeNonAscii);
}
bool WriteSingleQuotedString(ostream& out, const std::string& str)
{
out << "'";
int codePoint;
@@ -265,7 +227,7 @@ namespace YAML
return true;
}
bool WriteDoubleQuotedString(ostream_wrapper& out, const std::string& str, bool escapeNonAscii)
bool WriteDoubleQuotedString(ostream& out, const std::string& str, bool escapeNonAscii)
{
out << "\"";
int codePoint;
@@ -273,29 +235,24 @@ namespace YAML
GetNextCodePointAndAdvance(codePoint, i, str.end());
)
{
switch(codePoint) {
case '\"': out << "\\\""; break;
case '\\': out << "\\\\"; break;
case '\n': out << "\\n"; break;
case '\t': out << "\\t"; break;
case '\r': out << "\\r"; break;
case '\b': out << "\\b"; break;
default:
if(codePoint < 0x20 || (codePoint >= 0x80 && codePoint <= 0xA0)) // Control characters and non-breaking space
WriteDoubleQuoteEscapeSequence(out, codePoint);
else if (codePoint == 0xFEFF) // Byte order marks (ZWNS) should be escaped (YAML 1.2, sec. 5.2)
WriteDoubleQuoteEscapeSequence(out, codePoint);
else if (escapeNonAscii && codePoint > 0x7E)
WriteDoubleQuoteEscapeSequence(out, codePoint);
else
WriteCodePoint(out, codePoint);
}
if (codePoint == '\"')
out << "\\\"";
else if (codePoint == '\\')
out << "\\\\";
else if (codePoint < 0x20 || (codePoint >= 0x80 && codePoint <= 0xA0)) // Control characters and non-breaking space
WriteDoubleQuoteEscapeSequence(out, codePoint);
else if (codePoint == 0xFEFF) // Byte order marks (ZWNS) should be escaped (YAML 1.2, sec. 5.2)
WriteDoubleQuoteEscapeSequence(out, codePoint);
else if (escapeNonAscii && codePoint > 0x7E)
WriteDoubleQuoteEscapeSequence(out, codePoint);
else
WriteCodePoint(out, codePoint);
}
out << "\"";
return true;
}
bool WriteLiteralString(ostream_wrapper& out, const std::string& str, int indent)
bool WriteLiteralString(ostream& out, const std::string& str, int indent)
{
out << "|\n";
out << IndentTo(indent);
@@ -312,7 +269,7 @@ namespace YAML
return true;
}
bool WriteChar(ostream_wrapper& out, char ch)
bool WriteChar(ostream& out, char ch)
{
if(('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z'))
out << ch;
@@ -332,39 +289,36 @@ namespace YAML
return true;
}
bool WriteComment(ostream_wrapper& out, const std::string& str, int postCommentIndent)
bool WriteComment(ostream& out, const std::string& str, int postCommentIndent)
{
const unsigned curIndent = out.col();
out << "#" << Indentation(postCommentIndent);
out.set_comment();
int codePoint;
for(std::string::const_iterator i = str.begin();
GetNextCodePointAndAdvance(codePoint, i, str.end());
)
{
if(codePoint == '\n') {
if(codePoint == '\n')
out << "\n" << IndentTo(curIndent) << "#" << Indentation(postCommentIndent);
out.set_comment();
} else {
else
WriteCodePoint(out, codePoint);
}
}
return true;
}
bool WriteAlias(ostream_wrapper& out, const std::string& str)
bool WriteAlias(ostream& out, const std::string& str)
{
out << "*";
return WriteAliasName(out, str);
}
bool WriteAnchor(ostream_wrapper& out, const std::string& str)
bool WriteAnchor(ostream& out, const std::string& str)
{
out << "&";
return WriteAliasName(out, str);
}
bool WriteTag(ostream_wrapper& out, const std::string& str, bool verbatim)
bool WriteTag(ostream& out, const std::string& str, bool verbatim)
{
out << (verbatim ? "!<" : "!");
StringCharSource buffer(str.c_str(), str.size());
@@ -384,7 +338,7 @@ namespace YAML
return true;
}
bool WriteTagWithPrefix(ostream_wrapper& out, const std::string& prefix, const std::string& tag)
bool WriteTagWithPrefix(ostream& out, const std::string& prefix, const std::string& tag)
{
out << "!";
StringCharSource prefixBuffer(prefix.c_str(), prefix.size());
@@ -414,7 +368,7 @@ namespace YAML
return true;
}
bool WriteBinary(ostream_wrapper& out, const Binary& binary)
bool WriteBinary(ostream& out, const Binary& binary)
{
WriteDoubleQuotedString(out, EncodeBase64(binary.data(), binary.size()), false);
return true;
+12 -16
View File
@@ -6,30 +6,26 @@
#endif
#include "emitterstate.h"
#include "yaml-cpp/ostream_wrapper.h"
#include "yaml-cpp/ostream.h"
#include <string>
namespace YAML
{
class Binary;
struct StringFormat { enum value { Plain, SingleQuoted, DoubleQuoted, Literal }; };
namespace Utils
{
StringFormat::value ComputeStringFormat(const std::string& str, EMITTER_MANIP strFormat, FlowType::value flowType, bool escapeNonAscii);
bool WriteSingleQuotedString(ostream_wrapper& out, const std::string& str);
bool WriteDoubleQuotedString(ostream_wrapper& out, const std::string& str, bool escapeNonAscii);
bool WriteLiteralString(ostream_wrapper& out, const std::string& str, int indent);
bool WriteChar(ostream_wrapper& out, char ch);
bool WriteComment(ostream_wrapper& out, const std::string& str, int postCommentIndent);
bool WriteAlias(ostream_wrapper& out, const std::string& str);
bool WriteAnchor(ostream_wrapper& out, const std::string& str);
bool WriteTag(ostream_wrapper& out, const std::string& str, bool verbatim);
bool WriteTagWithPrefix(ostream_wrapper& out, const std::string& prefix, const std::string& tag);
bool WriteBinary(ostream_wrapper& out, const Binary& binary);
bool WriteString(ostream& out, const std::string& str, bool inFlow, bool escapeNonAscii);
bool WriteSingleQuotedString(ostream& out, const std::string& str);
bool WriteDoubleQuotedString(ostream& out, const std::string& str, bool escapeNonAscii);
bool WriteLiteralString(ostream& out, const std::string& str, int indent);
bool WriteChar(ostream& out, char ch);
bool WriteComment(ostream& out, const std::string& str, int postCommentIndent);
bool WriteAlias(ostream& out, const std::string& str);
bool WriteAnchor(ostream& out, const std::string& str);
bool WriteTag(ostream& out, const std::string& str, bool verbatim);
bool WriteTagWithPrefix(ostream& out, const std::string& prefix, const std::string& tag);
bool WriteBinary(ostream& out, const Binary& binary);
}
}
+1 -1
View File
@@ -91,7 +91,7 @@ namespace YAML
return e;
}
inline const RegEx& Key() {
static const RegEx e = RegEx('?') + BlankOrBreak();
static const RegEx e = RegEx('?');
return e;
}
inline const RegEx& KeyInFlow() {
+3 -3
View File
@@ -6,7 +6,7 @@
#endif
#include "yaml-cpp/ostream_wrapper.h"
#include "yaml-cpp/ostream.h"
#include <iostream>
namespace YAML
@@ -16,7 +16,7 @@ namespace YAML
unsigned n;
};
inline ostream_wrapper& operator << (ostream_wrapper& out, const Indentation& indent) {
inline ostream& operator << (ostream& out, const Indentation& indent) {
for(unsigned i=0;i<indent.n;i++)
out << ' ';
return out;
@@ -27,7 +27,7 @@ namespace YAML
unsigned n;
};
inline ostream_wrapper& operator << (ostream_wrapper& out, const IndentTo& indent) {
inline ostream& operator << (ostream& out, const IndentTo& indent) {
while(out.col() < indent.n)
out << ' ';
return out;
-14
View File
@@ -1,14 +0,0 @@
#include "yaml-cpp/node/node.h"
#include "nodebuilder.h"
#include "nodeevents.h"
namespace YAML
{
Node Clone(const Node& node)
{
NodeEvents events(node);
NodeBuilder builder;
events.Emit(builder);
return builder.Root();
}
}
+63
View File
@@ -0,0 +1,63 @@
#include "yaml-cpp/ostream.h"
#include <cstring>
namespace YAML
{
ostream::ostream(): m_buffer(0), m_pos(0), m_size(0), m_row(0), m_col(0)
{
reserve(1024);
}
ostream::~ostream()
{
delete [] m_buffer;
}
void ostream::reserve(unsigned size)
{
if(size <= m_size)
return;
char *newBuffer = new char[size];
std::memset(newBuffer, 0, size * sizeof(char));
std::memcpy(newBuffer, m_buffer, m_size * sizeof(char));
delete [] m_buffer;
m_buffer = newBuffer;
m_size = size;
}
void ostream::put(char ch)
{
if(m_pos >= m_size - 1) // an extra space for the NULL terminator
reserve(m_size * 2);
m_buffer[m_pos] = ch;
m_pos++;
if(ch == '\n') {
m_row++;
m_col = 0;
} else
m_col++;
}
ostream& operator << (ostream& out, const char *str)
{
std::size_t length = std::strlen(str);
for(std::size_t i=0;i<length;i++)
out.put(str[i]);
return out;
}
ostream& operator << (ostream& out, const std::string& str)
{
out << str.c_str();
return out;
}
ostream& operator << (ostream& out, char ch)
{
out.put(ch);
return out;
}
}
-56
View File
@@ -1,56 +0,0 @@
#include "yaml-cpp/ostream_wrapper.h"
#include <cstring>
#include <iostream>
namespace YAML
{
ostream_wrapper::ostream_wrapper(): m_pStream(0), m_pos(0), m_row(0), m_col(0), m_comment(false)
{
}
ostream_wrapper::ostream_wrapper(std::ostream& stream): m_pStream(&stream), m_pos(0), m_row(0), m_col(0), m_comment(false)
{
}
ostream_wrapper::~ostream_wrapper()
{
}
void ostream_wrapper::write(const std::string& str)
{
if(m_pStream) {
m_pStream->write(str.c_str(), str.size());
} else {
m_buffer.resize(std::max(m_buffer.size(), m_pos + str.size() + 1));
std::copy(str.begin(), str.end(), &m_buffer[m_pos]);
}
for(std::size_t i=0;i<str.size();i++)
update_pos(str[i]);
}
void ostream_wrapper::write(const char *str, std::size_t size)
{
if(m_pStream) {
m_pStream->write(str, size);
} else {
m_buffer.resize(std::max(m_buffer.size(), m_pos + size + 1));
std::copy(str, str + size, &m_buffer[m_pos]);
}
for(std::size_t i=0;i<size;i++)
update_pos(str[i]);
}
void ostream_wrapper::update_pos(char ch)
{
m_pos++;
m_col++;
if(ch == '\n') {
m_row++;
m_col = 0;
m_comment = false;
}
}
}
-4
View File
@@ -30,8 +30,6 @@ namespace YAML
Node LoadFile(const std::string& filename) {
std::ifstream fin(filename.c_str());
if(!fin)
throw BadFile();
return Load(fin);
}
@@ -61,8 +59,6 @@ namespace YAML
std::vector<Node> LoadAllFromFile(const std::string& filename) {
std::ifstream fin(filename.c_str());
if(!fin)
throw BadFile();
return LoadAll(fin);
}
}
+1 -4
View File
@@ -38,10 +38,7 @@ public:
}
T& top() { return *m_data.back(); }
const T& top() const { return *m_data.back(); }
T& top(std::ptrdiff_t diff) { return **(m_data.end() - 1 + diff); }
const T& top(std::ptrdiff_t diff) const { return **(m_data.end() - 1 + diff); }
private:
std::vector<T*> m_data;
};
+1 -8
View File
@@ -51,13 +51,6 @@ namespace YAML
return m_tokens.front();
}
// mark
// . Returns the current mark in the stream
Mark Scanner::mark() const
{
return INPUT.mark();
}
// EnsureTokensInQueue
// . Scan until there's a valid token at the front of the queue,
// or we're sure the queue is empty.
@@ -383,7 +376,7 @@ namespace YAML
// . Does not parse any more tokens.
void Scanner::ThrowParserException(const std::string& msg) const
{
Mark mark = Mark::null_mark();
Mark mark = Mark::null();
if(!m_tokens.empty()) {
const Token& token = m_tokens.front();
mark = token.mark;
-1
View File
@@ -31,7 +31,6 @@ namespace YAML
bool empty();
void pop();
Token& peek();
Mark mark() const;
private:
struct IndentMarker {
+6 -12
View File
@@ -48,7 +48,7 @@ namespace YAML
{
// an empty node *is* a possibility
if(m_scanner.empty()) {
eventHandler.OnNull(m_scanner.mark(), NullAnchor);
eventHandler.OnNull(Mark::null(), NullAnchor);
return;
}
@@ -57,7 +57,7 @@ namespace YAML
// special case: a value node by itself must be a map, with no header
if(m_scanner.peek().type == Token::VALUE) {
eventHandler.OnMapStart(mark, "?", NullAnchor);
eventHandler.OnMapStart(mark, "", NullAnchor);
HandleMap(eventHandler);
eventHandler.OnMapEnd();
return;
@@ -136,7 +136,7 @@ namespace YAML
while(1) {
if(m_scanner.empty())
throw ParserException(m_scanner.mark(), ErrorMsg::END_OF_SEQ);
throw ParserException(Mark::null(), ErrorMsg::END_OF_SEQ);
Token token = m_scanner.peek();
if(token.type != Token::BLOCK_ENTRY && token.type != Token::BLOCK_SEQ_END)
@@ -169,7 +169,7 @@ namespace YAML
while(1) {
if(m_scanner.empty())
throw ParserException(m_scanner.mark(), ErrorMsg::END_OF_SEQ_FLOW);
throw ParserException(Mark::null(), ErrorMsg::END_OF_SEQ_FLOW);
// first check for end
if(m_scanner.peek().type == Token::FLOW_SEQ_END) {
@@ -179,9 +179,6 @@ namespace YAML
// then read the node
HandleNode(eventHandler);
if(m_scanner.empty())
throw ParserException(m_scanner.mark(), ErrorMsg::END_OF_SEQ_FLOW);
// now eat the separator (or could be a sequence end, which we ignore - but if it's neither, then it's a bad node)
Token& token = m_scanner.peek();
@@ -214,7 +211,7 @@ namespace YAML
while(1) {
if(m_scanner.empty())
throw ParserException(m_scanner.mark(), ErrorMsg::END_OF_MAP);
throw ParserException(Mark::null(), ErrorMsg::END_OF_MAP);
Token token = m_scanner.peek();
if(token.type != Token::KEY && token.type != Token::VALUE && token.type != Token::BLOCK_MAP_END)
@@ -253,7 +250,7 @@ namespace YAML
while(1) {
if(m_scanner.empty())
throw ParserException(m_scanner.mark(), ErrorMsg::END_OF_MAP_FLOW);
throw ParserException(Mark::null(), ErrorMsg::END_OF_MAP_FLOW);
Token& token = m_scanner.peek();
// first check for end
@@ -277,9 +274,6 @@ namespace YAML
} else {
eventHandler.OnNull(token.mark, NullAnchor);
}
if(m_scanner.empty())
throw ParserException(m_scanner.mark(), ErrorMsg::END_OF_MAP_FLOW);
// now eat the separator (or could be a map end, which we ignore - but if it's neither, then it's a bad node)
Token& nextToken = m_scanner.peek();
-64
View File
@@ -1,64 +0,0 @@
#include "parsertests.h"
#include "handlermacros.h"
#include "yaml-cpp/yaml.h"
#include <iostream>
namespace Test
{
namespace Parser {
TEST NoEndOfMapFlow()
{
try {
HANDLE("---{header: {id: 1");
} catch(const YAML::ParserException& e) {
YAML_ASSERT(e.msg == std::string(YAML::ErrorMsg::END_OF_MAP_FLOW));
return true;
}
return " no exception caught";
}
TEST PlainScalarStartingWithQuestionMark()
{
HANDLE("foo: ?bar");
EXPECT_DOC_START();
EXPECT_MAP_START("?", 0);
EXPECT_SCALAR("?", 0, "foo");
EXPECT_SCALAR("?", 0, "?bar");
EXPECT_MAP_END();
EXPECT_DOC_END();
DONE();
}
}
namespace {
void RunParserTest(TEST (*test)(), const std::string& name, int& passed, int& total) {
TEST ret;
try {
ret = test();
} catch(const YAML::Exception& e) {
ret.ok = false;
ret.error = std::string(" Exception caught: ") + e.what();
}
if(!ret.ok) {
std::cout << "Parser test failed: " << name << "\n";
std::cout << ret.error << "\n";
}
if(ret.ok)
passed++;
total++;
}
}
bool RunParserTests()
{
int passed = 0;
int total = 0;
RunParserTest(&Parser::NoEndOfMapFlow, "No end of map flow", passed, total);
RunParserTest(&Parser::PlainScalarStartingWithQuestionMark, "Plain scalar starting with question mark", passed, total);
std::cout << "Parser tests: " << passed << "/" << total << " passed\n";
return passed == total;
}
}
File diff suppressed because it is too large Load Diff
-184
View File
@@ -1,184 +0,0 @@
import sys
import yaml
import hashlib
NS = 'Emitter'
DEFINE = 'YAML_GEN_TESTS'
EVENT_COUNT = 5
def encode_stream(line):
for c in line:
if c == '\n':
yield '\\n'
elif c == '"':
yield '\\"'
elif c == '\t':
yield '\\t'
elif ord(c) < 0x20:
yield '\\x' + hex(ord(c))
else:
yield c
def encode(line):
return ''.join(encode_stream(line))
def doc_start(implicit=False):
if implicit:
return {'emit': '', 'handle': 'DOC_START()'}
else:
return {'emit': 'YAML::BeginDoc', 'handle': 'DOC_START()'}
def doc_end(implicit=False):
if implicit:
return {'emit': '', 'handle': 'DOC_END()'}
else:
return {'emit': 'YAML::EndDoc', 'handle': 'DOC_END()'}
def scalar(value, tag='', anchor='', anchor_id=0):
emit = []
if tag:
emit += ['YAML::VerbatimTag("%s")' % encode(tag)]
if anchor:
emit += ['YAML::Anchor("%s")' % encode(anchor)]
if tag:
out_tag = encode(tag)
else:
if value == encode(value):
out_tag = '?'
else:
out_tag = '!'
emit += ['"%s"' % encode(value)]
return {'emit': emit, 'handle': 'SCALAR("%s", %s, "%s")' % (out_tag, anchor_id, encode(value))}
def comment(value):
return {'emit': 'YAML::Comment("%s")' % value, 'handle': ''}
def seq_start(tag='', anchor='', anchor_id=0):
emit = []
if tag:
emit += ['YAML::VerbatimTag("%s")' % encode(tag)]
if anchor:
emit += ['YAML::Anchor("%s")' % encode(anchor)]
if tag:
out_tag = encode(tag)
else:
out_tag = '?'
emit += ['YAML::BeginSeq']
return {'emit': emit, 'handle': 'SEQ_START("%s", %s)' % (out_tag, anchor_id)}
def seq_end():
return {'emit': 'YAML::EndSeq', 'handle': 'SEQ_END()'}
def map_start(tag='', anchor='', anchor_id=0):
emit = []
if tag:
emit += ['YAML::VerbatimTag("%s")' % encode(tag)]
if anchor:
emit += ['YAML::Anchor("%s")' % encode(anchor)]
if tag:
out_tag = encode(tag)
else:
out_tag = '?'
emit += ['YAML::BeginMap']
return {'emit': emit, 'handle': 'MAP_START("%s", %s)' % (out_tag, anchor_id)}
def map_end():
return {'emit': 'YAML::EndMap', 'handle': 'MAP_END()'}
def gen_templates():
yield [[doc_start(), doc_start(True)],
[scalar('foo'), scalar('foo\n'), scalar('foo', 'tag'), scalar('foo', '', 'anchor', 1)],
[doc_end(), doc_end(True)]]
yield [[doc_start(), doc_start(True)],
[seq_start()],
[[], [scalar('foo')], [scalar('foo', 'tag')], [scalar('foo', '', 'anchor', 1)], [scalar('foo', 'tag', 'anchor', 1)], [scalar('foo'), scalar('bar')], [scalar('foo', 'tag', 'anchor', 1), scalar('bar', 'tag', 'other', 2)]],
[seq_end()],
[doc_end(), doc_end(True)]]
yield [[doc_start(), doc_start(True)],
[map_start()],
[[], [scalar('foo'), scalar('bar')], [scalar('foo', 'tag', 'anchor', 1), scalar('bar', 'tag', 'other', 2)]],
[map_end()],
[doc_end(), doc_end(True)]]
yield [[doc_start(True)],
[map_start()],
[[scalar('foo')], [seq_start(), scalar('foo'), seq_end()], [map_start(), scalar('foo'), scalar('bar'), map_end()]],
[[scalar('foo')], [seq_start(), scalar('foo'), seq_end()], [map_start(), scalar('foo'), scalar('bar'), map_end()]],
[map_end()],
[doc_end(True)]]
yield [[doc_start(True)],
[seq_start()],
[[scalar('foo')], [seq_start(), scalar('foo'), seq_end()], [map_start(), scalar('foo'), scalar('bar'), map_end()]],
[[scalar('foo')], [seq_start(), scalar('foo'), seq_end()], [map_start(), scalar('foo'), scalar('bar'), map_end()]],
[seq_end()],
[doc_end(True)]]
def expand(template):
if len(template) == 0:
pass
elif len(template) == 1:
for item in template[0]:
if isinstance(item, list):
yield item
else:
yield [item]
else:
for car in expand(template[:1]):
for cdr in expand(template[1:]):
yield car + cdr
def gen_events():
for template in gen_templates():
for events in expand(template):
base = list(events)
for i in range(0, len(base)+1):
cpy = list(base)
cpy.insert(i, comment('comment'))
yield cpy
def gen_tests():
for events in gen_events():
name = 'test' + hashlib.sha1(''.join(yaml.dump(event) for event in events)).hexdigest()[:20]
yield {'name': name, 'events': events}
def create_emitter_tests(out):
out.write('#ifdef %s\n' % DEFINE)
out.write('namespace %s {\n' % NS)
tests = list(gen_tests())
for test in tests:
out.write('TEST %s(YAML::Emitter& out)\n' % test['name'])
out.write('{\n')
for event in test['events']:
emit = event['emit']
if isinstance(emit, list):
for e in emit:
out.write(' out << %s;\n' % e)
elif emit:
out.write(' out << %s;\n' % emit)
out.write('\n')
out.write(' HANDLE(out.c_str());\n')
for event in test['events']:
handle = event['handle']
if handle:
out.write(' EXPECT_%s;\n' % handle)
out.write(' DONE();\n')
out.write('}\n')
out.write('}\n')
out.write('#endif // %s\n\n' % DEFINE)
out.write('void RunGenEmitterTests(int& passed, int& total)\n')
out.write('{\n')
out.write('#ifdef %s\n' % DEFINE)
for test in tests:
out.write(' RunGenEmitterTest(&Emitter::%s, "%s", passed, total);\n' % (test['name'], encode(test['name'])))
out.write('#else // %s\n' % DEFINE)
out.write(' (void)passed; (void)total;\n')
out.write('#endif // %s\n' % DEFINE)
out.write('}\n')
if __name__ == '__main__':
create_emitter_tests(sys.stdout)
+62 -81
View File
@@ -1,5 +1,4 @@
#include "tests.h"
#include "handlermacros.h"
#include "yaml-cpp/yaml.h"
#include <iostream>
@@ -191,7 +190,7 @@ namespace Test
out << YAML::Value << "demon";
out << YAML::EndMap;
desiredOutput = "? - 1\n - 3\n: monster\n? [2, 0]\n: demon";
desiredOutput = "?\n - 1\n - 3\n: monster\n? [2, 0]\n: demon";
}
void AutoLongKey(YAML::Emitter& out, std::string& desiredOutput)
@@ -205,7 +204,7 @@ namespace Test
out << YAML::Value << "angel";
out << YAML::EndMap;
desiredOutput = "? - 1\n - 3\n: monster\n[2, 0]: demon\nthe origin: angel";
desiredOutput = "?\n - 1\n - 3\n: monster\n? [2, 0]\n: demon\nthe origin: angel";
}
void ScalarFormat(YAML::Emitter& out, std::string& desiredOutput)
@@ -219,7 +218,7 @@ namespace Test
out << YAML::Literal << "literal scalar\nthat may span\nmany, many\nlines and have \"whatever\" crazy\tsymbols that we like";
out << YAML::EndSeq;
desiredOutput = "- simple scalar\n- 'explicit single-quoted scalar'\n- \"explicit double-quoted scalar\"\n- \"auto-detected\\ndouble-quoted scalar\"\n- a non-\"auto-detected\" double-quoted scalar\n- |\n literal scalar\n that may span\n many, many\n lines and have \"whatever\" crazy\tsymbols that we like";
desiredOutput = "- simple scalar\n- 'explicit single-quoted scalar'\n- \"explicit double-quoted scalar\"\n- \"auto-detected\\x0adouble-quoted scalar\"\n- a non-\"auto-detected\" double-quoted scalar\n- |\n literal scalar\n that may span\n many, many\n lines and have \"whatever\" crazy\tsymbols that we like";
}
void AutoLongKeyScalar(YAML::Emitter& out, std::string& desiredOutput)
@@ -257,7 +256,7 @@ namespace Test
out << "total value";
out << YAML::EndMap;
desiredOutput = "? key: value\n next key: next value\n: total value";
desiredOutput = "?\n key: value\n next key: next value\n: total value";
}
void AliasAndAnchor(YAML::Emitter& out, std::string& desiredOutput)
@@ -540,7 +539,7 @@ namespace Test
{
out << YAML::Flow << YAML::BeginSeq << "foo" << YAML::Comment("foo!") << "bar" << YAML::EndSeq;
desiredOutput = "[foo, # foo!\nbar]";
desiredOutput = "[foo # foo!\n, bar]";
}
void CommentInFlowMap(YAML::Emitter& out, std::string& desiredOutput)
@@ -551,7 +550,7 @@ namespace Test
out << YAML::Key << "baz" << YAML::Value << "baz value" << YAML::Comment("baz!");
out << YAML::EndMap;
desiredOutput = "{foo: foo value, bar: bar value, # bar!\nbaz: baz value, # baz!\n}";
desiredOutput = "{foo: foo value, bar: bar value # bar!\n, baz: baz value # baz!\n}";
}
void Indentation(YAML::Emitter& out, std::string& desiredOutput)
@@ -564,7 +563,7 @@ namespace Test
out << YAML::EndMap;
out << YAML::EndSeq;
desiredOutput = "- key 1: value 1\n key 2:\n - a\n - b\n - c";
desiredOutput = "- key 1: value 1\n key 2:\n - a\n - b\n - c";
}
void SimpleGlobalSettings(YAML::Emitter& out, std::string& desiredOutput)
@@ -598,7 +597,7 @@ namespace Test
out << YAML::EndMap;
out << YAML::EndSeq;
desiredOutput = "- key 1: value 1\n key 2: [a, b, c]\n- [1, 2]:\n a: b";
desiredOutput = "- key 1: value 1\n key 2: [a, b, c]\n- ? [1, 2]\n :\n a: b";
}
void Null(YAML::Emitter& out, std::string& desiredOutput)
@@ -721,7 +720,7 @@ namespace Test
out << YAML::Flow << YAML::BeginSeq;
out << "a" << YAML::Newline << "b" << "c" << YAML::Newline << "d";
out << YAML::EndSeq;
desiredOutput = "[a,\nb, c,\nd]";
desiredOutput = "[a\n, b, c\n, d]";
}
void NewlineInBlockMap(YAML::Emitter& out, std::string& desiredOutput)
@@ -731,7 +730,7 @@ namespace Test
out << YAML::Key << "b" << YAML::Newline << YAML::Value << "bar";
out << YAML::LongKey << YAML::Key << "c" << YAML::Newline << YAML::Value << "car";
out << YAML::EndMap;
desiredOutput = "a: foo\nb:\n bar\n? c\n\n: car";
desiredOutput = "a: foo\n\nb: bar\n? c\n\n: car";
}
void NewlineInFlowMap(YAML::Emitter& out, std::string& desiredOutput)
@@ -740,7 +739,7 @@ namespace Test
out << YAML::Key << "a" << YAML::Value << "foo" << YAML::Newline;
out << YAML::Key << "b" << YAML::Value << "bar";
out << YAML::EndMap;
desiredOutput = "{a: foo,\nb: bar}";
desiredOutput = "{a: foo\n, b: bar}";
}
void LotsOfNewlines(YAML::Emitter& out, std::string& desiredOutput)
@@ -756,7 +755,7 @@ namespace Test
out << YAML::LongKey << YAML::Key << "f" << YAML::Newline << YAML::Value << "foo";
out << YAML::EndMap;
out << YAML::EndSeq;
desiredOutput = "- a\n\n-\n - b\n - c\n\n\n-\n d:\n e\n ? f\n\n : foo";
desiredOutput = "- a\n\n-\n - b\n - c\n\n\n-\n d: e\n ? f\n\n : foo";
}
void Binary(YAML::Emitter& out, std::string& desiredOutput)
@@ -912,40 +911,7 @@ namespace Test
desiredOutput = "[31, 0x1f, 037]";
}
void CompactMapWithNewline(YAML::Emitter& out, std::string& desiredOutput)
{
out << YAML::Comment("Characteristics");
out << YAML::BeginSeq;
out << YAML::BeginMap;
out << YAML::Key << "color" << YAML::Value << "blue";
out << YAML::Key << "height" << YAML::Value << 120;
out << YAML::EndMap;
out << YAML::Newline << YAML::Newline;
out << YAML::Comment("Skills");
out << YAML::BeginMap;
out << YAML::Key << "attack" << YAML::Value << 23;
out << YAML::Key << "intelligence" << YAML::Value << 56;
out << YAML::EndMap;
out << YAML::EndSeq;
desiredOutput =
"# Characteristics\n"
"- color: blue\n"
" height: 120\n"
"\n"
"# Skills\n"
"- attack: 23\n"
" intelligence: 56";
}
void ForceSingleQuotedToDouble(YAML::Emitter& out, std::string& desiredOutput)
{
out << YAML::SingleQuoted << "Hello\nWorld";
desiredOutput = "\"Hello\\nWorld\"";
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////
// incorrect emitting
void ExtraEndSeq(YAML::Emitter& out, std::string& desiredError)
@@ -969,6 +935,13 @@ namespace Test
out << YAML::EndMap;
}
void BadSingleQuoted(YAML::Emitter& out, std::string& desiredError)
{
desiredError = YAML::ErrorMsg::SINGLE_QUOTED_CHAR;
out << YAML::SingleQuoted << "Hello\nWorld";
}
void InvalidAnchor(YAML::Emitter& out, std::string& desiredError)
{
desiredError = YAML::ErrorMsg::INVALID_ANCHOR;
@@ -986,6 +959,43 @@ namespace Test
out << YAML::Alias("new\nline");
out << YAML::EndSeq;
}
void MissingKey(YAML::Emitter& out, std::string& desiredError)
{
desiredError = YAML::ErrorMsg::EXPECTED_KEY_TOKEN;
out << YAML::BeginMap;
out << YAML::Key << "key" << YAML::Value << "value";
out << "missing key" << YAML::Value << "value";
out << YAML::EndMap;
}
void MissingValue(YAML::Emitter& out, std::string& desiredError)
{
desiredError = YAML::ErrorMsg::EXPECTED_VALUE_TOKEN;
out << YAML::BeginMap;
out << YAML::Key << "key" << "value";
out << YAML::EndMap;
}
void UnexpectedKey(YAML::Emitter& out, std::string& desiredError)
{
desiredError = YAML::ErrorMsg::UNEXPECTED_KEY_TOKEN;
out << YAML::BeginSeq;
out << YAML::Key << "hi";
out << YAML::EndSeq;
}
void UnexpectedValue(YAML::Emitter& out, std::string& desiredError)
{
desiredError = YAML::ErrorMsg::UNEXPECTED_VALUE_TOKEN;
out << YAML::BeginSeq;
out << YAML::Value << "hi";
out << YAML::EndSeq;
}
}
namespace {
@@ -1033,37 +1043,7 @@ namespace Test
}
total++;
}
void RunGenEmitterTest(TEST (*test)(YAML::Emitter&), const std::string& name, int& passed, int& total) {
YAML::Emitter out;
TEST ret;
try {
ret = test(out);
} catch(const YAML::Exception& e) {
ret.ok = false;
ret.error = std::string(" Exception caught: ") + e.what();
}
if(!out.good()) {
ret.ok = false;
ret.error = out.GetLastError();
}
if(!ret.ok) {
std::cout << "Generated emitter test failed: " << name << "\n";
std::cout << "Output:\n";
std::cout << out.c_str() << "<<<\n";
std::cout << ret.error << "\n";
}
if(ret.ok)
passed++;
total++;
}
}
#include "genemittertests.h"
bool RunEmitterTests()
{
@@ -1146,16 +1126,17 @@ namespace Test
RunEmitterTest(&Emitter::SetPrecision, "set precision", passed, total);
RunEmitterTest(&Emitter::DashInBlockContext, "dash in block context", passed, total);
RunEmitterTest(&Emitter::HexAndOct, "hex and oct", passed, total);
RunEmitterTest(&Emitter::CompactMapWithNewline, "compact map with newline", passed, total);
RunEmitterTest(&Emitter::ForceSingleQuotedToDouble, "force single quoted to double", passed, total);
RunEmitterErrorTest(&Emitter::ExtraEndSeq, "extra EndSeq", passed, total);
RunEmitterErrorTest(&Emitter::ExtraEndMap, "extra EndMap", passed, total);
RunEmitterErrorTest(&Emitter::BadSingleQuoted, "bad single quoted string", passed, total);
RunEmitterErrorTest(&Emitter::InvalidAnchor, "invalid anchor", passed, total);
RunEmitterErrorTest(&Emitter::InvalidAlias, "invalid alias", passed, total);
RunEmitterErrorTest(&Emitter::MissingKey, "missing key", passed, total);
RunEmitterErrorTest(&Emitter::MissingValue, "missing value", passed, total);
RunEmitterErrorTest(&Emitter::UnexpectedKey, "unexpected key", passed, total);
RunEmitterErrorTest(&Emitter::UnexpectedValue, "unexpected value", passed, total);
RunEmitterErrorTest(&Emitter::BadLocalTag, "bad local tag", passed, total);
RunGenEmitterTests(passed, total);
std::cout << "Emitter tests: " << passed << "/" << total << " passed\n";
return passed == total;
-10256
View File
File diff suppressed because it is too large Load Diff
-190
View File
@@ -1,190 +0,0 @@
#include "teststruct.h"
#pragma once
#include "yaml-cpp/yaml.h"
#include "yaml-cpp/eventhandler.h"
#include <string>
#include <cassert>
namespace Test {
inline std::string Quote(const std::string& text) {
YAML::Emitter out;
out << YAML::DoubleQuoted << text;
return out.c_str();
}
struct Event {
enum Type { DocStart, DocEnd, Null, Alias, Scalar, SeqStart, SeqEnd, MapStart, MapEnd };
typedef YAML::Mark Mark;
typedef YAML::anchor_t anchor_t;
Event(Type type_, const std::string& tag_, anchor_t anchor_, const std::string& scalar_): type(type_), tag(tag_), anchor(anchor_), scalar(scalar_) {}
Type type;
std::string tag;
anchor_t anchor;
std::string scalar;
std::ostream& write(std::ostream& out) const {
switch(type) {
case DocStart:
return out << "DocStart";
case DocEnd:
return out << "DocEnd";
case Null:
return out << "Null(" << anchor << ")";
case Alias:
return out << "Alias(" << anchor << ")";
case Scalar:
return out << "Scalar(" << Quote(tag) << ", " << anchor << ", " << Quote(scalar) << ")";
case SeqStart:
return out << "SeqStart(" << Quote(tag) << ", " << anchor << ")";
case SeqEnd:
return out << "SeqEnd";
case MapStart:
return out << "MapStart(" << Quote(tag) << ", " << anchor << ")";
case MapEnd:
return out << "MapEnd";
}
assert(false);
return out;
}
};
inline std::ostream& operator << (std::ostream& out, const Event& event) {
return event.write(out);
}
inline bool operator == (const Event& a, const Event& b) {
return a.type == b.type && a.tag == b.tag && a.anchor == b.anchor && a.scalar == b.scalar;
}
inline bool operator != (const Event& a, const Event& b) {
return !(a == b);
}
class MockEventHandler: public YAML::EventHandler
{
public:
typedef YAML::Mark Mark;
typedef YAML::anchor_t anchor_t;
MockEventHandler() {}
virtual void OnDocumentStart(const Mark&) {
m_actualEvents.push_back(Event(Event::DocStart, "", 0, ""));
}
virtual void OnDocumentEnd() {
m_actualEvents.push_back(Event(Event::DocEnd, "", 0, ""));
}
virtual void OnNull(const Mark&, anchor_t anchor) {
m_actualEvents.push_back(Event(Event::Null, "", anchor, ""));
}
virtual void OnAlias(const Mark&, anchor_t anchor) {
m_actualEvents.push_back(Event(Event::Alias, "", anchor, ""));
}
virtual void OnScalar(const Mark&, const std::string& tag, anchor_t anchor, const std::string& value) {
m_actualEvents.push_back(Event(Event::Scalar, tag, anchor, value));
}
virtual void OnSequenceStart(const Mark&, const std::string& tag, anchor_t anchor) {
m_actualEvents.push_back(Event(Event::SeqStart, tag, anchor, ""));
}
virtual void OnSequenceEnd() {
m_actualEvents.push_back(Event(Event::SeqEnd, "", 0, ""));
}
virtual void OnMapStart(const Mark&, const std::string& tag, anchor_t anchor) {
m_actualEvents.push_back(Event(Event::MapStart, tag, anchor, ""));
}
virtual void OnMapEnd() {
m_actualEvents.push_back(Event(Event::MapEnd, "", 0, ""));
}
void Expect(const Event& event) { m_expectedEvents.push_back(event); }
Test::TEST Check() const {
std::size_t N = std::max(m_expectedEvents.size(), m_actualEvents.size());
for(std::size_t i=0;i<N;i++) {
if(i >= m_expectedEvents.size()) {
std::stringstream out;
for(std::size_t j=0;j<i;j++) {
out << " " << m_expectedEvents[j] << "\n";
}
out << " EXPECTED: (no event expected)\n";
out << " ACTUAL : " << m_actualEvents[i] << "\n";
return out.str().c_str();
}
if(i >= m_actualEvents.size()) {
std::stringstream out;
for(std::size_t j=0;j<i;j++) {
out << " " << m_expectedEvents[j] << "\n";
}
out << " EXPECTED: " << m_expectedEvents[i] << "\n";
out << " ACTUAL : (no event recorded)\n";
return out.str().c_str();
}
if(m_expectedEvents[i] != m_actualEvents[i]) {
std::stringstream out;
for(std::size_t j=0;j<i;j++) {
out << " " << m_expectedEvents[j] << "\n";
}
out << " EXPECTED: " << m_expectedEvents[i] << "\n";
out << " ACTUAL : " << m_actualEvents[i] << "\n";
return out.str().c_str();
}
}
return true;
}
std::vector<Event> m_expectedEvents;
std::vector<Event> m_actualEvents;
};
#define HANDLE(ex)\
MockEventHandler handler;\
std::stringstream stream(ex);\
YAML::Parser parser(stream);\
while(parser.HandleNextDocument(handler)) {}
#define EXPECT_DOC_START()\
handler.Expect(Event(Event::DocStart, "", 0, ""))
#define EXPECT_DOC_END()\
handler.Expect(Event(Event::DocEnd, "", 0, ""))
#define EXPECT_NULL(anchor)\
handler.Expect(Event(Event::Null, "", anchor, ""))
#define EXPECT_ALIAS(anchor)\
handler.Expect(Event(Event::Alias, "", anchor, ""))
#define EXPECT_SCALAR(tag, anchor, value)\
handler.Expect(Event(Event::Scalar, tag, anchor, value))
#define EXPECT_SEQ_START(tag, anchor)\
handler.Expect(Event(Event::SeqStart, tag, anchor, ""))
#define EXPECT_SEQ_END()\
handler.Expect(Event(Event::SeqEnd, "", 0, ""))
#define EXPECT_MAP_START(tag, anchor)\
handler.Expect(Event(Event::MapStart, tag, anchor, ""))
#define EXPECT_MAP_END()\
handler.Expect(Event(Event::MapEnd, "", 0, ""))
#define DONE()\
return handler.Check()
}
+1 -86
View File
@@ -373,86 +373,7 @@ namespace Test
}
return true;
}
TEST CloneScalar()
{
YAML::Node node = YAML::Load("!foo monkey");
YAML::Node clone = Clone(node);
YAML_ASSERT(!(node == clone));
YAML_ASSERT(node.as<std::string>() == clone.as<std::string>());
YAML_ASSERT(node.Tag() == clone.Tag());
return true;
}
TEST CloneSeq()
{
YAML::Node node = YAML::Load("[1, 3, 5, 7]");
YAML::Node clone = Clone(node);
YAML_ASSERT(!(node == clone));
YAML_ASSERT(clone.Type() == YAML::NodeType::Sequence);
YAML_ASSERT(node.size() == clone.size());
for(std::size_t i=0;i<node.size();i++)
YAML_ASSERT(node[i].as<int>() == clone[i].as<int>());
return true;
}
TEST CloneMap()
{
YAML::Node node = YAML::Load("{foo: bar}");
YAML::Node clone = Clone(node);
YAML_ASSERT(!(node == clone));
YAML_ASSERT(clone.Type() == YAML::NodeType::Map);
YAML_ASSERT(node.size() == clone.size());
YAML_ASSERT(node["foo"].as<std::string>() == clone["foo"].as<std::string>());
return true;
}
TEST CloneAlias()
{
YAML::Node node = YAML::Load("&foo [*foo]");
YAML::Node clone = Clone(node);
YAML_ASSERT(!(node == clone));
YAML_ASSERT(clone.Type() == YAML::NodeType::Sequence);
YAML_ASSERT(node.size() == clone.size());
YAML_ASSERT(clone == clone[0]);
return true;
}
TEST ForceInsertIntoMap()
{
YAML::Node node;
node["a"] = "b";
node.force_insert("x", "y");
node.force_insert("a", 5);
YAML_ASSERT(node.size() == 3);
YAML_ASSERT(node.Type() == YAML::NodeType::Map);
bool ab = false;
bool a5 = false;
bool xy = false;
for(YAML::const_iterator it=node.begin();it!=node.end();++it) {
if(it->first.as<std::string>() == "a") {
if(it->second.as<std::string>() == "b")
ab = true;
else if(it->second.as<std::string>() == "5")
a5 = true;
} else if(it->first.as<std::string>() == "x" && it->second.as<std::string>() == "y")
xy = true;
}
YAML_ASSERT(ab);
YAML_ASSERT(a5);
YAML_ASSERT(xy);
return true;
}
TEST ClearNode()
{
YAML::Node node = YAML::Load("[1, 2, 3]");
YAML_ASSERT(!node.IsNull());
node.clear();
YAML_ASSERT(node.IsNull());
return true;
}
}
}
void RunNodeTest(TEST (*test)(), const std::string& name, int& passed, int& total) {
TEST ret;
@@ -505,12 +426,6 @@ namespace Test
RunNodeTest(&Node::IterateMap, "iterate map", passed, total);
RunNodeTest(&Node::ForEach, "for each", passed, total);
RunNodeTest(&Node::ForEachMap, "for each map", passed, total);
RunNodeTest(&Node::CloneScalar, "clone scalar", passed, total);
RunNodeTest(&Node::CloneSeq, "clone seq", passed, total);
RunNodeTest(&Node::CloneMap, "clone map", passed, total);
RunNodeTest(&Node::CloneAlias, "clone alias", passed, total);
RunNodeTest(&Node::ForceInsertIntoMap, "force insert into map", passed, total);
RunNodeTest(&Node::ClearNode, "clear node", passed, total);
std::cout << "Node tests: " << passed << "/" << total << " passed\n";
return passed == total;
+10 -1
View File
@@ -5,9 +5,18 @@
#pragma once
#endif
#include "teststruct.h"
#include <string>
namespace Test {
struct TEST {
TEST(): ok(false) {}
TEST(bool ok_): ok(ok_) {}
TEST(const char *error_): ok(false), error(error_) {}
bool ok;
std::string error;
};
namespace Spec {
// 2.1
TEST SeqScalars();
-18
View File
@@ -1,18 +0,0 @@
#pragma once
#include <string>
#define YAML_ASSERT(cond) do { if(!(cond)) return " Assert failed: " #cond; } while(false)
namespace Test
{
struct TEST {
TEST(): ok(false) {}
TEST(bool ok_): ok(ok_) {}
TEST(const char *error_): ok(false), error(error_) {}
bool ok;
std::string error;
};
}
-6
View File
@@ -1,8 +1,2 @@
add_executable(parse parse.cpp)
target_link_libraries(parse yaml-cpp)
add_executable(sandbox sandbox.cpp)
target_link_libraries(sandbox yaml-cpp)
add_executable(read read.cpp)
target_link_libraries(read yaml-cpp)
-30
View File
@@ -1,30 +0,0 @@
#include "yaml-cpp/yaml.h"
#include "yaml-cpp/eventhandler.h"
#include <iostream>
class NullEventHandler: public YAML::EventHandler
{
public:
typedef YAML::Mark Mark;
typedef YAML::anchor_t anchor_t;
NullEventHandler() {}
virtual void OnDocumentStart(const Mark&) {}
virtual void OnDocumentEnd() {}
virtual void OnNull(const Mark&, anchor_t) {}
virtual void OnAlias(const Mark&, anchor_t) {}
virtual void OnScalar(const Mark&, const std::string&, anchor_t, const std::string&) {}
virtual void OnSequenceStart(const Mark&, const std::string&, anchor_t) {}
virtual void OnSequenceEnd() {}
virtual void OnMapStart(const Mark&, const std::string&, anchor_t) {}
virtual void OnMapEnd() {}
};
int main()
{
YAML::Parser parser(std::cin);
NullEventHandler handler;
parser.HandleNextDocument(handler);
return 0;
}
-32
View File
@@ -1,32 +0,0 @@
#include "yaml-cpp/yaml.h"
#include "yaml-cpp/eventhandler.h"
#include <iostream>
class NullEventHandler: public YAML::EventHandler
{
public:
typedef YAML::Mark Mark;
typedef YAML::anchor_t anchor_t;
NullEventHandler() {}
virtual void OnDocumentStart(const Mark&) {}
virtual void OnDocumentEnd() {}
virtual void OnNull(const Mark&, anchor_t) {}
virtual void OnAlias(const Mark&, anchor_t) {}
virtual void OnScalar(const Mark&, const std::string&, anchor_t, const std::string&) {}
virtual void OnSequenceStart(const Mark&, const std::string&, anchor_t) {}
virtual void OnSequenceEnd() {}
virtual void OnMapStart(const Mark&, const std::string&, anchor_t) {}
virtual void OnMapEnd() {}
};
int main()
{
std::stringstream stream("---{header: {id: 1");
YAML::Parser parser(stream);
// parser.PrintTokens(std::cout);
NullEventHandler handler;
parser.HandleNextDocument(handler);
return 0;
}