46 using boost::match_results;
47 using boost::regex_search;
48 using boost::regex_match;
51 const regex PAFParser::COMMENT_LINE(
"^\\s*#");
52 const regex PAFParser::EMPTY_LINE(
"^(\\s*)$");
53 const regex PAFParser::SPACE_SRCH(
"^(\\s+)");
54 const regex PAFParser::PARAM_SRCH(
"^(\\s*)(\\w[\\w\\d\\.]*)\\s*:\\s*");
55 const regex PAFParser::NAME_MTCH(
"\\w[\\w\\d]*(\\.\\w[\\w\\d])*");
56 const regex PAFParser::OPEN_SRCH(
"^\\{\\s*");
57 const regex PAFParser::CLOSE_SRCH(
"^\\s*\\}\\s*");
58 const regex PAFParser::DOUBLE_VALUE
59 (
"^([\\+\\-]?((((\\d+\\.\\d*)|(\\d*\\.\\d+))([eE][\\-\\+]?\\d{1,3})?)"
60 "|(\\d+[eE][\\-\\+]?\\d{1,3})))\\s*");
61 const regex PAFParser::INT_VALUE(
"^([+-]?\\d+)\\s*");
62 const regex PAFParser::ATRUE_VALUE(
"^([tT]rue)\\s*");
63 const regex PAFParser::AFALSE_VALUE(
"^([fF]alse)\\s*");
64 const regex PAFParser::QQSTRING_VALUE(
"^\"([^\"]*)\"\\s*");
65 const regex PAFParser::QSTRING_VALUE(
"^'([^']*)'\\s*");
66 const regex PAFParser::QQSTRING_START(
"^\"([^\"]*\\S)\\s*");
67 const regex PAFParser::QSTRING_START(
"^'([^']*\\S)\\s*");
68 const regex PAFParser::QQSTRING_EMPTYSTART(
"^\"\\s*$");
69 const regex PAFParser::QSTRING_EMPTYSTART(
"^'\\s*$");
70 const regex PAFParser::QQSTRING_END(
"^\\s*([^\"]*)\"\\s*");
71 const regex PAFParser::QSTRING_END(
"^\\s*([^']*)'\\s*");
72 const regex PAFParser::BARE_STRING_LINE(
"^\\s*(\\S(.*\\S)?)\\s*");
73 const regex PAFParser::BARE_STRING(
"^\\s*([^#\\}\\s]([^#\\}]*[^#\\}\\s])?)\\s*[#}]?");
74 const regex PAFParser::URN_VALUE(
"^@(urn\\:|@)");
75 const regex PAFParser::FILE_VALUE(
"^@");
81 : PolicyParser(policy), _buffer(), _lineno(0), _depth(0)
84 : PolicyParser(policy, strict), _buffer(), _lineno(0), _depth(0)
104 ios::iostate PAFParser::_nextLine(
istream& is,
string&
line) {
105 if (_buffer.
size() > 0) {
113 if (is.
eof() and
line.length() == 0)
return ios::eofbit;
116 return ios::iostate(0);
119 void PAFParser::_pushBackLine(
const string&
line) {
124 int PAFParser::_parseIntoPolicy(
istream& is, Policy& policy) {
130 while (!_nextLine(is,
line)) {
137 string msg =
"extra '}' character encountered.";
142 _pushBackLine(matched.
suffix());
149 string msg =
"Not a legal names designation: ";
152 throw LSST_EXCEPT(FormatSyntaxError, msg, _lineno);
158 count += _addValue(
name, value, policy, is);
161 string msg =
"Bad parameter name format: " +
line;
163 throw LSST_EXCEPT(FormatSyntaxError, msg, _lineno);
173 int PAFParser::_addValue(
const string& propname,
string& value,
189 policy.add(propname, subpolicy);
194 _pushBackLine(value);
197 count += _parseIntoPolicy(is, *subpolicy);
206 if (unparsed && (*unparsed)) {
207 msg =
"value contains unparsable non-numeric data: ";
213 policy.add(propname, d);
215 if (value.
size() > 0) {
221 _pushBackLine(value);
229 if (value.
size() > 0) {
230 msg =
"Expecting double value, found: ";
243 if (unparsed && (*unparsed)) {
244 msg =
"value contains unparsable non-integer data: ";
250 int ival = int(lval);
251 if (lval-ival != 0) {
253 msg =
"unsupported long integer value found: ";
259 policy.add(propname, ival);
262 if (value.
size() > 0) {
268 _pushBackLine(value);
276 if (value.
size() > 0) {
277 msg =
"Expecting integer value, found: ";
290 policy.add(propname,
true);
292 policy.add(propname,
false);
295 if (value.
size() > 0) {
301 _pushBackLine(value);
310 if (value.
size() > 0) {
311 msg =
"Expecting boolean value, found: ";
314 throw LSST_EXCEPT(FormatSyntaxError, msg, _lineno);
318 else if (value.
at(0) ==
'\'' || value.
at(0) ==
'"') {
333 else if (
regex_search(value, matched, QQSTRING_EMPTYSTART) ||
337 while (!_nextLine(is, value)) {
346 else if (
regex_search(value, matched, BARE_STRING_LINE)) {
355 throw LSST_EXCEPT(ParserError,
"read error", _lineno);
357 else if (
regex_search(value, matched, QSTRING_EMPTYSTART) ||
361 while (!_nextLine(is, value)) {
370 else if (
regex_match(value, matched, BARE_STRING_LINE)) {
379 throw LSST_EXCEPT(ParserError,
"read error", _lineno);
382 if (value.
size() > 0) {
388 _pushBackLine(value);
394 }
while (value.
size() > 0 &&
395 (value.
at(0) ==
'\'' || value.
at(0) ==
'"'));
397 if (value.
size() > 0) {
398 msg =
"Expecting quoted string value, found: ";
405 string trimmed = matched.
str(1);
406 string lowered(trimmed);
407 transform(lowered.begin(), lowered.end(), lowered.begin(), ::tolower);
418 policy.add(propname, trimmed);
421 value = value.
substr(resume);
423 _pushBackLine(value);