1
2 /******************************************************************************
3 * MODULE : verb_language.cpp
4 * DESCRIPTION: the "verbatim" language
5 * COPYRIGHT : (C) 1999 Joris van der Hoeven
6 *******************************************************************************
7 * This software falls under the GNU general public license version 3 or later.
8 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
9 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
10 ******************************************************************************/
11
12 #include "analyze.hpp"
13 #include "impl_language.hpp"
14 #include "scheme.hpp"
15 #include "packrat.hpp"
16
verb_language_rep(string name)17 verb_language_rep::verb_language_rep (string name):
18 language_rep (name)
19 {
20 hl_lan= packrat_abbreviation (res_name, "Main");
21 }
22
23 inline static bool
is_sep_char(char c)24 is_sep_char (char c) {
25 return c == '-' || c == '/' || c == ',' || c == '?';
26 }
27
28 text_property
advance(tree t,int & pos)29 verb_language_rep::advance (tree t, int& pos) {
30 string s= t->label;
31 if (pos==N(s)) return &tp_normal_rep;
32 if (s[pos]==' ') {
33 pos++;
34 return &tp_space_rep;
35 }
36 if (is_sep_char (s[pos])) {
37 pos++;
38 while (pos<N(s) && is_sep_char (s[pos]) && s[pos] != '-') pos++;
39 return &tp_hyph_rep;
40 }
41
42 array<int> cols= obtain_highlight (t, hl_lan);
43 if (N(cols) == 0)
44 while ((pos<N(s)) && (s[pos]!=' ') && !is_sep_char (s[pos])) pos++;
45 else if ((pos<N(s)) && (s[pos]!=' ') && !is_sep_char (s[pos])) {
46 pos++;
47 while ((pos<N(s)) && (s[pos]!=' ') && !is_sep_char (s[pos]) &&
48 cols[pos] == cols[pos-1]) pos++;
49 }
50 return &tp_normal_rep;
51 }
52
53 array<int>
get_hyphens(string s)54 verb_language_rep::get_hyphens (string s) {
55 int i;
56 array<int> penalty (N(s)+1);
57 for (i=0; i<N(penalty); i++) penalty[i]= HYPH_INVALID;
58 return penalty;
59 }
60
61 void
hyphenate(string s,int after,string & left,string & right)62 verb_language_rep::hyphenate (
63 string s, int after, string& left, string& right)
64 {
65 left = s(0, after);
66 right= s(after, N(s));
67 }
68
69
70 string
get_color(tree t,int start,int end)71 verb_language_rep::get_color (tree t, int start, int end) {
72 if (start >= end) return "";
73 array<int> cols= obtain_highlight (t, hl_lan);
74 if (start < N(cols) && cols[start] != 0)
75 return decode_color (res_name, cols[start]);
76 return "";
77 }
78
79 /******************************************************************************
80 * Interface
81 ******************************************************************************/
82
83 language
prog_language(string s)84 prog_language (string s) {
85 if (language::instances -> contains (s)) return language (s);
86 if (s == "scheme")
87 return make (language, s, tm_new<scheme_language_rep> (s));
88 if (s == "mathemagix" || s == "mmi" || s == "caas")
89 return make (language, s, tm_new<mathemagix_language_rep> (s));
90 if (s == "cpp")
91 return make (language, s, tm_new<cpp_language_rep> (s));
92 if (s == "scilab")
93 return make (language, s, tm_new<scilab_language_rep> (s));
94 if (s == "python")
95 return make (language, s, tm_new<python_language_rep> (s));
96 if ( s== "r")
97 return make (language, s, tm_new<r_language_rep> (s));
98 return make (language, s, tm_new<verb_language_rep> (s));
99 }
100