]> sourceware.org Git - systemtap.git/commitdiff
token colorizer: eschew tok_embedded etc. types
authorFrank Ch. Eigler <fche@redhat.com>
Tue, 9 Jul 2013 19:19:10 +0000 (15:19 -0400)
committerFrank Ch. Eigler <fche@redhat.com>
Tue, 9 Jul 2013 19:21:46 +0000 (15:21 -0400)
When printing source context for an error, we don't really know how
many characters from the source to highlight for any given token, as
that only stores the starting column position.

The tok->content.size() is a guide, but not a perfect one, as for some
(tok_string, tok_embedded, ...), the content is processed from the
source characters (with quotation signs removed, etc.), for others,
the tok->content() can be many lines long.  That's a problem because
if we try to source_line.substr(..., long_multiline_token.length()...),
we'll get a SEGV.

So we colorize only those tokens whose type is known to be simple and
literal transcriptions of the source file, starting at
column=tok->column.

session.cxx

index f61ea6e1579eff7345ace81a85c10311f5bb3e5e..a4ec4b7d75783fa1b7ce58d2f9ba808ffcd9d36a 100644 (file)
@@ -1917,11 +1917,18 @@ systemtap_session::print_error_source (std::ostream& message,
   //TRANSLATORS: Here we are printing the source string of the error
   message << align << _("source: ");
   string srcline = file_contents.substr(start_pos, end_pos-start_pos-1);
-  if (color_errors) {
+  if (color_errors &&
+      // Only colorize tokens whose content is known to match the source
+      // content.  e.g. tok_string doesn't qualify because of the double-quotes.
+      // tok_embedded lacks the %{ %}. tok_junk is just junky.
+      (tok->type == tok_number ||
+       tok->type == tok_identifier || 
+       tok->type == tok_operator)) {
     // Split into before token, token, and after token
+    string tok_content = tok->content;
     message << srcline.substr(0, col-1);
-    message << colorize(tok->content, "token");
-    message << srcline.substr(col+tok->content.size()-1) << endl;
+    message << colorize(tok_content, "token");
+    message << srcline.substr(col+tok_content.size()-1) << endl;
   } else
     message << srcline << endl;
   message << align << "        ";
This page took 0.033634 seconds and 5 git commands to generate.