lexer cosmetics

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24134 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2008-04-05 21:24:57 +00:00
parent f4c398c2b5
commit e1453ef687
14 changed files with 75 additions and 114 deletions

View File

@ -1625,7 +1625,8 @@ void BufferParams::readGraphicsDriver(Lexer & lex)
if (test == tmptok) {
graphicsDriver = tmptok;
break;
} else if (test == "") {
}
if (test.empty()) {
lex.printError(
"Warning: graphics driver `$$Token' not recognized!\n"
" Setting graphics driver to `default'.\n");

View File

@ -40,23 +40,20 @@ bool CmdDef::read(string const & def_file)
{ "\\define", BN_DEFINE }
};
Lexer lexrc(cmdDefTags);
if (lyxerr.debugging(Debug::PARSER))
lexrc.printTable(lyxerr);
Lexer lex(cmdDefTags);
FileName const tmp(i18nLibFileSearch("commands", def_file, "def"));
lexrc.setFile(tmp);
if (!lexrc.isOK()) {
lyxerr << "CmdDef::read: cannot open def file:"
<< tmp << endl;
lex.setContext("CmdDef::read");
lex.setFile(tmp);
if (!lex.isOK()) {
LYXERR0( "CmdDef::read: cannot open def file:" << tmp);
return false;
}
bool error = false;
while (lexrc.isOK()) {
switch (lexrc.lex()) {
while (lex.isOK()) {
switch (lex.lex()) {
case Lexer::LEX_UNDEF:
lexrc.printError("Unknown tag `$$Token'");
lex.printError("Unknown tag");
error = true;
continue;
case Lexer::LEX_FEOF:
@ -65,18 +62,18 @@ bool CmdDef::read(string const & def_file)
{
string name, def;
if (lexrc.next()) {
name = lexrc.getString();
if (lex.next()) {
name = lex.getString();
} else {
lexrc.printError("BN_DEFINE: Missing command name");
lex.printError("BN_DEFINE: Missing command name");
error = true;
break;
}
if (lexrc.next(true)) {
def = lexrc.getString();
if (lex.next(true)) {
def = lex.getString();
} else {
lexrc.printError("BN_DEFINE: missing command definition");
lex.printError("BN_DEFINE: missing command definition");
error = true;
break;
}
@ -84,15 +81,15 @@ bool CmdDef::read(string const & def_file)
newCmdDefResult e = newCmdDef(name, def);
switch (e) {
case CmdDefNameEmpty:
lexrc.printError("BN_DEFINE: Command name is empty");
lex.printError("BN_DEFINE: Command name is empty");
error = true;
break;
case CmdDefExists:
lexrc.printError("BN_DEFINE: Command `" + name + "' already defined");
lex.printError("BN_DEFINE: Command `" + name + "' already defined");
error = true;
break;
case CmdDefInvalid:
lexrc.printError("BN_DEFINE: Command definition for `" + name + "' is not valid");
lex.printError("BN_DEFINE: Command definition for `" + name + "' is not valid");
error = true;
break;
case CmdDefOk:
@ -102,11 +99,11 @@ bool CmdDef::read(string const & def_file)
break;
}
case BN_DEFFILE:
if (lexrc.next()) {
string const tmp = lexrc.getString();
if (lex.next()) {
string const tmp = lex.getString();
error |= !read(tmp);
} else {
lexrc.printError("BN_DEFFILE: Missing file name");
lex.printError("BN_DEFFILE: Missing file name");
error = true;
break;
@ -116,8 +113,7 @@ bool CmdDef::read(string const & def_file)
}
if (error)
lyxerr << "CmdDef::read: error while reading def file:"
<< tmp << endl;
LYXERR0("CmdDef::read: error while reading def file:" << tmp);
return !error;
}

View File

@ -534,6 +534,7 @@ void Encodings::read(FileName const & encfile, FileName const & symbolsfile)
Lexer lex(encodingtags);
lex.setFile(encfile);
lex.setContext("Encodings::read");
while (lex.isOK()) {
switch (lex.lex()) {
case et_encoding:
@ -552,39 +553,35 @@ void Encodings::read(FileName const & encfile, FileName const & symbolsfile)
else if (width == "variable")
fixedwidth = false;
else
lex.printError("Encodings::read: "
"Unknown width: `$$Token'");
lex.printError("Unknown width");
lex.next();
string const p = lex.getString();
Encoding::Package package = Encoding::none;
if (p == "none")
package = Encoding::none;
package = Encoding::none;
else if (p == "inputenc")
package = Encoding::inputenc;
else if (p == "CJK")
package = Encoding::CJK;
else
lex.printError("Encodings::read: "
"Unknown package: `$$Token'");
lex.printError("Unknown package");
LYXERR(Debug::INFO, "Reading encoding " << name);
encodinglist[name] = Encoding(name, latexname,
iconvname, fixedwidth, package);
if (lex.lex() != et_end)
lex.printError("Encodings::read: "
"missing end");
lex.printError("Missing end");
break;
}
case et_end:
lex.printError("Encodings::read: Misplaced end");
lex.printError("Misplaced end");
break;
case Lexer::LEX_FEOF:
break;
default:
lex.printError("Encodings::read: "
"Unknown tag: `$$Token'");
lex.printError("Unknown tag");
break;
}
}

View File

@ -337,14 +337,14 @@ FontInfo lyxRead(Lexer & lex, FontInfo const & fi)
} else if (ttok == "noun") {
f.setNoun(FONT_ON);
} else {
lex.printError("Illegal misc type `$$Token'");
lex.printError("Illegal misc type");
}
} else if (tok == "color") {
lex.next();
string const ttok = lex.getString();
setLyXColor(ttok, f);
} else {
lex.printError("Unknown tag `$$Token'");
lex.printError("Unknown tag");
error = true;
}
}

View File

@ -173,7 +173,9 @@ void Lexer::Pimpl::printError(string const & message) const
{
string const tmpmsg = subst(message, "$$Token", getString());
lyxerr << "LyX: " << tmpmsg << " [around line " << lineno
<< " of file " << to_utf8(makeDisplayPath(name)) << ']' << endl;
<< " of file " << to_utf8(makeDisplayPath(name))
<< " current token: '" << getString() << "'"
<< " context: '" << context << "']" << endl;
}
@ -760,6 +762,7 @@ bool Lexer::getBool() const
pimpl_->printError("Bad boolean `$$Token'. "
"Use \"false\" or \"true\"");
lastReadOk_ = false;
return false;
}

View File

@ -408,8 +408,7 @@ void MenuDefinition::read(Lexer & lex)
};
lex.pushTable(menutags);
if (lyxerr.debugging(Debug::PARSER))
lex.printTable(lyxerr);
lex.setContext("MenuDefinition::read: ");
bool quit = false;
bool optional = false;
@ -517,8 +516,7 @@ void MenuDefinition::read(Lexer & lex)
break;
default:
lex.printError("MenuDefinition::read: "
"Unknown menu tag: `$$Token'");
lex.printError("Unknown menu tag");
break;
}
}
@ -1416,15 +1414,12 @@ void Menus::read(Lexer & lex)
{ "menubar", md_menubar }
};
//consistency check
if (compare_ascii_no_case(lex.getString(), "menuset")) {
lyxerr << "Menubackend::read: ERROR wrong token:`"
<< lex.getString() << '\'' << endl;
}
// consistency check
if (compare_ascii_no_case(lex.getString(), "menuset"))
LYXERR0("Menus::read: ERROR wrong token: `" << lex.getString() << '\'');
lex.pushTable(menutags);
if (lyxerr.debugging(Debug::PARSER))
lex.printTable(lyxerr);
lex.setContext("Menus::read");
bool quit = false;
@ -1449,8 +1444,7 @@ void Menus::read(Lexer & lex)
quit = true;
break;
default:
lex.printError("menubackend::read: "
"Unknown menu tag: `$$Token'");
lex.printError("Unknown menu tag");
break;
}
}

View File

@ -292,23 +292,6 @@ void TemplateManager::readTemplates(FileName const & path)
}
namespace {
void add(vector<TransformID> & ids, string const & name)
{
TransformID id = transformIDTranslator().find(name);
if (int(id) == -1) {
lyxerr << "external::Template::readTemplate\n"
<< "Transform " << name << " is not recognized"
<< endl;
} else {
ids.push_back(id);
}
}
} // namespace anon
void Template::readTemplate(Lexer & lex)
{
enum {
@ -334,7 +317,9 @@ void Template::readTemplate(Lexer & lex)
};
PushPopHelper pph(lex, templateoptiontags);
lex.setContext("Template::readTemplate");
string token;
while (lex.isOK()) {
switch (lex.lex()) {
case TO_GUINAME:
@ -362,8 +347,12 @@ void Template::readTemplate(Lexer & lex)
break;
case TO_TRANSFORM:
lex.next(true);
add(transformIds, lex.getString());
lex >> token;
TransformID id = transformIDTranslator().find(token);
if (int(id) == -1)
LYXERR0("Transform " << token << " is not recognized");
else
ids.push_back(id);
break;
case TO_FORMAT:

View File

@ -85,6 +85,7 @@ void InsetFloatList::write(ostream & os) const
void InsetFloatList::read(Lexer & lex)
{
lex.setContext("InsetFloatList::read");
FloatList const & floats = buffer().params().documentClass().floats();
string token;
@ -93,9 +94,9 @@ void InsetFloatList::read(Lexer & lex)
LYXERR(Debug::INSETS, "FloatList::float_type: "
<< to_ascii(getParam("type")));
if (!floats.typeExist(to_ascii(getParam("type"))))
lex.printError("InsetFloatList: Unknown float type: `$$Token'");
lex.printError("Unknown float type");
} else {
lex.printError("InsetFloatList: Parse error: `$$Token'");
lex.printError("Parse error");
}
while (lex.isOK()) {
@ -105,8 +106,7 @@ void InsetFloatList::read(Lexer & lex)
break;
}
if (token != "\\end_inset") {
lex.printError("Missing \\end_inset at this point. "
"Read: `$$Token'");
lex.printError("Missing \\end_inset at this point.");
}
}

View File

@ -113,9 +113,10 @@ bool InsetLayout::read(Lexer & lex)
int le = lex.lex();
switch (le) {
case Lexer::LEX_UNDEF:
lex.printError("Unknown InsetLayout tag `$$Token'");
lex.printError("Unknown InsetLayout tag");
continue;
default: break;
default:
break;
}
switch (le) {
case IL_LYXTYPE:

View File

@ -78,7 +78,7 @@ void InsetNewpageParams::read(Lexer & lex)
else if (token == "cleardoublepage")
kind = InsetNewpageParams::CLEARDOUBLEPAGE;
else
lex.printError("Unknown kind: `$$Token'");
lex.printError("Unknown kind");
lex >> "\\end_inset";
}

View File

@ -328,8 +328,9 @@ void InsetSpaceParams::write(ostream & os) const
void InsetSpaceParams::read(Lexer & lex)
{
lex.next();
string const command = lex.getString();
lex.setContext("InsetSpaceParams::read");
string command;
lex >> command;
if (command == "\\space{}")
kind = InsetSpaceParams::NORMAL;
@ -362,21 +363,9 @@ void InsetSpaceParams::read(Lexer & lex)
else
lex.printError("InsetSpace: Unknown kind: `$$Token'");
string token;
lex >> token;
if (token == "\\length") {
lex.next();
string const len = lex.getString();
length = Length(len);
lex.next();
token = lex.getString();
}
if (!lex)
return;
if (token != "\\end_inset")
lex.printError("Missing \\end_inset at this point. "
"Read: `$$Token'");
if (lex.checkFor("\\length"))
lex >> length;
lex >> "\\end_inset";
}

View File

@ -2820,7 +2820,7 @@ void InsetTabular::read(Lexer & lex)
tabular.read(lex);
//if (old_format)
// return;
// return;
lex.next();
string token = lex.getString();
@ -2828,10 +2828,8 @@ void InsetTabular::read(Lexer & lex)
lex.next();
token = lex.getString();
}
if (!lex) {
lex.printError("Missing \\end_inset at this point. "
"Read: `$$Token'");
}
if (!lex)
lex.printError("Missing \\end_inset at this point. ");
}
@ -2841,7 +2839,7 @@ int InsetTabular::rowFromY(Cursor & cur, int y) const
int h = yo(cur.bv()) - tabular.rowAscent(0);
size_t nrows = tabular.rowCount();
row_type r = 0;
for (;r < nrows && y > h; ++r) {
for (; r < nrows && y > h; ++r) {
h += tabular.rowAscent(r);
h += tabular.rowDescent(r);
h += tabular.getAdditionalHeight(r);
@ -2856,9 +2854,8 @@ int InsetTabular::columnFromX(Cursor & cur, int x) const
int w = xo(cur.bv()) + ADD_TO_TABULAR_WIDTH;
size_t ncols = tabular.columnCount();
col_type c = 0;
for (;c < ncols && x > w; ++c) {
for (; c < ncols && x > w; ++c)
w += tabular.columnWidth(c);
}
return c - 1;
}
@ -2868,7 +2865,7 @@ void InsetTabular::metrics(MetricsInfo & mi, Dimension & dim) const
//lyxerr << "InsetTabular::metrics: " << mi.base.bv << " width: " <<
// mi.base.textwidth << "\n";
if (!mi.base.bv) {
lyxerr << "InsetTabular::metrics: need bv" << endl;
LYXERR0("need bv");
BOOST_ASSERT(false);
}

View File

@ -147,12 +147,11 @@ void InsetText::read(Lexer & lex)
Paragraph oldpar = *paragraphs().begin();
paragraphs().clear();
ErrorList errorList;
lex.setContext("InsetText::read");
bool res = text_.read(buffer(), lex, errorList, this);
if (!res) {
lex.printError("Missing \\end_inset at this point. "
"Read: `$$Token'");
}
if (!res)
lex.printError("Missing \\end_inset at this point. ");
// sanity check
// ensure we have at least one paragraph.

View File

@ -112,12 +112,7 @@ void InsetVSpace::read(Lexer & lex)
lex >> vsp;
if (lex)
space_ = VSpace(vsp);
string end_token;
lex >> end_token;
if (end_token != "\\end_inset")
lex.printError("Missing \\end_inset at this point. "
"Read: `$$Token'");
lex >> "\\end_inset";
}