SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
Sort.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <carl-formula/sort/SortManager.h>
4 
5 #include "Common.h"
6 #include "Lexicon.h"
7 #include "Identifier.h"
8 
9 namespace smtrat {
10 namespace parser {
11 
12 namespace spirit = boost::spirit;
13 namespace qi = boost::spirit::qi;
14 namespace px = boost::phoenix;
15 
16 struct SortParser : public qi::grammar<Iterator, carl::Sort(), Skipper> {
17  SortParser(): SortParser::base_type(sort, "sort") {
18  sort =
19  simpleSort[qi::_val = qi::_1]
20  | parameters[qi::_val = qi::_1]
21  | identifier[qi::_val = px::bind(&SortParser::getSort, px::ref(*this), qi::_1)]
22  | ("(" >> identifier >> +sort >> ")")[qi::_val = px::bind(&SortParser::getSortWithParam, px::ref(*this), qi::_1, qi::_2)]
23  ;
24  sort.name("sort");
26  }
27 
28  void setParameters(const std::vector<std::string>& params) {
29  for (const auto& p: params) {
30  parameters.add(p, carl::getSort(p));
31  }
32  }
33  void clearParameters() {
34  parameters.clear();
35  }
36 
37  carl::Sort getSort(const Identifier& i) {
38  if (i.indices == nullptr) return carl::getSort(i.symbol);
39  return carl::getSort(i.symbol, *i.indices);
40  }
41  carl::Sort getSortWithParam(const Identifier& i, const std::vector<carl::Sort>& params) {
42  if (i.indices == nullptr) return carl::getSort(i.symbol, params);
43  return carl::getSort(i.symbol, *i.indices, params);
44  }
45 private:
48  qi::symbols<char, carl::Sort> simpleSort;
49  qi::symbols<char, carl::Sort> parameters;
50  qi::rule<Iterator, carl::Sort(), Skipper> sort;
51 };
52 
53 }
54 }
PositionIteratorType Iterator
Definition: Common.h:49
Class to create the formulas for axioms.
std::string symbol
Definition: Common.h:37
std::vector< std::size_t > * indices
Definition: Common.h:38
carl::Sort getSortWithParam(const Identifier &i, const std::vector< carl::Sort > &params)
Definition: Sort.h:41
IdentifierParser identifier
Definition: Sort.h:47
carl::Sort getSort(const Identifier &i)
Definition: Sort.h:37
qi::symbols< char, carl::Sort > simpleSort
Definition: Sort.h:48
qi::symbols< char, carl::Sort > parameters
Definition: Sort.h:49
qi::rule< Iterator, carl::Sort(), Skipper > sort
Definition: Sort.h:50
void setParameters(const std::vector< std::string > &params)
Definition: Sort.h:28
SymbolParser symbol
Definition: Sort.h:46
static void addSimpleSorts(qi::symbols< char, carl::Sort > &sorts)
Collects simple sorts from all theory modules.
Definition: Theories.h:99