Mercurial > projects > dil
changeset 328:39f93a4ec416
- Added code for printing #line and filespec tokens.
- Added styles for #line and filespec.
author | aziz |
---|---|
date | Tue, 21 Aug 2007 17:56:00 +0000 |
parents | a48a987f7515 |
children | 17f43b0d6106 |
files | trunk/src/format.css trunk/src/main.d |
diffstat | 2 files changed, 45 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/trunk/src/format.css Tue Aug 21 16:49:00 2007 +0000 +++ b/trunk/src/format.css Tue Aug 21 17:56:00 2007 +0000 @@ -32,6 +32,10 @@ br { color: orange; } /* Special tokens */ st { color: green; font-weight: bold; } +/* #line, hash line */ +hl { color: green; } +/* filespec (e.g. #line number [filespec]) */ +fs { color: purple;} /* When the first line starts with #! it's a "shebang" */ shebang { color: gray; } /* Particular operators */
--- a/trunk/src/main.d Tue Aug 21 16:49:00 2007 +0000 +++ b/trunk/src/main.d Tue Aug 21 17:56:00 2007 +0000 @@ -157,6 +157,9 @@ SpecialToken, Shebang, Keyword, + HLineBegin, + HLineEnd, + Filespec, } auto html_tags = [ @@ -217,6 +220,12 @@ `<span class="shebang">%s</span>`, // Keyword `<span class="k">%s</span>`, + // HLineBegin + `<span class="hl">#line`, + // HLineEnd + "</span>", + // Filespec + `<span class="fs">%s</span>`, ]; auto xml_tags = [ @@ -274,6 +283,12 @@ "<shebang>%s</shebang>", // Keyword "<k>%s</k>", + // HLineBegin + "<hl>#line", + // HLineEnd + "</hl>", + // Filespec + "<fs>%s</fs>", ]; static assert(html_tags.length == DocPart.max+1); @@ -408,7 +423,7 @@ // Print whitespace between previous and current token. if (end != token.start) - writef("%s", xml_escape(end[0 .. token.start - end])); + writef("%s", end[0 .. token.start - end]); printToken(token, tags); end = token.end; } @@ -508,7 +523,31 @@ writef(tags[DP.Shebang], srcText); break; case TOK.HashLine: - writef("<hl>%s</hl>", srcText); + void printWS(char* start, char* end) + { + if (start != end) + writef(start[0 .. end - start]); + } + writef(tags[DP.HLineBegin]); + auto num = token.line_num; + // Print whitespace between #line and number + auto ptr = token.start + "#line".length; + printWS(ptr, num.start); + printToken(num, tags); + if (token.line_filespec) + { + auto filespec = token.line_filespec; + // Print whitespace between number and filespec + printWS(num.end, filespec.start); + writef(tags[DP.Filespec], xml_escape(filespec.srcText)); + + ptr = filespec.end; + } + else + ptr = num.end; + // Print remaining whitespace + printWS(ptr, token.end); + writef(tags[DP.HLineEnd]); break; default: if (token.isKeyword())