mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
read/input support for TeX's '\over'
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2503 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
d9c3e3e8a9
commit
1e9b743bce
@ -7,6 +7,9 @@
|
||||
math_cursor.C:
|
||||
math_hash.C: simplifications
|
||||
|
||||
* math_parser.C:
|
||||
math_cursor.C: reading support for TeX style \over
|
||||
|
||||
2001-08-10 André Pönitz <poenitz@gmx.net>
|
||||
|
||||
* math_scopeinset.[Ch]: new inset for {} blocks
|
||||
|
@ -35,6 +35,7 @@
|
||||
#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"
|
||||
@ -1261,22 +1262,10 @@ void MathCursor::interpret(string const & s)
|
||||
|
||||
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;
|
||||
@ -1287,10 +1276,32 @@ void MathCursor::interpret(string const & s)
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,7 @@
|
||||
#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"
|
||||
@ -99,6 +100,7 @@ lexcode_enum lexcode[256];
|
||||
|
||||
|
||||
const unsigned char LM_TK_OPEN = '{';
|
||||
const unsigned char LM_TK_CLOSE = '}';
|
||||
|
||||
enum {
|
||||
FLAG_BRACE = 1 << 0, // an opening brace needed
|
||||
@ -184,9 +186,13 @@ void lexInit()
|
||||
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();
|
||||
@ -196,6 +202,8 @@ public:
|
||||
void parse_into(MathArray & array, unsigned flags);
|
||||
///
|
||||
int lineno() const { return lineno_; }
|
||||
///
|
||||
void putback(int token);
|
||||
|
||||
private:
|
||||
///
|
||||
@ -230,9 +238,18 @@ 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;
|
||||
@ -291,6 +308,12 @@ int Parser::yylex()
|
||||
lexInit();
|
||||
init_done = true;
|
||||
}
|
||||
|
||||
if (putback_token_) {
|
||||
int token = putback_token_;
|
||||
putback_token_ = 0;
|
||||
return token;
|
||||
}
|
||||
|
||||
while (is_.good()) {
|
||||
unsigned char c = getuchar();
|
||||
@ -299,29 +322,45 @@ int Parser::yylex()
|
||||
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;
|
||||
@ -575,6 +614,15 @@ void Parser::parse_into(MathArray & array, unsigned flags)
|
||||
}
|
||||
}
|
||||
|
||||
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:
|
||||
@ -769,8 +817,10 @@ void Parser::parse_into(MathArray & array, unsigned flags)
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user