Teuchos - Trilinos Tools Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_XML.cpp
1 #include "Teuchos_XML.hpp"
2 
3 namespace Teuchos {
4 namespace XML {
5 
6 Language make_language() {
7  Language out;
8  Language::Productions& prods = out.productions;
9  prods.resize(NPRODS);
10  prods[PROD_DOC]("document") >> "toplevels";
11  prods[PROD_TOPLEVEL]("toplevels") >> "toplevel";
12  prods[PROD_TOPLEVELS]("toplevels") >> "toplevel", "toplevels";
13  prods[PROD_TOPLEVELS_MISC]("toplevels") >> "toplevel", "Misc", "toplevels";
14  prods[PROD_TOPLEVEL_ELEMENT]("toplevel") >> "element";
15  prods[PROD_TOPLEVEL_XMLDECL]("toplevel") >> "XMLDecl";
16  prods[PROD_ELEMENT_EMPTY]("element") >> "EmptyElemTag";
17  prods[PROD_ELEMENT]("element") >> "STag", "content";
18  prods[PROD_XMLDECL]("XMLDecl") >> "<", "?", "Name", "TagFill", "?", ">";
19  prods[PROD_STAG]("STag") >> "<", "Name", "TagFill", ">";
20  prods[PROD_ETAG]("ETag") >> "<", "/", "Name", "S?", ">";
21  prods[PROD_EMPTY_TAG]("EmptyElemTag") >> "<", "Name", "TagFill", "/", ">";
22  prods[PROD_CONTENT]("content") >> "CharData?", "ContentItem*", "ETag";
23  prods[PROD_NO_CONTENT_ITEMS]("ContentItem*");
24  prods[PROD_CONTENT_ITEMS]("ContentItem*") >> "ContentItem*", "ContentItem", "CharData?";
25  prods[PROD_CONTENT_ELEMENT]("ContentItem") >> "element";
26  prods[PROD_CONTENT_REF]("ContentItem") >> "Reference";
27  prods[PROD_CONTENT_COMMENT]("ContentItem") >> "Comment";
28  prods[PROD_NO_CHARDATA]("CharData?");
29  prods[PROD_CHARDATA]("CharData?") >> "CharData?", "DataChar";
30  prods[PROD_TAGFILL]("TagFill") >> "Attributes", "S?";
31  prods[PROD_NO_ATTS]("Attributes");
32  prods[PROD_ATTS]("Attributes") >> "Attributes", "S", "Attribute";
33  prods[PROD_ATT]("Attribute") >> "Name", "Eq", "AttValue";
34  prods[PROD_EQ]("Eq") >> "S?", "=", "S?";
35  prods[PROD_ATTVALUE_D]("AttValue") >> "\"", "DQuoteds", "\"";
36  prods[PROD_ATTVALUE_S]("AttValue") >> "'", "SQuoteds", "'";
37  prods[PROD_NO_DQUOTS]("DQuoteds");
38  prods[PROD_DQUOTS]("DQuoteds") >> "DQuoteds", "DQuoted";
39  prods[PROD_DQUOT_CHAR]("DQuoted") >> "DQuotedChar";
40  prods[PROD_DQUOT_REF]("DQuoted") >> "Reference";
41  prods[PROD_NO_SQUOTS]("SQuoteds");
42  prods[PROD_SQUOTS]("SQuoteds") >> "SQuoteds", "SQuoted";
43  prods[PROD_SQUOT_CHAR]("SQuoted") >> "SQuotedChar";
44  prods[PROD_SQUOT_REF]("SQuoted") >> "Reference";
45  prods[PROD_NAME]("Name") >> "NameFirstChar", "NameChars";
46  prods[PROD_NAME_FIRST_LETTER]("NameFirstChar") >> "Letter";
47  prods[PROD_NAME_FIRST_UNDER]("NameFirstChar") >> "_";
48  prods[PROD_NAME_FIRST_COLON]("NameFirstChar") >> ":";
49  prods[PROD_NO_NAME_CHARS]("NameChars");
50  prods[PROD_NAME_CHARS]("NameChars") >> "NameChars", "NameChar";
51  prods[PROD_NAME_LETTER]("NameChar") >> "Letter";
52  prods[PROD_NAME_DIGIT]("NameChar") >> "Digit";
53  prods[PROD_NAME_DOT]("NameChar") >> ".";
54  prods[PROD_NAME_DASH]("NameChar") >> "-";
55  prods[PROD_NAME_UNDER]("NameChar") >> "_";
56  prods[PROD_NAME_COLON]("NameChar") >> ":";
57  prods[PROD_NO_MISCS]("Miscs");
58  prods[PROD_MISCS]("Miscs") >> "Miscs", "Misc";
59  prods[PROD_MISC_COMMENT]("Misc") >> "Comment";
60  prods[PROD_MISC_SPACE]("Misc") >> "S";
61  prods[PROD_COMMENT]("Comment") >> "<", "!", "-", "-", "Commenteds", "-", "-", ">";
62  prods[PROD_NO_COMMENTED]("Commenteds");
63  prods[PROD_COMMENTED]("Commenteds") >> "Commenteds", "Commented";
64  prods[PROD_COMMENT_CHAR]("Commented") >> "CommentChar";
65  prods[PROD_COMMENT_DASH]("Commented") >> "-", "CommentChar";
66  prods[PROD_ENT_REF]("Reference") >> "&", "Name", ";";
67  prods[PROD_CHAR_REF]("Reference") >> "&", "#", "Digits", ";";
68  prods[PROD_ONE_DIGIT]("Digits") >> "Digit";
69  prods[PROD_DIGITS]("Digits") >> "Digits", "Digit";
70  prods[PROD_NO_SPACES]("S?");
71  prods[PROD_YES_SPACES]("S?") >> "S";
72  prods[PROD_ONE_SPACE]("S") >> "Space";
73  prods[PROD_SPACES]("S") >> "S", "Space";
74  prods[PROD_DQUOTED_COMMON]("DQuotedChar") >> "CommonChar";
75  prods[PROD_DQUOTED_SQUOT]("DQuotedChar") >> "'";
76  prods[PROD_DQUOTED_RSQUARE]("DQuotedChar") >> "]";
77  prods[PROD_DQUOTED_DASH]("DQuotedChar") >> "-";
78  prods[PROD_SQUOTED_CHAR]("SQuotedChar") >> "CommonChar";
79  prods[PROD_SQUOTED_DQUOT]("SQuotedChar") >> "\"";
80  prods[PROD_SQUOTED_RSQUARE]("SQuotedChar") >> "]";
81  prods[PROD_SQUOTED_DASH]("SQuotedChar") >> "-";
82  prods[PROD_DATA_COMMON]("DataChar") >> "CommonChar";
83  prods[PROD_DATA_SQUOT]("DataChar") >> "'";
84  prods[PROD_DATA_DQUOT]("DataChar") >> "\"";
85  prods[PROD_DATA_DASH]("DataChar") >> "-";
86  prods[PROD_COMMENT_COMMON]("CommentChar") >> "CommonChar";
87  prods[PROD_COMMENT_LANGLE]("CommentChar") >> "<";
88  prods[PROD_COMMENT_AMP]("CommentChar") >> "&";
89  prods[PROD_COMMENT_SQUOT]("CommentChar") >> "'";
90  prods[PROD_COMMENT_DQUOT]("CommentChar") >> "\"";
91  prods[PROD_COMMENT_RSQUARE]("CommentChar") >> "]";
92  prods[PROD_COMMON_SPACE]("CommonChar") >> "Space";
93  prods[PROD_COMMON_LETTER]("CommonChar") >> "Letter";
94  prods[PROD_COMMON_DIGIT]("CommonChar") >> "Digit";
95  prods[PROD_COMMON_EXCL]("CommonChar") >> "!";
96  prods[PROD_COMMON_POUND]("CommonChar") >> "#";
97  prods[PROD_COMMON_DOT]("CommonChar") >> ".";
98  prods[PROD_COMMON_SLASH]("CommonChar") >> "/";
99  prods[PROD_COMMON_COLON]("CommonChar") >> ":";
100  prods[PROD_COMMON_SEMICOLON]("CommonChar") >> ";";
101  prods[PROD_COMMON_RANGLE]("CommonChar") >> ">";
102  prods[PROD_COMMON_QUESTION]("CommonChar") >> "?";
103  prods[PROD_COMMON_EQUAL]("CommonChar") >> "=";
104  prods[PROD_COMMON_LSQUARE]("CommonChar") >> "[";
105  prods[PROD_COMMON_UNDER]("CommonChar") >> "_";
106  prods[PROD_COMMON_OTHER]("CommonChar") >> "OtherChar";
107  Language::Tokens& toks = out.tokens;
108  toks.resize(NTOKS);
109  toks[TOK_SPACE]("Space", "[ \t\r\n]");
110  toks[TOK_LETTER]("Letter", "[a-zA-Z]");
111  toks[TOK_DIGIT]("Digit", "[0-9]");
112  toks[TOK_EXCL]("!", "!");
113  toks[TOK_DQUOTE]("\"", "\"");
114  toks[TOK_SQUOTE]("'", "'");
115  toks[TOK_POUND]("#", "#");
116  toks[TOK_AMP]("&", "&");
117  toks[TOK_DASH]("-", "\\-");
118  toks[TOK_DOT](".", "\\.");
119  toks[TOK_SLASH]("/", "/");
120  toks[TOK_COLON](":", ":");
121  toks[TOK_SEMICOLON](";", ";");
122  toks[TOK_LANGLE]("<", "<");
123  toks[TOK_RANGLE](">", ">");
124  toks[TOK_QUESTION]("?", "\\?");
125  toks[TOK_EQUAL]("=", "=");
126  toks[TOK_LSQUARE]("[", "\\[");
127  toks[TOK_RSQUARE]("]", "\\]");
128  toks[TOK_UNDER]("_", "_");
129  toks[TOK_OTHER]("OtherChar", "[$%\\(\\)\\*\\+,@\\\\\\^`{}\\|~]");
130  return out;
131 }
132 
133 LanguagePtr ask_language() {
134  static LanguagePtr ptr;
135  if (ptr.strong_count() == 0) {
136  ptr.reset(new Language(make_language()));
137  }
138  return ptr;
139 }
140 
141 ReaderTablesPtr ask_reader_tables() {
142  static ReaderTablesPtr ptr;
143  if (ptr.strong_count() == 0) {
144  LanguagePtr lang = ask_language();
145  ptr = make_reader_tables(*lang);
146  }
147  return ptr;
148 }
149 
150 } // end namespace XML
151 } // end namespace Teuchos
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