Back to index

texmacs  1.0.7.15
scheme_language.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : scheme_language.cpp
00004 * DESCRIPTION: the "scheme" language
00005 * COPYRIGHT  : (C) 2007  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 
00016 scheme_language_rep::scheme_language_rep (string name):
00017   language_rep (name), colored ("")
00018 {
00019   eval ("(use-modules (utils misc tm-keywords))");
00020   list<string> l= as_list_string (eval ("(map symbol->string highlight-any)"));
00021   while (!is_nil (l)) {
00022     colored (l->item)= "#309090";
00023     l= l->next;
00024   }
00025 }
00026 
00027 text_property
00028 scheme_language_rep::advance (tree t, int& pos) {
00029   string s= t->label;
00030   if (pos==N(s)) return &tp_normal_rep;
00031   switch (s[pos]) {
00032   case ' ':
00033     pos++;
00034     return &tp_space_rep;
00035   case '(':
00036   case ')':
00037     pos++;
00038     return &tp_normal_rep;
00039   }
00040   while ((pos<N(s)) && (s[pos]!=' ') && (s[pos]!='(') && (s[pos]!=')')) pos++;
00041   if (pos < N(s) && pos >= 2 && (s[pos] == '(' || s[pos] == ')'))
00042     if (s[pos-2] == '#' && s[pos-1] == '\\') pos++;
00043   return &tp_normal_rep;
00044 }
00045 
00046 array<int>
00047 scheme_language_rep::get_hyphens (string s) {
00048   int i;
00049   array<int> penalty (N(s)+1);
00050   penalty[0]= HYPH_INVALID;
00051   for (i=1; i<N(s); i++)
00052     if (s[i-1] == '-' && is_alpha (s[i]))
00053       penalty[i]= HYPH_STD;
00054     else penalty[i]= HYPH_INVALID;
00055   penalty[i]= HYPH_INVALID;
00056   return penalty;
00057 }
00058 
00059 void
00060 scheme_language_rep::hyphenate (
00061   string s, int after, string& left, string& right)
00062 { 
00063   left = s(0, after);
00064   right= s(after, N(s));
00065 }
00066 
00067 string
00068 scheme_language_rep::get_color (tree t, int start, int end) {
00069   static string none= "";
00070   if (start >= end) return none;
00071   string s= t->label;
00072   for (int i= max (0, start-1000); i <= start; i++)
00073     switch (s[i]) {
00074     case ';': return "brown";
00075     case '\042':
00076       i++;
00077       while (i <= start && s[i] != '\042')
00078        if (s[i] == '\\' && i < start) i += 2;
00079        else i++;
00080       if (i >= start) return "dark grey";
00081       break;
00082     }
00083   if (is_numeric (s[start]) || s[start] == '\042' || s[start] == '#')
00084     return "dark grey";
00085   if (s[start] == ':') return "dark magenta";
00086   string r= s (start, end);
00087   if (!colored->contains (r)) {
00088     colored (r)= "";
00089     if (as_bool (call ("defined?", symbol_object (tm_decode (r)))))
00090       colored (r)= "#204080";
00091   }
00092   return colored[r];
00093 }