Teuchos - Trilinos Tools Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_YAML.cpp
1 #include "Teuchos_YAML.hpp"
2 
3 #include <iostream>
4 
5 namespace Teuchos {
6 namespace YAML {
7 
8 namespace {
9 
10 Language::Productions make_productions() {
11  Language::Productions prods;
12  prods.resize(NPRODS);
13  prods[PROD_DOC]("doc") >> "top_items";
14  prods[PROD_DOC2]("doc") >> "NEWLINE", "top_items";
15  prods[PROD_TOP_FIRST]("top_items") >> "top_item";
16  prods[PROD_TOP_NEXT]("top_items") >> "top_items", "top_item";
17  prods[PROD_TOP_DIRECT]("top_item") >> "%", "any*", "NEWLINE";
18  prods[PROD_TOP_BEGIN]("top_item") >> "-", "-", "-", "NEWLINE";
19  prods[PROD_TOP_END]("top_item") >> ".", ".", ".", "NEWLINE";
20  prods[PROD_TOP_BMAP]("top_item") >> "bmap_item";
21  prods[PROD_BMAP_FIRST]("bmap_items") >> "bmap_item";
22  prods[PROD_BMAP_NEXT]("bmap_items") >> "bmap_items", "bmap_item";
23  prods[PROD_BMAP_SCALAR]("bmap_item") >> "scalar", ":", "WS*", "tag?", "map_scalar", "NEWLINE";
24  prods[PROD_BMAP_BSCALAR]("bmap_item") >> "scalar", ":", "WS*", "bscalar";
25  prods[PROD_BMAP_BVALUE]("bmap_item") >> "scalar", ":", "WS*", "NEWLINE", "bvalue";
26  prods[PROD_BVALUE_EMPTY]("bvalue");
27  prods[PROD_BVALUE_BMAP]("bvalue") >> "INDENT", "bmap_items", "DEDENT";
28  /* TODO: allow a tag in this */
29  prods[PROD_BVALUE_BSEQ]("bvalue") >> "INDENT", "bseq_items", "DEDENT";
30  prods[PROD_BMAP_FMAP]("bmap_item") >> "scalar", ":", "WS*", "tag?", "fmap", "NEWLINE";
31  prods[PROD_BMAP_FSEQ]("bmap_item") >> "scalar", ":", "WS*", "tag?", "fseq", "NEWLINE";
32  prods[PROD_BSEQ_FIRST]("bseq_items") >> "bseq_item";
33  prods[PROD_BSEQ_NEXT]("bseq_items") >> "bseq_items", "bseq_item";
34  prods[PROD_BSEQ_SCALAR]("bseq_item") >> "-", "WS+", "tag?", "scalar", "NEWLINE";
35  prods[PROD_BSEQ_BSCALAR]("bseq_item") >> "-", "WS+", "bscalar";
36  prods[PROD_BSEQ_BMAP]("bseq_item") >> "-", "NEWLINE", "INDENT", "bmap_items", "DEDENT";
37  prods[PROD_BSEQ_BMAP_TRAIL]("bseq_item") >> "-", "WS+", "NEWLINE", "INDENT", "bmap_items", "DEDENT";
38  prods[PROD_BSEQ_BSEQ]("bseq_item") >> "-", "NEWLINE", "INDENT", "bseq_items", "DEDENT";
39  prods[PROD_BSEQ_BSEQ_TRAIL]("bseq_item") >> "-", "WS+", "NEWLINE", "INDENT", "bseq_items", "DEDENT";
40  prods[PROD_BSEQ_FMAP]("bseq_item") >> "-", "WS+", "tag?", "fmap", "NEWLINE";
41  prods[PROD_BSEQ_FSEQ]("bseq_item") >> "-", "WS+", "tag?", "fseq", "NEWLINE";
42  prods[PROD_FMAP]("fmap") >> "{", "WS*", "fmap_items", "}", "WS*";
43  prods[PROD_FMAP_EMPTY]("fmap") >> "{", "WS*", "}", "WS*";
44  prods[PROD_FMAP_FIRST]("fmap_items") >> "fmap_item";
45  prods[PROD_FMAP_NEXT]("fmap_items") >> "fmap_items", ",", "WS*", "fmap_item";
46  prods[PROD_FMAP_SCALAR]("fmap_item") >> "scalar", ":", "WS*", "tag?", "scalar";
47  prods[PROD_FMAP_FMAP]("fmap_item") >> "scalar", ":", "WS*", "tag?", "fmap";
48  prods[PROD_FMAP_FSEQ]("fmap_item") >> "scalar", ":", "WS*", "tag?", "fseq";
49  prods[PROD_FSEQ]("fseq") >> "[", "WS*", "fseq_items", "]", "WS*";
50  prods[PROD_FSEQ_EMPTY]("fseq") >> "[", "WS*", "]", "WS*";
51  prods[PROD_FSEQ_FIRST]("fseq_items") >> "fseq_item";
52  prods[PROD_FSEQ_NEXT]("fseq_items") >> "fseq_items", ",", "WS*", "fseq_item";
53  prods[PROD_FSEQ_SCALAR]("fseq_item") >> "tag?", "scalar";
54  prods[PROD_FSEQ_FMAP]("fseq_item") >> "tag?", "fmap";
55  prods[PROD_FSEQ_FSEQ]("fseq_item") >> "tag?", "fseq";
56  prods[PROD_SCALAR_RAW]("scalar") >> "scalar_head", "scalar_tail*";
57  prods[PROD_SCALAR_QUOTED]("scalar") >> "scalar_quoted";
58  prods[PROD_MAP_SCALAR_RAW]("map_scalar") >> "scalar_head", "scalar_tail*", "map_scalar_escaped*";
59  prods[PROD_MAP_SCALAR_QUOTED]("map_scalar") >> "scalar_quoted";
60  prods[PROD_SCALAR_DQUOTED]("scalar_quoted") >> "\"", "dquoted*", "descape*", "\"", "WS*";
61  prods[PROD_SCALAR_SQUOTED]("scalar_quoted") >> "'", "squoted*", "sescape*", "'", "WS*";
62  prods[PROD_SCALAR_HEAD_OTHER]("scalar_head") >> "OTHERCHAR";
63  prods[PROD_SCALAR_HEAD_DOT]("scalar_head") >> ".", "OTHERCHAR";
64  prods[PROD_SCALAR_HEAD_DASH]("scalar_head") >> "-", "OTHERCHAR";
65  prods[PROD_SCALAR_HEAD_DOT_DOT]("scalar_head") >> ".", ".", "OTHERCHAR";
66  prods[PROD_MAP_SCALAR_ESCAPED_EMPTY]("map_scalar_escaped*");
67  prods[PROD_MAP_SCALAR_ESCAPED_NEXT]("map_scalar_escaped*") >> "map_scalar_escaped*", ",", "scalar_tail*";
68  prods[PROD_TAG_EMPTY]("tag?");
69  prods[PROD_TAG]("tag?") >> "!", "!", "OTHERCHAR+", "WS+";
70  prods[PROD_BSCALAR]("bscalar") >> "bscalar_header", "WS*", "NEWLINE", "INDENT", "bscalar_items", "DEDENT";
71  prods[PROD_BSCALAR_FIRST]("bscalar_items") >> "bscalar_item";
72  prods[PROD_BSCALAR_NEXT]("bscalar_items") >> "bscalar_items", "bscalar_item";
73  prods[PROD_BSCALAR_LINE]("bscalar_item") >> "any*", "NEWLINE";
74  prods[PROD_BSCALAR_INDENT]("bscalar_item") >> "INDENT", "bscalar_items", "DEDENT";
75  prods[PROD_BSCALAR_HEADER_LITERAL]("bscalar_header") >> "|", "bscalar_head_c*";
76  prods[PROD_BSCALAR_HEADER_FOLDED]("bscalar_header") >> ">", "bscalar_head_c*";
77  prods[PROD_BSCALAR_HEAD_EMPTY]("bscalar_head_c*");
78  prods[PROD_BSCALAR_HEAD_NEXT]("bscalar_head_c*") >> "bscalar_head_c*", "bscalar_head_c";
79  prods[PROD_BSCALAR_HEAD_OTHER]("bscalar_head_c") >> "OTHERCHAR";
80  prods[PROD_BSCALAR_HEAD_DASH]("bscalar_head_c") >> "-";
81  prods[PROD_DQUOTED_EMPTY]("dquoted*");
82  prods[PROD_DQUOTED_NEXT]("dquoted*") >> "dquoted*", "dquoted";
83  prods[PROD_SQUOTED_EMPTY]("squoted*");
84  prods[PROD_SQUOTED_NEXT]("squoted*") >> "squoted*", "squoted";
85  prods[PROD_ANY_EMPTY]("any*");
86  prods[PROD_ANY_NEXT]("any*") >> "any*", "any";
87  prods[PROD_DESCAPE_EMPTY]("descape*");
88  prods[PROD_DESCAPE_NEXT]("descape*") >> "descape*", "descape";
89  prods[PROD_DESCAPE]("descape") >> "\\", "descaped", "dquoted*";
90  prods[PROD_SESCAPE_EMPTY]("sescape*");
91  prods[PROD_SESCAPE_NEXT]("sescape*") >> "sescape*", "sescape";
92  prods[PROD_SESCAPE]("sescape") >> "'", "'", "squoted*";
93  prods[PROD_SCALAR_TAIL_EMPTY]("scalar_tail*");
94  prods[PROD_SCALAR_TAIL_NEXT]("scalar_tail*") >> "scalar_tail*", "scalar_tail";
95  prods[PROD_OTHER_FIRST]("OTHERCHAR+") >> "OTHERCHAR";
96  prods[PROD_OTHER_NEXT]("OTHERCHAR+") >> "OTHERCHAR+", "OTHERCHAR";
97  prods[PROD_SCALAR_TAIL_SPACE]("scalar_tail") >> "WS";
98  prods[PROD_SCALAR_TAIL_DOT]("scalar_tail") >> ".";
99  prods[PROD_SCALAR_TAIL_DASH]("scalar_tail") >> "-";
100  prods[PROD_SCALAR_TAIL_SQUOT]("scalar_tail") >> "'";
101  prods[PROD_SCALAR_TAIL_OTHER]("scalar_tail") >> "OTHERCHAR";
102  prods[PROD_DESCAPED_DQUOT]("descaped") >> "\"";
103  prods[PROD_DESCAPED_SLASH]("descaped") >> "\\";
104  prods[PROD_DESCAPED_DQUOTED]("descaped") >> "dquoted";
105  prods[PROD_DQUOTED_COMMON]("dquoted") >> "common";
106  prods[PROD_DQUOTED_SQUOT]("dquoted") >> "'";
107  prods[PROD_SQUOTED_COMMON]("squoted") >> "common";
108  prods[PROD_SQUOTED_DQUOT]("squoted") >> "\"";
109  prods[PROD_SQUOTED_SLASH]("squoted") >> "\\";
110  prods[PROD_ANY_COMMON]("any") >> "common";
111  prods[PROD_ANY_DQUOT]("any") >> "\"";
112  prods[PROD_ANY_SQUOT]("any") >> "'";
113  prods[PROD_ANY_SLASH]("any") >> "\\";
114  prods[PROD_COMMON_SPACE]("common") >> "WS";
115  prods[PROD_COMMON_COLON]("common") >> ":";
116  prods[PROD_COMMON_DOT]("common") >> ".";
117  prods[PROD_COMMON_DASH]("common") >> "-";
118  prods[PROD_COMMON_PIPE]("common") >> "|";
119  prods[PROD_COMMON_LSQUARE]("common") >> "[";
120  prods[PROD_COMMON_RSQUARE]("common") >> "]";
121  prods[PROD_COMMON_LCURLY]("common") >> "{";
122  prods[PROD_COMMON_RCURLY]("common") >> "}";
123  prods[PROD_COMMON_RANGLE]("common") >> ">";
124  prods[PROD_COMMON_COMMA]("common") >> ",";
125  prods[PROD_COMMON_PERCENT]("common") >> "%";
126  prods[PROD_COMMON_EXCL]("common") >> "!";
127  prods[PROD_COMMON_OTHER]("common") >> "OTHERCHAR";
128  prods[PROD_SPACE_STAR_EMPTY]("WS*");
129  prods[PROD_SPACE_STAR_NEXT]("WS*") >> "WS*", "WS";
130  prods[PROD_SPACE_PLUS_FIRST]("WS+") >> "WS";
131  prods[PROD_SPACE_PLUS_NEXT]("WS+") >> "WS+", "WS";
132  return prods;
133 }
134 
135 } // end anonymous namespace
136 
137 Language make_language() {
138  Language out;
139  Language::Productions& prods = out.productions;
140  prods = make_productions();
141  Language::Tokens& toks = out.tokens;
142  toks.resize(NTOKS);
143  toks[TOK_NEWLINE]("NEWLINE", "((#[^\r\n]*)?\r?\n[ \t]*)+");
144  toks[TOK_INDENT]("INDENT", "((#[^\r\n]*)?\r?\n[ \t]*)+");
145  toks[TOK_DEDENT]("DEDENT", "((#[^\r\n]*)?\r?\n[ \t]*)+");
146  toks[TOK_SPACE]("WS", "[ \t]");
147  toks[TOK_COLON](":", ":");
148  toks[TOK_DOT](".", "\\.");
149  toks[TOK_DASH]("-", "\\-");
150  toks[TOK_DQUOT]("\"", "\"");
151  toks[TOK_SQUOT]("'", "'");
152  toks[TOK_SLASH]("\\", "\\\\");
153  toks[TOK_PIPE]("|", "\\|");
154  toks[TOK_LSQUARE]("[", "\\[");
155  toks[TOK_RSQUARE]("]", "\\]");
156  toks[TOK_LCURLY]("{", "{");
157  toks[TOK_RCURLY]("}", "}");
158  toks[TOK_RANGLE](">", ">");
159  toks[TOK_COMMA](",", ",");
160  toks[TOK_PERCENT]("%", "%");
161  toks[TOK_EXCL]("!", "!");
162  toks[TOK_OTHER]("OTHERCHAR", "[^ \t:\\.\\-\"'\\\\\\|\\[\\]{}>,%#!\n\r]");
163  return out;
164 }
165 
166 LanguagePtr ask_language() {
167  static LanguagePtr ptr;
168  if (ptr.strong_count() == 0) {
169  ptr.reset(new Language(make_language()));
170  }
171  return ptr;
172 }
173 
174 ReaderTablesPtr ask_reader_tables() {
175  static ReaderTablesPtr ptr;
176  if (ptr.strong_count() == 0) {
177  ptr = make_reader_tables(*(YAML::ask_language()));
178  }
179  return ptr;
180 }
181 
182 } // end namespace YAML
183 } // end namespace Teuchos
A TeuchosParser Language for a subset of YAML.
Productions productions
vector of productions
RCP< const ReaderTables > ReaderTablesPtr
an RCP to a const ReaderTables
ReaderTablesPtr make_reader_tables(Language const &language)
constructs ReaderTables for the given Language.
RCP< const Language > LanguagePtr
an RCP to a const Language