This requires quite a bit of trivial code shuffling.
#include "LaTeXFeatures.h"
#include "LaTeX.h"
#include "Layout.h"
-#include "Lexer.h"
#include "LyXAction.h"
#include "LyX.h"
#include "LyXRC.h"
#include "support/filetools.h"
#include "support/gettext.h"
#include "support/gzstream.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include "support/mutex.h"
#include "support/os.h"
class FuncStatus;
class Inset;
class InsetLabel;
-class Lexer;
class Text;
class LyXVC;
class LaTeXFeatures;
class DocFileName;
class FileName;
class FileNameList;
+class Lexer;
} // namespace support
namespace graphics {
//FIXME: The following function should be private
//private:
/// read the header, returns number of unknown tokens
- int readHeader(Lexer & lex);
+ int readHeader(support::Lexer & lex);
double fontScalingFactor() const;
/// check for active synctex support:
/// Reads a file without header.
/// \param par if != 0 insert the file.
/// \return \c true if file is not completely read.
- bool readDocument(Lexer &);
+ bool readDocument(support::Lexer &);
/// Try to extract the file from a version control container
/// before reading if the file cannot be found.
/// \sa LyXVC::file_not_found_hook
ReadStatus extractFromVC();
/// Reads the first tag of a LyX File and
/// returns the file format number.
- ReadStatus parseLyXFormat(Lexer & lex, support::FileName const & fn,
+ ReadStatus parseLyXFormat(support::Lexer & lex, support::FileName const & fn,
int & file_format) const;
/// Convert the LyX file to the LYX_FORMAT using
/// the lyx2lyx script and returns the filename
#include "LaTeXFeatures.h"
#include "LaTeXFonts.h"
#include "Font.h"
-#include "Lexer.h"
#include "LyXRC.h"
#include "OutputParams.h"
#include "Spacing.h"
#include "support/filetools.h"
#include "support/gettext.h"
#include "support/Length.h"
+#include "support/Lexer.h"
#include "support/Messages.h"
#include "support/mutex.h"
#include "support/Package.h"
namespace lyx {
-namespace support { class FileName; }
+namespace support {
+class FileName;
+class Lexer;
+}
class Author;
class AuthorList;
class LayoutFile;
class LayoutFileIndex;
class Length;
-class Lexer;
class OutputParams;
class otexstream;
class PDFOptions;
docstring B_(std::string const & l10n) const;
/// read a header token, if unrecognised, return it or an unknown class name
- std::string readToken(Lexer & lex,
+ std::string readToken(support::Lexer & lex,
std::string const & token, ///< token to read.
support::FileName const & filename);
private:
///
- void readPreamble(Lexer &);
+ void readPreamble(support::Lexer &);
///
- void readDocumentMetadata(Lexer &);
+ void readDocumentMetadata(support::Lexer &);
///
- void readLocalLayout(Lexer &, bool);
+ void readLocalLayout(support::Lexer &, bool);
///
- void readLanguage(Lexer &);
+ void readLanguage(support::Lexer &);
///
- void readGraphicsDriver(Lexer &);
+ void readGraphicsDriver(support::Lexer &);
///
- void readBullets(Lexer &);
+ void readBullets(support::Lexer &);
///
- void readBulletsLaTeX(Lexer &);
+ void readBulletsLaTeX(support::Lexer &);
///
- void readModules(Lexer &);
+ void readModules(support::Lexer &);
///
- void readRemovedModules(Lexer &);
+ void readRemovedModules(support::Lexer &);
///
- void readIncludeonly(Lexer &);
+ void readIncludeonly(support::Lexer &);
/// A cache for the default flavors
typedef std::map<std::string, Flavor> DefaultFlavorCache;
///
#include "Intl.h"
#include "Language.h"
#include "LayoutFile.h"
-#include "Lexer.h"
#include "LyX.h"
#include "LyXAction.h"
#include "lyxfind.h"
#include "support/gettext.h"
#include "support/lassert.h"
#include "support/Length.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include "support/lyxlib.h"
#include "support/types.h"
#include "CiteEnginesList.h"
#include "LaTeXFeatures.h"
-#include "Lexer.h"
#include "support/debug.h"
#include "support/FileName.h"
#include "support/gettext.h"
#include "support/filetools.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include "support/Translator.h"
#include "FuncRequest.h"
#include "LyXAction.h"
-#include "Lexer.h"
#include "support/debug.h"
#include "support/FileName.h"
#include "support/filetools.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include <string>
#include "ConverterCache.h"
#include "Format.h"
-#include "Lexer.h"
#include "LyXRC.h"
#include "Mover.h"
#include "support/convert.h"
#include "support/debug.h"
#include "support/filetools.h"
+#include "support/Lexer.h"
#include "support/lyxtime.h"
#include "support/Package.h"
#include "Counters.h"
#include "Layout.h"
-#include "Lexer.h"
#include "support/convert.h"
#include "support/counter_reps.h"
#include "support/docstring.h"
#include "support/gettext.h"
#include "support/lassert.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include <algorithm>
namespace lyx {
class Layout;
-class Lexer;
+
+namespace support { class Lexer; }
/// This represents a single counter.
class Counter {
docstring const & lsa, docstring const & prettyformat,
docstring const & guiname);
/// \return true on success
- bool read(Lexer & lex);
+ bool read(support::Lexer & lex);
///
void set(int v);
///
/// \param makeNew whether to make a new counter if one
/// doesn't already exist
/// \return true on success
- bool read(Lexer & lex, docstring const & name, bool makenew);
+ bool read(support::Lexer & lex, docstring const & name, bool makenew);
///
void set(docstring const & ctr, int val);
///
#include "Encoding.h"
-#include "Lexer.h"
-
#include "support/debug.h"
#include "support/docstring.h"
#include "support/gettext.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include "support/mutex.h"
#include "support/textutils.h"
#include "Encoding.h"
#include "Language.h"
#include "LaTeXFeatures.h"
-#include "Lexer.h"
#include "LyXRC.h"
#include "output_latex.h"
#include "OutputParams.h"
#include "support/convert.h"
#include "support/debug.h"
#include "support/gettext.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include <cstring>
#include "FontInfo.h"
#include "ColorSet.h"
-#include "Lexer.h"
#include "LyXRC.h"
#include "support/convert.h"
#include "support/debug.h"
#include "support/docstring.h"
#include "support/gettext.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include <algorithm>
namespace lyx {
-class Lexer;
+namespace support { class Lexer; }
///
class FontInfo
FontState setLyXMisc(std::string const &);
/// Read a font specification from Lexer. Used for layout files.
-FontInfo lyxRead(Lexer &, FontInfo const & fi = sane_font);
+FontInfo lyxRead(support::Lexer &, FontInfo const & fi = sane_font);
/// Write a font specification. Used for layout files.
void lyxWrite(std::ostream &, FontInfo const &, std::string const &, int);
#include "KeySequence.h"
#include "LyXAction.h"
-#include "Lexer.h"
#include "support/debug.h"
#include "support/docstream.h"
#include "support/FileName.h"
#include "support/filetools.h"
#include "support/gettext.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include "support/TempFile.h"
#include "LaTeXFonts.h"
#include "LaTeXFeatures.h"
-#include "Lexer.h"
#include "frontends/alert.h"
#include "support/FileName.h"
#include "support/filetools.h"
#include "support/gettext.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
namespace lyx {
-class Lexer;
+namespace support { class Lexer; }
/// LaTeX Font definition
class LaTeXFont {
/// Return the actually used package
docstring const getUsedPackage(bool ot1, bool complete, bool nomath) const;
///
- bool read(Lexer & lex);
+ bool read(support::Lexer & lex);
///
- bool readFont(Lexer & lex);
+ bool readFont(support::Lexer & lex);
private:
/// Return the preferred available package
std::string const getAvailablePackage(bool dryrun) const;
#include "LaTeXPackages.h"
-#include "Lexer.h"
-
#include "support/convert.h"
#include "support/debug.h"
#include "support/FileName.h"
#include "support/filetools.h"
#include "support/gettext.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include "support/Package.h"
#include "BufferParams.h"
#include "Encoding.h"
#include "LaTeXFonts.h"
-#include "Lexer.h"
#include "LyXRC.h"
#include "support/debug.h"
#include "support/FileName.h"
#include "support/filetools.h"
#include "support/lassert.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include "support/qstring_helpers.h"
#include "support/Messages.h"
namespace lyx {
-namespace support { class FileName; }
+namespace support {
+class FileName;
+class Lexer;
+}
class BufferParams;
class Encoding;
-class Lexer;
///
class Language {
/// This language corresponds to a translation of the GUI
bool hasGuiSupport() const { return has_gui_support_; }
///
- bool read(Lexer & lex);
+ bool read(support::Lexer & lex);
///
- bool readLanguage(Lexer & lex);
+ bool readLanguage(support::Lexer & lex);
///
typedef std::map<trivstring, trivdocstring> TranslationMap;
///
#include <config.h>
#include "Layout.h"
-#include "Lexer.h"
#include "output_xhtml.h"
#include "TextClass.h"
#include "support/debug.h"
#include "support/docstream.h"
#include "support/lassert.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include "support/textutils.h"
namespace lyx {
-class Lexer;
+namespace support { class Lexer; }
+
class TextClass;
/* Fixed labels are printed flushright, manual labels flushleft.
void setUnknown(bool unknown) { unknown_ = unknown; }
/// Reads a layout definition from file
/// \return true on success.
- bool read(Lexer &, TextClass const &, bool validating = false);
+ bool read(support::Lexer &, TextClass const &, bool validating = false);
///
- void readAlign(Lexer &);
+ void readAlign(support::Lexer &);
///
- void readAlignPossible(Lexer &);
+ void readAlignPossible(support::Lexer &);
///
- void readLabelType(Lexer &);
+ void readLabelType(support::Lexer &);
///
- void readEndLabelType(Lexer &);
+ void readEndLabelType(support::Lexer &);
///
- void readMargin(Lexer &);
+ void readMargin(support::Lexer &);
///
- void readLatexType(Lexer &);
+ void readLatexType(support::Lexer &);
///
- void readSpacing(Lexer &);
+ void readSpacing(support::Lexer &);
///
- void readArgument(Lexer &, bool);
+ void readArgument(support::Lexer &, bool);
/// Write a layout definition in utf8 encoding
void write(std::ostream &) const;
///
private:
/// Reads a layout definition from file
/// \return true on success.
- bool readIgnoreForcelocal(Lexer &, TextClass const &, bool validating);
+ bool readIgnoreForcelocal(support::Lexer &, TextClass const &, bool validating);
/// generates the default CSS for this layout
void makeDefaultCSS() const;
///
#include <config.h>
#include "LayoutFile.h"
-#include "Lexer.h"
#include "TextClass.h"
#include "support/debug.h"
#include "support/FileName.h"
#include "support/filetools.h"
#include "support/lassert.h"
+#include "support/Lexer.h"
#include "support/TempFile.h"
#include <fstream>
+++ /dev/null
-/**
- * \file Lexer.cpp
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Alejandro Aguilar Sierra
- * \author Lars Gullik Bjønnes
- * \author Jean-Marc Lasgouttes
- * \author John Levon
- *
- * Full author contact details are available in file CREDITS.
- */
-
-#include <config.h>
-
-#include "Lexer.h"
-
-#include "support/convert.h"
-#include "support/debug.h"
-#include "support/FileName.h"
-#include "support/filetools.h"
-#include "support/gzstream.h"
-#include "support/lassert.h"
-#include "support/lstrings.h"
-#include "support/lyxalgo.h"
-
-#include <algorithm> // sort, lower_bound
-#include <functional>
-#include <fstream>
-#include <istream>
-#include <stack>
-#include <vector>
-
-using namespace std;
-using namespace lyx::support;
-
-namespace lyx {
-
-//////////////////////////////////////////////////////////////////////
-//
-// Lexer::Pimpl
-//
-//////////////////////////////////////////////////////////////////////
-
-
-///
-class Lexer::Pimpl {
-public:
- ///
- Pimpl(LexerKeyword * tab, int num);
- ///
- string const getString() const;
- ///
- docstring const getDocString() const;
- ///
- void printError(string const & message) const;
- ///
- void printTable(ostream & os);
- ///
- void pushTable(LexerKeyword * tab, int num);
- ///
- void popTable();
- ///
- bool setFile(FileName const & filename);
- ///
- void setStream(istream & i);
- ///
- void setCommentChar(char c);
- ///
- bool next(bool esc = false);
- ///
- int searchKeyword(char const * const tag) const;
- ///
- int lex();
- ///
- bool eatLine();
- ///
- bool nextToken();
- /// test if there is a pushed token or the stream is ok
- bool inputAvailable();
- ///
- void pushToken(string const &);
- /// gz_ is only used to open files, the stream is accessed through is.
- gz::gzstreambuf gz_;
-
- /// the stream that we use.
- istream is;
- ///
- string name;
- ///
- LexerKeyword * table;
- ///
- int no_items;
- ///
- string buff;
- ///
- int status;
- ///
- int lineno;
- ///
- string pushTok;
- /// used for error messages
- string context;
- ///
- char commentChar;
-private:
- /// non-copyable
- Pimpl(Pimpl const &);
- void operator=(Pimpl const &);
-
- ///
- void verifyTable();
- ///
- class PushedTable {
- public:
- ///
- PushedTable()
- : table_elem(nullptr), table_siz(0) {}
- ///
- PushedTable(LexerKeyword * ki, int siz)
- : table_elem(ki), table_siz(siz) {}
- ///
- LexerKeyword * table_elem;
- ///
- int table_siz;
- };
- ///
- stack<PushedTable> pushed;
-};
-
-
-namespace {
-
-// used by lower_bound, sort and sorted
-bool compareTags(LexerKeyword const & a, LexerKeyword const & b)
-{
- // 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;
-}
-
-} // namespace
-
-
-
-Lexer::Pimpl::Pimpl(LexerKeyword * tab, int num)
- : is(&gz_), table(tab), no_items(num),
- status(0), lineno(0), commentChar('#')
-{
- verifyTable();
-}
-
-
-string const Lexer::Pimpl::getString() const
-{
- return buff;
-}
-
-
-docstring const Lexer::Pimpl::getDocString() const
-{
- return from_utf8(buff);
-}
-
-
-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))
- << " current token: '" << getString() << "'"
- << " context: '" << context << "']" << endl;
-}
-
-
-void Lexer::Pimpl::printTable(ostream & os)
-{
- os << "\nNumber of tags: " << no_items << endl;
- for (int i= 0; i < no_items; ++i)
- os << "table[" << i
- << "]: tag: `" << table[i].tag
- << "' code:" << table[i].code << '\n';
- os.flush();
-}
-
-
-void Lexer::Pimpl::verifyTable()
-{
- // Check if the table is sorted and if not, sort it.
- if (table
- && !lyx::sorted(table, table + no_items, &compareTags)) {
- lyxerr << "The table passed to Lexer is not sorted!\n"
- << "Tell the developers to fix it!" << endl;
- // We sort it anyway to avoid problems.
- lyxerr << "\nUnsorted:" << endl;
- printTable(lyxerr);
-
- sort(table, table + no_items, &compareTags);
- lyxerr << "\nSorted:" << endl;
- printTable(lyxerr);
- }
-}
-
-
-void Lexer::Pimpl::pushTable(LexerKeyword * tab, int num)
-{
- PushedTable tmppu(table, no_items);
- pushed.push(tmppu);
-
- table = tab;
- no_items = num;
-
- verifyTable();
-}
-
-
-void Lexer::Pimpl::popTable()
-{
- if (pushed.empty()) {
- lyxerr << "Lexer error: nothing to pop!" << endl;
- return;
- }
-
- PushedTable tmp = pushed.top();
- pushed.pop();
- table = tmp.table_elem;
- no_items = tmp.table_siz;
-}
-
-
-bool Lexer::Pimpl::setFile(FileName const & filename)
-{
- if (gz_.is_open() || istream::off_type(is.tellg()) > -1)
- LYXERR0("Error in LyXLex::setFile: file or stream already set.");
- gz_.open(filename.toSafeFilesystemEncoding().c_str(), ios::in);
- is.rdbuf(&gz_);
- name = filename.absFileName();
- lineno = 0;
- if (!gz_.is_open() || !is.good())
- return false;
-
- // Skip byte order mark.
- if (is.peek() == 0xef) {
- is.get();
- if (is.peek() == 0xbb) {
- is.get();
- LASSERT(is.get() == 0xbf, /**/);
- } else
- is.unget();
- }
-
- return true;
-}
-
-
-void Lexer::Pimpl::setStream(istream & i)
-{
- if (gz_.is_open() || istream::off_type(is.tellg()) > 0)
- LYXERR0("Error in Lexer::setStream: file or stream already set.");
- is.rdbuf(i.rdbuf());
- lineno = 0;
-}
-
-
-void Lexer::Pimpl::setCommentChar(char c)
-{
- commentChar = c;
-}
-
-
-bool Lexer::Pimpl::next(bool esc /* = false */)
-{
- if (!pushTok.empty()) {
- // There can have been a whole line pushed so
- // we extract the first word and leaves the rest
- // in pushTok. (Lgb)
- if (pushTok[0] == '\\' && pushTok.find(' ') != string::npos) {
- buff.clear();
- pushTok = split(pushTok, buff, ' ');
- } else {
- buff = pushTok;
- pushTok.clear();
- }
- status = LEX_TOKEN;
- return true;
- }
-
-
- char cc = 0;
- status = 0;
- while (is && !status) {
- is.get(cc);
- unsigned char c = cc;
-
- if (c == commentChar) {
- // Read rest of line (fast :-)
-#if 1
- // That is not fast... (Lgb)
- string dummy;
- getline(is, dummy);
-
- LYXERR(Debug::LYXLEX, "Comment read: `" << string(1, c) << dummy << '\'');
-#else
- // unfortunately ignore is buggy (Lgb)
- is.ignore(100, '\n');
-#endif
- ++lineno;
- continue;
- }
-
- if (c == '\"') {
- buff.clear();
-
- if (esc) {
-
- do {
- bool escaped = false;
- is.get(cc);
- c = cc;
- if (c == '\r') continue;
- if (c == '\\') {
- // escape the next char
- is.get(cc);
- c = cc;
- if (c == '\"' || c == '\\')
- escaped = true;
- else
- buff.push_back('\\');
- }
- buff.push_back(c);
-
- if (!escaped && c == '\"')
- break;
- } while (c != '\n' && is);
-
- } else {
-
- do {
- is.get(cc);
- c = cc;
- if (c != '\r')
- buff.push_back(c);
- } while (c != '\"' && c != '\n' && is);
-
- }
-
- if (c != '\"') {
- printError("Missing quote");
- if (c == '\n')
- ++lineno;
- }
-
- buff.resize(buff.size() - 1);
- status = LEX_DATA;
- break;
- }
-
- if (c == ',')
- continue; /* Skip ','s */
-
- // 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) {
- buff.clear();
-
- do {
- if (esc && c == '\\') {
- // escape the next char
- is.get(cc);
- c = cc;
- //escaped = true;
- }
- buff.push_back(c);
- is.get(cc);
- c = cc;
- } while (c > ' ' && c != ',' && is);
- status = LEX_TOKEN;
- }
-
- 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;
- }
-
- if (c == '\n')
- ++lineno;
-
- }
- if (status)
- return true;
-
- status = is.eof() ? LEX_FEOF: LEX_UNDEF;
- buff.clear();
- return false;
-}
-
-
-int Lexer::Pimpl::searchKeyword(char const * const tag) const
-{
- LexerKeyword search_tag = { tag, 0 };
- LexerKeyword * res =
- lower_bound(table, table + no_items,
- search_tag, &compareTags);
- // 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.
- if (res != table + no_items
- && !compare_ascii_no_case(res->tag, tag))
- return res->code;
- return LEX_UNDEF;
-}
-
-
-int Lexer::Pimpl::lex()
-{
- //NOTE: possible bug.
- if (next() && status == LEX_TOKEN)
- return searchKeyword(getString().c_str());
- return status;
-}
-
-
-bool Lexer::Pimpl::eatLine()
-{
- buff.clear();
-
- unsigned char c = '\0';
- char cc = 0;
- while (is && c != '\n') {
- is.get(cc);
- c = cc;
- //LYXERR(Debug::LYXLEX, "Lexer::EatLine read char: `" << c << '\'');
- if (c != '\r' && is)
- buff.push_back(c);
- }
-
- if (c == '\n') {
- ++lineno;
- buff.resize(buff.size() - 1);
- status = LEX_DATA;
- return true;
- } else if (buff.length() > 0) { // last line
- status = LEX_DATA;
- return true;
- } else {
- return false;
- }
-}
-
-
-bool Lexer::Pimpl::nextToken()
-{
- if (!pushTok.empty()) {
- // There can have been a whole line pushed so
- // we extract the first word and leaves the rest
- // in pushTok. (Lgb)
- if (pushTok[0] == '\\' && pushTok.find(' ') != string::npos) {
- buff.clear();
- pushTok = split(pushTok, buff, ' ');
- } else {
- buff = pushTok;
- pushTok.clear();
- }
- status = LEX_TOKEN;
- return true;
- }
-
- status = 0;
- while (is && !status) {
- unsigned char c = 0;
- char cc = 0;
- is.get(cc);
- c = cc;
- if ((c >= ' ' || c == '\t') && is) {
- buff.clear();
-
- if (c == '\\') { // first char == '\\'
- do {
- buff.push_back(c);
- is.get(cc);
- c = cc;
- } while (c > ' ' && c != '\\' && is);
- } else {
- do {
- buff.push_back(c);
- is.get(cc);
- c = cc;
- } while ((c >= ' ' || c == '\t') && c != '\\' && is);
- }
-
- if (c == '\\')
- is.putback(c); // put it back
- status = LEX_TOKEN;
- }
-
- if (c == '\n')
- ++lineno;
-
- }
- if (status)
- return true;
-
- status = is.eof() ? LEX_FEOF: LEX_UNDEF;
- buff.clear();
- return false;
-}
-
-
-bool Lexer::Pimpl::inputAvailable()
-{
- return is.good();
-}
-
-
-void Lexer::Pimpl::pushToken(string const & pt)
-{
- pushTok = pt;
-}
-
-
-
-
-//////////////////////////////////////////////////////////////////////
-//
-// Lexer
-//
-//////////////////////////////////////////////////////////////////////
-
-Lexer::Lexer()
- : pimpl_(new Pimpl(nullptr, 0)), lastReadOk_(false)
-{}
-
-
-void Lexer::init(LexerKeyword * tab, int num)
-{
- pimpl_ = new Pimpl(tab, num);
-}
-
-
-Lexer::~Lexer()
-{
- delete pimpl_;
-}
-
-
-bool Lexer::isOK() const
-{
- return pimpl_->inputAvailable();
-}
-
-
-void Lexer::setLineNumber(int l)
-{
- pimpl_->lineno = l;
-}
-
-
-int Lexer::lineNumber() const
-{
- return pimpl_->lineno;
-}
-
-
-istream & Lexer::getStream()
-{
- return pimpl_->is;
-}
-
-
-void Lexer::pushTable(LexerKeyword * tab, int num)
-{
- pimpl_->pushTable(tab, num);
-}
-
-
-void Lexer::popTable()
-{
- pimpl_->popTable();
-}
-
-
-void Lexer::printTable(ostream & os)
-{
- pimpl_->printTable(os);
-}
-
-
-void Lexer::printError(string const & message) const
-{
- pimpl_->printError(message);
-}
-
-
-bool Lexer::setFile(FileName const & filename)
-{
- return pimpl_->setFile(filename);
-}
-
-
-void Lexer::setStream(istream & i)
-{
- pimpl_->setStream(i);
-}
-
-
-void Lexer::setCommentChar(char c)
-{
- pimpl_->setCommentChar(c);
-}
-
-
-int Lexer::lex()
-{
- return pimpl_->lex();
-}
-
-
-int Lexer::getInteger() const
-{
- lastReadOk_ = pimpl_->status == LEX_DATA || pimpl_->status == LEX_TOKEN;
- if (!lastReadOk_) {
- pimpl_->printError("integer token missing");
- return -1;
- }
-
- if (isStrInt(pimpl_->getString()))
- return convert<int>(pimpl_->getString());
-
- lastReadOk_ = false;
- pimpl_->printError("Bad integer `$$Token'");
- return -1;
-}
-
-
-double Lexer::getFloat() const
-{
- // replace comma with dot in case the file was written with
- // the wrong locale (should be rare, but is easy enough to
- // avoid).
- lastReadOk_ = pimpl_->status == LEX_DATA || pimpl_->status == LEX_TOKEN;
- if (!lastReadOk_) {
- pimpl_->printError("float token missing");
- return -1;
- }
-
- string const str = subst(pimpl_->getString(), ",", ".");
- if (isStrDbl(str))
- return convert<double>(str);
-
- lastReadOk_ = false;
- pimpl_->printError("Bad float `$$Token'");
- return -1;
-}
-
-
-string const Lexer::getString(bool trim) const
-{
- lastReadOk_ = pimpl_->status == LEX_DATA || pimpl_->status == LEX_TOKEN;
-
- if (lastReadOk_)
- return trim ? support::trim(pimpl_->getString(), "\t ") : pimpl_->getString();
-
- return string();
-}
-
-
-docstring const Lexer::getDocString(bool trim) const
-{
- lastReadOk_ = pimpl_->status == LEX_DATA || pimpl_->status == LEX_TOKEN;
-
- if (lastReadOk_)
- return trim ? support::trim(pimpl_->getDocString(), "\t ") : pimpl_->getDocString();
-
- return docstring();
-}
-
-
-// I would prefer to give a tag number instead of an explicit token
-// here, but it is not possible because Buffer::readDocument uses
-// explicit tokens (JMarc)
-docstring Lexer::getLongString(docstring const & endtoken)
-{
- docstring str;
- docstring prefix;
- bool firstline = true;
- bool foundend = false;
-
- while (pimpl_->is) { //< eatLine only reads from is, not from pushTok
- if (!eatLine())
- // blank line in the file being read
- continue;
- docstring tmpstr = getDocString();
- docstring const token = trim(tmpstr, " \t");
-
- LYXERR(Debug::PARSER, "LongString: `" << tmpstr << '\'');
-
- // We do a case independent comparison, like searchKeyword does.
- if (compare_no_case(token, endtoken) == 0) {
- foundend = true;
- break;
- }
-
- if (firstline) {
- size_t i = tmpstr.find_first_not_of(from_ascii(" \t"));
- if (i != string::npos)
- prefix = tmpstr.substr(0, i);
- firstline = false;
- LYXERR(Debug::PARSER, "Prefix = `" << prefix << "\'");
- }
-
- // further lines in long strings may have the same
- // whitespace prefix as the first line. Remove it.
- if (!prefix.empty() && prefixIs(tmpstr, prefix))
- tmpstr.erase(0, prefix.length());
-
- str += tmpstr + '\n';
- }
-
- if (!foundend)
- printError("Long string not ended by `" + to_utf8(endtoken) + '\'');
-
- return str;
-}
-
-
-bool Lexer::getBool() const
-{
- string const s = pimpl_->getString();
- if (s == "false" || s == "0") {
- lastReadOk_ = true;
- return false;
- }
- if (s == "true" || s == "1") {
- lastReadOk_ = true;
- return true;
- }
- pimpl_->printError("Bad boolean `$$Token'. "
- "Use \"false\" or \"true\"");
- lastReadOk_ = false;
- return false;
-}
-
-
-bool Lexer::eatLine()
-{
- return pimpl_->eatLine();
-}
-
-
-bool Lexer::next(bool esc)
-{
- return pimpl_->next(esc);
-}
-
-
-bool Lexer::nextToken()
-{
- return pimpl_->nextToken();
-}
-
-
-void Lexer::pushToken(string const & pt)
-{
- pimpl_->pushToken(pt);
-}
-
-
-Lexer::operator void const *() const
-{
- // This behaviour is NOT the same as the streams which would
- // use fail() here. However, our implementation of getString() et al.
- // can cause the eof() and fail() bits to be set, even though we
- // haven't tried to read 'em.
- return lastReadOk_? this : nullptr;
-}
-
-
-bool Lexer::operator!() const
-{
- return !lastReadOk_;
-}
-
-
-Lexer & Lexer::operator>>(string & s)
-{
- if (isOK()) {
- next();
- s = getString();
- } else {
- lastReadOk_ = false;
- }
- return *this;
-}
-
-
-Lexer & Lexer::operator>>(docstring & s)
-{
- if (isOK()) {
- next();
- s = getDocString();
- } else {
- lastReadOk_ = false;
- }
- return *this;
-}
-
-
-Lexer & Lexer::operator>>(double & s)
-{
- if (isOK()) {
- next();
- s = getFloat();
- } else {
- lastReadOk_ = false;
- }
- return *this;
-}
-
-
-Lexer & Lexer::operator>>(int & s)
-{
- if (isOK()) {
- next();
- s = getInteger();
- } else {
- lastReadOk_ = false;
- }
- return *this;
-}
-
-
-Lexer & Lexer::operator>>(unsigned int & s)
-{
- if (isOK()) {
- next();
- s = getInteger();
- } else {
- lastReadOk_ = false;
- }
- return *this;
-}
-
-
-Lexer & Lexer::operator>>(bool & s)
-{
- if (isOK()) {
- next();
- s = getBool();
- } else {
- lastReadOk_ = false;
- }
- return *this;
-}
-
-
-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)
-{
- string res;
- res += '"';
- res += subst(subst(arg, "\\", "\\\\"), "\"", "\\\"");
- res += '"';
- return res;
-}
-
-
-// same for docstring
-docstring Lexer::quoteString(docstring const & arg)
-{
- docstring res;
- res += '"';
- res += subst(subst(arg, from_ascii("\\"), from_ascii("\\\\")),
- from_ascii("\""), from_ascii("\\\""));
- res += '"';
- return res;
-}
-
-
-Lexer & Lexer::operator>>(char const * required)
-{
- string token;
- *this >> token;
- if (token != required) {
- 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 & functionName)
-{
- pimpl_->context = functionName;
-}
-
-
-} // namespace lyx
+++ /dev/null
-// -*- C++ -*-
-/**
- * \file Lexer.h
- * This file is part of LyX, the document processor.
- * Licence details can be found in the file COPYING.
- *
- * \author Alejandro Aguilar Sierra
- * \author Lars Gullik Bjønnes
- *
- * Full author contact details are available in file CREDITS.
- */
-
-// Generalized simple lexical analizer.
-// It can be used for simple syntax parsers, like lyxrc,
-// texclass and others to come.
-
-#ifndef LEXER_H
-#define LEXER_H
-
-#include "support/strfwd.h"
-#include <string>
-
-namespace lyx {
-
-namespace support { class FileName; }
-
-/** A helper structure to describe a keyword for the Lexer.
- Usually used bundled in C style arrays and passed to the
- Lexer using a LexerKeywordTable object.
-*/
-struct LexerKeyword
-{
- /// the string to be recognized
- char const * tag;
- /// a corresponding numerical id
- int code;
-};
-
-
-/** Generalized simple lexical analizer.
- Use the method isOK() to check if there is still data available
- for lexing. Use one of the the operators void* or ! to test if
- the last reading operation was successful.
-
- Example:
-
- int readParam(LyxLex & lex)
- {
- int param = 1; // default value
- if (lex.isOK()) { // the lexer has data to read
- int p; // temporary variable
- lex >> p;
- if (lex)
- param = p; // only use the input if reading was successful
- }
- return param;
- }
-
- @see LyXRC.cpp for an example of usage.
- */
-class Lexer
-{
-public:
- /// initialize Lexer with no special keywords.
- Lexer();
- /// initialize Lexer with a bunch of keywords
- template<int N> Lexer(LexerKeyword (&table)[N])
- : pimpl_(0), lastReadOk_(false) { init(table, N); }
-
- ///
- ~Lexer();
-
- /// Lex basic codes
- enum {
- ///
- LEX_UNDEF = -1,
- ///
- LEX_FEOF = -2,
- ///
- LEX_DATA = -3,
- ///
- LEX_TOKEN = -4
- };
-
- /// stream is open and end of stream is not reached
- /// FIXME: test also if pushToken is not empty
- /// FIXME: the method should be renamed to something like
- /// dataAvailable(), in order to reflect the real behavior
- bool isOK() const;
- /// FIXME: The next two operators should be replaced by one method
- /// called e.g. lastReadOk(), in order to reflect the real
- /// behavior
- /// last read operation was successful.
- operator void const *() const;
- /// last read operation was not successful
- bool operator!() const;
- /// return true if able to open file, else false
- bool setFile(support::FileName const & filename);
- ///
- void setStream(std::istream & is);
- ///
- std::istream & getStream();
- /// Danger! Don't use it unless you know what you are doing.
- void setLineNumber(int l);
- /// Change the character that begins a comment. Default is '#'
- void setCommentChar(char c);
-
- /// returns a lex code
- int lex();
-
- /// Read the next string, as delimited by double quotes or
- /// whitespace. If esc is true, then we remember that some chars
- /// might be escaped: \" at least.
- bool next(bool esc = false);
-
- /// Read next token. This one is almost the same as next(),
- /// but it will consider " as a regular character and always
- /// split a word if it contains a backslash.
- bool nextToken();
-
- /// Puts the rest of the line in the buffer, where it will
- /// be available via getString() or getDocString().
- bool eatLine();
-
- /// Push a token, that next token got from lyxlex.
- void pushToken(std::string const &);
-
- /// return the current line number
- int lineNumber() const;
-
- ///
- int getInteger() const;
- ///
- bool getBool() const;
- ///
- double getFloat() const;
- ///
- std::string const getString(bool trim = false) const;
- ///
- docstring const getDocString(bool trim = false) const;
- /** Get a long string, ended by the tag `endtoken'. This string
- can span several lines. The first line serves as a template
- for what sequence of tabs and spaces make up the indentation.
- This prefix is skipped from each following line.
- */
- docstring getLongString(docstring const & endtoken);
-
- /// Pushes a token list on a stack and replaces it with a new one.
- template<int N> void pushTable(LexerKeyword (&table)[N])
- { pushTable(table, N); }
-
- /** Pops a token list into void and replaces it with the one now
- on top of the stack.
- */
- void popTable();
-
- /** Prints an error message with the corresponding line number
- and file name. If message contains the substring `$$Token',
- it is replaced with the value of GetString()
- */
- void printError(std::string const & message) const;
-
- /// Prints the current token table on the supplied ostream.
- void printTable(std::ostream &);
- /// Used to dispaly context information in case of errors.
- void setContext(std::string const & functionName);
-
- /// extract string
- Lexer & operator>>(std::string &);
- /// extract docstring
- Lexer & operator>>(docstring &);
- /// extract double
- Lexer & operator>>(double &);
- /// extract integer
- Lexer & operator>>(int &);
- /// extract unsigned integer
- 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
- static std::string quoteString(std::string const &);
- /// Quotes a docstring so that reading it again with Lexer::next(true)
- /// gets the original string
- static docstring quoteString(docstring const &);
-
-private:
- /// noncopyable
- Lexer(Lexer const &);
- void operator=(Lexer const &);
-
- ///
- friend class PushPopHelper;
-
- ///
- void init(LexerKeyword *, int);
- void pushTable(LexerKeyword *, int);
-
- ///
- class Pimpl;
- ///
- Pimpl * pimpl_;
- ///
- mutable bool lastReadOk_;
-};
-
-
-/// extract something constructable from a string, i.e. a LaTeX length
-template <class T>
-Lexer & operator>>(Lexer & lex, T & t)
-{
- if (lex.next())
- t = T(lex.getString());
- return lex;
-}
-
-
-/** Use to enable multiple exit points.
- This is needed to ensure that the pop is done upon exit from methods
- with more than one exit point or that can return as a response to
- exceptions.
- @author Lgb
-*/
-class PushPopHelper
-{
-public:
- ///
- template<int N>
- PushPopHelper(Lexer & l, LexerKeyword (&table)[N])
- : lex(l)
- {
- lex.pushTable(table, N);
- }
- ///
- ~PushPopHelper()
- {
- lex.popTable();
- }
- ///
- Lexer & lex;
-};
-/** Avoid wrong usage of PushPopHelper.
- To avoid wrong usage:
- PushPopHelper(...); // wrong
- PushPopHelper pph(...); // right
-*/
-#define PushPopHelper(x, y, z) unnamed_PushPopHelper;
-// Tip gotten from Bobby Schmidt's column in C/C++ Users Journal
-
-
-} // namespace lyx
-
-#endif
#include "Format.h"
#include "FuncCode.h"
#include "FuncRequest.h"
-#include "Lexer.h"
#include "LyX.h"
#include "Mover.h"
#include "SpellChecker.h"
#include "support/environment.h"
#include "support/FileName.h"
#include "support/filetools.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include "support/os.h"
#include "support/Package.h"
namespace lyx {
-namespace support { class FileName; }
-
+namespace support {
+class FileName;
class Lexer;
+}
/// This contains the runtime configuration of LyX
class LyXRC
FormatMismatch
};
///
- ReturnValues read(Lexer &, bool check_format);
+ ReturnValues read(support::Lexer &, bool check_format);
public:
///
typedef std::set<std::string> CommandSet;
LaTeXPackages.cpp \
LayoutFile.cpp \
LayoutModuleList.cpp \
- Lexer.cpp \
LyX.cpp \
LyXAction.cpp \
lyxfind.cpp \
LayoutEnums.h \
LayoutFile.h \
LayoutModuleList.h \
- Lexer.h \
LyXAction.h \
lyxfind.h \
LyX.h \
#include "ModuleList.h"
#include "LaTeXFeatures.h"
-#include "Lexer.h"
#include "support/debug.h"
#include "support/FileName.h"
#include "support/gettext.h"
#include "support/filetools.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include <algorithm>
#include "Encoding.h"
#include "LaTeXFeatures.h"
-#include "Lexer.h"
#include "OutputParams.h"
#include "texstream.h"
#include "support/debug.h"
#include "support/docstream.h"
#include "support/docstring.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include <sstream>
namespace lyx {
-class Lexer;
class OutputParams;
class otexstream;
+namespace support { class Lexer; }
+
// FIXME UNICODE
// Write functions need to use odostream instead of ostream before
// we can use docstring instead of string.
void writeLaTeX(OutputParams &, otexstream &,
bool hyperref_already_provided) const;
/// read tokens from lyx header
- std::string readToken(Lexer &lex, std::string const & token);
+ std::string readToken(support::Lexer &lex, std::string const & token);
/// set implicit settings for hyperref
void clear();
#include "ParagraphParameters.h"
#include "Layout.h"
-#include "Lexer.h"
#include "Paragraph.h"
#include "support/debug.h"
#include "support/docstring.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include <sstream>
namespace lyx {
class Layout;
-class Lexer;
class Paragraph;
+namespace support { class Lexer; }
+
///
class ParagraphParameters {
void read (std::string const & str, bool merge = true);
/// read the parameters from a lex
- void read(Lexer & lex, bool merge = true);
+ void read(support::Lexer & lex, bool merge = true);
///
void apply(ParagraphParameters const & params, Layout const & layout);
#include "Intl.h"
#include "Language.h"
#include "Layout.h"
-#include "Lexer.h"
#include "LyX.h"
#include "LyXAction.h"
#include "lyxfind.h"
#include "support/filetools.h"
#include "support/gettext.h"
#include "support/lassert.h"
+#include "support/Lexer.h"
#include "support/limited_stack.h"
#include "support/lstrings.h"
#include "support/lyxtime.h"
class FuncStatus;
class Inset;
class InsetText;
-class Lexer;
class Paragraph;
class ParagraphParameters;
+namespace support { class Lexer; }
+
/// This class encapsulates the main text data and operations in LyX.
/// This is more or less the private implementation of InsetText.
class Text {
void write(std::ostream & os) const;
/// returns true if \end_document has not been read
/// insetPtr is the containing Inset
- bool read(Lexer & lex, ErrorList & errorList,
+ bool read(support::Lexer & lex, ErrorList & errorList,
InsetText * insetPtr);
/// delete double spaces, leading spaces, and empty paragraphs around old cursor.
void pasteString(Cursor & cur, docstring const & str,
bool asParagraphs);
///
- void readParToken(Paragraph & par, Lexer & lex, std::string const & token,
+ void readParToken(Paragraph & par, support::Lexer & lex, std::string const & token,
Font & font, Change & change, ErrorList & errorList);
///
- void readParagraph(Paragraph & par, Lexer & lex, ErrorList & errorList);
+ void readParagraph(Paragraph & par, support::Lexer & lex, ErrorList & errorList);
/// Set Label Width string to all paragraphs of the same layout
/// and depth in a sequence.
void setLabelWidthStringToSequence(Cursor const & cur, docstring const & s);
#include "FloatList.h"
#include "Layout.h"
#include "LayoutFile.h"
-#include "Lexer.h"
#include "ModuleList.h"
#include "frontends/alert.h"
#include "support/FileName.h"
#include "support/filetools.h"
#include "support/gettext.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include "support/os.h"
#include "support/TempFile.h"
namespace lyx {
-namespace support { class FileName; }
+namespace support {
+class FileName;
+class Lexer;
+}
class FloatList;
class Layout;
class LayoutFile;
-class Lexer;
/// Based upon ideas in boost::noncopyable, inheriting from this
/// class effectively makes the copy constructor protected but the
///
ReturnValues read(std::string const & str, ReadType rt = MODULE);
///
- ReturnValues read(Lexer & lex, ReadType rt = BASECLASS);
+ ReturnValues read(support::Lexer & lex, ReadType rt = BASECLASS);
/// validates the layout information passed in str
static ReturnValues validate(std::string const & str);
/// \return the conversion of \param str to the latest layout format
/// Reads the layout file without running layout2layout.
ReturnValues readWithoutConv(support::FileName const & filename, ReadType rt);
/// \return true for success.
- bool readStyle(Lexer &, Layout &, ReadType) const;
+ bool readStyle(support::Lexer &, Layout &, ReadType) const;
///
- void readOutputType(Lexer &);
+ void readOutputType(support::Lexer &);
///
- void readTitleType(Lexer &);
+ void readTitleType(support::Lexer &);
///
- void readMaxCounter(Lexer &);
+ void readMaxCounter(support::Lexer &);
///
- void readClassOptions(Lexer &);
+ void readClassOptions(support::Lexer &);
///
- void readCharStyle(Lexer &, std::string const &);
+ void readCharStyle(support::Lexer &, std::string const &);
///
- bool readFloat(Lexer &);
+ bool readFloat(support::Lexer &);
///
std::vector<CitationStyle> const & getCiteStyles(CiteEngineType const &) const;
///
- bool readCiteEngine(Lexer &, ReadType, bool const add = false);
+ bool readCiteEngine(support::Lexer &, ReadType, bool const add = false);
///
- int readCiteEngineType(Lexer &) const;
+ int readCiteEngineType(support::Lexer &) const;
///
- bool readCiteFormat(Lexer &, ReadType);
+ bool readCiteFormat(support::Lexer &, ReadType);
///
- bool readOutlinerName(Lexer &);
+ bool readOutlinerName(support::Lexer &);
};
#include "Trans.h"
-#include "Lexer.h"
#include "Text.h"
#include "support/debug.h"
#include "support/docstream.h"
#include "support/FileName.h"
#include "support/filetools.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
using namespace std;
class Cursor;
class Text;
-class Lexer;
class TransManager;
+namespace support { class Lexer; }
+
///
enum tex_accent {
///
///
void freeKeymap();
///
- int load(Lexer &);
+ int load(support::Lexer &);
///
docstring const & match(char_type c);
///
#include "factory.h"
#include "FuncRequest.h"
-#include "Lexer.h"
#include "LyX.h"
#include "insets/InsetBibitem.h"
#include "support/debug.h"
#include "support/ExceptionMessage.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include "support/unique_ptr.h"
class Buffer;
class FuncRequest;
class Inset;
-class Lexer;
+namespace support { class Lexer; }
/// creates inset according to 'cmd'
Inset * createInset(Buffer * buf, FuncRequest const & cmd);
/// read inset from a file
-Inset * readInset(Lexer & lex, Buffer * buf);
+Inset * readInset(support::Lexer & lex, Buffer * buf);
} // namespace lyx
#include "KeyMap.h"
#include "Language.h"
#include "LaTeXPackages.h"
-#include "Lexer.h"
#include "LyX.h"
#include "LyXAction.h"
#include "LyXRC.h"
#include "support/ForkedCalls.h"
#include "support/gettext.h"
#include "support/lassert.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include "support/lyxalgo.h" // sorted
#include "support/mute_warning.h"
#include "GuiApplication.h"
#include "qt_helpers.h"
-#include "Lexer.h"
#include "frontends/Clipboard.h"
#include "support/docstring.h"
#include "support/gettext.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include <QTextBrowser>
#include "FuncRequest.h"
#include "GuiView.h"
#include "Layout.h"
-#include "Lexer.h"
#include "Paragraph.h"
#include "ParagraphParameters.h"
#include "Spacing.h"
#include "support/debug.h"
-#include "support/gettext.h"
+#include "support/Lexer.h"
#include <QCheckBox>
#include <QDialogButtonBox>
#include "TocModel.h"
#include "qt_helpers.h"
-#include "support/filetools.h"
#include "frontends/alert.h"
#include "frontends/KeySymbol.h"
#include "KeySymbol.h"
#include "Language.h"
#include "LayoutFile.h"
-#include "Lexer.h"
#include "LyXAction.h"
#include "LyX.h"
#include "LyXRC.h"
#include "support/debug.h"
#include "support/ExceptionMessage.h"
#include "support/FileName.h"
-#include "support/gettext.h"
+#include "support/filetools.h"
#include "support/ForkedCalls.h"
+#include "support/gettext.h"
#include "support/lassert.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include "support/os.h"
#include "support/Package.h"
#include "KeyMap.h"
#include "Language.h"
#include "Layout.h"
-#include "Lexer.h"
#include "LyXAction.h"
#include "LyX.h"
#include "LyXRC.h"
#include "insets/InsetInfo.h"
#include "insets/InsetQuotes.h"
-#include "support/lassert.h"
#include "support/convert.h"
#include "support/debug.h"
#include "support/docstring_list.h"
#include "support/filetools.h"
#include "support/gettext.h"
+#include "support/lassert.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include <QCursor>
class BufferView;
class docstring_list;
-class Lexer;
class FuncRequest;
+namespace support { class Lexer; }
+
namespace frontend {
class GuiView;
Menu * menu(QString const & name, GuiView & view, bool keyboard = false);
///
- void read(Lexer &);
+ void read(support::Lexer &);
///
void updateMenu(Menu * qmenu);
#include "Converter.h"
#include "Format.h"
#include "FuncRequest.h"
-#include "Lexer.h"
#include "LyXAction.h"
#include "qt_helpers.h"
#include "support/debug.h"
#include "support/gettext.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include <algorithm>
namespace lyx {
class FuncRequest;
-class Lexer;
+
+namespace support { class Lexer; }
namespace frontend {
Items items;
/// read a toolbar from the file
- ToolbarInfo & read(Lexer &);
+ ToolbarInfo & read(support::Lexer &);
private:
/// add toolbar item
Infos::iterator end() { return toolbar_info_.end(); }
/// read toolbars from the file
- void readToolbars(Lexer &);
+ void readToolbars(support::Lexer &);
/// read ui toolbar settings
- void readToolbarSettings(Lexer &);
+ void readToolbarSettings(support::Lexer &);
///
ToolbarInfo const * info(std::string const & name) const;
#include "ExternalTemplate.h"
-#include "Lexer.h"
#include "support/debug.h"
#include "support/filetools.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include "support/Package.h"
#include "support/PathChanger.h"
namespace lyx {
-namespace support { class FileName; }
-
+namespace support {
+class FileName;
class Lexer;
+}
enum PreviewMode {
PREVIEW_OFF = 0,
/// We have to have default commands for safety reasons!
Template();
///
- void readTemplate(Lexer &);
+ void readTemplate(support::Lexer &);
///
void dumpFormats(std::ostream &) const;
public:
Format();
///
- void readFormat(Lexer &);
+ void readFormat(support::Lexer &);
/// The text that should be inserted into the exported file
std::string product;
class InsetText;
class Language;
class LaTeXFeatures;
-class Lexer;
class MathAtom;
class MetricsInfo;
class PainterInfo;
namespace graphics { class PreviewLoader; }
-namespace support {class FileNameList; }
+namespace support {
+class FileNameList;
+class Lexer;
+}
/// returns the InsetCode corresponding to the \c name.
/// Eg, insetCode("branch") == BRANCH_CODE
/// write inset in .lyx format
virtual void write(std::ostream &) const {}
/// read inset in .lyx format
- virtual void read(Lexer &) {}
+ virtual void read(support::Lexer &) {}
/** Export the inset to LaTeX.
* Don't use a temporary stringstream if the final output is
* supposed to go to a file.
#include "InsetList.h"
#include "Language.h"
#include "Layout.h"
-#include "Lexer.h"
#include "ParIterator.h"
#include "TexRow.h"
#include "texstream.h"
#include "support/debug.h"
#include "support/docstream.h"
#include "support/gettext.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
using namespace std;
namespace lyx {
+using support::Lexer;
InsetArgument::InsetArgument(Buffer * buf, string const & name)
: InsetCollapsible(buf), name_(name), labelstring_(docstring()),
///
void write(std::ostream & os) const override;
///
- void read(Lexer & lex) override;
+ void read(support::Lexer & lex) override;
///
bool neverIndent() const override { return true; }
///
#include "InsetIterator.h"
#include "InsetList.h"
#include "Language.h"
-#include "Lexer.h"
#include "output_xhtml.h"
#include "Paragraph.h"
#include "ParagraphList.h"
#include "support/debug.h"
#include "support/docstream.h"
#include "support/gettext.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include "support/mutex.h"
///
bool isLabeled() const override { return true; }
///
- void read(Lexer & lex) override;
+ void read(support::Lexer & lex) override;
///
int plaintext(odocstringstream &, OutputParams const &,
size_t max_length = INT_MAX) const override;
#include "FuncStatus.h"
#include "FuncRequest.h"
#include "LaTeXFeatures.h"
-#include "Lexer.h"
#include "MetricsInfo.h"
#include "output_docbook.h"
#include "output_xhtml.h"
#include "support/docstream.h"
#include "support/FileName.h"
#include "support/gettext.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include "support/Translator.h"
///
void write(std::ostream & os) const;
///
- void read(Lexer & lex);
+ void read(support::Lexer & lex);
///
std::string type;
///
void write(std::ostream &) const override;
///
- void read(Lexer & lex) override;
+ void read(support::Lexer & lex) override;
///
void metrics(MetricsInfo &, Dimension &) const override;
///
#include "FuncStatus.h"
#include "Inset.h"
#include "LaTeXFeatures.h"
-#include "Lexer.h"
#include "LyX.h"
#include "output_docbook.h"
#include "output_xhtml.h"
#include "support/convert.h"
#include "support/debug.h"
#include "support/gettext.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include "frontends/alert.h"
namespace lyx {
+using support::Lexer;
+
InsetBranch::InsetBranch(Buffer * buf, InsetBranchParams const & params)
: InsetCollapsible(buf, InsetText::DefaultLayout), params_(params)
{}
///
void write(std::ostream & os) const;
///
- void read(Lexer & lex);
+ void read(support::Lexer & lex);
///
docstring branch;
///
///
void write(std::ostream &) const override;
///
- void read(Lexer & lex) override;
+ void read(support::Lexer & lex) override;
///
docstring const buttonLabel(BufferView const &) const override;
///
#include "FuncRequest.h"
#include "FuncStatus.h"
#include "InsetLayout.h"
-#include "Lexer.h"
#include "MetricsInfo.h"
#include "TextClass.h"
#include "TocBackend.h"
#include "support/FileName.h"
#include "support/gettext.h"
#include "support/lassert.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include "support/Changer.h"
#include "support/TempFile.h"
namespace lyx {
+using support::Lexer;
+
InsetCollapsible::InsetCollapsible(Buffer * buf, InsetText::UsePlain ltype)
: InsetText(buf, ltype), status_(Open)
{
///
docstring layoutName() const override { return from_ascii("Collapsible"); }
///
- void read(Lexer &) override;
+ void read(support::Lexer &) override;
///
void write(std::ostream &) const override;
#include "FuncRequest.h"
#include "FuncStatus.h"
#include "InsetIterator.h"
-#include "Lexer.h"
#include "LyX.h"
#include "MetricsInfo.h"
#include "texstream.h"
#include "insets/InsetWrap.h"
#include "support/debug.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include "frontends/Application.h"
///
void write(std::ostream & os) const override { p_.write(os); }
///
- void read(Lexer & lex) override { p_.Read(lex, &buffer()); }
+ void read(support::Lexer & lex) override { p_.Read(lex, &buffer()); }
///
void doDispatch(Cursor & cur, FuncRequest & cmd) override;
///
#include "Buffer.h"
#include "Encoding.h"
-#include "Lexer.h"
#include "frontends/alert.h"
#include "support/docstream.h"
#include "support/ExceptionMessage.h"
#include "support/gettext.h"
-#include "support/lstrings.h"
-
#include "support/lassert.h"
+#include "support/Lexer.h"
+#include "support/lstrings.h"
#include <algorithm>
#include <functional>
namespace lyx {
class Buffer;
-class Lexer;
class OutputParams;
+namespace support { class Lexer; }
+
class ParamInfo {
public:
///
///
InsetCode code() const { return insetCode_; }
/// Parse the command
- void read(Lexer &);
+ void read(support::Lexer &);
///
- void Read(Lexer &, Buffer const *);
+ void Read(support::Lexer &, Buffer const *);
///
void write(std::ostream &) const;
///
#include "FuncStatus.h"
#include "InsetLayout.h"
#include "Language.h"
-#include "Lexer.h"
#include "xml.h"
#include "ParagraphParameters.h"
#include "Paragraph.h"
#include "support/docstream.h"
#include "support/gettext.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include "support/TempFile.h"
#include "Encoding.h"
#include "FuncStatus.h"
#include "FuncRequest.h"
#include "LaTeXFeatures.h"
-#include "Lexer.h"
-#include "LyX.h" // use_gui
#include "LyXRC.h"
#include "MetricsInfo.h"
#include "output_latex.h"
#include "support/filetools.h"
#include "support/gettext.h"
#include "support/lassert.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include "support/lyxlib.h"
#include "support/TempFile.h"
InsetExternalParams();
void write(Buffer const &, std::ostream &) const;
- bool read(Buffer const &, Lexer &);
+ bool read(Buffer const &, support::Lexer &);
/// The name of the tempfile used for manipulations.
support::FileName tempname() const { return tempname_(); }
///
void write(std::ostream &) const override;
///
- void read(Lexer & lex) override;
+ void read(support::Lexer & lex) override;
///
int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const override;
#include "FuncRequest.h"
#include "FuncStatus.h"
#include "Language.h"
-#include "Lexer.h"
#include "ParIterator.h"
#include "TextClass.h"
#include "support/debug.h"
#include "support/gettext.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include <ostream>
#include "FuncRequest.h"
#include "FuncStatus.h"
#include "LaTeXFeatures.h"
-#include "Lexer.h"
#include "xml.h"
#include "output_docbook.h"
#include "output_xhtml.h"
#include "support/debug.h"
#include "support/docstream.h"
#include "support/gettext.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include "frontends/Application.h"
///
void write(std::ostream & os) const;
///
- void read(Lexer & lex);
+ void read(support::Lexer & lex);
///
std::string type;
///
///
void write(std::ostream & os) const override;
///
- void read(Lexer & lex) override;
+ void read(support::Lexer & lex) override;
///
void validate(LaTeXFeatures & features) const override;
///
#include "FuncRequest.h"
#include "Language.h"
#include "LaTeXFeatures.h"
-#include "Lexer.h"
#include "Paragraph.h"
#include "output_xhtml.h"
#include "texstream.h"
#include "support/debug.h"
#include "support/gettext.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include <ostream>
///
void write(std::ostream &) const override;
///
- void read(Lexer &) override;
+ void read(support::Lexer &) override;
///
void latex(otexstream &, OutputParams const &) const override;
///
#include "InsetIterator.h"
#include "LaTeX.h"
#include "LaTeXFeatures.h"
-#include "Lexer.h"
#include "MetricsInfo.h"
#include "Mover.h"
#include "output_docbook.h"
#include "support/filetools.h"
#include "support/gettext.h"
#include "support/Length.h"
+#include "support/Lexer.h"
#include "support/lyxlib.h"
#include "support/lstrings.h"
#include "support/os.h"
///
void write(std::ostream &) const override;
///
- void read(Lexer & lex) override;
+ void read(support::Lexer & lex) override;
/** returns the number of rows (\n's) of generated tex code.
#fragile == true# means, that the inset should take care about
fragile commands by adding a #\protect# before.
#include "Buffer.h"
#include "LyX.h" // for use_gui
-#include "Lexer.h"
#include "LyXRC.h"
#include "graphics/epstools.h"
#include "support/convert.h"
#include "support/debug.h"
#include "support/lyxlib.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include "support/Translator.h"
namespace lyx {
namespace graphics { class Params; }
+namespace support { class Lexer; }
-class Lexer;
class Buffer;
/// Buffer is needed to figure out if a figure is embedded.
void Write(std::ostream & os, Buffer const & buf) const;
/// If the token belongs to our parameters, read it.
- bool Read(Lexer & lex, std::string const & token, Buffer const & buf,
+ bool Read(support::Lexer & lex, std::string const & token, Buffer const & buf,
bool allowOrigin);
/// convert
// Only a subset of InsetGraphicsParams is needed for display purposes.
#include "FuncRequest.h"
#include "FuncStatus.h"
#include "LaTeXFeatures.h"
-#include "Lexer.h"
#include "MetricsInfo.h"
#include "RenderPreview.h"
#include "texstream.h"
#include "graphics/PreviewImage.h"
+#include "support/Lexer.h"
+
#include <sstream>
using namespace std;
#include "FuncStatus.h"
#include "InsetLayout.h"
#include "LaTeXFeatures.h"
-#include "Lexer.h"
#include "MetricsInfo.h"
#include "xml.h"
#include "texstream.h"
#include "support/debug.h"
#include "support/docstream.h"
#include "support/gettext.h"
+#include "support/Lexer.h"
#include "support/Translator.h"
using namespace std;
namespace lyx {
+using support::Lexer;
+
namespace {
typedef Translator<string, InsetIPADecoParams::Type> IPADecoTranslator;
///
void write(std::ostream & os) const;
///
- void read(Lexer & lex);
+ void read(support::Lexer & lex);
///
Type type;
};
///
void write(std::ostream &) const override;
///
- void read(Lexer & lex) override;
+ void read(support::Lexer & lex) override;
///
bool neverIndent() const override { return true; }
///
///
void write(std::ostream &) const override;
/// Will not be used when lyxf3
- void read(Lexer & lex) override;
+ void read(support::Lexer & lex) override;
///
void latex(otexstream &, OutputParams const &) const override;
///
#include "Paragraph.h"
#include "LaTeX.h"
#include "LaTeXFeatures.h"
-#include "Lexer.h"
#include "LyX.h"
#include "output_latex.h"
#include "output_xhtml.h"
#include "support/docstream.h"
#include "support/FileName.h"
#include "support/gettext.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include "support/Translator.h"
///
void write(std::ostream & os) const;
///
- void read(Lexer & lex);
+ void read(support::Lexer & lex);
///
docstring index;
///
///
void write(std::ostream & os) const override;
///
- void read(Lexer & lex) override;
+ void read(support::Lexer & lex) override;
///
void docbook(XMLStream &, OutputParams const &) const override;
///
#include "InsetList.h"
#include "LaTeX.h"
#include "LaTeXFeatures.h"
-#include "Lexer.h"
#include "MetricsInfo.h"
#include "xml.h"
#include "texstream.h"
#include "support/debug.h"
#include "support/docstream.h"
#include "support/gettext.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include "support/Translator.h"
///
void write(std::ostream & os) const;
///
- void read(Lexer & lex);
+ void read(support::Lexer & lex);
///
Type type;
};
///
void write(std::ostream &) const override;
///
- void read(Lexer & lex) override;
+ void read(support::Lexer & lex) override;
///
bool neverIndent() const override { return true; }
/// We do not output anything directly to the stream
#include "LyXAction.h"
#include "LyXRC.h"
#include "LyXVC.h"
-#include "Lexer.h"
#include "output_docbook.h"
#include "Paragraph.h"
#include "ParIterator.h"
#include "support/filetools.h"
#include "support/gettext.h"
#include "support/Length.h"
+#include "support/Lexer.h"
#include "support/Messages.h"
#include "support/lstrings.h"
#include "support/qstring_helpers.h"
///
bool hasSettings() const override { return true; }
///
- void read(Lexer & lex) override;
+ void read(support::Lexer & lex) override;
///
void write(std::ostream & os) const override;
///
#include "InsetLayout.h"
#include "ColorSet.h"
-#include "Lexer.h"
#include "TextClass.h"
#include "support/debug.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include "support/textutils.h"
namespace lyx {
-class Lexer;
class TextClass;
+namespace support { class Lexer; }
enum class InsetDecoration : int {
CLASSIC,
///
InsetLayout() { labelfont_.setColor(Color_insetlabel); }
///
- bool read(Lexer & lexrc, TextClass const & tclass,
+ bool read(support::Lexer & lexrc, TextClass const & tclass,
bool validating = false);
///
docstring name() const { return name_; }
///
std::string defaultCSSClass() const;
///
- void readArgument(Lexer &);
+ void readArgument(support::Lexer &);
///
docstring name_ = from_ascii("undefined");
/**
#include "InsetLayout.h"
#include "Language.h"
#include "LaTeXFeatures.h"
-#include "Lexer.h"
#include "output_latex.h"
#include "output_docbook.h"
#include "output_xhtml.h"
#include "support/debug.h"
#include "support/docstream.h"
#include "support/gettext.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include "support/lassert.h"
///
void write(std::ostream & os) const override;
///
- void read(Lexer & lex) override;
+ void read(support::Lexer & lex) override;
///
void latex(otexstream &, OutputParams const &) const override;
///
#include "InsetListingsParams.h"
-#include "support/Length.h"
-#include "Lexer.h"
-
#include "support/convert.h"
#include "support/gettext.h"
+#include "support/Length.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include "support/textutils.h"
void write(std::ostream &) const;
/// read parameters from an ostream
- void read(Lexer &);
+ void read(support::Lexer &);
/// valid parameter string
std::string params(std::string const & sep=",") const;
#include "Dimension.h"
#include "FuncRequest.h"
#include "FuncStatus.h"
-#include "Lexer.h"
#include "MetricsInfo.h"
#include "output_docbook.h"
#include "output_xhtml.h"
#include "support/debug.h"
#include "support/docstream.h"
#include "support/docstring.h"
+#include "support/Lexer.h"
using namespace std;
namespace lyx {
+using support::Lexer;
+
InsetNewline::InsetNewline() : Inset(nullptr)
{}
///
void write(std::ostream & os) const;
///
- void read(Lexer & lex);
+ void read(support::Lexer & lex);
///
Kind kind;
};
///
docstring xhtml(XMLStream &, OutputParams const &) const override;
///
- void read(Lexer & lex) override;
+ void read(support::Lexer & lex) override;
///
void write(std::ostream & os) const override;
/// is this equivalent to a space (which is BTW different from
#include "Cursor.h"
#include "FuncRequest.h"
#include "FuncStatus.h"
-#include "Lexer.h"
#include "MetricsInfo.h"
#include "xml.h"
#include "texstream.h"
#include "support/docstring.h"
#include "support/docstream.h"
#include "support/gettext.h"
+#include "support/Lexer.h"
using namespace std;
-
namespace lyx {
- InsetNewpage::InsetNewpage() : Inset(nullptr)
+using support::Lexer;
+
+InsetNewpage::InsetNewpage() : Inset(nullptr)
{}
///
void write(std::ostream & os) const;
///
- void read(Lexer & lex);
+ void read(support::Lexer & lex);
///
Kind kind;
};
///
docstring xhtml(XMLStream &, OutputParams const &) const override;
///
- void read(Lexer & lex) override;
+ void read(support::Lexer & lex) override;
///
void write(std::ostream & os) const override;
///
#include "FuncStatus.h"
#include "InsetLayout.h"
#include "LaTeXFeatures.h"
-#include "Lexer.h"
#include "LyXRC.h"
#include "output_docbook.h"
#include "output_latex.h"
#include "support/debug.h"
#include "support/docstream.h"
#include "support/gettext.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include "support/Translator.h"
namespace lyx {
+using support::Lexer;
+
namespace {
typedef Translator<string, InsetNoteParams::Type> NoteTranslator;
///
void write(std::ostream & os) const;
///
- void read(Lexer & lex);
+ void read(support::Lexer & lex);
///
Type type;
};
///
void write(std::ostream &) const override;
///
- void read(Lexer & lex) override;
+ void read(support::Lexer & lex) override;
/// show the note dialog
bool showInsetDialog(BufferView * bv) const override;
///
#include "FuncRequest.h"
#include "FuncStatus.h"
#include "LaTeXFeatures.h"
-#include "Lexer.h"
#include "MetricsInfo.h"
#include "texstream.h"
#include "TextClass.h"
#include "frontends/Application.h"
#include "frontends/FontMetrics.h"
+#include "support/Lexer.h"
#include "frontends/Painter.h"
#include <algorithm>
namespace lyx {
+using support::Lexer;
+
namespace {
typedef Translator<string, InsetPhantomParams::Type> PhantomTranslator;
///
void write(std::ostream & os) const;
///
- void read(Lexer & lex);
+ void read(support::Lexer & lex);
///
Type type;
};
///
void write(std::ostream &) const override;
///
- void read(Lexer & lex) override;
+ void read(support::Lexer & lex) override;
///
void setButtonLabel() override;
/// show the phantom dialog
#include "FuncRequest.h"
#include "Language.h"
#include "LaTeXFeatures.h"
-#include "Lexer.h"
#include "LyXRC.h"
#include "MetricsInfo.h"
#include "Paragraph.h"
#include "support/docstring.h"
#include "support/docstream.h"
#include "support/gettext.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include "support/textutils.h"
///
void write(std::ostream &) const override;
///
- void read(Lexer & lex) override;
+ void read(support::Lexer & lex) override;
///
bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const override;
///
#include "FuncRequest.h"
#include "FuncStatus.h"
#include "LaTeXFeatures.h"
-#include "Lexer.h"
#include "LyXAction.h"
#include "MetricsInfo.h"
#include "output_docbook.h"
#include "support/docstream.h"
#include "support/gettext.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include "support/Translator.h"
namespace lyx {
+using support::Lexer;
+
namespace {
typedef Translator<string, InsetScriptParams::Type> ScriptTranslator;
///
void write(std::ostream & os) const;
///
- void read(Lexer & lex);
+ void read(support::Lexer & lex);
///
int shift(FontInfo const & font) const;
///
///
void write(std::ostream &) const override;
///
- void read(Lexer & lex) override;
+ void read(support::Lexer & lex) override;
///
bool forcePlainLayout(idx_type = 0) const override { return true; }
///
#include "Dimension.h"
#include "FuncRequest.h"
#include "FuncStatus.h"
-#include "Lexer.h"
#include "MetricsInfo.h"
#include "output_docbook.h"
#include "output_xhtml.h"
#include "support/debug.h"
#include "support/docstream.h"
#include "support/docstring.h"
+#include "support/Lexer.h"
using namespace std;
using namespace lyx::frontend;
namespace lyx {
+using support::Lexer;
+
InsetSeparator::InsetSeparator() : Inset(nullptr)
{}
///
void write(std::ostream & os) const;
///
- void read(Lexer & lex);
+ void read(support::Lexer & lex);
///
Kind kind;
};
///
docstring xhtml(XMLStream &, OutputParams const &) const override;
///
- void read(Lexer & lex) override;
+ void read(support::Lexer & lex) override;
///
void write(std::ostream & os) const override;
/// is this equivalent to a space (which is BTW different from
#include "FuncStatus.h"
#include "Language.h"
#include "LaTeXFeatures.h"
-#include "Lexer.h"
#include "MetricsInfo.h"
#include "texstream.h"
#include "xml.h"
#include "frontends/Application.h"
#include "frontends/FontMetrics.h"
+#include "support/Lexer.h"
#include "frontends/Painter.h"
using namespace std;
namespace lyx {
+using support::Lexer;
InsetSpace::InsetSpace(InsetSpaceParams const & params)
: Inset(nullptr), params_(params)
///
void write(std::ostream & os) const;
///
- void read(Lexer & lex);
+ void read(support::Lexer & lex);
///
Kind kind;
///
///
void write(std::ostream &) const override;
/// Will not be used when lyxf3
- void read(Lexer & lex) override;
+ void read(support::Lexer & lex) override;
///
void latex(otexstream &, OutputParams const &) const override;
///
#include "Font.h"
#include "Language.h"
#include "LaTeXFeatures.h"
-#include "Lexer.h"
#include "MetricsInfo.h"
#include "output_xhtml.h"
#include "xml.h"
#include "support/debug.h"
#include "support/docstream.h"
+#include "support/Lexer.h"
using namespace std;
namespace lyx {
+using support::Lexer;
+
InsetSpecialChar::InsetSpecialChar(Kind k)
: Inset(nullptr), kind_(k)
///
void write(std::ostream &) const override;
/// Will not be used when lyxf3
- void read(Lexer & lex) override;
+ void read(support::Lexer & lex) override;
///
void latex(otexstream &, OutputParams const &) const override;
///
#include "InsetList.h"
#include "Language.h"
#include "LaTeXFeatures.h"
-#include "Lexer.h"
#include "LyX.h"
#include "LyXRC.h"
#include "MetricsInfo.h"
#include "support/FileName.h"
#include "support/gettext.h"
#include "support/lassert.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include "support/unique_ptr.h"
class Cursor;
class CursorSlice;
class FuncStatus;
-class Lexer;
class OutputParams;
class XMLStream;
+namespace support { class Lexer; }
///
class InsetTableCell : public InsetText
///
void write(std::ostream &) const;
///
- void read(Lexer &);
+ void read(support::Lexer &);
///
void latex(otexstream &, OutputParams const &) const;
/// serialise the table in DocBook, according to buffer parameters
///
static std::string params2string(InsetTabular const &);
///
- void read(Lexer &) override;
+ void read(support::Lexer &) override;
///
void write(std::ostream &) const override;
///
#include "Language.h"
#include "Layout.h"
#include "LaTeXFeatures.h"
-#include "Lexer.h"
+#include "support/Lexer.h"
#include "lyxfind.h"
#include "LyXRC.h"
#include "MetricsInfo.h"
/// empty inset to empty par
void clear();
///
- void read(Lexer & lex) override;
+ void read(support::Lexer & lex) override;
///
void write(std::ostream & os) const override;
/// Let the inset compute and store its reference font from \c outer.
#include "DispatchResult.h"
#include "FuncRequest.h"
#include "FuncStatus.h"
-#include "Lexer.h"
#include "MetricsInfo.h"
#include "xml.h"
#include "texstream.h"
#include "support/debug.h"
#include "support/docstream.h"
#include "support/gettext.h"
+#include "support/Lexer.h"
#include "support/lassert.h"
#include "frontends/Application.h"
namespace lyx {
+using support::Lexer;
+
namespace {
int const ADD_TO_VSPACE_WIDTH = 5;
/// in fact, appear at all.
docstring xhtml(XMLStream &, OutputParams const &) const override;
///
- void read(Lexer & lex) override;
+ void read(support::Lexer & lex) override;
///
void write(std::ostream & os) const override;
///
#include "FuncRequest.h"
#include "FuncStatus.h"
#include "LaTeXFeatures.h"
-#include "Lexer.h"
#include "xml.h"
#include "texstream.h"
#include "TextClass.h"
#include "support/debug.h"
#include "support/docstream.h"
#include "support/gettext.h"
+#include "support/Lexer.h"
#include "frontends/Application.h"
namespace lyx {
+using support::Lexer;
+
InsetWrap::InsetWrap(Buffer * buf, string const & type)
: InsetCaptionable(buf)
{
///
void write(std::ostream &) const;
///
- void read(Lexer &);
+ void read(support::Lexer &);
///
std::string type;
///
void write(std::ostream & os) const override;
///
- void read(Lexer & lex) override;
+ void read(support::Lexer & lex) override;
///
void validate(LaTeXFeatures & features) const override;
///
///
void footer_write(TeXMathStream &) const;
///
- void read(Lexer & lex) override;
+ void read(support::Lexer & lex) override;
///
- bool readQuiet(Lexer & lex);
+ bool readQuiet(support::Lexer & lex);
///
int plaintext(odocstringstream &, OutputParams const &,
size_t max_length = INT_MAX) const override;
#include "FuncRequest.h"
#include "FuncStatus.h"
#include "LaTeXFeatures.h"
-#include "Lexer.h"
#include "MetricsInfo.h"
#include "TocBackend.h"
#include "support/debug.h"
#include "support/gettext.h"
#include "support/docstream.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include <set>
namespace lyx {
using support::bformat;
+using support::Lexer;
//////////////////////////////////////////////////////////////////////
///
bool notifyCursorLeaves(Cursor const & old, Cursor & cur) override;
///
- void read(Lexer & lex) override;
+ void read(support::Lexer & lex) override;
///
void write(std::ostream & os) const override;
///
#include "Buffer.h"
#include "BufferParams.h"
#include "Encoding.h"
-#include "Lexer.h"
#include "support/convert.h"
#include "support/debug.h"
#include "support/docstream.h"
+#include "support/Lexer.h"
#include <sstream>
namespace lyx {
+using support::Lexer;
+
namespace {
InsetMath::mode_type asMode(InsetMath::mode_type oldmode, docstring const & str)
class MathAtom;
class MathData;
class InsetMathGrid;
-class Lexer;
+namespace support { class Lexer; }
///
class latexkeys {
Parse::flags f = Parse::NORMAL);
/// parse formula from the LyX lexxer
-bool mathed_parse_normal(Buffer * buf, MathAtom &, Lexer &,
+bool mathed_parse_normal(Buffer * buf, MathAtom &, support::Lexer &,
Parse::flags f = Parse::NORMAL);
/// parse formula from a string into a grid
--- /dev/null
+/**
+ * \file Lexer.cpp
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Alejandro Aguilar Sierra
+ * \author Lars Gullik Bjønnes
+ * \author Jean-Marc Lasgouttes
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+#include <config.h>
+
+#include "support/Lexer.h"
+
+#include "support/convert.h"
+#include "support/debug.h"
+#include "support/FileName.h"
+#include "support/filetools.h"
+#include "support/gzstream.h"
+#include "support/lassert.h"
+#include "support/lstrings.h"
+#include "support/lyxalgo.h"
+
+#include <algorithm> // sort, lower_bound
+#include <functional>
+#include <fstream>
+#include <istream>
+#include <stack>
+#include <vector>
+
+using namespace std;
+
+namespace lyx {
+
+namespace support {
+
+//////////////////////////////////////////////////////////////////////
+//
+// Lexer::Pimpl
+//
+//////////////////////////////////////////////////////////////////////
+
+
+///
+class Lexer::Pimpl {
+public:
+ ///
+ Pimpl(LexerKeyword * tab, int num);
+ ///
+ string const getString() const;
+ ///
+ docstring const getDocString() const;
+ ///
+ void printError(string const & message) const;
+ ///
+ void printTable(ostream & os);
+ ///
+ void pushTable(LexerKeyword * tab, int num);
+ ///
+ void popTable();
+ ///
+ bool setFile(FileName const & filename);
+ ///
+ void setStream(istream & i);
+ ///
+ void setCommentChar(char c);
+ ///
+ bool next(bool esc = false);
+ ///
+ int searchKeyword(char const * const tag) const;
+ ///
+ int lex();
+ ///
+ bool eatLine();
+ ///
+ bool nextToken();
+ /// test if there is a pushed token or the stream is ok
+ bool inputAvailable();
+ ///
+ void pushToken(string const &);
+ /// gz_ is only used to open files, the stream is accessed through is.
+ gz::gzstreambuf gz_;
+
+ /// the stream that we use.
+ istream is;
+ ///
+ string name;
+ ///
+ LexerKeyword * table;
+ ///
+ int no_items;
+ ///
+ string buff;
+ ///
+ int status;
+ ///
+ int lineno;
+ ///
+ string pushTok;
+ /// used for error messages
+ string context;
+ ///
+ char commentChar;
+private:
+ /// non-copyable
+ Pimpl(Pimpl const &);
+ void operator=(Pimpl const &);
+
+ ///
+ void verifyTable();
+ ///
+ class PushedTable {
+ public:
+ ///
+ PushedTable()
+ : table_elem(nullptr), table_siz(0) {}
+ ///
+ PushedTable(LexerKeyword * ki, int siz)
+ : table_elem(ki), table_siz(siz) {}
+ ///
+ LexerKeyword * table_elem;
+ ///
+ int table_siz;
+ };
+ ///
+ stack<PushedTable> pushed;
+};
+
+
+namespace {
+
+// used by lower_bound, sort and sorted
+bool compareTags(LexerKeyword const & a, LexerKeyword const & b)
+{
+ // 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;
+}
+
+} // namespace
+
+
+
+Lexer::Pimpl::Pimpl(LexerKeyword * tab, int num)
+ : is(&gz_), table(tab), no_items(num),
+ status(0), lineno(0), commentChar('#')
+{
+ verifyTable();
+}
+
+
+string const Lexer::Pimpl::getString() const
+{
+ return buff;
+}
+
+
+docstring const Lexer::Pimpl::getDocString() const
+{
+ return from_utf8(buff);
+}
+
+
+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))
+ << " current token: '" << getString() << "'"
+ << " context: '" << context << "']" << endl;
+}
+
+
+void Lexer::Pimpl::printTable(ostream & os)
+{
+ os << "\nNumber of tags: " << no_items << endl;
+ for (int i= 0; i < no_items; ++i)
+ os << "table[" << i
+ << "]: tag: `" << table[i].tag
+ << "' code:" << table[i].code << '\n';
+ os.flush();
+}
+
+
+void Lexer::Pimpl::verifyTable()
+{
+ // Check if the table is sorted and if not, sort it.
+ if (table
+ && !lyx::sorted(table, table + no_items, &compareTags)) {
+ lyxerr << "The table passed to Lexer is not sorted!\n"
+ << "Tell the developers to fix it!" << endl;
+ // We sort it anyway to avoid problems.
+ lyxerr << "\nUnsorted:" << endl;
+ printTable(lyxerr);
+
+ sort(table, table + no_items, &compareTags);
+ lyxerr << "\nSorted:" << endl;
+ printTable(lyxerr);
+ }
+}
+
+
+void Lexer::Pimpl::pushTable(LexerKeyword * tab, int num)
+{
+ PushedTable tmppu(table, no_items);
+ pushed.push(tmppu);
+
+ table = tab;
+ no_items = num;
+
+ verifyTable();
+}
+
+
+void Lexer::Pimpl::popTable()
+{
+ if (pushed.empty()) {
+ lyxerr << "Lexer error: nothing to pop!" << endl;
+ return;
+ }
+
+ PushedTable tmp = pushed.top();
+ pushed.pop();
+ table = tmp.table_elem;
+ no_items = tmp.table_siz;
+}
+
+
+bool Lexer::Pimpl::setFile(FileName const & filename)
+{
+ if (gz_.is_open() || istream::off_type(is.tellg()) > -1)
+ LYXERR0("Error in LyXLex::setFile: file or stream already set.");
+ gz_.open(filename.toSafeFilesystemEncoding().c_str(), ios::in);
+ is.rdbuf(&gz_);
+ name = filename.absFileName();
+ lineno = 0;
+ if (!gz_.is_open() || !is.good())
+ return false;
+
+ // Skip byte order mark.
+ if (is.peek() == 0xef) {
+ is.get();
+ if (is.peek() == 0xbb) {
+ is.get();
+ LASSERT(is.get() == 0xbf, /**/);
+ } else
+ is.unget();
+ }
+
+ return true;
+}
+
+
+void Lexer::Pimpl::setStream(istream & i)
+{
+ if (gz_.is_open() || istream::off_type(is.tellg()) > 0)
+ LYXERR0("Error in Lexer::setStream: file or stream already set.");
+ is.rdbuf(i.rdbuf());
+ lineno = 0;
+}
+
+
+void Lexer::Pimpl::setCommentChar(char c)
+{
+ commentChar = c;
+}
+
+
+bool Lexer::Pimpl::next(bool esc /* = false */)
+{
+ if (!pushTok.empty()) {
+ // There can have been a whole line pushed so
+ // we extract the first word and leaves the rest
+ // in pushTok. (Lgb)
+ if (pushTok[0] == '\\' && pushTok.find(' ') != string::npos) {
+ buff.clear();
+ pushTok = split(pushTok, buff, ' ');
+ } else {
+ buff = pushTok;
+ pushTok.clear();
+ }
+ status = LEX_TOKEN;
+ return true;
+ }
+
+
+ char cc = 0;
+ status = 0;
+ while (is && !status) {
+ is.get(cc);
+ unsigned char c = cc;
+
+ if (c == commentChar) {
+ // Read rest of line (fast :-)
+#if 1
+ // That is not fast... (Lgb)
+ string dummy;
+ getline(is, dummy);
+
+ LYXERR(Debug::LYXLEX, "Comment read: `" << string(1, c) << dummy << '\'');
+#else
+ // unfortunately ignore is buggy (Lgb)
+ is.ignore(100, '\n');
+#endif
+ ++lineno;
+ continue;
+ }
+
+ if (c == '\"') {
+ buff.clear();
+
+ if (esc) {
+
+ do {
+ bool escaped = false;
+ is.get(cc);
+ c = cc;
+ if (c == '\r') continue;
+ if (c == '\\') {
+ // escape the next char
+ is.get(cc);
+ c = cc;
+ if (c == '\"' || c == '\\')
+ escaped = true;
+ else
+ buff.push_back('\\');
+ }
+ buff.push_back(c);
+
+ if (!escaped && c == '\"')
+ break;
+ } while (c != '\n' && is);
+
+ } else {
+
+ do {
+ is.get(cc);
+ c = cc;
+ if (c != '\r')
+ buff.push_back(c);
+ } while (c != '\"' && c != '\n' && is);
+
+ }
+
+ if (c != '\"') {
+ printError("Missing quote");
+ if (c == '\n')
+ ++lineno;
+ }
+
+ buff.resize(buff.size() - 1);
+ status = LEX_DATA;
+ break;
+ }
+
+ if (c == ',')
+ continue; /* Skip ','s */
+
+ // 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) {
+ buff.clear();
+
+ do {
+ if (esc && c == '\\') {
+ // escape the next char
+ is.get(cc);
+ c = cc;
+ //escaped = true;
+ }
+ buff.push_back(c);
+ is.get(cc);
+ c = cc;
+ } while (c > ' ' && c != ',' && is);
+ status = LEX_TOKEN;
+ }
+
+ 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;
+ }
+
+ if (c == '\n')
+ ++lineno;
+
+ }
+ if (status)
+ return true;
+
+ status = is.eof() ? LEX_FEOF: LEX_UNDEF;
+ buff.clear();
+ return false;
+}
+
+
+int Lexer::Pimpl::searchKeyword(char const * const tag) const
+{
+ LexerKeyword search_tag = { tag, 0 };
+ LexerKeyword * res =
+ lower_bound(table, table + no_items,
+ search_tag, &compareTags);
+ // 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.
+ if (res != table + no_items
+ && !compare_ascii_no_case(res->tag, tag))
+ return res->code;
+ return LEX_UNDEF;
+}
+
+
+int Lexer::Pimpl::lex()
+{
+ //NOTE: possible bug.
+ if (next() && status == LEX_TOKEN)
+ return searchKeyword(getString().c_str());
+ return status;
+}
+
+
+bool Lexer::Pimpl::eatLine()
+{
+ buff.clear();
+
+ unsigned char c = '\0';
+ char cc = 0;
+ while (is && c != '\n') {
+ is.get(cc);
+ c = cc;
+ //LYXERR(Debug::LYXLEX, "Lexer::EatLine read char: `" << c << '\'');
+ if (c != '\r' && is)
+ buff.push_back(c);
+ }
+
+ if (c == '\n') {
+ ++lineno;
+ buff.resize(buff.size() - 1);
+ status = LEX_DATA;
+ return true;
+ } else if (buff.length() > 0) { // last line
+ status = LEX_DATA;
+ return true;
+ } else {
+ return false;
+ }
+}
+
+
+bool Lexer::Pimpl::nextToken()
+{
+ if (!pushTok.empty()) {
+ // There can have been a whole line pushed so
+ // we extract the first word and leaves the rest
+ // in pushTok. (Lgb)
+ if (pushTok[0] == '\\' && pushTok.find(' ') != string::npos) {
+ buff.clear();
+ pushTok = split(pushTok, buff, ' ');
+ } else {
+ buff = pushTok;
+ pushTok.clear();
+ }
+ status = LEX_TOKEN;
+ return true;
+ }
+
+ status = 0;
+ while (is && !status) {
+ unsigned char c = 0;
+ char cc = 0;
+ is.get(cc);
+ c = cc;
+ if ((c >= ' ' || c == '\t') && is) {
+ buff.clear();
+
+ if (c == '\\') { // first char == '\\'
+ do {
+ buff.push_back(c);
+ is.get(cc);
+ c = cc;
+ } while (c > ' ' && c != '\\' && is);
+ } else {
+ do {
+ buff.push_back(c);
+ is.get(cc);
+ c = cc;
+ } while ((c >= ' ' || c == '\t') && c != '\\' && is);
+ }
+
+ if (c == '\\')
+ is.putback(c); // put it back
+ status = LEX_TOKEN;
+ }
+
+ if (c == '\n')
+ ++lineno;
+
+ }
+ if (status)
+ return true;
+
+ status = is.eof() ? LEX_FEOF: LEX_UNDEF;
+ buff.clear();
+ return false;
+}
+
+
+bool Lexer::Pimpl::inputAvailable()
+{
+ return is.good();
+}
+
+
+void Lexer::Pimpl::pushToken(string const & pt)
+{
+ pushTok = pt;
+}
+
+
+
+
+//////////////////////////////////////////////////////////////////////
+//
+// Lexer
+//
+//////////////////////////////////////////////////////////////////////
+
+Lexer::Lexer()
+ : pimpl_(new Pimpl(nullptr, 0)), lastReadOk_(false)
+{}
+
+
+void Lexer::init(LexerKeyword * tab, int num)
+{
+ pimpl_ = new Pimpl(tab, num);
+}
+
+
+Lexer::~Lexer()
+{
+ delete pimpl_;
+}
+
+
+bool Lexer::isOK() const
+{
+ return pimpl_->inputAvailable();
+}
+
+
+void Lexer::setLineNumber(int l)
+{
+ pimpl_->lineno = l;
+}
+
+
+int Lexer::lineNumber() const
+{
+ return pimpl_->lineno;
+}
+
+
+istream & Lexer::getStream()
+{
+ return pimpl_->is;
+}
+
+
+void Lexer::pushTable(LexerKeyword * tab, int num)
+{
+ pimpl_->pushTable(tab, num);
+}
+
+
+void Lexer::popTable()
+{
+ pimpl_->popTable();
+}
+
+
+void Lexer::printTable(ostream & os)
+{
+ pimpl_->printTable(os);
+}
+
+
+void Lexer::printError(string const & message) const
+{
+ pimpl_->printError(message);
+}
+
+
+bool Lexer::setFile(FileName const & filename)
+{
+ return pimpl_->setFile(filename);
+}
+
+
+void Lexer::setStream(istream & i)
+{
+ pimpl_->setStream(i);
+}
+
+
+void Lexer::setCommentChar(char c)
+{
+ pimpl_->setCommentChar(c);
+}
+
+
+int Lexer::lex()
+{
+ return pimpl_->lex();
+}
+
+
+int Lexer::getInteger() const
+{
+ lastReadOk_ = pimpl_->status == LEX_DATA || pimpl_->status == LEX_TOKEN;
+ if (!lastReadOk_) {
+ pimpl_->printError("integer token missing");
+ return -1;
+ }
+
+ if (isStrInt(pimpl_->getString()))
+ return convert<int>(pimpl_->getString());
+
+ lastReadOk_ = false;
+ pimpl_->printError("Bad integer `$$Token'");
+ return -1;
+}
+
+
+double Lexer::getFloat() const
+{
+ // replace comma with dot in case the file was written with
+ // the wrong locale (should be rare, but is easy enough to
+ // avoid).
+ lastReadOk_ = pimpl_->status == LEX_DATA || pimpl_->status == LEX_TOKEN;
+ if (!lastReadOk_) {
+ pimpl_->printError("float token missing");
+ return -1;
+ }
+
+ string const str = subst(pimpl_->getString(), ",", ".");
+ if (isStrDbl(str))
+ return convert<double>(str);
+
+ lastReadOk_ = false;
+ pimpl_->printError("Bad float `$$Token'");
+ return -1;
+}
+
+
+string const Lexer::getString(bool trim) const
+{
+ lastReadOk_ = pimpl_->status == LEX_DATA || pimpl_->status == LEX_TOKEN;
+
+ if (lastReadOk_)
+ return trim ? support::trim(pimpl_->getString(), "\t ") : pimpl_->getString();
+
+ return string();
+}
+
+
+docstring const Lexer::getDocString(bool trim) const
+{
+ lastReadOk_ = pimpl_->status == LEX_DATA || pimpl_->status == LEX_TOKEN;
+
+ if (lastReadOk_)
+ return trim ? support::trim(pimpl_->getDocString(), "\t ") : pimpl_->getDocString();
+
+ return docstring();
+}
+
+
+// I would prefer to give a tag number instead of an explicit token
+// here, but it is not possible because Buffer::readDocument uses
+// explicit tokens (JMarc)
+docstring Lexer::getLongString(docstring const & endtoken)
+{
+ docstring str;
+ docstring prefix;
+ bool firstline = true;
+ bool foundend = false;
+
+ while (pimpl_->is) { //< eatLine only reads from is, not from pushTok
+ if (!eatLine())
+ // blank line in the file being read
+ continue;
+ docstring tmpstr = getDocString();
+ docstring const token = trim(tmpstr, " \t");
+
+ LYXERR(Debug::PARSER, "LongString: `" << tmpstr << '\'');
+
+ // We do a case independent comparison, like searchKeyword does.
+ if (compare_no_case(token, endtoken) == 0) {
+ foundend = true;
+ break;
+ }
+
+ if (firstline) {
+ size_t i = tmpstr.find_first_not_of(from_ascii(" \t"));
+ if (i != string::npos)
+ prefix = tmpstr.substr(0, i);
+ firstline = false;
+ LYXERR(Debug::PARSER, "Prefix = `" << prefix << "\'");
+ }
+
+ // further lines in long strings may have the same
+ // whitespace prefix as the first line. Remove it.
+ if (!prefix.empty() && prefixIs(tmpstr, prefix))
+ tmpstr.erase(0, prefix.length());
+
+ str += tmpstr + '\n';
+ }
+
+ if (!foundend)
+ printError("Long string not ended by `" + to_utf8(endtoken) + '\'');
+
+ return str;
+}
+
+
+bool Lexer::getBool() const
+{
+ string const s = pimpl_->getString();
+ if (s == "false" || s == "0") {
+ lastReadOk_ = true;
+ return false;
+ }
+ if (s == "true" || s == "1") {
+ lastReadOk_ = true;
+ return true;
+ }
+ pimpl_->printError("Bad boolean `$$Token'. "
+ "Use \"false\" or \"true\"");
+ lastReadOk_ = false;
+ return false;
+}
+
+
+bool Lexer::eatLine()
+{
+ return pimpl_->eatLine();
+}
+
+
+bool Lexer::next(bool esc)
+{
+ return pimpl_->next(esc);
+}
+
+
+bool Lexer::nextToken()
+{
+ return pimpl_->nextToken();
+}
+
+
+void Lexer::pushToken(string const & pt)
+{
+ pimpl_->pushToken(pt);
+}
+
+
+Lexer::operator void const *() const
+{
+ // This behaviour is NOT the same as the streams which would
+ // use fail() here. However, our implementation of getString() et al.
+ // can cause the eof() and fail() bits to be set, even though we
+ // haven't tried to read 'em.
+ return lastReadOk_? this : nullptr;
+}
+
+
+bool Lexer::operator!() const
+{
+ return !lastReadOk_;
+}
+
+
+Lexer & Lexer::operator>>(string & s)
+{
+ if (isOK()) {
+ next();
+ s = getString();
+ } else {
+ lastReadOk_ = false;
+ }
+ return *this;
+}
+
+
+Lexer & Lexer::operator>>(docstring & s)
+{
+ if (isOK()) {
+ next();
+ s = getDocString();
+ } else {
+ lastReadOk_ = false;
+ }
+ return *this;
+}
+
+
+Lexer & Lexer::operator>>(double & s)
+{
+ if (isOK()) {
+ next();
+ s = getFloat();
+ } else {
+ lastReadOk_ = false;
+ }
+ return *this;
+}
+
+
+Lexer & Lexer::operator>>(int & s)
+{
+ if (isOK()) {
+ next();
+ s = getInteger();
+ } else {
+ lastReadOk_ = false;
+ }
+ return *this;
+}
+
+
+Lexer & Lexer::operator>>(unsigned int & s)
+{
+ if (isOK()) {
+ next();
+ s = getInteger();
+ } else {
+ lastReadOk_ = false;
+ }
+ return *this;
+}
+
+
+Lexer & Lexer::operator>>(bool & s)
+{
+ if (isOK()) {
+ next();
+ s = getBool();
+ } else {
+ lastReadOk_ = false;
+ }
+ return *this;
+}
+
+
+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)
+{
+ string res;
+ res += '"';
+ res += subst(subst(arg, "\\", "\\\\"), "\"", "\\\"");
+ res += '"';
+ return res;
+}
+
+
+// same for docstring
+docstring Lexer::quoteString(docstring const & arg)
+{
+ docstring res;
+ res += '"';
+ res += subst(subst(arg, from_ascii("\\"), from_ascii("\\\\")),
+ from_ascii("\""), from_ascii("\\\""));
+ res += '"';
+ return res;
+}
+
+
+Lexer & Lexer::operator>>(char const * required)
+{
+ string token;
+ *this >> token;
+ if (token != required) {
+ 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 & functionName)
+{
+ pimpl_->context = functionName;
+}
+
+} // namespace support
+
+} // namespace lyx
--- /dev/null
+// -*- C++ -*-
+/**
+ * \file Lexer.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author Alejandro Aguilar Sierra
+ * \author Lars Gullik Bjønnes
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
+// Generalized simple lexical analizer.
+// It can be used for simple syntax parsers, like lyxrc,
+// texclass and others to come.
+
+#ifndef LEXER_H
+#define LEXER_H
+
+#include "support/strfwd.h"
+#include <string>
+
+namespace lyx {
+
+namespace support {
+
+class FileName;
+
+/** A helper structure to describe a keyword for the Lexer.
+ Usually used bundled in C style arrays and passed to the
+ Lexer using a LexerKeywordTable object.
+*/
+struct LexerKeyword
+{
+ /// the string to be recognized
+ char const * tag;
+ /// a corresponding numerical id
+ int code;
+};
+
+
+/** Generalized simple lexical analyzer.
+ Use the method isOK() to check if there is still data available
+ for lexing. Use one of the the operators void* or ! to test if
+ the last reading operation was successful.
+
+ Example:
+
+ int readParam(LyxLex & lex)
+ {
+ int param = 1; // default value
+ if (lex.isOK()) { // the lexer has data to read
+ int p; // temporary variable
+ lex >> p;
+ if (lex)
+ param = p; // only use the input if reading was successful
+ }
+ return param;
+ }
+
+ @see LyXRC.cpp for an example of usage.
+ */
+class Lexer
+{
+public:
+ /// initialize Lexer with no special keywords.
+ Lexer();
+ /// initialize Lexer with a bunch of keywords
+ template<int N> Lexer(LexerKeyword (&table)[N])
+ : pimpl_(0), lastReadOk_(false) { init(table, N); }
+
+ ///
+ ~Lexer();
+
+ /// Lex basic codes
+ enum {
+ ///
+ LEX_UNDEF = -1,
+ ///
+ LEX_FEOF = -2,
+ ///
+ LEX_DATA = -3,
+ ///
+ LEX_TOKEN = -4
+ };
+
+ /// stream is open and end of stream is not reached
+ /// FIXME: test also if pushToken is not empty
+ /// FIXME: the method should be renamed to something like
+ /// dataAvailable(), in order to reflect the real behavior
+ bool isOK() const;
+ /// FIXME: The next two operators should be replaced by one method
+ /// called e.g. lastReadOk(), in order to reflect the real
+ /// behavior
+ /// last read operation was successful.
+ operator void const *() const;
+ /// last read operation was not successful
+ bool operator!() const;
+ /// return true if able to open file, else false
+ bool setFile(support::FileName const & filename);
+ ///
+ void setStream(std::istream & is);
+ ///
+ std::istream & getStream();
+ /// Danger! Don't use it unless you know what you are doing.
+ void setLineNumber(int l);
+ /// Change the character that begins a comment. Default is '#'
+ void setCommentChar(char c);
+
+ /// returns a lex code
+ int lex();
+
+ /// Read the next string, as delimited by double quotes or
+ /// whitespace. If esc is true, then we remember that some chars
+ /// might be escaped: \" at least.
+ bool next(bool esc = false);
+
+ /// Read next token. This one is almost the same as next(),
+ /// but it will consider " as a regular character and always
+ /// split a word if it contains a backslash.
+ bool nextToken();
+
+ /// Puts the rest of the line in the buffer, where it will
+ /// be available via getString() or getDocString().
+ bool eatLine();
+
+ /// Push a token, that next token got from lyxlex.
+ void pushToken(std::string const &);
+
+ /// return the current line number
+ int lineNumber() const;
+
+ ///
+ int getInteger() const;
+ ///
+ bool getBool() const;
+ ///
+ double getFloat() const;
+ ///
+ std::string const getString(bool trim = false) const;
+ ///
+ docstring const getDocString(bool trim = false) const;
+ /** Get a long string, ended by the tag `endtoken'. This string
+ can span several lines. The first line serves as a template
+ for what sequence of tabs and spaces make up the indentation.
+ This prefix is skipped from each following line.
+ */
+ docstring getLongString(docstring const & endtoken);
+
+ /// Pushes a token list on a stack and replaces it with a new one.
+ template<int N> void pushTable(LexerKeyword (&table)[N])
+ { pushTable(table, N); }
+
+ /** Pops a token list into void and replaces it with the one now
+ on top of the stack.
+ */
+ void popTable();
+
+ /** Prints an error message with the corresponding line number
+ and file name. If message contains the substring `$$Token',
+ it is replaced with the value of GetString()
+ */
+ void printError(std::string const & message) const;
+
+ /// Prints the current token table on the supplied ostream.
+ void printTable(std::ostream &);
+ /// Used to dispaly context information in case of errors.
+ void setContext(std::string const & functionName);
+
+ /// extract string
+ Lexer & operator>>(std::string &);
+ /// extract docstring
+ Lexer & operator>>(docstring &);
+ /// extract double
+ Lexer & operator>>(double &);
+ /// extract integer
+ Lexer & operator>>(int &);
+ /// extract unsigned integer
+ 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
+ static std::string quoteString(std::string const &);
+ /// Quotes a docstring so that reading it again with Lexer::next(true)
+ /// gets the original string
+ static docstring quoteString(docstring const &);
+
+private:
+ /// noncopyable
+ Lexer(Lexer const &);
+ void operator=(Lexer const &);
+
+ ///
+ friend class PushPopHelper;
+
+ ///
+ void init(LexerKeyword *, int);
+ void pushTable(LexerKeyword *, int);
+
+ ///
+ class Pimpl;
+ ///
+ Pimpl * pimpl_;
+ ///
+ mutable bool lastReadOk_;
+};
+
+
+/// extract something constructable from a string, i.e. a LaTeX length
+template <class T>
+Lexer & operator>>(Lexer & lex, T & t)
+{
+ if (lex.next())
+ t = T(lex.getString());
+ return lex;
+}
+
+
+/** Use to enable multiple exit points.
+ This is needed to ensure that the pop is done upon exit from methods
+ with more than one exit point or that can return as a response to
+ exceptions.
+ @author Lgb
+*/
+class PushPopHelper
+{
+public:
+ ///
+ template<int N>
+ PushPopHelper(Lexer & l, LexerKeyword (&table)[N])
+ : lex(l)
+ {
+ lex.pushTable(table, N);
+ }
+ ///
+ ~PushPopHelper()
+ {
+ lex.popTable();
+ }
+ ///
+ Lexer & lex;
+};
+/** Avoid wrong usage of PushPopHelper.
+ To avoid wrong usage:
+ PushPopHelper(...); // wrong
+ PushPopHelper pph(...); // right
+*/
+#define PushPopHelper(x, y, z) unnamed_PushPopHelper;
+// Tip gotten from Bobby Schmidt's column in C/C++ Users Journal
+
+} // namespace support
+
+} // namespace lyx
+
+#endif
Length.cpp \
Length.h \
lengthcommon.cpp \
+ Lexer.cpp \
+ Lexer.h \
limited_stack.h \
lstrings.cpp \
lstrings.h \
#include "Encoding.h"
#include "LaTeXPackages.h"
#include "LayoutFile.h"
-#include "Lexer.h"
#include "TextClass.h"
#include "version.h"
#include "support/convert.h"
#include "support/FileName.h"
#include "support/filetools.h"
+#include "support/Lexer.h"
#include "support/lstrings.h"
#include <algorithm>