#include "math_charinset.h"
#include "math_decorationinset.h"
#include "math_deliminset.h"
+#include "math_fracinset.h"
#include "math_funcinset.h"
#include "math_macro.h"
#include "math_macrotable.h"
char c = s[0];
- lyxerr << "char: '" << c << "' int: " << int(c) << endl;
+ //lyxerr << "char: '" << c << "' int: " << int(c) << endl;
//owner_->getIntl()->getTrans().TranslateAndInsert(c, lt);
//lyxerr << "trans: '" << c << "' int: " << int(c) << endl;
- latexkeys const * l = in_word_set(s.substr(1));
- if (l) {
- lastcode_ = LM_TC_VAR;
- niceInsert(createMathInset(l));
- return;
- }
-
- if (MathMacroTable::hasTemplate(s.substr(1))) {
- niceInsert(new MathMacro(MathMacroTable::provideTemplate(s.substr(1))));
- return;
- }
-
if (s.size() > 8 && s.substr(0, 8) == "\\matrix ") {
int m = 1;
int n = 1;
m = std::max(1, m);
n = std::max(1, n);
v_align += 'c';
- MathArrayInset * pp = new MathArrayInset(m, n);
- pp->valign(v_align[0]);
- pp->halign(h_align);
- niceInsert(pp);
+ MathArrayInset * p = new MathArrayInset(m, n);
+ p->valign(v_align[0]);
+ p->halign(h_align);
+ niceInsert(p);
+ return;
+ }
+
+ if (s == "\\over") {
+ MathArray ar = array();
+ MathFracInset * p = new MathFracInset;
+ p->cell(0).swap(array());
+ pos() = 0;
+ niceInsert(p);
+ down();
+ return;
+ }
+
+ latexkeys const * l = in_word_set(s.substr(1));
+ if (l) {
+ lastcode_ = LM_TC_VAR;
+ niceInsert(createMathInset(l));
+ return;
+ }
+
+ if (MathMacroTable::hasTemplate(s.substr(1))) {
+ niceInsert(new MathMacro(MathMacroTable::provideTemplate(s.substr(1))));
return;
}
#include "math_charinset.h"
#include "math_deliminset.h"
#include "math_factory.h"
+#include "math_fracinset.h"
#include "math_funcinset.h"
#include "math_macro.h"
#include "math_macrotable.h"
const unsigned char LM_TK_OPEN = '{';
+const unsigned char LM_TK_CLOSE = '}';
enum {
FLAG_BRACE = 1 << 0, // an opening brace needed
class Parser {
public:
///
- Parser(LyXLex & lex) : is_(lex.getStream()), lineno_(lex.getLineNo()) {}
+ Parser(LyXLex & lex)
+ : is_(lex.getStream()), lineno_(lex.getLineNo()), putback_token_(0)
+ {}
///
- Parser(istream & is) : is_(is), lineno_(0) {}
+ Parser(istream & is)
+ : is_(is), lineno_(0), putback_token_(0)
+ {}
///
MathMacroTemplate * parse_macro();
void parse_into(MathArray & array, unsigned flags);
///
int lineno() const { return lineno_; }
+ ///
+ void putback(int token);
private:
///
string curr_label_;
///
string curr_skip_;
+
+ ///
+ int putback_token_;
};
+void Parser::putback(int token)
+{
+ putback_token_ = token;
+}
+
+
unsigned char Parser::getuchar()
{
char c = 0;
lexInit();
init_done = true;
}
+
+ if (putback_token_) {
+ int token = putback_token_;
+ putback_token_ = 0;
+ return token;
+ }
while (is_.good()) {
unsigned char c = getuchar();
if (lexcode[c] == LexNewLine) {
++lineno_;
continue;
- } else if (lexcode[c] == LexComment) {
+ }
+
+ if (lexcode[c] == LexComment) {
do {
c = getuchar();
} while (c != '\n' && is_.good()); // eat comments
- } else if (lexcode[c] == LexOther) {
+ }
+
+ if (lexcode[c] == LexOther) {
ival_ = c;
return LM_TK_STR;
- } else if (lexcode[c] == LexAlpha || lexcode[c] == LexSpace) {
+ }
+
+ if (lexcode[c] == LexAlpha || lexcode[c] == LexSpace) {
ival_ = c;
return LM_TK_ALPHA;
- } else if (lexcode[c] == LexBOP) {
+ }
+
+ if (lexcode[c] == LexBOP) {
ival_ = c;
return LM_TK_BOP;
- } else if (lexcode[c] == LexMath) {
+ }
+
+ if (lexcode[c] == LexMath) {
ival_ = 0;
return LM_TK_MATH;
- } else if (lexcode[c] == LexSelf) {
+ }
+
+ if (lexcode[c] == LexSelf) {
return c;
- } else if (lexcode[c] == LexArgument) {
+ }
+
+ if (lexcode[c] == LexArgument) {
c = getuchar();
ival_ = c - '0';
return LM_TK_ARGUMENT;
- } else if (lexcode[c] == LexESC) {
+ }
+
+ if (lexcode[c] == LexESC) {
c = getuchar();
//lyxerr << "reading second byte: '" << c << "' code: " << lexcode[c] << endl;
string s;
}
}
+ if (flags & FLAG_BLOCK) {
+ if (t == LM_TK_CLOSE || t == '&' ||
+ t == LM_TK_NEWLINE || t == LM_TK_END) {
+ putback(t);
+ return;
+ }
+ }
+
+
switch (t) {
case LM_TK_MATH:
case LM_TK_OVER:
{
- MathArray ar;
- parse_into(ar, FLAG_BLOCK);
+ MathFracInset * p = new MathFracInset;
+ p->cell(0).swap(array);
+ array.push_back(p);
+ parse_into(p->cell(1), FLAG_BLOCK);
break;
}