From fc13a4d45a23a5f02cbbfe024bfe72fc54fd4a38 Mon Sep 17 00:00:00 2001 From: alvinrdeleon Date: Wed, 20 May 2015 05:35:37 +0800 Subject: [PATCH] added support for pretty print. --- .../jspringbot/syntax/HighlighterUtils.java | 122 +- .../java/syntaxhighlight/ParseResult.java | 175 + .../src/main/java/syntaxhighlight/Parser.java | 42 + .../src/main/java/syntaxhighlight/Style.java | 229 + .../src/main/java/syntaxhighlight/Theme.java | 423 ++ .../SyntaxHighlighterParser.java | 143 + .../java/syntaxhighlighter/brush/Brush.java | 159 + .../syntaxhighlighter/brush/BrushAS3.java | 64 + .../brush/BrushAppleScript.java | 62 + .../syntaxhighlighter/brush/BrushBash.java | 67 + .../syntaxhighlighter/brush/BrushCSharp.java | 62 + .../brush/BrushColdFusion.java | 105 + .../syntaxhighlighter/brush/BrushCpp.java | 108 + .../syntaxhighlighter/brush/BrushCss.java | 91 + .../syntaxhighlighter/brush/BrushDelphi.java | 62 + .../syntaxhighlighter/brush/BrushDiff.java | 48 + .../syntaxhighlighter/brush/BrushErlang.java | 56 + .../syntaxhighlighter/brush/BrushGroovy.java | 74 + .../syntaxhighlighter/brush/BrushJScript.java | 57 + .../syntaxhighlighter/brush/BrushJava.java | 61 + .../syntaxhighlighter/brush/BrushJavaFX.java | 64 + .../syntaxhighlighter/brush/BrushPerl.java | 76 + .../syntaxhighlighter/brush/BrushPhp.java | 93 + .../syntaxhighlighter/brush/BrushPlain.java | 32 + .../brush/BrushPowerShell.java | 81 + .../syntaxhighlighter/brush/BrushPython.java | 69 + .../syntaxhighlighter/brush/BrushRuby.java | 63 + .../syntaxhighlighter/brush/BrushSass.java | 105 + .../syntaxhighlighter/brush/BrushScala.java | 58 + .../syntaxhighlighter/brush/BrushSql.java | 70 + .../java/syntaxhighlighter/brush/BrushVb.java | 63 + .../syntaxhighlighter/brush/BrushXml.java | 71 + .../brush/HTMLScriptRegExp.java | 134 + .../syntaxhighlighter/brush/RegExpRule.java | 246 + .../syntaxhighlighter/brush/package-info.java | 4 + .../syntaxhighlighter/parser/MatchResult.java | 136 + .../parser/SyntaxHighlighter.java | 255 + .../parser/package-info.java | 4 + .../syntaxhighlighter/theme/ThemeDefault.java | 111 + .../syntaxhighlighter/theme/ThemeDjango.java | 112 + .../syntaxhighlighter/theme/ThemeEclipse.java | 114 + .../syntaxhighlighter/theme/ThemeEmacs.java | 113 + .../theme/ThemeFadeToGrey.java | 114 + .../syntaxhighlighter/theme/ThemeMDUltra.java | 113 + .../theme/ThemeMidnight.java | 113 + .../syntaxhighlighter/theme/ThemeRDark.java | 113 + .../syntaxhighlighter/theme/package-info.java | 4 + .../src/main/resources/pygments/__init__.py | 91 - .../src/main/resources/pygments/cmdline.py | 433 -- .../src/main/resources/pygments/console.py | 74 - .../src/main/resources/pygments/filter.py | 74 - .../resources/pygments/filters/__init__.py | 357 -- .../src/main/resources/pygments/formatter.py | 92 - .../resources/pygments/formatters/__init__.py | 68 - .../resources/pygments/formatters/_mapping.py | 92 - .../resources/pygments/formatters/bbcode.py | 109 - .../resources/pygments/formatters/html.py | 750 --- .../main/resources/pygments/formatters/img.py | 553 -- .../resources/pygments/formatters/latex.py | 378 -- .../resources/pygments/formatters/other.py | 117 - .../main/resources/pygments/formatters/rtf.py | 136 - .../main/resources/pygments/formatters/svg.py | 154 - .../resources/pygments/formatters/terminal.py | 112 - .../pygments/formatters/terminal256.py | 222 - .../src/main/resources/pygments/lexer.py | 697 --- .../resources/pygments/lexers/__init__.py | 229 - .../resources/pygments/lexers/_asybuiltins.py | 1645 ----- .../resources/pygments/lexers/_clbuiltins.py | 232 - .../pygments/lexers/_lassobuiltins.py | 5413 ----------------- .../resources/pygments/lexers/_luabuiltins.py | 249 - .../resources/pygments/lexers/_mapping.py | 312 - .../resources/pygments/lexers/_phpbuiltins.py | 3787 ------------ .../pygments/lexers/_postgres_builtins.py | 232 - .../pygments/lexers/_scilab_builtins.py | 29 - .../resources/pygments/lexers/_vimbuiltins.py | 3 - .../main/resources/pygments/lexers/agile.py | 1815 ------ .../src/main/resources/pygments/lexers/asm.py | 360 -- .../resources/pygments/lexers/compiled.py | 3038 --------- .../main/resources/pygments/lexers/dotnet.py | 630 -- .../resources/pygments/lexers/functional.py | 2395 -------- .../src/main/resources/pygments/lexers/hdl.py | 356 -- .../src/main/resources/pygments/lexers/jvm.py | 932 --- .../main/resources/pygments/lexers/math.py | 1388 ----- .../main/resources/pygments/lexers/other.py | 3480 ----------- .../main/resources/pygments/lexers/parsers.py | 695 --- .../main/resources/pygments/lexers/shell.py | 364 -- .../main/resources/pygments/lexers/special.py | 100 - .../src/main/resources/pygments/lexers/sql.py | 559 -- .../resources/pygments/lexers/templates.py | 1733 ------ .../main/resources/pygments/lexers/text.py | 1759 ------ .../src/main/resources/pygments/lexers/web.py | 3183 ---------- .../src/main/resources/pygments/plugin.py | 74 - .../src/main/resources/pygments/scanner.py | 104 - .../src/main/resources/pygments/style.py | 117 - .../resources/pygments/styles/__init__.py | 70 - .../main/resources/pygments/styles/autumn.py | 65 - .../main/resources/pygments/styles/borland.py | 51 - .../src/main/resources/pygments/styles/bw.py | 49 - .../resources/pygments/styles/colorful.py | 81 - .../main/resources/pygments/styles/default.py | 73 - .../main/resources/pygments/styles/emacs.py | 72 - .../resources/pygments/styles/friendly.py | 72 - .../main/resources/pygments/styles/fruity.py | 42 - .../main/resources/pygments/styles/manni.py | 75 - .../main/resources/pygments/styles/monokai.py | 106 - .../main/resources/pygments/styles/murphy.py | 80 - .../main/resources/pygments/styles/native.py | 65 - .../main/resources/pygments/styles/pastie.py | 75 - .../main/resources/pygments/styles/perldoc.py | 69 - .../src/main/resources/pygments/styles/rrt.py | 33 - .../main/resources/pygments/styles/tango.py | 141 - .../main/resources/pygments/styles/trac.py | 63 - .../src/main/resources/pygments/styles/vim.py | 63 - .../src/main/resources/pygments/styles/vs.py | 38 - .../src/main/resources/pygments/token.py | 195 - .../src/main/resources/pygments/unistring.py | 140 - .../src/main/resources/pygments/util.py | 277 - .../spring/jspringbot-hightlight.xml | 12 +- .../syntax/HighlighterUtilsTest.java | 3 +- .../src/test/resources/jspringbot.properties | 2 + .../src/test/resources/log4j.properties | 8 + pom.xml | 10 + 122 files changed, 4758 insertions(+), 41735 deletions(-) create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlight/ParseResult.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlight/Parser.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlight/Style.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlight/Theme.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/SyntaxHighlighterParser.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/Brush.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushAS3.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushAppleScript.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushBash.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushCSharp.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushColdFusion.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushCpp.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushCss.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushDelphi.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushDiff.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushErlang.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushGroovy.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushJScript.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushJava.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushJavaFX.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushPerl.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushPhp.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushPlain.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushPowerShell.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushPython.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushRuby.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushSass.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushScala.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushSql.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushVb.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushXml.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/HTMLScriptRegExp.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/RegExpRule.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/package-info.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/parser/MatchResult.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/parser/SyntaxHighlighter.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/parser/package-info.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/theme/ThemeDefault.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/theme/ThemeDjango.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/theme/ThemeEclipse.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/theme/ThemeEmacs.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/theme/ThemeFadeToGrey.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/theme/ThemeMDUltra.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/theme/ThemeMidnight.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/theme/ThemeRDark.java create mode 100755 jspringbot-pretty-logger/src/main/java/syntaxhighlighter/theme/package-info.java delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/__init__.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/cmdline.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/console.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/filter.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/filters/__init__.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/formatter.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/formatters/__init__.py delete mode 100755 jspringbot-pretty-logger/src/main/resources/pygments/formatters/_mapping.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/formatters/bbcode.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/formatters/html.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/formatters/img.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/formatters/latex.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/formatters/other.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/formatters/rtf.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/formatters/svg.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/formatters/terminal.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/formatters/terminal256.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/lexer.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/lexers/__init__.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/lexers/_asybuiltins.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/lexers/_clbuiltins.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/lexers/_lassobuiltins.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/lexers/_luabuiltins.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/lexers/_mapping.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/lexers/_phpbuiltins.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/lexers/_postgres_builtins.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/lexers/_scilab_builtins.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/lexers/_vimbuiltins.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/lexers/agile.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/lexers/asm.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/lexers/compiled.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/lexers/dotnet.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/lexers/functional.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/lexers/hdl.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/lexers/jvm.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/lexers/math.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/lexers/other.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/lexers/parsers.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/lexers/shell.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/lexers/special.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/lexers/sql.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/lexers/templates.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/lexers/text.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/lexers/web.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/plugin.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/scanner.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/style.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/styles/__init__.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/styles/autumn.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/styles/borland.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/styles/bw.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/styles/colorful.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/styles/default.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/styles/emacs.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/styles/friendly.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/styles/fruity.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/styles/manni.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/styles/monokai.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/styles/murphy.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/styles/native.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/styles/pastie.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/styles/perldoc.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/styles/rrt.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/styles/tango.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/styles/trac.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/styles/vim.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/styles/vs.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/token.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/unistring.py delete mode 100644 jspringbot-pretty-logger/src/main/resources/pygments/util.py create mode 100644 jspringbot-pretty-logger/src/test/resources/jspringbot.properties create mode 100644 jspringbot-pretty-logger/src/test/resources/log4j.properties diff --git a/jspringbot-pretty-logger/src/main/java/org/jspringbot/syntax/HighlighterUtils.java b/jspringbot-pretty-logger/src/main/java/org/jspringbot/syntax/HighlighterUtils.java index 6f1fac7..76d5e41 100644 --- a/jspringbot-pretty-logger/src/main/java/org/jspringbot/syntax/HighlighterUtils.java +++ b/jspringbot-pretty-logger/src/main/java/org/jspringbot/syntax/HighlighterUtils.java @@ -18,12 +18,21 @@ package org.jspringbot.syntax; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.StringEscapeUtils; -import org.python.core.PySystemState; -import org.python.util.PythonInterpreter; - +import org.apache.commons.lang.StringUtils; +import syntaxhighlight.ParseResult; +import syntaxhighlight.Style; +import syntaxhighlight.Theme; +import syntaxhighlighter.SyntaxHighlighterParser; +import syntaxhighlighter.brush.*; +import syntaxhighlighter.theme.*; + +import java.awt.*; import java.io.IOException; import java.io.StringWriter; +import java.util.HashMap; +import java.util.Map; import java.util.Properties; /** @@ -31,21 +40,52 @@ */ public class HighlighterUtils { + public static final String DEFAULT_THEME = "default"; + + public static final Map THEME_MAP = new HashMap() {{ + put(DEFAULT_THEME, new ThemeDefault()); + put("django", new ThemeDjango()); + put("eclipse", new ThemeEclipse()); + put("emacs", new ThemeEmacs()); + put("grey", new ThemeFadeToGrey()); + put("mdultra", new ThemeMDUltra()); + put("midnight", new ThemeMidnight()); + put("rdark", new ThemeRDark()); + }}; + + public static final HighlighterUtils INSTANCE = new HighlighterUtils(); public static HighlighterUtils instance() { return INSTANCE; } - private PythonInterpreter interpreter; - private boolean enable = false; + private Theme theme; + + private Map parserMap; + private HighlighterUtils() { - PySystemState sys = new PySystemState(); - sys.setrecursionlimit(12000); + parserMap = new HashMap(); + + parserMap.put("xml", new SyntaxHighlighterParser(new BrushXml())); + parserMap.put("css", new SyntaxHighlighterParser(new BrushCss())); + parserMap.put("json", new SyntaxHighlighterParser(new BrushJScript())); + parserMap.put("javascript", new SyntaxHighlighterParser(new BrushJScript())); + parserMap.put("sql", new SyntaxHighlighterParser(new BrushSql())); + parserMap.put("text", new SyntaxHighlighterParser(new BrushPlain())); + parserMap.put("clojure", new SyntaxHighlighterParser(new BrushJScript())); + + theme = THEME_MAP.get(DEFAULT_THEME); + } + + public void setTheme(String theme) { + this.theme = THEME_MAP.get(theme); - interpreter = new PythonInterpreter(null, sys); + if(this.theme == null) { + this.theme = THEME_MAP.get(DEFAULT_THEME); + } } public void setEnable(boolean enable) { @@ -99,15 +139,65 @@ public String highlight(String code, String type, boolean linenumber) { return "\n" + StringEscapeUtils.escapeHtml(code); } - interpreter.set("code", code); - interpreter.set("type", type); + SyntaxHighlighterParser parser = parserMap.get(type); + if(parser == null) { + return "\n" + StringEscapeUtils.escapeHtml(code); + } + + int i = 0; + StringBuilder buf = new StringBuilder(); + + for (ParseResult result : parser.parse(code)) { + String before = StringUtils.substring(code, i, result.getOffset()); + if (StringUtils.isNotBlank(before)) { + buf.append(StringEscapeUtils.escapeHtml(before)); + } + + String token = StringUtils.substring(code, result.getOffset(), result.getOffset() + result.getLength()); + buf.append(""); + buf.append(token); + buf.append(""); + } + + return buf.toString(); + } - interpreter.exec("from pygments import highlight\n" + - "from pygments.lexers import get_lexer_by_name\n" + - "from pygments.formatters import HtmlFormatter\n" + - "formatter = HtmlFormatter(cssclass=\"syntax\"" + (linenumber ? ",linenos=\"table\"" : "") + ")\n" + - "result = highlight(code, get_lexer_by_name(type), formatter)\n"); + private static void cssColor(StringBuilder buf, String style, Color color) { + String rgb = Integer.toHexString(color.getRGB()); + rgb = rgb.substring(2, rgb.length()); - return String.valueOf(interpreter.get("result")) + ""; + buf.append(style).append(":#").append(StringUtils.lowerCase(rgb)).append(";"); } } diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlight/ParseResult.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlight/ParseResult.java new file mode 100755 index 0000000..a283355 --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlight/ParseResult.java @@ -0,0 +1,175 @@ +// Copyright (c) 2012 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlight; + +import java.util.ArrayList; +import java.util.List; + +/** + * The parser parsed result. + * + * This class include the information needed to highlight the syntax. + * Information includes where the content located in the document (offset and + * length) and what style(s) should be applied on that segment of content. + * + * @author Chan Wai Shing + */ +public class ParseResult { + + /** + * The start position of the content. + */ + protected int offset; + /** + * The length of the content. + */ + protected int length; + /** + * The style keys of the content. The style at higher index of the list will + * override the style of the lower index. + */ + protected List styleKeys; + + /** + * Constructor. + * + * @param offset the start position of the content + * @param length the length of the content + * @param styleKeys the style keys of the content + */ + public ParseResult(int offset, int length, List styleKeys) { + this.offset = offset; + this.length = length; + this.styleKeys = new ArrayList(styleKeys); + } + + /** + * The start position of the content. + * @return the start position of the content + */ + public int getOffset() { + return offset; + } + + /** + * The start position of the content. + * @param offset the start position of the content + */ + public void setOffset(int offset) { + this.offset = offset; + } + + /** + * The length of the content. + * @return the length of the content + */ + public int getLength() { + return length; + } + + /** + * The length of the content. + * @param length the length of the content + */ + public void setLength(int length) { + this.length = length; + } + + /** + * Get the style keys represented by one string key, see + * {@link Theme#getStylesAttributeSet(String)}. + * @return the style keys of the content + */ + public String getStyleKeysString() { + StringBuilder sb = new StringBuilder(10); + for (int i = 0, iEnd = styleKeys.size(); i < iEnd; i++) { + if (i != 0) { + sb.append(" "); + } + sb.append(styleKeys.get(i)); + } + return sb.toString(); + } + + /** + * The style keys of the content. + * @param styleKeys the style keys of the content + */ + public void setStyleKeys(List styleKeys) { + this.styleKeys = new ArrayList(styleKeys); + } + + /** + * The style keys of the content. + * @param styleKey the style key + * @return see the return value of {@link List#add(Object)} + */ + public boolean addStyleKey(String styleKey) { + return styleKeys.add(styleKey); + } + + /** + * The style keys of the content. + * @param styleKey the style key + * @return see the return value of {@link List#remove(Object)} + */ + public boolean removeStyleKey(String styleKey) { + return styleKeys.remove(styleKey); + } + + /** + * The style keys of the content. + */ + public void clearStyleKeys() { + styleKeys.clear(); + } + + /** + * The style keys for this matched result, see {@link syntaxhighlighter.theme}. + * @return the style keys + */ + public List getStyleKeys() { + return new ArrayList(styleKeys); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + sb.append("["); + sb.append(offset); + sb.append("; "); + sb.append(length); + sb.append("; "); + for (int i = 0, iEnd = styleKeys.size(); i < iEnd; i++) { + if (i != 0) { + sb.append(", "); + } + sb.append(styleKeys.get(i)); + } + sb.append("]"); + + return sb.toString(); + } +} \ No newline at end of file diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlight/Parser.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlight/Parser.java new file mode 100755 index 0000000..c414f31 --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlight/Parser.java @@ -0,0 +1,42 @@ +// Copyright (c) 2012 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlight; + +import java.util.List; + +/** + * The parser for syntax highlight. + * + * @author Chan Wai Shing + */ +public interface Parser { + + List parse(String content); + + /** + * Parse the {@code content} and return the parsed result. + * @param fileExtension the file extension of the content, null means not + * provided + * @param content the content + * @return the parsed result + */ + List parse(String fileExtension, String content); +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlight/Style.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlight/Style.java new file mode 100755 index 0000000..01bb3fe --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlight/Style.java @@ -0,0 +1,229 @@ +// Copyright (c) 2012 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlight; + +import javax.swing.text.SimpleAttributeSet; +import javax.swing.text.StyleConstants; +import java.awt.*; + +/** + * The style used by {@link syntaxhiglight.Theme} as those of CSS styles. + * + * @author Chan Wai Shing + */ +public class Style implements Cloneable { + + /** + * It indicate whether the {@link #attributeSet} has updated after any style + * changes. + */ + protected boolean changed; + /** + * The {@link AttributeSet} representation of this style. + */ + protected SimpleAttributeSet attributeSet; + /** + * Font bold. + */ + protected boolean bold; + /** + * Font color. + */ + protected Color color; + /** + * The background color, null means no background color is set. + */ + protected Color background; + /** + * Font underline. + */ + protected boolean underline; + /** + * Font italic. + */ + protected boolean italic; + + /** + * Constructor. + *

+ * Default values:
+ *

    + *
  • bold: false;
  • + *
  • color: black;
  • + *
  • background: null;
  • + *
  • underline: false;
  • + *
  • italic: false;
  • + *
+ *

+ */ + public Style() { + changed = true; + attributeSet = null; + + bold = false; + color = Color.black; + background = null; + underline = false; + italic = false; + } + + /** + * Get the {@link AttributeSet} of this style. + * @return the {@link AttributeSet} + */ + public SimpleAttributeSet getAttributeSet() { + if (changed) { + attributeSet = new SimpleAttributeSet(); + StyleConstants.setBold(attributeSet, bold); + StyleConstants.setForeground(attributeSet, color); + if (background != null) { + StyleConstants.setBackground(attributeSet, background); + } + StyleConstants.setUnderline(attributeSet, underline); + StyleConstants.setItalic(attributeSet, italic); + changed = false; + } + return attributeSet; + } + + /** + * Get the background color. + * @return the background color or null if no color is set + */ + public Color getBackground() { + return background; + } + + /** + * Set the background color. + * @param background null means do not set the background + */ + public void setBackground(Color background) { + changed = true; + this.background = background; + } + + public boolean isBold() { + return bold; + } + + public void setBold(boolean bold) { + changed = true; + this.bold = bold; + } + + public Color getColor() { + return color; + } + + public void setColor(Color color) { + if (color == null) { + throw new NullPointerException("argument 'color' cannot be null"); + } + changed = true; + this.color = color; + } + + public boolean isItalic() { + return italic; + } + + public void setItalic(boolean italic) { + changed = true; + this.italic = italic; + } + + public boolean isUnderline() { + return underline; + } + + public void setUnderline(boolean underline) { + changed = true; + this.underline = underline; + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + int hash = 7; + hash = 97 * hash + (this.bold ? 1 : 0); + hash = 97 * hash + (this.color != null ? this.color.hashCode() : 0); + hash = 97 * hash + (this.background != null ? this.background.hashCode() : 0); + hash = 97 * hash + (this.underline ? 1 : 0); + hash = 97 * hash + (this.italic ? 1 : 0); + return hash; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object obj) { + if (obj == null || !(obj instanceof Style)) { + return false; + } + if (obj == this) { + return true; + } + Style _object = (Style) obj; + return _object.bold == bold && _object.color.equals(color) && _object.background.equals(background) + && _object.underline == underline && _object.italic == italic; + } + + /** + * {@inheritDoc} + */ + @Override + public Style clone() { + Style object = null; + try { + object = (Style) super.clone(); + } catch (CloneNotSupportedException ex) { + } + return object; + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + sb.append("["); + sb.append(getClass().getName()); + sb.append(": "); + sb.append("bold: ").append(bold); + sb.append(", "); + sb.append("color: ").append(color); + sb.append(", "); + sb.append("background: ").append(background); + sb.append(", "); + sb.append("underline: ").append(underline); + sb.append(", "); + sb.append("italic: ").append(italic); + sb.append("]"); + + return sb.toString(); + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlight/Theme.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlight/Theme.java new file mode 100755 index 0000000..1310517 --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlight/Theme.java @@ -0,0 +1,423 @@ +// Copyright (c) 2012 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlight; + +import javax.swing.text.SimpleAttributeSet; +import java.awt.*; +import java.util.HashMap; +import java.util.Map; +import java.util.logging.Logger; + +public class Theme { + + private static final Logger LOG = Logger.getLogger(Theme.class.getName()); + /** + * The font of the script text. + */ + protected Font font; + /** + * The background color of the script text area. + */ + protected Color background; + /** + * The background color of the highlighted line of script text. + */ + protected Color highlightedBackground; + /** + * Gutter (line number column on the left) + */ + /** + * The color of the gutter text. + */ + protected Color gutterText; + /** + * The color of the border that joint the gutter and the script text area. + */ + protected Color gutterBorderColor; + /** + * The width of the border that joint the gutter and the script text area. + */ + protected int gutterBorderWidth; + /** + * The font of the gutter text. + */ + protected Font gutterTextFont; + /** + * The minimum padding from 'the leftmost of the line number text' to + * 'the left margin'. + */ + protected int gutterTextPaddingLeft; + /** + * The minimum padding from 'the rightmost of the line number text' to + * 'the right margin' (not to the gutter border). + */ + protected int gutterTextPaddingRight; + /** + * Text area. + */ + /** + * The default style. When the style requested by {@link #getStyle(String)} + * not exist, this will be returned. + */ + protected Style plain; + /** + * The styles of this theme. + */ + protected Map styles; + + /** + * Constructor.
+ *

+ * Default value:
+ *

    + *
  • font: Consolas 12pt
  • + *
  • background: white
  • + *
  • gutter text: black
  • + *
  • gutter border: R: 184, G: 184, B: 184
  • + *
  • gutter border width: 3px
  • + *
  • gutter text font: Consolas 12pt
  • + *
  • gutter text padding-left: 7px
  • + *
  • gutter text padding-right: 7px
  • + *
+ *

+ */ + public Theme() { + font = new Font("Consolas", Font.PLAIN, 12); + background = Color.white; + + highlightedBackground = Color.gray; + + gutterText = Color.black; + gutterBorderColor = new Color(184, 184, 184); + gutterBorderWidth = 3; + gutterTextFont = new Font("Consolas", Font.PLAIN, 12); + gutterTextPaddingLeft = 7; + gutterTextPaddingRight = 7; + + plain = new Style(); + + styles = new HashMap(); + } + + /** + * Set the default style. + * @param plain the style + */ + public void setPlain(Style plain) { + if (plain == null) { + throw new NullPointerException("argument 'plain' cannot be null"); + } + this.plain = plain; + } + + /** + * Get the default style. + * @return the style + */ + public Style getPlain() { + return plain; + } + + /** + * Get the {@link AttributeSet} of {@code styleKeys}. For more than one + * styles, separate the styles by space, e.g. 'plain comments'. + * @param styleKeys the style keys with keys separated by space + * @return the combined {@link AttributeSet} + */ + public SimpleAttributeSet getStylesAttributeSet(String styleKeys) { + if (styleKeys.indexOf(' ') != -1) { + SimpleAttributeSet returnAttributeSet = new SimpleAttributeSet(); + String[] _keys = styleKeys.split(" "); + for (String _key : _keys) { + returnAttributeSet.addAttributes(getStyle(_key).getAttributeSet()); + } + return returnAttributeSet; + } else { + return getStyle(styleKeys).getAttributeSet(); + } + } + + /** + * Add style. + * @param styleKey the keyword of the style + * @param style the style + * @return see the return value of {@link Map#put(Object, Object)} + */ + public Style addStyle(String styleKey, Style style) { + return styles.put(styleKey, style); + } + + /** + * Remove style by keyword. + * @param styleKey the keyword of the style + * @return see the return value of {@link Map#remove(Object)} + */ + public Style removeStyle(String styleKey) { + return styles.remove(styleKey); + } + + /** + * Get the style by keyword. + * @param key the keyword + * @return the {@link syntaxhighlighter.theme.Style} related to the + * {@code key}; if the style related to the {@code key} not exist, the + * style of 'plain' will return. + */ + public Style getStyle(String key) { + Style returnStyle = styles.get(key); + return returnStyle != null ? returnStyle : plain; + } + + /** + * Get all styles. + * @return the styles + */ + public Map getStyles() { + return new HashMap(styles); + } + + /** + * Clear all styles. + */ + public void clearStyles() { + styles.clear(); + } + + /** + * The font of the script text. + * @return the font + */ + public Font getFont() { + return font; + } + + /** + * The font of the script text. + * @param font the font + */ + public void setFont(Font font) { + if (font == null) { + throw new NullPointerException("argument 'font' cannot be null"); + } + this.font = font; + } + + /** + * The background color of the script text area. + * @return the color + */ + public Color getBackground() { + return background; + } + + /** + * The background color of the script text area. + * @param background the color + */ + public void setBackground(Color background) { + if (background == null) { + throw new NullPointerException("argument 'background' cannot be null"); + } + this.background = background; + } + + /** + * The background color of the highlighted line of script text. + * @return the color + */ + public Color getHighlightedBackground() { + return highlightedBackground; + } + + /** + * The background color of the highlighted line of script text. + * @param highlightedBackground the color + */ + public void setHighlightedBackground(Color highlightedBackground) { + if (highlightedBackground == null) { + throw new NullPointerException("argument 'highlightedBackground' cannot be null"); + } + this.highlightedBackground = highlightedBackground; + } + + /** + * The color of the gutter text. + * @return the color + */ + public Color getGutterText() { + return gutterText; + } + + /** + * The color of the gutter text. + * @param gutterText the color + */ + public void setGutterText(Color gutterText) { + if (gutterText == null) { + throw new NullPointerException("argument 'gutterText' cannot be null"); + } + this.gutterText = gutterText; + } + + /** + * The color of the border that joint the gutter and the script text area. + * @return the color + */ + public Color getGutterBorderColor() { + return gutterBorderColor; + } + + /** + * The color of the border that joint the gutter and the script text area. + * @param gutterBorderColor the color + */ + public void setGutterBorderColor(Color gutterBorderColor) { + if (gutterBorderColor == null) { + throw new NullPointerException("argument 'gutterBorderColor' cannot be null"); + } + this.gutterBorderColor = gutterBorderColor; + } + + /** + * The width of the border that joint the gutter and the script text area. + * @return the width in pixel + */ + public int getGutterBorderWidth() { + return gutterBorderWidth; + } + + /** + * The width of the border that joint the gutter and the script text area. + * @param gutterBorderWidth in pixel + */ + public void setGutterBorderWidth(int gutterBorderWidth) { + this.gutterBorderWidth = gutterBorderWidth; + } + + /** + * The font of the gutter text. + * @return the font + */ + public Font getGutterTextFont() { + return gutterTextFont; + } + + /** + * The font of the gutter text. + * @param gutterTextFont the font + */ + public void setGutterTextFont(Font gutterTextFont) { + if (gutterTextFont == null) { + throw new NullPointerException("argument 'gutterTextFont' cannot be null"); + } + this.gutterTextFont = gutterTextFont; + } + + /** + * The minimum padding from 'the leftmost of the line number text' to + * 'the left margin'. + * @return the padding in pixel + */ + public int getGutterTextPaddingLeft() { + return gutterTextPaddingLeft; + } + + /** + * The minimum padding from 'the leftmost of the line number text' to + * 'the left margin'. + * @param gutterTextPaddingLeft in pixel + */ + public void setGutterTextPaddingLeft(int gutterTextPaddingLeft) { + this.gutterTextPaddingLeft = gutterTextPaddingLeft; + } + + /** + * The minimum padding from 'the rightmost of the line number text' to + * 'the right margin' (not to the gutter border). + * @return the padding in pixel + */ + public int getGutterTextPaddingRight() { + return gutterTextPaddingRight; + } + + /** + * The minimum padding from 'the rightmost of the line number text' to + * 'the right margin' (not to the gutter border). + * @param gutterTextPaddingRight in pixel + */ + public void setGutterTextPaddingRight(int gutterTextPaddingRight) { + this.gutterTextPaddingRight = gutterTextPaddingRight; + } + + /** + * {@inheritDoc} + */ + @Override + public Theme clone() { + Theme object = null; + try { + object = (Theme) super.clone(); + object.styles = new HashMap(); + for (String key : styles.keySet()) { + object.styles.put(key, styles.get(key).clone()); + } + } catch (CloneNotSupportedException ex) { + } + return object; + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + sb.append("["); + sb.append(getClass().getName()); + sb.append(": "); + sb.append("font: ").append(getFont()); + sb.append("; "); + sb.append("background: ").append(getBackground()); + sb.append("; "); + sb.append("highlightedBackground: ").append(getHighlightedBackground()); + sb.append("; "); + sb.append("gutterText: ").append(getGutterText()); + sb.append("; "); + sb.append("gutterBorderColor: ").append(getGutterBorderColor()); + sb.append(", "); + sb.append("gutterBorderWidth: ").append(getGutterBorderWidth()); + sb.append(", "); + sb.append("gutterTextFont: ").append(getGutterTextFont()); + sb.append(", "); + sb.append("gutterTextPaddingLeft: ").append(getGutterTextPaddingLeft()); + sb.append(", "); + sb.append("gutterTextPaddingRight: ").append(getGutterTextPaddingRight()); + sb.append(", "); + sb.append("styles: "); + for (String _key : styles.keySet()) { + sb.append(_key).append(":").append(styles.get(_key)); + } + sb.append("]"); + + return sb.toString(); + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/SyntaxHighlighterParser.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/SyntaxHighlighterParser.java new file mode 100755 index 0000000..bf57dde --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/SyntaxHighlighterParser.java @@ -0,0 +1,143 @@ +package syntaxhighlighter; + +import syntaxhighlight.ParseResult; +import syntaxhighlight.Parser; +import syntaxhighlighter.brush.Brush; +import syntaxhighlighter.parser.MatchResult; +import syntaxhighlighter.parser.SyntaxHighlighter; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +/** + * The SyntaxHighlighter parser for syntax highlight. + * @author Chan Wai Shing + */ +public class SyntaxHighlighterParser implements Parser { + + protected SyntaxHighlighter syntaxHighlighter; + /** + * The brush to use for this syntax highlighter. + */ + protected Brush brush; + /** + * Indicate whether the HTML-Script option is turned on or not. + */ + private boolean htmlScript; + /** + * The brushes list for HTML-Script. + */ + protected final List htmlScriptBrushesList; + + /** + * Constructor. + * @param brush the brush to use + */ + public SyntaxHighlighterParser(Brush brush) { + if (brush == null) { + throw new NullPointerException("argument 'brush' cannot be null"); + } + syntaxHighlighter = new SyntaxHighlighter(); + this.brush = brush; + htmlScript = false; + htmlScriptBrushesList = new ArrayList(); + } + + /** + * Get the brush. + * @return brush the brush + */ + public Brush getBrush() { + return brush; + } + + /** + * Set the brush to use. + * @param brush the brush + */ + public void setBrush(Brush brush) { + this.brush = brush; + } + + /** + * Get the list of HTML Script brushes. + * See also {@link #setHtmlScript(boolean)}. + * @return a copy of the list + */ + public List getHTMLScriptBrushesList() { + return new ArrayList(htmlScriptBrushesList); + } + + /** + * Set HTML Script brushes. Note that this will clear all previous recorded + * HTML Script brushes. See also {@link #setHtmlScript(boolean)}. + * The highlighter will re-render the script text pane every time this + * function is invoked (if there is any content). + * + * @param htmlScriptBrushesList the list that contain the brushes + */ + public void setHTMLScriptBrushes(List htmlScriptBrushesList) { + synchronized (this.htmlScriptBrushesList) { + this.htmlScriptBrushesList.clear(); + if (htmlScriptBrushesList != null) { + this.htmlScriptBrushesList.addAll(htmlScriptBrushesList); + } + } + } + + public void addHTMLScriptBrush(Brush brush) { + if (brush == null) { + return; + } + htmlScriptBrushesList.add(brush); + } + + /** + * Clear all HTML Script brushes. + */ + public void clearHTMLScriptBrushes() { + htmlScriptBrushesList.clear(); + } + + + public boolean isHtmlScript() { + return htmlScript; + } + + + public void setHtmlScript(boolean htmlScript) { + if (this.htmlScript != htmlScript) { + this.htmlScript = htmlScript; + } + } + + @Override + public List parse(String content) { + return parse(null, content); + } + + @Override + public List parse(String fileExtension, String content) { + List returnList = new ArrayList(); + + syntaxHighlighter.setHTMLScriptBrushList(htmlScriptBrushesList); + Map> parsedResult = syntaxHighlighter.parse(brush, htmlScript, content.toCharArray(), 0, content.length()); + for (List resultList : parsedResult.values()) { + for (MatchResult result : resultList) { + List styleKeyList = null; + if (result.isBold() == Boolean.TRUE) { + styleKeyList = new ArrayList(2); + styleKeyList.add(result.getStyleKey()); + styleKeyList.add("bold"); + } else { + styleKeyList = Arrays.asList(new String[]{result.getStyleKey()}); + } + returnList.add(new ParseResult(result.getOffset(), result.getLength(), styleKeyList)); + } + } + + return returnList; + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/Brush.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/Brush.java new file mode 100755 index 0000000..5728c66 --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/Brush.java @@ -0,0 +1,159 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.brush; + +import java.util.ArrayList; +import java.util.List; + +/** + * Brush for syntax highlighter. + * + * In syntax highlighter, every supported programming language has its own + * brush. Brush contain a set of rules, the highlighter/parser will use these + * rules to determine the structure of the code and apply different color to + * different group of component. + * + * @author Chan Wai Shing + */ +public class Brush { + + /** + * Regular expression rules list. It will be executed in sequence. + */ + protected List regExpRuleList; + /** + * The list of common file extension for this language. It is no use so far, + * just for reference. + */ + protected List commonFileExtensionList; + /** + * HTML script RegExp, null means no HTML script RegExp for this brush. If + * this language will not be implanted into HTML, leave it null. + */ + protected HTMLScriptRegExp htmlScriptRegExp; + + /** + * Constructor. + */ + public Brush() { + regExpRuleList = new ArrayList(); + commonFileExtensionList = new ArrayList(); + htmlScriptRegExp = null; + } + + /** + * Get the regular expression rule list. + * @return a copy of the list + */ + public List getRegExpRuleList() { + return new ArrayList(regExpRuleList); + } + + /** + * Set the regular expression rule list. + * @param regExpRuleList the list + */ + public void setRegExpRuleList(List regExpRuleList) { + if (regExpRuleList == null) { + this.regExpRuleList = new ArrayList(); + return; + } + this.regExpRuleList = new ArrayList(regExpRuleList); + } + + /** + * Get the HTML script RegExp. + * @return the HTML script RegExp, null means not defined + */ + public HTMLScriptRegExp getHTMLScriptRegExp() { + return htmlScriptRegExp; + } + + /** + * Set the HTML script RegExp. + * @param htmlScriptRegExp the RegExp, null means no HTML script RegExp for + * this brush. + */ + public void setHTMLScriptRegExp(HTMLScriptRegExp htmlScriptRegExp) { + this.htmlScriptRegExp = htmlScriptRegExp; + } + + /** + * Get the common file extension list. + * @return a copy of the list + */ + public List getCommonFileExtensionList() { + return new ArrayList(commonFileExtensionList); + } + + /** + * Set the common file extension list. + * @param commonFileExtensionList the list, cannot be null + */ + public void setCommonFileExtensionList(List commonFileExtensionList) { + if (commonFileExtensionList == null) { + this.commonFileExtensionList = new ArrayList(); + return; + } + this.commonFileExtensionList = new ArrayList(commonFileExtensionList); + } + + /** + * Similar function in JavaScript SyntaxHighlighter for making string of + * keywords separated by space into regular expression. + * @param str the keywords separated by space + * @return the treated regexp string + */ + protected static String getKeywords(String str) { + if (str == null) { + throw new NullPointerException("argument 'str' cannot be null"); + } + return "\\b(?:" + str.replaceAll("^\\s+|\\s+$", "").replaceAll("\\s+", "|") + ")\\b"; + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + sb.append(getClass().getName()); + sb.append("\n"); + sb.append("rule count: "); + sb.append(regExpRuleList.size()); + for (int i = 0, iEnd = regExpRuleList.size(); i < iEnd; i++) { + RegExpRule rule = regExpRuleList.get(i); + sb.append("\n"); + sb.append(i); + sb.append(": "); + sb.append(rule.toString()); + } + sb.append("\n"); + sb.append("common file extension list: "); + sb.append(commonFileExtensionList); + sb.append("\n"); + sb.append("HTML Script RegExp: "); + sb.append(htmlScriptRegExp); + + return sb.toString(); + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushAS3.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushAS3.java new file mode 100755 index 0000000..72317aa --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushAS3.java @@ -0,0 +1,64 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.brush; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; + +/** + * Action Script brush. + * @author Chan Wai Shing + */ +public class BrushAS3 extends Brush { + + public BrushAS3() { + super(); + + // Created by Peter Atoria @ http://iAtoria.com + + String inits = "class interface function package"; + String keywords = "-Infinity ...rest Array as AS3 Boolean break case catch const continue Date decodeURI " + + "decodeURIComponent default delete do dynamic each else encodeURI encodeURIComponent escape " + + "extends false final finally flash_proxy for get if implements import in include Infinity " + + "instanceof int internal is isFinite isNaN isXMLName label namespace NaN native new null " + + "Null Number Object object_proxy override parseFloat parseInt private protected public " + + "return set static String super switch this throw true try typeof uint undefined unescape " + + "use void while with"; + + List _regExpRuleList = new ArrayList(); + _regExpRuleList.add(new RegExpRule(RegExpRule.singleLineCComments, "comments")); // one line comments + _regExpRuleList.add(new RegExpRule(RegExpRule.multiLineCComments, "comments")); // multiline comments + _regExpRuleList.add(new RegExpRule(RegExpRule.doubleQuotedString, "string")); // double quoted strings + _regExpRuleList.add(new RegExpRule(RegExpRule.singleQuotedString, "string")); // single quoted strings + _regExpRuleList.add(new RegExpRule("\\b([\\d]+(\\.[\\d]+)?|0x[a-f0-9]+)\\b", Pattern.CASE_INSENSITIVE, "value")); // numbers + _regExpRuleList.add(new RegExpRule(getKeywords(inits), Pattern.MULTILINE, "color3")); // initializations + _regExpRuleList.add(new RegExpRule(getKeywords(keywords), Pattern.MULTILINE, "keyword")); // keywords + _regExpRuleList.add(new RegExpRule("var", Pattern.MULTILINE, "variable")); // variable + _regExpRuleList.add(new RegExpRule("trace", Pattern.MULTILINE, "color1")); // trace + setRegExpRuleList(_regExpRuleList); + + setHTMLScriptRegExp(HTMLScriptRegExp.scriptScriptTags); + + setCommonFileExtensionList(Arrays.asList("as")); + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushAppleScript.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushAppleScript.java new file mode 100755 index 0000000..244c523 --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushAppleScript.java @@ -0,0 +1,62 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.brush; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; + +/** + * AppleScript brush + * @author Chan Wai Shing + */ +public class BrushAppleScript extends Brush { + + public BrushAppleScript() { + super(); + + // AppleScript brush by David Chambers + // http://davidchambersdesign.com/ + + String keywords = "after before beginning continue copy each end every from return get global in local named of set some that the then times to where whose with without"; + String ordinals = "first second third fourth fifth sixth seventh eighth ninth tenth last front back middle"; + String specials = "activate add alias AppleScript ask attachment boolean class constant delete duplicate empty exists false id integer list make message modal modified new no paragraph pi properties quit real record remove rest result reveal reverse run running save string true word yes"; + + List _regExpRuleList = new ArrayList(); + _regExpRuleList.add(new RegExpRule("(--|#).*$", Pattern.MULTILINE, "comments")); + _regExpRuleList.add(new RegExpRule("\\(\\*(?:[\\s\\S]*?\\(\\*[\\s\\S]*?\\*\\))*[\\s\\S]*?\\*\\)", Pattern.MULTILINE, "comments")); // support nested comments + _regExpRuleList.add(new RegExpRule("\"[\\s\\S]*?\"", Pattern.MULTILINE, "string")); + _regExpRuleList.add(new RegExpRule("(?:,|:|¬|'s\\b|\\(|\\)|\\{|\\}|«|\\b\\w*»)", "color1")); + _regExpRuleList.add(new RegExpRule("(-)?(\\d)+(\\.(\\d)?)?(E\\+(\\d)+)?", "color1")); // numbers + _regExpRuleList.add(new RegExpRule("(?:&(amp;|gt;|lt;)?|=|� |>|<|≥|>=|≤|<=|\\*|\\+|-|\\/|÷|\\^)", "color2")); + _regExpRuleList.add(new RegExpRule("\\b(?:and|as|div|mod|not|or|return(?!\\s&)(ing)?|equals|(is(n't| not)? )?equal( to)?|does(n't| not) equal|(is(n't| not)? )?(greater|less) than( or equal( to)?)?|(comes|does(n't| not) come) (after|before)|is(n't| not)?( in)? (back|front) of|is(n't| not)? behind|is(n't| not)?( (in|contained by))?|does(n't| not) contain|contain(s)?|(start|begin|end)(s)? with|((but|end) )?(consider|ignor)ing|prop(erty)?|(a )?ref(erence)?( to)?|repeat (until|while|with)|((end|exit) )?repeat|((else|end) )?if|else|(end )?(script|tell|try)|(on )?error|(put )?into|(of )?(it|me)|its|my|with (timeout( of)?|transaction)|end (timeout|transaction))\\b", "keyword")); + _regExpRuleList.add(new RegExpRule("\\b\\d+(st|nd|rd|th)\\b", "keyword")); // ordinals + _regExpRuleList.add(new RegExpRule("\\b(?:about|above|against|around|at|below|beneath|beside|between|by|(apart|aside) from|(instead|out) of|into|on(to)?|over|since|thr(ough|u)|under)\\b", "color3")); + _regExpRuleList.add(new RegExpRule("\\b(?:adding folder items to|after receiving|choose( ((remote )?application|color|folder|from list|URL))?|clipboard info|set the clipboard to|(the )?clipboard|entire contents|display(ing| (alert|dialog|mode))?|document( (edited|file|nib name))?|file( (name|type))?|(info )?for|giving up after|(name )?extension|quoted form|return(ed)?|second(?! item)(s)?|list (disks|folder)|text item(s| delimiters)?|(Unicode )?text|(disk )?item(s)?|((current|list) )?view|((container|key) )?window|with (data|icon( (caution|note|stop))?|parameter(s)?|prompt|properties|seed|title)|case|diacriticals|hyphens|numeric strings|punctuation|white space|folder creation|application(s( folder)?| (processes|scripts position|support))?|((desktop )?(pictures )?|(documents|downloads|favorites|home|keychain|library|movies|music|public|scripts|sites|system|users|utilities|workflows) )folder|desktop|Folder Action scripts|font(s| panel)?|help|internet plugins|modem scripts|(system )?preferences|printer descriptions|scripting (additions|components)|shared (documents|libraries)|startup (disk|items)|temporary items|trash|on server|in AppleTalk zone|((as|long|short) )?user name|user (ID|locale)|(with )?password|in (bundle( with identifier)?|directory)|(close|open for) access|read|write( permission)?|(g|s)et eof|using( delimiters)?|starting at|default (answer|button|color|country code|entr(y|ies)|identifiers|items|name|location|script editor)|hidden( answer)?|open(ed| (location|untitled))?|error (handling|reporting)|(do( shell)?|load|run|store) script|administrator privileges|altering line endings|get volume settings|(alert|boot|input|mount|output|set) volume|output muted|(fax|random )?number|round(ing)?|up|down|toward zero|to nearest|as taught in school|system (attribute|info)|((AppleScript( Studio)?|system) )?version|(home )?directory|(IPv4|primary Ethernet) address|CPU (type|speed)|physical memory|time (stamp|to GMT)|replacing|ASCII (character|number)|localized string|from table|offset|summarize|beep|delay|say|(empty|multiple) selections allowed|(of|preferred) type|invisibles|showing( package contents)?|editable URL|(File|FTP|News|Media|Web) [Ss]ervers|Telnet hosts|Directory services|Remote applications|waiting until completion|saving( (in|to))?|path (for|to( (((current|frontmost) )?application|resource))?)|POSIX (file|path)|(background|RGB) color|(OK|cancel) button name|cancel button|button(s)?|cubic ((centi)?met(re|er)s|yards|feet|inches)|square ((kilo)?met(re|er)s|miles|yards|feet)|(centi|kilo)?met(re|er)s|miles|yards|feet|inches|lit(re|er)s|gallons|quarts|(kilo)?grams|ounces|pounds|degrees (Celsius|Fahrenheit|Kelvin)|print( (dialog|settings))?|clos(e(able)?|ing)|(de)?miniaturized|miniaturizable|zoom(ed|able)|attribute run|action (method|property|title)|phone|email|((start|end)ing|home) page|((birth|creation|current|custom|modification) )?date|((((phonetic )?(first|last|middle))|computer|host|maiden|related) |nick)?name|aim|icq|jabber|msn|yahoo|address(es)?|save addressbook|should enable action|city|country( code)?|formatte(r|d address)|(palette )?label|state|street|zip|AIM [Hh]andle(s)?|my card|select(ion| all)?|unsaved|(alpha )?value|entr(y|ies)|group|(ICQ|Jabber|MSN) handle|person|people|company|department|icon image|job title|note|organization|suffix|vcard|url|copies|collating|pages (across|down)|request print time|target( printer)?|((GUI Scripting|Script menu) )?enabled|show Computer scripts|(de)?activated|awake from nib|became (key|main)|call method|of (class|object)|center|clicked toolbar item|closed|for document|exposed|(can )?hide|idle|keyboard (down|up)|event( (number|type))?|launch(ed)?|load (image|movie|nib|sound)|owner|log|mouse (down|dragged|entered|exited|moved|up)|move|column|localization|resource|script|register|drag (info|types)|resigned (active|key|main)|resiz(e(d)?|able)|right mouse (down|dragged|up)|scroll wheel|(at )?index|should (close|open( untitled)?|quit( after last window closed)?|zoom)|((proposed|screen) )?bounds|show(n)?|behind|in front of|size (mode|to fit)|update(d| toolbar item)?|was (hidden|miniaturized)|will (become active|close|finish launching|hide|miniaturize|move|open|quit|(resign )?active|((maximum|minimum|proposed) )?size|show|zoom)|bundle|data source|movie|pasteboard|sound|tool(bar| tip)|(color|open|save) panel|coordinate system|frontmost|main( (bundle|menu|window))?|((services|(excluded from )?windows) )?menu|((executable|frameworks|resource|scripts|shared (frameworks|support)) )?path|(selected item )?identifier|data|content(s| view)?|character(s)?|click count|(command|control|option|shift) key down|context|delta (x|y|z)|key( code)?|location|pressure|unmodified characters|types|(first )?responder|playing|(allowed|selectable) identifiers|allows customization|(auto saves )?configuration|visible|image( name)?|menu form representation|tag|user(-| )defaults|associated file name|(auto|needs) display|current field editor|floating|has (resize indicator|shadow)|hides when deactivated|level|minimized (image|title)|opaque|position|release when closed|sheet|title(d)?)\\b", "color3")); + _regExpRuleList.add(new RegExpRule(getKeywords(specials), Pattern.MULTILINE, "color3")); + _regExpRuleList.add(new RegExpRule(getKeywords(keywords), Pattern.MULTILINE, "keyword")); + _regExpRuleList.add(new RegExpRule(getKeywords(ordinals), Pattern.MULTILINE, "keyword")); + setRegExpRuleList(_regExpRuleList); + + setCommonFileExtensionList(Arrays.asList("applescript", "scpt")); + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushBash.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushBash.java new file mode 100755 index 0000000..5c04d9a --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushBash.java @@ -0,0 +1,67 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.brush; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; + +/** + * Bash brush. + * @author Chan Wai Shing + */ +public class BrushBash extends Brush { + + public BrushBash() { + super(); + + String keywords = "if fi then elif else for do done until while break continue case function return in eq ne ge le"; + String commands = "alias apropos awk basename bash bc bg builtin bzip2 cal cat cd cfdisk chgrp chmod chown chroot" + + "cksum clear cmp comm command cp cron crontab csplit cut date dc dd ddrescue declare df " + + "diff diff3 dig dir dircolors dirname dirs du echo egrep eject enable env ethtool eval " + + "exec exit expand export expr false fdformat fdisk fg fgrep file find fmt fold format " + + "free fsck ftp gawk getopts grep groups gzip hash head history hostname id ifconfig " + + "import install join kill less let ln local locate logname logout look lpc lpr lprint " + + "lprintd lprintq lprm ls lsof make man mkdir mkfifo mkisofs mknod more mount mtools " + + "mv netstat nice nl nohup nslookup open op passwd paste pathchk ping popd pr printcap " + + "printenv printf ps pushd pwd quota quotacheck quotactl ram rcp read readonly renice " + + "remsync rm rmdir rsync screen scp sdiff sed select seq set sftp shift shopt shutdown " + + "sleep sort source split ssh strace su sudo sum symlink sync tail tar tee test time " + + "times touch top traceroute trap tr true tsort tty type ulimit umask umount unalias " + + "uname unexpand uniq units unset unshar useradd usermod users uuencode uudecode v vdir " + + "vi watch wc whereis which who whoami Wget xargs yes"; + + List _regExpRuleList = new ArrayList(); + RegExpRule _regExpRule = new RegExpRule("^#!.*$", Pattern.MULTILINE, "preprocessor"); + _regExpRule.setBold(true); + _regExpRuleList.add(_regExpRule); + _regExpRuleList.add(new RegExpRule("\\/[\\w-\\/]+", Pattern.MULTILINE, "plain")); + _regExpRuleList.add(new RegExpRule(RegExpRule.singleLinePerlComments, "comments")); // one line comments + _regExpRuleList.add(new RegExpRule(RegExpRule.doubleQuotedString, "string")); // double quoted strings + _regExpRuleList.add(new RegExpRule(RegExpRule.singleQuotedString, "string")); // single quoted strings + _regExpRuleList.add(new RegExpRule(getKeywords(keywords), Pattern.MULTILINE, "keyword")); // keywords + _regExpRuleList.add(new RegExpRule(getKeywords(commands), Pattern.MULTILINE, "functions")); // commands + setRegExpRuleList(_regExpRuleList); + + setCommonFileExtensionList(Arrays.asList("sh")); + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushCSharp.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushCSharp.java new file mode 100755 index 0000000..b6f6988 --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushCSharp.java @@ -0,0 +1,62 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.brush; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; + +/** + * C# brush. + * @author Chan Wai Shing + */ +public class BrushCSharp extends Brush { + + public BrushCSharp() { + super(); + + String keywords = "abstract as base bool break byte case catch char checked class const " + + "continue decimal default delegate do double else enum event explicit " + + "extern false finally fixed float for foreach get goto if implicit in int " + + "interface internal is lock long namespace new null object operator out " + + "override params private protected public readonly ref return sbyte sealed set " + + "short sizeof stackalloc static string struct switch this throw true try " + + "typeof uint ulong unchecked unsafe ushort using virtual void while var"; + + List _regExpRuleList = new ArrayList(); + _regExpRuleList.add(new RegExpRule("\\/\\/\\/.*$", Pattern.MULTILINE, "color1")); // documents + _regExpRuleList.add(new RegExpRule(RegExpRule.singleLineCComments, "comments")); // one line comments + _regExpRuleList.add(new RegExpRule(RegExpRule.multiLineCComments, "comments")); // multiline comments + _regExpRuleList.add(new RegExpRule("@\"(?:[^\"]|\"\")*\"", "string")); // @-quoted strings + _regExpRuleList.add(new RegExpRule(RegExpRule.doubleQuotedString, "string")); // strings + _regExpRuleList.add(new RegExpRule(RegExpRule.singleQuotedString, "string")); // strings + _regExpRuleList.add(new RegExpRule("^\\s*#.*", Pattern.MULTILINE, "preprocessor")); // preprocessor tags like #region and #endregion + _regExpRuleList.add(new RegExpRule(getKeywords(keywords), Pattern.MULTILINE, "keyword")); // c# keyword + _regExpRuleList.add(new RegExpRule("\\bpartial(?=\\s+(?:class|interface|struct)\\b)", "keyword")); // contextual keyword: 'partial' + _regExpRuleList.add(new RegExpRule("\\byield(?=\\s+(?:return|break)\\b)", "keyword")); // contextual keyword: 'yield' + setRegExpRuleList(_regExpRuleList); + + setHTMLScriptRegExp(HTMLScriptRegExp.aspScriptTags); + + setCommonFileExtensionList(Arrays.asList("cs")); + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushColdFusion.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushColdFusion.java new file mode 100755 index 0000000..c953288 --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushColdFusion.java @@ -0,0 +1,105 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.brush; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; + +/** + * Cold Fusion brush. + * @author Chan Wai Shing + */ +public class BrushColdFusion extends Brush { + + public BrushColdFusion() { + super(); + + // Contributed by Jen + // http://www.jensbits.com/2009/05/14/coldfusion-brush-for-syntaxhighlighter-plus + + String funcs = "Abs ACos AddSOAPRequestHeader AddSOAPResponseHeader AjaxLink AjaxOnLoad ArrayAppend ArrayAvg ArrayClear ArrayDeleteAt " + + "ArrayInsertAt ArrayIsDefined ArrayIsEmpty ArrayLen ArrayMax ArrayMin ArraySet ArraySort ArraySum ArraySwap ArrayToList " + + "Asc ASin Atn BinaryDecode BinaryEncode BitAnd BitMaskClear BitMaskRead BitMaskSet BitNot BitOr BitSHLN BitSHRN BitXor " + + "Ceiling CharsetDecode CharsetEncode Chr CJustify Compare CompareNoCase Cos CreateDate CreateDateTime CreateObject " + + "CreateODBCDate CreateODBCDateTime CreateODBCTime CreateTime CreateTimeSpan CreateUUID DateAdd DateCompare DateConvert " + + "DateDiff DateFormat DatePart Day DayOfWeek DayOfWeekAsString DayOfYear DaysInMonth DaysInYear DE DecimalFormat DecrementValue " + + "Decrypt DecryptBinary DeleteClientVariable DeserializeJSON DirectoryExists DollarFormat DotNetToCFType Duplicate Encrypt " + + "EncryptBinary Evaluate Exp ExpandPath FileClose FileCopy FileDelete FileExists FileIsEOF FileMove FileOpen FileRead " + + "FileReadBinary FileReadLine FileSetAccessMode FileSetAttribute FileSetLastModified FileWrite Find FindNoCase FindOneOf " + + "FirstDayOfMonth Fix FormatBaseN GenerateSecretKey GetAuthUser GetBaseTagData GetBaseTagList GetBaseTemplatePath " + + "GetClientVariablesList GetComponentMetaData GetContextRoot GetCurrentTemplatePath GetDirectoryFromPath GetEncoding " + + "GetException GetFileFromPath GetFileInfo GetFunctionList GetGatewayHelper GetHttpRequestData GetHttpTimeString " + + "GetK2ServerDocCount GetK2ServerDocCountLimit GetLocale GetLocaleDisplayName GetLocalHostIP GetMetaData GetMetricData " + + "GetPageContext GetPrinterInfo GetProfileSections GetProfileString GetReadableImageFormats GetSOAPRequest GetSOAPRequestHeader " + + "GetSOAPResponse GetSOAPResponseHeader GetTempDirectory GetTempFile GetTemplatePath GetTickCount GetTimeZoneInfo GetToken " + + "GetUserRoles GetWriteableImageFormats Hash Hour HTMLCodeFormat HTMLEditFormat IIf ImageAddBorder ImageBlur ImageClearRect " + + "ImageCopy ImageCrop ImageDrawArc ImageDrawBeveledRect ImageDrawCubicCurve ImageDrawLine ImageDrawLines ImageDrawOval " + + "ImageDrawPoint ImageDrawQuadraticCurve ImageDrawRect ImageDrawRoundRect ImageDrawText ImageFlip ImageGetBlob ImageGetBufferedImage " + + "ImageGetEXIFTag ImageGetHeight ImageGetIPTCTag ImageGetWidth ImageGrayscale ImageInfo ImageNegative ImageNew ImageOverlay ImagePaste " + + "ImageRead ImageReadBase64 ImageResize ImageRotate ImageRotateDrawingAxis ImageScaleToFit ImageSetAntialiasing ImageSetBackgroundColor " + + "ImageSetDrawingColor ImageSetDrawingStroke ImageSetDrawingTransparency ImageSharpen ImageShear ImageShearDrawingAxis ImageTranslate " + + "ImageTranslateDrawingAxis ImageWrite ImageWriteBase64 ImageXORDrawingMode IncrementValue InputBaseN Insert Int IsArray IsBinary " + + "IsBoolean IsCustomFunction IsDate IsDDX IsDebugMode IsDefined IsImage IsImageFile IsInstanceOf IsJSON IsLeapYear IsLocalHost " + + "IsNumeric IsNumericDate IsObject IsPDFFile IsPDFObject IsQuery IsSimpleValue IsSOAPRequest IsStruct IsUserInAnyRole IsUserInRole " + + "IsUserLoggedIn IsValid IsWDDX IsXML IsXmlAttribute IsXmlDoc IsXmlElem IsXmlNode IsXmlRoot JavaCast JSStringFormat LCase Left Len " + + "ListAppend ListChangeDelims ListContains ListContainsNoCase ListDeleteAt ListFind ListFindNoCase ListFirst ListGetAt ListInsertAt " + + "ListLast ListLen ListPrepend ListQualify ListRest ListSetAt ListSort ListToArray ListValueCount ListValueCountNoCase LJustify Log " + + "Log10 LSCurrencyFormat LSDateFormat LSEuroCurrencyFormat LSIsCurrency LSIsDate LSIsNumeric LSNumberFormat LSParseCurrency LSParseDateTime " + + "LSParseEuroCurrency LSParseNumber LSTimeFormat LTrim Max Mid Min Minute Month MonthAsString Now NumberFormat ParagraphFormat ParseDateTime " + + "Pi PrecisionEvaluate PreserveSingleQuotes Quarter QueryAddColumn QueryAddRow QueryConvertForGrid QueryNew QuerySetCell QuotedValueList Rand " + + "Randomize RandRange REFind REFindNoCase ReleaseComObject REMatch REMatchNoCase RemoveChars RepeatString Replace ReplaceList ReplaceNoCase " + + "REReplace REReplaceNoCase Reverse Right RJustify Round RTrim Second SendGatewayMessage SerializeJSON SetEncoding SetLocale SetProfileString " + + "SetVariable Sgn Sin Sleep SpanExcluding SpanIncluding Sqr StripCR StructAppend StructClear StructCopy StructCount StructDelete StructFind " + + "StructFindKey StructFindValue StructGet StructInsert StructIsEmpty StructKeyArray StructKeyExists StructKeyList StructKeyList StructNew " + + "StructSort StructUpdate Tan TimeFormat ToBase64 ToBinary ToScript ToString Trim UCase URLDecode URLEncodedFormat URLSessionFormat Val " + + "ValueList VerifyClient Week Wrap Wrap WriteOutput XmlChildPos XmlElemNew XmlFormat XmlGetNodeType XmlNew XmlParse XmlSearch XmlTransform " + + "XmlValidate Year YesNoFormat"; + String keywords = "cfabort cfajaximport cfajaxproxy cfapplet cfapplication cfargument cfassociate cfbreak cfcache cfcalendar " + + "cfcase cfcatch cfchart cfchartdata cfchartseries cfcol cfcollection cfcomponent cfcontent cfcookie cfdbinfo " + + "cfdefaultcase cfdirectory cfdiv cfdocument cfdocumentitem cfdocumentsection cfdump cfelse cfelseif cferror " + + "cfexchangecalendar cfexchangeconnection cfexchangecontact cfexchangefilter cfexchangemail cfexchangetask " + + "cfexecute cfexit cffeed cffile cfflush cfform cfformgroup cfformitem cfftp cffunction cfgrid cfgridcolumn " + + "cfgridrow cfgridupdate cfheader cfhtmlhead cfhttp cfhttpparam cfif cfimage cfimport cfinclude cfindex " + + "cfinput cfinsert cfinterface cfinvoke cfinvokeargument cflayout cflayoutarea cfldap cflocation cflock cflog " + + "cflogin cfloginuser cflogout cfloop cfmail cfmailparam cfmailpart cfmenu cfmenuitem cfmodule cfNTauthenticate " + + "cfobject cfobjectcache cfoutput cfparam cfpdf cfpdfform cfpdfformparam cfpdfparam cfpdfsubform cfpod cfpop " + + "cfpresentation cfpresentationslide cfpresenter cfprint cfprocessingdirective cfprocparam cfprocresult " + + "cfproperty cfquery cfqueryparam cfregistry cfreport cfreportparam cfrethrow cfreturn cfsavecontent cfschedule " + + "cfscript cfsearch cfselect cfset cfsetting cfsilent cfslider cfsprydataset cfstoredproc cfswitch cftable " + + "cftextarea cfthread cfthrow cftimer cftooltip cftrace cftransaction cftree cftreeitem cftry cfupdate cfwddx " + + "cfwindow cfxml cfzip cfzipparam"; + String operators = "all and any between cross in join like not null or outer some"; + + List _regExpRuleList = new ArrayList(); + _regExpRuleList.add(new RegExpRule("--(.*)$", Pattern.MULTILINE, "comments")); // one line and multiline comments + _regExpRuleList.add(new RegExpRule(RegExpRule.xmlComments, "comments")); // single quoted strings + _regExpRuleList.add(new RegExpRule(RegExpRule.doubleQuotedString, "string")); // double quoted strings + _regExpRuleList.add(new RegExpRule(RegExpRule.singleQuotedString, "string")); // single quoted strings + _regExpRuleList.add(new RegExpRule(getKeywords(funcs), Pattern.CASE_INSENSITIVE | Pattern.MULTILINE, "functions")); // functions + _regExpRuleList.add(new RegExpRule(getKeywords(operators), Pattern.CASE_INSENSITIVE | Pattern.MULTILINE, "color1")); // operators and such + _regExpRuleList.add(new RegExpRule(getKeywords(keywords), Pattern.CASE_INSENSITIVE | Pattern.MULTILINE, "keyword")); // keyword + setRegExpRuleList(_regExpRuleList); + + setCommonFileExtensionList(Arrays.asList("cfm", "cfml")); + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushCpp.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushCpp.java new file mode 100755 index 0000000..074e124 --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushCpp.java @@ -0,0 +1,108 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.brush; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; + +/** + * C++ brush. + * @author Chan Wai Shing + */ +public class BrushCpp extends Brush { + + public BrushCpp() { + super(); + + // Copyright 2006 Shin, YoungJin + + String datatypes = "ATOM BOOL BOOLEAN BYTE CHAR COLORREF DWORD DWORDLONG DWORD_PTR " + + "DWORD32 DWORD64 FLOAT HACCEL HALF_PTR HANDLE HBITMAP HBRUSH " + + "HCOLORSPACE HCONV HCONVLIST HCURSOR HDC HDDEDATA HDESK HDROP HDWP " + + "HENHMETAFILE HFILE HFONT HGDIOBJ HGLOBAL HHOOK HICON HINSTANCE HKEY " + + "HKL HLOCAL HMENU HMETAFILE HMODULE HMONITOR HPALETTE HPEN HRESULT " + + "HRGN HRSRC HSZ HWINSTA HWND INT INT_PTR INT32 INT64 LANGID LCID LCTYPE " + + "LGRPID LONG LONGLONG LONG_PTR LONG32 LONG64 LPARAM LPBOOL LPBYTE LPCOLORREF " + + "LPCSTR LPCTSTR LPCVOID LPCWSTR LPDWORD LPHANDLE LPINT LPLONG LPSTR LPTSTR " + + "LPVOID LPWORD LPWSTR LRESULT PBOOL PBOOLEAN PBYTE PCHAR PCSTR PCTSTR PCWSTR " + + "PDWORDLONG PDWORD_PTR PDWORD32 PDWORD64 PFLOAT PHALF_PTR PHANDLE PHKEY PINT " + + "PINT_PTR PINT32 PINT64 PLCID PLONG PLONGLONG PLONG_PTR PLONG32 PLONG64 POINTER_32 " + + "POINTER_64 PSHORT PSIZE_T PSSIZE_T PSTR PTBYTE PTCHAR PTSTR PUCHAR PUHALF_PTR " + + "PUINT PUINT_PTR PUINT32 PUINT64 PULONG PULONGLONG PULONG_PTR PULONG32 PULONG64 " + + "PUSHORT PVOID PWCHAR PWORD PWSTR SC_HANDLE SC_LOCK SERVICE_STATUS_HANDLE SHORT " + + "SIZE_T SSIZE_T TBYTE TCHAR UCHAR UHALF_PTR UINT UINT_PTR UINT32 UINT64 ULONG " + + "ULONGLONG ULONG_PTR ULONG32 ULONG64 USHORT USN VOID WCHAR WORD WPARAM WPARAM WPARAM " + + "char bool short int __int32 __int64 __int8 __int16 long float double __wchar_t " + + "clock_t _complex _dev_t _diskfree_t div_t ldiv_t _exception _EXCEPTION_POINTERS " + + "FILE _finddata_t _finddatai64_t _wfinddata_t _wfinddatai64_t __finddata64_t " + + "__wfinddata64_t _FPIEEE_RECORD fpos_t _HEAPINFO _HFILE lconv intptr_t " + + "jmp_buf mbstate_t _off_t _onexit_t _PNH ptrdiff_t _purecall_handler " + + "sig_atomic_t size_t _stat __stat64 _stati64 terminate_function " + + "time_t __time64_t _timeb __timeb64 tm uintptr_t _utimbuf " + + "va_list wchar_t wctrans_t wctype_t wint_t signed"; + String keywords = "break case catch class const __finally __exception __try " + + "const_cast continue private public protected __declspec " + + "default delete deprecated dllexport dllimport do dynamic_cast " + + "else enum explicit extern if for friend goto inline " + + "mutable naked namespace new noinline noreturn nothrow " + + "register reinterpret_cast return selectany " + + "sizeof static static_cast struct switch template this " + + "thread throw true false try typedef typeid typename union " + + "using uuid virtual void volatile whcar_t while"; + String functions = "assert isalnum isalpha iscntrl isdigit isgraph islower isprint" + + "ispunct isspace isupper isxdigit tolower toupper errno localeconv " + + "setlocale acos asin atan atan2 ceil cos cosh exp fabs floor fmod " + + "frexp ldexp log log10 modf pow sin sinh sqrt tan tanh jmp_buf " + + "longjmp setjmp raise signal sig_atomic_t va_arg va_end va_start " + + "clearerr fclose feof ferror fflush fgetc fgetpos fgets fopen " + + "fprintf fputc fputs fread freopen fscanf fseek fsetpos ftell " + + "fwrite getc getchar gets perror printf putc putchar puts remove " + + "rename rewind scanf setbuf setvbuf sprintf sscanf tmpfile tmpnam " + + "ungetc vfprintf vprintf vsprintf abort abs atexit atof atoi atol " + + "bsearch calloc div exit free getenv labs ldiv malloc mblen mbstowcs " + + "mbtowc qsort rand realloc srand strtod strtol strtoul system " + + "wcstombs wctomb memchr memcmp memcpy memmove memset strcat strchr " + + "strcmp strcoll strcpy strcspn strerror strlen strncat strncmp " + + "strncpy strpbrk strrchr strspn strstr strtok strxfrm asctime " + + "clock ctime difftime gmtime localtime mktime strftime time"; + + List _regExpRuleList = new ArrayList(); + _regExpRuleList.add(new RegExpRule(RegExpRule.singleLineCComments, "comments")); // one line comments + _regExpRuleList.add(new RegExpRule(RegExpRule.multiLineCComments, "comments")); // multiline comments + _regExpRuleList.add(new RegExpRule(RegExpRule.doubleQuotedString, "string")); // strings + _regExpRuleList.add(new RegExpRule(RegExpRule.singleQuotedString, "string")); // strings + _regExpRuleList.add(new RegExpRule("^ *#.*", Pattern.MULTILINE, "preprocessor")); + RegExpRule _regExpRule = new RegExpRule(getKeywords(datatypes), Pattern.MULTILINE, "color1"); + _regExpRule.setBold(true); + _regExpRuleList.add(_regExpRule); + _regExpRule = new RegExpRule(getKeywords(functions), Pattern.MULTILINE, "functions"); + _regExpRule.setBold(true); + _regExpRuleList.add(_regExpRule); + _regExpRule = new RegExpRule(getKeywords(keywords), Pattern.MULTILINE, "keyword"); + _regExpRule.setBold(true); + _regExpRuleList.add(_regExpRule); + setRegExpRuleList(_regExpRuleList); + + setCommonFileExtensionList(Arrays.asList("c", "cpp")); + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushCss.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushCss.java new file mode 100755 index 0000000..7c8f9fc --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushCss.java @@ -0,0 +1,91 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.brush; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; + +/** + * CSS brush. + * @author Chan Wai Shing + */ +public class BrushCss extends Brush { + + public BrushCss() { + super(); + + String keywords = "ascent azimuth background-attachment background-color background-image background-position " + + "background-repeat background baseline bbox border-collapse border-color border-spacing border-style border-top " + + "border-right border-bottom border-left border-top-color border-right-color border-bottom-color border-left-color " + + "border-top-style border-right-style border-bottom-style border-left-style border-top-width border-right-width " + + "border-bottom-width border-left-width border-width border bottom cap-height caption-side centerline clear clip color " + + "content counter-increment counter-reset cue-after cue-before cue cursor definition-src descent direction display " + + "elevation empty-cells float font-size-adjust font-family font-size font-stretch font-style font-variant font-weight font " + + "height left letter-spacing line-height list-style-image list-style-position list-style-type list-style margin-top " + + "margin-right margin-bottom margin-left margin marker-offset marks mathline max-height max-width min-height min-width orphans " + + "outline-color outline-style outline-width outline overflow padding-top padding-right padding-bottom padding-left padding page " + + "page-break-after page-break-before page-break-inside pause pause-after pause-before pitch pitch-range play-during position " + + "quotes right richness size slope src speak-header speak-numeral speak-punctuation speak speech-rate stemh stemv stress " + + "table-layout text-align top text-decoration text-indent text-shadow text-transform unicode-bidi unicode-range units-per-em " + + "vertical-align visibility voice-family volume white-space widows width widths word-spacing x-height z-index"; + String values = "above absolute all always aqua armenian attr aural auto avoid baseline behind below bidi-override black blink block blue bold bolder " + + "both bottom braille capitalize caption center center-left center-right circle close-quote code collapse compact condensed " + + "continuous counter counters crop cross crosshair cursive dashed decimal decimal-leading-zero default digits disc dotted double " + + "embed embossed e-resize expanded extra-condensed extra-expanded fantasy far-left far-right fast faster fixed format fuchsia " + + "gray green groove handheld hebrew help hidden hide high higher icon inline-table inline inset inside invert italic " + + "justify landscape large larger left-side left leftwards level lighter lime line-through list-item local loud lower-alpha " + + "lowercase lower-greek lower-latin lower-roman lower low ltr marker maroon medium message-box middle mix move narrower " + + "navy ne-resize no-close-quote none no-open-quote no-repeat normal nowrap n-resize nw-resize oblique olive once open-quote outset " + + "outside overline pointer portrait pre print projection purple red relative repeat repeat-x repeat-y rgb ridge right right-side " + + "rightwards rtl run-in screen scroll semi-condensed semi-expanded separate se-resize show silent silver slower slow " + + "small small-caps small-caption smaller soft solid speech spell-out square s-resize static status-bar sub super sw-resize " + + "table-caption table-cell table-column table-column-group table-footer-group table-header-group table-row table-row-group teal " + + "text-bottom text-top thick thin top transparent tty tv ultra-condensed ultra-expanded underline upper-alpha uppercase upper-latin " + + "upper-roman url visible wait white wider w-resize x-fast x-high x-large x-loud x-low x-slow x-small x-soft xx-large xx-small yellow"; + String fonts = "[mM]onospace [tT]ahoma [vV]erdana [aA]rial [hH]elvetica [sS]ans-serif [sS]erif [cC]ourier mono sans serif"; + + List _regExpRuleList = new ArrayList(); + _regExpRuleList.add(new RegExpRule(RegExpRule.multiLineCComments, "comments")); // multiline comments + _regExpRuleList.add(new RegExpRule(RegExpRule.doubleQuotedString, "string")); // double quoted strings + _regExpRuleList.add(new RegExpRule(RegExpRule.singleQuotedString, "string")); // single quoted strings + _regExpRuleList.add(new RegExpRule("\\#[a-fA-F0-9]{3,6}", "value")); // html colors + _regExpRuleList.add(new RegExpRule("(-?\\d+)(\\.\\d+)?(px|em|pt|\\:|\\%|)", "value")); // sizes + _regExpRuleList.add(new RegExpRule("!important", "color3")); // !important + _regExpRuleList.add(new RegExpRule(getKeywordsCSS(keywords), Pattern.MULTILINE, "keyword")); // keywords + _regExpRuleList.add(new RegExpRule(getValuesCSS(values), "value")); // values + _regExpRuleList.add(new RegExpRule(getKeywords(fonts), "color1")); // fonts + setRegExpRuleList(_regExpRuleList); + + setHTMLScriptRegExp(new HTMLScriptRegExp("(?:<|<)\\s*style.*?(?:>|>)", "(?:<|<)\\/\\s*style\\s*(?:>|>)")); + + setCommonFileExtensionList(Arrays.asList("css")); + } + + protected static String getKeywordsCSS(String str) { + return "\\b([a-z_]|)" + str.replaceAll("\\s", "(?=:)\\\\b|\\\\b([a-z_\\\\*]|\\\\*|)") + "(?=:)\\b"; + } + + protected static String getValuesCSS(String str) { + return "\\b" + str.replaceAll("\\s", "(?!-)(?!:)\\\\b|\\\\b()") + ":\\b"; + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushDelphi.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushDelphi.java new file mode 100755 index 0000000..d492baa --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushDelphi.java @@ -0,0 +1,62 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.brush; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; + +/** + * Delphi brush. + * @author Chan Wai Shing + */ +public class BrushDelphi extends Brush { + + public BrushDelphi() { + super(); + + String keywords = "abs addr and ansichar ansistring array as asm begin boolean byte cardinal " + + "case char class comp const constructor currency destructor div do double " + + "downto else end except exports extended false file finalization finally " + + "for function goto if implementation in inherited int64 initialization " + + "integer interface is label library longint longword mod nil not object " + + "of on or packed pansichar pansistring pchar pcurrency pdatetime pextended " + + "pint64 pointer private procedure program property pshortstring pstring " + + "pvariant pwidechar pwidestring protected public published raise real real48 " + + "record repeat set shl shortint shortstring shr single smallint string then " + + "threadvar to true try type unit until uses val var varirnt while widechar " + + "widestring with word write writeln xor"; + + List _regExpRuleList = new ArrayList(); + _regExpRuleList.add(new RegExpRule("\\(\\*[\\s\\S]*?\\*\\)", Pattern.MULTILINE, "comments")); // multiline comments (* *) + _regExpRuleList.add(new RegExpRule("\\{(?!\\$)[\\s\\S]*?\\}", Pattern.MULTILINE, "comments")); // multiline comments { } + _regExpRuleList.add(new RegExpRule(RegExpRule.singleLineCComments, "comments")); // one line + _regExpRuleList.add(new RegExpRule(RegExpRule.singleQuotedString, "string")); // strings + _regExpRuleList.add(new RegExpRule("\\{\\$[a-zA-Z]+ .+\\}", "color1")); // compiler Directives and Region tags + _regExpRuleList.add(new RegExpRule("\\b[\\d\\.]+\\b", "value")); // numbers 12345 + _regExpRuleList.add(new RegExpRule("\\$[a-zA-Z0-9]+\\b", "value")); // numbers $F5D3 + _regExpRuleList.add(new RegExpRule(getKeywords(keywords), Pattern.MULTILINE | Pattern.CASE_INSENSITIVE, "keyword")); // keyword + setRegExpRuleList(_regExpRuleList); + + setCommonFileExtensionList(Arrays.asList("pas")); + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushDiff.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushDiff.java new file mode 100755 index 0000000..e25025b --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushDiff.java @@ -0,0 +1,48 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.brush; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; + +/** + * Diff file brush. + * @author Chan Wai Shing + */ +public class BrushDiff extends Brush { + + public BrushDiff() { + super(); + + List _regExpRuleList = new ArrayList(); + _regExpRuleList.add(new RegExpRule("^\\+\\+\\+\\s.*$", Pattern.MULTILINE, "color2")); // new file + _regExpRuleList.add(new RegExpRule("^\\-\\-\\-\\s.*$", Pattern.MULTILINE, "color2")); // old file + _regExpRuleList.add(new RegExpRule("^\\s.*$", Pattern.MULTILINE, "color1")); // unchanged + _regExpRuleList.add(new RegExpRule("^@@.*@@$", Pattern.MULTILINE, "variable")); // location + _regExpRuleList.add(new RegExpRule("^\\+.*$", Pattern.MULTILINE, "string")); // additions + _regExpRuleList.add(new RegExpRule("^\\-.*$", Pattern.MULTILINE, "color3")); // deletions + setRegExpRuleList(_regExpRuleList); + + setCommonFileExtensionList(Arrays.asList("diff", "patch")); + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushErlang.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushErlang.java new file mode 100755 index 0000000..8f4ef92 --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushErlang.java @@ -0,0 +1,56 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.brush; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Pattern; + +/** + * Erlang brush. + * @author Chan Wai Shing + */ +public class BrushErlang extends Brush { + + public BrushErlang() { + super(); + + // Contributed by Jean-Lou Dupont + // http://jldupont.blogspot.com/2009/06/erlang-syntax-highlighter.html + + // According to: http://erlang.org/doc/reference_manual/introduction.html#1.5 + String keywords = "after and andalso band begin bnot bor bsl bsr bxor " + + "case catch cond div end fun if let not of or orelse " + + "query receive rem try when xor" + + // additional + " module export import define"; + + List _regExpRuleList = new ArrayList(); + _regExpRuleList.add(new RegExpRule("[A-Z][A-Za-z0-9_]+", "constants")); + _regExpRuleList.add(new RegExpRule("\\%.+", Pattern.MULTILINE, "comments")); + _regExpRuleList.add(new RegExpRule("\\?[A-Za-z0-9_]+", "preprocessor")); + _regExpRuleList.add(new RegExpRule("[a-z0-9_]+:[a-z0-9_]+", "functions")); + _regExpRuleList.add(new RegExpRule(RegExpRule.doubleQuotedString, "string")); + _regExpRuleList.add(new RegExpRule(RegExpRule.singleQuotedString, "string")); + _regExpRuleList.add(new RegExpRule(getKeywords(keywords), Pattern.MULTILINE, "keyword")); + setRegExpRuleList(_regExpRuleList); + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushGroovy.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushGroovy.java new file mode 100755 index 0000000..3e88923 --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushGroovy.java @@ -0,0 +1,74 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.brush; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; + +/** + * Groovy brush. + * @author Chan Wai Shing + */ +public class BrushGroovy extends Brush { + + public BrushGroovy() { + super(); + + // Contributed by Andres Almiray + // http://jroller.com/aalmiray/entry/nice_source_code_syntax_highlighter + + String keywords = "as assert break case catch class continue def default do else extends finally " + + "if in implements import instanceof interface new package property return switch " + + "throw throws try while public protected private static"; + String types = "void boolean byte char short int long float double"; + String constants = "null"; + String methods = "allProperties count get size " + + "collect each eachProperty eachPropertyName eachWithIndex find findAll " + + "findIndexOf grep inject max min reverseEach sort " + + "asImmutable asSynchronized flatten intersect join pop reverse subMap toList " + + "padRight padLeft contains eachMatch toCharacter toLong toUrl tokenize " + + "eachFile eachFileRecurse eachB yte eachLine readBytes readLine getText " + + "splitEachLine withReader append encodeBase64 decodeBase64 filterLine " + + "transformChar transformLine withOutputStream withPrintWriter withStream " + + "withStreams withWriter withWriterAppend write writeLine " + + "dump inspect invokeMethod print println step times upto use waitForOrKill " + + "getText"; + + List _regExpRuleList = new ArrayList(); + _regExpRuleList.add(new RegExpRule(RegExpRule.singleLineCComments, "comments")); // one line comments + _regExpRuleList.add(new RegExpRule(RegExpRule.multiLineCComments, "comments")); // multiline comments + _regExpRuleList.add(new RegExpRule(RegExpRule.doubleQuotedString, "string")); // strings + _regExpRuleList.add(new RegExpRule(RegExpRule.singleQuotedString, "string")); // strings + _regExpRuleList.add(new RegExpRule("\"\"\".*\"\"\"", "string")); // GStrings + _regExpRuleList.add(new RegExpRule("\\b([\\d]+(\\.[\\d]+)?|0x[a-f0-9]+)\\b", Pattern.CASE_INSENSITIVE, "value")); // numbers + _regExpRuleList.add(new RegExpRule(getKeywords(keywords), Pattern.MULTILINE, "keyword")); // goovy keyword + _regExpRuleList.add(new RegExpRule(getKeywords(types), Pattern.MULTILINE, "color1")); // goovy/java type + _regExpRuleList.add(new RegExpRule(getKeywords(constants), Pattern.MULTILINE, "constants")); // constants + _regExpRuleList.add(new RegExpRule(getKeywords(methods), Pattern.MULTILINE, "functions")); // methods + setRegExpRuleList(_regExpRuleList); + + setHTMLScriptRegExp(HTMLScriptRegExp.aspScriptTags); + + setCommonFileExtensionList(Arrays.asList("groovy")); + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushJScript.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushJScript.java new file mode 100755 index 0000000..94532ba --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushJScript.java @@ -0,0 +1,57 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.brush; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; + +/** + * JavaScript brush. + * @author Chan Wai Shing + */ +public class BrushJScript extends Brush { + + public BrushJScript() { + super(); + + String keywords = "break case catch continue " + + "default delete do else false " + + "for function if in instanceof " + + "new null return super switch " + + "this throw true try typeof var while with"; + + List _regExpRuleList = new ArrayList(); + _regExpRuleList.add(new RegExpRule(RegExpRule.singleLineCComments, "comments")); // one line comments + _regExpRuleList.add(new RegExpRule(RegExpRule.multiLineCComments, "comments")); // multiline comments + // it's a standard not to use multi-line string + _regExpRuleList.add(new RegExpRule(RegExpRule.doubleQuotedString, "string")); // double quoted strings + _regExpRuleList.add(new RegExpRule(RegExpRule.singleQuotedString, "string")); // single quoted strings + _regExpRuleList.add(new RegExpRule("\\s*#.*", Pattern.MULTILINE, "preprocessor")); // preprocessor tags like #region and #endregion + _regExpRuleList.add(new RegExpRule(getKeywords(keywords), Pattern.MULTILINE, "keyword")); // keywords + setRegExpRuleList(_regExpRuleList); + + setHTMLScriptRegExp(HTMLScriptRegExp.scriptScriptTags); + + setCommonFileExtensionList(Arrays.asList("js", "es")); + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushJava.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushJava.java new file mode 100755 index 0000000..83a5f05 --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushJava.java @@ -0,0 +1,61 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.brush; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; + +/** + * Java brush. + * @author Chan Wai Shing + */ +public class BrushJava extends Brush { + + public BrushJava() { + super(); + + String keywords = "abstract assert boolean break byte case catch char class const " + + "continue default do double else enum extends " + + "false final finally float for goto if implements import " + + "instanceof int interface long native new null " + + "package private protected public return " + + "short static strictfp super switch synchronized this throw throws true " + + "transient try void volatile while"; + + List _regExpRuleList = new ArrayList(); + _regExpRuleList.add(new RegExpRule(RegExpRule.singleLineCComments, "comments")); // one line comments + _regExpRuleList.add(new RegExpRule("\\/\\*([^\\*][\\s\\S]*?)?\\*\\/", Pattern.MULTILINE, "comments")); // multiline comments + _regExpRuleList.add(new RegExpRule("\\/\\*(?!\\*\\/)\\*[\\s\\S]*?\\*\\/", Pattern.MULTILINE, "preprocessor")); // documentation comments + _regExpRuleList.add(new RegExpRule(RegExpRule.doubleQuotedString, "string")); // strings + _regExpRuleList.add(new RegExpRule(RegExpRule.singleQuotedString, "string")); // strings + _regExpRuleList.add(new RegExpRule("\\b([\\d]+(\\.[\\d]+)?|0x[a-f0-9]+)\\b", Pattern.CASE_INSENSITIVE, "value")); // numbers + _regExpRuleList.add(new RegExpRule("(?!\\@interface\\b)\\@[\\$\\w]+\\b", "color1")); // annotation @anno + _regExpRuleList.add(new RegExpRule("\\@interface\\b", "color2")); // @interface keyword + _regExpRuleList.add(new RegExpRule(getKeywords(keywords), Pattern.MULTILINE, "keyword")); // java keyword + setRegExpRuleList(_regExpRuleList); + + setHTMLScriptRegExp(new HTMLScriptRegExp("(?:<|<)%[@!=]?", "%(?:>|>)")); + + setCommonFileExtensionList(Arrays.asList("java")); + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushJavaFX.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushJavaFX.java new file mode 100755 index 0000000..caa6a64 --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushJavaFX.java @@ -0,0 +1,64 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.brush; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; + +/** + * Java FX brush. + * @author Chan Wai Shing + */ +public class BrushJavaFX extends Brush { + + public BrushJavaFX() { + super(); + + // Contributed by Patrick Webster + // http://patrickwebster.blogspot.com/2009/04/javafx-brush-for-syntaxhighlighter.html + + String datatypes = "Boolean Byte Character Double Duration " + + "Float Integer Long Number Short String Void"; + String keywords = "abstract after and as assert at before bind bound break catch class " + + "continue def delete else exclusive extends false finally first for from " + + "function if import in indexof init insert instanceof into inverse last " + + "lazy mixin mod nativearray new not null on or override package postinit " + + "protected public public-init public-read replace return reverse sizeof " + + "step super then this throw true try tween typeof var where while with " + + "attribute let private readonly static trigger"; + + List _regExpRuleList = new ArrayList(); + _regExpRuleList.add(new RegExpRule(RegExpRule.singleLineCComments, "comments")); + _regExpRuleList.add(new RegExpRule(RegExpRule.multiLineCComments, "comments")); + _regExpRuleList.add(new RegExpRule(RegExpRule.singleQuotedString, "string")); + _regExpRuleList.add(new RegExpRule(RegExpRule.doubleQuotedString, "string")); + _regExpRuleList.add(new RegExpRule("(-?\\.?)(\\b(\\d*\\.?\\d+|\\d+\\.?\\d*)(e[+-]?\\d+)?|0x[a-f\\d]+)\\b\\.?", Pattern.CASE_INSENSITIVE, "color2")); // numbers + _regExpRuleList.add(new RegExpRule(getKeywords(datatypes), Pattern.MULTILINE, "variable")); // datatypes + _regExpRuleList.add(new RegExpRule(getKeywords(keywords), Pattern.MULTILINE, "keyword")); + setRegExpRuleList(_regExpRuleList); + + setHTMLScriptRegExp(HTMLScriptRegExp.aspScriptTags); + + setCommonFileExtensionList(Arrays.asList("fx")); + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushPerl.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushPerl.java new file mode 100755 index 0000000..9ea3b50 --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushPerl.java @@ -0,0 +1,76 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.brush; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; + +/** + * Perl brush. + * @author Chan Wai Shing + */ +public class BrushPerl extends Brush { + + public BrushPerl() { + super(); + + // Contributed by David Simmons-Duffin and Marty Kube + + String funcs = "abs accept alarm atan2 bind binmode chdir chmod chomp chop chown chr " + + "chroot close closedir connect cos crypt defined delete each endgrent " + + "endhostent endnetent endprotoent endpwent endservent eof exec exists " + + "exp fcntl fileno flock fork format formline getc getgrent getgrgid " + + "getgrnam gethostbyaddr gethostbyname gethostent getlogin getnetbyaddr " + + "getnetbyname getnetent getpeername getpgrp getppid getpriority " + + "getprotobyname getprotobynumber getprotoent getpwent getpwnam getpwuid " + + "getservbyname getservbyport getservent getsockname getsockopt glob " + + "gmtime grep hex index int ioctl join keys kill lc lcfirst length link " + + "listen localtime lock log lstat map mkdir msgctl msgget msgrcv msgsnd " + + "oct open opendir ord pack pipe pop pos print printf prototype push " + + "quotemeta rand read readdir readline readlink readpipe recv rename " + + "reset reverse rewinddir rindex rmdir scalar seek seekdir select semctl " + + "semget semop send setgrent sethostent setnetent setpgrp setpriority " + + "setprotoent setpwent setservent setsockopt shift shmctl shmget shmread " + + "shmwrite shutdown sin sleep socket socketpair sort splice split sprintf " + + "sqrt srand stat study substr symlink syscall sysopen sysread sysseek " + + "system syswrite tell telldir time times tr truncate uc ucfirst umask " + + "undef unlink unpack unshift utime values vec wait waitpid warn write"; + String keywords = "bless caller continue dbmclose dbmopen die do dump else elsif eval exit " + + "for foreach goto if import last local my next no our package redo ref " + + "require return sub tie tied unless untie until use wantarray while"; + + List _regExpRuleList = new ArrayList(); + _regExpRuleList.add(new RegExpRule("#[^!].*$", Pattern.MULTILINE, "comments")); + _regExpRuleList.add(new RegExpRule("^\\s*#!.*$", Pattern.MULTILINE, "preprocessor")); // shebang + _regExpRuleList.add(new RegExpRule(RegExpRule.doubleQuotedString, "string")); + _regExpRuleList.add(new RegExpRule(RegExpRule.singleQuotedString, "string")); + _regExpRuleList.add(new RegExpRule("(\\$|@|%)\\w+", "variable")); + _regExpRuleList.add(new RegExpRule(getKeywords(funcs), Pattern.MULTILINE | Pattern.CASE_INSENSITIVE, "functions")); + _regExpRuleList.add(new RegExpRule(getKeywords(keywords), Pattern.MULTILINE, "keyword")); + setRegExpRuleList(_regExpRuleList); + + setHTMLScriptRegExp(HTMLScriptRegExp.phpScriptTags); + + setCommonFileExtensionList(Arrays.asList("pl", "pm", "t")); + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushPhp.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushPhp.java new file mode 100755 index 0000000..faf91dc --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushPhp.java @@ -0,0 +1,93 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.brush; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; + +/** + * PHP brush. + * @author Chan Wai Shing + */ +public class BrushPhp extends Brush { + + public BrushPhp() { + super(); + + String funcs = "abs acos acosh addcslashes addslashes " + + "array_change_key_case array_chunk array_combine array_count_values array_diff " + + "array_diff_assoc array_diff_key array_diff_uassoc array_diff_ukey array_fill " + + "array_filter array_flip array_intersect array_intersect_assoc array_intersect_key " + + "array_intersect_uassoc array_intersect_ukey array_key_exists array_keys array_map " + + "array_merge array_merge_recursive array_multisort array_pad array_pop array_product " + + "array_push array_rand array_reduce array_reverse array_search array_shift " + + "array_slice array_splice array_sum array_udiff array_udiff_assoc " + + "array_udiff_uassoc array_uintersect array_uintersect_assoc " + + "array_uintersect_uassoc array_unique array_unshift array_values array_walk " + + "array_walk_recursive atan atan2 atanh base64_decode base64_encode base_convert " + + "basename bcadd bccomp bcdiv bcmod bcmul bindec bindtextdomain bzclose bzcompress " + + "bzdecompress bzerrno bzerror bzerrstr bzflush bzopen bzread bzwrite ceil chdir " + + "checkdate checkdnsrr chgrp chmod chop chown chr chroot chunk_split class_exists " + + "closedir closelog copy cos cosh count count_chars date decbin dechex decoct " + + "deg2rad delete ebcdic2ascii echo empty end ereg ereg_replace eregi eregi_replace error_log " + + "error_reporting escapeshellarg escapeshellcmd eval exec exit exp explode extension_loaded " + + "feof fflush fgetc fgetcsv fgets fgetss file_exists file_get_contents file_put_contents " + + "fileatime filectime filegroup fileinode filemtime fileowner fileperms filesize filetype " + + "floatval flock floor flush fmod fnmatch fopen fpassthru fprintf fputcsv fputs fread fscanf " + + "fseek fsockopen fstat ftell ftok getallheaders getcwd getdate getenv gethostbyaddr gethostbyname " + + "gethostbynamel getimagesize getlastmod getmxrr getmygid getmyinode getmypid getmyuid getopt " + + "getprotobyname getprotobynumber getrandmax getrusage getservbyname getservbyport gettext " + + "gettimeofday gettype glob gmdate gmmktime ini_alter ini_get ini_get_all ini_restore ini_set " + + "interface_exists intval ip2long is_a is_array is_bool is_callable is_dir is_double " + + "is_executable is_file is_finite is_float is_infinite is_int is_integer is_link is_long " + + "is_nan is_null is_numeric is_object is_readable is_real is_resource is_scalar is_soap_fault " + + "is_string is_subclass_of is_uploaded_file is_writable is_writeable mkdir mktime nl2br " + + "parse_ini_file parse_str parse_url passthru pathinfo print readlink realpath rewind rewinddir rmdir " + + "round str_ireplace str_pad str_repeat str_replace str_rot13 str_shuffle str_split " + + "str_word_count strcasecmp strchr strcmp strcoll strcspn strftime strip_tags stripcslashes " + + "stripos stripslashes stristr strlen strnatcasecmp strnatcmp strncasecmp strncmp strpbrk " + + "strpos strptime strrchr strrev strripos strrpos strspn strstr strtok strtolower strtotime " + + "strtoupper strtr strval substr substr_compare"; + String keywords = "abstract and array as break case catch cfunction class clone const continue declare default die do " + + "else elseif enddeclare endfor endforeach endif endswitch endwhile extends final for foreach " + + "function include include_once global goto if implements interface instanceof namespace new " + + "old_function or private protected public return require require_once static switch " + + "throw try use var while xor"; + String constants = "__FILE__ __LINE__ __METHOD__ __FUNCTION__ __CLASS__"; + + List _regExpRuleList = new ArrayList(); + _regExpRuleList.add(new RegExpRule(RegExpRule.singleLineCComments, "comments")); // one line comments + _regExpRuleList.add(new RegExpRule(RegExpRule.multiLineCComments, "comments")); // multiline comments + _regExpRuleList.add(new RegExpRule(RegExpRule.doubleQuotedString, "string")); // double quoted strings + _regExpRuleList.add(new RegExpRule(RegExpRule.singleQuotedString, "string")); // single quoted strings + _regExpRuleList.add(new RegExpRule("\\$\\w+", "variable")); // variables + _regExpRuleList.add(new RegExpRule(getKeywords(funcs), Pattern.MULTILINE | Pattern.CASE_INSENSITIVE, "functions")); // common functions + _regExpRuleList.add(new RegExpRule(getKeywords(constants), Pattern.MULTILINE | Pattern.CASE_INSENSITIVE, "constants")); // constants + _regExpRuleList.add(new RegExpRule(getKeywords(keywords), Pattern.MULTILINE, "keyword")); // keyword + setRegExpRuleList(_regExpRuleList); + + setHTMLScriptRegExp(HTMLScriptRegExp.phpScriptTags); + + setCommonFileExtensionList(Arrays.asList("php", "php3", "php4", "php5", "phps", "phtml")); + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushPlain.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushPlain.java new file mode 100755 index 0000000..ac01db1 --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushPlain.java @@ -0,0 +1,32 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.brush; + +/** + * Plain text file brush. + * @author Chan Wai Shing + */ +public class BrushPlain extends Brush { + + public BrushPlain() { + super(); + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushPowerShell.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushPowerShell.java new file mode 100755 index 0000000..c0acf95 --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushPowerShell.java @@ -0,0 +1,81 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.brush; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; + +/** + * PowerShell brush. + * @author Chan Wai Shing + */ +public class BrushPowerShell extends Brush { + + public BrushPowerShell() { + super(); + + // Contributes by B.v.Zanten, Getronics + // http://confluence.atlassian.com/display/CONFEXT/New+Code+Macro + + String keywords = "Add-Content Add-History Add-Member Add-PSSnapin Clear(-Content)? Clear-Item " + + "Clear-ItemProperty Clear-Variable Compare-Object ConvertFrom-SecureString Convert-Path " + + "ConvertTo-Html ConvertTo-SecureString Copy(-Item)? Copy-ItemProperty Export-Alias " + + "Export-Clixml Export-Console Export-Csv ForEach(-Object)? Format-Custom Format-List " + + "Format-Table Format-Wide Get-Acl Get-Alias Get-AuthenticodeSignature Get-ChildItem Get-Command " + + "Get-Content Get-Credential Get-Culture Get-Date Get-EventLog Get-ExecutionPolicy " + + "Get-Help Get-History Get-Host Get-Item Get-ItemProperty Get-Location Get-Member " + + "Get-PfxCertificate Get-Process Get-PSDrive Get-PSProvider Get-PSSnapin Get-Service " + + "Get-TraceSource Get-UICulture Get-Unique Get-Variable Get-WmiObject Group-Object " + + "Import-Alias Import-Clixml Import-Csv Invoke-Expression Invoke-History Invoke-Item " + + "Join-Path Measure-Command Measure-Object Move(-Item)? Move-ItemProperty New-Alias " + + "New-Item New-ItemProperty New-Object New-PSDrive New-Service New-TimeSpan " + + "New-Variable Out-Default Out-File Out-Host Out-Null Out-Printer Out-String Pop-Location " + + "Push-Location Read-Host Remove-Item Remove-ItemProperty Remove-PSDrive Remove-PSSnapin " + + "Remove-Variable Rename-Item Rename-ItemProperty Resolve-Path Restart-Service Resume-Service " + + "Select-Object Select-String Set-Acl Set-Alias Set-AuthenticodeSignature Set-Content " + + "Set-Date Set-ExecutionPolicy Set-Item Set-ItemProperty Set-Location Set-PSDebug " + + "Set-Service Set-TraceSource Set(-Variable)? Sort-Object Split-Path Start-Service " + + "Start-Sleep Start-Transcript Stop-Process Stop-Service Stop-Transcript Suspend-Service " + + "Tee-Object Test-Path Trace-Command Update-FormatData Update-TypeData Where(-Object)? " + + "Write-Debug Write-Error Write(-Host)? Write-Output Write-Progress Write-Verbose Write-Warning"; + String alias = "ac asnp clc cli clp clv cpi cpp cvpa diff epal epcsv fc fl " + + "ft fw gal gc gci gcm gdr ghy gi gl gm gp gps group gsv " + + "gsnp gu gv gwmi iex ihy ii ipal ipcsv mi mp nal ndr ni nv oh rdr " + + "ri rni rnp rp rsnp rv rvpa sal sasv sc select si sl sleep sort sp " + + "spps spsv sv tee cat cd cp h history kill lp ls " + + "mount mv popd ps pushd pwd r rm rmdir echo cls chdir del dir " + + "erase rd ren type % \\?"; + + List _regExpRuleList = new ArrayList(); + _regExpRuleList.add(new RegExpRule("#.*$", Pattern.MULTILINE, "comments")); // one line comments + _regExpRuleList.add(new RegExpRule("\\$[a-zA-Z0-9]+\\b", "value")); // variables $Computer1 + _regExpRuleList.add(new RegExpRule("\\-[a-zA-Z]+\\b", "keyword")); // Operators -not -and -eq + _regExpRuleList.add(new RegExpRule(RegExpRule.doubleQuotedString, "string")); // strings + _regExpRuleList.add(new RegExpRule(RegExpRule.singleQuotedString, "string")); // strings + _regExpRuleList.add(new RegExpRule(getKeywords(keywords), Pattern.MULTILINE | Pattern.CASE_INSENSITIVE, "keyword")); + _regExpRuleList.add(new RegExpRule(getKeywords(alias), Pattern.MULTILINE | Pattern.CASE_INSENSITIVE, "keyword")); + setRegExpRuleList(_regExpRuleList); + + setCommonFileExtensionList(Arrays.asList("ps1")); + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushPython.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushPython.java new file mode 100755 index 0000000..be08329 --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushPython.java @@ -0,0 +1,69 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.brush; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; + +/** + * Python brush. + * @author Chan Wai Shing + */ +public class BrushPython extends Brush { + + public BrushPython() { + super(); + + // Contributed by Gheorghe Milas and Ahmad Sherif + + String keywords = "and assert break class continue def del elif else " + + "except exec finally for from global if import in is " + + "lambda not or pass print raise return try yield while"; + String funcs = "__import__ abs all any apply basestring bin bool buffer callable " + + "chr classmethod cmp coerce compile complex delattr dict dir " + + "divmod enumerate eval execfile file filter float format frozenset " + + "getattr globals hasattr hash help hex id input int intern " + + "isinstance issubclass iter len list locals long map max min next " + + "object oct open ord pow print property range raw_input reduce " + + "reload repr reversed round set setattr slice sorted staticmethod " + + "str sum super tuple type type unichr unicode vars xrange zip"; + String special = "None True False self cls class_"; + + List _regExpRuleList = new ArrayList(); + _regExpRuleList.add(new RegExpRule(RegExpRule.singleLinePerlComments, "comments")); + _regExpRuleList.add(new RegExpRule("^\\s*@\\w+", Pattern.MULTILINE, "color2")); + _regExpRuleList.add(new RegExpRule("(['\\\"]{3})([^['\\\"]{3}])*?['\\\"]{3}", Pattern.MULTILINE, "comments")); + _regExpRuleList.add(new RegExpRule("\"(?!\")(?:\\.|\\\\\\\"|[^\\\"\"\\n])*\"", Pattern.MULTILINE, "string")); + _regExpRuleList.add(new RegExpRule("'(?!')(?:\\.|(\\\\\\')|[^\\''\\n])*'", Pattern.MULTILINE, "string")); + _regExpRuleList.add(new RegExpRule("\\+|\\-|\\*|\\/|\\%|=|==", Pattern.MULTILINE, "keyword")); + _regExpRuleList.add(new RegExpRule("\\b\\d+\\.?\\w*", "value")); + _regExpRuleList.add(new RegExpRule(getKeywords(funcs), Pattern.MULTILINE | Pattern.CASE_INSENSITIVE, "functions")); + _regExpRuleList.add(new RegExpRule(getKeywords(keywords), Pattern.MULTILINE, "keyword")); + _regExpRuleList.add(new RegExpRule(getKeywords(special), Pattern.MULTILINE, "color1")); + setRegExpRuleList(_regExpRuleList); + + setHTMLScriptRegExp(HTMLScriptRegExp.aspScriptTags); + + setCommonFileExtensionList(Arrays.asList("py")); + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushRuby.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushRuby.java new file mode 100755 index 0000000..36be97f --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushRuby.java @@ -0,0 +1,63 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.brush; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; + +/** + * Ruby brush. + * @author Chan Wai Shing + */ +public class BrushRuby extends Brush { + + public BrushRuby() { + super(); + + // Contributed by Erik Peterson. + + String keywords = "alias and BEGIN begin break case class def define_method defined do each else elsif " + + "END end ensure false for if in module new next nil not or raise redo rescue retry return " + + "self super then throw true undef unless until when while yield"; + String builtins = "Array Bignum Binding Class Continuation Dir Exception FalseClass File::Stat File Fixnum Fload " + + "Hash Integer IO MatchData Method Module NilClass Numeric Object Proc Range Regexp String Struct::TMS Symbol " + + "ThreadGroup Thread Time TrueClass"; + + List _regExpRuleList = new ArrayList(); + _regExpRuleList.add(new RegExpRule(RegExpRule.singleLinePerlComments, "comments")); // one line comments + _regExpRuleList.add(new RegExpRule(RegExpRule.doubleQuotedString, "string")); // double quoted strings + _regExpRuleList.add(new RegExpRule(RegExpRule.singleQuotedString, "string")); // single quoted strings + _regExpRuleList.add(new RegExpRule("\\b[A-Z0-9_]+\\b", "constants")); // constants + _regExpRuleList.add(new RegExpRule(":[a-z][A-Za-z0-9_]*", "color2")); // symbols + RegExpRule _regExpRule = new RegExpRule("(\\$|@@|@)\\w+", "variable"); + _regExpRule.setBold(true); + _regExpRuleList.add(_regExpRule); // $global, @instance, and @@class variables + _regExpRuleList.add(new RegExpRule(getKeywords(keywords), Pattern.MULTILINE, "keyword")); // keywords + _regExpRuleList.add(new RegExpRule(getKeywords(builtins), Pattern.MULTILINE, "color1")); // builtins + setRegExpRuleList(_regExpRuleList); + + setHTMLScriptRegExp(HTMLScriptRegExp.phpScriptTags); + + setCommonFileExtensionList(Arrays.asList("rb", "rbw")); + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushSass.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushSass.java new file mode 100755 index 0000000..b49774c --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushSass.java @@ -0,0 +1,105 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.brush; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; + +/** + * Sass brush. + * @author Chan Wai Shing + */ +public class BrushSass extends Brush { + + public BrushSass() { + super(); + + String keywords = "ascent azimuth background-attachment background-color background-image background-position " + + "background-repeat background baseline bbox border-collapse border-color border-spacing border-style border-top " + + "border-right border-bottom border-left border-top-color border-right-color border-bottom-color border-left-color " + + "border-top-style border-right-style border-bottom-style border-left-style border-top-width border-right-width " + + "border-bottom-width border-left-width border-width border bottom cap-height caption-side centerline clear clip color " + + "content counter-increment counter-reset cue-after cue-before cue cursor definition-src descent direction display " + + "elevation empty-cells float font-size-adjust font-family font-size font-stretch font-style font-variant font-weight font " + + "height left letter-spacing line-height list-style-image list-style-position list-style-type list-style margin-top " + + "margin-right margin-bottom margin-left margin marker-offset marks mathline max-height max-width min-height min-width orphans " + + "outline-color outline-style outline-width outline overflow padding-top padding-right padding-bottom padding-left padding page " + + "page-break-after page-break-before page-break-inside pause pause-after pause-before pitch pitch-range play-during position " + + "quotes right richness size slope src speak-header speak-numeral speak-punctuation speak speech-rate stemh stemv stress " + + "table-layout text-align top text-decoration text-indent text-shadow text-transform unicode-bidi unicode-range units-per-em " + + "vertical-align visibility voice-family volume white-space widows width widths word-spacing x-height z-index zoom"; + String values = "above absolute all always aqua armenian attr aural auto avoid baseline behind below bidi-override black blink block blue bold bolder " + + "both bottom braille capitalize caption center center-left center-right circle close-quote code collapse compact condensed " + + "continuous counter counters crop cross crosshair cursive dashed decimal decimal-leading-zero digits disc dotted double " + + "embed embossed e-resize expanded extra-condensed extra-expanded fantasy far-left far-right fast faster fixed format fuchsia " + + "gray green groove handheld hebrew help hidden hide high higher icon inline-table inline inset inside invert italic " + + "justify landscape large larger left-side left leftwards level lighter lime line-through list-item local loud lower-alpha " + + "lowercase lower-greek lower-latin lower-roman lower low ltr marker maroon medium message-box middle mix move narrower " + + "navy ne-resize no-close-quote none no-open-quote no-repeat normal nowrap n-resize nw-resize oblique olive once open-quote outset " + + "outside overline pointer portrait pre print projection purple red relative repeat repeat-x repeat-y rgb ridge right right-side " + + "rightwards rtl run-in screen scroll semi-condensed semi-expanded separate se-resize show silent silver slower slow " + + "small small-caps small-caption smaller soft solid speech spell-out square s-resize static status-bar sub super sw-resize " + + "table-caption table-cell table-column table-column-group table-footer-group table-header-group table-row table-row-group teal " + + "text-bottom text-top thick thin top transparent tty tv ultra-condensed ultra-expanded underline upper-alpha uppercase upper-latin " + + "upper-roman url visible wait white wider w-resize x-fast x-high x-large x-loud x-low x-slow x-small x-soft xx-large xx-small yellow"; + String fonts = "[mM]onospace [tT]ahoma [vV]erdana [aA]rial [hH]elvetica [sS]ans-serif [sS]erif [cC]ourier mono sans serif"; + String statements = "!important !default"; + String preprocessors = "import extend debug warn if for while mixin include"; + + List _regExpRuleList = new ArrayList(); + _regExpRuleList.add(new RegExpRule(RegExpRule.multiLineCComments, "comments")); // multiline comments + _regExpRuleList.add(new RegExpRule(RegExpRule.singleLineCComments, "comments")); // singleline comments + _regExpRuleList.add(new RegExpRule(RegExpRule.doubleQuotedString, "string")); // double quoted strings + _regExpRuleList.add(new RegExpRule(RegExpRule.singleQuotedString, "string")); // single quoted strings + _regExpRuleList.add(new RegExpRule("\\#[a-fA-F0-9]{3,6}", "value")); // html colors + _regExpRuleList.add(new RegExpRule("\\b(-?\\d+)(\\.\\d+)?(px|em|pt|\\:|\\%|)\\b", "value")); // sizes + _regExpRuleList.add(new RegExpRule("(\\$|!)\\w+", "variable")); // variables + _regExpRuleList.add(new RegExpRule(getKeywords(statements), "color3")); // statements + _regExpRuleList.add(new RegExpRule(getKeywordsPrependedBy(preprocessors, "@"), "preprocessor")); // preprocessor + _regExpRuleList.add(new RegExpRule("(^|\\n)\\s*=.*", "functions")); // short mixin declarations + _regExpRuleList.add(new RegExpRule("(^|\\n)\\s*\\+.*", "functions")); // short mixin call + _regExpRuleList.add(new RegExpRule("&", "keyword")); // & + _regExpRuleList.add(new RegExpRule("#(\\w|-|_)+", "color2")); // ids + // original code uses 'color4' which do not exist yet, here uses color1 as a temporary replacement + _regExpRuleList.add(new RegExpRule("(\\.(\\w|-|_)+)", "color1")); // classes + _regExpRuleList.add(new RegExpRule(getKeywordsCSS(keywords), Pattern.MULTILINE, "keyword")); // keywords + _regExpRuleList.add(new RegExpRule(getKeywordsPrependedBy(keywords, ":"), "keyword")); // :keyword value + _regExpRuleList.add(new RegExpRule(getValuesCSS(values), "value")); // values + _regExpRuleList.add(new RegExpRule(getKeywords(fonts), "color1")); // fonts + setRegExpRuleList(_regExpRuleList); + + setCommonFileExtensionList(Arrays.asList("sass", "scss")); + } + + protected static String getKeywordsCSS(String str) { + return "\\b([a-z_]|)" + str.replaceAll("\\s", "(?=:)\\\\b|\\\\b([a-z_\\\\*]|\\\\*|)") + "(?=:)\\b"; + } + + protected static String getValuesCSS(String str) { + return "\\b" + str.replaceAll("\\s", "(?!-)(?!:)\\\\b|\\\\b()") + ":\\b"; + } + + protected static String getKeywordsPrependedBy(String keywords, String by) { + return "(?:" + by + "\\b" + keywords.replaceAll("^\\s+|\\s+$", "").replaceAll("\\s+", "|" + by + "\\b").replaceAll("^\\s+|\\s+$", "") + ")\\b"; + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushScala.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushScala.java new file mode 100755 index 0000000..037789f --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushScala.java @@ -0,0 +1,58 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.brush; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; + +/** + * Scala brush. + * @author Chan Wai Shing + */ +public class BrushScala extends Brush { + + public BrushScala() { + super(); + + // Contributed by Yegor Jbanov and David Bernard. + + String keywords = "val sealed case def true trait implicit forSome import match object null finally super " + + "override try lazy for var catch throw type extends class while with new final yield abstract " + + "else do if return protected private this package false"; + String keyops = "[_:=><%#@]+"; + + List _regExpRuleList = new ArrayList(); + _regExpRuleList.add(new RegExpRule(RegExpRule.singleLineCComments, "comments")); // one line comments + _regExpRuleList.add(new RegExpRule(RegExpRule.multiLineCComments, "comments")); // multiline comments + _regExpRuleList.add(new RegExpRule(RegExpRule.multiLineSingleQuotedString, "string")); // multi-line strings + // problem: scala should start multiple line string with triple double-quote + _regExpRuleList.add(new RegExpRule(RegExpRule.multiLineDoubleQuotedString, "string")); // double-quoted string + _regExpRuleList.add(new RegExpRule(RegExpRule.singleQuotedString, "string")); // strings + _regExpRuleList.add(new RegExpRule("0x[a-f0-9]+|\\d+(\\.\\d+)?", Pattern.CASE_INSENSITIVE, "value")); // numbers + _regExpRuleList.add(new RegExpRule(getKeywords(keywords), Pattern.MULTILINE, "keyword")); // keywords + _regExpRuleList.add(new RegExpRule(keyops, Pattern.MULTILINE, "keyword")); // scala keyword + setRegExpRuleList(_regExpRuleList); + + setCommonFileExtensionList(Arrays.asList("scl", "scala")); + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushSql.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushSql.java new file mode 100755 index 0000000..cf6df95 --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushSql.java @@ -0,0 +1,70 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.brush; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; + +/** + * SQL brush. + * @author Chan Wai Shing + */ +public class BrushSql extends Brush { + + public BrushSql() { + super(); + + String funcs = "abs avg case cast coalesce convert count current_timestamp " + + "current_user day isnull left lower month nullif replace right " + + "session_user space substring sum system_user upper user year"; + String keywords = "absolute action add after alter as asc at authorization begin bigint " + + "binary bit by cascade char character check checkpoint close collate " + + "column commit committed connect connection constraint contains continue " + + "create cube current current_date current_time cursor database date " + + "deallocate dec decimal declare default delete desc distinct double drop " + + "dynamic else end end-exec escape except exec execute false fetch first " + + "float for force foreign forward free from full function global goto grant " + + "group grouping having hour ignore index inner insensitive insert instead " + + "int integer intersect into is isolation key last level load local max min " + + "minute modify move name national nchar next no numeric of off on only " + + "open option order out output partial password precision prepare primary " + + "prior privileges procedure public read real references relative repeatable " + + "restrict return returns revoke rollback rollup rows rule schema scroll " + + "second section select sequence serializable set size smallint static " + + "statistics table temp temporary then time timestamp to top transaction " + + "translation trigger true truncate uncommitted union unique update values " + + "varchar varying view when where with work"; + String operators = "all and any between cross in join like not null or outer some"; + + List _regExpRuleList = new ArrayList(); + _regExpRuleList.add(new RegExpRule("--(.*)$", Pattern.MULTILINE, "comments")); // one line and multiline comments + _regExpRuleList.add(new RegExpRule(RegExpRule.multiLineDoubleQuotedString, "string")); // double quoted strings + _regExpRuleList.add(new RegExpRule(RegExpRule.multiLineSingleQuotedString, "string")); // single quoted strings + _regExpRuleList.add(new RegExpRule(getKeywords(funcs), Pattern.MULTILINE | Pattern.CASE_INSENSITIVE, "color2")); // functions + _regExpRuleList.add(new RegExpRule(getKeywords(operators), Pattern.MULTILINE | Pattern.CASE_INSENSITIVE, "color1")); // operators and such + _regExpRuleList.add(new RegExpRule(getKeywords(keywords), Pattern.MULTILINE | Pattern.CASE_INSENSITIVE, "keyword"));// keyword + setRegExpRuleList(_regExpRuleList); + + setCommonFileExtensionList(Arrays.asList("sql")); + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushVb.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushVb.java new file mode 100755 index 0000000..4b7d276 --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushVb.java @@ -0,0 +1,63 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.brush; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; + +/** + * Visual Basic brush. + * @author Chan Wai Shing + */ +public class BrushVb extends Brush { + + public BrushVb() { + super(); + + String keywords = "AddHandler AddressOf AndAlso Alias And Ansi As Assembly Auto " + + "Boolean ByRef Byte ByVal Call Case Catch CBool CByte CChar CDate " + + "CDec CDbl Char CInt Class CLng CObj Const CShort CSng CStr CType " + + "Date Decimal Declare Default Delegate Dim DirectCast Do Double Each " + + "Else ElseIf End Enum Erase Error Event Exit False Finally For Friend " + + "Function Get GetType GoSub GoTo Handles If Implements Imports In " + + "Inherits Integer Interface Is Let Lib Like Long Loop Me Mod Module " + + "MustInherit MustOverride MyBase MyClass Namespace New Next Not Nothing " + + "NotInheritable NotOverridable Object On Option Optional Or OrElse " + + "Overloads Overridable Overrides ParamArray Preserve Private Property " + + "Protected Public RaiseEvent ReadOnly ReDim REM RemoveHandler Resume " + + "Return Select Set Shadows Shared Short Single Static Step Stop String " + + "Structure Sub SyncLock Then Throw To True Try TypeOf Unicode Until " + + "Variant When While With WithEvents WriteOnly Xor"; + + List _regExpRuleList = new ArrayList(); + _regExpRuleList.add(new RegExpRule("'.*$", Pattern.MULTILINE, "comments")); // one line comments + _regExpRuleList.add(new RegExpRule(RegExpRule.doubleQuotedString, "string")); // strings + _regExpRuleList.add(new RegExpRule("^\\s*#.*$", Pattern.MULTILINE, "preprocessor")); // preprocessor tags like #region and #endregion + _regExpRuleList.add(new RegExpRule(getKeywords(keywords), Pattern.MULTILINE, "keyword")); // vb keyword + setRegExpRuleList(_regExpRuleList); + + setHTMLScriptRegExp(HTMLScriptRegExp.aspScriptTags); + + setCommonFileExtensionList(Arrays.asList("vb", "vbs")); + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushXml.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushXml.java new file mode 100755 index 0000000..7c9073a --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/BrushXml.java @@ -0,0 +1,71 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.brush; + +import java.util.*; +import java.util.regex.Pattern; + +/** + * General XML (include HTML) brush. + * @author Chan Wai Shing + */ +public class BrushXml extends Brush { + + public BrushXml() { + super(); + + List _regExpRuleList = new ArrayList(); + + _regExpRuleList.add(new RegExpRule("(\\<|<)\\!\\[[\\w\\s]*?\\[(.|\\s)*?\\]\\](\\>|>)", Pattern.MULTILINE, "color2")); // + _regExpRuleList.add(new RegExpRule(RegExpRule.xmlComments, "comments")); // + + // regular expression for highlighting the tag + RegExpRule tagRegExpRule = new RegExpRule("(?:<|<)[\\s\\/\\?]*([:\\w-\\.]+)", Pattern.COMMENTS, ""); + Map tagMatchesToStyleKey = new HashMap(); + // highlight the tag only, not including the symbols at the start, 1 means the group 1 of the matched results + tagMatchesToStyleKey.put(1, "keyword"); + tagRegExpRule.setGroupOperations(tagMatchesToStyleKey); + + // regular expression for highlighting the variable assignment + RegExpRule valueRegExpRule = new RegExpRule("([\\w:\\-\\.]+)" + + "\\s*=\\s*" + + "(\".*?\"|'.*?'|\\w+)", Pattern.COMMENTS, ""); + Map valueMatchesToStyleKey = new HashMap(); + // highlight the variable name, 1 means the group 1 of the matched results + valueMatchesToStyleKey.put(1, "color1"); + // highlight the value, 2 means the group 2 of the matched results + valueMatchesToStyleKey.put(2, "string"); + valueRegExpRule.setGroupOperations(valueMatchesToStyleKey); + + RegExpRule _regExpRule = new RegExpRule("((?:<|<)[\\s\\/\\?]*(?:\\w+))(.*?)[\\s\\/\\?]*(?:>|>)", Pattern.DOTALL, ""); + Map matchesToRegExp = new HashMap(); + // perform futher operation on the group 1 of the matched results + matchesToRegExp.put(1, tagRegExpRule); + // perform futher operation on the group 2 of the matched results + matchesToRegExp.put(2, valueRegExpRule); + _regExpRule.setGroupOperations(matchesToRegExp); + _regExpRuleList.add(_regExpRule); + + setRegExpRuleList(_regExpRuleList); + + setCommonFileExtensionList(Arrays.asList("xml", "html", "xhtml", "xslt")); + } +} \ No newline at end of file diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/HTMLScriptRegExp.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/HTMLScriptRegExp.java new file mode 100755 index 0000000..e813b01 --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/HTMLScriptRegExp.java @@ -0,0 +1,134 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.brush; + +import java.util.regex.Pattern; + +/** + * Regular expression for HTML script. This will be used to determine if the + * language was implanted into the HTML using {@code left} and {@code right}. + * e.g. left is "<script>" and right is "</script>", if there is any + * content start with "<script>" and "</script>", the content in between + * these two will be parsed by using this brush. + * + * @author Chan Wai Shing + */ +public class HTMLScriptRegExp { + + /** + * Common HTML script RegExp. + */ + public static final HTMLScriptRegExp phpScriptTags = new HTMLScriptRegExp("(?:<|<)\\?=?", "\\?(?:>|>)"); + /** + * Common HTML script RegExp. + */ + public static final HTMLScriptRegExp aspScriptTags = new HTMLScriptRegExp("(?:<|<)%=?", "%(?:>|>)"); + /** + * Common HTML script RegExp. + */ + public static final HTMLScriptRegExp scriptScriptTags = new HTMLScriptRegExp("(?:<|<)\\s*script.*?(?:>|>)", "(?:<|<)\\/\\s*script\\s*(?:>|>)"); + /** + * The regular expression of the left tag. + */ + protected String left; + /** + * The regular expression of the right tag. + */ + protected String right; + + /** + * Constructor. + * @param left the regular expression of the left tag, cannot be null + * @param right the regular expression of the right tag, cannot be null + */ + public HTMLScriptRegExp(String left, String right) { + setLeft(left); + setRight(right); + } + + /** + * Get the regular expression of the left tag. + * @return the RegExp + */ + public String getLeft() { + return left; + } + + /** + * Set the regular expression of the left tag. + * @param left the RegExp + */ + public void setLeft(String left) { + if (left == null) { + throw new NullPointerException("argument 'left' cannot be null"); + } + this.left = left; + } + + /** + * Get the regular expression of the right tag. + * @return the RegExp + */ + public String getRight() { + return right; + } + + /** + * Set the regular expression of the right tag. + * @param right the RegExp + */ + public void setRight(String right) { + if (right == null) { + throw new NullPointerException("argument 'right' cannot be null"); + } + this.right = right; + } + + /** + * Get the pattern of this HTML script RegExp. + * It is a combination of left and right tag and some pattern to match the + * in-between content. Group 1 is the left tag, group 2 is the inner content, + * group 3 is the right tag. + * + * @return the pattern with flags: CASE_INSENSITIVE and DOTALL + */ + public Pattern getpattern() { + return Pattern.compile("(" + left + ")(.*?)(" + right + ")", Pattern.CASE_INSENSITIVE | Pattern.DOTALL); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + sb.append(getClass().getName()); + sb.append(":["); + sb.append("left: "); + sb.append(left); + sb.append("right: "); + sb.append(right); + sb.append("]"); + + return sb.toString(); + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/RegExpRule.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/RegExpRule.java new file mode 100755 index 0000000..bb27557 --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/RegExpRule.java @@ -0,0 +1,246 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.brush; + +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Pattern; + +/** + * The regular expression rule. + * + * @author Chan Wai Shing + */ +public class RegExpRule { + + /** + * Common regular expression rule. + */ + public static final Pattern multiLineCComments = Pattern.compile("\\/\\*[\\s\\S]*?\\*\\/", Pattern.MULTILINE); + /** + * Common regular expression rule. + */ + public static final Pattern singleLineCComments = Pattern.compile("\\/\\/.*$", Pattern.MULTILINE); + /** + * Common regular expression rule. + */ + public static final Pattern singleLinePerlComments = Pattern.compile("#.*$", Pattern.MULTILINE); + /** + * Common regular expression rule. + */ + public static final Pattern doubleQuotedString = Pattern.compile("\"([^\\\\\"\\n]|\\\\.)*\""); + /** + * Common regular expression rule. + */ + public static final Pattern singleQuotedString = Pattern.compile("'([^\\\\'\\n]|\\\\.)*'"); + /** + * Common regular expression rule. + */ + public static final Pattern multiLineDoubleQuotedString = Pattern.compile("\"([^\\\\\"]|\\\\.)*\"", Pattern.DOTALL); + /** + * Common regular expression rule. + */ + public static final Pattern multiLineSingleQuotedString = Pattern.compile("'([^\\\\']|\\\\.)*'", Pattern.DOTALL); + /** + * Common regular expression rule. + */ + public static final Pattern xmlComments = Pattern.compile("\\w+:\\/\\/[\\w-.\\/?%&=:@;]*"); + /** + * The compiled pattern. + */ + protected Pattern pattern; + /** + * The key is the group number (see {@link java.util.regex.Matcher}) of the + * matched result. + *

+ * The value can either be a string or a RegExpRule: + *

    + *
  • If it is a string, it should be one of the style key from + * {@link syntaxhighlighter.theme}.
    + * The style will be applied to the 'strip of string related to the group + * number'.
  • + *
  • If it is a RegExpRule, the RegExpRule will be applied on the 'strip + * of string related to the group number' for further operations/matching.
  • + *
+ *

+ */ + protected Map groupOperations; + /** + * Set 'bold the matched results' or not. Null means don't set this, remain + * default. + */ + protected Boolean bold; + + /** + * Constructor. + * @param regExp the regular expression for this rule + * @param styleKey the style key, the style to apply to the matched result + */ + public RegExpRule(String regExp, String styleKey) { + this(regExp, 0, styleKey); + } + + /** + * Constructor. + * @param regExp the regular expression for this rule + * @param regFlags the flags for the regular expression, see the flags in + * {@link Pattern} + * @param styleKey the style key, the style to apply to the matched result + */ + public RegExpRule(String regExp, int regFlags, String styleKey) { + this(Pattern.compile(regExp, regFlags), styleKey); + } + + /** + * Constructor. + * @param pattern the compiled regular expression + * @param styleKey the style key, the style to apply to the matched result + */ + public RegExpRule(Pattern pattern, String styleKey) { + if (pattern == null) { + throw new NullPointerException("argument 'pattern' cannot be null"); + } + if (styleKey == null) { + throw new NullPointerException("argument 'styleKey' cannot be null"); + } + setPattern(pattern); + this.groupOperations = new HashMap(); + groupOperations.put(0, styleKey); + } + + /** + * Get the compiled pattern + * @return the pattern + */ + public Pattern getPattern() { + return pattern; + } + + /** + * Set the compiled pattern. + * @param pattern the pattern + */ + public void setPattern(Pattern pattern) { + if (pattern == null) { + throw new NullPointerException("argument 'pattern' cannot be null"); + } + this.pattern = pattern; + } + + /** + * Get the string of the regular expression. + * @return the string of the regular expression + */ + public String getRegExp() { + return pattern.pattern(); + } + + /** + * Set the string of the regular expression. + * @param regExp the string of the regular expression + */ + public void setRegExp(String regExp) { + if (regExp == null) { + throw new NullPointerException("argument 'regExp' cannot be null"); + } + pattern = Pattern.compile(regExp, pattern.flags()); + } + + /** + * Get the flags of the regular expression. + * @return the flags of the regular expression + */ + public int getRegExpFlags() { + return pattern.flags(); + } + + /** + * Set the flags of the regular expression. + * @param flags the flags, see the flags in {@link Pattern} + */ + public void setRegExpFlags(int flags) { + pattern = Pattern.compile(pattern.pattern(), flags); + } + + /** + * Get the map of group operations. For more details, see + * {@link #groupOperations}. + * @return a copy of the group operations map + */ + public Map getGroupOperations() { + return new HashMap(groupOperations); + } + + /** + * Set the map of group operations. For more details, see + * {@link #groupOperations}. + * @param GroupOperations the group operations map + */ + public void setGroupOperations(Map GroupOperations) { + if (GroupOperations == null) { + this.groupOperations = new HashMap(); + return; + } + this.groupOperations = new HashMap(GroupOperations); + } + + /** + * Get whether bold the matched result or not. + * @return true means bold it, false means dun bold, null mean neither bold + * nor not bold (remain default) + */ + public Boolean getBold() { + return bold; + } + + /** + * Set bold the matched results or not. Null means remain default. + * @param bold true means bold it, false means dun bold, null mean neither + * bold nor not bold (remain default) + */ + public void setBold(Boolean bold) { + this.bold = bold; + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + sb.append(getClass().getName()); + sb.append(": "); + sb.append("regExp: "); + sb.append(getRegExp()); + sb.append(", "); + sb.append("regFlags: "); + sb.append(getRegExpFlags()); + sb.append(", "); + sb.append("getGroupOperations: "); + sb.append(getGroupOperations()); + sb.append(", "); + sb.append("bold: "); + sb.append(getBold()); + + return sb.toString(); + } +} \ No newline at end of file diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/package-info.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/package-info.java new file mode 100755 index 0000000..66f0ab0 --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/brush/package-info.java @@ -0,0 +1,4 @@ +/** + * All brushes that comes with release. + */ +package syntaxhighlighter.brush; \ No newline at end of file diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/parser/MatchResult.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/parser/MatchResult.java new file mode 100755 index 0000000..e31728e --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/parser/MatchResult.java @@ -0,0 +1,136 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.parser; + +/** + * Matched result, it will be generated when parsing the content. + * + * @author Chan Wai Shing + */ +public class MatchResult { + + /** + * The position in the document for this matched result. + */ + private int offset; + /** + * The length of the matched result. + */ + private int length; + /** + * The style key for this matched result, see {@link syntaxhighlighter.theme}. + */ + private String styleKey; + /** + * Indicate whether this match should be bolded or not. + * This will override the 'bold' setting of the style (by styleKey). + * If it is null, there will be nothing done on the 'bold' of the style. + */ + private Boolean bold; + + /** + * Constructor. + * + * @param offset the position in the document for this matched result + * @param length the length of the matched result. + * @param styleKey the style key for this matched result, cannot be null, see + * {@link syntaxhighlighter.theme} + * @param bold indicate whether this match should be bolded or not, for + * details see {@link #bold} + */ + protected MatchResult(int offset, int length, String styleKey, Boolean bold) { + if (styleKey == null) { + throw new NullPointerException("argument 'styleKey' cannot be null"); + } + this.offset = offset; + this.length = length; + this.styleKey = styleKey; + this.bold = bold; + } + + /** + * The position in the document for this matched result. + * @return the offset in the document + */ + public int getOffset() { + return offset; + } + + /** + * The position in the document for this matched result. + * @param offset the offset in the document + */ + public void setOffset(int offset) { + this.offset = offset; + } + + /** + * The length of the matched result. + * @return the length + */ + public int getLength() { + return length; + } + + /** + * The length of the matched result. + * @param length the length + */ + public void setLength(int length) { + this.length = length; + } + + /** + * The style key for this matched result, see {@link syntaxhighlighter.theme}. + * @return the style key + */ + public String getStyleKey() { + return styleKey; + } + + /** + * Indicate whether this match should be bolded or not. + * This will override the 'bold' setting of the style (by styleKey). + * If it is null, there will be nothing done on the 'bold' of the style. + * @return true to bold, false not bold, null means not set (no action to + * take) + */ + public Boolean isBold() { + return bold; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + sb.append("["); + sb.append(offset); + sb.append(", "); + sb.append(length); + sb.append(", "); + sb.append(styleKey); + sb.append(", "); + sb.append(bold); + sb.append("]"); + + return sb.toString(); + } +} \ No newline at end of file diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/parser/SyntaxHighlighter.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/parser/SyntaxHighlighter.java new file mode 100755 index 0000000..45f4a9a --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/parser/SyntaxHighlighter.java @@ -0,0 +1,255 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.parser; + +import syntaxhighlighter.brush.Brush; +import syntaxhighlighter.brush.RegExpRule; + +import javax.swing.text.Segment; +import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * The parser of the syntax highlighter. + * + * @author Chan Wai Shing + */ +public class SyntaxHighlighter { + + protected final List htmlScriptBrushList; + + /** + * Constructor. + */ + public SyntaxHighlighter() { + htmlScriptBrushList = new ArrayList(); + } + + /** + * Add matched result to {@code matches}. + * @param matches the list of matches + * @param match the matched result + */ + protected void addMatch(Map> matches, MatchResult match) { + if (matches == null || match == null) { + return; + } + List matchList = matches.get(match.getOffset()); + if (matchList == null) { + matchList = new ArrayList(); + matches.put(match.getOffset(), matchList); + } + matchList.add(match); + } + + /** + * Remove those matches that fufil the condition from {@code matches}. + * @param matches the list of matches + * @param start the start position in the document + * @param end the end position in the document + */ + protected void removeMatches(Map> matches, int start, int end) { + if (matches == null) { + return; + } + for (int offset : matches.keySet()) { + List offsetMatches = matches.get(offset); + + ListIterator iterator = offsetMatches.listIterator(); + while (iterator.hasNext()) { + MatchResult match = iterator.next(); + + // the start and end position in the document for this matched result + int _start = match.getOffset(), _end = _start + match.getLength(); + + if (_start >= end || _end <= start) { + // out of the range + continue; + } + if (_start >= start && _end <= end) { + // fit or within range + iterator.remove(); + } else if (_end <= end) { + // overlap with the start + // remove the style within the range and remain those without the range + iterator.set(new MatchResult(_start, start - _start, match.getStyleKey(), match.isBold())); + } else if (_start >= start) { + // overlap with the end + // remove the style within the range and remain those without the range + iterator.set(new MatchResult(end, _end - end, match.getStyleKey(), match.isBold())); + } + } + } + } + + /** + * Parse the content start from {@code offset} with {@code length} and + * return the result. + * + * @param brush the brush to use + * @param htmlScript turn HTML-Script on or not + * @param content the content to parse in char array + * @param offset the offset + * @param length the length + * + * @return the parsed result, the key of the map is style key + */ + public Map> parse(Brush brush, boolean htmlScript, char[] content, int offset, int length) { + if (brush == null || content == null) { + return null; + } + Map> matches = new TreeMap>(); + return parse(matches, brush, htmlScript, content, offset, length); + } + + /** + * Parse the content start from {@code offset} with {@code length} with the + * brush and return the result. All new matches will be added to + * {@code matches}. + * + * @param matches the list of matches + * @param brush the brush to use + * @param htmlScript turn HTML-Script on or not + * @param content the content to parse in char array + * @param offset the offset + * @param length the length + * + * @return the parsed result, the key of the map is style key + */ + protected Map> parse(Map> matches, Brush brush, boolean htmlScript, char[] content, int offset, int length) { + if (matches == null || brush == null || content == null) { + return null; + } + // parse the RegExpRule in the brush first + List regExpRuleList = brush.getRegExpRuleList(); + for (RegExpRule regExpRule : regExpRuleList) { + parse(matches, regExpRule, content, offset, length); + } + + // parse the HTML-Script brushes later + if (htmlScript) { + synchronized (htmlScriptBrushList) { + for (Brush htmlScriptBrush : htmlScriptBrushList) { + Pattern _pattern = htmlScriptBrush.getHTMLScriptRegExp().getpattern(); + + Matcher matcher = _pattern.matcher(new Segment(content, offset, length)); + while (matcher.find()) { + // HTML-Script brush has superior priority, so remove all previous matches within the matched range + removeMatches(matches, matcher.start() + offset, matcher.end() + offset); + + // the left tag of HTML-Script + int start = matcher.start(1) + offset, end = matcher.end(1) + offset; + addMatch(matches, new MatchResult(start, end - start, "script", false)); + + // the content of HTML-Script, parse it using the HTML-Script brush + start = matcher.start(2) + offset; + end = matcher.end(2) + offset; + parse(matches, htmlScriptBrush, false, content, start, end - start); + + // the right tag of HTML-Script + start = matcher.start(3) + offset; + end = matcher.end(3) + offset; + addMatch(matches, new MatchResult(start, end - start, "script", false)); + } + } + } + } + + return matches; + } + + /** + * Parse the content start from {@code offset} with {@code length} using the + * {@code regExpRule}. All new matches will be added to {@code matches}. + * + * @param matches the list of matches + * @param regExpRule the RegExp rule to use + * @param content the content to parse in char array + * @param offset the offset + * @param length the length + */ + protected void parse(Map> matches, RegExpRule regExpRule, char[] content, int offset, int length) { + if (matches == null || regExpRule == null || content == null) { + return; + } + Map groupOperations = regExpRule.getGroupOperations(); + + Pattern regExpPattern = regExpRule.getPattern(); + Matcher matcher = regExpPattern.matcher(new Segment(content, offset, length)); + while (matcher.find()) { + // deal with the matched result + for (int groupId : groupOperations.keySet()) { + Object operation = groupOperations.get(groupId); + + // the start and end position of the match + int start = matcher.start(groupId), end = matcher.end(groupId); + if (start == -1 || end == -1) { + continue; + } + start += offset; + end += offset; + + if (operation instanceof String) { + // add the style to the match + addMatch(matches, new MatchResult(start, end - start, (String) operation, regExpRule.getBold())); + } else { + // parse the result using the operation RegExpRule + parse(matches, (RegExpRule) operation, content, start, end - start); + } + } + } + } + + /** + * Get the list of HTML Script brushes. + * @return a copy of the list + */ + public List getHTMLScriptBrushList() { + return new ArrayList(htmlScriptBrushList); + } + + /** + * Set HTML Script brushes. Note that this will clear all previous recorded + * HTML Script brushes. + * + * @param htmlScriptBrushList the list that contain the brushes + */ + public void setHTMLScriptBrushList(List htmlScriptBrushList) { + synchronized (this.htmlScriptBrushList) { + this.htmlScriptBrushList.clear(); + if (htmlScriptBrushList != null) { + this.htmlScriptBrushList.addAll(htmlScriptBrushList); + } + } + } + + /** + * Add HTML Script brushes. + * @param brush the brush to add + */ + public void addHTMLScriptBrush(Brush brush) { + if (brush == null) { + return; + } + htmlScriptBrushList.add(brush); + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/parser/package-info.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/parser/package-info.java new file mode 100755 index 0000000..2017d6a --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/parser/package-info.java @@ -0,0 +1,4 @@ +/** + * The parser. + */ +package syntaxhighlighter.parser; \ No newline at end of file diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/theme/ThemeDefault.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/theme/ThemeDefault.java new file mode 100755 index 0000000..989685b --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/theme/ThemeDefault.java @@ -0,0 +1,111 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.theme; + +import syntaxhighlight.Style; +import syntaxhighlight.Theme; + +import java.awt.*; + +/** + * Default theme. + * @author Chan Wai Shing + */ +public class ThemeDefault extends Theme { + + public ThemeDefault() { + super(); + + setFont(new Font("Consolas", Font.PLAIN, 12)); + setBackground(Color.white); + + setHighlightedBackground(Color.decode("0xe0e0e0")); + + setGutterText(Color.decode("0xafafaf")); + setGutterBorderColor(Color.decode("0x6ce26c")); + setGutterBorderWidth(3); + setGutterTextFont(new Font("Verdana", Font.PLAIN, 11)); + setGutterTextPaddingLeft(7); + setGutterTextPaddingRight(7); + + Style style = new Style(); + style.setBold(true); + addStyle("bold", style); + + style = new Style(); + style.setColor(Color.black); + addStyle("plain", style); + setPlain(style); + + style = new Style(); + style.setColor(Color.decode("0x008200")); + addStyle("comments", style); + + style = new Style(); + style.setColor(Color.blue); + addStyle("string", style); + + style = new Style(); + style.setBold(true); + style.setColor(Color.decode("0x006699")); + addStyle("keyword", style); + + style = new Style(); + style.setColor(Color.gray); + addStyle("preprocessor", style); + + style = new Style(); + style.setColor(Color.decode("0xaa7700")); + addStyle("variable", style); + + style = new Style(); + style.setColor(Color.decode("0x009900")); + addStyle("value", style); + + style = new Style(); + style.setColor(Color.decode("0xff1493")); + addStyle("functions", style); + + style = new Style(); + style.setColor(Color.decode("0x0066cc")); + addStyle("constants", style); + + style = new Style(); + style.setBold(true); + style.setColor(Color.decode("0x006699")); + addStyle("script", style); + + style = new Style(); + addStyle("scriptBackground", style); + + style = new Style(); + style.setColor(Color.gray); + addStyle("color3", style); + + style = new Style(); + style.setColor(Color.decode("0xff1493")); + addStyle("color2", style); + + style = new Style(); + style.setColor(Color.red); + addStyle("color3", style); + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/theme/ThemeDjango.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/theme/ThemeDjango.java new file mode 100755 index 0000000..3847539 --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/theme/ThemeDjango.java @@ -0,0 +1,112 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.theme; + +import syntaxhighlight.Style; +import syntaxhighlight.Theme; + +import java.awt.*; + +/** + * Django theme. + * @author Chan Wai Shing + */ +public class ThemeDjango extends Theme { + + public ThemeDjango() { + super(); + + setFont(new Font("Consolas", Font.PLAIN, 12)); + setBackground(Color.decode("0x0a2b1d")); + + setHighlightedBackground(Color.decode("0x233729")); + + setGutterText(Color.decode("0x497958")); + setGutterBorderColor(Color.decode("0x41a83e")); + setGutterBorderWidth(3); + setGutterTextFont(new Font("Verdana", Font.PLAIN, 11)); + setGutterTextPaddingLeft(7); + setGutterTextPaddingRight(7); + + Style style = new Style(); + style.setBold(true); + addStyle("bold", style); + + style = new Style(); + style.setColor(Color.decode("0xf8f8f8")); + addStyle("plain", style); + setPlain(style); + + style = new Style(); + style.setItalic(true); + style.setColor(Color.decode("0x336442")); + addStyle("comments", style); + + style = new Style(); + style.setColor(Color.decode("0x9df39f")); + addStyle("string", style); + + style = new Style(); + style.setBold(true); + style.setColor(Color.decode("0x96dd3b")); + addStyle("keyword", style); + + style = new Style(); + style.setColor(Color.decode("0x91bb9e")); + addStyle("preprocessor", style); + + style = new Style(); + style.setColor(Color.decode("0xffaa3e")); + addStyle("variable", style); + + style = new Style(); + style.setColor(Color.decode("0xf7e741")); + addStyle("value", style); + + style = new Style(); + style.setColor(Color.decode("0xffaa3e")); + addStyle("functions", style); + + style = new Style(); + style.setColor(Color.decode("0xe0e8ff")); + addStyle("constants", style); + + style = new Style(); + style.setBold(true); + style.setColor(Color.decode("0x96dd3b")); + addStyle("script", style); + + style = new Style(); + addStyle("scriptBackground", style); + + style = new Style(); + style.setColor(Color.decode("0xeb939a")); + addStyle("color3", style); + + style = new Style(); + style.setColor(Color.decode("0x91bb9e")); + addStyle("color2", style); + + style = new Style(); + style.setColor(Color.decode("0xedef7d")); + addStyle("color3", style); + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/theme/ThemeEclipse.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/theme/ThemeEclipse.java new file mode 100755 index 0000000..ff92d43 --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/theme/ThemeEclipse.java @@ -0,0 +1,114 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.theme; + +import syntaxhighlight.Style; +import syntaxhighlight.Theme; + +import java.awt.*; + +/** + * Eclipse theme. + * @author Chan Wai Shing + */ +public class ThemeEclipse extends Theme { + + public ThemeEclipse() { + super(); + + // (C) Code-House + // :http//blog.code-house.org/2009/10/xml-i-adnotacje-kod-ogolnego-przeznaczenia-i-jpa/ + + setFont(new Font("Consolas", Font.PLAIN, 12)); + setBackground(Color.decode("0xffffff")); + + setHighlightedBackground(Color.decode("0xc3defe")); + + setGutterText(Color.decode("0x787878")); + setGutterBorderColor(Color.decode("0xd4d0c8")); + setGutterBorderWidth(3); + setGutterTextFont(new Font("Verdana", Font.PLAIN, 11)); + setGutterTextPaddingLeft(7); + setGutterTextPaddingRight(7); + + Style style = new Style(); + style.setBold(true); + addStyle("bold", style); + + style = new Style(); + style.setColor(Color.decode("0x000000")); + addStyle("plain", style); + setPlain(style); + + style = new Style(); + style.setColor(Color.decode("0x3f5fbf")); + addStyle("comments", style); + + style = new Style(); + style.setColor(Color.decode("0x2a00ff")); + addStyle("string", style); + + style = new Style(); + style.setBold(true); + style.setColor(Color.decode("0x7f0055")); + addStyle("keyword", style); + + style = new Style(); + style.setColor(Color.decode("0x646464")); + addStyle("preprocessor", style); + + style = new Style(); + style.setColor(Color.decode("0xaa7700")); + addStyle("variable", style); + + style = new Style(); + style.setColor(Color.decode("0x009900")); + addStyle("value", style); + + style = new Style(); + style.setColor(Color.decode("0xff1493")); + addStyle("functions", style); + + style = new Style(); + style.setColor(Color.decode("0x0066cc")); + addStyle("constants", style); + + style = new Style(); + style.setBold(true); + style.setColor(Color.decode("0x7f0055")); + addStyle("script", style); + + style = new Style(); + addStyle("scriptBackground", style); + + style = new Style(); + style.setColor(Color.gray); + addStyle("color3", style); + + style = new Style(); + style.setColor(Color.decode("0xff1493")); + addStyle("color2", style); + + style = new Style(); + style.setColor(Color.red); + addStyle("color3", style); + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/theme/ThemeEmacs.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/theme/ThemeEmacs.java new file mode 100755 index 0000000..9dab4f0 --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/theme/ThemeEmacs.java @@ -0,0 +1,113 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.theme; + +import syntaxhighlight.Style; +import syntaxhighlight.Theme; + +import java.awt.*; + +/** + * Emacs theme. + * @author Chan Wai Shing + */ +public class ThemeEmacs extends Theme { + + public ThemeEmacs() { + super(); + + // Emacs SyntaxHighlighter theme based on theme by Joshua Emmons + // http://www.skia.net/ + + setFont(new Font("Consolas", Font.PLAIN, 12)); + setBackground(Color.black); + + setHighlightedBackground(Color.decode("0x2A3133")); + + setGutterText(Color.decode("0xd3d3d3")); + setGutterBorderColor(Color.decode("0x990000")); + setGutterBorderWidth(3); + setGutterTextFont(new Font("Verdana", Font.PLAIN, 11)); + setGutterTextPaddingLeft(7); + setGutterTextPaddingRight(7); + + Style style = new Style(); + style.setBold(true); + addStyle("bold", style); + + style = new Style(); + style.setColor(Color.decode("0xd3d3d3")); + addStyle("plain", style); + setPlain(style); + + style = new Style(); + style.setColor(Color.decode("0xff7d27")); + addStyle("comments", style); + + style = new Style(); + style.setColor(Color.decode("0xff9e7b")); + addStyle("string", style); + + style = new Style(); + style.setColor(Color.decode("0x00ffff")); + addStyle("keyword", style); + + style = new Style(); + style.setColor(Color.decode("0xaec4de")); + addStyle("preprocessor", style); + + style = new Style(); + style.setColor(Color.decode("0xffaa3e")); + addStyle("variable", style); + + style = new Style(); + style.setColor(Color.decode("0x009900")); + addStyle("value", style); + + style = new Style(); + style.setColor(Color.decode("0x81cef9")); + addStyle("functions", style); + + style = new Style(); + style.setColor(Color.decode("0xff9e7b")); + addStyle("constants", style); + + style = new Style(); + style.setBold(true); + style.setColor(Color.decode("0x00ffff")); + addStyle("script", style); + + style = new Style(); + addStyle("scriptBackground", style); + + style = new Style(); + style.setColor(Color.decode("0xebdb8d")); + addStyle("color3", style); + + style = new Style(); + style.setColor(Color.decode("0xff7d27")); + addStyle("color2", style); + + style = new Style(); + style.setColor(Color.decode("0xaec4de")); + addStyle("color3", style); + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/theme/ThemeFadeToGrey.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/theme/ThemeFadeToGrey.java new file mode 100755 index 0000000..25bb1ee --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/theme/ThemeFadeToGrey.java @@ -0,0 +1,114 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.theme; + +import syntaxhighlight.Style; +import syntaxhighlight.Theme; + +import java.awt.*; + +/** + * Fade to Grey theme. + * @author Chan Wai Shing + */ +public class ThemeFadeToGrey extends Theme { + + public ThemeFadeToGrey() { + super(); + + // Fade to Grey SyntaxHighlighter theme based on theme by Brasten Sager + // :http//www.ibrasten.com/ + + setFont(new Font("Consolas", Font.PLAIN, 12)); + setBackground(Color.decode("0x121212")); + + setHighlightedBackground(Color.decode("0x2C2C29")); + + setGutterText(Color.decode("0xafafaf")); + setGutterBorderColor(Color.decode("0x3185b9")); + setGutterBorderWidth(3); + setGutterTextFont(new Font("Verdana", Font.PLAIN, 11)); + setGutterTextPaddingLeft(7); + setGutterTextPaddingRight(7); + + Style style = new Style(); + style.setBold(true); + addStyle("bold", style); + + style = new Style(); + style.setColor(Color.white); + addStyle("plain", style); + setPlain(style); + + style = new Style(); + style.setColor(Color.decode("0x696854")); + addStyle("comments", style); + + style = new Style(); + style.setColor(Color.decode("0xe3e658")); + addStyle("string", style); + + style = new Style(); + style.setColor(Color.decode("0xd01d33")); + addStyle("keyword", style); + + style = new Style(); + style.setColor(Color.decode("0x435a5f")); + addStyle("preprocessor", style); + + style = new Style(); + style.setColor(Color.decode("0x898989")); + addStyle("variable", style); + + style = new Style(); + style.setColor(Color.decode("0x009900")); + addStyle("value", style); + + style = new Style(); + style.setBold(true); + style.setColor(Color.decode("0xaaaaaa")); + addStyle("functions", style); + + style = new Style(); + style.setColor(Color.decode("0x96daff")); + addStyle("constants", style); + + style = new Style(); + style.setBold(true); + style.setColor(Color.decode("0xd01d33")); + addStyle("script", style); + + style = new Style(); + addStyle("scriptBackground", style); + + style = new Style(); + style.setColor(Color.decode("0xffc074")); + addStyle("color3", style); + + style = new Style(); + style.setColor(Color.decode("0x4a8cdb")); + addStyle("color2", style); + + style = new Style(); + style.setColor(Color.decode("0x96daff")); + addStyle("color3", style); + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/theme/ThemeMDUltra.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/theme/ThemeMDUltra.java new file mode 100755 index 0000000..498c010 --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/theme/ThemeMDUltra.java @@ -0,0 +1,113 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.theme; + +import syntaxhighlight.Style; +import syntaxhighlight.Theme; + +import java.awt.*; + +/** + * MD Ultra theme. + * @author Chan Wai Shing + */ +public class ThemeMDUltra extends Theme { + + public ThemeMDUltra() { + super(); + + // MDUltra SyntaxHighlighter theme based on Midnight Theme + // http://www.mddev.co.uk/ + + setFont(new Font("Consolas", Font.PLAIN, 12)); + setBackground(Color.decode("0x222222")); + + setHighlightedBackground(Color.decode("0x253e5a")); + + setGutterText(Color.decode("0x38566f")); + setGutterBorderColor(Color.decode("0x435a5f")); + setGutterBorderWidth(3); + setGutterTextFont(new Font("Verdana", Font.PLAIN, 11)); + setGutterTextPaddingLeft(7); + setGutterTextPaddingRight(7); + + Style style = new Style(); + style.setBold(true); + addStyle("bold", style); + + style = new Style(); + style.setColor(Color.decode("0x00ff00")); + addStyle("plain", style); + setPlain(style); + + style = new Style(); + style.setColor(Color.decode("0x428bdd")); + addStyle("comments", style); + + style = new Style(); + style.setColor(Color.decode("0x00ff00")); + addStyle("string", style); + + style = new Style(); + style.setColor(Color.decode("0xaaaaff")); + addStyle("keyword", style); + + style = new Style(); + style.setColor(Color.decode("0x8aa6c1")); + addStyle("preprocessor", style); + + style = new Style(); + style.setColor(Color.decode("0x00ffff")); + addStyle("variable", style); + + style = new Style(); + style.setColor(Color.decode("0xf7e741")); + addStyle("value", style); + + style = new Style(); + style.setColor(Color.decode("0xff8000")); + addStyle("functions", style); + + style = new Style(); + style.setColor(Color.yellow); + addStyle("constants", style); + + style = new Style(); + style.setBold(true); + style.setColor(Color.decode("0xaaaaff")); + addStyle("script", style); + + style = new Style(); + addStyle("scriptBackground", style); + + style = new Style(); + style.setColor(Color.red); + addStyle("color3", style); + + style = new Style(); + style.setColor(Color.yellow); + addStyle("color2", style); + + style = new Style(); + style.setColor(Color.decode("0xffaa3e")); + addStyle("color3", style); + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/theme/ThemeMidnight.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/theme/ThemeMidnight.java new file mode 100755 index 0000000..fbd31fc --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/theme/ThemeMidnight.java @@ -0,0 +1,113 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.theme; + +import syntaxhighlight.Style; +import syntaxhighlight.Theme; + +import java.awt.*; + +/** + * Midnight theme. + * @author Chan Wai Shing + */ +public class ThemeMidnight extends Theme { + + public ThemeMidnight() { + super(); + + // Midnight SyntaxHighlighter theme based on theme by J.D. Myers + // http://webdesign.lsnjd.com/ + + setFont(new Font("Consolas", Font.PLAIN, 12)); + setBackground(Color.decode("0x0f192a")); + + setHighlightedBackground(Color.decode("0x253e5a")); + + setGutterText(Color.decode("0xafafaf")); + setGutterBorderColor(Color.decode("0x435a5f")); + setGutterBorderWidth(3); + setGutterTextFont(new Font("Verdana", Font.PLAIN, 11)); + setGutterTextPaddingLeft(7); + setGutterTextPaddingRight(7); + + Style style = new Style(); + style.setBold(true); + addStyle("bold", style); + + style = new Style(); + style.setColor(Color.decode("0xd1edff")); + addStyle("plain", style); + setPlain(style); + + style = new Style(); + style.setColor(Color.decode("0x428bdd")); + addStyle("comments", style); + + style = new Style(); + style.setColor(Color.decode("0x1dc116")); + addStyle("string", style); + + style = new Style(); + style.setColor(Color.decode("0xb43d3d")); + addStyle("keyword", style); + + style = new Style(); + style.setColor(Color.decode("0x8aa6c1")); + addStyle("preprocessor", style); + + style = new Style(); + style.setColor(Color.decode("0xffaa3e")); + addStyle("variable", style); + + style = new Style(); + style.setColor(Color.decode("0xf7e741")); + addStyle("value", style); + + style = new Style(); + style.setColor(Color.decode("0xffaa3e")); + addStyle("functions", style); + + style = new Style(); + style.setColor(Color.decode("0xe0e8ff")); + addStyle("constants", style); + + style = new Style(); + style.setBold(true); + style.setColor(Color.decode("0xb43d3d")); + addStyle("script", style); + + style = new Style(); + addStyle("scriptBackground", style); + + style = new Style(); + style.setColor(Color.decode("0xf8bb00")); + addStyle("color3", style); + + style = new Style(); + style.setColor(Color.white); + addStyle("color2", style); + + style = new Style(); + style.setColor(Color.decode("0x0ffaa3e")); + addStyle("color3", style); + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/theme/ThemeRDark.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/theme/ThemeRDark.java new file mode 100755 index 0000000..21d4171 --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/theme/ThemeRDark.java @@ -0,0 +1,113 @@ +// Copyright (c) 2011 Chan Wai Shing +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +package syntaxhighlighter.theme; + +import syntaxhighlight.Style; +import syntaxhighlight.Theme; + +import java.awt.*; + +/** + * RDark theme. + * @author Chan Wai Shing + */ +public class ThemeRDark extends Theme { + + public ThemeRDark() { + super(); + + // RDark SyntaxHighlighter theme based on theme by Radu Dineiu + // http://www.vim.org/scripts/script.php?script_id=1732 + + setFont(new Font("Consolas", Font.PLAIN, 12)); + setBackground(Color.decode("0x1b2426")); + + setHighlightedBackground(Color.decode("0x323E41")); + + setGutterText(Color.decode("0xafafaf")); + setGutterBorderColor(Color.decode("0x435a5f")); + setGutterBorderWidth(3); + setGutterTextFont(new Font("Verdana", Font.PLAIN, 11)); + setGutterTextPaddingLeft(7); + setGutterTextPaddingRight(7); + + Style style = new Style(); + style.setBold(true); + addStyle("bold", style); + + style = new Style(); + style.setColor(Color.decode("0xb9bdb6")); + addStyle("plain", style); + setPlain(style); + + style = new Style(); + style.setColor(Color.decode("0x878a85")); + addStyle("comments", style); + + style = new Style(); + style.setColor(Color.decode("0x5ce638")); + addStyle("string", style); + + style = new Style(); + style.setColor(Color.decode("0x5ba1cf")); + addStyle("keyword", style); + + style = new Style(); + style.setColor(Color.decode("0x435a5f")); + addStyle("preprocessor", style); + + style = new Style(); + style.setColor(Color.decode("0xffaa3e")); + addStyle("variable", style); + + style = new Style(); + style.setColor(Color.decode("0x009900")); + addStyle("value", style); + + style = new Style(); + style.setColor(Color.decode("0xffaa3e")); + addStyle("functions", style); + + style = new Style(); + style.setColor(Color.decode("0xe0e8ff")); + addStyle("constants", style); + + style = new Style(); + style.setBold(true); + style.setColor(Color.decode("0x5ba1cf")); + addStyle("script", style); + + style = new Style(); + addStyle("scriptBackground", style); + + style = new Style(); + style.setColor(Color.decode("0xe0e8ff")); + addStyle("color3", style); + + style = new Style(); + style.setColor(Color.white); + addStyle("color2", style); + + style = new Style(); + style.setColor(Color.decode("0xffaa3e")); + addStyle("color3", style); + } +} diff --git a/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/theme/package-info.java b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/theme/package-info.java new file mode 100755 index 0000000..54029a4 --- /dev/null +++ b/jspringbot-pretty-logger/src/main/java/syntaxhighlighter/theme/package-info.java @@ -0,0 +1,4 @@ +/** + * All themes that comes with release. + */ +package syntaxhighlighter.theme; \ No newline at end of file diff --git a/jspringbot-pretty-logger/src/main/resources/pygments/__init__.py b/jspringbot-pretty-logger/src/main/resources/pygments/__init__.py deleted file mode 100644 index 0ecc167..0000000 --- a/jspringbot-pretty-logger/src/main/resources/pygments/__init__.py +++ /dev/null @@ -1,91 +0,0 @@ -# -*- coding: utf-8 -*- -""" - Pygments - ~~~~~~~~ - - Pygments is a syntax highlighting package written in Python. - - It is a generic syntax highlighter for general use in all kinds of software - such as forum systems, wikis or other applications that need to prettify - source code. Highlights are: - - * a wide range of common languages and markup formats is supported - * special attention is paid to details, increasing quality by a fair amount - * support for new languages and formats are added easily - * a number of output formats, presently HTML, LaTeX, RTF, SVG, all image - formats that PIL supports, and ANSI sequences - * it is usable as a command-line tool and as a library - * ... and it highlights even Brainfuck! - - The `Pygments tip`_ is installable with ``easy_install Pygments==dev``. - - .. _Pygments tip: - http://bitbucket.org/birkenfeld/pygments-main/get/tip.zip#egg=Pygments-dev - - :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS. - :license: BSD, see LICENSE for details. -""" - -__version__ = '1.5' -__docformat__ = 'restructuredtext' - -__all__ = ['lex', 'format', 'highlight'] - - -import sys - -from pygments.util import StringIO, BytesIO - - -def lex(code, lexer): - """ - Lex ``code`` with ``lexer`` and return an iterable of tokens. - """ - try: - return lexer.get_tokens(code) - except TypeError, err: - if isinstance(err.args[0], str) and \ - 'unbound method get_tokens' in err.args[0]: - raise TypeError('lex() argument must be a lexer instance, ' - 'not a class') - raise - - -def format(tokens, formatter, outfile=None): - """ - Format a tokenlist ``tokens`` with the formatter ``formatter``. - - If ``outfile`` is given and a valid file object (an object - with a ``write`` method), the result will be written to it, otherwise - it is returned as a string. - """ - try: - if not outfile: - #print formatter, 'using', formatter.encoding - realoutfile = formatter.encoding and BytesIO() or StringIO() - formatter.format(tokens, realoutfile) - return realoutfile.getvalue() - else: - formatter.format(tokens, outfile) - except TypeError, err: - if isinstance(err.args[0], str) and \ - 'unbound method format' in err.args[0]: - raise TypeError('format() argument must be a formatter instance, ' - 'not a class') - raise - - -def highlight(code, lexer, formatter, outfile=None): - """ - Lex ``code`` with ``lexer`` and format it with the formatter ``formatter``. - - If ``outfile`` is given and a valid file object (an object - with a ``write`` method), the result will be written to it, otherwise - it is returned as a string. - """ - return format(lex(code, lexer), formatter, outfile) - - -if __name__ == '__main__': - from pygments.cmdline import main - sys.exit(main(sys.argv)) diff --git a/jspringbot-pretty-logger/src/main/resources/pygments/cmdline.py b/jspringbot-pretty-logger/src/main/resources/pygments/cmdline.py deleted file mode 100644 index 1f14cf5..0000000 --- a/jspringbot-pretty-logger/src/main/resources/pygments/cmdline.py +++ /dev/null @@ -1,433 +0,0 @@ -# -*- coding: utf-8 -*- -""" - pygments.cmdline - ~~~~~~~~~~~~~~~~ - - Command line interface. - - :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS. - :license: BSD, see LICENSE for details. -""" -import sys -import getopt -from textwrap import dedent - -from pygments import __version__, highlight -from pygments.util import ClassNotFound, OptionError, docstring_headline -from pygments.lexers import get_all_lexers, get_lexer_by_name, get_lexer_for_filename, \ - find_lexer_class, guess_lexer, TextLexer -from pygments.formatters import get_all_formatters, get_formatter_by_name, \ - get_formatter_for_filename, find_formatter_class, \ - TerminalFormatter # pylint:disable-msg=E0611 -from pygments.filters import get_all_filters, find_filter_class -from pygments.styles import get_all_styles, get_style_by_name - - -USAGE = """\ -Usage: %s [-l | -g] [-F [:]] [-f ] - [-O ] [-P ] [-o ] [] - - %s -S - - -

%(title)s

- -''' - -DOC_HEADER_EXTERNALCSS = '''\ - - - - - %(title)s - - - - -

%(title)s

- -''' - -DOC_FOOTER = '''\ - - -''' - - -class HtmlFormatter(Formatter): - r""" - Format tokens as HTML 4 ```` tags within a ``
`` tag, wrapped
-    in a ``
`` tag. The ``
``'s CSS class can be set by the `cssclass` - option. - - If the `linenos` option is set to ``"table"``, the ``
`` is
-    additionally wrapped inside a ```` which has one row and two
-    cells: one containing the line numbers and one containing the code.
-    Example:
-
-    .. sourcecode:: html
-
-        
-
- - -
-
1
-            2
-
-
def foo(bar):
-              pass
-            
-
- - (whitespace added to improve clarity). - - Wrapping can be disabled using the `nowrap` option. - - A list of lines can be specified using the `hl_lines` option to make these - lines highlighted (as of Pygments 0.11). - - With the `full` option, a complete HTML 4 document is output, including - the style definitions inside a ``