Browse code

A complete refactor/rewrite of the original seqbias code. This should behave more or less identically, but is much more coherent.

git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/seqbias@57223 bc3139a8-67e5-0310-9ffc-ced21a209358

Daniel Jones authored on 04/08/2011 07:36:48
Showing1 changed files
... ...
@@ -1,8 +1,10 @@
1
-#pragma once
2
-
3 1
 #ifndef SCANNER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
4 2
 #define SCANNER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
5 3
 
4
+#if !defined(__GNUC__) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4) // GCC supports "pragma once" correctly since 3.4
5
+#pragma once
6
+#endif
7
+
6 8
 
7 9
 #include <ios>
8 10
 #include <string>
... ...
@@ -10,6 +12,7 @@
10 12
 #include <stack>
11 13
 #include <set>
12 14
 #include <map>
15
+#include "ptr_vector.h"
13 16
 #include "stream.h"
14 17
 #include "token.h"
15 18
 
... ...
@@ -29,11 +32,6 @@ namespace YAML
29 32
 		void pop();
30 33
 		Token& peek();
31 34
 
32
-		// anchor management
33
-		void Save(const std::string& anchor, Node* value);
34
-		const Node *Retrieve(const std::string& anchor) const;
35
-		void ClearAnchors();
36
-
37 35
 	private:
38 36
 		struct IndentMarker {
39 37
 			enum INDENT_TYPE { MAP, SEQ, NONE };
... ...
@@ -117,17 +115,16 @@ namespace YAML
117 115
 		Stream INPUT;
118 116
 
119 117
 		// the output (tokens)
120
-		std::queue <Token> m_tokens;
118
+		std::queue<Token> m_tokens;
121 119
 
122 120
 		// state info
123 121
 		bool m_startedStream, m_endedStream;
124 122
 		bool m_simpleKeyAllowed;
125 123
 		bool m_canBeJSONFlow;
126
-		std::stack <SimpleKey> m_simpleKeys;
127
-		std::stack <IndentMarker *> m_indents;
128
-		std::vector <IndentMarker *> m_indentRefs; // for "garbage collection"
129
-		std::stack <FLOW_MARKER> m_flows;
130
-		std::map <std::string, const Node *> m_anchors;
124
+		std::stack<SimpleKey> m_simpleKeys;
125
+		std::stack<IndentMarker *> m_indents;
126
+		ptr_vector<IndentMarker> m_indentRefs; // for "garbage collection"
127
+		std::stack<FLOW_MARKER> m_flows;
131 128
 	};
132 129
 }
133 130
 
Browse code

Added the seqbias package to the repository.

git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/seqbias@52013 bc3139a8-67e5-0310-9ffc-ced21a209358

Chao-Jen Wong authored on 22/01/2011 00:26:36
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,135 @@
1
+#pragma once
2
+
3
+#ifndef SCANNER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
4
+#define SCANNER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
5
+
6
+
7
+#include <ios>
8
+#include <string>
9
+#include <queue>
10
+#include <stack>
11
+#include <set>
12
+#include <map>
13
+#include "stream.h"
14
+#include "token.h"
15
+
16
+namespace YAML
17
+{
18
+	class Node;
19
+	class RegEx;
20
+
21
+	class Scanner
22
+	{
23
+	public:
24
+		Scanner(std::istream& in);
25
+		~Scanner();
26
+
27
+		// token queue management (hopefully this looks kinda stl-ish)
28
+		bool empty();
29
+		void pop();
30
+		Token& peek();
31
+
32
+		// anchor management
33
+		void Save(const std::string& anchor, Node* value);
34
+		const Node *Retrieve(const std::string& anchor) const;
35
+		void ClearAnchors();
36
+
37
+	private:
38
+		struct IndentMarker {
39
+			enum INDENT_TYPE { MAP, SEQ, NONE };
40
+			enum STATUS { VALID, INVALID, UNKNOWN };
41
+			IndentMarker(int column_, INDENT_TYPE type_): column(column_), type(type_), status(VALID), pStartToken(0) {}
42
+		
43
+			int column;
44
+			INDENT_TYPE type;
45
+			STATUS status;
46
+			Token *pStartToken;
47
+		};
48
+		
49
+		enum FLOW_MARKER { FLOW_MAP, FLOW_SEQ };
50
+	
51
+	private:	
52
+		// scanning
53
+		void EnsureTokensInQueue();
54
+		void ScanNextToken();
55
+		void ScanToNextToken();
56
+		void StartStream();
57
+		void EndStream();
58
+		Token *PushToken(Token::TYPE type);
59
+		
60
+		bool InFlowContext() const { return !m_flows.empty(); }
61
+		bool InBlockContext() const { return m_flows.empty(); }
62
+		int GetFlowLevel() const { return m_flows.size(); }
63
+		
64
+		Token::TYPE GetStartTokenFor(IndentMarker::INDENT_TYPE type) const;
65
+		IndentMarker *PushIndentTo(int column, IndentMarker::INDENT_TYPE type);
66
+		void PopIndentToHere();
67
+		void PopAllIndents();
68
+		void PopIndent();
69
+		int GetTopIndent() const;
70
+
71
+		// checking input
72
+		bool CanInsertPotentialSimpleKey() const;
73
+		bool ExistsActiveSimpleKey() const;
74
+		void InsertPotentialSimpleKey();
75
+		void InvalidateSimpleKey();
76
+		bool VerifySimpleKey();
77
+		void PopAllSimpleKeys();
78
+		
79
+		void ThrowParserException(const std::string& msg) const;
80
+
81
+		bool IsWhitespaceToBeEaten(char ch);
82
+		const RegEx& GetValueRegex() const;
83
+
84
+		struct SimpleKey {
85
+			SimpleKey(const Mark& mark_, int flowLevel_);
86
+
87
+			void Validate();
88
+			void Invalidate();
89
+			
90
+			Mark mark;
91
+			int flowLevel;
92
+			IndentMarker *pIndent;
93
+			Token *pMapStart, *pKey;
94
+		};
95
+
96
+		// and the tokens
97
+		void ScanDirective();
98
+		void ScanDocStart();
99
+		void ScanDocEnd();
100
+		void ScanBlockSeqStart();
101
+		void ScanBlockMapSTart();
102
+		void ScanBlockEnd();
103
+		void ScanBlockEntry();
104
+		void ScanFlowStart();
105
+		void ScanFlowEnd();
106
+		void ScanFlowEntry();
107
+		void ScanKey();
108
+		void ScanValue();
109
+		void ScanAnchorOrAlias();
110
+		void ScanTag();
111
+		void ScanPlainScalar();
112
+		void ScanQuotedScalar();
113
+		void ScanBlockScalar();
114
+
115
+	private:
116
+		// the stream
117
+		Stream INPUT;
118
+
119
+		// the output (tokens)
120
+		std::queue <Token> m_tokens;
121
+
122
+		// state info
123
+		bool m_startedStream, m_endedStream;
124
+		bool m_simpleKeyAllowed;
125
+		bool m_canBeJSONFlow;
126
+		std::stack <SimpleKey> m_simpleKeys;
127
+		std::stack <IndentMarker *> m_indents;
128
+		std::vector <IndentMarker *> m_indentRefs; // for "garbage collection"
129
+		std::stack <FLOW_MARKER> m_flows;
130
+		std::map <std::string, const Node *> m_anchors;
131
+	};
132
+}
133
+
134
+#endif // SCANNER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
135
+