Back to index

texmacs  1.0.7.15
language.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : language.cpp
00004 * COPYRIGHT  : (C) 1999  Joris van der Hoeven
00005 *******************************************************************************
00006 * This software falls under the GNU general public license version 3 or later.
00007 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00008 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00009 ******************************************************************************/
00010 
00011 #include "impl_language.hpp"
00012 #include "packrat.hpp"
00013 
00014 RESOURCE_CODE(language);
00015 
00016 text_property_rep global_tpr;
00017 
00018 text_property_rep tp_normal_rep (TP_NORMAL);
00019 text_property_rep tp_hyph_rep (TP_HYPH, SPC_NONE, SPC_NONE, 0, 0);
00020 text_property_rep tp_space_rep (TP_SPACE, SPC_NONE, SPC_SPACE, 0,0);
00021 text_property_rep tp_dspace_rep (TP_DSPACE, SPC_NONE, SPC_DSPACE, 0,0);
00022 text_property_rep tp_period_rep (TP_PERIOD, SPC_NONE, SPC_PERIOD, 0, 0);
00023 text_property_rep tp_blank_rep
00024   (TP_BLANK, SPC_NONE, SPC_SPACE, 0, HYPH_INVALID);
00025 text_property_rep tp_half_rep
00026   (TP_OPERATOR, SPC_NONE, SPC_HALF, 0, HYPH_INVALID);
00027 text_property_rep tp_operator_rep
00028   (TP_OPERATOR, SPC_NONE, SPC_OPERATOR, 0, HYPH_INVALID);
00029 text_property_rep tp_shortop_rep
00030   (TP_SHORTOP, SPC_NONE, SPC_TINY, 0, HYPH_INVALID);
00031 
00032 /******************************************************************************
00033 * Text properties
00034 ******************************************************************************/
00035 
00036 text_property_rep::text_property_rep (
00037   int type2, int spc_before2, int spc_after2,
00038   int pen_before2, int pen_after2,
00039   int op_type2, int priority2, int limits2):
00040     type (type2),
00041     spc_before (spc_before2), spc_after (spc_after2),
00042     pen_before (pen_before2), pen_after (pen_after2),
00043     op_type (op_type2), priority (priority2), limits (limits2) {}
00044 
00045 bool
00046 operator == (text_property_rep tpr1, text_property_rep tpr2) {
00047   return
00048     (tpr1.type == tpr2.type) &&
00049     (tpr1.spc_before == tpr2.spc_before) &&
00050     (tpr1.spc_after == tpr2.spc_after) &&
00051     (tpr1.pen_before == tpr2.pen_before) &&
00052     (tpr1.pen_after == tpr2.pen_after) &&
00053     (tpr1.op_type == tpr2.op_type) &&
00054     (tpr1.priority == tpr2.priority) &&
00055     (tpr1.limits == tpr2.limits);
00056 }
00057 
00058 bool
00059 operator != (text_property_rep tpr1, text_property_rep tpr2) {
00060   return !(tpr1 == tpr2);
00061 }
00062 
00063 /******************************************************************************
00064 * Initialized the allowed successions of mathematical operators
00065 ******************************************************************************/
00066 
00067 int succession_status_table [OP_TOTAL * OP_TOTAL];
00068 
00069 /*
00070 int
00071 succession_status (int op1, int op2) {
00072   cout << "Check " << op1 << ":" << op2 << " -> " <<
00073     succession_status_table [op1 * OP_TOTAL + op2] << "\n";
00074   return succession_status_table [op1 * OP_TOTAL + op2];
00075 }
00076 */
00077 
00078 static inline void set_status (int op1, int op2, int st) {
00079   succession_status_table [op1 * OP_TOTAL + op2]= st; }
00080 
00081 static inline void init_could_end (int op) {
00082   set_status (op, OP_UNARY, REMOVE_CURRENT_SPACE);
00083   set_status (op, OP_N_ARY, REMOVE_CURRENT_SPACE);
00084   set_status (op, OP_PREFIX, REMOVE_CURRENT_SPACE);
00085   set_status (op, OP_BIG, REMOVE_CURRENT_SPACE);
00086 }
00087 
00088 static inline void init_expect_after (int op) {
00089   set_status (op, OP_TEXT, REMOVE_CURRENT_SPACE);
00090   set_status (op, OP_BINARY, REMOVE_SPACE_BEFORE);
00091   set_status (op, OP_POSTFIX, REMOVE_CURRENT_SPACE);
00092   set_status (op, OP_INFIX, REMOVE_CURRENT_SPACE);
00093   set_status (op, OP_APPLY, REMOVE_SPACE_BEFORE);
00094   set_status (op, OP_SEPARATOR, REMOVE_SPACE_BEFORE);
00095   set_status (op, OP_MIDDLE_BRACKET, REMOVE_SPACE_BEFORE);
00096   set_status (op, OP_CLOSING_BRACKET, REMOVE_SPACE_BEFORE);
00097 }
00098 
00099 static inline void init_expect_space (int op) {
00100   set_status (op, OP_TEXT, REMOVE_CURRENT_SPACE);
00101   set_status (op, OP_SYMBOL, REMOVE_SPACE_BEFORE);
00102   set_status (op, OP_UNARY, REMOVE_SPACE_BEFORE);
00103   set_status (op, OP_BINARY, REMOVE_SPACE_BEFORE);
00104   set_status (op, OP_N_ARY, REMOVE_SPACE_BEFORE);
00105   set_status (op, OP_PREFIX, REMOVE_SPACE_BEFORE);
00106   set_status (op, OP_POSTFIX, REMOVE_SPACE_BEFORE);
00107   set_status (op, OP_INFIX, REMOVE_SPACE_BEFORE);
00108   set_status (op, OP_SEPARATOR, REMOVE_SPACE_BEFORE);
00109   set_status (op, OP_MIDDLE_BRACKET, REMOVE_SPACE_BEFORE);
00110   set_status (op, OP_CLOSING_BRACKET, REMOVE_SPACE_BEFORE);
00111   set_status (op, OP_BIG, REMOVE_SPACE_BEFORE);
00112 }
00113 
00114 void
00115 init_succession_status_table () {
00116   for (int i=0; i < (OP_TOTAL * OP_TOTAL); i++)
00117     succession_status_table[i]= SUCCESSION_OK;
00118 
00119   for (int i=0; i<OP_TOTAL; i++) {
00120     set_status (OP_UNKNOWN, i, REMOVE_ALL_SPACE);
00121     set_status (i, OP_UNKNOWN, REMOVE_ALL_SPACE);
00122   }
00123 
00124   init_expect_after (OP_TEXT);
00125   init_could_end    (OP_SYMBOL);
00126   init_expect_space (OP_UNARY);
00127   init_expect_space (OP_BINARY);
00128   init_expect_space (OP_N_ARY);
00129   init_expect_after (OP_PREFIX);
00130   init_could_end    (OP_POSTFIX);
00131   init_expect_after (OP_INFIX);
00132   init_expect_after (OP_APPLY);
00133   init_expect_after (OP_SEPARATOR);
00134   init_expect_after (OP_OPENING_BRACKET);
00135   init_expect_after (OP_MIDDLE_BRACKET);
00136   init_could_end    (OP_CLOSING_BRACKET);
00137   init_expect_after (OP_BIG);
00138   set_status (OP_APPLY, OP_BINARY, SUCCESSION_OK);
00139   set_status (OP_OPENING_BRACKET, OP_CLOSING_BRACKET, SUCCESSION_OK);
00140 }
00141 
00142 /******************************************************************************
00143 * Default group of a string
00144 ******************************************************************************/
00145 
00146 language_rep::language_rep (string s):
00147   rep<language> (s), hl_lan (0) {}
00148 
00149 string
00150 language_rep::get_group (string s) {
00151   (void) s;
00152   return "default";
00153 }
00154 
00155 array<string>
00156 language_rep::get_members (string s) {
00157   (void) s;
00158   return array<string> ();
00159 }
00160 
00161 void
00162 language_rep::highlight (tree t) {
00163   if (hl_lan != 0 && !has_highlight (t, hl_lan))
00164     packrat_highlight (res_name, "Main", t);
00165 }
00166 
00167 string
00168 language_rep::get_color (tree t, int start, int end) {
00169   (void) t; (void) start; (void) end;
00170   return "";
00171 }