clingo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
nongroundparser.hh
Go to the documentation of this file.
1 // {{{ GPL License
2 
3 // This file is part of gringo - a grounder for logic programs.
4 // Copyright (C) 2013 Roland Kaminski
5 
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 
16 // You should have received a copy of the GNU General Public License
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
19 // }}}
20 
21 #ifndef _GRINGO_INPUT_NONGROUNDPARSER_HH
22 #define _GRINGO_INPUT_NONGROUNDPARSER_HH
23 
25 #include <gringo/lexerstate.hh>
26 #include <memory>
27 #include <iosfwd>
28 #include <set>
29 
30 namespace Gringo { namespace Input {
31 
32 // {{{ declaration of NonGroundParser
33 
34 using StringVec = std::vector<std::string>;
35 using ProgramVec = std::vector<std::tuple<FWString, IdVec, std::string>>;
36 
37 class NonGroundParser : private LexerState<std::pair<FWString, std::pair<FWString, IdVec>>> {
38 public:
40  void parseError(Location const &loc, std::string const &token);
41  void pushFile(std::string &&filename);
42  void pushStream(std::string &&name, std::unique_ptr<std::istream>);
43  void pushBlocks(ProgramVec &&blocks);
44  int lex(void *pValue, Location &loc);
45  bool parseDefine(std::string const &define);
46  bool parse();
47  bool empty() { return LexerState::empty(); }
48  void include(unsigned sUid, Location const &loc, bool include);
50  // {{{ aggregate helper functions
52  unsigned aggregate(AggregateFunction fun, unsigned choice, unsigned elems, BoundVecUid bounds);
53  HdLitUid headaggregate(Location const &loc, unsigned hdaggr);
54  BdLitVecUid bodyaggregate(BdLitVecUid body, Location const &loc, NAF naf, unsigned bdaggr);
55  // }}}
57 
58 private:
59  int lex_impl(void *pValue, Location &loc);
60  void lexerError(std::string const &token);
61  bool push(std::string const &filename, bool include = false);
62  bool push(std::string const &file, std::unique_ptr<std::istream> in);
63  void pop();
64  void _init();
65  FWString filename() const;
66 
67 private:
68  std::set<std::string> filenames_;
69  unsigned not_;
71  struct Aggr
72  {
74  unsigned choice;
75  unsigned elems;
76  BoundVecUid bounds;
77  };
78  Indexed<Aggr> _aggregates;
79  int _startSymbol;
80  FWString _filename;
81 };
82 
83 // }}}
84 
85 } } // namespace Input Gringo
86 
87 #endif // _GRINGO_INPUT_NONGROUNDPARSER_HH
void pushBlocks(ProgramVec &&blocks)
Definition: nongroundparser.cc:87
NAF
Definition: base.hh:32
Definition: locatable.hh:30
unsigned aggregate(AggregateFunction fun, unsigned choice, unsigned elems, BoundVecUid bounds)
Definition: nongroundparser.cc:223
BoundVecUid boundvec(Relation ra, TermUid ta, Relation rb, TermUid tb)
Definition: nongroundparser.cc:239
std::vector< std::tuple< FWString, IdVec, std::string >> ProgramVec
Definition: nongroundparser.hh:35
Definition: nongroundparser.hh:37
UBodyAggr bdaggr(NAF naf, AggregateFunction fun, BoundVec &&bounds, BodyAggrElemVec &&elems)
Definition: aggregate_helper.hh:53
bool empty() const
Definition: lexerstate.hh:218
void include(unsigned sUid, Location const &loc, bool include)
Definition: nongroundparser.cc:122
void pushStream(std::string &&name, std::unique_ptr< std::istream >)
Definition: nongroundparser.cc:76
Relation
Definition: base.hh:44
bool parse()
Definition: nongroundparser.cc:211
Definition: flyweight.hh:60
std::vector< std::string > StringVec
Definition: nongroundparser.hh:34
void parseError(Location const &loc, std::string const &token)
Definition: nongroundparser.cc:42
INongroundProgramBuilder & builder()
Definition: nongroundparser.cc:221
UHeadAggr hdaggr(AggregateFunction fun, BoundVec &&bounds, HeadAggrElemVec &&elems)
Definition: aggregate_helper.hh:68
NonGroundParser(INongroundProgramBuilder &pb)
Definition: nongroundparser.cc:37
~NonGroundParser()
Definition: nongroundparser.cc:247
HdLitUid headaggregate(Location const &loc, unsigned hdaggr)
Definition: nongroundparser.cc:227
void pushFile(std::string &&filename)
Definition: nongroundparser.cc:65
Definition: programbuilder.hh:82
bool parseDefine(std::string const &define)
Definition: nongroundparser.cc:202
bool empty()
Definition: nongroundparser.hh:47
BdLitVecUid bodyaggregate(BdLitVecUid body, Location const &loc, NAF naf, unsigned bdaggr)
Definition: nongroundparser.cc:233
Definition: lexerstate.hh:39
BdLitVecUid
Definition: programbuilder.hh:76
TermUid
Definition: programbuilder.hh:67
int lex(void *pValue, Location &loc)
Definition: nongroundparser.cc:102
std::unique_ptr< FunctionTerm > fun(char const *name, T &&...args)
Definition: term_helper.hh:67
AggregateFunction
Definition: base.hh:54
BoundVecUid
Definition: programbuilder.hh:77
HdLitUid
Definition: programbuilder.hh:75