Special tokens, ddoc, better highlighter colors
This commit is contained in:
parent
c7b84ca0cc
commit
9a6e765335
|
@ -17,6 +17,8 @@ void writeSpan(string cssClass, string value)
|
||||||
stdout.write(`<span class="`, cssClass, `">`, value.replace("&", "&").replace("<", "<"), `</span>`);
|
stdout.write(`<span class="`, cssClass, `">`, value.replace("&", "&").replace("<", "<"), `</span>`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// http://ethanschoonover.com/solarized
|
||||||
void highlight(R)(R tokens)
|
void highlight(R)(R tokens)
|
||||||
{
|
{
|
||||||
stdout.writeln(q"[<!DOCTYPE html>
|
stdout.writeln(q"[<!DOCTYPE html>
|
||||||
|
@ -25,13 +27,14 @@ void highlight(R)(R tokens)
|
||||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
|
||||||
<body>
|
<body>
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
html { background-color: #fff; color: #222; }
|
html { background-color: #fdf6e3; color: #002b36; }
|
||||||
.kwrd { font-weight: bold; color: blue; }
|
.kwrd { color: #b58900; font-weight: bold; }
|
||||||
.com { color: green; font-style: italic;}
|
.com { color: #93a1a1; font-style: italic; }
|
||||||
.num { color: orangered; font-weigth: bold; }
|
.num { color: #dc322f; font-weigth: bold; }
|
||||||
.str { color: red; font-style: italic; }
|
.str { color: #2aa198; font-style: italic; }
|
||||||
.op { color: 333; font-weight: bold; }
|
.op { color: #586e75; font-weight: bold; }
|
||||||
.type { color: magenta; font-weight: bold; }
|
.type { color: #268bd2; font-weight: bold; }
|
||||||
|
.cons { color: #859900; font-weight: bold; }
|
||||||
</style>
|
</style>
|
||||||
<pre>]");
|
<pre>]");
|
||||||
|
|
||||||
|
@ -49,6 +52,8 @@ html { background-color: #fff; color: #222; }
|
||||||
writeSpan("num", t.value);
|
writeSpan("num", t.value);
|
||||||
else if (t.type > TokenType.OPERATORS_BEGIN && t.type < TokenType.OPERATORS_END)
|
else if (t.type > TokenType.OPERATORS_BEGIN && t.type < TokenType.OPERATORS_END)
|
||||||
writeSpan("op", t.value);
|
writeSpan("op", t.value);
|
||||||
|
else if (t.type > TokenType.CONSTANTS_BEGIN && t.type < TokenType.CONSTANTS_END)
|
||||||
|
writeSpan("cons", t.value);
|
||||||
else
|
else
|
||||||
stdout.write(t.value.replace("<", "<"));
|
stdout.write(t.value.replace("<", "<"));
|
||||||
}
|
}
|
||||||
|
|
8
main.d
8
main.d
|
@ -160,13 +160,13 @@ int main(string[] args)
|
||||||
char[] buf;
|
char[] buf;
|
||||||
while (stdin.readln(buf))
|
while (stdin.readln(buf))
|
||||||
f.put(buf);
|
f.put(buf);
|
||||||
highlighter.highlight(f.data.byToken(IterationStyle.Everything,
|
highlighter.highlight(f.data.byToken("stdin", IterationStyle.Everything,
|
||||||
StringStyle.Source));
|
TokenStyle.Source));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
highlighter.highlight(args[1].readText().byToken(
|
highlighter.highlight(args[1].readText().byToken(args[1],
|
||||||
IterationStyle.Everything, StringStyle.Source));
|
IterationStyle.Everything, TokenStyle.Source));
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
858
std/d/lexer.d
858
std/d/lexer.d
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue