diff --git a/highlighter.d b/highlighter.d index 324712d..93ce5f2 100644 --- a/highlighter.d +++ b/highlighter.d @@ -17,6 +17,8 @@ void writeSpan(string cssClass, string value) stdout.write(``, value.replace("&", "&").replace("<", "<"), ``); } + +// http://ethanschoonover.com/solarized void highlight(R)(R tokens) { stdout.writeln(q"[ @@ -25,13 +27,14 @@ void highlight(R)(R tokens)
]");
@@ -49,6 +52,8 @@ html { background-color: #fff; color: #222; }
writeSpan("num", t.value);
else if (t.type > TokenType.OPERATORS_BEGIN && t.type < TokenType.OPERATORS_END)
writeSpan("op", t.value);
+ else if (t.type > TokenType.CONSTANTS_BEGIN && t.type < TokenType.CONSTANTS_END)
+ writeSpan("cons", t.value);
else
stdout.write(t.value.replace("<", "<"));
}
diff --git a/main.d b/main.d
index 848cd0a..55058f1 100644
--- a/main.d
+++ b/main.d
@@ -160,13 +160,13 @@ int main(string[] args)
char[] buf;
while (stdin.readln(buf))
f.put(buf);
- highlighter.highlight(f.data.byToken(IterationStyle.Everything,
- StringStyle.Source));
+ highlighter.highlight(f.data.byToken("stdin", IterationStyle.Everything,
+ TokenStyle.Source));
}
else
{
- highlighter.highlight(args[1].readText().byToken(
- IterationStyle.Everything, StringStyle.Source));
+ highlighter.highlight(args[1].readText().byToken(args[1],
+ IterationStyle.Everything, TokenStyle.Source));
}
return 0;
}
diff --git a/std/d/lexer.d b/std/d/lexer.d
index 840b76e..f05c531 100644
--- a/std/d/lexer.d
+++ b/std/d/lexer.d
@@ -1,7 +1,7 @@
// Written in the D programming language
/**
- * This module contains a range-based lexer for the D programming language.
+ * This module contains a range-based _lexer for the D programming language.
*
* Examples:
*
@@ -17,6 +17,7 @@
* stdout.write(``, value.replace("&", "&").replace("<", "<"), ``);
* }
*
+ * // http://ethanschoonover.com/solarized
* void highlight(R)(R tokens)
* {
* stdout.writeln(q"[
@@ -25,41 +26,62 @@
*
*
*
* ]");
*
- * foreach (Token t; tokens)
- * {
- * if (t.type > TokenType.TYPES_BEGIN && t.type < TokenType.TYPES_END)
- * writeSpan("type", t.value);
- * else if (t.type > TokenType.KEYWORDS_BEGIN && t.type < TokenType.KEYWORDS_END)
- * writeSpan("kwrd", t.value);
- * else if (t.type == TokenType.Comment)
- * writeSpan("com", t.value);
- * else if (t.type > TokenType.STRINGS_BEGIN && t.type < TokenType.STRINGS_END)
- * writeSpan("str", t.value);
- * else if (t.type > TokenType.NUMBERS_BEGIN && t.type < TokenType.NUMBERS_END)
- * writeSpan("num", t.value);
- * else if (t.type > TokenType.OPERATORS_BEGIN && t.type < TokenType.OPERATORS_END)
- * writeSpan("op", t.value);
- * else
- * stdout.write(t.value.replace("<", "<"));
- * }
- * stdout.writeln("\n");
+ * foreach (Token t; tokens)
+ * {
+ * if (t.type > TokenType.TYPES_BEGIN && t.type < TokenType.TYPES_END)
+ * writeSpan("type", t.value);
+ * else if (t.type > TokenType.KEYWORDS_BEGIN && t.type < TokenType.KEYWORDS_END)
+ * writeSpan("kwrd", t.value);
+ * else if (t.type == TokenType.Comment)
+ * writeSpan("com", t.value);
+ * else if (t.type > TokenType.STRINGS_BEGIN && t.type < TokenType.STRINGS_END)
+ * writeSpan("str", t.value);
+ * else if (t.type > TokenType.NUMBERS_BEGIN && t.type < TokenType.NUMBERS_END)
+ * writeSpan("num", t.value);
+ * else if (t.type > TokenType.OPERATORS_BEGIN && t.type < TokenType.OPERATORS_END)
+ * writeSpan("op", t.value);
+ * else
+ * stdout.write(t.value.replace("<", "<"));
+ * }
+ * stdout.writeln("\n