dlvhex
2.5.0
|
00001 /* dlvhex -- Answer-Set Programming with external interfaces. 00002 * Copyright (C) 2005-2007 Roman Schindlauer 00003 * Copyright (C) 2006-2015 Thomas Krennwallner 00004 * Copyright (C) 2009-2016 Peter Schüller 00005 * Copyright (C) 2011-2016 Christoph Redl 00006 * Copyright (C) 2015-2016 Tobias Kaminski 00007 * Copyright (C) 2015-2016 Antonius Weinzierl 00008 * 00009 * This file is part of dlvhex. 00010 * 00011 * dlvhex is free software; you can redistribute it and/or modify it 00012 * under the terms of the GNU Lesser General Public License as 00013 * published by the Free Software Foundation; either version 2.1 of 00014 * the License, or (at your option) any later version. 00015 * 00016 * dlvhex is distributed in the hope that it will be useful, but 00017 * WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 * Lesser General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU Lesser General Public 00022 * License along with dlvhex; if not, write to the Free Software 00023 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 00024 * 02110-1301 USA. 00025 */ 00026 00036 #ifndef TERM_HPP_INCLUDED__12102010 00037 #define TERM_HPP_INCLUDED__12102010 00038 00039 #include "dlvhex2/PlatformDefinitions.h" 00040 #include "dlvhex2/ID.h" 00041 #include "dlvhex2/Logger.h" 00042 #include "dlvhex2/fwd.h" 00043 00044 DLVHEX_NAMESPACE_BEGIN 00045 00052 struct DLVHEX_EXPORT Term: 00053 private ostream_printable<Term> 00054 { 00056 IDKind kind; 00057 00058 // Anonymous variables: are parsed as one variable "_". 00059 // Then they are processed into new distinct variables, 00060 // each with the anonymous bit set and with a new ID. 00062 std::string symbol; 00063 00071 std::vector<ID> arguments; 00072 00078 Term(IDKind kind, const std::string& symbol): kind(kind), symbol(symbol) { 00079 assert(ID(kind,0).isTerm()); 00080 00081 arguments.push_back(ID_FAIL); 00082 } 00083 00090 Term(IDKind kind, const std::vector<ID>& arguments, RegistryPtr reg); 00091 00098 void updateSymbolOfNestedTerm(Registry* reg); 00099 00103 bool isQuotedString() const 00104 { 00105 if ((symbol.at(0) == '"') && (symbol.at(symbol.length()-1) == '"')) 00106 return true; 00107 return false; 00108 } 00109 00113 bool isNestedTerm() const 00114 { 00115 return arguments[0] != ID_FAIL; 00116 } 00117 00121 std::string getQuotedString() const 00122 { 00123 return '"' + getUnquotedString() + '"'; 00124 } 00125 00129 std::string getUnquotedString() const 00130 { 00131 ; 00132 if (isQuotedString()) 00133 return symbol.substr(1, symbol.length()-2); 00134 return symbol; 00135 } 00136 00141 void analyzeTerm(RegistryPtr reg); 00142 00148 std::ostream& print(std::ostream& o) const 00149 { 00150 return o << "Term(" << symbol << ")"; 00151 } 00152 }; 00153 00154 DLVHEX_NAMESPACE_END 00155 #endif // TERM_HPP_INCLUDED__12102010 00156 00157 // vim:expandtab:ts=4:sw=4: 00158 // mode: C++ 00159 // End: