mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
reorganinze language reading a bit
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24125 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
d6cc538f51
commit
0e5945667a
@ -483,8 +483,8 @@ int Buffer::readHeader(Lexer & lex)
|
||||
ErrorList & errorList = d->errorLists["Parse"];
|
||||
|
||||
while (lex.isOK()) {
|
||||
lex.next();
|
||||
string const token = lex.getString();
|
||||
string token;
|
||||
lex >> token;
|
||||
|
||||
if (token.empty())
|
||||
continue;
|
||||
@ -539,9 +539,7 @@ bool Buffer::readDocument(Lexer & lex)
|
||||
ErrorList & errorList = d->errorLists["Parse"];
|
||||
errorList.clear();
|
||||
|
||||
lex.next();
|
||||
string const token = lex.getString();
|
||||
if (token != "\\begin_document") {
|
||||
if (!lex.checkFor("\\begin_document")) {
|
||||
docstring const s = _("\\begin_document is missing");
|
||||
errorList.push_back(ErrorItem(_("Document header error"),
|
||||
s, -1, 0, 0));
|
||||
@ -731,36 +729,19 @@ Buffer::ReadStatus Buffer::readFile(Lexer & lex, FileName const & filename,
|
||||
{
|
||||
BOOST_ASSERT(!filename.empty());
|
||||
|
||||
if (!lex.isOK()) {
|
||||
Alert::error(_("Document could not be read"),
|
||||
bformat(_("%1$s could not be read."), from_utf8(filename.absFilename())));
|
||||
return failure;
|
||||
}
|
||||
|
||||
lex.next();
|
||||
string const token = lex.getString();
|
||||
|
||||
if (!lex) {
|
||||
Alert::error(_("Document could not be read"),
|
||||
bformat(_("%1$s could not be read."), from_utf8(filename.absFilename())));
|
||||
return failure;
|
||||
}
|
||||
|
||||
// the first token _must_ be...
|
||||
if (token != "\\lyxformat") {
|
||||
lyxerr << "Token: " << token << endl;
|
||||
|
||||
// the first (non-comment) token _must_ be...
|
||||
if (!lex.checkFor("\\lyxformat")) {
|
||||
Alert::error(_("Document format failure"),
|
||||
bformat(_("%1$s is not a LyX document."),
|
||||
bformat(_("%1$s is not a readable LyX document."),
|
||||
from_utf8(filename.absFilename())));
|
||||
return failure;
|
||||
}
|
||||
|
||||
lex.next();
|
||||
string tmp_format = lex.getString();
|
||||
string tmp_format;
|
||||
lex >> tmp_format;
|
||||
//lyxerr << "LyX Format: `" << tmp_format << '\'' << endl;
|
||||
// if present remove ".," from string.
|
||||
string::size_type dot = tmp_format.find_first_of(".,");
|
||||
size_t dot = tmp_format.find_first_of(".,");
|
||||
//lyxerr << " dot found at " << dot << endl;
|
||||
if (dot != string::npos)
|
||||
tmp_format.erase(dot, 1);
|
||||
|
@ -26,74 +26,67 @@
|
||||
using namespace std;
|
||||
using namespace lyx::support;
|
||||
|
||||
|
||||
namespace lyx {
|
||||
|
||||
|
||||
Languages languages;
|
||||
Language ignore_lang;
|
||||
Language latex_lang;
|
||||
Language const * english_language;
|
||||
Language const * default_language;
|
||||
Language ignore_lang("ignore", "ignore", "Ignore", false, "", 0, "ignore", "");
|
||||
Language const * ignore_language = &ignore_lang;
|
||||
Language latex_lang("latex", "", "Latex", false, "", 0, "latex", "");
|
||||
Language const * latex_language = &latex_lang;
|
||||
|
||||
|
||||
bool Language::read(Lexer & lex)
|
||||
{
|
||||
encoding_ = 0;
|
||||
lex >> lang_;
|
||||
lex >> babel_;
|
||||
lex >> display_;
|
||||
lex >> rightToLeft_;
|
||||
lex >> encodingStr_;
|
||||
lex >> code_;
|
||||
lex >> latex_options_;
|
||||
if (!lex)
|
||||
return false;
|
||||
|
||||
encoding_ = encodings.fromLyXName(encodingStr_);
|
||||
if (!encoding_ && !encodingStr_.empty()) {
|
||||
encoding_ = encodings.fromLyXName("iso8859-1");
|
||||
LYXERR0("Unknown encoding " << encodingStr_);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void Languages::read(FileName const & filename)
|
||||
{
|
||||
// We need to set the encoding of latex_lang
|
||||
latex_lang = Language("latex", "", "Latex", false, "iso8859-1",
|
||||
encodings.fromLyXName("iso8859-1"),
|
||||
"latex", "");
|
||||
|
||||
Lexer lex;
|
||||
lex.setFile(filename);
|
||||
while (lex.isOK()) {
|
||||
string lang;
|
||||
string babel;
|
||||
string display;
|
||||
string encoding_str;
|
||||
string code;
|
||||
string latex_options;
|
||||
bool rtl = false;
|
||||
|
||||
if (lex.next())
|
||||
lang = lex.getString();
|
||||
else
|
||||
lex.setContext("Languages::read");
|
||||
while (1) {
|
||||
Language l;
|
||||
l.read(lex);
|
||||
if (!lex)
|
||||
break;
|
||||
LYXERR(Debug::INFO, "Reading language " << lang);
|
||||
|
||||
if (lex.next())
|
||||
babel = lex.getString();
|
||||
if (lex.next())
|
||||
display = lex.getString();
|
||||
if (lex.next())
|
||||
rtl = lex.getBool();
|
||||
if (lex.next())
|
||||
encoding_str = lex.getString();
|
||||
if (lex.next())
|
||||
code = lex.getString();
|
||||
if (lex.next())
|
||||
latex_options = lex.getString();
|
||||
|
||||
Encoding const * encoding = encodings.fromLyXName(encoding_str);
|
||||
if (!encoding) {
|
||||
encoding = encodings.fromLyXName("iso8859-1");
|
||||
lyxerr << "Unknown encoding " << encoding_str << endl;
|
||||
}
|
||||
|
||||
languagelist[lang] = Language(lang, babel, display, rtl,
|
||||
encoding_str, encoding, code, latex_options);
|
||||
LYXERR(Debug::INFO, "Reading language " << l.lang());
|
||||
if (l.lang() == "latex")
|
||||
latex_lang = l;
|
||||
else if (l.lang() == "ignore")
|
||||
ignore_lang = l;
|
||||
else
|
||||
languagelist[l.lang()] = l;
|
||||
}
|
||||
|
||||
default_language = getLanguage(lyxrc.default_language);
|
||||
if (!default_language) {
|
||||
lyxerr << "Default language \"" << lyxrc.default_language
|
||||
<< "\" not found!" << endl;
|
||||
LYXERR0("Default language \"" << lyxrc.default_language
|
||||
<< "\" not found!");
|
||||
default_language = getLanguage("english");
|
||||
if (!default_language)
|
||||
default_language = &(*languagelist.begin()).second;
|
||||
lyxerr << "Using \"" << default_language->lang()
|
||||
<< "\" instead!" << endl;
|
||||
LYXERR0("Using \"" << default_language->lang() << "\" instead!");
|
||||
}
|
||||
english_language = getLanguage("english");
|
||||
if (!english_language)
|
||||
|
@ -24,6 +24,7 @@ namespace lyx {
|
||||
namespace support { class FileName; }
|
||||
|
||||
class Encoding;
|
||||
class Lexer;
|
||||
|
||||
///
|
||||
class Language {
|
||||
@ -31,13 +32,6 @@ public:
|
||||
///
|
||||
Language() : rightToLeft_(false) {}
|
||||
///
|
||||
Language(std::string const & l, std::string const & b, std::string const & d,
|
||||
bool rtl, std::string const & es, Encoding const * e, std::string const & c,
|
||||
std::string const & o)
|
||||
: lang_(l), babel_(b), display_(d), rightToLeft_(rtl),
|
||||
encodingStr_(es), encoding_(e), code_(c), latex_options_(o)
|
||||
{}
|
||||
///
|
||||
std::string const & lang() const { return lang_; }
|
||||
///
|
||||
std::string const & babel() const { return babel_; }
|
||||
@ -53,6 +47,8 @@ public:
|
||||
std::string const & code() const { return code_; }
|
||||
///
|
||||
std::string const & latex_options() const { return latex_options_; }
|
||||
///
|
||||
bool read(Lexer & lex);
|
||||
private:
|
||||
///
|
||||
std::string lang_;
|
||||
|
Loading…
Reference in New Issue
Block a user