simplify Lexer handling a bit more

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24106 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2008-04-03 20:55:09 +00:00
parent 13b5a9e3ce
commit c88e7a7ef6
14 changed files with 191 additions and 208 deletions

View File

@ -28,23 +28,18 @@ using namespace lyx::support;
namespace lyx {
namespace {
enum CmdDefTags {
BN_DEFFILE,
BN_DEFINE
};
LexerKeyword cmdDefTags[] = {
{ "\\def_file", BN_DEFFILE },
{ "\\define", BN_DEFINE }
};
}
bool CmdDef::read(string const & def_file)
{
enum {
BN_DEFFILE,
BN_DEFINE
};
LexerKeyword cmdDefTags[] = {
{ "\\def_file", BN_DEFFILE },
{ "\\define", BN_DEFINE }
};
Lexer lexrc(cmdDefTags);
if (lyxerr.debugging(Debug::PARSER))
lexrc.printTable(lyxerr);
@ -108,7 +103,7 @@ bool CmdDef::read(string const & def_file)
}
case BN_DEFFILE:
if (lexrc.next()) {
string const tmp(lexrc.getString());
string const tmp = lexrc.getString();
error |= !read(tmp);
} else {
lexrc.printError("BN_DEFFILE: Missing file name");
@ -157,10 +152,10 @@ bool CmdDef::lock(string const & name, FuncRequest & func)
void CmdDef::release(string const & name)
{
string const name2 = trim(name);
lockSet.erase(name2);
}
CmdDef::newCmdDefResult CmdDef::newCmdDef(string const & name,
string const & def)
{
@ -173,8 +168,8 @@ CmdDef::newCmdDefResult CmdDef::newCmdDef(string const & name,
return CmdDefExists;
FuncRequest func = lyxaction.lookupFunc(def);
if (func.action == LFUN_NOACTION ||
func.action == LFUN_UNKNOWN_ACTION) {
if (func.action == LFUN_NOACTION
|| func.action == LFUN_UNKNOWN_ACTION) {
return CmdDefInvalid;
}

View File

@ -522,12 +522,12 @@ void Encodings::read(FileName const & encfile, FileName const & symbolsfile)
}
// Now read the encodings
enum Encodingtags {
enum {
et_encoding = 1,
et_end,
};
struct LexerKeyword encodingtags[] = {
LexerKeyword encodingtags[] = {
{ "encoding", et_encoding },
{ "end", et_end }
};

View File

@ -117,25 +117,20 @@ void KeyMap::clear()
}
namespace {
enum BindTags {
BN_BIND,
BN_BINDFILE,
BN_UNBIND,
};
LexerKeyword bindTags[] = {
{ "\\bind", BN_BIND },
{ "\\bind_file", BN_BINDFILE },
{ "\\unbind", BN_UNBIND },
};
}
bool KeyMap::read(string const & bind_file, KeyMap * unbind_map)
{
enum {
BN_BIND,
BN_BINDFILE,
BN_UNBIND,
};
LexerKeyword bindTags[] = {
{ "\\bind", BN_BIND },
{ "\\bind_file", BN_BINDFILE },
{ "\\unbind", BN_UNBIND },
};
Lexer lexrc(bindTags);
if (lyxerr.debugging(Debug::PARSER))
lexrc.printTable(lyxerr);

View File

@ -504,7 +504,7 @@ bool Layout::read(Lexer & lexrc, TextClass const & tclass)
}
enum AlignTags {
enum {
AT_BLOCK = 1,
AT_LEFT,
AT_RIGHT,
@ -512,7 +512,6 @@ enum AlignTags {
AT_LAYOUT
};
void Layout::readAlign(Lexer & lexrc)
{
LexerKeyword alignTags[] = {
@ -523,7 +522,7 @@ void Layout::readAlign(Lexer & lexrc)
{ "right", AT_RIGHT }
};
PushPopHelper pph(lexrc, alignTags, AT_LAYOUT);
PushPopHelper pph(lexrc, alignTags);
int le = lexrc.lex();
switch (le) {
case Lexer::LEX_UNDEF:
@ -531,7 +530,7 @@ void Layout::readAlign(Lexer & lexrc)
return;
default: break;
};
switch (static_cast<AlignTags>(le)) {
switch (le) {
case AT_BLOCK:
align = LYX_ALIGN_BLOCK;
break;
@ -572,7 +571,7 @@ void Layout::readAlignPossible(Lexer & lexrc)
continue;
default: break;
};
switch (static_cast<AlignTags>(le)) {
switch (le) {
case AT_BLOCK:
alignpossible |= LYX_ALIGN_BLOCK;
break;
@ -594,36 +593,36 @@ void Layout::readAlignPossible(Lexer & lexrc)
}
enum LabelTypeTags {
LA_NO_LABEL = 1,
LA_MANUAL,
LA_TOP_ENVIRONMENT,
LA_CENTERED_TOP_ENVIRONMENT,
LA_STATIC,
LA_SENSITIVE,
LA_COUNTER,
LA_ENUMERATE,
LA_ITEMIZE,
LA_BIBLIO
};
void Layout::readLabelType(Lexer & lexrc)
{
LexerKeyword labelTypeTags[] = {
{ "bibliography", LA_BIBLIO },
{ "centered_top_environment", LA_CENTERED_TOP_ENVIRONMENT },
{ "counter", LA_COUNTER },
{ "enumerate", LA_ENUMERATE },
{ "itemize", LA_ITEMIZE },
{ "manual", LA_MANUAL },
{ "no_label", LA_NO_LABEL },
{ "sensitive", LA_SENSITIVE },
{ "static", LA_STATIC },
{ "top_environment", LA_TOP_ENVIRONMENT }
enum {
LA_NO_LABEL = 1,
LA_MANUAL,
LA_TOP_ENVIRONMENT,
LA_CENTERED_TOP_ENVIRONMENT,
LA_STATIC,
LA_SENSITIVE,
LA_COUNTER,
LA_ENUMERATE,
LA_ITEMIZE,
LA_BIBLIO
};
PushPopHelper pph(lexrc, labelTypeTags, LA_BIBLIO);
LexerKeyword labelTypeTags[] = {
{ "bibliography", LA_BIBLIO },
{ "centered_top_environment", LA_CENTERED_TOP_ENVIRONMENT },
{ "counter", LA_COUNTER },
{ "enumerate", LA_ENUMERATE },
{ "itemize", LA_ITEMIZE },
{ "manual", LA_MANUAL },
{ "no_label", LA_NO_LABEL },
{ "sensitive", LA_SENSITIVE },
{ "static", LA_STATIC },
{ "top_environment", LA_TOP_ENVIRONMENT }
};
PushPopHelper pph(lexrc, labelTypeTags);
int le = lexrc.lex();
switch (le) {
case Lexer::LEX_UNDEF:
@ -631,7 +630,7 @@ void Layout::readLabelType(Lexer & lexrc)
return;
default: break;
}
switch (static_cast<LabelTypeTags>(le)) {
switch (le) {
case LA_NO_LABEL:
labeltype = LABEL_NO_LABEL;
break;
@ -666,19 +665,16 @@ void Layout::readLabelType(Lexer & lexrc)
}
static LexerKeyword endlabelTypeTags[] =
{
{ "box", END_LABEL_BOX },
{ "filled_box", END_LABEL_FILLED_BOX },
{ "no_label", END_LABEL_NO_LABEL },
{ "static", END_LABEL_STATIC }
};
void Layout::readEndLabelType(Lexer & lexrc)
{
PushPopHelper pph(lexrc, endlabelTypeTags,
END_LABEL_ENUM_LAST-END_LABEL_ENUM_FIRST+1);
static LexerKeyword endlabelTypeTags[] = {
{ "box", END_LABEL_BOX },
{ "filled_box", END_LABEL_FILLED_BOX },
{ "no_label", END_LABEL_NO_LABEL },
{ "static", END_LABEL_STATIC }
};
PushPopHelper pph(lexrc, endlabelTypeTags);
int le = lexrc.lex();
switch (le) {
case Lexer::LEX_UNDEF:
@ -708,7 +704,7 @@ void Layout::readMargin(Lexer & lexrc)
{ "static", MARGIN_STATIC }
};
PushPopHelper pph(lexrc, marginTags, MARGIN_RIGHT_ADDRESS_BOX);
PushPopHelper pph(lexrc, marginTags);
int le = lexrc.lex();
switch (le) {
@ -741,7 +737,7 @@ void Layout::readLatexType(Lexer & lexrc)
{ "paragraph", LATEX_PARAGRAPH }
};
PushPopHelper pph(lexrc, latexTypeTags, LATEX_LIST_ENVIRONMENT);
PushPopHelper pph(lexrc, latexTypeTags);
int le = lexrc.lex();
switch (le) {
case Lexer::LEX_UNDEF:
@ -763,16 +759,15 @@ void Layout::readLatexType(Lexer & lexrc)
}
enum SpacingTags {
ST_SPACING_SINGLE = 1,
ST_SPACING_ONEHALF,
ST_SPACING_DOUBLE,
ST_OTHER
};
void Layout::readSpacing(Lexer & lexrc)
{
enum {
ST_SPACING_SINGLE = 1,
ST_SPACING_ONEHALF,
ST_SPACING_DOUBLE,
ST_OTHER
};
LexerKeyword spacingTags[] = {
{"double", ST_SPACING_DOUBLE },
{"onehalf", ST_SPACING_ONEHALF },
@ -780,7 +775,7 @@ void Layout::readSpacing(Lexer & lexrc)
{"single", ST_SPACING_SINGLE }
};
PushPopHelper pph(lexrc, spacingTags, ST_OTHER);
PushPopHelper pph(lexrc, spacingTags);
int le = lexrc.lex();
switch (le) {
case Lexer::LEX_UNDEF:
@ -788,7 +783,7 @@ void Layout::readSpacing(Lexer & lexrc)
return;
default: break;
}
switch (static_cast<SpacingTags>(le)) {
switch (le) {
case ST_SPACING_SINGLE:
spacing.set(Spacing::Single);
break;

View File

@ -67,7 +67,7 @@ public:
///
bool next(bool esc = false);
///
int search_kw(char const * const tag) const;
int searchKeyword(char const * const tag) const;
///
int lex();
///
@ -424,7 +424,7 @@ bool Lexer::Pimpl::next(bool esc /* = false */)
}
int Lexer::Pimpl::search_kw(char const * const tag) const
int Lexer::Pimpl::searchKeyword(char const * const tag) const
{
LexerKeyword search_tag = { tag, 0 };
LexerKeyword * res =
@ -444,7 +444,7 @@ int Lexer::Pimpl::lex()
{
//NOTE: possible bug.
if (next() && status == LEX_TOKEN)
return search_kw(getString().c_str());
return searchKeyword(getString().c_str());
return status;
}
@ -721,7 +721,7 @@ string const Lexer::getLongString(string const & endtoken)
LYXERR(Debug::PARSER, "LongString: `" << getString() << '\'');
// We do a case independent comparison, like search_kw does.
// We do a case independent comparison, like searchKeyword does.
if (compare_ascii_no_case(token, endtoken) == 0)
break;

View File

@ -216,10 +216,11 @@ class PushPopHelper
{
public:
///
PushPopHelper(Lexer & lexrc, LexerKeyword * i, int s)
: lex(lexrc)
template<int N>
PushPopHelper(Lexer & l, LexerKeyword (&table)[N])
: lex(l)
{
lex.pushTable(i, s);
lex.pushTable(table, N);
}
///
~PushPopHelper()

View File

@ -987,7 +987,7 @@ bool LyX::readUIFile(string const & name, bool include)
ui_last
};
struct LexerKeyword uitags[] = {
LexerKeyword uitags[] = {
{ "include", ui_include },
{ "menuset", ui_menuset },
{ "toolbars", ui_toolbars },

View File

@ -195,7 +195,8 @@ LyXRC::LyXRC()
}
void LyXRC::setDefaults() {
void LyXRC::setDefaults()
{
bind_file = "cua";
def_file = "default";
ui_file = "default";

View File

@ -622,10 +622,10 @@ void TextClass::readTitleType(Lexer & lexrc)
{
LexerKeyword titleTypeTags[] = {
{ "commandafter", TITLE_COMMAND_AFTER },
{ "environment", TITLE_ENVIRONMENT }
{ "environment", TITLE_ENVIRONMENT }
};
PushPopHelper pph(lexrc, titleTypeTags, TITLE_ENVIRONMENT);
PushPopHelper pph(lexrc, titleTypeTags);
int le = lexrc.lex();
switch (le) {
@ -648,12 +648,12 @@ void TextClass::readTitleType(Lexer & lexrc)
void TextClass::readOutputType(Lexer & lexrc)
{
LexerKeyword outputTypeTags[] = {
{ "docbook", DOCBOOK },
{ "latex", LATEX },
{ "docbook", DOCBOOK },
{ "latex", LATEX },
{ "literate", LITERATE }
};
PushPopHelper pph(lexrc, outputTypeTags, LITERATE);
PushPopHelper pph(lexrc, outputTypeTags);
int le = lexrc.lex();
switch (le) {
@ -674,22 +674,21 @@ void TextClass::readOutputType(Lexer & lexrc)
}
enum ClassOptionsTags {
CO_FONTSIZE = 1,
CO_PAGESTYLE,
CO_OTHER,
CO_HEADER,
CO_END
};
void TextClass::readClassOptions(Lexer & lexrc)
{
enum {
CO_FONTSIZE = 1,
CO_PAGESTYLE,
CO_OTHER,
CO_HEADER,
CO_END
};
LexerKeyword classOptionsTags[] = {
{"end", CO_END },
{"fontsize", CO_FONTSIZE },
{"header", CO_HEADER },
{"other", CO_OTHER },
{"end", CO_END },
{"fontsize", CO_FONTSIZE },
{"header", CO_HEADER },
{"other", CO_OTHER },
{"pagestyle", CO_PAGESTYLE }
};
@ -703,7 +702,7 @@ void TextClass::readClassOptions(Lexer & lexrc)
continue;
default: break;
}
switch (static_cast<ClassOptionsTags>(le)) {
switch (le) {
case CO_FONTSIZE:
lexrc.next();
opt_fontsize_ = rtrim(lexrc.getString());
@ -729,21 +728,20 @@ void TextClass::readClassOptions(Lexer & lexrc)
}
enum FloatTags {
FT_TYPE = 1,
FT_NAME,
FT_PLACEMENT,
FT_EXT,
FT_WITHIN,
FT_STYLE,
FT_LISTNAME,
FT_BUILTIN,
FT_END
};
void TextClass::readFloat(Lexer & lexrc)
{
enum {
FT_TYPE = 1,
FT_NAME,
FT_PLACEMENT,
FT_EXT,
FT_WITHIN,
FT_STYLE,
FT_LISTNAME,
FT_BUILTIN,
FT_END
};
LexerKeyword floatTags[] = {
{ "end", FT_END },
{ "extension", FT_EXT },
@ -776,7 +774,7 @@ void TextClass::readFloat(Lexer & lexrc)
continue;
default: break;
}
switch (static_cast<FloatTags>(le)) {
switch (le) {
case FT_TYPE:
lexrc.next();
type = lexrc.getString();
@ -845,17 +843,16 @@ void TextClass::readFloat(Lexer & lexrc)
}
enum CounterTags {
CT_NAME = 1,
CT_WITHIN,
CT_LABELSTRING,
CT_LABELSTRING_APPENDIX,
CT_END
};
void TextClass::readCounter(Lexer & lexrc)
{
enum {
CT_NAME = 1,
CT_WITHIN,
CT_LABELSTRING,
CT_LABELSTRING_APPENDIX,
CT_END
};
LexerKeyword counterTags[] = {
{ "end", CT_END },
{ "labelstring", CT_LABELSTRING },
@ -880,7 +877,7 @@ void TextClass::readCounter(Lexer & lexrc)
continue;
default: break;
}
switch (static_cast<CounterTags>(le)) {
switch (le) {
case CT_NAME:
lexrc.next();
name = lexrc.getDocString();

View File

@ -378,7 +378,7 @@ docstring const Trans::process(char_type c, TransManager & k)
int Trans::load(string const & language)
{
struct LexerKeyword kmapTags[] = {
LexerKeyword kmapTags[] = {
{"\\kcomb", KCOMB },
{ "\\kmap", KMAP },
{ "\\kmod", KMOD },

View File

@ -357,7 +357,7 @@ void MenuDefinition::addWithStatusCheck(MenuItem const & i)
void MenuDefinition::read(Lexer & lex)
{
enum Menutags {
enum {
md_item = 1,
md_branches,
md_documents,
@ -382,7 +382,7 @@ void MenuDefinition::read(Lexer & lex)
md_toolbars
};
struct LexerKeyword menutags[] = {
LexerKeyword menutags[] = {
{ "bookmarks", md_bookmarks },
{ "branches", md_branches },
{ "charstyles", md_charstyles },
@ -1404,13 +1404,13 @@ Menus::Menus() : d(new Impl) {}
void Menus::read(Lexer & lex)
{
enum Menutags {
enum {
md_menu,
md_menubar,
md_endmenuset,
};
struct LexerKeyword menutags[] = {
LexerKeyword menutags[] = {
{ "end", md_endmenuset },
{ "menu", md_menu },
{ "menubar", md_menubar }

View File

@ -73,16 +73,16 @@ class DumpPreambleDef {
public:
typedef TemplateManager::PreambleDefs::value_type value_type;
DumpPreambleDef(ostream & o) : ost(o) {}
DumpPreambleDef(ostream & os) : os_(os) {}
void operator()(value_type const & vt) {
ost << "PreambleDef " << vt.first << '\n'
os_ << "PreambleDef " << vt.first << '\n'
<< vt.second
<< "PreambleDefEnd" << endl;
}
private:
ostream & ost;
ostream & os_;
};
@ -90,12 +90,12 @@ class DumpTemplate {
public:
typedef TemplateManager::Templates::value_type value_type;
DumpTemplate(ostream & o) : ost(o) {}
DumpTemplate(ostream & os) : os_(os) {}
void operator()(value_type const & vt) {
Template const & et = vt.second;
ost << "Template " << et.lyxName << '\n'
os_ << "Template " << et.lyxName << '\n'
<< "\tGuiName " << et.guiName << '\n'
<< "\tHelpText\n"
<< et.helpText
@ -108,28 +108,28 @@ public:
IDs::const_iterator it = et.transformIds.begin();
IDs::const_iterator end = et.transformIds.end();
for (; it != end; ++it) {
ost << "\tTransform "
os_ << "\tTransform "
<< transformIDTranslator().find(*it) << '\n';
}
et.dumpFormats(ost);
ost << "TemplateEnd" << endl;
et.dumpFormats(os_);
os_ << "TemplateEnd" << endl;
}
private:
ostream & ost;
ostream & os_;
};
class DumpFormat {
public:
typedef Template::Formats::value_type value_type;
DumpFormat(ostream & o) : ost(o) {}
DumpFormat(ostream & o) : os_(o) {}
void operator()(value_type const & vt) const {
Template::Format const & ft = vt.second;
ost << "\tFormat " << vt.first << '\n'
os_ << "\tFormat " << vt.first << '\n'
<< "\t\tProduct " << ft.product << '\n'
<< "\t\tUpdateFormat " << ft.updateFormat << '\n'
<< "\t\tUpdateResult " << ft.updateResult << '\n';
@ -138,14 +138,14 @@ public:
vector<string>::const_iterator qend = ft.requirements.end();
for (; qit != qend; ++qit) {
lyxerr << "req:" << *qit << endl;
ost << "\t\tRequirement " << *qit << '\n';
os_ << "\t\tRequirement " << *qit << '\n';
}
typedef vector<Template::Option> Options;
Options::const_iterator oit = ft.options.begin();
Options::const_iterator oend = ft.options.end();
for (; oit != oend; ++oit) {
ost << "\t\tOption "
os_ << "\t\tOption "
<< oit->name
<< ": "
<< oit->option
@ -155,7 +155,7 @@ public:
vector<string>::const_iterator pit = ft.preambleNames.begin();
vector<string>::const_iterator pend = ft.preambleNames.end();
for (; pit != pend; ++pit) {
ost << "\t\tPreamble " << *pit << '\n';
os_ << "\t\tPreamble " << *pit << '\n';
}
typedef Template::Format::FileMap FileMap;
@ -165,15 +165,15 @@ public:
vector<string>::const_iterator fit = rit->second.begin();
vector<string>::const_iterator fend = rit->second.end();
for (; fit != fend; ++fit) {
ost << "\t\tReferencedFile " << rit->first
os_ << "\t\tReferencedFile " << rit->first
<< " \"" << *fit << "\"\n";
}
}
ost << "\tFormatEnd\n";
os_ << "\tFormatEnd\n";
}
private:
ostream & ost;
ostream & os_;
};
@ -333,7 +333,7 @@ void Template::readTemplate(Lexer & lex)
{ "transform", TO_TRANSFORM }
};
PushPopHelper pph(lex, templateoptiontags, TO_END);
PushPopHelper pph(lex, templateoptiontags);
while (lex.isOK()) {
switch (lex.lex()) {
@ -467,7 +467,7 @@ void setOptionFactory(Template::Format & format, string const & transform,
void Template::Format::readFormat(Lexer & lex)
{
enum FormatTags {
enum {
FO_PRODUCT = 1,
FO_UPDATEFORMAT,
FO_UPDATERESULT,
@ -493,7 +493,7 @@ void Template::Format::readFormat(Lexer & lex)
{ "updateresult", FO_UPDATERESULT }
};
PushPopHelper pph(lex, formattags, FO_END);
PushPopHelper pph(lex, formattags);
while (lex.isOK()) {
switch (lex.lex()) {
@ -564,6 +564,3 @@ void Template::Format::readFormat(Lexer & lex)
} // namespace external
} // namespace lyx

View File

@ -245,7 +245,7 @@ void InsetExternalParams::write(Buffer const & buf, ostream & os) const
bool InsetExternalParams::read(Buffer const & buffer, Lexer & lex)
{
enum ExternalTags {
enum {
EX_TEMPLATE = 1,
EX_FILENAME,
EX_EMBED,
@ -283,7 +283,7 @@ bool InsetExternalParams::read(Buffer const & buffer, Lexer & lex)
{ "width", EX_WIDTH }
};
PushPopHelper pph(lex, external_tags, EX_END);
PushPopHelper pph(lex, external_tags);
bool found_end = false;
bool read_error = false;

View File

@ -38,39 +38,19 @@ InsetLayout::InsetLayout() :
}
enum InsetLayoutTags {
IL_FONT,
IL_BGCOLOR,
IL_DECORATION,
IL_FREESPACING,
IL_FORCELTR,
IL_LABELFONT,
IL_LABELSTRING,
IL_LATEXNAME,
IL_LATEXPARAM,
IL_LATEXTYPE,
IL_LYXTYPE,
IL_KEEPEMPTY,
IL_MULTIPAR,
IL_NEEDPROTECT,
IL_PASSTHRU,
IL_PREAMBLE,
IL_REQUIRES,
IL_END
};
namespace {
InsetLayout::InsetDecoration translateDecoration(std::string const & str)
{
if (str == "classic")
return InsetLayout::Classic;
if (str == "minimalistic")
return InsetLayout::Minimalistic;
if (str == "conglomerate")
return InsetLayout::Conglomerate;
return InsetLayout::Default;
}
InsetLayout::InsetDecoration translateDecoration(std::string const & str)
{
if (str == "classic")
return InsetLayout::Classic;
if (str == "minimalistic")
return InsetLayout::Minimalistic;
if (str == "conglomerate")
return InsetLayout::Conglomerate;
return InsetLayout::Default;
}
}
@ -78,6 +58,28 @@ bool InsetLayout::read(Lexer & lexrc)
{
name_ = support::subst(lexrc.getDocString(), '_', ' ');
enum {
IL_FONT,
IL_BGCOLOR,
IL_DECORATION,
IL_FREESPACING,
IL_FORCELTR,
IL_LABELFONT,
IL_LABELSTRING,
IL_LATEXNAME,
IL_LATEXPARAM,
IL_LATEXTYPE,
IL_LYXTYPE,
IL_KEEPEMPTY,
IL_MULTIPAR,
IL_NEEDPROTECT,
IL_PASSTHRU,
IL_PREAMBLE,
IL_REQUIRES,
IL_END
};
LexerKeyword elementTags[] = {
{ "bgcolor", IL_BGCOLOR },
{ "decoration", IL_DECORATION },
@ -114,7 +116,7 @@ bool InsetLayout::read(Lexer & lexrc)
continue;
default: break;
}
switch (static_cast<InsetLayoutTags>(le)) {
switch (le) {
case IL_LYXTYPE:
lexrc.next();
lyxtype_ = lexrc.getString();