3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alejandro Aguilar Sierra
7 * \author Lars Gullik Bjønnes
8 * \author Jean-Marc Lasgouttes
11 * Full author contact details are available in file CREDITS.
17 #include "lyxlex_pimpl.h"
19 #include "support/lstrings.h"
21 using namespace lyx::support;
28 LyXLex::LyXLex(keyword_item * tab, int num)
29 : pimpl_(new Pimpl(tab, num))
39 bool LyXLex::isOK() const
41 return pimpl_->is.good();
45 void LyXLex::setLineNo(int l)
51 int LyXLex::getLineNo() const
53 return pimpl_->lineno;
57 istream & LyXLex::getStream()
63 void LyXLex::pushTable(keyword_item * tab, int num)
65 pimpl_->pushTable(tab, num);
69 void LyXLex::popTable()
75 void LyXLex::printTable(ostream & os)
77 pimpl_->printTable(os);
81 void LyXLex::printError(string const & message) const
83 pimpl_->printError(message);
87 bool LyXLex::setFile(string const & filename)
89 return pimpl_->setFile(filename);
93 void LyXLex::setStream(istream & i)
99 void LyXLex::setCommentChar(char c)
101 pimpl_->setCommentChar(c);
106 return pimpl_->lex();
110 int LyXLex::getInteger() const
112 if (isStrInt(pimpl_->getString()))
113 return strToInt(pimpl_->getString());
114 pimpl_->printError("Bad integer `$$Token'");
119 float LyXLex::getFloat() const
121 // replace comma with dot in case the file was written with
122 // the wrong locale (should be rare, but is easy enough to
124 string str = subst(pimpl_->getString(), ",", ".");
126 return strToDbl(str);
127 pimpl_->printError("Bad float `$$Token'");
132 string const LyXLex::getString() const
134 return pimpl_->getString();
138 // I would prefer to give a tag number instead of an explicit token
139 // here, but it is not possible because Buffer::readBody uses
140 // explicit tokens (JMarc)
141 string const LyXLex::getLongString(string const & endtoken)
144 bool firstline = true;
148 // blank line in the file being read
151 string const token = trim(getString(), " \t");
153 lyxerr[Debug::PARSER] << "LongString: `"
154 << getString() << '\'' << endl;
156 // We do a case independent comparison, like search_kw does.
157 if (compare_ascii_no_case(token, endtoken) == 0)
160 string tmpstr = getString();
162 string::size_type i(tmpstr.find_first_not_of(' '));
163 if (i != string::npos)
164 prefix = tmpstr.substr(0, i);
166 lyxerr[Debug::PARSER]
167 << "Prefix = `" << prefix << "\'" << endl;
170 // further lines in long strings may have the same
171 // whitespace prefix as the first line. Remove it.
172 if (prefix.length() && prefixIs(tmpstr, prefix)) {
173 tmpstr.erase(0, prefix.length() - 1);
176 str += ltrim(tmpstr, "\t") + '\n';
180 printError("Long string not ended by `" + endtoken + '\'');
187 bool LyXLex::getBool() const
189 if (pimpl_->getString() == "true") {
191 } else if (pimpl_->getString() != "false") {
192 pimpl_->printError("Bad boolean `$$Token'. "
193 "Use \"false\" or \"true\"");
199 bool LyXLex::eatLine()
201 return pimpl_->eatLine();
205 bool LyXLex::next(bool esc)
207 return pimpl_->next(esc);
211 bool LyXLex::nextToken()
213 return pimpl_->nextToken();
217 void LyXLex::pushToken(string const & pt)
219 pimpl_->pushToken(pt);
223 int LyXLex::findToken(char const * str[])
226 pimpl_->printError("file ended while scanning string token");
232 string const search_token = pimpl_->getString();
234 if (search_token != "default") {
235 while (str[i][0] && str[i] != search_token) {
239 pimpl_->printError("Unknown argument `$$Token'");