help-source-highlight
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-source-highlight] Processing escape sequences


From: Lorenzo Bettini
Subject: Re: [Help-source-highlight] Processing escape sequences
Date: Mon, 22 Feb 2010 12:21:48 +0100
User-agent: Thunderbird 2.0.0.23 (X11/20090817)

Dario Teixeira wrote:
Hi,

I am using the Source-highlight library to perform a fairly straightforward
syntax highlighting task: given a string containing the source-code, and
another with the language definition, I want to return a string with the
highlighted version of source-code expressed in a custom "foobar" outlang.
In pseudo-C++, something like the code below:  (forget optimisations for now)

string highlight (string src, string langdef)
        {
        istringstream in (src);
        ostringstream out;
        SourceHighlight hiliter ("foobar.outlang");
        hiliter.highlight (in, out, langdef);
        return out.str ();
        }

In rough terms, this works.  There is however one big problem: any use of
escaping directives within the "src" (like "\n") is being processed, instead
of being written verbatim into the output string.  Is there any way to turn
off this behaviour?

Thanks in advance!
Best regards,
Dario Teixeira

Dear Dario

I'm not sure I understand what the final result should be, but in the outlang file you can specify some regular expression based translations. For instance, in latex.outlang you have

translations
"_" "$\\_$"
"{" "\\{"
"}" "\\}"
"<" "\\textless{}"
">" "\\textgreater{}"
"&" "\\&"
"\\" "\\textbackslash{}"
"^" "\\textasciicircum{}"
"~" "\\textasciitilde{}"
"\n" " \\\\\n"
" " "\\ "
"\t" "\\ \\ \\ \\ \\ \\ \\ \\ "
"%" "\\%"
"#" "\\#"
"$" "\\$"
"|" "$|$"
"---" "-\\/-\\/-"
"--" "-\\/-"
"\"" "\"{}" # avoids problems with some inputenc
end

in html_notfixed.outlang

translations
"\n" "<br>\n"
"  " "&nbsp; "
'^ ' "&nbsp;" # a space at the beginning of a line
"\t" "&nbsp; &nbsp; &nbsp; &nbsp; "
end

so probably you should be able to achieve your goal in your foobar.outlang file.

Please, let me know whether this solves this issue

cheers
        Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134     (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com  http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net




reply via email to

[Prev in Thread] Current Thread [Next in Thread]