2003-08-23 00:17:00 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file lyxlex_pimpl.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
|
* \author J<EFBFBD>rgen Vigna
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "lyxlex_pimpl.h"
|
2003-09-09 22:13:45 +00:00
|
|
|
|
|
2003-02-13 16:53:15 +00:00
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
#include "support/filetools.h"
|
2003-09-09 22:13:45 +00:00
|
|
|
|
#include "support/lyxalgo.h"
|
2001-07-29 17:39:01 +00:00
|
|
|
|
#include "support/lstrings.h"
|
2003-02-13 16:53:15 +00:00
|
|
|
|
|
2005-01-18 14:15:57 +00:00
|
|
|
|
#include <functional>
|
|
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::support::compare_ascii_no_case;
|
2004-10-29 15:47:55 +00:00
|
|
|
|
using lyx::support::getFormatFromContents;
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::support::MakeDisplayPath;
|
|
|
|
|
using lyx::support::split;
|
|
|
|
|
using lyx::support::subst;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
2003-09-08 00:33:41 +00:00
|
|
|
|
using std::endl;
|
|
|
|
|
using std::getline;
|
|
|
|
|
using std::lower_bound;
|
2000-04-08 17:02:02 +00:00
|
|
|
|
using std::sort;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2000-04-08 17:02:02 +00:00
|
|
|
|
using std::ios;
|
|
|
|
|
using std::istream;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
using std::ostream;
|
2000-04-08 17:02:02 +00:00
|
|
|
|
|
2004-01-31 15:30:24 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
2005-01-19 15:03:31 +00:00
|
|
|
|
class compare_tags
|
2004-07-25 00:04:42 +00:00
|
|
|
|
: public std::binary_function<keyword_item, keyword_item, bool> {
|
2005-01-19 15:03:31 +00:00
|
|
|
|
public:
|
2000-07-24 21:49:58 +00:00
|
|
|
|
// used by lower_bound, sort and sorted
|
2004-07-25 00:04:42 +00:00
|
|
|
|
bool operator()(keyword_item const & a, keyword_item const & b) const
|
|
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
|
// we use the ascii version, because in turkish, 'i'
|
|
|
|
|
// is not the lowercase version of 'I', and thus
|
|
|
|
|
// turkish locale breaks parsing of tags.
|
|
|
|
|
return compare_ascii_no_case(a.tag, b.tag) < 0;
|
2000-04-08 17:02:02 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
2004-01-31 15:30:24 +00:00
|
|
|
|
|
|
|
|
|
} // end of anon namespace
|
2000-04-08 17:02:02 +00:00
|
|
|
|
|
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
LyXLex::Pimpl::Pimpl(keyword_item * tab, int num)
|
2003-12-02 12:02:39 +00:00
|
|
|
|
: is(&fb_), table(tab), no_items(num),
|
2000-11-08 15:19:55 +00:00
|
|
|
|
status(0), lineno(0), commentChar('#')
|
2000-04-08 17:02:02 +00:00
|
|
|
|
{
|
2000-08-05 05:17:18 +00:00
|
|
|
|
verifyTable();
|
2000-04-08 17:02:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-08-06 19:12:46 +00:00
|
|
|
|
string const LyXLex::Pimpl::getString() const
|
2000-04-08 17:02:02 +00:00
|
|
|
|
{
|
2003-04-14 12:44:36 +00:00
|
|
|
|
return string(buff.begin(), buff.end());
|
2000-04-08 17:02:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXLex::Pimpl::printError(string const & message) const
|
|
|
|
|
{
|
2001-08-06 19:12:46 +00:00
|
|
|
|
string const tmpmsg = subst(message, "$$Token", getString());
|
2000-04-08 17:02:02 +00:00
|
|
|
|
lyxerr << "LyX: " << tmpmsg << " [around line " << lineno
|
|
|
|
|
<< " of file " << MakeDisplayPath(name) << ']' << endl;
|
|
|
|
|
}
|
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
void LyXLex::Pimpl::printTable(ostream & os)
|
|
|
|
|
{
|
2003-08-02 11:30:30 +00:00
|
|
|
|
os << "\nNumber of tags: " << no_items << endl;
|
2000-11-04 10:00:12 +00:00
|
|
|
|
for (int i= 0; i < no_items; ++i)
|
2000-04-08 17:02:02 +00:00
|
|
|
|
os << "table[" << i
|
|
|
|
|
<< "]: tag: `" << table[i].tag
|
|
|
|
|
<< "' code:" << table[i].code << '\n';
|
|
|
|
|
os.flush();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-08-05 05:17:18 +00:00
|
|
|
|
void LyXLex::Pimpl::verifyTable()
|
2000-04-08 17:02:02 +00:00
|
|
|
|
{
|
|
|
|
|
// Check if the table is sorted and if not, sort it.
|
|
|
|
|
if (table
|
2001-04-17 15:15:59 +00:00
|
|
|
|
&& !lyx::sorted(table, table + no_items, compare_tags())) {
|
2000-08-05 05:17:18 +00:00
|
|
|
|
lyxerr << "The table passed to LyXLex is not sorted!\n"
|
2000-04-08 17:02:02 +00:00
|
|
|
|
<< "Tell the developers to fix it!" << endl;
|
|
|
|
|
// We sort it anyway to avoid problems.
|
2003-08-02 11:30:30 +00:00
|
|
|
|
lyxerr << "\nUnsorted:" << endl;
|
2000-04-08 17:02:02 +00:00
|
|
|
|
printTable(lyxerr);
|
2000-08-05 05:17:18 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
sort(table, table + no_items, compare_tags());
|
2003-08-02 11:30:30 +00:00
|
|
|
|
lyxerr << "\nSorted:" << endl;
|
2000-04-08 17:02:02 +00:00
|
|
|
|
printTable(lyxerr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-08-05 05:17:18 +00:00
|
|
|
|
|
|
|
|
|
void LyXLex::Pimpl::pushTable(keyword_item * tab, int num)
|
|
|
|
|
{
|
|
|
|
|
pushed_table tmppu(table, no_items);
|
|
|
|
|
pushed.push(tmppu);
|
|
|
|
|
|
|
|
|
|
table = tab;
|
|
|
|
|
no_items = num;
|
|
|
|
|
|
|
|
|
|
verifyTable();
|
|
|
|
|
}
|
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
void LyXLex::Pimpl::popTable()
|
|
|
|
|
{
|
2000-08-05 05:17:18 +00:00
|
|
|
|
if (pushed.empty()) {
|
2000-04-08 17:02:02 +00:00
|
|
|
|
lyxerr << "LyXLex error: nothing to pop!" << endl;
|
2000-08-05 05:17:18 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-08-05 05:17:18 +00:00
|
|
|
|
pushed_table tmp = pushed.top();
|
|
|
|
|
pushed.pop();
|
|
|
|
|
table = tmp.table_elem;
|
|
|
|
|
no_items = tmp.table_siz;
|
2000-04-08 17:02:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool LyXLex::Pimpl::setFile(string const & filename)
|
|
|
|
|
{
|
2003-07-28 14:40:29 +00:00
|
|
|
|
// Check the format of the file.
|
2004-10-29 15:47:55 +00:00
|
|
|
|
string const format = getFormatFromContents(filename);
|
2003-07-28 14:40:29 +00:00
|
|
|
|
|
|
|
|
|
if (format == "gzip" || format == "zip" || format == "compress") {
|
2003-10-09 13:27:51 +00:00
|
|
|
|
lyxerr[Debug::LYXLEX] << "lyxlex: compressed" << endl;
|
2003-07-27 23:40:08 +00:00
|
|
|
|
|
2005-01-20 21:34:23 +00:00
|
|
|
|
#ifdef USE_COMPRESSION
|
2003-07-28 14:40:29 +00:00
|
|
|
|
// The check only outputs a debug message, because it triggers
|
|
|
|
|
// a bug in compaq cxx 6.2, where is_open() returns 'true' for
|
|
|
|
|
// a fresh new filebuf. (JMarc)
|
2003-12-02 12:02:39 +00:00
|
|
|
|
if (gz_.is_open() || istream::off_type(is.tellg()) > -1)
|
2003-07-27 23:40:08 +00:00
|
|
|
|
lyxerr[Debug::LYXLEX] << "Error in LyXLex::setFile: "
|
|
|
|
|
"file or stream already set." << endl;
|
2003-12-02 12:02:39 +00:00
|
|
|
|
gz_.open(filename.c_str(), ios::in);
|
|
|
|
|
is.rdbuf(&gz_);
|
2003-07-27 23:40:08 +00:00
|
|
|
|
name = filename;
|
|
|
|
|
lineno = 0;
|
2003-12-02 12:02:39 +00:00
|
|
|
|
return gz_.is_open() && is.good();
|
2005-01-20 21:34:23 +00:00
|
|
|
|
#else
|
|
|
|
|
return false;
|
|
|
|
|
#endif
|
2003-07-27 23:40:08 +00:00
|
|
|
|
} else {
|
2003-10-09 13:27:51 +00:00
|
|
|
|
lyxerr[Debug::LYXLEX] << "lyxlex: UNcompressed" << endl;
|
2003-07-27 23:40:08 +00:00
|
|
|
|
|
2003-07-28 14:40:29 +00:00
|
|
|
|
// The check only outputs a debug message, because it triggers
|
|
|
|
|
// a bug in compaq cxx 6.2, where is_open() returns 'true' for
|
|
|
|
|
// a fresh new filebuf. (JMarc)
|
2003-12-02 12:02:39 +00:00
|
|
|
|
if (fb_.is_open() || istream::off_type(is.tellg()) > 0)
|
2003-07-27 23:40:08 +00:00
|
|
|
|
lyxerr[Debug::LYXLEX] << "Error in LyXLex::setFile: "
|
|
|
|
|
"file or stream already set." << endl;
|
2003-12-02 12:02:39 +00:00
|
|
|
|
fb_.open(filename.c_str(), ios::in);
|
|
|
|
|
is.rdbuf(&fb_);
|
2003-07-27 23:40:08 +00:00
|
|
|
|
name = filename;
|
|
|
|
|
lineno = 0;
|
2003-12-02 12:02:39 +00:00
|
|
|
|
return fb_.is_open() && is.good();
|
2003-07-27 23:40:08 +00:00
|
|
|
|
}
|
2000-04-08 17:02:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
void LyXLex::Pimpl::setStream(istream & i)
|
|
|
|
|
{
|
2003-12-02 12:02:39 +00:00
|
|
|
|
if (fb_.is_open() || istream::off_type(is.tellg()) > 0)
|
2000-09-14 13:50:47 +00:00
|
|
|
|
lyxerr[Debug::LYXLEX] << "Error in LyXLex::setStream: "
|
2000-04-08 17:02:02 +00:00
|
|
|
|
"file or stream already set." << endl;
|
|
|
|
|
is.rdbuf(i.rdbuf());
|
|
|
|
|
lineno = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-14 12:44:36 +00:00
|
|
|
|
|
2000-11-08 15:19:55 +00:00
|
|
|
|
void LyXLex::Pimpl::setCommentChar(char c)
|
|
|
|
|
{
|
|
|
|
|
commentChar = c;
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
|
2000-04-11 16:57:16 +00:00
|
|
|
|
bool LyXLex::Pimpl::next(bool esc /* = false */)
|
2000-04-08 17:02:02 +00:00
|
|
|
|
{
|
2000-05-17 14:43:09 +00:00
|
|
|
|
if (!pushTok.empty()) {
|
2001-03-11 03:20:44 +00:00
|
|
|
|
// There can have been a whole line pushed so
|
|
|
|
|
// we extract the first word and leaves the rest
|
|
|
|
|
// in pushTok. (Lgb)
|
2003-03-12 07:39:17 +00:00
|
|
|
|
if (pushTok.find(' ') != string::npos && pushTok[0] == '\\') {
|
2001-03-11 03:20:44 +00:00
|
|
|
|
string tmp;
|
|
|
|
|
pushTok = split(pushTok, tmp, ' ');
|
2003-04-14 12:44:36 +00:00
|
|
|
|
buff.assign(tmp.begin(), tmp.end());
|
2001-03-11 03:20:44 +00:00
|
|
|
|
return true;
|
|
|
|
|
} else {
|
2003-04-14 12:44:36 +00:00
|
|
|
|
buff.assign(pushTok.begin(), pushTok.end());
|
2001-03-11 03:20:44 +00:00
|
|
|
|
pushTok.erase();
|
|
|
|
|
return true;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
}
|
2000-05-17 14:43:09 +00:00
|
|
|
|
}
|
2000-04-08 17:02:02 +00:00
|
|
|
|
if (!esc) {
|
|
|
|
|
unsigned char c = 0; // getc() returns an int
|
|
|
|
|
char cc = 0;
|
|
|
|
|
status = 0;
|
|
|
|
|
while (is && !status) {
|
|
|
|
|
is.get(cc);
|
|
|
|
|
c = cc;
|
2000-11-08 15:19:55 +00:00
|
|
|
|
if (c == commentChar) {
|
2000-04-08 17:02:02 +00:00
|
|
|
|
// Read rest of line (fast :-)
|
2000-10-11 21:06:43 +00:00
|
|
|
|
#if 1
|
2003-04-14 12:44:36 +00:00
|
|
|
|
// That is not fast... (Lgb)
|
|
|
|
|
string dummy;
|
|
|
|
|
getline(is, dummy);
|
2003-04-14 13:12:40 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
lyxerr[Debug::LYXLEX] << "Comment read: `" << c
|
2003-04-14 12:44:36 +00:00
|
|
|
|
<< dummy << '\'' << endl;
|
2000-10-11 21:06:43 +00:00
|
|
|
|
#else
|
2001-06-25 00:06:33 +00:00
|
|
|
|
// unfortunately ignore is buggy (Lgb)
|
2000-10-11 21:06:43 +00:00
|
|
|
|
is.ignore(100, '\n');
|
|
|
|
|
#endif
|
2000-04-08 17:02:02 +00:00
|
|
|
|
++lineno;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
if (c == '\"') {
|
2003-04-14 12:44:36 +00:00
|
|
|
|
buff.clear();
|
2003-04-14 13:12:40 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
do {
|
|
|
|
|
is.get(cc);
|
|
|
|
|
c = cc;
|
|
|
|
|
if (c != '\r')
|
2003-04-14 12:44:36 +00:00
|
|
|
|
buff.push_back(c);
|
|
|
|
|
} while (c != '\"' && c != '\n' && is);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
if (c != '\"') {
|
|
|
|
|
printError("Missing quote");
|
|
|
|
|
if (c == '\n')
|
|
|
|
|
++lineno;
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-14 12:44:36 +00:00
|
|
|
|
buff.pop_back();
|
2000-04-08 17:02:02 +00:00
|
|
|
|
status = LEX_DATA;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
break;
|
2000-04-08 17:02:02 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
if (c == ',')
|
|
|
|
|
continue; /* Skip ','s */
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
// using relational operators with chars other
|
|
|
|
|
// than == and != is not safe. And if it is done
|
|
|
|
|
// the type _have_ to be unsigned. It usually a
|
|
|
|
|
// lot better to use the functions from cctype
|
|
|
|
|
if (c > ' ' && is) {
|
2003-04-14 12:44:36 +00:00
|
|
|
|
buff.clear();
|
2003-04-14 13:12:40 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
do {
|
2003-04-14 12:44:36 +00:00
|
|
|
|
buff.push_back(c);
|
2000-04-08 17:02:02 +00:00
|
|
|
|
is.get(cc);
|
|
|
|
|
c = cc;
|
2003-04-14 12:44:36 +00:00
|
|
|
|
} while (c > ' ' && c != ',' && is);
|
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
status = LEX_TOKEN;
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
if (c == '\r' && is) {
|
|
|
|
|
// The Windows support has lead to the
|
|
|
|
|
// possibility of "\r\n" at the end of
|
|
|
|
|
// a line. This will stop LyX choking
|
|
|
|
|
// when it expected to find a '\n'
|
|
|
|
|
is.get(cc);
|
|
|
|
|
c = cc;
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
if (c == '\n')
|
|
|
|
|
++lineno;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
}
|
|
|
|
|
if (status) return true;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
status = is.eof() ? LEX_FEOF: LEX_UNDEF;
|
2003-04-14 12:44:36 +00:00
|
|
|
|
buff.clear();
|
2000-04-08 17:02:02 +00:00
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
unsigned char c = 0; // getc() returns an int
|
|
|
|
|
char cc = 0;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
status = 0;
|
|
|
|
|
while (is && !status) {
|
|
|
|
|
is.get(cc);
|
|
|
|
|
c = cc;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
// skip ','s
|
|
|
|
|
if (c == ',') continue;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
if (c == '\\') {
|
|
|
|
|
// escape
|
2003-04-14 12:44:36 +00:00
|
|
|
|
buff.clear();
|
2003-04-14 13:12:40 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
do {
|
|
|
|
|
if (c == '\\') {
|
|
|
|
|
// escape the next char
|
|
|
|
|
is.get(cc);
|
|
|
|
|
c = cc;
|
|
|
|
|
}
|
2003-04-14 12:44:36 +00:00
|
|
|
|
buff.push_back(c);
|
2000-04-08 17:02:02 +00:00
|
|
|
|
is.get(cc);
|
|
|
|
|
c = cc;
|
2003-04-14 12:44:36 +00:00
|
|
|
|
} while (c > ' ' && c != ',' && is);
|
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
status = LEX_TOKEN;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-11-08 15:19:55 +00:00
|
|
|
|
if (c == commentChar) {
|
2000-04-08 17:02:02 +00:00
|
|
|
|
// Read rest of line (fast :-)
|
2000-10-11 21:06:43 +00:00
|
|
|
|
#if 1
|
2003-04-14 12:44:36 +00:00
|
|
|
|
// That is still not fast... (Lgb)
|
|
|
|
|
string dummy;
|
|
|
|
|
getline(is, dummy);
|
2003-04-14 13:12:40 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
lyxerr[Debug::LYXLEX] << "Comment read: `" << c
|
2003-04-14 12:44:36 +00:00
|
|
|
|
<< dummy << '\'' << endl;
|
2000-10-11 21:06:43 +00:00
|
|
|
|
#else
|
|
|
|
|
// but ignore is also still buggy (Lgb)
|
|
|
|
|
// This is fast (Lgb)
|
|
|
|
|
is.ignore(100, '\n');
|
|
|
|
|
#endif
|
2000-04-08 17:02:02 +00:00
|
|
|
|
++lineno;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
// string
|
|
|
|
|
if (c == '\"') {
|
2003-04-14 12:44:36 +00:00
|
|
|
|
buff.clear();
|
2003-04-14 13:12:40 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
bool escaped = false;
|
|
|
|
|
do {
|
|
|
|
|
escaped = false;
|
|
|
|
|
is.get(cc);
|
|
|
|
|
c = cc;
|
|
|
|
|
if (c == '\r') continue;
|
|
|
|
|
if (c == '\\') {
|
|
|
|
|
// escape the next char
|
|
|
|
|
is.get(cc);
|
|
|
|
|
c = cc;
|
2001-08-18 10:33:17 +00:00
|
|
|
|
if (c == '\"' || c == '\\')
|
|
|
|
|
escaped = true;
|
|
|
|
|
else
|
2003-04-14 12:44:36 +00:00
|
|
|
|
buff.push_back('\\');
|
2000-04-08 17:02:02 +00:00
|
|
|
|
}
|
2003-04-14 12:44:36 +00:00
|
|
|
|
buff.push_back(c);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
if (!escaped && c == '\"') break;
|
2003-04-14 12:44:36 +00:00
|
|
|
|
} while (c != '\n' && is);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
if (c != '\"') {
|
|
|
|
|
printError("Missing quote");
|
|
|
|
|
if (c == '\n')
|
|
|
|
|
++lineno;
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-04-14 12:44:36 +00:00
|
|
|
|
buff.pop_back();
|
2000-04-08 17:02:02 +00:00
|
|
|
|
status = LEX_DATA;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
break;
|
2000-04-08 17:02:02 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
if (c > ' ' && is) {
|
2003-04-14 12:44:36 +00:00
|
|
|
|
buff.clear();
|
2003-04-14 13:12:40 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
do {
|
|
|
|
|
if (c == '\\') {
|
|
|
|
|
// escape the next char
|
|
|
|
|
is.get(cc);
|
|
|
|
|
c = cc;
|
|
|
|
|
//escaped = true;
|
|
|
|
|
}
|
2003-04-14 12:44:36 +00:00
|
|
|
|
buff.push_back(c);
|
2000-04-08 17:02:02 +00:00
|
|
|
|
is.get(cc);
|
|
|
|
|
c = cc;
|
2003-04-14 12:44:36 +00:00
|
|
|
|
} while (c > ' ' && c != ',' && is);
|
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
status = LEX_TOKEN;
|
|
|
|
|
}
|
|
|
|
|
// new line
|
|
|
|
|
if (c == '\n')
|
|
|
|
|
++lineno;
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
if (status) return true;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
status = is.eof() ? LEX_FEOF : LEX_UNDEF;
|
2003-04-14 12:44:36 +00:00
|
|
|
|
buff.clear();
|
2000-04-08 17:02:02 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-07-24 21:49:58 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
int LyXLex::Pimpl::search_kw(char const * const tag) const
|
|
|
|
|
{
|
2000-07-24 21:49:58 +00:00
|
|
|
|
keyword_item search_tag = { tag, 0 };
|
2000-04-08 17:02:02 +00:00
|
|
|
|
keyword_item * res =
|
|
|
|
|
lower_bound(table, table + no_items,
|
2000-07-24 21:49:58 +00:00
|
|
|
|
search_tag, compare_tags());
|
2002-07-16 21:17:10 +00:00
|
|
|
|
// use the compare_ascii_no_case instead of compare_no_case,
|
|
|
|
|
// because in turkish, 'i' is not the lowercase version of 'I',
|
|
|
|
|
// and thus turkish locale breaks parsing of tags.
|
2000-04-08 17:02:02 +00:00
|
|
|
|
if (res != table + no_items
|
2002-07-16 21:17:10 +00:00
|
|
|
|
&& !compare_ascii_no_case(res->tag, tag))
|
2000-04-08 17:02:02 +00:00
|
|
|
|
return res->code;
|
|
|
|
|
return LEX_UNDEF;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int LyXLex::Pimpl::lex()
|
|
|
|
|
{
|
|
|
|
|
//NOTE: possible bug.
|
2003-04-14 12:44:36 +00:00
|
|
|
|
if (next() && status == LEX_TOKEN) {
|
|
|
|
|
return search_kw(getString().c_str());
|
|
|
|
|
} else
|
2000-04-08 17:02:02 +00:00
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-08-06 19:12:46 +00:00
|
|
|
|
bool LyXLex::Pimpl::eatLine()
|
2000-04-08 17:02:02 +00:00
|
|
|
|
{
|
2003-04-14 12:44:36 +00:00
|
|
|
|
buff.clear();
|
2003-04-14 13:12:40 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
unsigned char c = '\0';
|
|
|
|
|
char cc = 0;
|
2003-04-14 12:44:36 +00:00
|
|
|
|
while (is && c != '\n') {
|
2000-04-08 17:02:02 +00:00
|
|
|
|
is.get(cc);
|
|
|
|
|
c = cc;
|
2001-06-01 10:53:24 +00:00
|
|
|
|
//lyxerr[Debug::LYXLEX] << "LyXLex::EatLine read char: `"
|
2002-11-27 10:30:28 +00:00
|
|
|
|
// << c << '\'' << endl;
|
2000-04-08 17:02:02 +00:00
|
|
|
|
if (c != '\r')
|
2003-04-14 12:44:36 +00:00
|
|
|
|
buff.push_back(c);
|
2000-04-08 17:02:02 +00:00
|
|
|
|
}
|
2003-04-14 12:44:36 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
if (c == '\n') {
|
|
|
|
|
++lineno;
|
2003-04-14 12:44:36 +00:00
|
|
|
|
buff.pop_back();
|
2000-04-08 17:02:02 +00:00
|
|
|
|
status = LEX_DATA;
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool LyXLex::Pimpl::nextToken()
|
|
|
|
|
{
|
2000-05-17 14:43:09 +00:00
|
|
|
|
if (!pushTok.empty()) {
|
2001-03-11 03:20:44 +00:00
|
|
|
|
// There can have been a whole line pushed so
|
|
|
|
|
// we extract the first word and leaves the rest
|
|
|
|
|
// in pushTok. (Lgb)
|
2003-03-12 07:39:17 +00:00
|
|
|
|
if (pushTok.find(' ') != string::npos && pushTok[0] == '\\') {
|
2001-03-11 03:20:44 +00:00
|
|
|
|
string tmp;
|
|
|
|
|
pushTok = split(pushTok, tmp, ' ');
|
2003-04-14 12:44:36 +00:00
|
|
|
|
buff.assign(tmp.begin(), tmp.end());
|
2001-03-11 03:20:44 +00:00
|
|
|
|
return true;
|
|
|
|
|
} else {
|
2003-04-14 12:44:36 +00:00
|
|
|
|
buff.assign(pushTok.begin(), pushTok.end());
|
2001-03-11 03:20:44 +00:00
|
|
|
|
pushTok.erase();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2000-05-17 14:43:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
status = 0;
|
|
|
|
|
while (is && !status) {
|
|
|
|
|
unsigned char c = 0;
|
|
|
|
|
char cc = 0;
|
|
|
|
|
is.get(cc);
|
|
|
|
|
c = cc;
|
|
|
|
|
if (c >= ' ' && is) {
|
2003-04-14 12:44:36 +00:00
|
|
|
|
buff.clear();
|
2003-04-14 13:12:40 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
if (c == '\\') { // first char == '\\'
|
|
|
|
|
do {
|
2003-04-14 12:44:36 +00:00
|
|
|
|
buff.push_back(c);
|
2000-04-08 17:02:02 +00:00
|
|
|
|
is.get(cc);
|
|
|
|
|
c = cc;
|
2003-04-14 12:44:36 +00:00
|
|
|
|
} while (c > ' ' && c != '\\' && is);
|
2000-04-08 17:02:02 +00:00
|
|
|
|
} else {
|
|
|
|
|
do {
|
2003-04-14 12:44:36 +00:00
|
|
|
|
buff.push_back(c);
|
2000-04-08 17:02:02 +00:00
|
|
|
|
is.get(cc);
|
|
|
|
|
c = cc;
|
2003-04-14 12:44:36 +00:00
|
|
|
|
} while (c >= ' ' && c != '\\' && is);
|
2000-04-08 17:02:02 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
if (c == '\\') is.putback(c); // put it back
|
|
|
|
|
status = LEX_TOKEN;
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
if (c == '\n')
|
|
|
|
|
++lineno;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
}
|
|
|
|
|
if (status) return true;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
status = is.eof() ? LEX_FEOF: LEX_UNDEF;
|
2003-04-14 12:44:36 +00:00
|
|
|
|
buff.clear();
|
2000-04-08 17:02:02 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2000-05-17 14:43:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXLex::Pimpl::pushToken(string const & pt)
|
|
|
|
|
{
|
|
|
|
|
pushTok = pt;
|
|
|
|
|
}
|