parser.h 1.33 KB
Newer Older
1
2
#pragma once

jbeder's avatar
jbeder committed
3
4
5
6
#ifndef PARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define PARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66


7
#include "graphbuilder.h"
8
#include "noncopyable.h"
9
#include <ios>
10
#include <memory>
11
12
13

namespace YAML
{
14
15
	struct Directives;
	struct Mark;
16
	struct Token;
17
18
19
20
	class EventHandler;
	class GraphBuilderInterface;
	class Node;
	class Scanner;
21

22
	class Parser: private noncopyable
23
24
	{
	public:
25
		Parser();
26
27
28
29
30
31
		Parser(std::istream& in);
		~Parser();

		operator bool() const;

		void Load(std::istream& in);
32
33
34
35
36
37
38
39
40
41
42
43
		bool HandleNextDocument(EventHandler& eventHandler);
		
		void *BuildNextDocumentGraph(GraphBuilderInterface& graphBuilder);
		template <class Builder>
		typename Builder::Node *BuildNextDocumentGraph(Builder& graphBuilder)
		{
			GraphBuilder<Builder> wrapper(graphBuilder); // Must be lvalue to make C++ happy
			return static_cast<typename Builder::Node *>(
				BuildNextDocumentGraph(wrapper.AsBuilderInterface())
			);
		}
		
44
		bool GetNextDocument(Node& document);
45
46
47
48
		void PrintTokens(std::ostream& out);

	private:
		void ParseDirectives();
49
50
51
		void HandleDirective(const Token& token);
		void HandleYamlDirective(const Token& token);
		void HandleTagDirective(const Token& token);
52
		
53
	private:
54
		std::auto_ptr<Scanner> m_pScanner;
55
		std::auto_ptr<Directives> m_pDirectives;
56
57
	};
}
jbeder's avatar
jbeder committed
58
59

#endif // PARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66