new parser

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2528 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2001-08-17 09:48:24 +00:00
parent b76821ddff
commit 77dca4f3bc
14 changed files with 582 additions and 555 deletions

View File

@ -1,3 +1,7 @@
2001-08-17 André Pönitz <poenitz@gmx.net>
* math_parser.C: new "lexxer"
2001-08-13 André Pönitz <poenitz@gmx.net> 2001-08-13 André Pönitz <poenitz@gmx.net>
* math_factory.[Ch]: new files for the creation of math insets * math_factory.[Ch]: new files for the creation of math insets

View File

@ -553,11 +553,12 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action,
case LFUN_MATH_SPACE: case LFUN_MATH_SPACE:
{ {
bv->lockedInsetStoreUndo(Undo::EDIT); bv->lockedInsetStoreUndo(Undo::EDIT);
MathSpaceInset * p = mathcursor->prevSpaceInset(); //MathSpaceInset * p = mathcursor->prevSpaceInset();
if (p) //if (p)
p->incSpace(); // p->incSpace();
else //else
mathcursor->insert(new MathSpaceInset(1)); // mathcursor->insert(new MathSpaceInset(1));
mathcursor->insert(new MathSpaceInset(1));
updateLocal(bv, true); updateLocal(bv, true);
break; break;
} }

View File

@ -2,6 +2,8 @@
#pragma implementation #pragma implementation
#endif #endif
#include <cctype>
#include "math_charinset.h" #include "math_charinset.h"
#include "LColor.h" #include "LColor.h"
#include "Painter.h" #include "Painter.h"
@ -11,11 +13,27 @@
#include "debug.h" #include "debug.h"
MathCharInset::MathCharInset(char c)
: char_(c), code_(nativeCode(c))
{
if (isalpha(c))
code_ = LM_TC_VAR;
}
MathCharInset::MathCharInset(char c, MathTextCodes t) MathCharInset::MathCharInset(char c, MathTextCodes t)
: char_(c), code_(t) : char_(c), code_((t == LM_TC_MIN) ? nativeCode(c) : t)
{} {}
MathTextCodes MathCharInset::nativeCode(char c) const
{
if (isalpha(c))
return LM_TC_VAR;
return LM_TC_MIN;
}
MathInset * MathCharInset::clone() const MathInset * MathCharInset::clone() const
{ {
return new MathCharInset(*this); return new MathCharInset(*this);

View File

@ -14,11 +14,15 @@
class MathCharInset : public MathInset { class MathCharInset : public MathInset {
public: public:
///
explicit MathCharInset(char c);
/// ///
MathCharInset(char c, MathTextCodes t); MathCharInset(char c, MathTextCodes t);
/// ///
MathInset * clone() const; MathInset * clone() const;
/// ///
MathTextCodes nativeCode(char c) const;
///
void metrics(MathStyles st) const; void metrics(MathStyles st) const;
/// ///
void draw(Painter &, int x, int y) const; void draw(Painter &, int x, int y) const;

View File

@ -1277,16 +1277,9 @@ void MathCursor::interpret(string const & s)
return; return;
} }
if (('0' <= c && c <= '9') || strchr(";:!|[]().,?", c)) { if (strchr("0123456789;:!|[]().,?+/-*<>=", c)) {
if (lastcode_ != LM_TC_TEXTRM) if (lastcode_ != LM_TC_TEXTRM)
lastcode_ = LM_TC_CONST; lastcode_ = LM_TC_VAR;
insert(c, lastcode_);
return;
}
if (strchr("+/-*<>=", c)) {
if (lastcode_ != LM_TC_TEXTRM)
lastcode_ = LM_TC_BOP;
insert(c, lastcode_); insert(c, lastcode_);
return; return;
} }
@ -1305,6 +1298,12 @@ void MathCursor::interpret(string const & s)
return; return;
} }
MathSpaceInset * p = prevSpaceInset();
if (p) {
p->incSpace();
return;
}
if (lastcode_ == LM_TC_TEXTRM) { if (lastcode_ == LM_TC_TEXTRM) {
insert(c, LM_TC_TEXTRM); insert(c, LM_TC_TEXTRM);
return; return;

View File

@ -55,8 +55,6 @@ enum MathTextCodes {
/// ///
LM_FONT_BEGIN, LM_FONT_BEGIN,
/// Internal code for constants 4
LM_TC_CONST,
/// Internal code for variables /// Internal code for variables
LM_TC_VAR, LM_TC_VAR,
/// ///
@ -81,8 +79,6 @@ enum MathTextCodes {
LM_TC_GREEK, LM_TC_GREEK,
/// Internal code when typing a single greek character /// Internal code when typing a single greek character
LM_TC_GREEK1, LM_TC_GREEK1,
/// Internal code for operators
LM_TC_BOP,
/// Internal code for symbols /// Internal code for symbols
LM_TC_SYMB, LM_TC_SYMB,
/// Internal code for symbols that get bigger in displayed math /// Internal code for symbols that get bigger in displayed math

View File

@ -64,8 +64,13 @@ void MathDelimInset::metrics(MathStyles st) const
{ {
xcell(0).metrics(st); xcell(0).metrics(st);
size_ = st; size_ = st;
ascent_ = std::max(xcell(0).ascent(), mathed_char_ascent(LM_TC_VAR, st,'I')); int a, d, w;
descent_ = xcell(0).descent(); mathed_char_dim(LM_TC_VAR, st,'I', a, d, w);
int h0 = (a + d) / 2;
int a0 = std::max(xcell(0).ascent(), a) - h0;
int d0 = std::max(xcell(0).descent(), d) + h0;
ascent_ = max(a0, d0) + h0;
descent_ = max(a0, d0) - h0;
width_ = xcell(0).width() + 2 * dw() + 4; width_ = xcell(0).width() + 2 * dw() + 4;
} }
@ -78,6 +83,6 @@ void MathDelimInset::draw(Painter & pain, int x, int y) const
int const w = dw(); int const w = dw();
int const b = y - ascent_ - 2; int const b = y - ascent_ - 2;
xcell(0).draw(pain, x + w + 2, y); xcell(0).draw(pain, x + w + 2, y);
mathed_draw_deco(pain, x, b, w, height() + 4, left_); mathed_draw_deco(pain, x + 1, b, w, height() + 4, left_);
mathed_draw_deco(pain, x + width() - w, b, w, height() + 4, right_); mathed_draw_deco(pain, x + width() - w - 1, b, w, height() + 4, right_);
} }

View File

@ -11,6 +11,7 @@
#include "math_macro.h" #include "math_macro.h"
#include "math_macrotable.h" #include "math_macrotable.h"
#include "math_noglyphinset.h" #include "math_noglyphinset.h"
#include "math_notinset.h"
#include "math_rootinset.h" #include "math_rootinset.h"
#include "math_spaceinset.h" #include "math_spaceinset.h"
#include "math_sqrtinset.h" #include "math_sqrtinset.h"
@ -38,6 +39,8 @@ MathInset * createMathInset(latexkeys const * l)
case LM_TK_OVER: case LM_TK_OVER:
case LM_TK_FRAC: case LM_TK_FRAC:
return new MathFracInset; return new MathFracInset;
case LM_TK_NOT:
return new MathNotInset;
case LM_TK_SQRT: case LM_TK_SQRT:
return new MathSqrtInset; return new MathSqrtInset;
case LM_TK_ROOT: case LM_TK_ROOT:

View File

@ -181,6 +181,8 @@ public:
/// ///
virtual bool isRelOp() const { return false; } virtual bool isRelOp() const { return false; }
/// ///
virtual bool isMacro() const { return false; }
///
virtual char getChar() const { return 0; } virtual char getChar() const { return 0; }
/// ///
virtual MathTextCodes code() const { return LM_TC_MIN; } virtual MathTextCodes code() const { return LM_TC_MIN; }

View File

@ -129,8 +129,8 @@ void MathMacro::draw(Painter & pain, int x, int y) const
col = LColor::black; col = LColor::black;
} }
if (nargs() > 0) //if (nargs() > 0)
pain.rectangle(x + 1, y - ascent() + 1, width() - 2, height() - 2, col); // pain.rectangle(x + 1, y - ascent() + 1, width() - 2, height() - 2, col);
} }

View File

@ -64,6 +64,8 @@ public:
/// ///
void validate(LaTeXFeatures &) const; void validate(LaTeXFeatures &) const;
///
bool isMacro() const { return true; }
private: private:
/// ///

File diff suppressed because it is too large Load Diff

View File

@ -37,13 +37,7 @@ class LyXLex;
enum MathTokenEnum enum MathTokenEnum
{ {
/// ///
LM_TK_BOP = 256, LM_TK_SYM = 256,
///
LM_TK_ALPHA,
///
LM_TK_STR,
///
LM_TK_SYM,
/// ///
LM_TK_CHOOSE, LM_TK_CHOOSE,
/// ///

View File

@ -16,6 +16,12 @@ using std::endl;
using std::max; using std::max;
bool isBinaryOp(char c)
{
return strchr("+-<>=/*", c);
}
/// ///
class Matrix { class Matrix {
public: public:
@ -533,7 +539,7 @@ int mathed_char_descent(MathTextCodes type, MathStyles size, unsigned char c)
int mathed_char_width(MathTextCodes type, MathStyles size, unsigned char c) int mathed_char_width(MathTextCodes type, MathStyles size, unsigned char c)
{ {
LyXFont const font = WhichFont(type, size); LyXFont const font = WhichFont(type, size);
if (type == LM_TC_BOP) if (isBinaryOp(c))
return lyxfont::width(c, font) + 2 * lyxfont::width(' ', font); return lyxfont::width(c, font) + 2 * lyxfont::width(' ', font);
else else
return lyxfont::width(c, font); return lyxfont::width(c, font);
@ -655,12 +661,6 @@ void mathed_draw_deco(Painter & pain, int x, int y, int w, int h,
} }
bool isBinaryOp(char c)
{
return true;
}
// In a near future maybe we use a better fonts renderer // In a near future maybe we use a better fonts renderer
void drawStr(Painter & pain, MathTextCodes type, MathStyles siz, void drawStr(Painter & pain, MathTextCodes type, MathStyles siz,
int x, int y, string const & s) int x, int y, string const & s)
@ -673,10 +673,10 @@ void drawChar
(Painter & pain, MathTextCodes type, MathStyles siz, int x, int y, char c) (Painter & pain, MathTextCodes type, MathStyles siz, int x, int y, char c)
{ {
string s; string s;
if (type == LM_TC_BOP) if (isBinaryOp(c))
s += ' '; s += ' ';
s += c; s += c;
if (type == LM_TC_BOP) if (isBinaryOp(c))
s += ' '; s += ' ';
drawStr(pain, type, siz, x, y, s); drawStr(pain, type, siz, x, y, s);
} }