18 using namespace trieste;
19 using namespace wf::ops;
21 inline const auto Module = TokenDef(
"rego-module", flag::symtab);
22 inline const auto Package = TokenDef(
"rego-package");
23 inline const auto Policy = TokenDef(
"rego-policy");
24 inline const auto Rule = TokenDef(
"rego-rule", flag::symtab);
25 inline const auto RuleHead = TokenDef(
"rego-rulehead");
26 inline const auto RuleHeadComp = TokenDef(
"rego-ruleheadcomp");
27 inline const auto RuleHeadFunc = TokenDef(
"rego-ruleheadfunc");
28 inline const auto RuleHeadSet = TokenDef(
"rego-ruleheadset");
29 inline const auto RuleHeadObj = TokenDef(
"rego-ruleheadobj");
30 inline const auto RuleArgs = TokenDef(
"rego-ruleargs");
31 inline const auto Query = TokenDef(
"rego-query");
32 inline const auto Literal = TokenDef(
"rego-literal");
33 inline const auto Expr = TokenDef(
"rego-expr");
34 inline const auto ExprInfix = TokenDef(
"rego-exprinfix");
35 inline const auto ExprCall = TokenDef(
"rego-exprcall");
36 inline const auto ExprEvery = TokenDef(
"rego-exprevery");
37 inline const auto ExprParens = TokenDef(
"rego-exprparens");
38 inline const auto UnaryExpr = TokenDef(
"rego-unaryexpr");
39 inline const auto NotExpr = TokenDef(
"rego-not-expr");
40 inline const auto Term = TokenDef(
"rego-term");
41 inline const auto InfixOperator = TokenDef(
"rego-infixoperator");
42 inline const auto BoolOperator = TokenDef(
"rego-booloperator");
43 inline const auto ArithOperator = TokenDef(
"rego-arithoperator");
44 inline const auto AssignOperator = TokenDef(
"rego-assignoperator");
45 inline const auto BinOperator = TokenDef(
"rego-binoperator");
46 inline const auto Ref = TokenDef(
"rego-ref");
47 inline const auto RefArgBrack = TokenDef(
"rego-refargbrack");
48 inline const auto RefArgDot = TokenDef(
"rego-refargdot");
49 inline const auto Var = TokenDef(
"rego-var", flag::print);
50 inline const auto Scalar = TokenDef(
"rego-scalar");
51 inline const auto String = TokenDef(
"rego-string");
52 inline const auto Array = TokenDef(
"rego-array");
53 inline const auto Object = TokenDef(
"rego-object");
54 inline const auto Set = TokenDef(
"rego-set");
55 inline const auto ObjectItem = TokenDef(
"rego-objectitem");
56 inline const auto RawString = TokenDef(
"rego-rawstring", flag::print);
57 inline const auto JSONString = TokenDef(
"rego-STRING", flag::print);
58 inline const auto Int = TokenDef(
"rego-INT", flag::print);
59 inline const auto Float = TokenDef(
"rego-FLOAT", flag::print);
60 inline const auto True = TokenDef(
"rego-true");
61 inline const auto False = TokenDef(
"rego-false");
62 inline const auto Null = TokenDef(
"rego-null");
63 inline const auto Equals = TokenDef(
"rego-equals");
64 inline const auto NotEquals = TokenDef(
"rego-notequals");
65 inline const auto LessThan = TokenDef(
"rego-lessthan");
66 inline const auto GreaterThan = TokenDef(
"rego-greaterthan");
67 inline const auto LessThanOrEquals = TokenDef(
"rego-lessthanorequals");
68 inline const auto GreaterThanOrEquals = TokenDef(
"rego-greaterthanorequals");
69 inline const auto Add = TokenDef(
"rego-add");
70 inline const auto Subtract = TokenDef(
"rego-subtract");
71 inline const auto Multiply = TokenDef(
"rego-multiply");
72 inline const auto Divide = TokenDef(
"rego-divide");
73 inline const auto Modulo = TokenDef(
"rego-modulo");
74 inline const auto And = TokenDef(
"rego-and");
75 inline const auto Or = TokenDef(
"rego-or");
76 inline const auto Assign = TokenDef(
"rego-assign");
77 inline const auto Unify = TokenDef(
"rego-unify");
78 inline const auto Default = TokenDef(
"rego-default");
79 inline const auto Some = TokenDef(
"rego-some");
80 inline const auto SomeDecl = TokenDef(
"rego-somedecl");
81 inline const auto If = TokenDef(
"rego-if");
82 inline const auto IsIn = TokenDef(
"rego-in");
83 inline const auto Contains = TokenDef(
"rego-contains");
84 inline const auto Else = TokenDef(
"rego-else");
85 inline const auto As = TokenDef(
"rego-as");
86 inline const auto With = TokenDef(
"rego-with");
87 inline const auto Every = TokenDef(
"rego-every");
88 inline const auto ArrayCompr = TokenDef(
"rego-arraycompr");
89 inline const auto ObjectCompr = TokenDef(
"rego-objectcompr");
90 inline const auto SetCompr = TokenDef(
"rego-setcompr");
91 inline const auto Membership = TokenDef(
"rego-membership");
92 inline const auto Not = TokenDef(
"rego-not");
93 inline const auto Import =
94 TokenDef(
"rego-import", flag::lookdown | flag::lookup | flag::shadowing);
95 inline const auto Placeholder = TokenDef(
"rego-placeholder");
96 inline const auto Version = TokenDef(
"rego-version", flag::print);
99 inline const auto RuleBodySeq = TokenDef(
"rego-rulebodyseq");
100 inline const auto ImportSeq = TokenDef(
"rego-importseq");
101 inline const auto RuleRef = TokenDef(
"rego-ruleref");
102 inline const auto RuleHeadType = TokenDef(
"rego-ruleheadtype");
103 inline const auto WithSeq = TokenDef(
"rego-withseq");
104 inline const auto TermSeq = TokenDef(
"rego-termseq");
105 inline const auto ExprSeq = TokenDef(
"rego-exprseq");
106 inline const auto VarSeq = TokenDef(
"rego-varseq");
107 inline const auto RefHead = TokenDef(
"rego-refhead");
108 inline const auto RefArgSeq = TokenDef(
"rego-refargseq");
109 inline const auto Key = TokenDef(
"rego-key", flag::print);
110 inline const auto Val = TokenDef(
"rego-value");
111 inline const auto Undefined = TokenDef(
"rego-undefined");
114 inline const auto Results = TokenDef(
"rego-results", flag::symtab);
115 inline const auto Result = TokenDef(
"rego-result", flag::symtab);
116 inline const auto Bindings = TokenDef(
"rego-bindings");
117 inline const auto Terms = TokenDef(
"rego-terms");
118 inline const auto Binding = TokenDef(
"rego-binding", flag::lookdown);
119 inline const auto ErrorCode = TokenDef(
"rego-errorcode");
120 inline const auto ErrorSeq = TokenDef(
"rego-errorseq");
122 inline const auto wf_assign_op = Assign | Unify;
123 inline const auto wf_arith_op = Add | Subtract | Multiply | Divide | Modulo;
124 inline const auto wf_bin_op = And | Or | Subtract;
125 inline const auto wf_bool_op = Equals | NotEquals | LessThan |
126 LessThanOrEquals | GreaterThan | GreaterThanOrEquals | Not;
127 inline const auto wf_exprs =
128 Term | ExprCall | ExprInfix | ExprEvery | ExprParens | UnaryExpr;
131 inline const auto wf =
132 (Top <<= Query | Module)
133 | (Module <<= Package * Version * ImportSeq * Policy)
134 | (ImportSeq <<= Import++)
135 | (Import <<= Ref * Var)
137 | (Policy <<= Rule++)
138 | (Rule <<= (Default >>= True | False) * RuleHead * RuleBodySeq)
139 | (RuleHead <<= RuleRef * (RuleHeadType >>= (RuleHeadSet | RuleHeadObj | RuleHeadFunc | RuleHeadComp)))
140 | (RuleRef <<= Var | Ref)
141 | (RuleHeadComp <<= Expr)
142 | (RuleHeadObj <<= Expr * Expr)
143 | (RuleHeadFunc <<= RuleArgs * Expr)
144 | (RuleHeadSet <<= Expr)
145 | (RuleArgs <<= Term++)
146 | (RuleBodySeq <<= (Else | Query)++)
147 | (Else <<= Expr * Query)
148 | (Query <<= Literal++)
149 | (Literal <<= (Expr >>= SomeDecl | Expr | NotExpr) * WithSeq)
150 | (WithSeq <<= With++)
151 | (With <<= Term * Expr)
152 | (SomeDecl <<= ExprSeq * (IsIn >>= Expr | Undefined))
154 | (Expr <<= (Term | ExprCall | ExprInfix | ExprEvery | ExprParens | UnaryExpr))
155 | (ExprCall <<= Ref * ExprSeq)
156 | (ExprSeq <<= Expr++)
157 | (ExprInfix <<= Expr * InfixOperator * Expr)
158 | (ExprEvery <<= VarSeq * (IsIn >>= Term | ExprCall | ExprInfix) * Query)
159 | (VarSeq <<= Var++[1])
160 | (ExprParens <<= Expr)
161 | (UnaryExpr <<= Expr)
162 | (Membership <<= ExprSeq * Expr)
163 | (Term <<= Ref | Var | Scalar | Array | Object | Set | Membership | ArrayCompr | ObjectCompr | SetCompr)
164 | (ArrayCompr <<= Expr * Query)
165 | (SetCompr <<= Expr * Query)
166 | (ObjectCompr <<= Expr * Expr * Query)
167 | (InfixOperator <<= AssignOperator | BoolOperator | ArithOperator | BinOperator)
168 | (BoolOperator <<= Equals | NotEquals | LessThan | GreaterThan | LessThanOrEquals | GreaterThanOrEquals)
169 | (ArithOperator <<= Add | Subtract | Multiply | Divide | Modulo)
170 | (BinOperator <<= And | Or)
171 | (AssignOperator <<= Assign | Unify)
172 | (Ref <<= RefHead * RefArgSeq)
173 | (RefHead <<= Var | Array | Object | Set | ArrayCompr | ObjectCompr | SetCompr | ExprCall)
174 | (RefArgSeq <<= (RefArgDot | RefArgBrack)++)
175 | (RefArgBrack <<= Expr | Placeholder)
176 | (RefArgDot <<= Var)
177 | (Scalar <<= String | Int | Float | True | False | Null)
178 | (String <<= JSONString | RawString)
180 | (Object <<= ObjectItem++)
181 | (ObjectItem <<= (Key >>= Expr) * (Val >>= Expr))
187 inline const auto wf_result =
188 (Top <<= Results | Undefined)
189 | (Results <<= Result++[1])
190 | (Result <<= Terms * Bindings)
192 | (Bindings <<= Binding++)
193 | (Binding <<= (Key >>= Var) * (Val >>= Term))[Key]
194 | (Term <<= Scalar | Array | Object | Set)
197 | (Object <<= ObjectItem++)
198 | (ObjectItem <<= (Key >>= Term) * (Val >>= Term))
199 | (Scalar <<= JSONString | Int | Float | True | False | Null)
200 | (Error <<= ErrorMsg * ErrorAst * ErrorCode)
223 BigInt(
const Location& value);
224 BigInt(std::int64_t value);
225 BigInt(std::size_t value);
227 const Location& loc()
const;
228 std::int64_t to_int()
const;
229 std::size_t to_size()
const;
230 bool is_negative()
const;
231 bool is_zero()
const;
235 static bool is_int(
const Location& loc);
243 friend bool operator>(
const BigInt& lhs,
const BigInt& rhs);
244 friend bool operator<(
const BigInt& lhs,
const BigInt& rhs);
245 friend bool operator<=(
const BigInt& lhs,
const BigInt& rhs);
246 friend bool operator>=(
const BigInt& lhs,
const BigInt& rhs);
247 friend bool operator==(
const BigInt& lhs,
const BigInt& rhs);
248 friend bool operator!=(
const BigInt& lhs,
const BigInt& rhs);
250 friend std::ostream& operator<<(std::ostream& os,
const BigInt& value);
257 std::string quotient;
258 std::string remainder;
261 static bool less_than(
262 const std::string_view& lhs,
const std::string_view& rhs);
263 static bool greater_than(
264 const std::string_view& lhs,
const std::string_view& rhs);
265 static bool equal(
const std::string_view& lhs,
const std::string_view& rhs);
266 static std::string add(
267 const std::string_view& lhs,
const std::string_view& rhs,
bool negative);
268 static std::string subtract(
269 const std::string_view& lhs,
const std::string_view& rhs,
bool negative);
270 static DivideResult divide(
271 const std::string_view& lhs,
const std::string_view& rhs);
272 static std::string multiply(
273 const std::string_view& lhs,
const std::string_view& rhs);
274 std::string_view digits()
const;
276 static Location Zero;
339 const std::string&
code()
const;
348 const std::string&
pre()
const;
365 const std::string&
func()
const;
374 const std::vector<Token>&
types()
const;
393 bool m_specify_number;
395 std::string m_prefix;
396 std::string m_message;
398 std::vector<Token> m_types;
480 const Node& node,
const std::string_view& key);
553 Node
array(
const Nodes& array_members);
561 Node
set(
const Nodes& set_members);
578 const std::size_t
AnyArity = std::numeric_limits<std::size_t>::max();
700 Node
call(const Location& name, const Location&
version, const Nodes& args);
733 template <typename T>
736 for (
auto& built_in : built_ins)
760 static std::shared_ptr<BuiltInsDef>
create();
762 std::map<Location, BuiltIn>::const_iterator begin()
const;
763 std::map<Location, BuiltIn>::const_iterator end()
const;
766 std::map<Location, BuiltIn> m_builtins;
767 bool m_strict_errors;
770 using BuiltIns = std::shared_ptr<BuiltInsDef>;
772 const std::string UnknownError =
"unknown_error";
773 const std::string EvalTypeError =
"eval_type_error";
774 const std::string EvalBuiltInError =
"eval_builtin_error";
775 const std::string RegoTypeError =
"rego_type_error";
776 const std::string RegoParseError =
"rego_parse_error";
777 const std::string RegoCompileError =
"rego_compile_error";
778 const std::string EvalConflictError =
"eval_conflict_error";
779 const std::string WellFormedError =
"wellformed_error";
780 const std::string RuntimeError =
"runtime_error";
781 const std::string RecursionError =
"rego_recursion_error";
782 const std::string DefaultVersion =
"v0";
793 const std::string& msg,
794 const std::string& code = UnknownError);
804 Node node,
const std::string& msg,
const std::string& code = UnknownError);
823 const trieste::Node& node,
824 bool set_as_array =
false,
825 bool sort_arrays =
false);
832 None = REGO_LOG_LEVEL_NONE,
833 Error = REGO_LOG_LEVEL_ERROR,
834 Output = REGO_LOG_LEVEL_OUTPUT,
835 Warn = REGO_LOG_LEVEL_WARN,
836 Info = REGO_LOG_LEVEL_INFO,
837 Debug = REGO_LOG_LEVEL_DEBUG,
838 Trace = REGO_LOG_LEVEL_TRACE,
902 Node
add_module(
const std::string& name,
const std::string& contents);
977 std::string
query(
const std::string& query_expr);
999 const std::filesystem::path&
debug_path()
const;
1029 friend void setError(regoInterpreter*
rego,
const std::string& error);
1031 regoInterpreter*
rego,
const char* query_expr);
1033 void merge(
const Node& ast);
1034 std::string output_to_string(
const Node& output)
const;
1037 std::filesystem::path m_debug_path;
1038 BuiltIns m_builtins;
1041 Rewriter m_from_json;
1042 Rewriter m_to_input;
1043 std::size_t m_data_count;
1045 std::string m_c_error;