knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
strings.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of KnowRob, please consult
3  * https://github.com/knowrob/knowrob for license details.
4  */
5 
6 #include <boost/spirit/include/phoenix.hpp>
7 #include "knowrob/queries/QueryError.h"
8 #include "knowrob/queries/parsers/strings.h"
9 #include "knowrob/semweb/PrefixRegistry.h"
10 
11 static std::string createIRI(const std::string &prefix, const std::string &name) {
13  if (uri.has_value()) {
14  return uri.value();
15  } else {
16  throw knowrob::QueryError("Cannot construct IRI for '{}': " "IRI prefix '{}' is not registered!", name, prefix);
17  }
18 }
19 
20 namespace knowrob::parsers::str {
21  namespace qi = boost::spirit::qi;
22  namespace ascii = boost::spirit::ascii;
23  #define RETURN_STRING_RULE(expr) static StringRule r(expr); return r
24 
26  RETURN_STRING_RULE(qi::lexeme['\'' >> +(qi::char_ - '\'') >> '\'']);
27  }
28 
30  RETURN_STRING_RULE(qi::lexeme['"' >> +(qi::char_ - '"') >> '"']);
31  }
32 
34  RETURN_STRING_RULE(qi::raw[ascii::lower >> *(ascii::alnum | '_')]);
35  }
36 
38  RETURN_STRING_RULE(qi::raw[ascii::upper >> *(ascii::alnum | '_')]);
39  }
40 
42  RETURN_STRING_RULE(qi::raw[ascii::alpha >> *(ascii::alnum | '_')]);
43  }
44 
46  RETURN_STRING_RULE(str::single_quotes() | qi::raw[ascii::alpha >> *(ascii::alnum | '_')]);
47  }
48 
50  RETURN_STRING_RULE((iri_ns() >> ':' >> iri_entity())
51  [qi::_val = boost::phoenix::bind(&createIRI, qi::_1, qi::_2)]);
52  }
53 
56  }
57 
60  }
61 
63  RETURN_STRING_RULE(qi::raw['_']);
64  }
65 
67  RETURN_STRING_RULE(qi::raw[qi::double_]);
68  }
69 
72  }
73 }
static std::optional< std::string > createIRI(std::string_view alias, std::string_view entityName)
constexpr std::string_view prefix
Definition: owl.h:14
StringRule & number()
Definition: strings.cpp:66
StringRule & iri()
Definition: strings.cpp:49
boost::spirit::qi::rule< std::string::const_iterator, std::string()> StringRule
Definition: strings.h:12
StringRule & atom_or_iri()
Definition: strings.cpp:58
StringRule & upper_prefix()
Definition: strings.cpp:37
StringRule & blank()
Definition: strings.cpp:62
StringRule & iri_entity()
Definition: strings.cpp:45
StringRule & single_quotes()
Definition: strings.cpp:25
StringRule & lower_prefix()
Definition: strings.cpp:33
StringRule & iri_ns()
Definition: strings.cpp:41
StringRule & double_quotes()
Definition: strings.cpp:29
StringRule & xsd_value()
Definition: strings.cpp:70
StringRule & atom()
Definition: strings.cpp:54
TermRule & string()
Definition: terms.cpp:63
#define RETURN_STRING_RULE(expr)
Definition: strings.cpp:23