Back to index

texmacs  1.0.7.15
verb_language.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : verb_language.cpp
00004 * DESCRIPTION: the "verbatim" language
00005 * COPYRIGHT  : (C) 1999  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #include "analyze.hpp"
00013 #include "impl_language.hpp"
00014 #include "scheme.hpp"
00015 #include "packrat.hpp"
00016 
00017 verb_language_rep::verb_language_rep (string name):
00018   language_rep (name)
00019 {
00020   hl_lan= packrat_abbreviation (res_name, "Main");
00021 }
00022 
00023 text_property
00024 verb_language_rep::advance (tree t, int& pos) {
00025   string s= t->label;
00026   if (pos==N(s)) return &tp_normal_rep;
00027   if (s[pos]==' ') {
00028     pos++;
00029     return &tp_space_rep;
00030   }
00031   if (s[pos]=='-') {
00032     pos++;
00033     return &tp_hyph_rep;
00034   }
00035 
00036   array<int> cols= obtain_highlight (t, hl_lan);
00037   if (N(cols) == 0)
00038     while ((pos<N(s)) && (s[pos]!=' ') && (s[pos]!='-')) pos++;
00039   else if ((pos<N(s)) && (s[pos]!=' ') && (s[pos]!='-')) {
00040     pos++;
00041     while ((pos<N(s)) && (s[pos]!=' ') && (s[pos]!='-') &&
00042           cols[pos] == cols[pos-1]) pos++;
00043   }
00044   return &tp_normal_rep;
00045 }
00046 
00047 array<int>
00048 verb_language_rep::get_hyphens (string s) {
00049   int i;
00050   array<int> penalty (N(s)+1);
00051   for (i=0; i<N(penalty); i++) penalty[i]= HYPH_INVALID;
00052   return penalty;
00053 }
00054 
00055 void
00056 verb_language_rep::hyphenate (
00057   string s, int after, string& left, string& right)
00058 { 
00059   left = s(0, after);
00060   right= s(after, N(s));
00061 }
00062 
00063 
00064 string
00065 verb_language_rep::get_color (tree t, int start, int end) {
00066   if (start >= end) return "";
00067   array<int> cols= obtain_highlight (t, hl_lan);
00068   if (start < N(cols) && cols[start] != 0)
00069     return decode_color (cols[start]);
00070   return "";
00071 }
00072 
00073 /******************************************************************************
00074 * Interface
00075 ******************************************************************************/
00076 
00077 language
00078 prog_language (string s) {
00079   if (language::instances -> contains (s)) return language (s);
00080   if (s == "scheme")
00081     return make (language, s, tm_new<scheme_language_rep> (s));
00082   if (s == "mathemagix")
00083     return make (language, s, tm_new<mathemagix_language_rep> (s));
00084   if (s == "cpp")
00085     return make (language, s, tm_new<cpp_language_rep> (s));
00086   return make (language, s, tm_new<verb_language_rep> (s));
00087 }