From d4582c5bc122e895dd602db6980d8cd7cb40feea Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Thu, 9 Aug 2001 10:34:43 +0000 Subject: [PATCH] move some more parser information to math_hash to make it accessible by the cursor git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2461 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/formulabase.C | 4 +--- src/mathed/math_hash.C | 18 +++++++++++++++-- src/mathed/math_parser.C | 42 +++++++++++----------------------------- src/mathed/math_parser.h | 2 +- 4 files changed, 29 insertions(+), 37 deletions(-) diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index 51b92312a3..d871cef4d3 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -48,8 +48,6 @@ using std::endl; using std::ostream; using std::vector; -extern char const * latex_special_chars; - extern char const * latex_mathenv[]; MathCursor * mathcursor = 0; @@ -806,7 +804,7 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action, if (code != LM_TC_TEXTRM) code = LM_TC_BOP; mathcursor->insert(c, code); - } else if (strchr(latex_special_chars, c) && c != '_') { + } else if (strchr("#$%^{|}", c)) { MathTextCodes code = mathcursor->getLastCode(); if (code != LM_TC_TEXTRM) code = LM_TC_SPECIAL; diff --git a/src/mathed/math_hash.C b/src/mathed/math_hash.C index 2d460c5bbf..0461e9ddc3 100644 --- a/src/mathed/math_hash.C +++ b/src/mathed/math_hash.C @@ -11,9 +11,17 @@ namespace { latexkeys const wordlist[] = { //{"displaystyle", LM_TK_STY, LM_ST_DISPLAY, LMB_NONE}, + //{"oint", LM_TK_BIGSYM, LM_oint, LMB_NONE}, + //{"pmod", LM_TK_SYM, 0, LMB_NONE}, //{"scriptscriptstyle", LM_TK_STY, LM_ST_SCRIPTSCRIPT, LMB_NONE}, //{"scriptstyle", LM_TK_STY, LM_ST_SCRIPT, LMB_NONE}, //{"textstyle", LM_TK_STY, LM_ST_TEXT, LMB_NONE}, + {"#", LM_TK_SPECIAL, '#', LMB_NONE}, + {"$", LM_TK_SPECIAL, '$', LMB_NONE}, + {"%", LM_TK_SPECIAL, '%', LMB_NONE}, + {"&", LM_TK_SPECIAL, '&', LMB_NONE}, + {"(", LM_TK_BEGIN, LM_OT_SIMPLE, LMB_NONE}, + {")", LM_TK_END, LM_OT_SIMPLE, LMB_NONE}, {"Delta", LM_TK_SYM, LM_Delta, LMB_NONE}, {"Downarrow", LM_TK_SYM, LM_Downarrow, LMB_NONE}, {"Gamma", LM_TK_SYM, LM_Gamma, LMB_NONE}, @@ -38,6 +46,11 @@ latexkeys const wordlist[] = {"Upsilon", LM_TK_SYM, LM_Upsilon, LMB_NONE}, {"Vert", LM_TK_SYM, LM_Vert, LMB_NONE}, {"Xi", LM_TK_SYM, LM_Xi, LMB_NONE}, + {"[", LM_TK_BEGIN, LM_OT_EQUATION, LMB_NONE}, +// -1 needed in mathed_parse_lines! + {"\\", LM_TK_NEWLINE, static_cast(-1), LMB_NONE}, + {"]", LM_TK_END, LM_OT_EQUATION, LMB_NONE}, + {"_", LM_TK_SPECIAL, '_', LMB_NONE}, {"acute", LM_TK_DECORATION, LM_acute, LMB_NONE}, {"aleph", LM_TK_SYM, LM_aleph, LMB_NONE}, {"alpha", LM_TK_SYM, LM_alpha, LMB_NONE}, @@ -184,7 +197,6 @@ latexkeys const wordlist[] = {"nu", LM_TK_SYM, LM_nu, LMB_NONE}, {"nwarrow", LM_TK_SYM, LM_nwarrow, LMB_NONE}, {"odot", LM_TK_SYM, LM_odot, LMB_OPERATOR}, - //{"oint", LM_TK_BIGSYM, LM_oint, LMB_NONE}, {"omega", LM_TK_SYM, LM_omega, LMB_NONE}, {"ominus", LM_TK_SYM, LM_ominus, LMB_OPERATOR}, {"oplus", LM_TK_SYM, LM_oplus, LMB_OPERATOR}, @@ -200,7 +212,6 @@ latexkeys const wordlist[] = {"phi", LM_TK_SYM, LM_phi, LMB_NONE}, {"pi", LM_TK_SYM, LM_pi, LMB_NONE}, {"pm", LM_TK_SYM, LM_pm, LMB_OPERATOR}, - //{"pmod", LM_TK_SYM, 0, LMB_NONE}, {"prec", LM_TK_SYM, LM_prec, LMB_RELATION}, {"preceq", LM_TK_SYM, LM_preceq, LMB_RELATION}, {"prime", LM_TK_SYM, LM_prime, LMB_NONE}, @@ -280,6 +291,9 @@ latexkeys const wordlist[] = {"wr", LM_TK_SYM, LM_wr, LMB_OPERATOR}, {"xi", LM_TK_SYM, LM_xi, LMB_NONE}, {"zeta", LM_TK_SYM, LM_zeta, LMB_NONE}, + {"{", LM_TK_SPECIAL, '{', LMB_NONE}, + {"|", LM_TK_UNDEF, '|', LMB_NONE}, + {"}", LM_TK_SPECIAL, '}', LMB_NONE} }; diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index b5338a4be9..e34d3aa637 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -80,9 +80,6 @@ enum lexcode_enum { lexcode_enum lexcode[256]; -char const * latex_special_chars = "#$%&_{}"; - - namespace { void mathed_parse_into(MathArray & array, unsigned flags); @@ -286,34 +283,15 @@ int yylex() return LM_TK_CLOSE; } else if (lexcode[c] == LexESC) { c = getuchar(yyis); - if (c == '\\') { - yylval.i = -1; - return LM_TK_NEWLINE; - } - if (c == '(') { - yylval.i = LM_OT_SIMPLE; - return LM_TK_BEGIN; - } - if (c == ')') { - yylval.i = LM_OT_SIMPLE; - return LM_TK_END; - } - if (c == '[') { - yylval.i = LM_OT_EQUATION; - return LM_TK_BEGIN; - } - if (c == ']') { - yylval.i = LM_OT_EQUATION; - return LM_TK_END; - } - if (c == '|') { - yytext = "|"; - return LM_TK_UNDEF; + string s; + s += c; + latexkeys const * l = in_word_set(s); + if (l) { + //lyxerr << "found special token for '" << l->name + // << "' : " << l->id << " \n"; + yylval.i = l->id; + return l->token; } - if (contains(latex_special_chars, c)) { - yylval.i = c; - return LM_TK_SPECIAL; - } if (lexcode[c] == LexMathSpace) { int i; for (i = 0; i < 4 && static_cast(c) != latex_mathspace[i][0]; ++i) @@ -411,7 +389,9 @@ void mathed_parse_lines(MathGridInset * p, int col, bool numbered, bool outmost) m->label(row, curr_label); } - // Hack! +#ifdef WITH_WARNINGS +#warning Hack! +#endif // no newline if (yylval.i != -1) break; diff --git a/src/mathed/math_parser.h b/src/mathed/math_parser.h index 5cf3638ed4..7ebf014707 100644 --- a/src/mathed/math_parser.h +++ b/src/mathed/math_parser.h @@ -108,7 +108,7 @@ struct latexkeys { /// unsigned int id; /// - MathBinaryTypes bin; + int numargs; }; -- 2.39.2