Clingo
Loading...
Searching...
No Matches
script.hh
1#pragma once
2
3#include <clingo/core/location.hh>
4#include <clingo/core/logger.hh>
5
6namespace CppClingo::Ground {
7
10
13 public:
15 virtual ~ScriptExec() = default;
17 void exec(Location const &loc, Logger &log, std::string_view name, std::string_view code) {
18 do_exec(loc, log, name, code);
19 }
20
21 private:
22 virtual void do_exec(Location const &loc, Logger &log, std::string_view name, std::string_view code) = 0;
23};
24
29 public:
31 virtual ~ScriptCallback() = default;
33 auto callable(std::string_view name, size_t args) -> bool { return do_callable(name, args); }
35 void call(Location const &loc, std::string_view name, SymbolSpan args, SymbolVec &out) {
36 do_call(loc, name, args, out);
37 }
38
39 private:
40 virtual auto do_callable(std::string_view name, size_t args) -> bool = 0;
41 virtual void do_call(Location const &loc, std::string_view name, SymbolSpan args, SymbolVec &out) = 0;
42};
43
45
46} // namespace CppClingo::Ground
Interface to call functions during parsing/grounding.
Definition script.hh:28
auto callable(std::string_view name, size_t args) -> bool
Check if the function with the given name and number of arguments is callable.
Definition script.hh:33
virtual ~ScriptCallback()=default
Virtual destructor.
void call(Location const &loc, std::string_view name, SymbolSpan args, SymbolVec &out)
Call the function with the given name and arguments.
Definition script.hh:35
Interface to execute code in source files.
Definition script.hh:12
void exec(Location const &loc, Logger &log, std::string_view name, std::string_view code)
Execute the given code for the given script.
Definition script.hh:17
virtual ~ScriptExec()=default
Virtual destructor.
The Location of an expression in an input source.
Definition location.hh:44
Simple logger to report message to stderr or via a callback.
Definition logger.hh:63
std::span< Symbol const > SymbolSpan
A span of symbols.
Definition symbol.hh:218
std::vector< Symbol > SymbolVec
A vector of symbols.
Definition symbol.hh:220