2002-06-03 07:31:08 +00:00
|
|
|
|
/** The math parser
|
|
|
|
|
\author Andr<EFBFBD> P<EFBFBD>nitz (2001)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
|
/*
|
2001-10-29 15:45:24 +00:00
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
|
If someone desperately needs partial "structures" (such as a few
|
|
|
|
|
cells of an array inset or similar) (s)he could uses the
|
|
|
|
|
following hack as starting point to write some macros:
|
2001-10-29 15:45:24 +00:00
|
|
|
|
|
|
|
|
|
\newif\ifcomment
|
|
|
|
|
\commentfalse
|
|
|
|
|
\ifcomment
|
|
|
|
|
\def\makeamptab{\catcode`\&=4\relax}
|
|
|
|
|
\def\makeampletter{\catcode`\&=11\relax}
|
|
|
|
|
\def\b{\makeampletter\expandafter\makeamptab\bi}
|
|
|
|
|
\long\def\bi#1\e{}
|
|
|
|
|
\else
|
|
|
|
|
\def\b{}\def\e{}
|
|
|
|
|
\fi
|
|
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
\[\begin{array}{ccc}
|
2003-02-13 16:53:15 +00:00
|
|
|
|
1
|
|
|
|
|
&
|
|
|
|
|
|
2001-10-29 15:45:24 +00:00
|
|
|
|
\end{array}\]
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include <config.h>
|
2000-09-26 13:54:57 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
#include "math_parser.h"
|
|
|
|
|
#include "math_inset.h"
|
2001-07-17 07:38:41 +00:00
|
|
|
|
#include "math_arrayinset.h"
|
2001-10-29 15:45:24 +00:00
|
|
|
|
#include "math_braceinset.h"
|
2002-02-15 14:07:09 +00:00
|
|
|
|
#include "math_boxinset.h"
|
2001-08-09 09:19:18 +00:00
|
|
|
|
#include "math_charinset.h"
|
2002-08-14 15:13:07 +00:00
|
|
|
|
#include "math_commentinset.h"
|
2001-07-17 07:38:41 +00:00
|
|
|
|
#include "math_deliminset.h"
|
2002-07-09 09:46:31 +00:00
|
|
|
|
#include "math_envinset.h"
|
2002-06-18 15:44:30 +00:00
|
|
|
|
#include "math_extern.h"
|
2001-08-13 14:02:37 +00:00
|
|
|
|
#include "math_factory.h"
|
2001-08-21 14:20:50 +00:00
|
|
|
|
#include "math_kerninset.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "math_macro.h"
|
2001-02-13 17:08:51 +00:00
|
|
|
|
#include "math_macrotemplate.h"
|
2001-11-08 12:28:33 +00:00
|
|
|
|
#include "math_hullinset.h"
|
2002-07-08 11:29:51 +00:00
|
|
|
|
#include "math_parboxinset.h"
|
|
|
|
|
#include "math_parinset.h"
|
2001-07-17 07:38:41 +00:00
|
|
|
|
#include "math_rootinset.h"
|
2001-07-12 07:18:29 +00:00
|
|
|
|
#include "math_scriptinset.h"
|
2002-08-08 14:22:44 +00:00
|
|
|
|
#include "math_sizeinset.h"
|
2001-07-17 07:38:41 +00:00
|
|
|
|
#include "math_sqrtinset.h"
|
2002-08-08 14:22:44 +00:00
|
|
|
|
#include "math_stringinset.h"
|
2001-11-08 12:15:12 +00:00
|
|
|
|
#include "math_support.h"
|
2002-02-11 08:19:02 +00:00
|
|
|
|
#include "math_xyarrowinset.h"
|
2001-12-18 03:16:46 +00:00
|
|
|
|
|
2002-07-08 06:39:40 +00:00
|
|
|
|
//#include "insets/insetref.h"
|
2002-06-24 15:51:35 +00:00
|
|
|
|
#include "ref_inset.h"
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
#include "lyxlex.h"
|
2001-11-08 12:55:58 +00:00
|
|
|
|
#include "debug.h"
|
2002-02-15 14:07:09 +00:00
|
|
|
|
#include "support/LAssert.h"
|
2001-07-29 17:39:01 +00:00
|
|
|
|
#include "support/lstrings.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-12-18 03:16:46 +00:00
|
|
|
|
#include <cctype>
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
|
using std::istream;
|
2001-08-17 11:08:55 +00:00
|
|
|
|
using std::ostream;
|
|
|
|
|
using std::ios;
|
2000-03-28 02:18:55 +00:00
|
|
|
|
using std::endl;
|
2001-12-18 03:16:46 +00:00
|
|
|
|
using std::fill;
|
2002-02-16 15:59:55 +00:00
|
|
|
|
using std::vector;
|
2002-05-28 11:13:01 +00:00
|
|
|
|
using std::atoi;
|
2000-03-28 02:18:55 +00:00
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
|
|
2002-02-15 14:07:09 +00:00
|
|
|
|
//#define FILEDEBUG
|
|
|
|
|
|
2000-11-02 04:48:34 +00:00
|
|
|
|
|
2001-08-10 07:52:04 +00:00
|
|
|
|
namespace {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2002-10-15 08:41:35 +00:00
|
|
|
|
MathInset::mode_type asMode(MathInset::mode_type oldmode, string const & str)
|
2002-08-08 14:22:44 +00:00
|
|
|
|
{
|
|
|
|
|
if (str == "mathmode")
|
|
|
|
|
return MathInset::MATH_MODE;
|
|
|
|
|
if (str == "textmode" || str == "forcetext")
|
|
|
|
|
return MathInset::TEXT_MODE;
|
2002-10-15 08:41:35 +00:00
|
|
|
|
return oldmode;
|
2002-08-08 14:22:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
bool stared(string const & s)
|
|
|
|
|
{
|
2002-01-08 13:31:14 +00:00
|
|
|
|
string::size_type const n = s.size();
|
2001-08-17 09:48:24 +00:00
|
|
|
|
return n && s[n - 1] == '*';
|
|
|
|
|
}
|
|
|
|
|
|
2001-08-10 09:30:02 +00:00
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
// These are TeX's catcodes
|
|
|
|
|
enum CatCode {
|
2002-03-21 17:42:56 +00:00
|
|
|
|
catEscape, // 0 backslash
|
2001-08-17 09:48:24 +00:00
|
|
|
|
catBegin, // 1 {
|
|
|
|
|
catEnd, // 2 }
|
|
|
|
|
catMath, // 3 $
|
|
|
|
|
catAlign, // 4 &
|
|
|
|
|
catNewline, // 5 ^^M
|
|
|
|
|
catParameter, // 6 #
|
|
|
|
|
catSuper, // 7 ^
|
|
|
|
|
catSub, // 8 _
|
2002-03-21 17:42:56 +00:00
|
|
|
|
catIgnore, // 9
|
2001-08-17 09:48:24 +00:00
|
|
|
|
catSpace, // 10 space
|
|
|
|
|
catLetter, // 11 a-zA-Z
|
|
|
|
|
catOther, // 12 none of the above
|
|
|
|
|
catActive, // 13 ~
|
|
|
|
|
catComment, // 14 %
|
|
|
|
|
catInvalid // 15 <delete>
|
2001-06-25 00:06:33 +00:00
|
|
|
|
};
|
|
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
|
CatCode theCatcode[256];
|
2001-08-17 10:21:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline CatCode catcode(unsigned char c)
|
|
|
|
|
{
|
|
|
|
|
return theCatcode[c];
|
|
|
|
|
}
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
enum {
|
2002-06-18 15:44:30 +00:00
|
|
|
|
FLAG_BRACE_LAST = 1 << 1, // last closing brace ends the parsing
|
2001-08-17 09:48:24 +00:00
|
|
|
|
FLAG_RIGHT = 1 << 2, // next \\right ends the parsing process
|
|
|
|
|
FLAG_END = 1 << 3, // next \\end ends the parsing process
|
2002-07-08 11:29:51 +00:00
|
|
|
|
FLAG_BRACK_LAST = 1 << 4, // next closing bracket ends the parsing
|
2002-06-18 15:44:30 +00:00
|
|
|
|
FLAG_TEXTMODE = 1 << 5, // we are in a box
|
2002-02-04 18:44:51 +00:00
|
|
|
|
FLAG_ITEM = 1 << 6, // read a (possibly braced token)
|
2002-06-18 15:44:30 +00:00
|
|
|
|
FLAG_LEAVE = 1 << 7, // leave the loop at the end
|
|
|
|
|
FLAG_SIMPLE = 1 << 8, // next $ leaves the loop
|
|
|
|
|
FLAG_EQUATION = 1 << 9, // next \] leaves the loop
|
2002-07-08 11:29:51 +00:00
|
|
|
|
FLAG_SIMPLE2 = 1 << 10, // next \) leaves the loop
|
2002-08-12 09:53:04 +00:00
|
|
|
|
FLAG_OPTION = 1 << 11, // read [...] style option
|
|
|
|
|
FLAG_BRACED = 1 << 12 // read {...} style argument
|
1999-09-27 18:44:28 +00:00
|
|
|
|
};
|
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
void catInit()
|
|
|
|
|
{
|
2001-12-18 03:16:46 +00:00
|
|
|
|
fill(theCatcode, theCatcode + 256, catOther);
|
|
|
|
|
fill(theCatcode + 'a', theCatcode + 'z' + 1, catLetter);
|
|
|
|
|
fill(theCatcode + 'A', theCatcode + 'Z' + 1, catLetter);
|
2001-08-17 10:21:37 +00:00
|
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
|
theCatcode['\\'] = catEscape;
|
|
|
|
|
theCatcode['{'] = catBegin;
|
|
|
|
|
theCatcode['}'] = catEnd;
|
|
|
|
|
theCatcode['$'] = catMath;
|
|
|
|
|
theCatcode['&'] = catAlign;
|
|
|
|
|
theCatcode['\n'] = catNewline;
|
|
|
|
|
theCatcode['#'] = catParameter;
|
|
|
|
|
theCatcode['^'] = catSuper;
|
|
|
|
|
theCatcode['_'] = catSub;
|
|
|
|
|
theCatcode[''] = catIgnore;
|
|
|
|
|
theCatcode[' '] = catSpace;
|
|
|
|
|
theCatcode['\t'] = catSpace;
|
2002-07-31 17:26:14 +00:00
|
|
|
|
theCatcode['\r'] = catNewline;
|
2002-03-21 17:42:56 +00:00
|
|
|
|
theCatcode['~'] = catActive;
|
|
|
|
|
theCatcode['%'] = catComment;
|
2001-08-17 09:48:24 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
2001-02-26 12:53:35 +00:00
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
//
|
|
|
|
|
// Helper class for parsing
|
|
|
|
|
//
|
2001-02-26 12:53:35 +00:00
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
class Token {
|
|
|
|
|
public:
|
|
|
|
|
///
|
|
|
|
|
Token() : cs_(), char_(0), cat_(catIgnore) {}
|
|
|
|
|
///
|
|
|
|
|
Token(char c, CatCode cat) : cs_(), char_(c), cat_(cat) {}
|
|
|
|
|
///
|
2001-12-18 03:16:46 +00:00
|
|
|
|
Token(string const & cs) : cs_(cs), char_(0), cat_(catIgnore) {}
|
2001-02-26 12:53:35 +00:00
|
|
|
|
|
2001-08-17 10:51:50 +00:00
|
|
|
|
///
|
2001-08-17 09:48:24 +00:00
|
|
|
|
string const & cs() const { return cs_; }
|
|
|
|
|
///
|
|
|
|
|
CatCode cat() const { return cat_; }
|
|
|
|
|
///
|
|
|
|
|
char character() const { return char_; }
|
|
|
|
|
///
|
2002-08-08 14:22:44 +00:00
|
|
|
|
string asString() const { return cs_.size() ? cs_ : string(1, char_); }
|
2001-08-13 14:02:37 +00:00
|
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
|
private:
|
2001-08-17 09:48:24 +00:00
|
|
|
|
///
|
|
|
|
|
string cs_;
|
|
|
|
|
///
|
|
|
|
|
char char_;
|
|
|
|
|
///
|
|
|
|
|
CatCode cat_;
|
|
|
|
|
};
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
ostream & operator<<(ostream & os, Token const & t)
|
|
|
|
|
{
|
|
|
|
|
if (t.cs().size())
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << '\\' << t.cs();
|
2001-08-17 09:48:24 +00:00
|
|
|
|
else
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << '[' << t.character() << ',' << t.cat() << ']';
|
2001-08-17 09:48:24 +00:00
|
|
|
|
return os;
|
|
|
|
|
}
|
2001-08-10 09:30:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Parser {
|
2001-08-17 09:48:24 +00:00
|
|
|
|
|
2001-08-10 09:30:02 +00:00
|
|
|
|
public:
|
2002-08-08 14:22:44 +00:00
|
|
|
|
///
|
|
|
|
|
typedef MathInset::mode_type mode_type;
|
|
|
|
|
|
2001-08-10 09:30:02 +00:00
|
|
|
|
///
|
2001-08-17 09:48:24 +00:00
|
|
|
|
Parser(LyXLex & lex);
|
2001-08-10 09:30:02 +00:00
|
|
|
|
///
|
2001-08-17 09:48:24 +00:00
|
|
|
|
Parser(istream & is);
|
2001-08-10 09:30:02 +00:00
|
|
|
|
|
|
|
|
|
///
|
2002-07-12 14:24:47 +00:00
|
|
|
|
bool parse(MathAtom & at);
|
2001-08-10 09:30:02 +00:00
|
|
|
|
///
|
2002-08-08 14:22:44 +00:00
|
|
|
|
void parse(MathArray & array, unsigned flags, mode_type mode);
|
2001-08-10 09:30:02 +00:00
|
|
|
|
///
|
2002-08-14 16:11:55 +00:00
|
|
|
|
void parse1(MathGridInset & grid, unsigned flags, mode_type mode,
|
|
|
|
|
bool numbered);
|
|
|
|
|
///
|
2002-08-12 09:53:04 +00:00
|
|
|
|
MathArray parse(unsigned flags, mode_type mode);
|
|
|
|
|
///
|
2001-08-10 09:30:02 +00:00
|
|
|
|
int lineno() const { return lineno_; }
|
2001-08-13 14:46:06 +00:00
|
|
|
|
///
|
2001-08-17 09:48:24 +00:00
|
|
|
|
void putback();
|
2001-08-10 09:30:02 +00:00
|
|
|
|
|
|
|
|
|
private:
|
2002-02-07 09:47:21 +00:00
|
|
|
|
///
|
2002-08-08 14:22:44 +00:00
|
|
|
|
void parse2(MathAtom & at, unsigned flags, mode_type mode, bool numbered);
|
2002-05-30 07:09:54 +00:00
|
|
|
|
/// get arg delimited by 'left' and 'right'
|
|
|
|
|
string getArg(char left, char right);
|
2001-08-10 09:30:02 +00:00
|
|
|
|
///
|
2001-08-17 09:48:24 +00:00
|
|
|
|
char getChar();
|
2001-08-10 09:30:02 +00:00
|
|
|
|
///
|
|
|
|
|
void error(string const & msg);
|
2002-02-11 08:19:02 +00:00
|
|
|
|
/// dump contents to screen
|
|
|
|
|
void dump() const;
|
2001-08-10 09:30:02 +00:00
|
|
|
|
///
|
2001-08-17 09:48:24 +00:00
|
|
|
|
void tokenize(istream & is);
|
2001-08-10 09:30:02 +00:00
|
|
|
|
///
|
2001-08-17 09:48:24 +00:00
|
|
|
|
void tokenize(string const & s);
|
|
|
|
|
///
|
2002-02-12 09:11:50 +00:00
|
|
|
|
void skipSpaceTokens(istream & is, char c);
|
|
|
|
|
///
|
2001-08-17 09:48:24 +00:00
|
|
|
|
void push_back(Token const & t);
|
|
|
|
|
///
|
|
|
|
|
void pop_back();
|
2001-08-10 09:30:02 +00:00
|
|
|
|
///
|
2001-08-17 09:48:24 +00:00
|
|
|
|
Token const & prevToken() const;
|
2001-08-10 09:30:02 +00:00
|
|
|
|
///
|
2001-08-17 09:48:24 +00:00
|
|
|
|
Token const & nextToken() const;
|
2001-08-10 09:30:02 +00:00
|
|
|
|
///
|
2001-08-17 09:48:24 +00:00
|
|
|
|
Token const & getToken();
|
2001-11-28 13:09:40 +00:00
|
|
|
|
/// skips spaces if any
|
|
|
|
|
void skipSpaces();
|
2001-08-17 09:48:24 +00:00
|
|
|
|
///
|
|
|
|
|
void lex(string const & s);
|
|
|
|
|
///
|
|
|
|
|
bool good() const;
|
2002-09-30 06:48:53 +00:00
|
|
|
|
///
|
|
|
|
|
string parse_verbatim_item();
|
|
|
|
|
///
|
|
|
|
|
string parse_verbatim_option();
|
2001-08-10 09:30:02 +00:00
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
///
|
|
|
|
|
int lineno_;
|
|
|
|
|
///
|
2002-02-16 15:59:55 +00:00
|
|
|
|
vector<Token> tokens_;
|
2001-08-17 09:48:24 +00:00
|
|
|
|
///
|
|
|
|
|
unsigned pos_;
|
2001-08-10 09:30:02 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
Parser::Parser(LyXLex & lexer)
|
2002-06-03 07:31:08 +00:00
|
|
|
|
: lineno_(lexer.getLineNo()), pos_(0)
|
2001-08-13 14:46:06 +00:00
|
|
|
|
{
|
2001-08-17 09:48:24 +00:00
|
|
|
|
tokenize(lexer.getStream());
|
2001-08-18 12:02:40 +00:00
|
|
|
|
lexer.eatLine();
|
2001-08-13 14:46:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
Parser::Parser(istream & is)
|
2002-06-03 07:31:08 +00:00
|
|
|
|
: lineno_(0), pos_(0)
|
2001-08-10 09:30:02 +00:00
|
|
|
|
{
|
2001-08-17 09:48:24 +00:00
|
|
|
|
tokenize(is);
|
2001-08-10 09:30:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
void Parser::push_back(Token const & t)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-08-17 09:48:24 +00:00
|
|
|
|
tokens_.push_back(t);
|
|
|
|
|
}
|
2001-07-13 07:55:55 +00:00
|
|
|
|
|
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
void Parser::pop_back()
|
|
|
|
|
{
|
|
|
|
|
tokens_.pop_back();
|
|
|
|
|
}
|
2001-07-13 07:55:55 +00:00
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
|
|
|
|
|
Token const & Parser::prevToken() const
|
|
|
|
|
{
|
|
|
|
|
static const Token dummy;
|
|
|
|
|
return pos_ > 0 ? tokens_[pos_ - 1] : dummy;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-11-15 11:06:41 +00:00
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
Token const & Parser::nextToken() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-08-17 09:48:24 +00:00
|
|
|
|
static const Token dummy;
|
|
|
|
|
return good() ? tokens_[pos_] : dummy;
|
|
|
|
|
}
|
2001-08-13 14:46:06 +00:00
|
|
|
|
|
2001-08-14 07:46:11 +00:00
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
Token const & Parser::getToken()
|
|
|
|
|
{
|
|
|
|
|
static const Token dummy;
|
2002-02-11 15:55:13 +00:00
|
|
|
|
//lyxerr << "looking at token " << tokens_[pos_] << " pos: " << pos_ << '\n';
|
2001-08-17 09:48:24 +00:00
|
|
|
|
return good() ? tokens_[pos_++] : dummy;
|
|
|
|
|
}
|
2001-08-14 07:46:11 +00:00
|
|
|
|
|
2001-08-13 14:46:06 +00:00
|
|
|
|
|
2001-11-28 13:09:40 +00:00
|
|
|
|
void Parser::skipSpaces()
|
|
|
|
|
{
|
2002-08-02 07:50:01 +00:00
|
|
|
|
while (nextToken().cat() == catSpace || nextToken().cat() == catNewline)
|
2001-11-28 13:09:40 +00:00
|
|
|
|
getToken();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
void Parser::putback()
|
|
|
|
|
{
|
|
|
|
|
--pos_;
|
|
|
|
|
}
|
2001-08-13 14:46:06 +00:00
|
|
|
|
|
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
bool Parser::good() const
|
|
|
|
|
{
|
|
|
|
|
return pos_ < tokens_.size();
|
|
|
|
|
}
|
2001-08-13 14:46:06 +00:00
|
|
|
|
|
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
char Parser::getChar()
|
|
|
|
|
{
|
2002-06-24 15:37:14 +00:00
|
|
|
|
if (!good())
|
|
|
|
|
error("The input stream is not well...");
|
2001-08-17 09:48:24 +00:00
|
|
|
|
return tokens_[pos_++].character();
|
|
|
|
|
}
|
|
|
|
|
|
2001-08-13 14:46:06 +00:00
|
|
|
|
|
2002-03-27 16:13:52 +00:00
|
|
|
|
string Parser::getArg(char left, char right)
|
2001-08-17 09:48:24 +00:00
|
|
|
|
{
|
2002-02-11 08:19:02 +00:00
|
|
|
|
skipSpaces();
|
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
string result;
|
|
|
|
|
char c = getChar();
|
2001-08-13 14:46:06 +00:00
|
|
|
|
|
2002-03-27 16:13:52 +00:00
|
|
|
|
if (c != left)
|
2001-08-17 09:48:24 +00:00
|
|
|
|
putback();
|
2002-03-21 17:42:56 +00:00
|
|
|
|
else
|
2002-03-27 16:13:52 +00:00
|
|
|
|
while ((c = getChar()) != right && good())
|
2001-08-17 09:48:24 +00:00
|
|
|
|
result += c;
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-31 17:26:14 +00:00
|
|
|
|
void Parser::skipSpaceTokens(istream & is, char c)
|
|
|
|
|
{
|
|
|
|
|
// skip trailing spaces
|
|
|
|
|
while (catcode(c) == catSpace || catcode(c) == catNewline)
|
|
|
|
|
if (!is.get(c))
|
|
|
|
|
break;
|
|
|
|
|
//lyxerr << "putting back: " << c << "\n";
|
|
|
|
|
is.putback(c);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
void Parser::tokenize(istream & is)
|
|
|
|
|
{
|
|
|
|
|
// eat everything up to the next \end_inset or end of stream
|
|
|
|
|
// and store it in s for further tokenization
|
|
|
|
|
string s;
|
|
|
|
|
char c;
|
|
|
|
|
while (is.get(c)) {
|
|
|
|
|
s += c;
|
|
|
|
|
if (s.size() >= 10 && s.substr(s.size() - 10) == "\\end_inset") {
|
|
|
|
|
s = s.substr(0, s.size() - 10);
|
|
|
|
|
break;
|
2001-08-13 14:46:06 +00:00
|
|
|
|
}
|
2001-08-17 09:48:24 +00:00
|
|
|
|
}
|
2002-12-18 10:57:45 +00:00
|
|
|
|
// Remove the space after \end_inset
|
|
|
|
|
if (is.get(c) && c != ' ')
|
|
|
|
|
is.unget();
|
2001-08-13 14:46:06 +00:00
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
// tokenize buffer
|
|
|
|
|
tokenize(s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Parser::tokenize(string const & buffer)
|
|
|
|
|
{
|
|
|
|
|
static bool init_done = false;
|
2002-03-21 17:42:56 +00:00
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
if (!init_done) {
|
|
|
|
|
catInit();
|
|
|
|
|
init_done = true;
|
|
|
|
|
}
|
|
|
|
|
|
2001-09-05 15:22:20 +00:00
|
|
|
|
istringstream is(buffer.c_str(), ios::in | ios::binary);
|
2001-08-17 09:48:24 +00:00
|
|
|
|
|
2001-08-17 10:21:37 +00:00
|
|
|
|
char c;
|
2001-08-17 09:48:24 +00:00
|
|
|
|
while (is.get(c)) {
|
2002-05-28 11:13:01 +00:00
|
|
|
|
//lyxerr << "reading c: " << c << "\n";
|
2001-08-17 09:48:24 +00:00
|
|
|
|
|
2001-08-17 10:21:37 +00:00
|
|
|
|
switch (catcode(c)) {
|
2001-08-17 09:48:24 +00:00
|
|
|
|
case catNewline: {
|
2002-03-21 17:42:56 +00:00
|
|
|
|
++lineno_;
|
2001-08-17 09:48:24 +00:00
|
|
|
|
is.get(c);
|
2001-08-17 10:21:37 +00:00
|
|
|
|
if (catcode(c) == catNewline)
|
2001-08-17 09:48:24 +00:00
|
|
|
|
; //push_back(Token("par"));
|
|
|
|
|
else {
|
2002-07-31 17:26:14 +00:00
|
|
|
|
push_back(Token('\n', catNewline));
|
2002-03-21 17:42:56 +00:00
|
|
|
|
is.putback(c);
|
2001-08-13 14:02:37 +00:00
|
|
|
|
}
|
2001-08-17 09:48:24 +00:00
|
|
|
|
break;
|
2001-02-26 12:53:35 +00:00
|
|
|
|
}
|
2001-08-17 09:48:24 +00:00
|
|
|
|
|
2002-08-14 15:13:07 +00:00
|
|
|
|
/*
|
2001-08-17 09:48:24 +00:00
|
|
|
|
case catComment: {
|
2001-08-17 10:21:37 +00:00
|
|
|
|
while (is.get(c) && catcode(c) != catNewline)
|
2001-08-17 09:48:24 +00:00
|
|
|
|
;
|
2002-03-21 17:42:56 +00:00
|
|
|
|
++lineno_;
|
2001-08-17 09:48:24 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2002-08-14 15:13:07 +00:00
|
|
|
|
*/
|
2001-08-17 09:48:24 +00:00
|
|
|
|
|
|
|
|
|
case catEscape: {
|
|
|
|
|
is.get(c);
|
2002-02-11 15:55:13 +00:00
|
|
|
|
if (!is) {
|
|
|
|
|
error("unexpected end of input");
|
|
|
|
|
} else {
|
|
|
|
|
string s(1, c);
|
|
|
|
|
if (catcode(c) == catLetter) {
|
2002-02-12 09:11:50 +00:00
|
|
|
|
// collect letters
|
2002-02-11 15:55:13 +00:00
|
|
|
|
while (is.get(c) && catcode(c) == catLetter)
|
|
|
|
|
s += c;
|
2002-02-12 09:11:50 +00:00
|
|
|
|
skipSpaceTokens(is, c);
|
2002-03-21 17:42:56 +00:00
|
|
|
|
}
|
2002-02-11 15:55:13 +00:00
|
|
|
|
push_back(Token(s));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2002-02-12 09:11:50 +00:00
|
|
|
|
case catSuper:
|
|
|
|
|
case catSub: {
|
|
|
|
|
push_back(Token(c, catcode(c)));
|
|
|
|
|
is.get(c);
|
|
|
|
|
skipSpaceTokens(is, c);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2002-02-11 15:55:13 +00:00
|
|
|
|
case catIgnore: {
|
|
|
|
|
lyxerr << "ignoring a char: " << int(c) << "\n";
|
2001-08-17 09:48:24 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
2001-08-17 10:21:37 +00:00
|
|
|
|
push_back(Token(c, catcode(c)));
|
2001-02-26 12:53:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-08-17 09:48:24 +00:00
|
|
|
|
|
2002-02-15 14:07:09 +00:00
|
|
|
|
#ifdef FILEDEBUG
|
|
|
|
|
dump();
|
|
|
|
|
#endif
|
2002-02-11 08:19:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Parser::dump() const
|
|
|
|
|
{
|
2001-08-17 15:47:02 +00:00
|
|
|
|
lyxerr << "\nTokens: ";
|
2002-03-27 16:13:52 +00:00
|
|
|
|
for (unsigned i = 0; i < tokens_.size(); ++i) {
|
|
|
|
|
if (i == pos_)
|
|
|
|
|
lyxerr << " <#> ";
|
2001-08-17 15:47:02 +00:00
|
|
|
|
lyxerr << tokens_[i];
|
2002-03-27 16:13:52 +00:00
|
|
|
|
}
|
2002-06-05 07:54:26 +00:00
|
|
|
|
lyxerr << " pos: " << pos_ << "\n";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-21 17:42:56 +00:00
|
|
|
|
void Parser::error(string const & msg)
|
2001-07-26 06:46:50 +00:00
|
|
|
|
{
|
2001-08-10 09:30:02 +00:00
|
|
|
|
lyxerr << "Line ~" << lineno_ << ": Math parse error: " << msg << endl;
|
2002-02-11 08:19:02 +00:00
|
|
|
|
dump();
|
2001-09-12 09:17:46 +00:00
|
|
|
|
//exit(1);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-07-12 07:18:29 +00:00
|
|
|
|
|
2002-07-12 14:24:47 +00:00
|
|
|
|
bool Parser::parse(MathAtom & at)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2002-06-28 12:33:21 +00:00
|
|
|
|
skipSpaces();
|
2002-06-24 15:37:14 +00:00
|
|
|
|
MathArray ar;
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse(ar, false, MathInset::UNDECIDED_MODE);
|
2002-07-08 06:39:40 +00:00
|
|
|
|
if (ar.size() != 1 || ar.front()->getType() == "none") {
|
|
|
|
|
lyxerr << "unusual contents found: " << ar << endl;
|
2002-08-23 11:24:55 +00:00
|
|
|
|
at = MathAtom(new MathParInset(ar));
|
|
|
|
|
//if (at->nargs() > 0)
|
|
|
|
|
// at.nucleus()->cell(0) = ar;
|
|
|
|
|
//else
|
|
|
|
|
// lyxerr << "unusual contents found: " << ar << endl;
|
2001-10-15 14:19:16 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2002-06-24 15:37:14 +00:00
|
|
|
|
at = ar[0];
|
|
|
|
|
return true;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-09-30 06:48:53 +00:00
|
|
|
|
string Parser::parse_verbatim_option()
|
|
|
|
|
{
|
|
|
|
|
string res;
|
|
|
|
|
if (nextToken().character() == '[') {
|
|
|
|
|
Token t = getToken();
|
|
|
|
|
for (Token t = getToken(); t.character() != ']' && good(); t = getToken()) {
|
|
|
|
|
if (t.cat() == catBegin) {
|
|
|
|
|
putback();
|
|
|
|
|
res += '{' + parse_verbatim_item() + '}';
|
2002-11-24 15:20:31 +00:00
|
|
|
|
} else
|
2002-09-30 06:48:53 +00:00
|
|
|
|
res += t.asString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string Parser::parse_verbatim_item()
|
|
|
|
|
{
|
|
|
|
|
string res;
|
|
|
|
|
if (nextToken().cat() == catBegin) {
|
|
|
|
|
Token t = getToken();
|
|
|
|
|
for (Token t = getToken(); t.cat() != catEnd && good(); t = getToken()) {
|
|
|
|
|
if (t.cat() == catBegin) {
|
|
|
|
|
putback();
|
|
|
|
|
res += '{' + parse_verbatim_item() + '}';
|
|
|
|
|
}
|
2002-11-24 15:20:31 +00:00
|
|
|
|
else
|
2002-09-30 06:48:53 +00:00
|
|
|
|
res += t.asString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-12 09:53:04 +00:00
|
|
|
|
MathArray Parser::parse(unsigned flags, mode_type mode)
|
|
|
|
|
{
|
|
|
|
|
MathArray ar;
|
|
|
|
|
parse(ar, flags, mode);
|
|
|
|
|
return ar;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-08 14:22:44 +00:00
|
|
|
|
void Parser::parse(MathArray & array, unsigned flags, mode_type mode)
|
2002-02-07 09:47:21 +00:00
|
|
|
|
{
|
2002-06-03 07:31:08 +00:00
|
|
|
|
MathGridInset grid(1, 1);
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse1(grid, flags, mode, false);
|
2002-06-03 07:31:08 +00:00
|
|
|
|
array = grid.cell(0);
|
2002-02-07 09:47:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-08 14:22:44 +00:00
|
|
|
|
void Parser::parse2(MathAtom & at, unsigned flags, mode_type mode,
|
|
|
|
|
bool numbered)
|
2002-06-03 07:31:08 +00:00
|
|
|
|
{
|
2002-08-09 07:01:17 +00:00
|
|
|
|
parse1(*(at.nucleus()->asGridInset()), flags, mode, numbered);
|
2002-06-03 07:31:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-12 14:24:47 +00:00
|
|
|
|
void Parser::parse1(MathGridInset & grid, unsigned flags,
|
2002-08-08 14:22:44 +00:00
|
|
|
|
mode_type mode, bool numbered)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{
|
2002-08-28 17:59:32 +00:00
|
|
|
|
int limits = 0;
|
2002-06-03 07:31:08 +00:00
|
|
|
|
MathGridInset::row_type cellrow = 0;
|
|
|
|
|
MathGridInset::col_type cellcol = 0;
|
|
|
|
|
MathArray * cell = &grid.cell(grid.index(cellrow, cellcol));
|
|
|
|
|
|
|
|
|
|
if (grid.asHullInset())
|
|
|
|
|
grid.asHullInset()->numbered(cellrow, numbered);
|
|
|
|
|
|
|
|
|
|
//dump();
|
|
|
|
|
//lyxerr << "grid: " << grid << endl;
|
2001-07-27 12:32:29 +00:00
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
while (good()) {
|
|
|
|
|
Token const & t = getToken();
|
2002-03-21 17:42:56 +00:00
|
|
|
|
|
2002-02-15 14:07:09 +00:00
|
|
|
|
#ifdef FILEDEBUG
|
|
|
|
|
lyxerr << "t: " << t << " flags: " << flags << "\n";
|
2002-08-14 15:13:07 +00:00
|
|
|
|
cell->dump();
|
2002-02-15 14:07:09 +00:00
|
|
|
|
lyxerr << "\n";
|
|
|
|
|
#endif
|
2001-04-24 16:13:38 +00:00
|
|
|
|
|
2001-07-13 07:55:55 +00:00
|
|
|
|
if (flags & FLAG_ITEM) {
|
2002-03-07 17:34:51 +00:00
|
|
|
|
if (t.cat() == catSpace)
|
|
|
|
|
continue;
|
|
|
|
|
|
2001-07-13 07:55:55 +00:00
|
|
|
|
flags &= ~FLAG_ITEM;
|
2002-03-21 17:42:56 +00:00
|
|
|
|
if (t.cat() == catBegin) {
|
2001-08-10 15:49:15 +00:00
|
|
|
|
// skip the brace and collect everything to the next matching
|
2001-07-13 07:55:55 +00:00
|
|
|
|
// closing brace
|
|
|
|
|
flags |= FLAG_BRACE_LAST;
|
2001-08-14 07:46:11 +00:00
|
|
|
|
continue;
|
2001-02-26 12:53:35 +00:00
|
|
|
|
}
|
2002-03-07 17:34:51 +00:00
|
|
|
|
|
|
|
|
|
// handle only this single token, leave the loop if done
|
|
|
|
|
flags |= FLAG_LEAVE;
|
2001-02-26 12:53:35 +00:00
|
|
|
|
}
|
2001-04-25 15:43:57 +00:00
|
|
|
|
|
2002-07-08 11:29:51 +00:00
|
|
|
|
|
2002-08-12 09:53:04 +00:00
|
|
|
|
if (flags & FLAG_BRACED) {
|
|
|
|
|
if (t.cat() == catSpace)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (t.cat() != catBegin) {
|
|
|
|
|
error("opening brace expected");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// skip the brace and collect everything to the next matching
|
|
|
|
|
// closing brace
|
|
|
|
|
flags = FLAG_BRACE_LAST;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-08 11:29:51 +00:00
|
|
|
|
if (flags & FLAG_OPTION) {
|
|
|
|
|
if (t.cat() == catOther && t.character() == '[') {
|
2002-08-05 06:39:33 +00:00
|
|
|
|
MathArray ar;
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse(ar, FLAG_BRACK_LAST, mode);
|
2002-08-05 06:39:33 +00:00
|
|
|
|
cell->append(ar);
|
|
|
|
|
} else {
|
|
|
|
|
// no option found, put back token and we are done
|
|
|
|
|
putback();
|
2002-07-08 11:29:51 +00:00
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
//
|
|
|
|
|
// cat codes
|
|
|
|
|
//
|
2001-12-18 12:21:33 +00:00
|
|
|
|
if (t.cat() == catMath) {
|
2002-08-08 14:22:44 +00:00
|
|
|
|
if (mode != MathInset::MATH_MODE) {
|
2002-06-04 09:45:41 +00:00
|
|
|
|
// we are inside some text mode thingy, so opening new math is allowed
|
2002-06-24 15:37:14 +00:00
|
|
|
|
Token const & n = getToken();
|
|
|
|
|
if (n.cat() == catMath) {
|
|
|
|
|
// TeX's $$...$$ syntax for displayed math
|
2002-07-03 10:36:44 +00:00
|
|
|
|
cell->push_back(MathAtom(new MathHullInset("equation")));
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse2(cell->back(), FLAG_SIMPLE, MathInset::MATH_MODE, false);
|
2002-06-24 15:37:14 +00:00
|
|
|
|
getToken(); // skip the second '$' token
|
|
|
|
|
} else {
|
|
|
|
|
// simple $...$ stuff
|
|
|
|
|
putback();
|
2002-07-03 10:36:44 +00:00
|
|
|
|
cell->push_back(MathAtom(new MathHullInset("simple")));
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse2(cell->back(), FLAG_SIMPLE, MathInset::MATH_MODE, false);
|
2002-06-24 15:37:14 +00:00
|
|
|
|
}
|
2002-06-04 09:45:41 +00:00
|
|
|
|
}
|
2002-06-24 15:37:14 +00:00
|
|
|
|
|
2002-06-05 07:54:26 +00:00
|
|
|
|
else if (flags & FLAG_SIMPLE) {
|
2002-06-03 07:31:08 +00:00
|
|
|
|
// this is the end of the formula
|
|
|
|
|
return;
|
|
|
|
|
}
|
2002-06-24 15:37:14 +00:00
|
|
|
|
|
2002-06-05 07:54:26 +00:00
|
|
|
|
else {
|
2002-06-24 15:37:14 +00:00
|
|
|
|
error("something strange in the parser\n");
|
2002-06-05 07:54:26 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2001-12-18 12:21:33 +00:00
|
|
|
|
}
|
2001-08-13 14:46:06 +00:00
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
else if (t.cat() == catLetter)
|
2002-06-24 15:37:14 +00:00
|
|
|
|
cell->push_back(MathAtom(new MathCharInset(t.character())));
|
2001-08-13 14:02:37 +00:00
|
|
|
|
|
2002-08-22 10:04:11 +00:00
|
|
|
|
else if (t.cat() == catSpace && mode != MathInset::MATH_MODE) {
|
|
|
|
|
if (cell->empty() || cell->back()->getChar() != ' ')
|
|
|
|
|
cell->push_back(MathAtom(new MathCharInset(t.character())));
|
|
|
|
|
}
|
2001-02-26 12:53:35 +00:00
|
|
|
|
|
2002-08-08 14:22:44 +00:00
|
|
|
|
else if (t.cat() == catNewline && mode != MathInset::MATH_MODE)
|
2002-07-31 17:26:14 +00:00
|
|
|
|
cell->push_back(MathAtom(new MathCharInset(t.character())));
|
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
else if (t.cat() == catParameter) {
|
|
|
|
|
Token const & n = getToken();
|
2002-06-03 07:31:08 +00:00
|
|
|
|
cell->push_back(MathAtom(new MathMacroArgument(n.character()-'0')));
|
2001-08-03 09:54:48 +00:00
|
|
|
|
}
|
2001-02-26 12:53:35 +00:00
|
|
|
|
|
2002-08-06 09:15:46 +00:00
|
|
|
|
else if (t.cat() == catActive)
|
|
|
|
|
cell->push_back(MathAtom(new MathCharInset(t.character())));
|
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
else if (t.cat() == catBegin) {
|
2001-10-31 15:14:22 +00:00
|
|
|
|
MathArray ar;
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse(ar, FLAG_BRACE_LAST, mode);
|
2002-07-10 07:15:36 +00:00
|
|
|
|
// do not create a BraceInset if they were written by LyX
|
2002-07-04 11:00:51 +00:00
|
|
|
|
// this helps to keep the annoyance of "a choose b" to a minimum
|
2002-07-11 07:56:14 +00:00
|
|
|
|
if (ar.size() == 1 && ar[0]->extraBraces())
|
2002-07-30 13:56:02 +00:00
|
|
|
|
cell->append(ar);
|
2002-07-11 07:56:14 +00:00
|
|
|
|
else
|
|
|
|
|
cell->push_back(MathAtom(new MathBraceInset(ar)));
|
2001-08-17 09:48:24 +00:00
|
|
|
|
}
|
2001-02-26 12:53:35 +00:00
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
else if (t.cat() == catEnd) {
|
2001-08-29 16:23:54 +00:00
|
|
|
|
if (flags & FLAG_BRACE_LAST)
|
|
|
|
|
return;
|
2002-06-27 11:31:32 +00:00
|
|
|
|
error("found '}' unexpectedly");
|
2002-04-02 07:33:38 +00:00
|
|
|
|
//lyx::Assert(0);
|
2002-06-03 07:31:08 +00:00
|
|
|
|
//add(cell, '}', LM_TC_TEX);
|
2001-08-17 09:48:24 +00:00
|
|
|
|
}
|
2002-03-21 17:42:56 +00:00
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
else if (t.cat() == catAlign) {
|
2002-06-03 07:31:08 +00:00
|
|
|
|
++cellcol;
|
2002-06-05 07:12:05 +00:00
|
|
|
|
//lyxerr << " column now " << cellcol << " max: " << grid.ncols() << "\n";
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (cellcol == grid.ncols()) {
|
2002-08-30 08:36:35 +00:00
|
|
|
|
//lyxerr << "adding column " << cellcol << "\n";
|
2002-06-03 07:31:08 +00:00
|
|
|
|
grid.addCol(cellcol - 1);
|
|
|
|
|
}
|
|
|
|
|
cell = &grid.cell(grid.index(cellrow, cellcol));
|
2001-08-17 09:48:24 +00:00
|
|
|
|
}
|
2002-03-21 17:42:56 +00:00
|
|
|
|
|
2001-09-11 10:58:17 +00:00
|
|
|
|
else if (t.cat() == catSuper || t.cat() == catSub) {
|
2002-09-30 06:48:53 +00:00
|
|
|
|
bool up = (t.cat() == catSuper);
|
|
|
|
|
// we need no new script inset if the last thing was a scriptinset,
|
|
|
|
|
// which has that script already not the same script already
|
|
|
|
|
if (!cell->size())
|
|
|
|
|
cell->push_back(MathAtom(new MathScriptInset(up)));
|
|
|
|
|
else if (cell->back()->asScriptInset() &&
|
|
|
|
|
!cell->back()->asScriptInset()->has(up))
|
|
|
|
|
cell->back().nucleus()->asScriptInset()->ensure(up);
|
|
|
|
|
else if (cell->back()->asScriptInset())
|
|
|
|
|
cell->push_back(MathAtom(new MathScriptInset(up)));
|
|
|
|
|
else
|
|
|
|
|
cell->back() = MathAtom(new MathScriptInset(cell->back(), up));
|
|
|
|
|
MathScriptInset * p = cell->back().nucleus()->asScriptInset();
|
|
|
|
|
// special handling of {}-bases
|
|
|
|
|
// is this always correct?
|
2003-02-14 16:20:44 +00:00
|
|
|
|
// It appears that this is wrong (Dekel)
|
|
|
|
|
//if (p->nuc().size() == 1 && p->nuc().back()->asNestInset() &&
|
|
|
|
|
// p->nuc().back()->extraBraces())
|
|
|
|
|
// p->nuc() = p->nuc().back()->asNestInset()->cell(0);
|
2002-09-30 06:48:53 +00:00
|
|
|
|
parse(p->cell(up), FLAG_ITEM, mode);
|
|
|
|
|
if (limits) {
|
|
|
|
|
p->limits(limits);
|
|
|
|
|
limits = 0;
|
2002-08-08 14:22:44 +00:00
|
|
|
|
}
|
2001-09-11 10:58:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-08-05 06:39:33 +00:00
|
|
|
|
else if (t.character() == ']' && (flags & FLAG_BRACK_LAST)) {
|
2002-08-29 10:48:52 +00:00
|
|
|
|
//lyxerr << "finished reading option\n";
|
2001-08-17 09:48:24 +00:00
|
|
|
|
return;
|
2002-08-05 06:39:33 +00:00
|
|
|
|
}
|
2001-08-17 09:48:24 +00:00
|
|
|
|
|
|
|
|
|
else if (t.cat() == catOther)
|
2002-06-24 15:37:14 +00:00
|
|
|
|
cell->push_back(MathAtom(new MathCharInset(t.character())));
|
2002-03-21 17:42:56 +00:00
|
|
|
|
|
2002-08-14 15:13:07 +00:00
|
|
|
|
else if (t.cat() == catComment) {
|
|
|
|
|
string s;
|
|
|
|
|
while (good()) {
|
|
|
|
|
Token const & t = getToken();
|
|
|
|
|
if (t.cat() == catNewline)
|
|
|
|
|
break;
|
|
|
|
|
s += t.asString();
|
|
|
|
|
}
|
|
|
|
|
cell->push_back(MathAtom(new MathCommentInset(s)));
|
|
|
|
|
skipSpaces();
|
|
|
|
|
}
|
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
//
|
2001-10-31 12:26:42 +00:00
|
|
|
|
// control sequences
|
2002-03-21 17:42:56 +00:00
|
|
|
|
//
|
2002-07-12 14:24:47 +00:00
|
|
|
|
|
2002-08-01 15:53:46 +00:00
|
|
|
|
else if (t.cs() == "lyxlock") {
|
|
|
|
|
if (cell->size())
|
2002-08-09 07:01:17 +00:00
|
|
|
|
cell->back().nucleus()->lock(true);
|
2002-08-01 15:53:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-07-12 14:24:47 +00:00
|
|
|
|
else if (t.cs() == "def" || t.cs() == "newcommand") {
|
|
|
|
|
string name;
|
|
|
|
|
int nargs = 0;
|
|
|
|
|
if (t.cs() == "def") {
|
|
|
|
|
// get name
|
|
|
|
|
name = getToken().cs();
|
|
|
|
|
|
|
|
|
|
// read parameter
|
|
|
|
|
string pars;
|
|
|
|
|
while (good() && nextToken().cat() != catBegin) {
|
|
|
|
|
pars += getToken().cs();
|
|
|
|
|
++nargs;
|
|
|
|
|
}
|
|
|
|
|
nargs /= 2;
|
|
|
|
|
//lyxerr << "read \\def parameter list '" << pars << "'\n";
|
|
|
|
|
|
|
|
|
|
} else { // t.cs() == "newcommand"
|
|
|
|
|
|
|
|
|
|
if (getToken().cat() != catBegin) {
|
|
|
|
|
error("'{' in \\newcommand expected (1) \n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
name = getToken().cs();
|
|
|
|
|
|
|
|
|
|
if (getToken().cat() != catEnd) {
|
|
|
|
|
error("'}' in \\newcommand expected\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string arg = getArg('[', ']');
|
|
|
|
|
if (!arg.empty())
|
|
|
|
|
nargs = atoi(arg.c_str());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MathArray ar1;
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse(ar1, FLAG_ITEM, MathInset::UNDECIDED_MODE);
|
2002-07-12 14:24:47 +00:00
|
|
|
|
|
|
|
|
|
// we cannot handle recursive stuff at all
|
|
|
|
|
//MathArray test;
|
|
|
|
|
//test.push_back(createMathInset(name));
|
|
|
|
|
//if (ar1.contains(test)) {
|
|
|
|
|
// error("we cannot handle recursive macros at all.\n");
|
|
|
|
|
// return;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
// is a version for display attached?
|
|
|
|
|
skipSpaces();
|
|
|
|
|
MathArray ar2;
|
|
|
|
|
if (nextToken().cat() == catBegin) {
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse(ar2, FLAG_ITEM, MathInset::MATH_MODE);
|
2002-07-12 14:24:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cell->push_back(MathAtom(new MathMacroTemplate(name, nargs, ar1, ar2)));
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-24 15:37:14 +00:00
|
|
|
|
else if (t.cs() == "(") {
|
2002-07-03 10:36:44 +00:00
|
|
|
|
cell->push_back(MathAtom(new MathHullInset("simple")));
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse2(cell->back(), FLAG_SIMPLE2, MathInset::MATH_MODE, false);
|
2002-06-24 15:37:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (t.cs() == "[") {
|
2002-07-03 10:36:44 +00:00
|
|
|
|
cell->push_back(MathAtom(new MathHullInset("equation")));
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse2(cell->back(), FLAG_EQUATION, MathInset::MATH_MODE, false);
|
2002-06-24 15:37:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-10-31 12:26:42 +00:00
|
|
|
|
else if (t.cs() == "protect")
|
2002-06-24 15:37:14 +00:00
|
|
|
|
// ignore \\protect, will hopefully be re-added during output
|
2001-08-17 09:48:24 +00:00
|
|
|
|
;
|
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
|
else if (t.cs() == "end") {
|
|
|
|
|
if (flags & FLAG_END) {
|
|
|
|
|
// eat environment name
|
|
|
|
|
//string const name =
|
|
|
|
|
getArg('{', '}');
|
|
|
|
|
// FIXME: check that we ended the correct environment
|
|
|
|
|
return;
|
|
|
|
|
}
|
2002-06-27 11:31:32 +00:00
|
|
|
|
error("found 'end' unexpectedly");
|
2002-06-18 15:44:30 +00:00
|
|
|
|
}
|
2001-08-17 09:48:24 +00:00
|
|
|
|
|
2002-06-27 11:31:32 +00:00
|
|
|
|
else if (t.cs() == ")") {
|
|
|
|
|
if (flags & FLAG_SIMPLE2)
|
|
|
|
|
return;
|
|
|
|
|
error("found '\\)' unexpectedly");
|
|
|
|
|
}
|
2001-08-17 09:48:24 +00:00
|
|
|
|
|
2002-06-27 11:31:32 +00:00
|
|
|
|
else if (t.cs() == "]") {
|
|
|
|
|
if (flags & FLAG_EQUATION)
|
|
|
|
|
return;
|
|
|
|
|
error("found '\\]' unexpectedly");
|
|
|
|
|
}
|
2001-08-17 09:48:24 +00:00
|
|
|
|
|
|
|
|
|
else if (t.cs() == "\\") {
|
2002-06-03 07:31:08 +00:00
|
|
|
|
grid.vcrskip(LyXLength(getArg('[', ']')), cellrow);
|
|
|
|
|
++cellrow;
|
|
|
|
|
cellcol = 0;
|
|
|
|
|
if (cellrow == grid.nrows())
|
|
|
|
|
grid.addRow(cellrow - 1);
|
|
|
|
|
if (grid.asHullInset())
|
|
|
|
|
grid.asHullInset()->numbered(cellrow, numbered);
|
|
|
|
|
cell = &grid.cell(grid.index(cellrow, cellcol));
|
2001-08-10 10:39:56 +00:00
|
|
|
|
}
|
2002-03-21 17:42:56 +00:00
|
|
|
|
|
2002-08-15 18:04:01 +00:00
|
|
|
|
#if 0
|
2002-06-18 15:44:30 +00:00
|
|
|
|
else if (t.cs() == "multicolumn") {
|
|
|
|
|
// extract column count and insert dummy cells
|
|
|
|
|
MathArray count;
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse(count, FLAG_ITEM, mode);
|
2002-06-18 15:44:30 +00:00
|
|
|
|
int cols = 1;
|
|
|
|
|
if (!extractNumber(count, cols)) {
|
|
|
|
|
lyxerr << " can't extract number of cells from " << count << "\n";
|
|
|
|
|
}
|
|
|
|
|
// resize the table if necessary
|
|
|
|
|
for (int i = 0; i < cols; ++i) {
|
|
|
|
|
++cellcol;
|
2002-06-24 20:28:12 +00:00
|
|
|
|
if (cellcol == grid.ncols()) {
|
2002-08-30 08:36:35 +00:00
|
|
|
|
//lyxerr << "adding column " << cellcol << "\n";
|
2002-06-18 15:44:30 +00:00
|
|
|
|
grid.addCol(cellcol - 1);
|
|
|
|
|
}
|
|
|
|
|
cell = &grid.cell(grid.index(cellrow, cellcol));
|
|
|
|
|
// mark this as dummy
|
|
|
|
|
grid.cellinfo(grid.index(cellrow, cellcol)).dummy_ = true;
|
|
|
|
|
}
|
|
|
|
|
// the last cell is the real thng, not a dummy
|
|
|
|
|
grid.cellinfo(grid.index(cellrow, cellcol)).dummy_ = false;
|
|
|
|
|
|
|
|
|
|
// read special alignment
|
|
|
|
|
MathArray align;
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse(align, FLAG_ITEM, mode);
|
2002-06-18 15:44:30 +00:00
|
|
|
|
//grid.cellinfo(grid.index(cellrow, cellcol)).align_ = extractString(align);
|
|
|
|
|
|
|
|
|
|
// parse the remaining contents into the "real" cell
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse(*cell, FLAG_ITEM, mode);
|
2002-06-18 15:44:30 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
|
else if (t.cs() == "limits")
|
|
|
|
|
limits = 1;
|
2002-03-21 17:42:56 +00:00
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
|
else if (t.cs() == "nolimits")
|
|
|
|
|
limits = -1;
|
2002-03-21 17:42:56 +00:00
|
|
|
|
|
2002-06-03 07:31:08 +00:00
|
|
|
|
else if (t.cs() == "nonumber") {
|
|
|
|
|
if (grid.asHullInset())
|
|
|
|
|
grid.asHullInset()->numbered(cellrow, false);
|
|
|
|
|
}
|
2001-07-26 16:56:23 +00:00
|
|
|
|
|
2002-06-03 07:31:08 +00:00
|
|
|
|
else if (t.cs() == "number") {
|
|
|
|
|
if (grid.asHullInset())
|
|
|
|
|
grid.asHullInset()->numbered(cellrow, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (t.cs() == "hline") {
|
2002-11-08 08:44:52 +00:00
|
|
|
|
grid.rowinfo(cellrow).lines_ ++;
|
2002-06-03 07:31:08 +00:00
|
|
|
|
}
|
2001-02-26 12:53:35 +00:00
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
else if (t.cs() == "sqrt") {
|
2002-07-08 11:29:51 +00:00
|
|
|
|
MathArray ar;
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse(ar, FLAG_OPTION, mode);
|
2002-07-08 11:29:51 +00:00
|
|
|
|
if (ar.size()) {
|
2002-06-03 07:31:08 +00:00
|
|
|
|
cell->push_back(MathAtom(new MathRootInset));
|
2002-08-09 07:01:17 +00:00
|
|
|
|
cell->back().nucleus()->cell(0) = ar;
|
|
|
|
|
parse(cell->back().nucleus()->cell(1), FLAG_ITEM, mode);
|
2001-02-26 12:53:35 +00:00
|
|
|
|
} else {
|
2002-06-03 07:31:08 +00:00
|
|
|
|
cell->push_back(MathAtom(new MathSqrtInset));
|
2002-08-09 07:01:17 +00:00
|
|
|
|
parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode);
|
2001-02-26 12:53:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-21 17:42:56 +00:00
|
|
|
|
|
2003-02-05 11:44:14 +00:00
|
|
|
|
else if (t.cs() == "xrightarrow" || t.cs() == "xleftarrow") {
|
|
|
|
|
cell->push_back(createMathInset(t.cs()));
|
|
|
|
|
parse(cell->back().nucleus()->cell(1), FLAG_OPTION, mode);
|
|
|
|
|
parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode);
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-25 15:48:47 +00:00
|
|
|
|
else if (t.cs() == "ref" || t.cs() == "prettyref" ||
|
|
|
|
|
t.cs() == "pageref" || t.cs() == "vpageref" || t.cs() == "vref") {
|
|
|
|
|
cell->push_back(MathAtom(new RefInset(t.cs())));
|
2002-08-09 07:01:17 +00:00
|
|
|
|
parse(cell->back().nucleus()->cell(1), FLAG_OPTION, mode);
|
|
|
|
|
parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode);
|
2002-06-24 15:37:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
else if (t.cs() == "left") {
|
2001-09-12 12:51:55 +00:00
|
|
|
|
string l = getToken().asString();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
MathArray ar;
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse(ar, FLAG_RIGHT, mode);
|
2001-09-12 12:51:55 +00:00
|
|
|
|
string r = getToken().asString();
|
2002-06-25 13:19:50 +00:00
|
|
|
|
cell->push_back(MathAtom(new MathDelimInset(l, r, ar)));
|
2001-02-26 12:53:35 +00:00
|
|
|
|
}
|
2002-03-21 17:42:56 +00:00
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
else if (t.cs() == "right") {
|
2002-06-24 15:37:14 +00:00
|
|
|
|
if (flags & FLAG_RIGHT)
|
|
|
|
|
return;
|
|
|
|
|
//lyxerr << "got so far: '" << cell << "'\n";
|
|
|
|
|
error("Unmatched right delimiter");
|
2001-08-17 09:48:24 +00:00
|
|
|
|
return;
|
2001-08-10 15:32:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
else if (t.cs() == "begin") {
|
2002-03-21 17:42:56 +00:00
|
|
|
|
string const name = getArg('{', '}');
|
2002-08-12 09:53:04 +00:00
|
|
|
|
|
2002-02-14 14:52:23 +00:00
|
|
|
|
if (name == "array" || name == "subarray") {
|
2002-09-30 06:48:53 +00:00
|
|
|
|
string const valign = parse_verbatim_option() + 'c';
|
|
|
|
|
string const halign = parse_verbatim_item();
|
2002-06-03 07:31:08 +00:00
|
|
|
|
cell->push_back(MathAtom(new MathArrayInset(name, valign[0], halign)));
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse2(cell->back(), FLAG_END, mode, false);
|
2002-06-24 15:37:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (name == "split" || name == "cases" ||
|
2002-03-21 17:42:56 +00:00
|
|
|
|
name == "gathered" || name == "aligned") {
|
2002-06-03 07:31:08 +00:00
|
|
|
|
cell->push_back(createMathInset(name));
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse2(cell->back(), FLAG_END, mode, false);
|
2002-06-24 15:37:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (name == "math") {
|
2002-07-03 10:36:44 +00:00
|
|
|
|
cell->push_back(MathAtom(new MathHullInset("simple")));
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, true);
|
2002-06-24 15:37:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (name == "equation" || name == "equation*"
|
|
|
|
|
|| name == "displaymath") {
|
2002-07-03 10:36:44 +00:00
|
|
|
|
cell->push_back(MathAtom(new MathHullInset("equation")));
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, (name == "equation"));
|
2002-06-24 15:37:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (name == "eqnarray" || name == "eqnarray*") {
|
2002-07-03 10:36:44 +00:00
|
|
|
|
cell->push_back(MathAtom(new MathHullInset("eqnarray")));
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
|
2002-06-24 15:37:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (name == "align" || name == "align*") {
|
2002-07-03 10:36:44 +00:00
|
|
|
|
cell->push_back(MathAtom(new MathHullInset("align")));
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
|
2002-06-24 15:37:14 +00:00
|
|
|
|
}
|
2002-10-14 12:56:21 +00:00
|
|
|
|
|
|
|
|
|
else if (name == "flalign" || name == "flalign*") {
|
|
|
|
|
cell->push_back(MathAtom(new MathHullInset("flalign")));
|
|
|
|
|
parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
|
|
|
|
|
}
|
2002-06-24 15:37:14 +00:00
|
|
|
|
|
|
|
|
|
else if (name == "alignat" || name == "alignat*") {
|
|
|
|
|
// ignore this for a while
|
|
|
|
|
getArg('{', '}');
|
2002-07-03 10:36:44 +00:00
|
|
|
|
cell->push_back(MathAtom(new MathHullInset("alignat")));
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
|
2002-06-24 15:37:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (name == "xalignat" || name == "xalignat*") {
|
|
|
|
|
// ignore this for a while
|
|
|
|
|
getArg('{', '}');
|
2002-07-03 10:36:44 +00:00
|
|
|
|
cell->push_back(MathAtom(new MathHullInset("xalignat")));
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
|
2002-06-24 15:37:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (name == "xxalignat") {
|
|
|
|
|
// ignore this for a while
|
|
|
|
|
getArg('{', '}');
|
2002-07-03 10:36:44 +00:00
|
|
|
|
cell->push_back(MathAtom(new MathHullInset("xxalignat")));
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
|
2002-06-24 15:37:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (name == "multline" || name == "multline*") {
|
2002-07-03 10:36:44 +00:00
|
|
|
|
cell->push_back(MathAtom(new MathHullInset("multline")));
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
|
2002-06-24 15:37:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (name == "gather" || name == "gather*") {
|
2002-07-03 10:36:44 +00:00
|
|
|
|
cell->push_back(MathAtom(new MathHullInset("gather")));
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse2(cell->back(), FLAG_END, MathInset::MATH_MODE, !stared(name));
|
2002-06-24 15:37:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-07-09 09:46:31 +00:00
|
|
|
|
else if (latexkeys const * l = in_word_set(name)) {
|
|
|
|
|
if (l->inset == "matrix") {
|
|
|
|
|
cell->push_back(createMathInset(name));
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse2(cell->back(), FLAG_END, mode, false);
|
2002-06-24 15:37:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-07-09 09:46:31 +00:00
|
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
// lyxerr << "unknow math inset begin '" << name << "'\n";
|
|
|
|
|
// create generic environment inset
|
|
|
|
|
cell->push_back(MathAtom(new MathEnvInset(name)));
|
2002-08-09 07:01:17 +00:00
|
|
|
|
parse(cell->back().nucleus()->cell(0), FLAG_END, mode);
|
2002-07-09 09:46:31 +00:00
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
2002-03-21 17:42:56 +00:00
|
|
|
|
|
2001-08-21 14:20:50 +00:00
|
|
|
|
else if (t.cs() == "kern") {
|
|
|
|
|
#ifdef WITH_WARNINGS
|
|
|
|
|
#warning A hack...
|
|
|
|
|
#endif
|
|
|
|
|
string s;
|
2002-11-24 15:20:31 +00:00
|
|
|
|
while (true) {
|
2001-08-21 14:20:50 +00:00
|
|
|
|
Token const & t = getToken();
|
|
|
|
|
if (!good()) {
|
2002-03-21 17:42:56 +00:00
|
|
|
|
putback();
|
2001-08-21 14:20:50 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
s += t.character();
|
|
|
|
|
if (isValidLength(s))
|
|
|
|
|
break;
|
|
|
|
|
}
|
2002-06-03 07:31:08 +00:00
|
|
|
|
cell->push_back(MathAtom(new MathKernInset(s)));
|
2002-03-27 10:51:46 +00:00
|
|
|
|
}
|
2002-03-25 12:11:25 +00:00
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
else if (t.cs() == "label") {
|
2002-09-30 06:48:53 +00:00
|
|
|
|
string label = parse_verbatim_item();
|
2002-07-10 15:23:36 +00:00
|
|
|
|
if (grid.asHullInset()) {
|
2002-09-30 06:48:53 +00:00
|
|
|
|
grid.asHullInset()->label(cellrow, label);
|
2002-07-11 07:56:14 +00:00
|
|
|
|
} else {
|
|
|
|
|
cell->push_back(createMathInset(t.cs()));
|
2002-09-30 06:48:53 +00:00
|
|
|
|
cell->push_back(MathAtom(new MathBraceInset(asArray(label))));
|
2002-07-10 15:23:36 +00:00
|
|
|
|
}
|
2001-08-17 09:48:24 +00:00
|
|
|
|
}
|
2001-08-13 14:02:37 +00:00
|
|
|
|
|
2001-08-17 17:50:00 +00:00
|
|
|
|
else if (t.cs() == "choose" || t.cs() == "over" || t.cs() == "atop") {
|
2002-08-09 07:01:17 +00:00
|
|
|
|
MathAtom at = createMathInset(t.cs());
|
|
|
|
|
at.nucleus()->cell(0) = *cell;
|
2002-07-30 13:56:02 +00:00
|
|
|
|
cell->clear();
|
2002-08-09 07:01:17 +00:00
|
|
|
|
parse(at.nucleus()->cell(1), flags, mode);
|
|
|
|
|
cell->push_back(at);
|
2001-10-31 12:04:45 +00:00
|
|
|
|
return;
|
2001-08-13 14:02:37 +00:00
|
|
|
|
}
|
2001-10-19 11:25:48 +00:00
|
|
|
|
|
2002-02-14 14:52:23 +00:00
|
|
|
|
else if (t.cs() == "substack") {
|
2002-06-03 07:31:08 +00:00
|
|
|
|
cell->push_back(createMathInset(t.cs()));
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse2(cell->back(), FLAG_ITEM, mode, false);
|
2002-02-14 14:52:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-02-04 18:44:51 +00:00
|
|
|
|
else if (t.cs() == "xymatrix") {
|
2002-06-03 07:31:08 +00:00
|
|
|
|
cell->push_back(createMathInset(t.cs()));
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse2(cell->back(), FLAG_ITEM, mode, false);
|
2002-02-04 18:44:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-08-29 10:48:52 +00:00
|
|
|
|
else if (t.cs() == "framebox") {
|
|
|
|
|
cell->push_back(createMathInset(t.cs()));
|
|
|
|
|
parse(cell->back().nucleus()->cell(0), FLAG_OPTION, mode);
|
|
|
|
|
parse(cell->back().nucleus()->cell(1), FLAG_ITEM, mode);
|
|
|
|
|
}
|
|
|
|
|
|
2002-01-09 15:21:56 +00:00
|
|
|
|
#if 0
|
2002-08-28 08:30:27 +00:00
|
|
|
|
else if (t.cs() == "infer") {
|
|
|
|
|
MathArray ar;
|
|
|
|
|
parse(ar, FLAG_OPTION, mode);
|
|
|
|
|
cell->push_back(createMathInset(t.cs()));
|
|
|
|
|
parse2(cell->back(), FLAG_ITEM, mode, false);
|
|
|
|
|
}
|
|
|
|
|
|
2002-02-11 08:19:02 +00:00
|
|
|
|
// Disabled
|
|
|
|
|
else if (1 && t.cs() == "ar") {
|
|
|
|
|
MathXYArrowInset * p = new MathXYArrowInset;
|
|
|
|
|
// try to read target
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse(p->cell(0), FLAG_OTPTION, mode);
|
2002-02-11 08:19:02 +00:00
|
|
|
|
// try to read label
|
|
|
|
|
if (nextToken().cat() == catSuper || nextToken().cat() == catSub) {
|
|
|
|
|
p->up_ = nextToken().cat() == catSuper;
|
|
|
|
|
getToken();
|
2002-08-08 14:22:44 +00:00
|
|
|
|
parse(p->cell(1), FLAG_ITEM, mode);
|
2002-02-11 08:19:02 +00:00
|
|
|
|
//lyxerr << "read label: " << p->cell(1) << "\n";
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-03 07:31:08 +00:00
|
|
|
|
cell->push_back(MathAtom(p));
|
|
|
|
|
//lyxerr << "read cell: " << cell << "\n";
|
2002-02-08 08:03:38 +00:00
|
|
|
|
}
|
2002-02-15 14:07:09 +00:00
|
|
|
|
#endif
|
2002-02-08 08:03:38 +00:00
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
else if (t.cs().size()) {
|
|
|
|
|
latexkeys const * l = in_word_set(t.cs());
|
|
|
|
|
if (l) {
|
2002-05-30 07:09:54 +00:00
|
|
|
|
if (l->inset == "font") {
|
2002-07-17 10:25:33 +00:00
|
|
|
|
cell->push_back(createMathInset(t.cs()));
|
2002-10-15 08:41:35 +00:00
|
|
|
|
parse(cell->back().nucleus()->cell(0), FLAG_ITEM, asMode(mode, l->extra));
|
2001-08-17 09:48:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-05-30 07:09:54 +00:00
|
|
|
|
else if (l->inset == "oldfont") {
|
2002-06-24 15:37:14 +00:00
|
|
|
|
cell->push_back(createMathInset(t.cs()));
|
2002-10-15 08:41:35 +00:00
|
|
|
|
parse(cell->back().nucleus()->cell(0), flags, asMode(mode, l->extra));
|
2002-05-30 07:09:54 +00:00
|
|
|
|
return;
|
2001-10-24 17:14:05 +00:00
|
|
|
|
}
|
2001-08-17 09:48:24 +00:00
|
|
|
|
|
2002-05-30 07:09:54 +00:00
|
|
|
|
else if (l->inset == "style") {
|
2002-06-24 15:37:14 +00:00
|
|
|
|
cell->push_back(createMathInset(t.cs()));
|
2002-08-09 07:01:17 +00:00
|
|
|
|
parse(cell->back().nucleus()->cell(0), flags, mode);
|
2002-01-03 12:02:54 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2002-07-08 11:29:51 +00:00
|
|
|
|
else if (l->inset == "parbox") {
|
|
|
|
|
// read optional positioning and width
|
2002-09-30 06:48:53 +00:00
|
|
|
|
string pos = parse_verbatim_option();
|
2002-11-24 15:20:31 +00:00
|
|
|
|
string width = parse_verbatim_item();
|
2002-07-08 11:29:51 +00:00
|
|
|
|
cell->push_back(createMathInset(t.cs()));
|
2002-08-09 07:01:17 +00:00
|
|
|
|
parse(cell->back().nucleus()->cell(0), FLAG_ITEM, MathInset::TEXT_MODE);
|
2002-09-30 06:48:53 +00:00
|
|
|
|
cell->back().nucleus()->asParboxInset()->setPosition(pos);
|
|
|
|
|
cell->back().nucleus()->asParboxInset()->setWidth(width);
|
2002-07-08 11:29:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-08-17 09:48:24 +00:00
|
|
|
|
else {
|
2002-08-09 07:01:17 +00:00
|
|
|
|
MathAtom at = createMathInset(t.cs());
|
|
|
|
|
for (MathInset::idx_type i = 0; i < at->nargs(); ++i)
|
2002-10-15 08:41:35 +00:00
|
|
|
|
parse(at.nucleus()->cell(i), FLAG_ITEM, asMode(mode, l->extra));
|
2002-08-09 07:01:17 +00:00
|
|
|
|
cell->push_back(at);
|
2001-08-17 09:48:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else {
|
2002-08-09 07:01:17 +00:00
|
|
|
|
MathAtom at = createMathInset(t.cs());
|
2002-08-08 14:22:44 +00:00
|
|
|
|
MathInset::mode_type m = mode;
|
|
|
|
|
if (m == MathInset::UNDECIDED_MODE)
|
2002-08-09 07:01:17 +00:00
|
|
|
|
m = at->currentMode();
|
2002-08-29 09:57:57 +00:00
|
|
|
|
MathInset::idx_type start = 0;
|
2002-08-29 10:48:52 +00:00
|
|
|
|
// this fails on \bigg[...\bigg]
|
|
|
|
|
//MathArray opt;
|
|
|
|
|
//parse(opt, FLAG_OPTION, MathInset::VERBATIM_MODE);
|
|
|
|
|
//if (opt.size()) {
|
|
|
|
|
// start = 1;
|
|
|
|
|
// at.nucleus()->cell(0) = opt;
|
|
|
|
|
//}
|
2002-08-29 09:57:57 +00:00
|
|
|
|
for (MathInset::idx_type i = start; i < at->nargs(); ++i)
|
2002-08-09 07:01:17 +00:00
|
|
|
|
parse(at.nucleus()->cell(i), FLAG_ITEM, m);
|
|
|
|
|
cell->push_back(at);
|
2001-08-13 14:02:37 +00:00
|
|
|
|
}
|
2001-08-17 09:48:24 +00:00
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2001-07-13 07:55:55 +00:00
|
|
|
|
|
|
|
|
|
if (flags & FLAG_LEAVE) {
|
|
|
|
|
flags &= ~FLAG_LEAVE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2001-08-14 07:46:11 +00:00
|
|
|
|
}
|
2001-08-10 07:52:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
|
|
|
|
|
|
|
2001-08-10 09:30:02 +00:00
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
2001-07-12 07:18:29 +00:00
|
|
|
|
|
2001-10-18 13:21:21 +00:00
|
|
|
|
void mathed_parse_cell(MathArray & ar, string const & str)
|
2001-07-26 16:14:23 +00:00
|
|
|
|
{
|
|
|
|
|
istringstream is(str.c_str());
|
2001-10-18 13:21:21 +00:00
|
|
|
|
mathed_parse_cell(ar, is);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void mathed_parse_cell(MathArray & ar, istream & is)
|
|
|
|
|
{
|
2002-08-08 14:22:44 +00:00
|
|
|
|
Parser(is).parse(ar, 0, MathInset::MATH_MODE);
|
2001-07-20 10:57:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
|
bool mathed_parse_normal(MathAtom & t, string const & str)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-08-10 07:52:04 +00:00
|
|
|
|
istringstream is(str.c_str());
|
2002-07-12 14:24:47 +00:00
|
|
|
|
return Parser(is).parse(t);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-07-08 11:29:51 +00:00
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
|
bool mathed_parse_normal(MathAtom & t, istream & is)
|
2001-08-03 09:54:48 +00:00
|
|
|
|
{
|
2002-07-12 14:24:47 +00:00
|
|
|
|
return Parser(is).parse(t);
|
2001-08-03 09:54:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-07-08 11:29:51 +00:00
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
|
bool mathed_parse_normal(MathAtom & t, LyXLex & lex)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-07-12 14:24:47 +00:00
|
|
|
|
return Parser(lex).parse(t);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-08-14 16:11:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void mathed_parse_normal(MathGridInset & grid, string const & str)
|
|
|
|
|
{
|
|
|
|
|
istringstream is(str.c_str());
|
|
|
|
|
Parser(is).parse1(grid, 0, MathInset::MATH_MODE, false);
|
|
|
|
|
}
|