The Unified and Autonomous Development Platform
Add JavaScript and CSS tokenizer.
robin shine05b9465a29b6
diff --git a/commons.tokenizer/src/main/java/com/pmease/commons/tokenizer/AbstractTokenizer.java b/commons.tokenizer/src/main/java/com/pmease/commons/tokenizer/AbstractTokenizer.javaindex ad3eb1abcf..f5745620f8 100644--- a/commons.tokenizer/src/main/java/com/pmease/commons/tokenizer/AbstractTokenizer.java+++ b/commons.tokenizer/src/main/java/com/pmease/commons/tokenizer/AbstractTokenizer.java@@ -29,9 +29,7 @@ public abstract class AbstractTokenizer<S> implements Tokenizer {return tokenizedLines;}- protected S startState() {- return null;- }+ protected abstract S startState();protected abstract String token(StringStream stream, S state);diff --git a/commons.tokenizer/src/main/java/com/pmease/commons/tokenizer/CssTokenizer.java b/commons.tokenizer/src/main/java/com/pmease/commons/tokenizer/CssTokenizer.javanew file mode 100644index 0000000000..5c7dbcd76e--- /dev/null+++ b/commons.tokenizer/src/main/java/com/pmease/commons/tokenizer/CssTokenizer.java@@ -0,0 +1,954 @@+package com.pmease.commons.tokenizer;++import java.util.HashMap;+import java.util.Map;+import java.util.Set;+import java.util.regex.Pattern;++import com.google.common.collect.Sets;+import com.pmease.commons.util.StringUtils;++public abstract class CssTokenizer extends AbstractTokenizer<CssTokenizer.State> {++ private static Set<String> mediaTypes = Sets.newHashSet(+ "all", "aural", "braille", "handheld", "print", "projection", "screen",+ "tty", "tv", "embossed");++ private static Set<String> mediaFeatures = Sets.newHashSet(+ "width", "min-width", "max-width", "height", "min-height", "max-height",+ "device-width", "min-device-width", "max-device-width", "device-height",+ "min-device-height", "max-device-height", "aspect-ratio",+ "min-aspect-ratio", "max-aspect-ratio", "device-aspect-ratio",+ "min-device-aspect-ratio", "max-device-aspect-ratio", "color", "min-color",+ "max-color", "color-index", "min-color-index", "max-color-index",+ "monochrome", "min-monochrome", "max-monochrome", "resolution",+ "min-resolution", "max-resolution", "scan", "grid"+ );++ private static Set<String> propertyKeywords = Sets.newHashSet(+ "align-content", "align-items", "align-self", "alignment-adjust",+ "alignment-baseline", "anchor-point", "animation", "animation-delay",+ "animation-direction", "animation-duration", "animation-fill-mode",+ "animation-iteration-count", "animation-name", "animation-play-state",+ "animation-timing-function", "appearance", "azimuth", "backface-visibility",+ "background", "background-attachment", "background-clip", "background-color",+ "background-image", "background-origin", "background-position",+ "background-repeat", "background-size", "baseline-shift", "binding",+ "bleed", "bookmark-label", "bookmark-level", "bookmark-state",+ "bookmark-target", "border", "border-bottom", "border-bottom-color",+ "border-bottom-left-radius", "border-bottom-right-radius",+ "border-bottom-style", "border-bottom-width", "border-collapse",+ "border-color", "border-image", "border-image-outset",+ "border-image-repeat", "border-image-slice", "border-image-source",+ "border-image-width", "border-left", "border-left-color",+ "border-left-style", "border-left-width", "border-radius", "border-right",+ "border-right-color", "border-right-style", "border-right-width",+ "border-spacing", "border-style", "border-top", "border-top-color",+ "border-top-left-radius", "border-top-right-radius", "border-top-style",+ "border-top-width", "border-width", "bottom", "box-decoration-break",+ "box-shadow", "box-sizing", "break-after", "break-before", "break-inside",+ "caption-side", "clear", "clip", "color", "color-profile", "column-count",+ "column-fill", "column-gap", "column-rule", "column-rule-color",+ "column-rule-style", "column-rule-width", "column-span", "column-width",+ "columns", "content", "counter-increment", "counter-reset", "crop", "cue",+ "cue-after", "cue-before", "cursor", "direction", "display",+ "dominant-baseline", "drop-initial-after-adjust",+ "drop-initial-after-align", "drop-initial-before-adjust",+ "drop-initial-before-align", "drop-initial-size", "drop-initial-value",+ "elevation", "empty-cells", "fit", "fit-position", "flex", "flex-basis",+ "flex-direction", "flex-flow", "flex-grow", "flex-shrink", "flex-wrap",+ "float", "float-offset", "flow-from", "flow-into", "font", "font-feature-settings",+ "font-family", "font-kerning", "font-language-override", "font-size", "font-size-adjust",+ "font-stretch", "font-style", "font-synthesis", "font-variant",+ "font-variant-alternates", "font-variant-caps", "font-variant-east-asian",+ "font-variant-ligatures", "font-variant-numeric", "font-variant-position",+ "font-weight", "grid", "grid-area", "grid-auto-columns", "grid-auto-flow",+ "grid-auto-position", "grid-auto-rows", "grid-column", "grid-column-end",+ "grid-column-start", "grid-row", "grid-row-end", "grid-row-start",+ "grid-template", "grid-template-areas", "grid-template-columns",+ "grid-template-rows", "hanging-punctuation", "height", "hyphens",+ "icon", "image-orientation", "image-rendering", "image-resolution",+ "inline-box-align", "justify-content", "left", "letter-spacing",+ "line-break", "line-height", "line-stacking", "line-stacking-ruby",+ "line-stacking-shift", "line-stacking-strategy", "list-style",+ "list-style-image", "list-style-position", "list-style-type", "margin",+ "margin-bottom", "margin-left", "margin-right", "margin-top",+ "marker-offset", "marks", "marquee-direction", "marquee-loop",+ "marquee-play-count", "marquee-speed", "marquee-style", "max-height",+ "max-width", "min-height", "min-width", "move-to", "nav-down", "nav-index",+ "nav-left", "nav-right", "nav-up", "object-fit", "object-position",+ "opacity", "order", "orphans", "outline",+ "outline-color", "outline-offset", "outline-style", "outline-width",+ "overflow", "overflow-style", "overflow-wrap", "overflow-x", "overflow-y",+ "padding", "padding-bottom", "padding-left", "padding-right", "padding-top",+ "page", "page-break-after", "page-break-before", "page-break-inside",+ "page-policy", "pause", "pause-after", "pause-before", "perspective",+ "perspective-origin", "pitch", "pitch-range", "play-during", "position",+ "presentation-level", "punctuation-trim", "quotes", "region-break-after",+ "region-break-before", "region-break-inside", "region-fragment",+ "rendering-intent", "resize", "rest", "rest-after", "rest-before", "richness",+ "right", "rotation", "rotation-point", "ruby-align", "ruby-overhang",+ "ruby-position", "ruby-span", "shape-image-threshold", "shape-inside", "shape-margin",+ "shape-outside", "size", "speak", "speak-as", "speak-header",+ "speak-numeral", "speak-punctuation", "speech-rate", "stress", "string-set",+ "tab-size", "table-layout", "target", "target-name", "target-new",+ "target-position", "text-align", "text-align-last", "text-decoration",+ "text-decoration-color", "text-decoration-line", "text-decoration-skip",+ "text-decoration-style", "text-emphasis", "text-emphasis-color",+ "text-emphasis-position", "text-emphasis-style", "text-height",+ "text-indent", "text-justify", "text-outline", "text-overflow", "text-shadow",+ "text-size-adjust", "text-space-collapse", "text-transform", "text-underline-position",+ "text-wrap", "top", "transform", "transform-origin", "transform-style",+ "transition", "transition-delay", "transition-duration",+ "transition-property", "transition-timing-function", "unicode-bidi",+ "vertical-align", "visibility", "voice-balance", "voice-duration",+ "voice-family", "voice-pitch", "voice-range", "voice-rate", "voice-stress",+ "voice-volume", "volume", "white-space", "widows", "width", "word-break",+ "word-spacing", "word-wrap", "z-index",+ // SVG-specific+ "clip-path", "clip-rule", "mask", "enable-background", "filter", "flood-color",+ "flood-opacity", "lighting-color", "stop-color", "stop-opacity", "pointer-events",+ "color-interpolation", "color-interpolation-filters",+ "color-rendering", "fill", "fill-opacity", "fill-rule", "image-rendering",+ "marker", "marker-end", "marker-mid", "marker-start", "shape-rendering", "stroke",+ "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin",+ "stroke-miterlimit", "stroke-opacity", "stroke-width", "text-rendering",+ "baseline-shift", "dominant-baseline", "glyph-orientation-horizontal",+ "glyph-orientation-vertical", "text-anchor", "writing-mode"+ );++ private static Set<String> nonStandardPropertyKeywords = Sets.newHashSet(+ "scrollbar-arrow-color", "scrollbar-base-color", "scrollbar-dark-shadow-color",+ "scrollbar-face-color", "scrollbar-highlight-color", "scrollbar-shadow-color",+ "scrollbar-3d-light-color", "scrollbar-track-color", "shape-inside",+ "searchfield-cancel-button", "searchfield-decoration", "searchfield-results-button",+ "searchfield-results-decoration", "zoom"+ );++ private static Set<String> colorKeywords = Sets.newHashSet(+ "aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige",+ "bisque", "black", "blanchedalmond", "blue", "blueviolet", "brown",+ "burlywood", "cadetblue", "chartreuse", "chocolate", "coral", "cornflowerblue",+ "cornsilk", "crimson", "cyan", "darkblue", "darkcyan", "darkgoldenrod",+ "darkgray", "darkgreen", "darkkhaki", "darkmagenta", "darkolivegreen",+ "darkorange", "darkorchid", "darkred", "darksalmon", "darkseagreen",+ "darkslateblue", "darkslategray", "darkturquoise", "darkviolet",+ "deeppink", "deepskyblue", "dimgray", "dodgerblue", "firebrick",+ "floralwhite", "forestgreen", "fuchsia", "gainsboro", "ghostwhite",+ "gold", "goldenrod", "gray", "grey", "green", "greenyellow", "honeydew",+ "hotpink", "indianred", "indigo", "ivory", "khaki", "lavender",+ "lavenderblush", "lawngreen", "lemonchiffon", "lightblue", "lightcoral",+ "lightcyan", "lightgoldenrodyellow", "lightgray", "lightgreen", "lightpink",+ "lightsalmon", "lightseagreen", "lightskyblue", "lightslategray",+ "lightsteelblue", "lightyellow", "lime", "limegreen", "linen", "magenta",+ "maroon", "mediumaquamarine", "mediumblue", "mediumorchid", "mediumpurple",+ "mediumseagreen", "mediumslateblue", "mediumspringgreen", "mediumturquoise",+ "mediumvioletred", "midnightblue", "mintcream", "mistyrose", "moccasin",+ "navajowhite", "navy", "oldlace", "olive", "olivedrab", "orange", "orangered",+ "orchid", "palegoldenrod", "palegreen", "paleturquoise", "palevioletred",+ "papayawhip", "peachpuff", "peru", "pink", "plum", "powderblue",+ "purple", "rebeccapurple", "red", "rosybrown", "royalblue", "saddlebrown",+ "salmon", "sandybrown", "seagreen", "seashell", "sienna", "silver", "skyblue",+ "slateblue", "slategray", "snow", "springgreen", "steelblue", "tan",+ "teal", "thistle", "tomato", "turquoise", "violet", "wheat", "white",+ "whitesmoke", "yellow", "yellowgreen"+ );++ private static Set<String> valueKeywords = Sets.newHashSet(+ "above", "absolute", "activeborder", "activecaption", "afar",+ "after-white-space", "ahead", "alias", "all", "all-scroll", "alternate",+ "always", "amharic", "amharic-abegede", "antialiased", "appworkspace",+ "arabic-indic", "armenian", "asterisks", "auto", "avoid", "avoid-column", "avoid-page",+ "avoid-region", "background", "backwards", "baseline", "below", "bidi-override", "binary",+ "bengali", "blink", "block", "block-axis", "bold", "bolder", "border", "border-box",+ "both", "bottom", "break", "break-all", "break-word", "button", "button-bevel",+ "buttonface", "buttonhighlight", "buttonshadow", "buttontext", "cambodian",+ "capitalize", "caps-lock-indicator", "caption", "captiontext", "caret",+ "cell", "center", "checkbox", "circle", "cjk-earthly-branch",+ "cjk-heavenly-stem", "cjk-ideographic", "clear", "clip", "close-quote",+ "col-resize", "collapse", "column", "compact", "condensed", "contain", "content",+ "content-box", "context-menu", "continuous", "copy", "cover", "crop",+ "cross", "crosshair", "currentcolor", "cursive", "dashed", "decimal",+ "decimal-leading-zero", "default", "default-button", "destination-atop",+ "destination-in", "destination-out", "destination-over", "devanagari",+ "disc", "discard", "document", "dot-dash", "dot-dot-dash", "dotted",+ "double", "down", "e-resize", "ease", "ease-in", "ease-in-out", "ease-out",+ "element", "ellipse", "ellipsis", "embed", "end", "ethiopic", "ethiopic-abegede",+ "ethiopic-abegede-am-et", "ethiopic-abegede-gez", "ethiopic-abegede-ti-er",+ "ethiopic-abegede-ti-et", "ethiopic-halehame-aa-er",+ "ethiopic-halehame-aa-et", "ethiopic-halehame-am-et",+ "ethiopic-halehame-gez", "ethiopic-halehame-om-et",+ "ethiopic-halehame-sid-et", "ethiopic-halehame-so-et",+ "ethiopic-halehame-ti-er", "ethiopic-halehame-ti-et",+ "ethiopic-halehame-tig", "ew-resize", "expanded", "extra-condensed",+ "extra-expanded", "fantasy", "fast", "fill", "fixed", "flat", "flex", "footnotes",+ "forwards", "from", "geometricPrecision", "georgian", "graytext", "groove",+ "gujarati", "gurmukhi", "hand", "hangul", "hangul-consonant", "hebrew",+ "help", "hidden", "hide", "higher", "highlight", "highlighttext",+ "hiragana", "hiragana-iroha", "horizontal", "hsl", "hsla", "icon", "ignore",+ "inactiveborder", "inactivecaption", "inactivecaptiontext", "infinite",+ "infobackground", "infotext", "inherit", "initial", "inline", "inline-axis",+ "inline-block", "inline-flex", "inline-table", "inset", "inside", "intrinsic", "invert",+ "italic", "justify", "kannada", "katakana", "katakana-iroha", "keep-all", "khmer",+ "landscape", "lao", "large", "larger", "left", "level", "lighter",+ "line-through", "linear", "lines", "list-item", "listbox", "listitem",+ "local", "logical", "loud", "lower", "lower-alpha", "lower-armenian",+ "lower-greek", "lower-hexadecimal", "lower-latin", "lower-norwegian",+ "lower-roman", "lowercase", "ltr", "malayalam", "match",+ "media-controls-background", "media-current-time-display",+ "media-fullscreen-button", "media-mute-button", "media-play-button",+ "media-return-to-realtime-button", "media-rewind-button",+ "media-seek-back-button", "media-seek-forward-button", "media-slider",+ "media-sliderthumb", "media-time-remaining-display", "media-volume-slider",+ "media-volume-slider-container", "media-volume-sliderthumb", "medium",+ "menu", "menulist", "menulist-button", "menulist-text",+ "menulist-textfield", "menutext", "message-box", "middle", "min-intrinsic",+ "mix", "mongolian", "monospace", "move", "multiple", "myanmar", "n-resize",+ "narrower", "ne-resize", "nesw-resize", "no-close-quote", "no-drop",+ "no-open-quote", "no-repeat", "none", "normal", "not-allowed", "nowrap",+ "ns-resize", "nw-resize", "nwse-resize", "oblique", "octal", "open-quote",+ "optimizeLegibility", "optimizeSpeed", "oriya", "oromo", "outset",+ "outside", "outside-shape", "overlay", "overline", "padding", "padding-box",+ "painted", "page", "paused", "persian", "plus-darker", "plus-lighter", "pointer",+ "polygon", "portrait", "pre", "pre-line", "pre-wrap", "preserve-3d", "progress", "push-button",+ "radio", "read-only", "read-write", "read-write-plaintext-only", "rectangle", "region",+ "relative", "repeat", "repeat-x", "repeat-y", "reset", "reverse", "rgb", "rgba",+ "ridge", "right", "round", "row-resize", "rtl", "run-in", "running",+ "s-resize", "sans-serif", "scroll", "scrollbar", "se-resize", "searchfield",+ "searchfield-cancel-button", "searchfield-decoration",+ "searchfield-results-button", "searchfield-results-decoration",+ "semi-condensed", "semi-expanded", "separate", "serif", "show", "sidama",+ "single", "skip-white-space", "slide", "slider-horizontal",+ "slider-vertical", "sliderthumb-horizontal", "sliderthumb-vertical", "slow",+ "small", "small-caps", "small-caption", "smaller", "solid", "somali",+ "source-atop", "source-in", "source-out", "source-over", "space", "square",+ "square-button", "start", "static", "status-bar", "stretch", "stroke",+ "sub", "subpixel-antialiased", "super", "sw-resize", "table",+ "table-caption", "table-cell", "table-column", "table-column-group",+ "table-footer-group", "table-header-group", "table-row", "table-row-group",+ "telugu", "text", "text-bottom", "text-top", "textarea", "textfield", "thai",+ "thick", "thin", "threeddarkshadow", "threedface", "threedhighlight",+ "threedlightshadow", "threedshadow", "tibetan", "tigre", "tigrinya-er",+ "tigrinya-er-abegede", "tigrinya-et", "tigrinya-et-abegede", "to", "top",+ "transparent", "ultra-condensed", "ultra-expanded", "underline", "up",+ "upper-alpha", "upper-armenian", "upper-greek", "upper-hexadecimal",+ "upper-latin", "upper-norwegian", "upper-roman", "uppercase", "urdu", "url",+ "vertical", "vertical-text", "visible", "visibleFill", "visiblePainted",+ "visibleStroke", "visual", "w-resize", "wait", "wave", "wider",+ "window", "windowframe", "windowtext", "x-large", "x-small", "xor",+ "xx-large", "xx-small"+ );++ private static Set<String> fontProperties = Sets.newHashSet(+ "font-family", "src", "unicode-range", "font-variant", "font-feature-settings",+ "font-stretch", "font-weight", "font-style"+ );++ static class State {+ Processor tokenize;+ StateTransition state;+ Context context;+ String override;+ String type;++ State(Processor tokenize, StateTransition state, Context context) {+ this.tokenize = tokenize;+ this.state = state;+ this.context = context;+ }+ }++ static class Context {+ int indent;+ StateTransition type;+ Context prev;++ Context(StateTransition type, int indent, Context prev) {+ this.type = type;+ this.indent = indent;+ this.prev = prev;+ }++ }++ private StateTransition pushContext(State state, StringStream stream, StateTransition type) {+ state.context = new Context(type, stream.indentation() + indentUnit(), state.context);+ return type;+ }++ private StateTransition popContext(State state) {+ state.context = state.context.prev;+ return state.context.type;+ }++ @Override+ protected State startState() {+ return new State(null, new StatesTop(), new Context(new StatesTop(), 0, null));+ }++ protected boolean allowNested() {+ return false;+ }++ static interface StateTransition {+ StateTransition transition(String type, StringStream stream, State state);+ }++ private static final Pattern STATES_TOP_PATTERN = Pattern.compile("^@(-(moz|ms|o|webkit)-)?keyframes$");++ class StatesTop implements StateTransition {++ @Override+ public StateTransition transition(String type, StringStream stream, State state) {+ if (type.equals("{")) {+ return pushContext(state, stream, new StatesBlock());+ } else if (type.equals("}") && state.context.prev != null) {+ return popContext(state);+ } else if (type.equals("@media")) {+ return pushContext(state, stream, new StatesMedia());+ } else if (type.equals("@font-face")) {+ return new StatesFontFaceBefore();+ } else if (STATES_TOP_PATTERN.matcher(type).find()) {+ return new StatesKeyFrames();+ } else if (type.length() != 0 && type.charAt(0) == '@') {+ return pushContext(state, stream, new StatesAt());+ } else if (type.equals("hash")) {+ state.override = "builtin";+ } else if (type.equals("word")) {+ state.override = "tag";+ } else if (type.equals("variable-definition")) {+ return new StatesMaybeProp();+ } else if (type.equals("interpolation")) {+ return pushContext(state, stream, new StatesInterpolation());+ } else if (type.equals(":")) {+ return new StatesPseudo();+ } else if (allowNested() && type.equals("(")) {+ return pushContext(state, stream, new StatesParens());+ }+ return state.context.type;+ }++ }++ private static Pattern STATES_BLOCK_PATTERN = Pattern.compile("^\\s*:(?:\\s|$)");++ class StatesBlock implements StateTransition {++ @Override+ public StateTransition transition(String type, StringStream stream, State state) {+ if (type.equals("word")) {+ String word = stream.current().toLowerCase();+ if (propertyKeywords.contains(word)) {+ state.override = "property";+ return new StatesMaybeProp();+ } else if (nonStandardPropertyKeywords.contains(word)) {+ state.override = "string-2";+ return new StatesMaybeProp();+ } else if (allowNested()) {+ state.override = !stream.match(STATES_BLOCK_PATTERN, false).isEmpty()? "property" : "tag";+ return new StatesBlock();+ } else {+ state.override += " error";+ return new StatesMaybeProp();+ }+ } else if (type.equals("meta")) {+ return new StatesBlock();+ } else if (!allowNested() && (type.equals("hash") || type.equals("qualifier"))) {+ state.override = "error";+ return new StatesBlock();+ } else {+ return new StatesTop().transition(type, stream, state);+ }+ }++ }++ class StatesMaybeProp implements StateTransition {++ @Override+ public StateTransition transition(String type, StringStream stream, State state) {+ if (type.equals(":"))+ return pushContext(state, stream, new StatesProp());+ return pass(type, stream, state);+ }++ }++ private static Pattern STATES_PROP_PATTERN = Pattern.compile("^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$");++ class StatesProp implements StateTransition {++ @Override+ public StateTransition transition(String type, StringStream stream, State state) {+ if (type.equals(";"))+ return popContext(state);+ if (type.equals("{") && allowNested())+ return pushContext(state, stream, new StatesPropBlock());+ if (type.equals("}") || type.equals("{"))+ return popAndPass(type, stream, state);+ if (type.equals("("))+ return pushContext(state, stream, new StatesParens());++ if (type.equals("hash") && !STATES_PROP_PATTERN.matcher(stream.current()).find()) {+ state.override += " error";+ } else if (type.equals("word")) {+ wordAsValue(stream, state);+ } else if (type.equals("interpolation")) {+ return pushContext(state, stream, new StatesInterpolation());+ }+ return new StatesProp();+ }++ }++ class StatesPropBlock implements StateTransition {++ @Override+ public StateTransition transition(String type, StringStream stream, State state) {+ if (type.equals("}"))+ return popContext(state);+ if (type.equals("word")) {+ state.override = "property";+ return new StatesMaybeProp();+ }+ return state.context.type;+ }++ }++ class StatesParens implements StateTransition {++ @Override+ public StateTransition transition(String type, StringStream stream, State state) {+ if (type.equals("{") || type.equals("}"))+ return popAndPass(type, stream, state);+ if (type.equals(")"))+ return popContext(state);+ if (type.equals("("))+ return pushContext(state, stream, new StatesParens());+ if (type.equals("word"))+ wordAsValue(stream, state);+ return new StatesParens();+ }++ }++ class StatesPseudo implements StateTransition {++ @Override+ public StateTransition transition(String type, StringStream stream, State state) {+ if (type.equals("word")) {+ state.override = "variable-3";+ return state.context.type;+ }+ return pass(type, stream, state);+ }++ }++ class StatesMedia implements StateTransition {++ @Override+ public StateTransition transition(String type, StringStream stream, State state) {+ if (type.equals("("))+ return pushContext(state, stream, new StatesMediaParens());+ if (type.equals("}"))+ return popAndPass(type, stream, state);+ if (type.equals("{")) {+ StateTransition transition = popContext(state);+ if (transition != null)+ return pushContext(state, stream, allowNested()? new StatesBlock() : new StatesTop());+ else+ return null;+ }++ if (type.equals("word")) {+ String word = stream.current().toLowerCase();+ if (word.equals("only") || word.equals("not") || word.equals("and"))+ state.override = "keyword";+ else if (mediaTypes.contains(word))+ state.override = "attribute";+ else if (mediaFeatures.contains(word))+ state.override = "property";+ else+ state.override = "error";+ }+ return state.context.type;+ }++ }++ class StatesMediaParens implements StateTransition {++ @Override+ public StateTransition transition(String type, StringStream stream, State state) {+ if (type.equals(")"))+ return popContext(state);+ if (type.equals("{") || type.equals("}"))+ return popAndPass(type, stream, state, 2);+ return new StatesMedia().transition(type, stream, state);+ }++ }++ class StatesFontFaceBefore implements StateTransition {++ @Override+ public StateTransition transition(String type, StringStream stream, State state) {+ if (type.equals("{"))+ return pushContext(state, stream, new StatesFontFace());+ return pass(type, stream, state);+ }++ }++ class StatesFontFace implements StateTransition {++ @Override+ public StateTransition transition(String type, StringStream stream, State state) {+ if (type.equals("}"))+ return popContext(state);+ if (type.equals("word")) {+ if (!fontProperties.contains(stream.current().toLowerCase()))+ state.override = "error";+ else+ state.override = "property";+ return new StatesMaybeProp();+ }+ return new StatesFontFace();+ }++ }++ class StatesKeyFrames implements StateTransition {++ @Override+ public StateTransition transition(String type, StringStream stream, State state) {+ if (type.equals("word")) {+ state.override = "variable";+ return new StatesKeyFrames();+ }+ if (type.equals("{"))+ return pushContext(state, stream, new StatesTop());+ return pass(type, stream, state);+ }++ }++ class StatesAt implements StateTransition {++ @Override+ public StateTransition transition(String type, StringStream stream, State state) {+ if (type.equals(";"))+ return popContext(state);+ if (type.equals("{") || type.equals("}"))+ return popAndPass(type, stream, state);+ if (type.equals("word"))+ state.override = "tag";+ else if (type.equals("hash"))+ state.override = "builtin";+ return new StatesAt();+ }++ }++ class StatesInterpolation implements StateTransition {++ @Override+ public StateTransition transition(String type, StringStream stream, State state) {+ if (type.equals("}"))+ return popContext(state);+ if (type.equals("{") || type.equals(";"))+ return popAndPass(type, stream, state);+ if (!type.equals("variable"))+ state.override = "error";+ return new StatesInterpolation();+ }++ }++ StateTransition pass(String type, StringStream stream, State state) {+ return state.context.type.transition(type, stream, state);+ }++ StateTransition popAndPass(String type, StringStream stream, State state) {+ return popAndPass(type, stream, state, 1);+ }++ StateTransition popAndPass(String type, StringStream stream, State state, int n) {+ for (int i = n; i > 0; i--)+ state.context = state.context.prev;+ return pass(type, stream, state);+ }++ void wordAsValue(StringStream stream, State state) {+ String word = stream.current().toLowerCase();+ if (valueKeywords.contains(word))+ state.override = "atom";+ else if (colorKeywords.contains(word))+ state.override = "keyword";+ else+ state.override = "variable";+ }++ static interface Processor {+ String process(StringStream stream, State state);+ }++ @Override+ protected String token(StringStream stream, State state) {+ if (state.tokenize == null && stream.eatSpace())+ return "";+ String style;+ if (state.tokenize != null)+ style = state.tokenize.process(stream, state);+ else+ style = tokenBase(stream, state);++ if (style.contains(" ")) {+ state.type = StringUtils.substringAfter(style, " ");+ style = StringUtils.substringBefore(style, " ");+ }+ state.override = style;+ state.state = state.state.transition(state.type, stream, state);+ return state.override;+ }++ String ret(String style, String tp, State state) {+ state.type = tp;+ return style;+ }++ private static Pattern TOKEN_BASE_PATTERN1 = Pattern.compile("[\\w\\\\\\-]");++ private static Pattern TOKEN_BASE_PATTERN2 = Pattern.compile("^\\s*\\w*");++ private static Pattern TOKEN_BASE_PATTERN3 = Pattern.compile("\\d");++ private static Pattern TOKEN_BASE_PATTERN4 = Pattern.compile("[\\w.%]");++ private static Pattern TOKEN_BASE_PATTERN5 = Pattern.compile("[\\d.]");++ private static Pattern TOKEN_BASE_PATTERN6 = Pattern.compile("^\\w+-");++ private static Pattern TOKEN_BASE_PATTERN7 = Pattern.compile("[,+>*\\/]");++ private static Pattern TOKEN_BASE_PATTERN8 = Pattern.compile("^-?[_a-z][_a-z0-9-]*", Pattern.CASE_INSENSITIVE);++ private static Pattern TOKEN_BASE_PATTERN9 = Pattern.compile("[:;{}\\[\\]\\(\\)]");++ private static Pattern TOKEN_BASE_PATTERN10 = Pattern.compile("[\\w\\\\\\-]");++ String tokenBase(StringStream stream, State state) {+ String ch = stream.next();+ if (tokenHooks().containsKey(ch)) {+ String result = tokenHooks().get(ch).process(stream, state);+ if (result.length() != 0)+ return result;+ }+ if (ch.equals("@")) {+ stream.eatWhile(TOKEN_BASE_PATTERN1);+ return ret("def", stream.current(), state);+ } else if (ch.equals("=") || (ch.equals("~") || ch.equals("|")) && stream.eat("=").length()!=0) {+ return ret("", "compare", state);+ } else if (ch.equals("\"") || ch.equals("'")) {+ state.tokenize = new TokenString(ch);+ return state.tokenize.process(stream, state);+ } else if (ch.equals("#")) {+ stream.eatWhile(TOKEN_BASE_PATTERN1);+ return ret("atom", "hash", state);+ } else if (ch.equals("!")) {+ stream.match(TOKEN_BASE_PATTERN2);+ return ret("keyword", "important", state);+ } else if (TOKEN_BASE_PATTERN3.matcher(ch).find() || ch.equals(".") && stream.eat(TOKEN_BASE_PATTERN3).length()!=0) {+ stream.eatWhile(TOKEN_BASE_PATTERN4);+ return ret("number", "unit", state);+ } else if (ch.equals("-")) {+ if (TOKEN_BASE_PATTERN5.matcher(stream.peek()).find()) {+ stream.eatWhile(TOKEN_BASE_PATTERN4);+ return ret("number", "unit", state);+ } else if (!stream.match(TOKEN_BASE_PATTERN6).isEmpty()) {+ return ret("meta", "meta", state);+ }+ } else if (TOKEN_BASE_PATTERN7.matcher(ch).find()) {+ return ret("", "select-op", state);+ } else if (ch.equals(".") && !stream.match(TOKEN_BASE_PATTERN8).isEmpty()) {+ return ret("qualifier", "qualifier", state);+ } else if (TOKEN_BASE_PATTERN9.matcher(ch).find()) {+ return ret("", ch, state);+ } else if (ch.equals("u") && stream.match("rl(")) {+ stream.backUp(1);+ state.tokenize = new TokenParenthesized();+ return ret("property", "word", state);+ } else if (TOKEN_BASE_PATTERN10.matcher(ch).find()) {+ stream.eatWhile(TOKEN_BASE_PATTERN10);+ return ret("property", "word", state);+ } else {+ return ret("", "", state);+ }+ return "";+ }++ class TokenString implements Processor {++ private final String quote;++ public TokenString(String quote) {+ this.quote = quote;+ }++ @Override+ public String process(StringStream stream, State state) {+ boolean escaped = false;+ String ch;+ while ((ch = stream.next()).length() != 0) {+ if (ch.equals(quote) && !escaped) {+ if (quote.equals(")"))+ stream.backUp(1);+ break;+ }+ escaped = !escaped && ch.equals("\\");+ }+ if (ch.equals(quote) || !escaped && !quote.equals(")"))+ state.tokenize = null;+ return ret("string", "string", state);+ }++ }++ private static Pattern TOKEN_PARENTHESIZED_PATTERN = Pattern.compile("\\s*[\\\"\\')]");++ class TokenParenthesized implements Processor {++ @Override+ public String process(StringStream stream, State state) {+ stream.next(); // Must be '('+ if (stream.match(TOKEN_PARENTHESIZED_PATTERN, false).isEmpty())+ state.tokenize = new TokenString(")");+ else+ state.tokenize = null;+ return ret("", "(", state);+ }++ }++ class TokenCComment implements Processor {++ @Override+ public String process(StringStream stream, State state) {+ boolean maybeEnd = false;+ String ch;+ while ((ch = stream.next()).length() != 0) {+ if (maybeEnd && ch.equals("/")) {+ state.tokenize = null;+ break;+ }+ maybeEnd = (ch.equals("*"));+ }+ return "comment comment";+ }++ }++ class TokenSGMLComment implements Processor {++ @Override+ public String process(StringStream stream, State state) {+ if (stream.skipTo("-->")) {+ stream.match("-->");+ state.tokenize = null;+ } else {+ stream.skipToEnd();+ }+ return "comment comment";+ }++ }++ protected abstract Map<String, Processor> tokenHooks();++ public static class Css extends CssTokenizer {++ private Map<String, Processor> TOKEN_HOOKS = new HashMap<>();++ public Css() {+ TOKEN_HOOKS.put("<", new Processor() {++ @Override+ public String process(StringStream stream, State state) {+ if (!stream.match("!--"))+ return "";+ state.tokenize = new Css.TokenSGMLComment();+ return new TokenSGMLComment().process(stream, state);+ }++ });+ TOKEN_HOOKS.put("/", new Processor() {++ @Override+ public String process(StringStream stream, State state) {+ if (stream.eat("*").length() == 0)+ return "";+ state.tokenize = new TokenCComment();+ return state.tokenize.process(stream, state);+ }++ });+ }++ @Override+ public boolean accept(String fileName) {+ return acceptExtensions(fileName, "css");+ }++ @Override+ protected Map<String, Processor> tokenHooks() {+ return TOKEN_HOOKS;+ }++ }++ public static class SCSS extends CssTokenizer {++ private Map<String, Processor> TOKEN_HOOKS = new HashMap<>();++ private static Pattern PATTERN1 = Pattern.compile("\\s*\\{");++ private static Pattern PATTERN2 = Pattern.compile("^[\\w-]+");++ private static Pattern PATTERN3 = Pattern.compile("^\\s*:");++ public SCSS() {+ TOKEN_HOOKS.put("/", new Processor() {++ @Override+ public String process(StringStream stream, State state) {+ if (stream.eat("/").length() != 0) {+ stream.skipToEnd();+ return "comment comment";+ } else if (stream.eat("*").length() != 0) {+ state.tokenize = new TokenCComment();+ return state.tokenize.process(stream, state);+ } else {+ return "operator operator";+ }+ }++ });+ TOKEN_HOOKS.put(":", new Processor() {++ @Override+ public String process(StringStream stream, State state) {+ if (!stream.match(PATTERN1).isEmpty())+ return " {";+ return "";+ }++ });+ TOKEN_HOOKS.put("$", new Processor() {++ @Override+ public String process(StringStream stream, State state) {+ stream.match(PATTERN2);+ if (!stream.match(PATTERN3, false).isEmpty())+ return "variable-2 variable-definition";+ return "variable-2 variable";+ }++ });+ TOKEN_HOOKS.put("#", new Processor() {++ @Override+ public String process(StringStream stream, State state) {+ if (stream.eat("{").length() == 0)+ return "";+ return " interpolation";+ }++ });+ }++ @Override+ public boolean accept(String fileName) {+ return acceptExtensions(fileName, "scss");+ }++ @Override+ protected boolean allowNested() {+ return true;+ }++ @Override+ protected Map<String, Processor> tokenHooks() {+ return TOKEN_HOOKS;+ }++ }++ public static class LESS extends CssTokenizer {++ private Map<String, Processor> TOKEN_HOOKS = new HashMap<>();++ private static Pattern PATTERN1 = Pattern.compile("^(charset|document|font-face|import|(-(moz|ms|o|webkit)-)?keyframes|media|namespace|page|supports)\\b");++ private static Pattern PATTERN2 = Pattern.compile("^[\\w\\\\\\-]");++ private static Pattern PATTERN3 = Pattern.compile("^\\s*:");++ public LESS() {+ TOKEN_HOOKS.put("/", new Processor() {++ @Override+ public String process(StringStream stream, State state) {+ if (stream.eat("/").length() != 0) {+ stream.skipToEnd();+ return "comment comment";+ } else if (stream.eat("*").length() != 0) {+ state.tokenize = new TokenCComment();+ return state.tokenize.process(stream, state);+ } else {+ return "operator operator";+ }+ }++ });+ TOKEN_HOOKS.put("@", new Processor() {++ @Override+ public String process(StringStream stream, State state) {+ if (!stream.match(PATTERN1, false).isEmpty())+ return "";+ stream.eatWhile(PATTERN2);+ if (!stream.match(PATTERN3, false).isEmpty())+ return "variable-2 variable-definition";+ return "variable-2 variable";+ }++ });+ TOKEN_HOOKS.put("&", new Processor() {++ @Override+ public String process(StringStream stream, State state) {+ return "atom atom";+ }++ });+ }++ @Override+ public boolean accept(String fileName) {+ return acceptExtensions(fileName, "less");+ }++ @Override+ protected boolean allowNested() {+ return true;+ }++ @Override+ protected Map<String, Processor> tokenHooks() {+ return TOKEN_HOOKS;+ }++ }+}diff --git a/commons.tokenizer/src/main/java/com/pmease/commons/tokenizer/JavascriptTokenizer.java b/commons.tokenizer/src/main/java/com/pmease/commons/tokenizer/JavascriptTokenizer.javanew file mode 100644index 0000000000..d2447fa5d5--- /dev/null+++ b/commons.tokenizer/src/main/java/com/pmease/commons/tokenizer/JavascriptTokenizer.java@@ -0,0 +1,1375 @@+package com.pmease.commons.tokenizer;++import java.util.HashMap;+import java.util.Map;+import java.util.Set;+import java.util.Stack;+import java.util.regex.Pattern;++import com.google.common.collect.Sets;++public abstract class JavascriptTokenizer extends AbstractTokenizer<JavascriptTokenizer.State> {++ static class State {+ String type = "";+ String content;+ Processor tokenize;+ String lastType;+ int fatArrowAt = -1;+ Var localVars;+ Var globalVars;+ Context context;+ Stack<Combinator> cc;+ String style;+ String marked;+ JSLexical lexical;+ int indented;+ }++ static class Keyword {+ final String type, style;++ Keyword(String type, String style) {+ this.type = type;+ this.style = style;+ }+ }++ static interface Processor {+ String process(StringStream stream, State state);+ }++ static Keyword kw(String type) {+ return new Keyword(type, "keyword");+ }++ static Keyword A = kw("keyword a");+ static Keyword B = kw("keyword b");+ static Keyword C = kw("keyword c");+ static Keyword operator = kw("operator");+ static Keyword atom = new Keyword("atom", "atom");++ final Map<String, Keyword> keywords = new HashMap<>();++ final boolean isTS;++ public JavascriptTokenizer(boolean typescript) {+ isTS = typescript;++ keywords.put("if", kw("if"));+ keywords.put("while", A);+ keywords.put("with", A);+ keywords.put("else", B);+ keywords.put("do", B);+ keywords.put("try", B);+ keywords.put("finally", B);+ keywords.put("return", C);+ keywords.put("break", C);+ keywords.put("continue", C);+ keywords.put("new", C);+ keywords.put("delete", C);+ keywords.put("throw", C);+ keywords.put("debugger", C);+ keywords.put("var", kw("var"));+ keywords.put("const", kw("var"));+ keywords.put("let", kw("var"));+ keywords.put("function", kw("function"));+ keywords.put("catch", kw("catch"));+ keywords.put("for", kw("for"));+ keywords.put("switch", kw("switch"));+ keywords.put("case", kw("case"));+ keywords.put("default", kw("default"));+ keywords.put("in", operator);+ keywords.put("typeof", operator);+ keywords.put("instanceof", operator);+ keywords.put("true", atom);+ keywords.put("false", atom);+ keywords.put("null", atom);+ keywords.put("undefined", atom);+ keywords.put("NaN", atom);+ keywords.put("Infinity", atom);+ keywords.put("this", kw("this"));+ keywords.put("module", kw("module"));+ keywords.put("class", kw("class"));+ keywords.put("super", kw("atom"));+ keywords.put("yield", C);+ keywords.put("export", kw("export"));+ keywords.put("import", kw("import"));+ keywords.put("extends", C);++ if (isTS) {+ Keyword type = new Keyword("variable", "variable-3");+ keywords.put("interface", kw("interface"));+ keywords.put("extends", kw("extends"));+ keywords.put("constructor", kw("constructor"));+ keywords.put("public", kw("public"));+ keywords.put("private", kw("private"));+ keywords.put("protected", kw("protected"));+ keywords.put("static", kw("static"));+ keywords.put("string", type);+ keywords.put("number", type);+ keywords.put("bool", type);+ keywords.put("any", type);+ }+ }++ static Pattern wordRE = Pattern.compile("[\\w$\\xa1-\\uffff]");++ static Pattern isOperatorChar = Pattern.compile("[+\\-*&%=<>!?|~^]");++ static Pattern isJsonldKeyword = Pattern.compile("^@(context|id|value|language|type|container|list|set|reverse|index|base|vocab|graph)\"");++ void readRegexp(StringStream stream) {+ boolean escaped = false;+ String next;+ boolean inSet = false;+ while ((next = stream.next()).length() != 0) {+ if (!escaped) {+ if (next.equals("/") && !inSet)+ return;+ if (next.equals("["))+ inSet = true;+ else if (inSet && next.equals("]"))+ inSet = false;+ }+ escaped = !escaped && next.equals("\\");+ }+ }++ String ret(String tp, String style, String cont, State state) {+ state.type = tp; state.content = cont;+ return style;+ }++ static Pattern TOKEN_BASE_PATTERN1 = Pattern.compile("^\\d+(?:[eE][+\\-]?\\d+)?");++ static Pattern TOKEN_BASE_PATTERN2 = Pattern.compile("[\\[\\]{}\\(\\),;\\:\\.]");++ static Pattern TOKEN_BASE_PATTERN3 = Pattern.compile("x", Pattern.CASE_INSENSITIVE);++ static Pattern TOKEN_BASE_PATTERN4 = Pattern.compile("[\\da-f]", Pattern.CASE_INSENSITIVE);++ static Pattern TOKEN_BASE_PATTERN5 = Pattern.compile("\\d");++ static Pattern TOKEN_BASE_PATTERN6 = Pattern.compile("^\\d*(?:\\.\\d*)?(?:[eE][+\\-]?\\d+)?");++ static Pattern TOKEN_BASE_PATTERN7 = Pattern.compile("^[\\[{}\\(,;:]$");++ static Pattern TOKEN_BASE_PATTERN8 = Pattern.compile("[gimy]");++ class TokenBase implements Processor {++ @Override+ public String process(StringStream stream, State state) {+ String ch = stream.next();+ if (ch.equals("\"") || ch.equals("'")) {+ state.tokenize = new TokenString(ch);+ return state.tokenize.process(stream, state);+ } else if (ch.equals(".") && !stream.match(TOKEN_BASE_PATTERN1).isEmpty()) {+ return ret("number", "number", "", state);+ } else if (ch.equals(".") && stream.match("..")) {+ return ret("spread", "meta", "", state);+ } else if (TOKEN_BASE_PATTERN2.matcher(ch).find()) {+ return ret(ch, "", "", state);+ } else if (ch.equals("=") && stream.eat(">").length() != 0) {+ return ret("=>", "operator", "", state);+ } else if (ch.equals("0") && stream.eat(TOKEN_BASE_PATTERN3).length() != 0) {+ stream.eatWhile(TOKEN_BASE_PATTERN4);+ return ret("number", "number", "", state);+ } else if (TOKEN_BASE_PATTERN5.matcher(ch).find()) {+ stream.match(TOKEN_BASE_PATTERN6);+ return ret("number", "number", "", state);+ } else if (ch.equals("/")) {+ if (stream.eat("*").length() != 0) {+ state.tokenize = new TokenComment();+ return state.tokenize.process(stream, state);+ } else if (stream.eat("/").length() != 0) {+ stream.skipToEnd();+ return ret("comment", "comment", "", state);+ } else if (state.lastType.equals("operator") || state.lastType.equals("keyword c") ||+ state.lastType.equals("sof") || TOKEN_BASE_PATTERN7.matcher(state.lastType).find()) {+ readRegexp(stream);+ stream.eatWhile(TOKEN_BASE_PATTERN8); // 'y' is "sticky" option in Mozilla+ return ret("regexp", "string-2", "", state);+ } else {+ stream.eatWhile(isOperatorChar);+ return ret("operator", "operator", stream.current(), state);+ }+ } else if (ch.equals("`")) {+ state.tokenize = new TokenQuasi();+ return state.tokenize.process(stream, state);+ } else if (ch.equals("#")) {+ stream.skipToEnd();+ return ret("error", "error", "", state);+ } else if (isOperatorChar.matcher(ch).find()) {+ stream.eatWhile(isOperatorChar);+ return ret("operator", "operator", stream.current(), state);+ } else if (wordRE.matcher(ch).find()) {+ stream.eatWhile(wordRE);+ String word = stream.current();+ Keyword known = keywords.get(word);+ return (known!=null && !state.lastType.equals(".")) ? ret(known.type, known.style, word, state) :+ ret("variable", "variable", word, state);+ }+ return "";+ }++ }++ class TokenString implements Processor {+ final String quote;++ TokenString(String quote) {+ this.quote = quote;+ }++ @Override+ public String process(StringStream stream, State state) {+ boolean escaped = false;+ String next;+ if (jsonldMode() && stream.peek().equals("@") && !stream.match(isJsonldKeyword).isEmpty()){+ state.tokenize = new TokenBase();+ return ret("jsonld-keyword", "meta", "", state);+ }+ while ((next = stream.next()).length() != 0) {+ if (next.equals(quote) && !escaped)+ break;+ escaped = !escaped && next.equals("\\");+ }+ if (!escaped)+ state.tokenize = new TokenBase();+ return ret("string", "string", "", state);+ }++ }++ class TokenComment implements Processor {++ @Override+ public String process(StringStream stream, State state) {+ boolean maybeEnd = false;+ String ch;+ while ((ch = stream.next()).length() != 0) {+ if (ch.equals("/") && maybeEnd) {+ state.tokenize = new TokenBase();+ break;+ }+ maybeEnd = (ch.equals("*"));+ }+ return ret("comment", "comment", "", state);+ }++ }++ class TokenQuasi implements Processor {++ @Override+ public String process(StringStream stream, State state) {+ boolean escaped = false;+ String next;+ while ((next = stream.next()).length() != 0) {+ if (!escaped && (next.equals("`") || next.equals("$") && stream.eat("{").length() != 0)) {+ state.tokenize = new TokenBase();+ break;+ }+ escaped = !escaped && next.equals("\\");+ }+ return ret("quasi", "string-2", stream.current(), state);+ }++ }++ static String brackets = "([{}])";++ static Pattern FIND_FAT_ARROW_PATTERN = Pattern.compile("[\"'\\/]");++ void findFatArrow(StringStream stream, State state) {+ if (state.fatArrowAt != -1)+ state.fatArrowAt = -1;++ int arrow = stream.string().indexOf("=>", stream.start());+ if (arrow < 0)+ return;++ int depth = 0;+ boolean sawSomething = false;+ int pos;+ for (pos = arrow - 1; pos >= 0; --pos) {+ String ch = String.valueOf(stream.string().charAt(pos));+ int bracket = brackets.indexOf(ch);+ if (bracket >= 0 && bracket < 3) {+ if (depth==0) {+ ++pos; break;+ }+ if (--depth == 0)+ break;+ } else if (bracket >= 3 && bracket < 6) {+ ++depth;+ } else if (wordRE.matcher(ch).find()) {+ sawSomething = true;+ } else if (FIND_FAT_ARROW_PATTERN.matcher(ch).find()) {+ return;+ } else if (sawSomething && depth==0) {+ ++pos;+ break;+ }+ }+ if (sawSomething && depth==0)+ state.fatArrowAt = pos;+ }++ static Set<String> atomicTypes = Sets.newHashSet(+ "atom", "number", "variable", "string", "regexp", "this", "jsonld-keyword");++ class JSLexical {+ int indented;+ int column;+ String type;+ JSLexical prev;+ String info;+ Boolean align;+ int pos;++ JSLexical(int indented, int column, String type, Boolean align, JSLexical prev, String info) {+ this.indented = indented;+ this.column = column;+ this.type = type;+ this.prev = prev;+ this.info = info;+ if (align != null)+ this.align = align;+ }+ }++ class Var {+ String name;+ Var next;++ Var(String name, Var next) {+ this.name = name;+ this.next = next;+ }+ }++ class Context {+ Var vars;+ Context prev;++ Context(Var vars, Context prev) {+ this.vars = vars;+ this.prev = prev;+ }+ }++ boolean inScope(State state, String varname) {+ for (Var v = state.localVars; v != null; v = v.next)+ if (v.name.equals(varname))+ return true;+ for (Context cx = state.context; cx != null; cx = cx.prev) {+ for (Var v = cx.vars; v!=null; v = v.next)+ if (v.name.equals(varname)) return true;+ }+ return false;+ }++ static abstract class Combinator {++ abstract boolean combine(StringStream stream, State state, String type, String value);++ boolean lex() {+ return false;+ }+ }++ class Expression extends Combinator {++ @Override+ public boolean combine(StringStream stream, State state, String type, String content) {+ return expressionInner(stream, state, type, false);+ }+ }++ class ExpressionNoComma extends Combinator {++ @Override+ public boolean combine(StringStream stream, State state, String type, String content) {+ return expressionInner(stream, state, type, true);+ }++ }++ boolean pass(State state, Combinator... combinators) {+ for (int i = combinators.length - 1; i >= 0; i--)+ state.cc.push(combinators[i]);+ return false;+ }++ boolean cont(State state, Combinator... combinators) {+ pass(state, combinators);+ return true;+ }++ boolean inList(Var list, String varname) {+ for (Var v = list; v!=null; v = v.next) {+ if (v.name.equals(varname))+ return true;+ }+ return false;+ }++ void register(State state, String varname) {+ if (state.context != null) {+ state.marked = "def";+ if (inList(state.localVars, varname))+ return;+ state.localVars = new Var(varname, state.localVars);+ } else {+ if (inList(state.globalVars, varname))+ return;+ if (globalVars() != null)+ state.globalVars = new Var(varname, state.globalVars);+ }+ }++ final Var defaultVars = new Var("this", new Var("arguments", null));++ class PushContext extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type, String value) {+ state.context = new Context(state.localVars, state.context);+ state.localVars = defaultVars;+ return false;+ }++ }++ class PopContext extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type, String value) {+ state.localVars = state.context.vars;+ state.context = state.context.prev;+ return false;+ }++ }++ class PushLex extends Combinator {++ final String type;++ final String info;++ PushLex(String type, String info) {+ this.type = type;+ this.info = info;+ }++ @Override+ boolean lex() {+ return true;+ }++ @Override+ boolean combine(StringStream stream, State state, String type, String content) {+ int indent = state.indented;+ if (state.lexical.type.equals("stat"))+ indent = state.lexical.indented;+ else for (JSLexical outer = state.lexical; outer!=null && outer.type.equals(")") && outer.align!=null&&outer.align; outer = outer.prev)+ indent = outer.indented;+ state.lexical = new JSLexical(indent, stream.column(), this.type, null, state.lexical, info);+ return false;+ }++ }++ class PopLex extends Combinator {++ @Override+ boolean lex() {+ return true;+ }++ @Override+ boolean combine(StringStream stream, State state, String type, String content) {+ if (state.lexical.prev != null) {+ if (state.lexical.type.equals(")"))+ state.indented = state.lexical.indented;+ state.lexical = state.lexical.prev;+ }+ return false;+ }++ }++ class Expect extends Combinator {++ final String wanted;++ Expect(String wanted) {+ this.wanted = wanted;+ }++ @Override+ boolean combine(StringStream stream, State state, String type, String content) {+ if (type.equals(wanted))+ return cont(state);+ else if (wanted.equals(";"))+ return pass(state);+ else+ return cont(state, new Expect(wanted));+ }++ }++ class Statement extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type, String value) {+ if (type.equals("var"))+ return cont(state, new PushLex("vardef", String.valueOf(value.length())), new Vardef(), new Expect(";"), new PopLex());+ if (type.equals("keyword a"))+ return cont(state, new PushLex("form", ""), new Expression(), new Statement(), new PopLex());+ if (type.equals("keyword b"))+ return cont(state, new PushLex("form", ""), new Statement(), new PopLex());+ if (type.equals("{"))+ return cont(state, new PushLex("}", ""), new Block(), new PopLex());+ if (type.equals(";"))+ return cont(state);+ if (type.equals("if")) {+ if (state.lexical.info.equals("else") && (state.cc.get(state.cc.size() - 1) instanceof PopLex))+ state.cc.pop().combine(stream, state, "", "");+ return cont(state, new PushLex("form", ""), new Expression(), new Statement(), new PopLex(), new Maybeelse());+ }+ if (type.equals("function"))+ return cont(state, new Functiondef());+ if (type.equals("for"))+ return cont(state, new PushLex("form", ""), new Forspec(), new Statement(), new PopLex());+ if (type.equals("variable"))+ return cont(state, new PushLex("stat", ""), new Maybelabel());+ if (type.equals("switch"))+ return cont(state, new PushLex("form", ""), new Expression(), new PushLex("}", "switch"), new Expect("{"), new Block(), new PopLex(), new PopLex());+ if (type.equals("case"))+ return cont(state, new Expression(), new Expect(":"));+ if (type.equals("default"))+ return cont(state, new Expect(":"));+ if (type.equals("catch"))+ return cont(state, new PushLex("form", ""), new PushContext(), new Expect("("), new Funarg(), new Expect(")"), new Statement(), new PopLex(), new PopContext());+ if (type.equals("module"))+ return cont(state, new PushLex("form", ""), new PushContext(), new AfterModule(), new PopContext(), new PopLex());+ if (type.equals("class"))+ return cont(state, new PushLex("form", ""), new ClassName(), new PopLex());+ if (type.equals("export"))+ return cont(state, new PushLex("form", ""), new AfterExport(), new PopLex());+ if (type.equals("import"))+ return cont(state, new PushLex("form", ""), new AfterImport(), new PopLex());+ return pass(state, new PushLex("stat", ""), new Expression(), new Expect(";"), new PopLex());+ }++ }++ boolean expressionInner(StringStream stream, State state, String type, boolean noComma) {+ if (state.fatArrowAt == stream.start()) {+ Combinator body = noComma ? new ArrowBodyNoComma() : new ArrowBody();+ if (type.equals("("))+ return cont(state, new PushContext(), new PushLex(")", ""), new Commasep(new PatternCombinator(), ")"), new PopLex(), new Expect("=>"), body, new PopContext());+ else if (type.equals("variable"))+ return pass(state, new PushContext(), new PatternCombinator(), new Expect("=>"), body, new PopContext());+ }++ Combinator maybeop = noComma ? new MaybeoperatorNoComma() : new MaybeoperatorComma();+ if (atomicTypes.contains(type))+ return cont(state, maybeop);+ if (type.equals("function"))+ return cont(state, new Functiondef(), maybeop);+ if (type.equals("keyword c"))+ return cont(state, noComma ? new MaybeexpressionNoComma() : new Maybeexpression());+ if (type.equals("("))+ return cont(state, new PushLex(")", ""), new Maybeexpression(), new Comprehension(), new Expect(")"), new PopLex(), maybeop);+ if (type.equals("operator") || type.equals("spread"))+ return cont(state, noComma ? new ExpressionNoComma() : new Expression());+ if (type.equals("["))+ return cont(state, new PushLex("]", ""), new ArrayLiteral(), new PopLex(), maybeop);+ if (type.equals("{"))+ return contCommasep(state, new Objprop(), "}", "", maybeop);+ if (type.equals("quasi")) {+ return pass(state, new Quasi(), maybeop);+ }+ return cont(state);+ }++ String parseJS(State state, String style, String type, String content, StringStream stream) {+ Stack<Combinator> cc = state.cc;+ // Communicate our context to the combinators.+ // (Less wasteful than consing up a hundred closures on every call.)+ state.marked = ""; state.style = style;++ if (state.lexical.align == null)+ state.lexical.align = true;++ while(true) {+ Combinator combinator = !state.cc.isEmpty()? cc.pop() : jsonMode() ? new Expression() : new Statement();+ if (combinator.combine(stream, state, type, content)) {+ while(!state.cc.isEmpty() && state.cc.get(state.cc.size() - 1).lex())+ cc.pop().combine(stream, state, "", "");+ if (state.marked.length()!=0)+ return state.marked;+ if (type.equals("variable") && inScope(state, content))+ return "variable-2";+ return style;+ }+ }+ }++ static Pattern MAYBE_EXPRESSION_PATTERN = Pattern.compile("[;\\}\\)\\],]");++ class Maybeexpression extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type, String value) {+ if (MAYBE_EXPRESSION_PATTERN.matcher(type).find())+ return pass(state);+ return pass(state, new Expression());+ }+ }++ class MaybeexpressionNoComma extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type, String value) {+ if (MAYBE_EXPRESSION_PATTERN.matcher(type).find())+ return pass(state);+ return pass(state, new ExpressionNoComma());+ }+ }++ class MaybeoperatorComma extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type, String value) {+ if (type.equals(","))+ return cont(state, new Expression());+ return new MaybeoperatorNoComma(false).combine(stream, state, type, value);+ }++ }++ static Pattern MAYBE_OPERATOR_NOCOMMA_PATTERN = Pattern.compile("\\+\\+|--");++ class MaybeoperatorNoComma extends Combinator {++ final boolean noComma;++ MaybeoperatorNoComma() {+ noComma = true;+ }++ MaybeoperatorNoComma(boolean noComma) {+ this.noComma = noComma;+ }++ @Override+ boolean combine(StringStream stream, State state, String type, String value) {+ Combinator me = noComma == false ? new MaybeoperatorComma() : new MaybeoperatorNoComma();+ Combinator expr = noComma == false ? new Expression() : new ExpressionNoComma();+ if (type.equals("=>"))+ return cont(state, new PushContext(), noComma ? new ArrowBodyNoComma() : new ArrowBody(), new PopContext());+ if (type.equals("operator")) {+ if (MAYBE_OPERATOR_NOCOMMA_PATTERN.matcher(value).find())+ return cont(state, me);+ if (value.equals("?"))+ return cont(state, new Expression(), new Expect(":"), expr);+ return cont(state, expr);+ }+ if (type.equals("quasi")) {return pass(state, new Quasi(), me); }+ if (type.equals(";")) return false;+ if (type.equals("(")) return contCommasep(state, new ExpressionNoComma(), ")", "call", me);+ if (type.equals(".")) return cont(state, new Property(), me);+ if (type.equals("[")) return cont(state, new PushLex("]", ""), new Maybeexpression(), new Expect("]"), new PopLex(), me);+ return false;+ }++ }++ class Quasi extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type, String value) {+ if (!type.equals("quasi"))+ return pass(state);+ if (!value.substring(value.length() - 2).equals("${"))+ return cont(state, new Quasi());+ return cont(state, new Expression(), new ContinueQuasi());+ }++ }++ class ContinueQuasi extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type, String value) {+ if (type.equals("}")) {+ state.marked = "string-2";+ state.tokenize = new TokenQuasi();+ return cont(state, new Quasi());+ }+ return false;+ }++ }++ class ArrowBody extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type, String value) {+ findFatArrow(stream, state);+ return pass(state, type.equals("{") ? new Statement() : new Expression());+ }++ }++ class ArrowBodyNoComma extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type,+ String value) {+ findFatArrow(stream, state);+ return pass(state, type.equals("{") ? new Statement(): new ExpressionNoComma());+ }++ }++ class Maybelabel extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type,+ String value) {+ if (type.equals(":"))+ return cont(state, new PopLex(), new Statement());+ return pass(state, new MaybeoperatorComma(), new Expect(";"), new PopLex());+ }++ }++ class Property extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type,+ String value) {+ if (type.equals("variable")) {+ state.marked = "property";+ return cont(state);+ }+ return false;+ }++ }++ class Objprop extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type,+ String value) {+ if (type.equals("variable") || state.style.equals("keyword")) {+ state.marked = "property";+ if (value.equals("get") || value.equals("set"))+ return cont(state, new GetterSetter());+ return cont(state, new Afterprop());+ } else if (type.equals("number") || type.equals("string")) {+ state.marked = jsonldMode() ? "property" : (state.style + " property");+ return cont(state, new Afterprop());+ } else if (type.equals("jsonld-keyword")) {+ return cont(state, new Afterprop());+ } else if (type.equals("[")) {+ return cont(state, new Expression(), new Expect("]"), new Afterprop());+ }+ return false;+ }++ }++ class GetterSetter extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type,+ String value) {+ if (!type.equals("variable"))+ return pass(state, new Afterprop());+ state.marked = "property";+ return cont(state, new Functiondef());+ }++ }++ class Afterprop extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type,+ String value) {+ if (type.equals(":"))+ return cont(state, new ExpressionNoComma());+ if (type.equals("("))+ return pass(state, new Functiondef());+ return false;+ }++ }++ class Commasep extends Combinator {++ final Combinator what;++ final String end;++ Commasep(Combinator what, String end) {+ this.what = what;+ this.end = end;+ }++ @Override+ boolean combine(StringStream stream, State state, String type,+ String value) {+ if (type.equals(end))+ return cont(state);+ return pass(state, what, new Combinator() {++ @Override+ boolean combine(StringStream stream, State state, String type,+ String value) {+ if (type.equals(",")) {+ JSLexical lex = state.lexical;+ if (lex.info.equals("call"))+ lex.pos = lex.pos + 1;+ return cont(state, what, this);+ }+ if (type.equals(end))+ return cont(state);+ return cont(state, new Expect(end));+ }++ });+ }++ }++ boolean contCommasep(State state, Combinator what, String end, String info, Combinator...combinators) {+ for (Combinator combinator: combinators)+ state.cc.push(combinator);+ return cont(state, new PushLex(end, info), new Commasep(what, end), new PopLex());+ }++ class Block extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type,+ String value) {+ if (type.equals("}"))+ return cont(state);+ return pass(state, new Statement(), new Block());+ }++ }++ class Maybetype extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type,+ String value) {+ if (isTS && type.equals(":"))+ return cont(state, new Typedef());+ return false;+ }++ }++ class Typedef extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type,+ String value) {+ if (type.equals("variable")) {+ state.marked = "variable-3";+ return cont(state);+ }+ return false;+ }++ }++ class Vardef extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type,+ String value) {+ return pass(state, new PatternCombinator(), new Maybetype(), new MaybeAssign(), new VardefCont());+ }++ }++ class PatternCombinator extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type,+ String value) {+ if (type.equals("variable")) {+ register(state, value);+ return cont(state);+ }+ if (type.equals("[")) return contCommasep(state, new PatternCombinator(), "]", "");+ if (type.equals("{")) return contCommasep(state, new Proppattern(), "}", "");+ return false;+ }++ }++ static Pattern PROP_PATTERN_PATTERN = Pattern.compile("^\\s*:");++ class Proppattern extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type,+ String value) {+ if (type.equals("variable") && stream.match(PROP_PATTERN_PATTERN, false).isEmpty()) {+ register(state, value);+ return cont(state, new MaybeAssign());+ }+ if (type.equals("variable")) state.marked = "property";+ return cont(state, new Expect(":"), new PatternCombinator(), new MaybeAssign());+ }++ }++ class MaybeAssign extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type,+ String value) {+ if (value.equals("=")) return cont(state, new ExpressionNoComma());+ return false;+ }++ }++ class VardefCont extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type,+ String value) {+ if (type.equals(",")) return cont(state, new Vardef());+ return false;+ }++ }++ class Maybeelse extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type,+ String value) {+ if (type.equals("keyword b") && value.equals("else"))+ return cont(state, new PushLex("form", "else"), new Statement(), new PopLex());+ return false;+ }++ }++ class Forspec extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type,+ String value) {+ if (type.equals("("))+ return cont(state, new PushLex(")", ""), new Forspec1(), new Expect(")"), new PopLex());+ return false;+ }++ }++ class Forspec1 extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type,+ String value) {+ if (type.equals("var"))+ return cont(state, new Vardef(), new Expect(";"), new Forspec2());+ if (type.equals(";"))+ return cont(state, new Forspec2());+ if (type.equals("variable"))+ return cont(state, new Formaybeinof());+ return pass(state, new Expression(), new Expect(";"), new Forspec2());+ }++ }++ class Forspec2 extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type,+ String value) {+ if (type.equals(";")) return cont(state, new Forspec3());+ if (value.equals("in") || value.equals("of")) {+ state.marked = "keyword";+ return cont(state, new Expression());+ }+ return pass(state, new Expression(), new Expect(";"), new Forspec3());+ }++ }++ class Forspec3 extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type,+ String value) {+ if (!type.equals(")"))+ cont(state, new Expression());+ return false;+ }++ }++ class Formaybeinof extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type,+ String value) {+ if (value.equals("in") || value.equals("of")) {+ state.marked = "keyword";+ return cont(state, new Expression());+ }+ return cont(state, new MaybeoperatorComma(), new Forspec2());+ }++ }++ class Functiondef extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type,+ String value) {+ if (value.equals("*")) {+ state.marked = "keyword";+ return cont(state, new Functiondef());+ }+ if (type.equals("variable")) {+ register(state, value);+ return cont(state, new Functiondef());+ }+ if (type.equals("(")) return cont(state, new PushContext(), new PushLex(")", ""), new Commasep(new Funarg(), ")"), new PopLex(), new Statement(), new PopContext());+ return false;+ }++ }++ class Funarg extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type,+ String value) {+ if (type.equals("spread"))+ return cont(state, new Funarg());+ return pass(state, new PatternCombinator(), new Maybetype());+ }++ }++ class ClassName extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type,+ String value) {+ if (type.equals("variable")) {+ register(state, value);+ return cont(state, new ClassNameAfter());+ }+ return false;+ }++ }++ class ClassNameAfter extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type,+ String value) {+ if (value.equals("extends"))+ return cont(state, new Expression(), new ClassNameAfter());+ if (type.equals("{"))+ return cont(state, new PushLex("}", ""), new ClassBody(), new PopLex());+ return false;+ }++ }++ class ClassBody extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type,+ String value) {+ if (type.equals("variable") || state.style.equals("keyword")) {+ state.marked = "property";+ if (value.equals("get") || value.equals("set"))+ return cont(state, new ClassGetterSetter(), new Functiondef(), new ClassBody());+ return cont(state, new Functiondef(), new ClassBody());+ }+ if (value.equals("*")) {+ state.marked = "keyword";+ return cont(state, new ClassBody());+ }+ if (type.equals(";")) return cont(state, new ClassBody());+ if (type.equals("}")) return cont(state);+ return false;+ }++ }++ class ClassGetterSetter extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type,+ String value) {+ if (!type.equals("variable"))+ return pass(state);+ state.marked = "property";+ return cont(state);+ }++ }++ class AfterModule extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type,+ String value) {+ if (type.equals("string")) return cont(state, new Statement());+ if (type.equals("variable")) { register(state, value); return cont(state, new MaybeFrom()); }+ return false;+ }++ }++ class AfterExport extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type,+ String value) {+ if (value.equals("*")) {+ state.marked = "keyword";+ return cont(state, new MaybeFrom(), new Expect(";"));+ }+ if (value.equals("default")) {+ state.marked = "keyword";+ return cont(state, new Expression(), new Expect(";"));+ }+ return pass(state, new Statement());+ }++ }++ class AfterImport extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type,+ String value) {+ if (type.equals("string")) return cont(state);+ return pass(state, new ImportSpec(), new MaybeFrom());+ }++ }++ class ImportSpec extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type,+ String value) {+ if (type.equals("{")) return contCommasep(state, new ImportSpec(), "}", "");+ if (type.equals("variable")) register(state, value);+ return cont(state);+ }++ }++ class MaybeFrom extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type,+ String value) {+ if (value.equals("from")) {+ state.marked = "keyword";+ return cont(state, new Expression());+ }+ return false;+ }++ }++ class ArrayLiteral extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type,+ String value) {+ if (type.equals("]")) return cont(state);+ return pass(state, new ExpressionNoComma(), new MaybeArrayComprehension());+ }++ }++ class MaybeArrayComprehension extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type,+ String value) {+ if (type.equals("for")) return pass(state, new Comprehension(), new Expect("]"));+ if (type.equals(",")) return cont(state, new Commasep(new MaybeexpressionNoComma(), "]"));+ return pass(state, new Commasep(new ExpressionNoComma(), "]"));+ }++ }++ class Comprehension extends Combinator {++ @Override+ boolean combine(StringStream stream, State state, String type,+ String value) {+ if (type.equals("for")) return cont(state, new Forspec(), new Comprehension());+ if (type.equals("if")) return cont(state, new Expression(), new Comprehension());+ return false;+ }++ }+++ @Override+ protected State startState() {+ State state = new State();+ state.tokenize = new TokenBase();+ state.lastType = "sof";+ state.cc = new Stack<>();+ state.lexical = new JSLexical(-indentUnit(), 0, "block", false, null, "");+ state.indented = 0;+ state.localVars = null;+ state.context = null;+ return state;+ }++ @Override+ protected String token(StringStream stream, State state) {+ if (stream.sol()) {+ if (state.lexical.align == null)+ state.lexical.align = false;+ state.indented = stream.indentation();+ findFatArrow(stream, state);+ }+ if (!(state.tokenize instanceof TokenComment) && stream.eatSpace()) return "";+ String style = state.tokenize.process(stream, state);+ if (state.type.equals("comment")) return style;+ state.lastType = state.type.equals("operator") && (state.content.equals("++") || state.content.equals("--")) ? "incdec" : state.type;+ return parseJS(state, style, state.type, state.content, stream);+ }++ protected abstract boolean jsonldMode();++ protected abstract boolean json();++ protected Var globalVars() {+ return null;+ }++ protected boolean jsonMode() {+ return jsonldMode() || json();+ }++ public static class JavaScript extends JavascriptTokenizer {++ public JavaScript() {+ super(false);+ }++ @Override+ public boolean accept(String fileName) {+ return acceptExtensions(fileName, "js");+ }++ @Override+ protected boolean jsonldMode() {+ return false;+ }++ @Override+ protected boolean json() {+ return false;+ }++ }++ public static class TypeScript extends JavascriptTokenizer {++ public TypeScript() {+ super(true);+ }++ @Override+ public boolean accept(String fileName) {+ return acceptExtensions(fileName, "ts");+ }++ @Override+ protected boolean jsonldMode() {+ return false;+ }++ @Override+ protected boolean json() {+ return false;+ }++ }++ public static class JSON extends JavascriptTokenizer {++ public JSON() {+ super(false);+ }++ @Override+ public boolean accept(String fileName) {+ return acceptExtensions(fileName, "json", "map");+ }++ @Override+ protected boolean jsonldMode() {+ return false;+ }++ @Override+ protected boolean json() {+ return true;+ }++ }++ public static class JSON_LD extends JavascriptTokenizer {++ public JSON_LD() {+ super(false);+ }++ @Override+ public boolean accept(String fileName) {+ return acceptExtensions(fileName, "jsonld");+ }++ @Override+ protected boolean jsonldMode() {+ return true;+ }++ @Override+ protected boolean json() {+ return false;+ }++ }++}diff --git a/commons.tokenizer/src/main/java/com/pmease/commons/tokenizer/StringStream.java b/commons.tokenizer/src/main/java/com/pmease/commons/tokenizer/StringStream.javaindex 3b1b556cc2..2a003123ed 100644--- a/commons.tokenizer/src/main/java/com/pmease/commons/tokenizer/StringStream.java+++ b/commons.tokenizer/src/main/java/com/pmease/commons/tokenizer/StringStream.java@@ -93,7 +93,7 @@ public class StringStream {++pos;return ch;} else {- return null;+ return "";}}@@ -105,7 +105,7 @@ public class StringStream {public boolean eatWhile(Pattern pattern) {int start = pos;- while (eat(pattern) != null);+ while (eat(pattern).length() != 0);return pos>start;}diff --git a/commons.tokenizer/src/test/java/commons/tokenizer/AbstractTokenizerTest.java b/commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/AbstractTokenizerTest.javasimilarity index 98%rename from commons.tokenizer/src/test/java/commons/tokenizer/AbstractTokenizerTest.javarename to commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/AbstractTokenizerTest.javaindex 88011e786b..ae21059678 100644--- a/commons.tokenizer/src/test/java/commons/tokenizer/AbstractTokenizerTest.java+++ b/commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/AbstractTokenizerTest.java@@ -1,4 +1,4 @@-package commons.tokenizer;+package com.pmease.commons.tokenizer;import java.io.ByteArrayInputStream;import java.io.IOException;diff --git a/commons.tokenizer/src/test/java/commons/tokenizer/ClikeTokenizerTest.java b/commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/ClikeTokenizerTest.javasimilarity index 74%rename from commons.tokenizer/src/test/java/commons/tokenizer/ClikeTokenizerTest.javarename to commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/ClikeTokenizerTest.javaindex 912bd688ac..f6b96c032a 100644--- a/commons.tokenizer/src/test/java/commons/tokenizer/ClikeTokenizerTest.java+++ b/commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/ClikeTokenizerTest.java@@ -1,4 +1,4 @@-package commons.tokenizer;+package com.pmease.commons.tokenizer;import org.junit.Test;@@ -7,32 +7,12 @@ import com.pmease.commons.tokenizer.ClikeTokenizer;public class ClikeTokenizerTest extends AbstractTokenizerTest {@Test- public void testC() {+ public void test() {verify(new ClikeTokenizer.C(), new String[]{"clike/clike.js"}, "testfiles/test.c");- }-- @Test- public void testCpp() {verify(new ClikeTokenizer.Cpp(), new String[]{"clike/clike.js"}, "testfiles/test.cpp");- }-- @Test- public void testJava() {verify(new ClikeTokenizer.Java(), new String[]{"clike/clike.js"}, "testfiles/test.java.txt");- }-- @Test- public void testCSharp() {verify(new ClikeTokenizer.CSharp(), new String[]{"clike/clike.js"}, "testfiles/test.cs");- }-- @Test- public void testScala() {verify(new ClikeTokenizer.Scala(), new String[]{"clike/clike.js"}, "testfiles/test.scala");- }-- @Test- public void testObjectiveC() {verify(new ClikeTokenizer.ObjectiveC(), new String[]{"clike/clike.js"}, "testfiles/test.m");}diff --git a/commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/CssTokenizerTest.java b/commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/CssTokenizerTest.javanew file mode 100644index 0000000000..a341b2340c--- /dev/null+++ b/commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/CssTokenizerTest.java@@ -0,0 +1,14 @@+package com.pmease.commons.tokenizer;++import org.junit.Test;++public class CssTokenizerTest extends AbstractTokenizerTest {++ @Test+ public void test() {+ verify(new CssTokenizer.Css(), new String[]{"css/css.js"}, "testfiles/test.css");+ verify(new CssTokenizer.SCSS(), new String[]{"css/css.js"}, "testfiles/test.scss");+ verify(new CssTokenizer.LESS(), new String[]{"css/css.js"}, "testfiles/test.less");+ }++}diff --git a/commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/JavascriptTokenzierTest.java b/commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/JavascriptTokenzierTest.javanew file mode 100644index 0000000000..dce3256a94--- /dev/null+++ b/commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/JavascriptTokenzierTest.java@@ -0,0 +1,15 @@+package com.pmease.commons.tokenizer;++import org.junit.Test;++public class JavascriptTokenzierTest extends AbstractTokenizerTest {++ @Test+ public void test() {+ verify(new JavascriptTokenizer.JavaScript(), new String[]{"javascript/javascript.js"}, "testfiles/test.js");+ verify(new JavascriptTokenizer.JSON(), new String[]{"javascript/javascript.js"}, "testfiles/test.json");+ verify(new JavascriptTokenizer.JSON_LD(), new String[]{"javascript/javascript.js"}, "testfiles/test.jsonld");+ verify(new JavascriptTokenizer.TypeScript(), new String[]{"javascript/javascript.js"}, "testfiles/test.ts");+ }++}diff --git a/commons.tokenizer/src/test/java/commons/tokenizer/testfiles/test.c b/commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/testfiles/test.csimilarity index 100%rename from commons.tokenizer/src/test/java/commons/tokenizer/testfiles/test.crename to commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/testfiles/test.cdiff --git a/commons.tokenizer/src/test/java/commons/tokenizer/testfiles/test.cpp b/commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/testfiles/test.cppsimilarity index 100%rename from commons.tokenizer/src/test/java/commons/tokenizer/testfiles/test.cpprename to commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/testfiles/test.cppdiff --git a/commons.tokenizer/src/test/java/commons/tokenizer/testfiles/test.cs b/commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/testfiles/test.cssimilarity index 100%rename from commons.tokenizer/src/test/java/commons/tokenizer/testfiles/test.csrename to commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/testfiles/test.csdiff --git a/commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/testfiles/test.css b/commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/testfiles/test.cssnew file mode 100644index 0000000000..212f09cb56--- /dev/null+++ b/commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/testfiles/test.css@@ -0,0 +1,33 @@+/* Some example CSS */++@import url("something.css");++body {+ margin: 0;+ padding: 3em 6em;+ font-family: tahoma, arial, sans-serif;+ color: #000;+}++#navigation a {+ font-weight: bold;+ text-decoration: none !important;+}++h1 {+ font-size: 2.5em;+}++h2 {+ font-size: 1.7em;+}++h1:before, h2:before {+ content: "::";+}++code {+ font-family: courier, monospace;+ font-size: 80%;+ color: #418A8A;+}diff --git a/commons.tokenizer/src/test/java/commons/tokenizer/testfiles/test.java.txt b/commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/testfiles/test.java.txtsimilarity index 100%rename from commons.tokenizer/src/test/java/commons/tokenizer/testfiles/test.java.txtrename to commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/testfiles/test.java.txtdiff --git a/commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/testfiles/test.js b/commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/testfiles/test.jsnew file mode 100644index 0000000000..91b0e89a06--- /dev/null+++ b/commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/testfiles/test.js@@ -0,0 +1,200 @@+// CodeMirror, copyright (c) by Marijn Haverbeke and others+// Distributed under an MIT license: http://codemirror.net/LICENSE++(function() {+ var mode = CodeMirror.getMode({indentUnit: 2}, "javascript");+ function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); }++ MT("locals",+ "[keyword function] [variable foo]([def a], [def b]) { [keyword var] [def c] [operator =] [number 10]; [keyword return] [variable-2 a] [operator +] [variable-2 c] [operator +] [variable d]; }");++ MT("comma-and-binop",+ "[keyword function](){ [keyword var] [def x] [operator =] [number 1] [operator +] [number 2], [def y]; }");++ MT("destructuring",+ "([keyword function]([def a], [[[def b], [def c] ]]) {",+ " [keyword let] {[def d], [property foo]: [def c][operator =][number 10], [def x]} [operator =] [variable foo]([variable-2 a]);",+ " [[[variable-2 c], [variable y] ]] [operator =] [variable-2 c];",+ "})();");++ MT("class_body",+ "[keyword class] [variable Foo] {",+ " [property constructor]() {}",+ " [property sayName]() {",+ " [keyword return] [string-2 `foo${][variable foo][string-2 }oo`];",+ " }",+ "}");++ MT("class",+ "[keyword class] [variable Point] [keyword extends] [variable SuperThing] {",+ " [property get] [property prop]() { [keyword return] [number 24]; }",+ " [property constructor]([def x], [def y]) {",+ " [keyword super]([string 'something']);",+ " [keyword this].[property x] [operator =] [variable-2 x];",+ " }",+ "}");++ MT("module",+ "[keyword module] [string 'foo'] {",+ " [keyword export] [keyword let] [def x] [operator =] [number 42];",+ " [keyword export] [keyword *] [keyword from] [string 'somewhere'];",+ "}");++ MT("import",+ "[keyword function] [variable foo]() {",+ " [keyword import] [def $] [keyword from] [string 'jquery'];",+ " [keyword module] [def crypto] [keyword from] [string 'crypto'];",+ " [keyword import] { [def encrypt], [def decrypt] } [keyword from] [string 'crypto'];",+ "}");++ MT("const",+ "[keyword function] [variable f]() {",+ " [keyword const] [[ [def a], [def b] ]] [operator =] [[ [number 1], [number 2] ]];",+ "}");++ MT("for/of",+ "[keyword for]([keyword let] [variable of] [keyword of] [variable something]) {}");++ MT("generator",+ "[keyword function*] [variable repeat]([def n]) {",+ " [keyword for]([keyword var] [def i] [operator =] [number 0]; [variable-2 i] [operator <] [variable-2 n]; [operator ++][variable-2 i])",+ " [keyword yield] [variable-2 i];",+ "}");++ MT("quotedStringAddition",+ "[keyword let] [variable f] [operator =] [variable a] [operator +] [string 'fatarrow'] [operator +] [variable c];");++ MT("quotedFatArrow",+ "[keyword let] [variable f] [operator =] [variable a] [operator +] [string '=>'] [operator +] [variable c];");++ MT("fatArrow",+ "[variable array].[property filter]([def a] [operator =>] [variable-2 a] [operator +] [number 1]);",+ "[variable a];", // No longer in scope+ "[keyword let] [variable f] [operator =] ([[ [def a], [def b] ]], [def c]) [operator =>] [variable-2 a] [operator +] [variable-2 c];",+ "[variable c];");++ MT("spread",+ "[keyword function] [variable f]([def a], [meta ...][def b]) {",+ " [variable something]([variable-2 a], [meta ...][variable-2 b]);",+ "}");++ MT("comprehension",+ "[keyword function] [variable f]() {",+ " [[([variable x] [operator +] [number 1]) [keyword for] ([keyword var] [def x] [keyword in] [variable y]) [keyword if] [variable pred]([variable-2 x]) ]];",+ " ([variable u] [keyword for] ([keyword var] [def u] [keyword of] [variable generateValues]()) [keyword if] ([variable-2 u].[property color] [operator ===] [string 'blue']));",+ "}");++ MT("quasi",+ "[variable re][string-2 `fofdlakj${][variable x] [operator +] ([variable re][string-2 `foo`]) [operator +] [number 1][string-2 }fdsa`] [operator +] [number 2]");++ MT("quasi_no_function",+ "[variable x] [operator =] [string-2 `fofdlakj${][variable x] [operator +] [string-2 `foo`] [operator +] [number 1][string-2 }fdsa`] [operator +] [number 2]");++ MT("indent_statement",+ "[keyword var] [variable x] [operator =] [number 10]",+ "[variable x] [operator +=] [variable y] [operator +]",+ " [atom Infinity]",+ "[keyword debugger];");++ MT("indent_if",+ "[keyword if] ([number 1])",+ " [keyword break];",+ "[keyword else] [keyword if] ([number 2])",+ " [keyword continue];",+ "[keyword else]",+ " [number 10];",+ "[keyword if] ([number 1]) {",+ " [keyword break];",+ "} [keyword else] [keyword if] ([number 2]) {",+ " [keyword continue];",+ "} [keyword else] {",+ " [number 10];",+ "}");++ MT("indent_for",+ "[keyword for] ([keyword var] [variable i] [operator =] [number 0];",+ " [variable i] [operator <] [number 100];",+ " [variable i][operator ++])",+ " [variable doSomething]([variable i]);",+ "[keyword debugger];");++ MT("indent_c_style",+ "[keyword function] [variable foo]()",+ "{",+ " [keyword debugger];",+ "}");++ MT("indent_else",+ "[keyword for] (;;)",+ " [keyword if] ([variable foo])",+ " [keyword if] ([variable bar])",+ " [number 1];",+ " [keyword else]",+ " [number 2];",+ " [keyword else]",+ " [number 3];");++ MT("indent_funarg",+ "[variable foo]([number 10000],",+ " [keyword function]([def a]) {",+ " [keyword debugger];",+ "};");++ MT("indent_below_if",+ "[keyword for] (;;)",+ " [keyword if] ([variable foo])",+ " [number 1];",+ "[number 2];");++ MT("multilinestring",+ "[keyword var] [variable x] [operator =] [string 'foo\\]",+ "[string bar'];");++ MT("scary_regexp",+ "[string-2 /foo[[/]]bar/];");++ MT("indent_strange_array",+ "[keyword var] [variable x] [operator =] [[",+ " [number 1],,",+ " [number 2],",+ "]];",+ "[number 10];");++ var jsonld_mode = CodeMirror.getMode(+ {indentUnit: 2},+ {name: "javascript", jsonld: true}+ );+ function LD(name) {+ test.mode(name, jsonld_mode, Array.prototype.slice.call(arguments, 1));+ }++ LD("json_ld_keywords",+ '{',+ ' [meta "@context"]: {',+ ' [meta "@base"]: [string "http://example.com"],',+ ' [meta "@vocab"]: [string "http://xmlns.com/foaf/0.1/"],',+ ' [property "likesFlavor"]: {',+ ' [meta "@container"]: [meta "@list"]',+ ' [meta "@reverse"]: [string "@beFavoriteOf"]',+ ' },',+ ' [property "nick"]: { [meta "@container"]: [meta "@set"] },',+ ' [property "nick"]: { [meta "@container"]: [meta "@index"] }',+ ' },',+ ' [meta "@graph"]: [[ {',+ ' [meta "@id"]: [string "http://dbpedia.org/resource/John_Lennon"],',+ ' [property "name"]: [string "John Lennon"],',+ ' [property "modified"]: {',+ ' [meta "@value"]: [string "2010-05-29T14:17:39+02:00"],',+ ' [meta "@type"]: [string "http://www.w3.org/2001/XMLSchema#dateTime"]',+ ' }',+ ' } ]]',+ '}');++ LD("json_ld_fake",+ '{',+ ' [property "@fake"]: [string "@fake"],',+ ' [property "@contextual"]: [string "@identifier"],',+ ' [property "[email protected]"]: [string "@graphical"],',+ ' [property "@ID"]: [string "@@ID"]',+ '}');+})();diff --git a/commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/testfiles/test.json b/commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/testfiles/test.jsonnew file mode 100644index 0000000000..b07325f5aa--- /dev/null+++ b/commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/testfiles/test.json@@ -0,0 +1,98 @@+{+ "100": {+ "aliases": "",+ "keywords": "hundred points symbol numbers perfect score 100 percent a plus perfect school quiz score test exam",+ "shortname": ":100:",+ "unicode": "1F4AF"+ },+ "1234": {+ "aliases": "",+ "keywords": "input symbol for numbers blue-square numbers",+ "shortname": ":1234:",+ "unicode": "1F522"+ },+ "8ball": {+ "aliases": "",+ "keywords": "billiards pool billiards eight ball pool pocket ball cue",+ "shortname": ":8ball:",+ "unicode": "1F3B1"+ },+ "a": {+ "aliases": "",+ "keywords": "negative squared latin capital letter a alphabet letter red-square",+ "shortname": ":a:",+ "unicode": "1F170"+ },+ "ab": {+ "aliases": "",+ "keywords": "negative squared ab alphabet red-square",+ "shortname": ":ab:",+ "unicode": "1F18E"+ },+ "abc": {+ "aliases": "",+ "keywords": "input symbol for latin letters alphabet blue-square",+ "shortname": ":abc:",+ "unicode": "1F524"+ },+ "abcd": {+ "aliases": "",+ "keywords": "input symbol for latin small letters alphabet blue-square",+ "shortname": ":abcd:",+ "unicode": "1F521"+ },+ "ac": {+ "aliases": "",+ "keywords": "ascension country nation",+ "shortname": ":ac:",+ "unicode": "1F1E6-1F1E8"+ },+ "accept": {+ "aliases": "",+ "keywords": "circled ideograph accept agree chinese good kanji ok yes",+ "shortname": ":accept:",+ "unicode": "1F251"+ },+ "ad": {+ "aliases": "",+ "keywords": "andorra country nation",+ "shortname": ":ad:",+ "unicode": "1F1E6-1F1E9"+ },+ "ae": {+ "aliases": "",+ "keywords": "the united arab emirates country nation",+ "shortname": ":ae:",+ "unicode": "1F1E6-1F1EA"+ },+ "aerial_tramway": {+ "aliases": "",+ "keywords": "aerial tramway transportation vehicle aerial tram tramway cable transport",+ "shortname": ":aerial_tramway:",+ "unicode": "1F6A1"+ },+ "af": {+ "aliases": "",+ "keywords": "afghanistan country nation afghanestan",+ "shortname": ":af:",+ "unicode": "1F1E6-1F1EB"+ },+ "ag": {+ "aliases": "",+ "keywords": "antigua and barbuda country nation",+ "shortname": ":ag:",+ "unicode": "1F1E6-1F1EC"+ },+ "ai": {+ "aliases": "",+ "keywords": "anguilla country nation",+ "shortname": ":ai:",+ "unicode": "1F1E6-1F1EE"+ },+ "airplane": {+ "aliases": "",+ "keywords": "airplane flight transportation vehicle airplane plane airport travel airlines fly jet jumbo boeing airbus",+ "shortname": ":airplane:",+ "unicode": "2708"+ }+}diff --git a/commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/testfiles/test.jsonld b/commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/testfiles/test.jsonldnew file mode 100644index 0000000000..a6fa380690--- /dev/null+++ b/commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/testfiles/test.jsonld@@ -0,0 +1,27 @@+{+ "@context": {+ "name": "http://schema.org/name",+ "description": "http://schema.org/description",+ "image": {+ "@id": "http://schema.org/image",+ "@type": "@id"+ },+ "geo": "http://schema.org/geo",+ "latitude": {+ "@id": "http://schema.org/latitude",+ "@type": "xsd:float"+ },+ "longitude": {+ "@id": "http://schema.org/longitude",+ "@type": "xsd:float"+ },+ "xsd": "http://www.w3.org/2001/XMLSchema#"+ },+ "name": "The Empire State Building",+ "description": "The Empire State Building is a 102-story landmark in New York City.",+ "image": "http://www.civil.usherbrooke.ca/cours/gci215a/empire-state-building.jpg",+ "geo": {+ "latitude": "40.75",+ "longitude": "73.98"+ }+}diff --git a/commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/testfiles/test.less b/commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/testfiles/test.lessnew file mode 100644index 0000000000..3d8ba0401d--- /dev/null+++ b/commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/testfiles/test.less@@ -0,0 +1,112 @@+@media screen and (device-aspect-ratio: 16/9) { … }+@media screen and (device-aspect-ratio: 1280/720) { … }+@media screen and (device-aspect-ratio: 2560/1440) { … }++html:lang(fr-be)++tr:nth-child(2n+1) /* represents every odd row of an HTML table */++img:nth-of-type(2n+1) { float: right; }+img:nth-of-type(2n) { float: left; }++body > h2:not(:first-of-type):not(:last-of-type)++html|*:not(:link):not(:visited)+*|*:not(:hover)+p::first-line { text-transform: uppercase }++@namespace foo url(http://www.example.com);+foo|h1 { color: blue } /* first rule */++span[hello="Ocean"][goodbye="Land"]++E[foo]{+ padding:65px;+}++input[type="search"]::-webkit-search-decoration,+input[type="search"]::-webkit-search-cancel-button {+ -webkit-appearance: none; // Inner-padding issues in Chrome OSX, Safari 5+}+button::-moz-focus-inner,+input::-moz-focus-inner { // Inner padding and border oddities in FF3/4+ padding: 0;+ border: 0;+}+.btn {+ // reset here as of 2.0.3 due to Recess property order+ border-color: #ccc;+ border-color: rgba(0,0,0,.1) rgba(0,0,0,.1) rgba(0,0,0,.25);+}+fieldset span button, fieldset span input[type="file"] {+ font-size:12px;+ font-family:Arial, Helvetica, sans-serif;+}++.rounded-corners (@radius: 5px) {+ border-radius: @radius;+ -webkit-border-radius: @radius;+ -moz-border-radius: @radius;+}++@import url("something.css");++@light-blue: hsl(190, 50%, 65%);++#menu {+ position: absolute;+ width: 100%;+ z-index: 3;+ clear: both;+ display: block;+ background-color: @blue;+ height: 42px;+ border-top: 2px solid lighten(@alpha-blue, 20%);+ border-bottom: 2px solid darken(@alpha-blue, 25%);+ .box-shadow(0, 1px, 8px, 0.6);+ -moz-box-shadow: 0 0 0 #000; // Because firefox sucks.++ &.docked {+ background-color: hsla(210, 60%, 40%, 0.4);+ }+ &:hover {+ background-color: @blue;+ }++ #dropdown {+ margin: 0 0 0 117px;+ padding: 0;+ padding-top: 5px;+ display: none;+ width: 190px;+ border-top: 2px solid @medium;+ color: @highlight;+ border: 2px solid darken(@medium, 25%);+ border-left-color: darken(@medium, 15%);+ border-right-color: darken(@medium, 15%);+ border-top-width: 0;+ background-color: darken(@medium, 10%);+ ul {+ padding: 0px;+ }+ li {+ font-size: 14px;+ display: block;+ text-align: left;+ padding: 0;+ border: 0;+ a {+ display: block;+ padding: 0px 15px;+ text-decoration: none;+ color: white;+ &:hover {+ background-color: darken(@medium, 15%);+ text-decoration: none;+ }+ }+ }+ .border-radius(5px, bottom);+ .box-shadow(0, 6px, 8px, 0.5);+ }+}diff --git a/commons.tokenizer/src/test/java/commons/tokenizer/testfiles/test.m b/commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/testfiles/test.msimilarity index 100%rename from commons.tokenizer/src/test/java/commons/tokenizer/testfiles/test.mrename to commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/testfiles/test.mdiff --git a/commons.tokenizer/src/test/java/commons/tokenizer/testfiles/test.scala b/commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/testfiles/test.scalasimilarity index 100%rename from commons.tokenizer/src/test/java/commons/tokenizer/testfiles/test.scalarename to commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/testfiles/test.scaladiff --git a/commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/testfiles/test.scss b/commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/testfiles/test.scssnew file mode 100644index 0000000000..e6aa2a9e61--- /dev/null+++ b/commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/testfiles/test.scss@@ -0,0 +1,116 @@+/* Some example SCSS */++@import "compass/css3";+$variable: #333;++$blue: #3bbfce;+$margin: 16px;++.content-navigation {+ #nested {+ background-color: black;+ }+ border-color: $blue;+ color:+ darken($blue, 9%);+}++.border {+ padding: $margin / 2;+ margin: $margin / 2;+ border-color: $blue;+}++@mixin table-base {+ th {+ text-align: center;+ font-weight: bold;+ }+ td, th {padding: 2px}+}++table.hl {+ margin: 2em 0;+ td.ln {+ text-align: right;+ }+}++li {+ font: {+ family: serif;+ weight: bold;+ size: 1.2em;+ }+}++@mixin left($dist) {+ float: left;+ margin-left: $dist;+}++#data {+ @include left(10px);+ @include table-base;+}++.source {+ @include flow-into(target);+ border: 10px solid green;+ margin: 20px;+ width: 200px; }++.new-container {+ @include flow-from(target);+ border: 10px solid red;+ margin: 20px;+ width: 200px; }++body {+ margin: 0;+ padding: 3em 6em;+ font-family: tahoma, arial, sans-serif;+ color: #000;+}++@mixin yellow() {+ background: yellow;+}++.big {+ font-size: 14px;+}++.nested {+ @include border-radius(3px);+ @extend .big;+ p {+ background: whitesmoke;+ a {+ color: red;+ }+ }+}++#navigation a {+ font-weight: bold;+ text-decoration: none !important;+}++h1 {+ font-size: 2.5em;+}++h2 {+ font-size: 1.7em;+}++h1:before, h2:before {+ content: "::";+}++code {+ font-family: courier, monospace;+ font-size: 80%;+ color: #418A8A;+}diff --git a/commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/testfiles/test.ts b/commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/testfiles/test.tsnew file mode 100644index 0000000000..558decd5d5--- /dev/null+++ b/commons.tokenizer/src/test/java/com/pmease/commons/tokenizer/testfiles/test.ts@@ -0,0 +1,20 @@+class Greeter {+ greeting: string;+ constructor (message: string) {+ this.greeting = message;+ }+ greet() {+ return "Hello, " + this.greeting;+ }+}++var greeter = new Greeter("world");++var button = document.createElement('button')+button.innerText = "Say Hello"+button.onclick = function() {+ alert(greeter.greet())+}++document.body.appendChild(button)+diff --git a/gitplex.product/src/test/java/gitplex/product/Test.java b/gitplex.product/src/test/java/gitplex/product/Test.javaindex dd980987c2..ddad796f59 100644--- a/gitplex.product/src/test/java/gitplex/product/Test.java+++ b/gitplex.product/src/test/java/gitplex/product/Test.java@@ -1,15 +1,23 @@package gitplex.product;+import java.io.File;import java.io.IOException;-import java.util.regex.Pattern;+import java.util.List;import com.pmease.commons.git.AbstractGitTest;+import com.pmease.commons.tokenizer.JavascriptTokenizer;+import com.pmease.commons.util.FileUtils;public class Test extends AbstractGitTest {@org.junit.Testpublic void test() throws IOException {- System.out.println(Pattern.compile("[^\\s\\w]").matcher("hello+world-+just").replaceAll("\\\\$0"));+ List<String> lines = FileUtils.readLines(new File("W:\\commons\\commons.tokenizer\\src\\test\\java\\com\\pmease\\commons\\tokenizer\\testfiles\\test.js"));+ for (int i=1; i<=100; i++) {+ long time = System.currentTimeMillis();+ new JavascriptTokenizer.JavaScript().tokenize(lines);+ System.out.println(System.currentTimeMillis()-time);+ }}}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/RunModePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/RunModePage.javaindex a441968a53..87a74afb97 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/RunModePage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/RunModePage.java@@ -27,11 +27,11 @@ public class RunModePage extends CommonPage {response.render(JavaScriptHeaderItem.forReference(new WebjarsJavaScriptResourceReference("codemirror/current/mode/meta.js")));response.render(JavaScriptHeaderItem.forReference(- new WebjarsJavaScriptResourceReference("codemirror/current/mode/clike/clike.js")));+ new WebjarsJavaScriptResourceReference("codemirror/current/mode/javascript/javascript.js")));response.render(CssHeaderItem.forReference(new WebjarsCssResourceReference("codemirror/current/lib/codemirror.css")));- File file = new File("W:\\commons\\commons.tokenizer\\src\\test\\java\\commons\\tokenizer\\testfiles\\test.scala");+ File file = new File("W:\\commons\\commons.tokenizer\\src\\test\\java\\com\\pmease\\commons\\tokenizer\\testfiles\\test.json");try {response.render(OnDomReadyHeaderItem.forScript(String.format(