use simpler parser interface

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24122 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2008-04-05 10:34:29 +00:00
parent 4846ee98ad
commit e7645f2439
23 changed files with 229 additions and 671 deletions

View File

@ -753,16 +753,18 @@ string const Lexer::getLongString(string const & endtoken)
bool Lexer::getBool() const
{
if (pimpl_->getString() == "true") {
string const s = pimpl_->getString();
if (s == "false" || s == "0") {
lastReadOk_ = true;
return false;
}
if (s == "true" || s == "1") {
lastReadOk_ = true;
return true;
} else if (pimpl_->getString() != "false") {
pimpl_->printError("Bad boolean `$$Token'. "
"Use \"false\" or \"true\"");
lastReadOk_ = false;
}
lastReadOk_ = true;
return false;
pimpl_->printError("Bad boolean `$$Token'. "
"Use \"false\" or \"true\"");
lastReadOk_ = false;
}
@ -878,6 +880,16 @@ Lexer & Lexer::operator>>(bool & s)
}
Lexer & Lexer::operator>>(char & c)
{
string s;
operator>>(s);
if (!s.empty())
c = s[0];
return *this;
}
// quotes a string, e.g. for use in preferences files or as an argument
// of the "log" dialog
string Lexer::quoteString(string const & arg)
@ -895,13 +907,25 @@ Lexer & Lexer::operator>>(char const * required)
string token;
*this >> token;
if (token != required) {
LYXERR0("Missing '" << required << "'-tag in " << pimpl_->context);
LYXERR0("Missing '" << required << "'-tag in " << pimpl_->context
<< ". Got " << token << " instead. Line: " << lineNumber());
pushToken(token);
}
return *this;
}
bool Lexer::checkFor(char const * required)
{
string token;
*this >> token;
if (token == required)
return true;
pushToken(token);
return false;
}
void Lexer::setContext(std::string const & str)
{
pimpl_->context = str;

View File

@ -182,9 +182,13 @@ public:
Lexer & operator>>(unsigned int &);
/// extract bool
Lexer & operator>>(bool &);
/// extract first char of the string
Lexer & operator>>(char &);
/// read and check a required token
Lexer & operator>>(char const * required);
/// check for an optional token and swallow it if present.
bool checkFor(char const * required);
/// Quotes a string so that reading it again with Lexer::next(true)
/// gets the original string

View File

@ -340,7 +340,8 @@ int LyXRC::read(FileName const & filename)
lexrc.printTable(lyxerr);
lexrc.setFile(filename);
if (!lexrc.isOK()) return -2;
if (!lexrc.isOK())
return -2;
LYXERR(Debug::LYXRC, "Reading '" << filename << "'...");
@ -416,33 +417,24 @@ int LyXRC::read(Lexer & lexrc)
break;
case RC_AUTORESET_OPTIONS:
if (lexrc.next()) {
auto_reset_options = lexrc.getBool();
}
lexrc >> auto_reset_options;
break;
case RC_DISPLAY_GRAPHICS:
if (lexrc.next()) {
if (lexrc.next())
display_graphics = graphics::displayTranslator().find(lexrc.getString());
}
break;
case RC_TEX_EXPECTS_WINDOWS_PATHS:
if (lexrc.next()) {
windows_style_tex_paths = lexrc.getBool();
}
lexrc >> windows_style_tex_paths;
break;
case RC_TEX_ALLOWS_SPACES:
if (lexrc.next()) {
tex_allows_spaces = lexrc.getBool();
}
lexrc >> tex_allows_spaces;
break;
case RC_KBMAP:
if (lexrc.next()) {
use_kbmap = lexrc.getBool();
}
lexrc >> use_kbmap;
break;
case RC_KBMAP_PRIMARY:
@ -474,129 +466,87 @@ int LyXRC::read(Lexer & lexrc)
break;
case RC_FONT_ENCODING:
if (lexrc.next()) {
fontenc = lexrc.getString();
}
lexrc >> fontenc;
break;
case RC_PRINTER:
if (lexrc.next()) {
printer = lexrc.getString();
}
lexrc >> printer;
break;
case RC_PRINT_COMMAND:
if (lexrc.next()) {
print_command = lexrc.getString();
}
lexrc >> print_command;
break;
case RC_PRINTEVENPAGEFLAG:
if (lexrc.next()) {
print_evenpage_flag = lexrc.getString();
}
lexrc >> print_evenpage_flag;
break;
case RC_PRINTODDPAGEFLAG:
if (lexrc.next()) {
print_oddpage_flag = lexrc.getString();
}
lexrc >> print_oddpage_flag;
break;
case RC_PRINTPAGERANGEFLAG:
if (lexrc.next()) {
print_pagerange_flag = lexrc.getString();
}
lexrc >> print_pagerange_flag;
break;
case RC_PRINTCOPIESFLAG:
if (lexrc.next()) {
print_copies_flag = lexrc.getString();
}
lexrc >> print_copies_flag;
break;
case RC_PRINTCOLLCOPIESFLAG:
if (lexrc.next()) {
print_collcopies_flag = lexrc.getString();
}
lexrc >> print_collcopies_flag;
break;
case RC_PRINTREVERSEFLAG:
if (lexrc.next()) {
print_reverse_flag = lexrc.getString();
}
lexrc >> print_reverse_flag;
break;
case RC_PRINTLANDSCAPEFLAG:
if (lexrc.next()) {
print_landscape_flag = lexrc.getString();
}
lexrc >> print_landscape_flag;
break;
case RC_PRINTTOPRINTER:
if (lexrc.next()) {
print_to_printer = lexrc.getString();
}
lexrc >> print_to_printer;
break;
case RC_PRINT_ADAPTOUTPUT:
if (lexrc.next()) {
print_adapt_output = lexrc.getBool();
}
lexrc >> print_adapt_output;
break;
case RC_PRINTTOFILE:
if (lexrc.next()) {
print_to_file = os::internal_path(lexrc.getString());
}
print_to_file = os::internal_path(lexrc.getString());
break;
case RC_PRINTFILEEXTENSION:
if (lexrc.next()) {
print_file_extension = lexrc.getString();
}
lexrc >> print_file_extension;
break;
case RC_PRINTEXSTRAOPTIONS:
if (lexrc.next()) {
print_extra_options = lexrc.getString();
}
lexrc >> print_extra_options;
break;
case RC_PRINTSPOOL_COMMAND:
if (lexrc.next()) {
print_spool_command = lexrc.getString();
}
lexrc >> print_spool_command;
break;
case RC_PRINTSPOOL_PRINTERPREFIX:
if (lexrc.next()) {
print_spool_printerprefix = lexrc.getString();
}
lexrc >> print_spool_printerprefix;
break;
case RC_PRINTPAPERDIMENSIONFLAG:
if (lexrc.next()) {
print_paper_dimension_flag = lexrc.getString();
}
lexrc >> print_paper_dimension_flag;
break;
case RC_PRINTPAPERFLAG:
if (lexrc.next()) {
print_paper_flag = lexrc.getString();
}
lexrc >> print_paper_flag;
break;
case RC_CUSTOM_EXPORT_COMMAND:
if (lexrc.next()) {
custom_export_command = lexrc.getString();
}
lexrc >> custom_export_command;
break;
case RC_CUSTOM_EXPORT_FORMAT:
if (lexrc.next()) {
custom_export_format = lexrc.getString();
}
lexrc >> custom_export_format;
break;
case RC_DEFAULT_PAPERSIZE:
@ -639,94 +589,48 @@ int LyXRC::read(Lexer & lexrc)
break;
case RC_CHKTEX_COMMAND:
if (lexrc.next()) {
chktex_command = lexrc.getString();
}
lexrc >> chktex_command;
break;
case RC_BIBTEX_COMMAND:
if (lexrc.next()) {
bibtex_command = lexrc.getString();
}
lexrc >> bibtex_command;
break;
case RC_INDEX_COMMAND:
if (lexrc.next()) {
index_command = lexrc.getString();
}
lexrc >> index_command;
break;
case RC_SCREEN_DPI:
if (lexrc.next()) {
dpi = lexrc.getInteger();
}
lexrc >> dpi;
break;
case RC_SCREEN_ZOOM:
if (lexrc.next()) {
zoom = lexrc.getInteger();
}
lexrc >> zoom;
break;
case RC_GEOMETRY_SESSION:
if (lexrc.next()) {
allow_geometry_session = lexrc.getBool();
}
lexrc >> allow_geometry_session;
break;
case RC_SCREEN_FONT_SIZES:
if (lexrc.next()) {
font_sizes[FONT_SIZE_TINY] =
lexrc.getString();
}
if (lexrc.next()) {
font_sizes[FONT_SIZE_SCRIPT] =
lexrc.getString();
}
if (lexrc.next()) {
font_sizes[FONT_SIZE_FOOTNOTE] =
lexrc.getString();
}
if (lexrc.next()) {
font_sizes[FONT_SIZE_SMALL] =
lexrc.getString();
}
if (lexrc.next()) {
font_sizes[FONT_SIZE_NORMAL] =
lexrc.getString();
}
if (lexrc.next()) {
font_sizes[FONT_SIZE_LARGE] =
lexrc.getString();
}
if (lexrc.next()) {
font_sizes[FONT_SIZE_LARGER] =
lexrc.getString();
}
if (lexrc.next()) {
font_sizes[FONT_SIZE_LARGEST] =
lexrc.getString();
}
if (lexrc.next()) {
font_sizes[FONT_SIZE_HUGE] =
lexrc.getString();
}
if (lexrc.next()) {
font_sizes[FONT_SIZE_HUGER] =
lexrc.getString();
}
lexrc >> font_sizes[FONT_SIZE_TINY];
lexrc >> font_sizes[FONT_SIZE_SCRIPT];
lexrc >> font_sizes[FONT_SIZE_FOOTNOTE];
lexrc >> font_sizes[FONT_SIZE_SMALL];
lexrc >> font_sizes[FONT_SIZE_NORMAL];
lexrc >> font_sizes[FONT_SIZE_LARGE];
lexrc >> font_sizes[FONT_SIZE_LARGER];
lexrc >> font_sizes[FONT_SIZE_LARGEST];
lexrc >> font_sizes[FONT_SIZE_HUGE];
lexrc >> font_sizes[FONT_SIZE_HUGER];
break;
case RC_SCREEN_FONT_SCALABLE:
if (lexrc.next()) {
use_scalable_fonts = lexrc.getBool();
}
lexrc >> use_scalable_fonts;
break;
case RC_AUTOSAVE:
if (lexrc.next()) {
autosave = lexrc.getInteger();
}
lexrc >> autosave;
break;
case RC_DOCUMENTPATH:
@ -764,87 +668,59 @@ int LyXRC::read(Lexer & lexrc)
break;
case RC_USELASTFILEPOS:
if (lexrc.next()) {
use_lastfilepos = lexrc.getBool();
}
lexrc >> use_lastfilepos;
break;
case RC_LOADSESSION:
if (lexrc.next()) {
load_session = lexrc.getBool();
}
lexrc >> load_session;
break;
case RC_MOUSE_WHEEL_SPEED:
if (lexrc.next()) {
mouse_wheel_speed = lexrc.getFloat();
}
lexrc >> mouse_wheel_speed;
break;
case RC_COMPLETION_INLINE_DELAY:
if (lexrc.next()) {
completion_inline_delay = lexrc.getFloat();
}
lexrc >> completion_inline_delay;
break;
case RC_COMPLETION_INLINE_MATH:
if (lexrc.next()) {
completion_inline_math = lexrc.getBool();
}
lexrc >> completion_inline_math;
break;
case RC_COMPLETION_INLINE_TEXT:
if (lexrc.next()) {
completion_inline_text = lexrc.getBool();
}
lexrc >> completion_inline_text;
break;
case RC_COMPLETION_INLINE_DOTS:
if (lexrc.next()) {
completion_inline_dots = lexrc.getInteger();
}
lexrc >> completion_inline_dots;
break;
case RC_COMPLETION_POPUP_DELAY:
if (lexrc.next()) {
completion_popup_delay = lexrc.getFloat();
}
lexrc >> completion_popup_delay;
break;
case RC_COMPLETION_POPUP_MATH:
if (lexrc.next()) {
completion_popup_math = lexrc.getBool();
}
lexrc >> completion_popup_math;
break;
case RC_COMPLETION_POPUP_TEXT:
if (lexrc.next()) {
completion_popup_text = lexrc.getBool();
}
lexrc >> completion_popup_text;
break;
case RC_COMPLETION_CURSOR_TEXT:
if (lexrc.next()) {
completion_cursor_text = lexrc.getBool();
}
lexrc >> completion_cursor_text;
break;
case RC_COMPLETION_POPUP_AFTER_COMPLETE:
if (lexrc.next()) {
completion_popup_after_complete = lexrc.getBool();
}
lexrc >> completion_popup_after_complete;
break;
case RC_NUMLASTFILES:
if (lexrc.next()) {
num_lastfiles = lexrc.getInteger();
}
lexrc >> num_lastfiles;
break;
case RC_CHECKLASTFILES:
if (lexrc.next()) {
check_lastfiles = lexrc.getBool();
}
lexrc >> check_lastfiles;
break;
case RC_SCREEN_FONT_ROMAN:
@ -1106,68 +982,32 @@ int LyXRC::read(Lexer & lexrc)
case RC_COPIER: {
string fmt, command;
if (lexrc.next()) {
fmt = lexrc.getString();
}
if (lexrc.next()) {
command = lexrc.getString();
}
lexrc >> fmt >> command;
setMover(fmt, command);
break;
}
case RC_CONVERTER: {
string from, to, command, flags;
if (lexrc.next()) {
from = lexrc.getString();
}
if (lexrc.next()) {
to = lexrc.getString();
}
if (lexrc.next()) {
command = lexrc.getString();
}
if (lexrc.next()) {
flags = lexrc.getString();
}
if (command.empty()) {
lexrc >> from >> to >> command >> flags;
if (command.empty())
theConverters().erase(from, to);
} else {
else
theConverters().add(from, to, command, flags);
}
break;
}
// compatibility with versions older than 1.4.0 only
case RC_VIEWER: {
string format, command;
if (lexrc.next()) {
format = lexrc.getString();
}
if (lexrc.next()) {
command = lexrc.getString();
}
lexrc >> format >> command;
formats.setViewer(format, command);
break;
}
case RC_FORMAT: {
string format, extension, prettyname, shortcut;
if (lexrc.next()) {
format = lexrc.getString();
}
if (lexrc.next()) {
extension = lexrc.getString();
}
if (lexrc.next()) {
prettyname = lexrc.getString();
}
if (lexrc.next()) {
shortcut = lexrc.getString();
}
lexrc >> format >> extension >> prettyname >> shortcut;
string viewer, editor;
if (lexrc.next())
viewer = lexrc.getString();
if (lexrc.next())
editor = lexrc.getString();
lexrc >> viewer >> editor;
string flags;
// Hack to ensure compatibility with versions older
// than 1.5.0
@ -1313,7 +1153,7 @@ int LyXRC::read(Lexer & lexrc)
case RC_OPEN_BUFFERS_IN_TABS:
if (lexrc.next())
open_buffers_in_tabs = lexrc.getBool();
break;
break;
case RC_USE_BUNDLED_FORMAT:
if (lexrc.next())
use_bundled_format = lexrc.getBool();

View File

@ -584,128 +584,19 @@ void InsetBoxParams::write(ostream & os) const
void InsetBoxParams::read(Lexer & lex)
{
if (!lex.isOK())
return;
lex.next();
type = lex.getString();
if (!lex)
return;
lex.next();
string token;
token = lex.getString();
if (!lex)
return;
if (token == "position") {
lex.next();
// The [0] is needed. We need the first and only char in
// this string -- MV
pos = lex.getString()[0];
} else {
lyxerr << "InsetBox::Read: Missing 'position'-tag!" << token << endl;
lex.pushToken(token);
}
lex.next();
token = lex.getString();
if (!lex)
return;
if (token == "hor_pos") {
lex.next();
hor_pos = lex.getString()[0];
} else {
lyxerr << "InsetBox::Read: Missing 'hor_pos'-tag!" << token << endl;
lex.pushToken(token);
}
lex.next();
token = lex.getString();
if (!lex)
return;
if (token == "has_inner_box") {
lex.next();
inner_box = lex.getInteger();
if (type == "Framed")
inner_box = false;
} else {
lyxerr << "InsetBox::Read: Missing 'has_inner_box'-tag!" << endl;
lex.pushToken(token);
}
lex.next();
token = lex.getString();
if (!lex)
return;
if (token == "inner_pos") {
lex.next();
inner_pos = lex.getString()[0];
} else {
lyxerr << "InsetBox::Read: Missing 'inner_pos'-tag!"
<< token << endl;
lex.pushToken(token);
}
lex.next();
token = lex.getString();
if (!lex)
return;
if (token == "use_parbox") {
lex.next();
use_parbox = lex.getInteger();
} else {
lyxerr << "InsetBox::Read: Missing 'use_parbox'-tag!" << endl;
lex.pushToken(token);
}
lex.next();
token = lex.getString();
if (!lex)
return;
if (token == "width") {
lex.next();
width = Length(lex.getString());
} else {
lyxerr << "InsetBox::Read: Missing 'width'-tag!" << endl;
lex.pushToken(token);
}
lex.next();
token = lex.getString();
if (!lex)
return;
if (token == "special") {
lex.next();
special = lex.getString();
} else {
lyxerr << "InsetBox::Read: Missing 'special'-tag!" << endl;
lex.pushToken(token);
}
lex.next();
token = lex.getString();
if (!lex)
return;
if (token == "height") {
lex.next();
height = Length(lex.getString());
} else {
lyxerr << "InsetBox::Read: Missing 'height'-tag!" << endl;
lex.pushToken(token);
}
lex.next();
token = lex.getString();
if (!lex)
return;
if (token == "height_special") {
lex.next();
height_special = lex.getString();
} else {
lyxerr << "InsetBox::Read: Missing 'height_special'-tag!" << endl;
lex.pushToken(token);
}
lex.setContext("InsetBoxParams::read");
lex >> type;
lex >> "position" >> pos;
lex >> "hor_pos" >> hor_pos;
lex >> "has_inner_box" >> inner_box;
if (type == "Framed")
inner_box = false;
lex >> "inner_pos" >> inner_pos;
lex >> "use_parbox" >> use_parbox;
lex >> "width" >> width;
lex >> "special" >> special;
lex >> "height" >> height;
lex >> "height_special" >> height_special;
}

View File

@ -283,25 +283,8 @@ void InsetBranch::string2params(string const & in, InsetBranchParams & params)
istringstream data(in);
Lexer lex;
lex.setStream(data);
string name;
lex >> name;
if (name != "branch") {
LYXERR0("InsetBranch::string2params(" << in << ")\n"
"Expected arg 1 to be \"branch\"\n");
return;
}
// This is part of the inset proper that is usually swallowed
// by Text::readInset
string id;
lex >> id;
if (!lex || id != "Branch") {
LYXERR0("InsetBranch::string2params(" << in << ")\n"
"Expected arg 2 to be \"Branch\"\n");
return;
}
lex.setContext("InsetBranch::string2params");
lex >> "branch" >> "Branch";
params.read(lex);
}

View File

@ -70,11 +70,8 @@ void InsetCaption::read(Lexer & lex)
#if 0
// We will enably this check again when the compability
// code is removed from Buffer::Read (Lgb)
string const token = lex.GetString();
if (token != "Caption") {
lyxerr << "InsetCaption::Read: consistency check failed."
<< endl;
}
lex.setContext("InsetCaption::Read: consistency check");
lex >> "Caption";
#endif
InsetText::read(lex);
}

View File

@ -158,40 +158,19 @@ void InsetCollapsable::write(ostream & os) const
void InsetCollapsable::read(Lexer & lex)
{
bool token_found = false;
if (lex.isOK()) {
lex.next();
string const token = lex.getString();
if (token == "status") {
lex.next();
string const tmp_token = lex.getString();
lex.setContext("InsetCollapsable::read");
string tmp_token;
status_ = Collapsed;
lex >> "status";
lex >> tmp_token;
if (tmp_token == "open")
status_ = Open;
if (tmp_token == "collapsed") {
status_ = Collapsed;
token_found = true;
} else if (tmp_token == "open") {
status_ = Open;
token_found = true;
} else {
lyxerr << "InsetCollapsable::read: Missing status!"
<< endl;
// Take countermeasures
lex.pushToken(token);
}
} else {
LYXERR0("InsetCollapsable::read: Missing 'status'-tag!");
// take countermeasures
lex.pushToken(token);
}
}
// this must be set before we enter InsetText::read()
setLayout(buffer().params());
InsetText::read(lex);
if (!token_found)
status_ = isOpen() ? Open : Collapsed;
// Force default font, if so requested
// This avoids paragraphs in buffer language that would have a
// foreign language after a document language change, and it ensures

View File

@ -194,31 +194,12 @@ bool InsetCommand::string2params(string const & name, string const & in,
InsetCommandParams & params)
{
params.clear();
if (in.empty())
return false;
istringstream data(in);
Lexer lex;
lex.setStream(data);
string n;
lex >> n;
if (!lex || n != name) {
LYXERR0("InsetCommand::string2params(" << in << ")\n"
"Expected arg 1 to be \"" << name << "\"\n");
return false;
}
// This is part of the inset proper that is usually swallowed
// by Text::readInset
string id;
lex >> id;
if (!lex || id != "CommandInset") {
LYXERR0("InsetCommand::string2params(" << in << ")\n"
"Expected arg 2 to be \"CommandInset\"\n");
return false;
}
lex.setContext("InsetCommand::string2params");
lex >> name.c_str(); // check for name
lex >> "CommandInset";
params.read(lex);
return true;
}

View File

@ -258,30 +258,12 @@ void InsetCommandParams::setCmdName(string const & name)
void InsetCommandParams::read(Lexer & lex)
{
if (lex.isOK()) {
lex.next();
string const insetType = lex.getString();
InsetCode const code = insetCode(insetType);
if (code != insetCode_) {
lex.printError("InsetCommandParams: Attempt to change type of inset.");
throw ExceptionMessage(WarningException, _("InsetCommandParams Error: "),
_("Attempt to change type of parameters."));
}
}
if (lex.isOK()) {
lex.next();
string const test = lex.getString();
if (test != "LatexCommand") {
lex.printError("InsetCommandParams: No LatexCommand line found.");
throw ExceptionMessage(WarningException, _("InsetCommandParams error: "),
_("Can't find LatexCommand line."));
}
}
lex.next();
cmdName_ = lex.getString();
if (!isCompatibleCommand(insetCode_, cmdName_)){
lex.printError("InsetCommandParams: Incompatible command name " + cmdName_ + ".");
lex.setContext("InsetCommandParams::read");
lex >> insetName(insetCode_).c_str();
lex >> "LatexCommand";
lex >> cmdName_;
if (!isCompatibleCommand(insetCode_, cmdName_)) {
lex.printError("Incompatible command name " + cmdName_ + ".");
throw ExceptionMessage(WarningException, _("InsetCommandParams Error: "),
_("Incompatible command name."));
}

View File

@ -192,26 +192,16 @@ bool InsetERT::showInsetDialog(BufferView * bv) const
InsetCollapsable::CollapseStatus InsetERT::string2params(string const & in)
{
CollapseStatus status = Collapsed;
if (in.empty())
return status;
return Collapsed;
istringstream data(in);
Lexer lex;
lex.setStream(data);
string name;
lex >> name;
if (name != "ert") {
LYXERR0("Expected arg 1 to be \"ert\" in " << in);
return status;
}
lex.setContext("InsetERT::string2params");
lex >> "ert";
int s;
lex >> s;
if (lex)
status = static_cast<CollapseStatus>(s);
return status;
return static_cast<CollapseStatus>(s);
}

View File

@ -71,17 +71,14 @@ void InsetFlex::write(ostream & os) const
void InsetFlex::read(Lexer & lex)
{
string token;
while (lex.isOK()) {
lex.next();
string token = lex.getString();
lex >> token;
if (token == "Flex") {
lex.next();
name_ = lex.getString();
}
// This is handled in Collapsable
else if (token == "status") {
} else if (token == "status") {
// This is handled in Collapsable
lex.pushToken(token);
break;
}

View File

@ -216,32 +216,11 @@ void InsetFloatParams::write(ostream & os) const
void InsetFloatParams::read(Lexer & lex)
{
string token;
lex >> token;
if (token == "placement") {
lex.setContext("InsetFloatParams::read");
if (lex.checkFor("placement"))
lex >> placement;
} else {
// take countermeasures
lex.pushToken(token);
}
lex >> token;
if (token == "wide") {
lex >> wide;
} else {
lyxerr << "InsetFloat::Read:: Missing wide!"
<< endl;
// take countermeasures
lex.pushToken(token);
}
lex >> token;
if (token == "sideways") {
lex >> sideways;
} else {
lyxerr << "InsetFloat::Read:: Missing sideways!"
<< endl;
// take countermeasures
lex.pushToken(token);
}
lex >> "wide" >> wide;
lex >> "sideways" >> sideways;
}
@ -454,25 +433,9 @@ void InsetFloat::string2params(string const & in, InsetFloatParams & params)
istringstream data(in);
Lexer lex;
lex.setStream(data);
string name;
lex >> name;
if (!lex || name != "float") {
LYXERR0("InsetFloat::string2params(" << in << ")\n"
"Expected arg 1 to be \"float\"\n");
}
// This is part of the inset proper that is usually swallowed
// by Text::readInset
string id;
lex >> id;
if (!lex || id != "Float") {
LYXERR0("InsetFloat::string2params(" << in << ")\n"
"Expected arg 1 to be \"Float\"\n");
}
// We have to read the type here!
lex >> params.type;
lex.setContext("InsetFloat::string2params");
lex >> "float" >> "Float";
lex >> params.type; // We have to read the type here!
params.read(lex);
}

View File

@ -301,13 +301,9 @@ void InsetGraphics::write(ostream & os) const
void InsetGraphics::read(Lexer & lex)
{
string const token = lex.getString();
if (token == "Graphics")
readInsetGraphics(lex, buffer().filePath(), params_);
else
LYXERR(Debug::GRAPHICS, "Not a Graphics inset!");
lex.setContext("InsetGraphics::read");
//lex >> "Graphics";
readInsetGraphics(lex, buffer().filePath(), params_);
params_.filename.enable(buffer().embedded(), buffer(), false);
graphic_->update(params().as_grfxParams());
}
@ -963,15 +959,8 @@ void InsetGraphics::string2params(string const & in, Buffer const & buffer,
istringstream data(in);
Lexer lex;
lex.setStream(data);
string name;
lex >> name;
if (!lex || name != "graphics") {
LYXERR0("InsetGraphics::string2params(" << in << ")\n"
"Expected arg 1 to be \"graphics\"\n");
return;
}
lex.setContext("InsetGraphics::string2params");
lex >> "graphics";
params = InsetGraphicsParams();
readInsetGraphics(lex, buffer.filePath(), params);
}

View File

@ -54,9 +54,9 @@ InsetLayout::InsetDecoration translateDecoration(std::string const & str)
}
bool InsetLayout::read(Lexer & lexrc)
bool InsetLayout::read(Lexer & lex)
{
name_ = support::subst(lexrc.getDocString(), '_', ' ');
name_ = support::subst(lex.getDocString(), '_', ' ');
enum {
IL_FONT,
@ -101,93 +101,82 @@ bool InsetLayout::read(Lexer & lexrc)
{ "requires", IL_REQUIRES }
};
lexrc.pushTable(elementTags);
lex.pushTable(elementTags);
FontInfo font = inherit_font;
labelfont_ = inherit_font;
bgcolor_ = Color_background;
bool getout = false;
while (!getout && lexrc.isOK()) {
int le = lexrc.lex();
string tmp;
while (!getout && lex.isOK()) {
int le = lex.lex();
switch (le) {
case Lexer::LEX_UNDEF:
lexrc.printError("Unknown InsetLayout tag `$$Token'");
lex.printError("Unknown InsetLayout tag `$$Token'");
continue;
default: break;
}
switch (le) {
case IL_LYXTYPE:
lexrc.next();
lyxtype_ = lexrc.getString();
lex >> lyxtype_;
break;
case IL_LATEXTYPE:
lexrc.next();
latextype_ = lexrc.getString();
lex >> latextype_;
break;
case IL_LABELSTRING:
lexrc.next();
labelstring_ = lexrc.getDocString();
lex >> labelstring_;
break;
case IL_DECORATION:
lexrc.next();
decoration_ = translateDecoration(lexrc.getString());
lex >> tmp;
decoration_ = translateDecoration(tmp);
break;
case IL_LATEXNAME:
lexrc.next();
latexname_ = lexrc.getString();
lex >> latexname_;
break;
case IL_LATEXPARAM:
lexrc.next();
latexparam_ = support::subst(lexrc.getString(), "&quot;", "\"");
lex >> tmp;
latexparam_ = support::subst(tmp, "&quot;", "\"");
break;
case IL_LABELFONT:
labelfont_ = lyxRead(lexrc, inherit_font);
labelfont_ = lyxRead(lex, inherit_font);
break;
case IL_FORCELTR:
lexrc.next();
forceltr_ = lexrc.getBool();
lex >> forceltr_;
break;
case IL_MULTIPAR:
lexrc.next();
multipar_ = lexrc.getBool();
lex >> multipar_;
break;
case IL_PASSTHRU:
lexrc.next();
passthru_ = lexrc.getBool();
lex >> passthru_;
break;
case IL_KEEPEMPTY:
lexrc.next();
keepempty_ = lexrc.getBool();
lex >> keepempty_;
break;
case IL_FREESPACING:
lexrc.next();
freespacing_ = lexrc.getBool();
lex >> freespacing_;
break;
case IL_NEEDPROTECT:
lexrc.next();
needprotect_ = lexrc.getBool();
lex >> needprotect_;
break;
case IL_FONT: {
font_ = lyxRead(lexrc, inherit_font);
font_ = lyxRead(lex, inherit_font);
// If you want to define labelfont, you need to do so after
// font is defined.
labelfont_ = font_;
break;
}
case IL_BGCOLOR: {
lexrc.next();
string const token = lexrc.getString();
bgcolor_ = lcolor.getFromLyXName(token);
case IL_BGCOLOR:
lex >> tmp;
bgcolor_ = lcolor.getFromLyXName(tmp);
break;
}
case IL_PREAMBLE:
preamble_ = lexrc.getLongString("EndPreamble");
preamble_ = lex.getLongString("EndPreamble");
break;
case IL_REQUIRES: {
lexrc.eatLine();
lex.eatLine();
vector<string> const req
= support::getVectorFromString(lexrc.getString());
= support::getVectorFromString(lex.getString());
requires_.insert(req.begin(), req.end());
break;
}
@ -205,7 +194,7 @@ bool InsetLayout::read(Lexer & lexrc)
// any realization against a given context.
labelfont_.realize(sane_font);
lexrc.popTable();
lex.popTable();
return true;
}

View File

@ -100,7 +100,7 @@ void InsetListings::read(Lexer & lex)
{
while (lex.isOK()) {
lex.next();
string const token = lex.getString();
string token = lex.getString();
if (token == "lstparams") {
lex.next();
string const value = lex.getString();

View File

@ -710,10 +710,9 @@ void InsetListingsParams::write(ostream & os) const
void InsetListingsParams::read(Lexer & lex)
{
lex >> inline_;
int s;
int s = Inset::Collapsed;
lex >> s;
if (lex)
status_ = static_cast<InsetCollapsable::CollapseStatus>(s);
status_ = static_cast<InsetCollapsable::CollapseStatus>(s);
string par;
lex >> par;
fromEncodedString(par);

View File

@ -52,23 +52,16 @@ void InsetNewlineParams::write(ostream & os) const
void InsetNewlineParams::read(Lexer & lex)
{
lex.next();
string const command = lex.getString();
if (command == "newline")
string token;
lex.setContext("InsetNewlineParams::read");
lex >> token;
if (token == "newline")
kind = InsetNewlineParams::NEWLINE;
else if (command == "linebreak")
else if (token == "linebreak")
kind = InsetNewlineParams::LINEBREAK;
else
lex.printError("InsetNewline: Unknown kind: `$$Token'");
string token;
lex >> token;
if (!lex)
return;
if (token != "\\end_inset")
lex.printError("Missing \\end_inset at this point. "
"Read: `$$Token'");
lex.printError("Unknown kind: `$$Token'");
lex >> "\\end_inset";
}
@ -267,18 +260,11 @@ void InsetNewline::string2params(string const & in, InsetNewlineParams & params)
params = InsetNewlineParams();
if (in.empty())
return;
istringstream data(in);
Lexer lex;
lex.setStream(data);
string name;
lex >> name;
if (!lex || name != "newline") {
LYXERR0("Expected arg 1 to be \"newlien\" in " << in);
return;
}
lex.setContext("InsetNewline::string2params");
lex >> "newline";
params.read(lex);
}

View File

@ -65,27 +65,22 @@ void InsetNewpageParams::write(ostream & os) const
void InsetNewpageParams::read(Lexer & lex)
{
lex.next();
string const command = lex.getString();
if (command == "newpage")
kind = InsetNewpageParams::NEWPAGE;
else if (command == "pagebreak")
kind = InsetNewpageParams::PAGEBREAK;
else if (command == "clearpage")
kind = InsetNewpageParams::CLEARPAGE;
else if (command == "cleardoublepage")
kind = InsetNewpageParams::CLEARDOUBLEPAGE;
else
lex.printError("InsetNewpage: Unknown kind: `$$Token'");
lex.setContext("InsetNewpageParams::read");
string token;
lex >> token;
if (!lex)
return;
if (token != "\\end_inset")
lex.printError("Missing \\end_inset at this point. "
"Read: `$$Token'");
if (token == "newpage")
kind = InsetNewpageParams::NEWPAGE;
else if (token == "pagebreak")
kind = InsetNewpageParams::PAGEBREAK;
else if (token == "clearpage")
kind = InsetNewpageParams::CLEARPAGE;
else if (token == "cleardoublepage")
kind = InsetNewpageParams::CLEARDOUBLEPAGE;
else
lex.printError("Unknown kind: `$$Token'");
lex >> "\\end_inset";
}

View File

@ -370,22 +370,8 @@ void InsetNote::string2params(string const & in, InsetNoteParams & params)
istringstream data(in);
Lexer lex;
lex.setStream(data);
string name;
lex >> name;
if (!lex || name != "note") {
LYXERR0("Expected arg 1 to be \"note\" in " << in);
return;
}
// This is part of the inset proper that is usually swallowed
// by Text::readInset
string id;
lex >> id;
if (!lex || id != "Note") {
LYXERR0("Expected arg 1 to be \"Note\" in " << in);
return;
}
lex.setContext("InsetNote::string2params");
lex >> "note" >> "Note";
params.read(lex);
}

View File

@ -276,12 +276,10 @@ void InsetQuotes::write(ostream & os) const
void InsetQuotes::read(Lexer & lex)
{
lex.setContext("InsetQuotes::read");
lex.next();
parseString(lex.getString());
lex.next();
if (lex.getString() != "\\end_inset") {
lex.printError("Missing \\end_inset at this point");
}
lex >> "\\end_inset";
}

View File

@ -510,10 +510,10 @@ void InsetSpace::textString(odocstream & os) const
bool InsetSpace::isStretchableSpace() const
{
return (params_.kind == InsetSpaceParams::HFILL ||
params_.kind == InsetSpaceParams::HFILL_PROTECTED ||
params_.kind == InsetSpaceParams::DOTFILL ||
params_.kind == InsetSpaceParams::HRULEFILL);
return params_.kind == InsetSpaceParams::HFILL
|| params_.kind == InsetSpaceParams::HFILL_PROTECTED
|| params_.kind == InsetSpaceParams::DOTFILL
|| params_.kind == InsetSpaceParams::HRULEFILL;
}
@ -532,13 +532,8 @@ void InsetSpace::string2params(string const & in, InsetSpaceParams & params)
istringstream data(in);
Lexer lex;
lex.setStream(data);
string name;
lex >> name;
if (!lex || name != "space") {
LYXERR0("Expected arg 1 to be \"space\" in " << in);
return;
}
lex.setContext("InsetSpace::string2params");
lex >> "space";
params.read(lex);
}

View File

@ -2815,12 +2815,12 @@ docstring InsetTabular::contextMenu(BufferView const &, int, int) const
void InsetTabular::read(Lexer & lex)
{
bool const old_format = (lex.getString() == "\\LyXTable");
//bool const old_format = (lex.getString() == "\\LyXTable");
tabular.read(lex);
if (old_format)
return;
//if (old_format)
// return;
lex.next();
string token = lex.getString();

View File

@ -257,18 +257,8 @@ void InsetVSpace::string2params(string const & in, VSpace & vspace)
istringstream data(in);
Lexer lex;
lex.setStream(data);
string name;
lex >> name;
if (!lex || name != "vspace") {
LYXERR0("Expected arg 1 to be \"vspace\" in " << in);
return;
}
string vsp;
lex >> vsp;
if (lex)
vspace = VSpace(vsp);
lex.setContext("InsetVSpace::string2params");
lex >> "vspace" >> vspace;
}