Clingo
Loading...
Searching...
No Matches
parser.hh
1#pragma once
2
3#include <clingo/input/statement.hh>
4
5#include <clingo/core/backend.hh>
6#include <clingo/core/logger.hh>
7
8#include <istream>
9
10namespace CppClingo::Input {
11
12namespace Parse {
13
14class ParserState;
15
16}
17
20
22class Parser {
23 public:
27 Parser(Logger &log, SymbolStore &store, ProgramBackend *prg_backend = nullptr,
28 TheoryBackend *thy_backend = nullptr);
30 Parser(Parser const &other) = delete;
32 Parser(Parser &&other) noexcept;
34 auto operator=(Parser const &other) -> Parser & = delete;
36 auto operator=(Parser &&other) noexcept -> Parser &;
38 ~Parser() noexcept;
39
41 void init(std::istream &in, String file);
45 void init(std::string_view in, String file);
46
48 auto parse_symbol() -> std::optional<SharedSymbol>;
50 auto parse_program_parts() -> std::optional<ProgramParamVec>;
52 auto parse_const_def() -> std::optional<std::pair<SharedString, SharedSymbol>>;
54 auto parse_term() -> std::optional<Term>;
56 auto parse_theory_term() -> std::optional<TheoryTerm>;
58 auto parse_literal() -> std::optional<Lit>;
60 auto parse_body_literal() -> std::optional<BdLit>;
62 auto parse_head_literal() -> std::optional<HdLit>;
64 auto parse_statement() -> std::optional<Stm>;
65
71 auto scan() -> std::pair<std::optional<Stm>, bool>;
72
73 private:
74 std::unique_ptr<Parse::ParserState> impl_;
75};
76
78
79} // namespace CppClingo::Input
A parser for the clingo language.
Definition parser.hh:22
auto parse_term() -> std::optional< Term >
Parse a term.
auto parse_program_parts() -> std::optional< ProgramParamVec >
Parse program params to ground.
auto parse_theory_term() -> std::optional< TheoryTerm >
Parse a theory term.
~Parser() noexcept
Destroy the parser.
auto parse_head_literal() -> std::optional< HdLit >
Parse a head literal.
Parser(Parser const &other)=delete
Copy construct the parser.
auto scan() -> std::pair< std::optional< Stm >, bool >
Scan statements.
auto parse_symbol() -> std::optional< SharedSymbol >
Parse a symbol.
auto parse_const_def() -> std::optional< std::pair< SharedString, SharedSymbol > >
Parse a const definition of form name=symbol.
auto operator=(Parser &&other) noexcept -> Parser &
Move assign the parser.
Parser(Logger &log, SymbolStore &store, ProgramBackend *prg_backend=nullptr, TheoryBackend *thy_backend=nullptr)
Construct the parser.
auto parse_body_literal() -> std::optional< BdLit >
Parse a body literal.
auto operator=(Parser const &other) -> Parser &=delete
Copy assign the parser.
auto parse_literal() -> std::optional< Lit >
Parse a literal.
Parser(Parser &&other) noexcept
Move construct the parser.
auto parse_statement() -> std::optional< Stm >
Parse a statement.
Simple logger to report message to stderr or via a callback.
Definition logger.hh:63
Abstract class connecting grounder and solver.
Definition backend.hh:54
Class managing the lifetime of a String.
Definition symbol.hh:93
Class managing the lifetime of a Symbol.
Definition symbol.hh:306
Reference to a string stored in a symbol store.
Definition symbol.hh:18
A store for symbols.
Definition symbol.hh:454
Abstract class connecting grounder and theory data.
Definition backend.hh:213
std::variant< BdLitSimple, BdLitConjunction, BdLitAggregate, BdLitSetAggregate, BdLitTheoryAtom > BdLit
A body literal.
Definition body_literal.hh:116
std::variant< HdLitSimple, HdLitDisjunction, HdLitAggregate, HdLitSetAggregate, HdLitTheoryAtom > HdLit
A head literal.
Definition head_literal.hh:130
std::variant< LitBool, LitComparison, LitSymbolic > Lit
Variant holding the different literal types.
Definition literal.hh:129
std::vector< ProgramParam > ProgramParamVec
A list of program params.
Definition statement.hh:761
std::variant< StmRule, StmTheory, StmOptimize, StmWeakConstraint, StmShow, StmShowNothing, StmShowSig, StmProject, StmProjectSig, StmDefined, StmExternal, StmEdge, StmHeuristic, StmScript, StmInclude, StmProgram, StmConst, StmParts, StmComment > Stm
Variant of available statements.
Definition statement.hh:828
std::variant< TermVariable, TermSymbol, TermTuple, TermFunction, TermAbs, TermUnary, TermBinary > Term
Variant holding the different term types.
Definition term.hh:45
std::variant< TheoryTermSymbol, TheoryTermVariable, TheoryTermTuple, TheoryTermFunction, TheoryTermUnparsed > TheoryTerm
A variant for the different theory terms.
Definition theory.hh:22