diff --git a/IDE/src/main/java/org/sikuli/ide/EditorPane.java b/IDE/src/main/java/org/sikuli/ide/EditorPane.java index 945c212c3..0efb96401 100755 --- a/IDE/src/main/java/org/sikuli/ide/EditorPane.java +++ b/IDE/src/main/java/org/sikuli/ide/EditorPane.java @@ -8,10 +8,6 @@ import org.sikuli.idesupport.IDESupport; import org.sikuli.idesupport.IIDESupport; import org.sikuli.idesupport.IIndentationLogic; -import org.sikuli.idesupport.syntaxhighlight.ResolutionException; -import org.sikuli.idesupport.syntaxhighlight.grammar.Lexer; -import org.sikuli.idesupport.syntaxhighlight.grammar.Token; -import org.sikuli.idesupport.syntaxhighlight.grammar.TokenType; import org.sikuli.script.Image; import org.sikuli.script.ImagePath; import org.sikuli.script.Location; @@ -914,30 +910,12 @@ public void reparseOnRenameImage(String oldName, String newName, boolean fileOve if (fileOverWritten) { Image.unCache(newName); } - Map> images = parseforImages(); - oldName = new File(oldName).getName(); - List poss = images.get(oldName); - if (images.containsKey(oldName) && poss.size() > 0) { - Collections.sort(poss, new Comparator() { - @Override - public int compare(Integer o1, Integer o2) { - if (o1 > o2) return -1; - return 1; - } - }); - reparseRenameImages(poss, oldName, new File(newName).getName()); - } - doReparse(); - } - private boolean reparseRenameImages(List poss, String oldName, String newName) { - StringBuilder text = new StringBuilder(getText()); - int lenOld = oldName.length(); - for (int pos : poss) { - text.replace(pos - lenOld, pos, newName); - } - setText(text.toString()); - return true; + String text = getText(); + Pattern oldPattern = Pattern.compile("[\"']" + Pattern.quote(oldName) + "[\"']"); + text = oldPattern.matcher(text).replaceAll(newName); + setText(text); + doReparse(); } public void doReparse() { @@ -1094,165 +1072,16 @@ public String getPatternString(String ifn, float sim, Location off, Image img, f return codeGenerator.pattern(pattern, mask); } - //TODO move Lexer stuff to its own package - private Lexer getLexer() { -//TODO this only works for cleanbundle to find the image strings - String scriptType = "python"; - if (null != lexers.get(scriptType)) { - return lexers.get(scriptType); - } - try { - Lexer lexer = Lexer.getByName(scriptType); - lexers.put(scriptType, lexer); - return lexer; - } catch (ResolutionException ex) { - return null; - } - } - - private static final Map lexers = new HashMap(); - - private Map> parseforImages() { - String pbundle = FileManager.slashify(editorPaneImageFolder.getAbsolutePath(), false); - log(3, "parseforImages: in %s", pbundle); - String scriptText = getText(); - Lexer lexer = getLexer(); - Map> images = new HashMap>(); - lineNumber = 0; - parseforImagesWalk(pbundle, lexer, scriptText, 0, images); -// images = parseForStrings(scriptText); - log(3, "parseforImages finished"); - return images; - } - - int lineNumber = 0; - String uncompleteStringError = "uncomplete_string_error"; - - private void parseforImagesWalk(String pbundle, Lexer lexer, - String text, int pos, Map> images) { - //log(3, "parseforImagesWalk"); - Iterable tokens = lexer.getTokens(text); - boolean inString = false; - String current; - String innerText; - String[] possibleImage = new String[]{""}; - String[] stringType = new String[]{""}; - for (Token t : tokens) { - current = t.getValue(); - if (current.endsWith("\n")) { - lineNumber++; - if (inString) { - SX.popError( - String.format("Orphan string delimiter (\" or ')\n" + - "in line %d\n" + - "No images will be deleted!\n" + - "Correct the problem before next save!", lineNumber), - "Delete images on save"); - log(-1, "DeleteImagesOnSave: No images deleted, caused by orphan string delimiter (\" or ') in line %d", lineNumber); - images.clear(); - images.put(uncompleteStringError, null); - break; - } - } - if (t.getType() == TokenType.Comment) { - //log(3, "parseforImagesWalk::Comment"); - innerText = t.getValue().substring(1); - parseforImagesWalk(pbundle, lexer, innerText, t.getPos() + 1, images); - continue; - } - if (t.getType() == TokenType.String_Doc) { - //log(3, "parseforImagesWalk::String_Doc"); - innerText = t.getValue().substring(3, t.getValue().length() - 3); - parseforImagesWalk(pbundle, lexer, innerText, t.getPos() + 3, images); - continue; - } - if (!inString) { - inString = parseforImagesGetName(current, inString, possibleImage, stringType); - continue; - } - if (!parseforImagesGetName(current, inString, possibleImage, stringType)) { - inString = false; - parseforImagesCollect(pbundle, possibleImage[0], pos + t.getPos(), images); - continue; - } - } - } - - //TODO find image names in script: implement with regex - Pattern aString1 = Pattern.compile(".*?'(.*?)'"); - Pattern aString2 = Pattern.compile(".*?\"(.*?)\""); - String stringDelimiter = ".*['\"].*"; - - private Map> parseForStrings(String text) { - Map> images = new HashMap>(); - String[] lines = text.split("\n"); - int nLine = 0; - for (String line : lines) { - if (line.matches(".*['\"].*")) { - nLine++; - if (line.matches(".*(\"\"\"|''').*")) continue; - String tail = line; - while (true) { - Matcher matcher = aString1.matcher(tail); - if (matcher.find()) { - String possibleImage = (matcher.group(1) == null ? matcher.group(2) : matcher.group(1)).trim(); - if (!possibleImage.isEmpty()) { - Debug.logp("%d: %s (%s)", nLine, tail, possibleImage); - } - tail = tail.substring(matcher.end()); - if (tail.isEmpty()) { - break; - } - } else { - if (tail.matches(stringDelimiter)) { - Debug.logp("problem: %d: %s", nLine, tail); - } - break; - } - } - } - } - return images; - } - - private boolean parseforImagesGetName(String current, boolean inString, - String[] possibleImage, String[] stringType) { - //log(3, "parseforImagesGetName (inString: %s) %s", inString, current); - if (!inString) { - if (!current.isEmpty() && (current.contains("\"") || current.contains("'"))) { - possibleImage[0] = ""; - stringType[0] = current.substring(current.length() - 1, current.length()); - return true; - } - } - if (!current.isEmpty() && "'\"".contains(current) && stringType[0].equals(current)) { - return false; - } - if (inString) { - possibleImage[0] += current; - } - return inString; - } - - private void parseforImagesCollect(String pbundle, String img, int pos, Map> images) { - String fimg; - //log(3, "parseforImagesCollect"); - if (img.endsWith(".png") || img.endsWith(".jpg") || img.endsWith(".jpeg")) { - fimg = FileManager.slashify(img, false); - if (fimg.contains("/")) { - if (!fimg.contains(pbundle)) { - return; - } - img = new File(fimg).getName(); - } - if (images.containsKey(img)) { - images.get(img).add(pos); - } else { - List poss = new ArrayList(); - poss.add(pos); - images.put(img, poss); - } + private Set parseforImages() throws IIDESupport.IncompleteStringException { + if (editorPaneIDESupport != null) { + String pbundle = FileManager.slashify(editorPaneImageFolder.getAbsolutePath(), false); + log(3, "parseforImages: in %s", pbundle); + String scriptText = getText(); + Set images = editorPaneIDESupport.findImageStrings(scriptText); + log(3, "parseforImages finished"); + return images; } + return null; } public boolean showThumbs; @@ -1519,12 +1348,21 @@ private void convertSrcToHtml(String bundle) { private void cleanBundle() { log(3, "cleanBundle"); - Set foundImages = parseforImages().keySet(); - if (foundImages.contains(uncompleteStringError)) { - log(-1, "cleanBundle aborted (%s)", uncompleteStringError); - } else { - FileManager.deleteNotUsedImages(getBundlePath(), foundImages); - log(lvl, "cleanBundle finished"); + try { + Set foundImages = parseforImages(); + if(foundImages != null) { + FileManager.deleteNotUsedImages(getBundlePath(), foundImages); + log(lvl, "cleanBundle finished"); + } + } catch(IIDESupport.IncompleteStringException e) { + int lineNumber = e.getLineNumber(); + SX.popError( + String.format("Missing string delimiter (\" or ')\n" + + "in line %d\n" + + "No images will be deleted!\n" + + "Correct the problem before next save!", lineNumber), + "Delete images on save"); + log(-1, "DeleteImagesOnSave: No images deleted, caused by orphan string delimiter (\" or ') in line %d", lineNumber); } } diff --git a/IDE/src/main/java/org/sikuli/idesupport/IIDESupport.java b/IDE/src/main/java/org/sikuli/idesupport/IIDESupport.java index 2a6c44703..7e6c10759 100644 --- a/IDE/src/main/java/org/sikuli/idesupport/IIDESupport.java +++ b/IDE/src/main/java/org/sikuli/idesupport/IIDESupport.java @@ -4,11 +4,27 @@ package org.sikuli.idesupport; +import java.util.Set; + import org.sikuli.idesupport.IIndentationLogic; import org.sikuli.script.support.generators.ICodeGenerator; public interface IIDESupport { + @SuppressWarnings("serial") + public static class IncompleteStringException extends Exception { + int lineNumber; + + public IncompleteStringException(int lineNumber) { + super(); + this.lineNumber = lineNumber; + } + + public int getLineNumber() { + return lineNumber; + } + } + String[] getTypes(); IIndentationLogic getIndentationLogic(); @@ -17,4 +33,6 @@ public interface IIDESupport { public ICodeGenerator getCodeGenerator(); + Set findImageStrings(String text) throws IncompleteStringException; + } diff --git a/IDE/src/main/java/org/sikuli/idesupport/JRubyIDESupport.java b/IDE/src/main/java/org/sikuli/idesupport/JRubyIDESupport.java index 64c1ea0f1..fed9f3f5f 100644 --- a/IDE/src/main/java/org/sikuli/idesupport/JRubyIDESupport.java +++ b/IDE/src/main/java/org/sikuli/idesupport/JRubyIDESupport.java @@ -3,6 +3,8 @@ */ package org.sikuli.idesupport; +import java.util.Set; + import org.sikuli.script.runners.JRubyRunner; import org.sikuli.script.support.generators.ICodeGenerator; import org.sikuli.script.support.generators.JythonCodeGenerator; @@ -33,4 +35,9 @@ public ICodeGenerator getCodeGenerator() { return new JythonCodeGenerator(); } + @Override + public Set findImageStrings(String text) throws IncompleteStringException { + return new JythonIDESupport().findImageStrings(text); + } + } diff --git a/IDE/src/main/java/org/sikuli/idesupport/JythonIDESupport.java b/IDE/src/main/java/org/sikuli/idesupport/JythonIDESupport.java index 78dfd650e..f66b33c5c 100644 --- a/IDE/src/main/java/org/sikuli/idesupport/JythonIDESupport.java +++ b/IDE/src/main/java/org/sikuli/idesupport/JythonIDESupport.java @@ -258,5 +258,43 @@ private List getLines(String script) { @Override public ICodeGenerator getCodeGenerator() { return new JythonCodeGenerator(); + } + + private static final Pattern IMAGE_STRING_PATTERN = Pattern.compile("[\"']?([^(/\"']+?\\.png)[\"']?", Pattern.CASE_INSENSITIVE); + + /* + * This method is also used by JRubyIDESupport. When modified it must either + * be JRuby compatible or JRubyIDESupport needs its own implementation. + */ + @Override + public Set findImageStrings(String text) throws IIDESupport.IncompleteStringException { + Set images = new HashSet<>(); + + Matcher m = IMAGE_STRING_PATTERN.matcher(text); + + while(m.find()) { + String string = m.group(); + + if((string.startsWith("\"") && string.endsWith("\"")) || (string.startsWith("'") && string.endsWith("'"))) { + images.add(m.group(1)); + } else { + int lineNumber = getLineNumber(text, m.start()); + throw new IIDESupport.IncompleteStringException(lineNumber); + } + } + + return images; + } + + private int getLineNumber(String text, int index) { + int currentChars = 0; + String[] lines = text.split("\n"); + for(int i=0;i index) { + return i + 1; + } + } + return -1; } } diff --git a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/Def.java b/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/Def.java deleted file mode 100644 index bdac76d11..000000000 --- a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/Def.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license - */ - -package org.sikuli.idesupport.syntaxhighlight; - -/** - * @author Tal Liron - */ -public abstract class Def -{ - // - // Attributes - // - - public boolean isResolved() - { - return resolved; - } - - public Def getCause( C container ) - { - return null; - } - - // - // Operations - // - - public boolean resolve( C container ) throws ResolutionException - { - return false; - } - - // - // Object - // - - @Override - public String toString() - { - return getClass().getSimpleName(); - } - - // ////////////////////////////////////////////////////////////////////////// - // Protected - - protected boolean resolved = false; -} diff --git a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/Filter.java b/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/Filter.java deleted file mode 100644 index 8c88c7beb..000000000 --- a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/Filter.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license - */ - -package org.sikuli.idesupport.syntaxhighlight; - -/** - * @author Tal Liron - */ -public abstract class Filter -{ - public static Filter getFilterByName( String name ) - { - return null; - } -} diff --git a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/Jygments.java b/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/Jygments.java deleted file mode 100644 index 2de55c041..000000000 --- a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/Jygments.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license - */ - -package org.sikuli.idesupport.syntaxhighlight; - -import java.io.IOException; -import java.io.Writer; - -import org.sikuli.idesupport.syntaxhighlight.format.Formatter; -import org.sikuli.idesupport.syntaxhighlight.grammar.Lexer; -import org.sikuli.idesupport.syntaxhighlight.grammar.Token; - -/** - * @author Tal Liron - */ -public abstract class Jygments -{ - // - // Static operations - // - - public static Iterable lex( String code, Lexer lexer ) - { - return lexer.getTokens( code ); - } - - public static void format( Iterable tokens, Formatter formatter, Writer writer ) throws IOException - { - formatter.format( tokens, writer ); - } - - public static void highlight( String code, Lexer lexer, Formatter formatter, Writer writer ) throws IOException - { - format( lex( code, lexer ), formatter, writer ); - } - - // ////////////////////////////////////////////////////////////////////////// - // Private - - private Jygments() - { - } -} diff --git a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/NestedDef.java b/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/NestedDef.java deleted file mode 100644 index ec858184a..000000000 --- a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/NestedDef.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license - */ - -package org.sikuli.idesupport.syntaxhighlight; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author Tal Liron - */ -public class NestedDef extends Def -{ - // - // Operations - // - - public void addDef( Def def ) - { - defs.add( def ); - } - - // - // Def - // - - @Override - public boolean resolve( C container ) throws ResolutionException - { - // Keep resolving until done - boolean didSomething = false, keepGoing = true; - while( keepGoing ) - { - keepGoing = false; - for( Def def : new ArrayList>( defs ) ) - { - if( !def.isResolved() ) - { - if( def.resolve( container ) ) - { - keepGoing = true; - didSomething = true; - } - } - } - } - - // Are we resolved? - resolved = true; - for( Def def : defs ) - { - if( !def.isResolved() ) - { - resolved = false; - break; - } - } - - return didSomething; - } - - @Override - public Def getCause( C container ) - { - for( Def def : defs ) - if( !def.isResolved() ) - return def; - return null; - } - - // ////////////////////////////////////////////////////////////////////////// - // Private - - private final List> defs = new ArrayList>(); -} diff --git a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/ResolutionException.java b/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/ResolutionException.java deleted file mode 100644 index 65e13334b..000000000 --- a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/ResolutionException.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license - */ - -package org.sikuli.idesupport.syntaxhighlight; - -/** - * @author Tal Liron - */ -public class ResolutionException extends Exception -{ - // - // Construction - // - - public ResolutionException( String message ) - { - super( message ); - } - - public ResolutionException( String message, Throwable cause ) - { - super( message, cause ); - } - - public ResolutionException( Throwable cause ) - { - super( cause ); - } - - // ////////////////////////////////////////////////////////////////////////// - // Private - - private static final long serialVersionUID = 1L; -} diff --git a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/Run.java b/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/Run.java deleted file mode 100644 index f16d234b7..000000000 --- a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/Run.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license - */ - -package org.sikuli.idesupport.syntaxhighlight; - -import java.io.FileInputStream; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Date; -import org.sikuli.idesupport.syntaxhighlight.format.Formatter; -import org.sikuli.idesupport.syntaxhighlight.grammar.Lexer; -import org.sikuli.idesupport.syntaxhighlight.grammar.Token; - -public class Run { - - private static void p(String text, Object... args) { - System.out.println(String.format(text, args)); - } - - public static void main(String[] args) throws IOException, ResolutionException { - String file = System.getProperty("user.dir") + "/src/main/java/org/sikuli/syntaxhighlight/Util.java"; - String aLexer = "python"; - Lexer lexer = Lexer.getByName(aLexer); - if (lexer != null) { - Formatter formatter = Formatter.getByName("html"); - String code = Util.streamToString(new FileInputStream(file)); -// code = " String code = Util.streamToString(new FileInputStream(file));"; - long start = new Date().getTime(); - Iterable tokens = lexer.getTokens(code); - long lexing = new Date().getTime() - start; - formatter.format(tokens, new PrintWriter("/Users/rhocke/Desktop/shtest.html")); - long formatting = new Date().getTime()- start - lexing; - p("%s: processed (%d, %d)", aLexer, lexing, formatting); - } else { - p("%s: no Lexer found", aLexer); - } - } -} diff --git a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/Util.java b/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/Util.java deleted file mode 100644 index af6a5635a..000000000 --- a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/Util.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license - */ -package org.sikuli.idesupport.syntaxhighlight; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.URI; -import java.net.URISyntaxException; -import java.security.CodeSource; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * @author Tal Liron - */ -public class Util { - - public static String literalRegEx(String expression) { - return "\\Q" + expression + "\\E"; - } - - public static String replace(String string, String occurence, String replacement) { - return string.replaceAll(literalRegEx(occurence), replacement); - } - - public static String streamToString(InputStream stream) throws IOException { - StringBuilder builder = new StringBuilder(); - String line; - - try { - BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "UTF-8")); - while ((line = reader.readLine()) != null) { - builder.append(line).append("\n"); - } - } finally { - stream.close(); - } - - return builder.toString(); - } - - public static String rejsonToJson(InputStream stream) throws IOException { - String rejson = streamToString(stream); - String json = rejsonToJson(rejson, true); - json = rejsonToJson(json, false); - return json; - } - - public static String rejsonToJson(String rejson, boolean doubleQuote) { - Matcher matcher = doubleQuote ? DOUBLE_QUOTED_STRING.matcher(rejson) : SINGLE_QUOTED_STRING.matcher(rejson); - StringBuilder json = new StringBuilder(); - int start = 0, end = 0, lastEnd = 0; - while (matcher.find()) { - lastEnd = end; - start = matcher.start(); - end = matcher.end(); - if ((start > 0) && (rejson.charAt(start - 1) == 'r')) { - // Convert Python-style r"" string to Java-compatible pattern - String string = rejson.substring(start + 1, end - 1); - json.append(rejson.substring(lastEnd, start - 1)); - json.append('\"'); - json.append(pythonRegExToJavaPattern(string, doubleQuote)); - json.append('\"'); - } /* - * else if( !doubleQuote ) { // From single quote to double quote - * String string = rejson.substring( start + 1, end - 1 ); - * json.append( rejson.substring( lastEnd, start - 1 ) ); - * json.append( '\"' ); json.append( string.replaceAll( "\"", - * "\\\\\"" ) ); json.append( '\"' ); } - */ else { - // As is - json.append(rejson.substring(lastEnd, end)); - } - } - json.append(rejson.substring(end)); - // System.out.println( json ); - return json.toString(); - } - - public static String pythonRegExToJavaPattern(String pattern, boolean doubleQuote) { - pattern = pattern.replaceAll("\\\\", "\\\\\\\\"); - pattern = pattern.replaceAll("\\{", "\\\\\\\\{"); - pattern = pattern.replaceAll("\\}", "\\\\\\\\}"); - if (!doubleQuote) { - pattern = pattern.replaceAll("\"", "\\\\\""); - } - // System.out.println( pattern ); - return pattern; - } - - public static String escapeHtml(String text) { - text = text.replace("&", "&"); - text = text.replace("<", "<"); - text = text.replace(">", ">"); - text = text.replace("\"", """); - text = text.replace("'", "'"); - return text; - } - - public static String asHtml(String text) { - text = escapeHtml(text); - text = text.replace(" ", " "); - return text; - } - private static final Pattern DOUBLE_QUOTED_STRING = Pattern.compile("\"(?>\\\\.|.)*?\""); - private static final Pattern SINGLE_QUOTED_STRING = Pattern.compile("'(?>\\\\.|.)*?'"); - public static String extJSON = ".jso"; - private static CodeSource csJygments = Jygments.class.getProtectionDomain().getCodeSource(); - - public static InputStream getJsonFile(String pack, String sub, String name, String fullname) { - URI jarFileURI = null; - File jarFile = null; - InputStream stream = null; - String jsonname = name.replace('.', '/') + extJSON; - fullname = fullname.replace('.', '/') + extJSON; - File fileInPack = null; - File fileInRoot = null; - try { - jarFileURI = csJygments.getLocation().toURI(); - } catch (URISyntaxException ex) { - System.out.println("Util: getJsonFile: URISyntaxException: " + ex.toString()); - } - if (jarFileURI != null ) { - String jarFilePath = jarFileURI.getPath(); - if (jarFileURI.getScheme().equals("file") && !jarFilePath.contains(".jar")) { - if (!pack.isEmpty()) { - pack = pack.replace(".", "/"); - if (!sub.isEmpty()) { - sub = sub.replace(".", "/"); - pack = pack + "/" + sub; - fileInRoot = new File(jarFilePath, sub + "/" + jsonname); - } - fileInPack = new File(jarFilePath, pack + "/" + jsonname); - } - if (fileInPack != null && fileInPack.exists()) { - jarFile = fileInPack; - } else if (fileInRoot != null && fileInRoot.exists()) { - jarFile = fileInRoot; - } - if (jarFile != null) { - try { - stream = new FileInputStream(jarFile); - } catch (FileNotFoundException ex) { - System.out.println("Jygments: Util: not found:\n" + jarFile) ; - } - } - } else { - stream = Jygments.class.getClassLoader().getResourceAsStream(fullname); - } - } - return stream; - } -} diff --git a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/contrib/Css2Lexer.java b/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/contrib/Css2Lexer.java deleted file mode 100644 index 7b57a50f8..000000000 --- a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/contrib/Css2Lexer.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license - */ - -package org.sikuli.idesupport.syntaxhighlight.contrib; - -import java.util.regex.Pattern; - -import org.sikuli.idesupport.syntaxhighlight.ResolutionException; -import org.sikuli.idesupport.syntaxhighlight.grammar.RegexLexer; - -/** - * @author Tal Liron - */ -public class Css2Lexer extends RegexLexer -{ - public Css2Lexer() - { - super(); - - addAlias( "css" ); - addFilename( "*.css" ); - addMimeType( "text/css" ); - - include( "root", "basics" ); - - int flags = Pattern.MULTILINE; - rule( "basics", "\\s+", flags, "Text" ); - rule( "basics", "/\\*(?:.|\\n)*?\\*/", flags, "Comment" ); - rule( "basics", "\\{", flags, "Punctuation", "content" ); - rule( "basics", "\\:[a-zA-Z0-9_-]+", flags, "Name.Decorator" ); - rule( "basics", "\\.[a-zA-Z0-9_-]+", flags, "Name.Class" ); - rule( "basics", "\\#[a-zA-Z0-9_-]+", flags, "Name.Function" ); - rule( "basics", "@[a-zA-Z0-9_-]+", flags, "Keyword", "atrule" ); - rule( "basics", "[a-zA-Z0-9_-]+", flags, "Name.Tag" ); - rule( "basics", "[~\\^\\*!%&\\[\\]\\(\\)<>\\|+=@:;,./?-]", flags, "Operator" ); - rule( "basics", "\"(\\\\\\\\|\\\\\"|[^\"])*\"", flags, "String.Double" ); - rule( "basics", "'(\\\\\\\\|\\\\'|[^'])*'\"", flags, "String.Single" ); - - rule( "atrule", "\\{", flags, "Punctuation", "atcontent" ); - rule( "atrule", ";", flags, "Punctuation", "#pop" ); - include( "atrule", "basics" ); - - include( "atcontent", "basics" ); - rule( "atcontent", "}", flags, "Punctuation", "#pop:2" ); - - rule( "content", "\\s+", flags, "Text" ); - rule( "content", "}", flags, "Punctuation", "#pop" ); - rule( "content", "url\\(.*?\\)", flags, "String.Other" ); - rule( "content", "^@.*?$", flags, "Comment.Preproc" ); - - rule( "content", "(azimuth|background-attachment|background-color|" + "background-image|background-position|background-repeat|" + "background|border-bottom-color|border-bottom-style|" - + "border-bottom-width|border-left-color|border-left-style|" + "border-left-width|border-right|border-right-color|" + "border-right-style|border-right-width|border-top-color|" - + "border-top-style|border-top-width|border-bottom|" + "border-collapse|border-left|border-width|border-color|" + "border-spacing|border-style|border-top|border|caption-side|" - + "clear|clip|color|content|counter-increment|counter-reset|" + "cue-after|cue-before|cue|cursor|direction|display|" + "elevation|empty-cells|float|font-family|font-size|" - + "font-size-adjust|font-stretch|font-style|font-variant|" + "font-weight|font|height|letter-spacing|line-height|" + "list-style-type|list-style-image|list-style-position|" - + "list-style|margin-bottom|margin-left|margin-right|" + "margin-top|margin|marker-offset|marks|max-height|max-width|" + "min-height|min-width|opacity|orphans|outline|outline-color|" - + "outline-style|outline-width|overflow|padding-bottom|" + "padding-left|padding-right|padding-top|padding|page|" + "page-break-after|page-break-before|page-break-inside|" - + "pause-after|pause-before|pause|pitch|pitch-range|" + "play-during|position|quotes|richness|right|size|" + "speak-header|speak-numeral|speak-punctuation|speak|" - + "speech-rate|stress|table-layout|text-align|text-decoration|" + "text-indent|text-shadow|text-transform|top|unicode-bidi|" + "vertical-align|visibility|voice-family|volume|white-space|" - + "widows|width|word-spacing|z-index|bottom|left|" + "above|absolute|always|armenian|aural|auto|avoid|baseline|" + "behind|below|bidi-override|blink|block|bold|bolder|both|" - + "capitalize|center-left|center-right|center|circle|" + "cjk-ideographic|close-quote|collapse|condensed|continuous|" + "crop|crosshair|cross|cursive|dashed|decimal-leading-zero|" - + "decimal|default|digits|disc|dotted|double|e-resize|embed|" + "extra-condensed|extra-expanded|expanded|fantasy|far-left|" + "far-right|faster|fast|fixed|georgian|groove|hebrew|help|" - + "hidden|hide|higher|high|hiragana-iroha|hiragana|icon|" + "inherit|inline-table|inline|inset|inside|invert|italic|" + "justify|katakana-iroha|katakana|landscape|larger|large|" - + "left-side|leftwards|level|lighter|line-through|list-item|" + "loud|lower-alpha|lower-greek|lower-roman|lowercase|ltr|" + "lower|low|medium|message-box|middle|mix|monospace|" - + "n-resize|narrower|ne-resize|no-close-quote|no-open-quote|" + "no-repeat|none|normal|nowrap|nw-resize|oblique|once|" + "open-quote|outset|outside|overline|pointer|portrait|px|" - + "relative|repeat-x|repeat-y|repeat|rgb|ridge|right-side|" + "rightwards|s-resize|sans-serif|scroll|se-resize|" + "semi-condensed|semi-expanded|separate|serif|show|silent|" - + "slow|slower|small-caps|small-caption|smaller|soft|solid|" + "spell-out|square|static|status-bar|super|sw-resize|" + "table-caption|table-cell|table-column|table-column-group|" - + "table-footer-group|table-header-group|table-row|" + "table-row-group|text|text-bottom|text-top|thick|thin|" + "transparent|ultra-condensed|ultra-expanded|underline|" - + "upper-alpha|upper-latin|upper-roman|uppercase|url|" + "visible|w-resize|wait|wider|x-fast|x-high|x-large|x-loud|" + "x-low|x-small|x-soft|xx-large|xx-small|yes)\\b", flags, "Keyword" ); - - rule( "content", "(indigo|gold|firebrick|indianred|yellow|darkolivegreen|" + "darkseagreen|mediumvioletred|mediumorchid|chartreuse|" + "mediumslateblue|black|springgreen|crimson|lightsalmon|brown|" - + "turquoise|olivedrab|cyan|silver|skyblue|gray|darkturquoise|" + "goldenrod|darkgreen|darkviolet|darkgray|lightpink|teal|" + "arkmagenta|lightgoldenrodyellow|lavender|yellowgreen|thistle|" - + "violet|navy|orchid|blue|ghostwhite|honeydew|cornflowerblue|" + "darkblue|darkkhaki|mediumpurple|cornsilk|red|bisque|slategray|" + "darkcyan|khaki|wheat|deepskyblue|darkred|steelblue|aliceblue|" - + "gainsboro|mediumturquoise|floralwhite|coral|purple|lightgrey|" + "lightcyan|darksalmon|beige|azure|lightsteelblue|oldlace|" + "greenyellow|royalblue|lightseagreen|mistyrose|sienna|" - + "lightcoral|orangered|navajowhite|lime|palegreen|burlywood|" + "seashell|mediumspringgreen|fuchsia|papayawhip|blanchedalmond|" + "peru|aquamarine|white|darkslategray|ivory|dodgerblue|" - + "lemonchiffon|chocolate|orange|forestgreen|slateblue|olive|" + "mintcream|antiquewhite|darkorange|cadetblue|moccasin|" + "limegreen|saddlebrown|darkslateblue|lightskyblue|deeppink|" - + "plum|aqua|darkgoldenrod|maroon|sandybrown|magenta|tan|" + "rosybrown|pink|lightblue|palevioletred|mediumseagreen|" + "dimgray|powderblue|seagreen|snow|mediumblue|midnightblue|" - + "paleturquoise|palegoldenrod|whitesmoke|darkorchid|salmon|" + "lightslategray|lawngreen|lightgreen|tomato|hotpink|" + "lightyellow|lavenderblush|linen|mediumaquamarine|green|" + "blueviolet|peachpuff)\\b", - flags, "Name.Builtin" ); - - rule( "content", "\\!important", flags, "Comment.Preproc" ); - rule( "content", "/\\*(?:.|\\n)*?\\*/'", flags, "Comment" ); - rule( "content", "\\#[a-zA-Z0-9]{1,6}", flags, "Number" ); - rule( "content", "[\\.-]?[0-9]*[\\.]?[0-9]+(em|px|\\%|pt|pc|in|mm|cm|ex)", flags, "Number" ); - rule( "content", "-?[0-9]+", flags, "Number" ); - rule( "content", "[~\\^\\*!%&<>\\|+=@:,./?-]+", flags, "Operator" ); - rule( "content", "[\\[\\]();]+", flags, "Punctuation" ); - rule( "content", "\"(\\\\\\\\|\\\\\"|[^\"])*\"", flags, "String.Double" ); - rule( "content", "\"'(\\\\\\\\|\\\\'|[^'])*'", flags, "String.Single" ); - rule( "content", "[a-zA-Z][a-zA-Z0-9]+", flags, "Name" ); - - try - { - resolve(); - } - catch( ResolutionException x ) - { - throw new RuntimeException( x ); - } - } -} diff --git a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/contrib/DebugFormatter.java b/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/contrib/DebugFormatter.java deleted file mode 100644 index f2cb08151..000000000 --- a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/contrib/DebugFormatter.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license - */ - -package org.sikuli.idesupport.syntaxhighlight.contrib; - -import java.io.IOException; -import java.io.Writer; - -import org.sikuli.idesupport.syntaxhighlight.format.Formatter; -import org.sikuli.idesupport.syntaxhighlight.grammar.Token; -import org.sikuli.idesupport.syntaxhighlight.style.Style; - -/** - * @author Tal Liron - */ -public class DebugFormatter extends Formatter -{ - // - // Construction - // - - public DebugFormatter() - { - this( null, false, null, null ); - } - - public DebugFormatter( Style style, boolean full, String title, String encoding ) - { - super( style, full, title, encoding ); - } - - // - // Formatter - // - - @Override - public void format( Iterable tokenSource, Writer writer ) throws IOException - { - for( Token token : tokenSource ) - writer.write( token.getPos() + " " + token.getType() + ": " + token.getValue() + "\n" ); - writer.flush(); - } -} diff --git a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/contrib/Default2Style.java b/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/contrib/Default2Style.java deleted file mode 100644 index eb769dd25..000000000 --- a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/contrib/Default2Style.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license - */ - -package org.sikuli.idesupport.syntaxhighlight.contrib; - -import org.sikuli.idesupport.syntaxhighlight.ResolutionException; -import org.sikuli.idesupport.syntaxhighlight.style.Style; - -/** - * @author Tal Liron - */ -public class Default2Style extends Style -{ - public Default2Style() - { - super(); - - add( "Whitespace", "#bbbbbb" ); - add( "Comment", "italic", "#408080" ); - add( "Comment.Preproc", "noitalic", "#BC7A00" ); - - add( "Keyword", "bold", "#008000" ); - add( "Keyword.Pseudo", "nobold" ); - add( "Keyword.Type", "nobold", "#B00040" ); - - add( "Operator", "#666666" ); - add( "Operator.Word", "bold", "#AA22FF" ); - - add( "Name.Builtin", "#008000" ); - add( "Name.Function", "#0000FF" ); - add( "Name.Class", "bold", "#0000FF" ); - add( "Name.Namespace", "bold", "#0000FF" ); - add( "Name.Exception", "bold", "#D2413A" ); - add( "Name.Variable", "#19177C" ); - add( "Name.Constant", "#880000" ); - add( "Name.Label", "#A0A000" ); - add( "Name.Entity", "bold", "#999999" ); - add( "Name.Attribute", "#7D9029" ); - add( "Name.Tag", "bold", "#008000" ); - add( "Name.Decorator", "#AA22FF" ); - - add( "String", "#BA2121" ); - add( "String.Doc", "italic" ); - add( "String.Interpol", "bold", "#BB6688" ); - add( "String.Escape", "bold", "#BB6622" ); - add( "String.Regex", "#BB6688" ); - add( "String.Symbol", "#19177C" ); - add( "String.Other", "#008000" ); - add( "Number", "#666666" ); - - add( "Generic.Heading", "bold", "#000080" ); - add( "Generic.Subheading", "bold", "#800080" ); - add( "Generic.Deleted", "#A00000" ); - add( "Generic.Inserted", "#00A000" ); - add( "Generic.Error", "#FF0000" ); - add( "Generic.Emph", "italic" ); - add( "Generic.Strong", "bold" ); - add( "Generic.Prompt", "bold", "#000080" ); - add( "Generic.Output", "#888" ); - add( "Generic.Traceback", "#04D" ); - - add( "Error", "border", "#FF0000" ); - - try - { - resolve(); - } - catch( ResolutionException x ) - { - throw new RuntimeException( x ); - } - } -} diff --git a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/contrib/HtmlFormatter.java b/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/contrib/HtmlFormatter.java deleted file mode 100644 index cdd9d33cc..000000000 --- a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/contrib/HtmlFormatter.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license - */ - -package org.sikuli.idesupport.syntaxhighlight.contrib; - -import java.io.IOException; -import java.io.Writer; -import java.util.List; -import java.util.Map; - -import org.sikuli.idesupport.syntaxhighlight.ResolutionException; -import org.sikuli.idesupport.syntaxhighlight.Util; -import org.sikuli.idesupport.syntaxhighlight.format.Formatter; -import org.sikuli.idesupport.syntaxhighlight.grammar.Token; -import org.sikuli.idesupport.syntaxhighlight.grammar.TokenType; -import org.sikuli.idesupport.syntaxhighlight.style.ColorStyleElement; -import org.sikuli.idesupport.syntaxhighlight.style.EffectStyleElement; -import org.sikuli.idesupport.syntaxhighlight.style.FontStyleElement; -import org.sikuli.idesupport.syntaxhighlight.style.Style; -import org.sikuli.idesupport.syntaxhighlight.style.StyleElement; - -/** - * @author Tal Liron - */ -public class HtmlFormatter extends Formatter -{ - // - // Construction - // - - public HtmlFormatter() throws ResolutionException - { - this( Style.getByName( "default" ), false, null, null ); - } - - public HtmlFormatter( Style style, boolean full, String title, String encoding ) - { - super( style, full, title, encoding ); - } - - // - // Formatter - // - - @Override - public void format( Iterable tokenSource, Writer writer ) throws IOException - { - writer.write( getDocHeader1() ); - writer.write( " " ); - writer.write( Util.escapeHtml( getTitle() ) ); - writer.write( "\n" ); - writer.write( getDocHeader2() ); - writer.write( getEncoding() ); - writer.write( getDocHeader3() ); - writer.write( getCssFileTemplate() ); - formatStyleSheet( writer ); - writer.write( getDocHeader4() ); - if( getTitle().length() > 0 ) - { - writer.write( "

" ); - writer.write( Util.escapeHtml( getTitle() ) ); - writer.write( "

\n" ); - } - writer.write( "
\n" );
-		StringBuilder line = new StringBuilder();
-		int line_no = 1;
-		for( Token token : tokenSource )
-		{
-	        String[] toks = token.getValue().split("\n", -1);
-	        for(int i = 0; i < toks.length - 1; i++) {
-	            format_partial_token(token, toks[i], line);
-	            format_line(line.toString(), writer, line_no++);
-	            line = new StringBuilder();
-            }
-            format_partial_token(token, toks[toks.length-1], line);
-		}
-		if(line.length() > 0)
-		    format_line(line.toString(), writer, line_no++);
-
-		writer.write( "
\n" ); - writer.write( getDocFooter() ); - writer.flush(); - } - - private void format_partial_token(Token token, String part_tok, StringBuilder line) - { - if( token.getType().getShortName().length() > 0 ) - { - line.append( "" ); - line.append( Util.escapeHtml( part_tok ) ); - line.append( "" ); - } - else - line.append( Util.escapeHtml( part_tok ) ); - } - - public void format_line(String line, Writer writer, int line_no) throws IOException - { - writer.write(line); - writer.write("\n"); - } - - // ////////////////////////////////////////////////////////////////////////// - // Protected - - protected String getClassPrefix() - { - return ""; - } - - protected String getCssFileTemplate() - { - return " td.linenos { background-color: #f0f0f0; padding-right: 10px; }\n" + " span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }\n" - + " pre { line-height: 125%; }\n"; - } - - protected String getDocHeader1() - { - return "\n" + "\n" + "\n"; - } - - protected String getDocHeader2() - { - return " \n" + " \n" + " \n" + "\n"; - } - - /* - * private static final String DOC_HEADER_EXTERNAL_CSS = - * "\n" + "\n" + "\n" + - * "\n" + " %(title)s\n" + - * " \n" - * + " \n" - * + " \n" + "\n" + "

%(title)s

\n"; - */ - - protected String getDocFooter() - { - return "\n" + "\n"; - } - - // ////////////////////////////////////////////////////////////////////////// - // Private - - private void formatStyleSheet( Writer writer ) throws IOException - { - for( Map.Entry> entry : getStyle().getStyleElements().entrySet() ) - { - TokenType tokenType = entry.getKey(); - List styleElementsForTokenType = entry.getValue(); - writer.write( " ." ); - writer.write( getClassPrefix() ); - writer.write( tokenType.getShortName() ); - writer.write( " { " ); - for( StyleElement styleElement : styleElementsForTokenType ) - { - if( styleElement instanceof ColorStyleElement ) - { - ColorStyleElement colorStyleElement = (ColorStyleElement) styleElement; - if( colorStyleElement.getType() == ColorStyleElement.Type.Foreground ) - writer.write( "color: " ); - else if( colorStyleElement.getType() == ColorStyleElement.Type.Background ) - writer.write( "background-color: " ); - else if( colorStyleElement.getType() == ColorStyleElement.Type.Border ) - writer.write( "border: 1px solid " ); - writer.write( colorStyleElement.getColor() ); - writer.write( "; " ); - } - else if( styleElement instanceof EffectStyleElement ) - { - if( styleElement == EffectStyleElement.Bold ) - writer.write( "font-weight: bold; " ); - else if( styleElement == EffectStyleElement.Italic ) - writer.write( "font-style: italic; " ); - else if( styleElement == EffectStyleElement.Underline ) - writer.write( "text-decoration: underline; " ); - } - else if( styleElement instanceof FontStyleElement ) - { - // We don't want to set fonts in this formatter - } - } - writer.write( "} /* " ); - writer.write( tokenType.getName() ); - writer.write( " */\n" ); - } - } -} diff --git a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/format/Formatter.java b/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/format/Formatter.java deleted file mode 100644 index 97e5d583b..000000000 --- a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/format/Formatter.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license - */ - -package org.sikuli.idesupport.syntaxhighlight.format; - -import java.io.IOException; -import java.io.Writer; - -import org.sikuli.idesupport.syntaxhighlight.Jygments; -import org.sikuli.idesupport.syntaxhighlight.ResolutionException; -import org.sikuli.idesupport.syntaxhighlight.grammar.Token; -import org.sikuli.idesupport.syntaxhighlight.style.Style; - -/** - * @author Tal Liron - */ -public abstract class Formatter -{ - // - // Static operations - // - - public static Formatter getByName( String name ) throws ResolutionException - { - if( Character.isLowerCase( name.charAt( 0 ) ) ) - name = Character.toUpperCase( name.charAt( 0 ) ) + name.substring( 1 ) + "Formatter"; - - Formatter formatter = getByFullName( name ); - if( formatter != null ) - return formatter; - else - { - // Try contrib package - String pack = Jygments.class.getPackage().getName() + ".contrib"; - formatter = getByFullName( pack + "." + name ); - if( formatter == null ) - { - // Try this package - pack = Formatter.class.getPackage().getName(); - formatter = getByFullName( pack + "." + name ); - } - return formatter; - } - } - - public static Formatter getByFullName( String fullName ) throws ResolutionException - { - try - { - return (Formatter) Jygments.class.getClassLoader().loadClass( fullName ).newInstance(); - } - catch( InstantiationException x ) - { - } - catch( IllegalAccessException x ) - { - } - catch( ClassNotFoundException x ) - { - } - - return null; - } - - public Formatter( Style style, boolean full, String title, String encoding ) - { - this.style = style; - this.title = title != null ? title : ""; - this.encoding = encoding != null ? encoding : "utf8"; - } - - public Style getStyle() - { - return style; - } - - public String getTitle() - { - return title; - } - - public String getEncoding() - { - return encoding; - } - - public abstract void format( Iterable tokenSource, Writer writer ) throws IOException; - - // ////////////////////////////////////////////////////////////////////////// - // Private - - private final Style style; - - private final String title; - - private final String encoding; -} diff --git a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/DelegatedLexer.java b/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/DelegatedLexer.java deleted file mode 100644 index 623814b09..000000000 --- a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/DelegatedLexer.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license - */ - -package org.sikuli.idesupport.syntaxhighlight.grammar; - -import org.sikuli.idesupport.syntaxhighlight.ResolutionException; -import java.util.Map; -import java.util.List; -import java.util.ListIterator; -import java.util.LinkedList; - -/** - * @author Tal Liron - */ -public class DelegatedLexer extends Lexer -{ - // - // Lexer - // - - @Override - public Iterable getTokensUnprocessed( String text ) - { - StringBuilder buffered = new StringBuilder(); - List lngBuffer = new LinkedList(); - List insertions = new LinkedList(); - - Iterable tokens = languageLexer.getTokensUnprocessed( text ); - - for( Token t : tokens ) - { - if( t.getType().getName().equals( "Other" ) ) - { - if( !lngBuffer.isEmpty() ) - { - insertions.add( new Insertion( buffered.length(), lngBuffer ) ); - lngBuffer = new LinkedList(); - } - buffered.append( t.getValue() ); - } - else - lngBuffer.add( t ); - } - - if( !lngBuffer.isEmpty() ) - insertions.add( new Insertion( buffered.length(), lngBuffer ) ); - - return doInsertions( insertions, rootLexer.getTokensUnprocessed( buffered.toString() ) ); - } - - // ////////////////////////////////////////////////////////////////////////// - // Protected - - @Override - protected void addJson( Map json ) throws ResolutionException - { - super.addJson( json ); - rootLexer = Lexer.getByName( (String) json.get( "root_lexer" ) ); - languageLexer = Lexer.getByName( (String) json.get( "language_lexer" ) ); - } - - // ////////////////////////////////////////////////////////////////////////// - // Private - - private Lexer rootLexer; - - private Lexer languageLexer; - - private static class Insertion - { - public int index; - - public List lngBuffer; - - public Insertion( int index, List lngBuffer ) - { - super(); - this.index = index; - this.lngBuffer = lngBuffer; - } - } - - private Iterable doInsertions( List insertions, Iterable tokens ) - { - ListIterator li = insertions.listIterator(); - Insertion next_ins = li.hasNext() ? (Insertion) li.next() : null; - int len = 0; - LinkedList rc = new LinkedList(); - - for( Token t : tokens ) - { - len += t.getValue().length(); - String s = t.getValue(); - int pos = 0; - while( next_ins != null && next_ins.index <= len ) - { - rc.add( new Token( t.getPos(), t.getType(), s.substring( pos, s.length() + ( next_ins.index - len ) ) ) ); - pos = s.length() + ( next_ins.index - len ); - for( Token tt : next_ins.lngBuffer ) - rc.add( tt ); - next_ins = li.hasNext() ? li.next() : null; - } - if( pos < s.length() ) - rc.add( new Token( t.getPos(), t.getType(), s.substring( pos ) ) ); - } - - // Do remaining tokens - while( li.hasNext() ) - for( Token tt : ( (Insertion) li.next() ).lngBuffer ) - rc.add( tt ); - - return rc; - } -} diff --git a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/Grammar.java b/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/Grammar.java deleted file mode 100644 index 888071fc9..000000000 --- a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/Grammar.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license - */ - -package org.sikuli.idesupport.syntaxhighlight.grammar; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.sikuli.idesupport.syntaxhighlight.Def; -import org.sikuli.idesupport.syntaxhighlight.NestedDef; -import org.sikuli.idesupport.syntaxhighlight.ResolutionException; - -/** - * @author Tal Liron - */ -public class Grammar extends NestedDef -{ - // - // Attributes - // - - public State getState( String stateName ) - { - State state = statesByName.get( stateName ); - if( state == null ) - { - state = new State( stateName ); - statesByName.put( stateName, state ); - addDef( state ); - } - return state; - } - - public State resolveState( String stateName ) throws ResolutionException - { - if( stateName.startsWith( "#pop" ) ) - { - int depth = 1; - if( stateName.length() > 4 ) - { - String depthString = stateName.substring( 5 ); - try - { - depth = Integer.parseInt( depthString ); - } - catch( NumberFormatException x ) - { - throw new ResolutionException( x ); - } - } - return new RelativeState( false, depth ); - } - else if( stateName.startsWith( "#push" ) ) - { - int depth = 1; - if( stateName.length() > 5 ) - { - String depthString = stateName.substring( 6 ); - try - { - depth = Integer.parseInt( depthString ); - } - catch( NumberFormatException x ) - { - throw new ResolutionException( x ); - } - } - return new RelativeState( true, depth ); - } - - State state = getState( stateName ); - if( state.isResolved() ) - return state; - else - return null; - } - - public List resolveStates( List stateNames ) throws ResolutionException - { - ArrayList states = new ArrayList(); - for( String stateName : stateNames ) - { - String[] combinedStateName = stateName.split( "\\+" ); - if( combinedStateName.length > 1 ) - { - State combinedState = null; - - for( String singleStateName : combinedStateName ) - { - State state = resolveState( singleStateName ); - if( state == null ) - return null; - - if( combinedState == null ) - combinedState = state; - else - combinedState = new State( combinedState, state ); - } - - states.add( combinedState ); - } - else - { - State state = resolveState( stateName ); - if( state == null ) - return null; - - states.add( state ); - } - } - - return states; - } - - // - // Operations - // - - public void resolve() throws ResolutionException - { - resolve( this ); - - // Are we resolved? - for( Map.Entry entry : statesByName.entrySet() ) - { - if( !entry.getValue().isResolved() ) - { - String message = "Unresolved state: " + entry.getKey(); - Def cause = entry.getValue().getCause( this ); - while( cause != null ) - { - message += ", cause: " + cause; - cause = cause.getCause( this ); - } - throw new ResolutionException( message ); - } - } - } - - // ////////////////////////////////////////////////////////////////////////// - // Private - - private final Map statesByName = new HashMap(); -} diff --git a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/Lexer.java b/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/Lexer.java deleted file mode 100644 index 8cafc64f0..000000000 --- a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/Lexer.java +++ /dev/null @@ -1,364 +0,0 @@ -/* - * Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license - */ - -package org.sikuli.idesupport.syntaxhighlight.grammar; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.jar.JarEntry; -import java.util.jar.JarInputStream; - -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.sikuli.idesupport.syntaxhighlight.Filter; -import org.sikuli.idesupport.syntaxhighlight.Jygments; -import org.sikuli.idesupport.syntaxhighlight.ResolutionException; -import org.sikuli.idesupport.syntaxhighlight.Util; -import org.sikuli.idesupport.syntaxhighlight.grammar.def.ChangeStateTokenRuleDef; -import org.sikuli.idesupport.syntaxhighlight.grammar.def.IncludeDef; -import org.sikuli.idesupport.syntaxhighlight.grammar.def.TokenRuleDef; - -/** - * @author Tal Liron - */ -public class Lexer extends Grammar -{ - // - // Static operations - // - private static ClassLoader cl = Jygments.class.getClassLoader(); - - public static Lexer getByName( String name ) throws ResolutionException - { - if( ( name == null ) || ( name.length() == 0 ) ) - name = "Lexer"; - else if( Character.isLowerCase( name.charAt( 0 ) ) ) - name = Character.toUpperCase( name.charAt( 0 ) ) + name.substring( 1 ) + "Lexer"; - - Lexer lexer = getByFullName( name ); - if( lexer != null ) - return lexer; - else - { - // Try contrib package - lexer = getByFullName( "LexerContrib", "", name ); - if( lexer == null ) - { - // Try this package - String pack = Lexer.class.getPackage().getName(); - lexer = getByFullName( pack, "", name ); - } - return lexer; - } - } - - public static Lexer getByFullName( String name ) throws ResolutionException { - return getByFullName("", "", name); - } - - @SuppressWarnings("unchecked") - public static Lexer getByFullName( String pack, String sub, String name ) throws ResolutionException - { - String fullname = name; - if (!pack.isEmpty()) { - if (!sub.isEmpty()) { - fullname = pack + "." + sub + "." + fullname; - } else { - fullname = pack + "." + fullname; - } - } - // Try cache - Lexer lexer = lexers.get( fullname ); - if( lexer != null ) - return lexer; - - try - { - Class cLexer = (Class) cl.loadClass( fullname ); - Lexer iLexer = (Lexer) (cLexer.newInstance()); - return iLexer; - } - catch( Exception x ) - { - //System.out.println("[error] Jygments: Lexer: problem loading class " + fullname); - } - - InputStream stream = Util.getJsonFile(pack, sub, name, fullname); - if( stream != null ) - { - try - { - String converted = Util.rejsonToJson( stream ); - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.getFactory().configure( JsonParser.Feature.ALLOW_COMMENTS, true ); - Map json = objectMapper.readValue( converted, HashMap.class ); - Object className = json.get( "class" ); - if( className == null ) - className = ""; - - lexer = getByName( className.toString() ); - lexer.addJson( json ); - lexer.resolve(); - - if( lexer != null ) - { - // Cache it - Lexer existing = lexers.putIfAbsent( fullname, lexer ); - if( existing != null ) { - lexer = existing; - } - } - - return lexer; - } - catch( JsonParseException x ) - { - throw new ResolutionException( x ); - } - catch( JsonMappingException x ) - { - throw new ResolutionException( x ); - } - catch( IOException x ) - { - throw new ResolutionException( x ); - } - } - - return null; - } - - public static Lexer getForFileName( String fileName ) throws ResolutionException - { - if( lexerMap.isEmpty() ) - { - try - { - File jarFile = new File( Jygments.class.getProtectionDomain().getCodeSource().getLocation().toURI() ); - JarInputStream jarInputStream = new JarInputStream( new FileInputStream( jarFile ) ); - try - { - for( JarEntry jarEntry = jarInputStream.getNextJarEntry(); jarEntry != null; jarEntry = jarInputStream.getNextJarEntry() ) - { - if( jarEntry.getName().endsWith( Util.extJSON ) ) - { - String lexerName = jarEntry.getName(); - // strip off the JSON file ending - lexerName = lexerName.substring( 0, lexerName.length() - Util.extJSON.length() ); - Lexer lexer = Lexer.getByFullName( lexerName ); - for( String filename : lexer.filenames ) - if( filename.startsWith( "*." ) ) - lexerMap.put( filename.substring( filename.lastIndexOf( '.' ) ), lexer ); - } - } - } - finally - { - jarInputStream.close(); - } - } - catch( URISyntaxException x ) - { - throw new ResolutionException( x ); - } - catch( FileNotFoundException x ) - { - throw new ResolutionException( x ); - } - catch( IOException x ) - { - throw new ResolutionException( x ); - } - } - - return lexerMap.get( fileName.substring( fileName.lastIndexOf( '.' ) ) ); - } - - // - // Construction - // - - public Lexer() - { - this( false, false, 4, "utf8" ); - } - - public Lexer( boolean stripNewlines, boolean stripAll, int tabSize, String encoding ) - { - this.stripNewLines = stripNewlines; - this.stripAll = stripAll; - this.tabSize = tabSize; - } - - // - // Attributes - // - - public List getFilters() - { - return filters; - } - - public boolean isStripNewLines() - { - return stripNewLines; - } - - public void setStripNewLines( boolean stripNewLines ) - { - this.stripNewLines = stripNewLines; - } - - public boolean isStripAll() - { - return stripAll; - } - - public void setStripAll( boolean stripAll ) - { - this.stripAll = stripAll; - } - - public int getTabSize() - { - return tabSize; - } - - public void setTabSize( int tabSize ) - { - this.tabSize = tabSize; - } - - public void addFilter( Filter filter ) - { - filters.add( filter ); - } - - public float analyzeText( String text ) - { - return 0; - } - - public Iterable getTokens( String text ) - { - return getTokens( text, false ); - } - - public Iterable getTokens( String text, boolean unfiltered ) - { - // text = text.replace( "\r\n", "\n" ).replace( "\r", "\n" ); - // if( stripAll ) - // text = text.trim(); - // if( stripNewLines ) - // text = text.replace( "\n", "" ); - if( tabSize > 0 ) - { - // expand tabs - } - if( !text.endsWith( "\n" ) ) - text += "\n"; - Iterable tokens = getTokensUnprocessed( text ); - if( !unfiltered ) - { - // apply filters - } - return tokens; - } - - public Iterable getTokensUnprocessed( String text ) - { - ArrayList list = new ArrayList( 1 ); - list.add( new Token( 0, TokenType.Text, text ) ); - return list; - } - - // ////////////////////////////////////////////////////////////////////////// - // Protected - - protected void addAlias( String alias ) - { - aliases.add( alias ); - } - - protected void addFilename( String filename ) - { - filenames.add( filename ); - } - - protected void addMimeType( String mimeType ) - { - mimeTypes.add( mimeType ); - } - - protected void include( String stateName, String includedStateName ) - { - getState( stateName ).addDef( new IncludeDef( stateName, includedStateName ) ); - } - - protected void rule( String stateName, String pattern, int flags, String tokenTypeName ) - { - getState( stateName ).addDef( new TokenRuleDef( stateName, pattern, flags, tokenTypeName ) ); - } - - protected void rule( String stateName, String pattern, int flags, String tokenTypeName, String nextStateName ) - { - getState( stateName ).addDef( new ChangeStateTokenRuleDef( stateName, pattern, flags, new String[] - { - tokenTypeName - }, nextStateName ) ); - } - - protected void rule( String stateName, String pattern, int flags, String[] tokenTypeNames ) - { - getState( stateName ).addDef( new TokenRuleDef( stateName, pattern, flags, tokenTypeNames ) ); - } - - protected void rule( String stateName, String pattern, int flags, String[] tokenTypeNames, String... nextStateNames ) - { - getState( stateName ).addDef( new ChangeStateTokenRuleDef( stateName, pattern, flags, tokenTypeNames, nextStateNames ) ); - } - - protected void addJson( Map json ) throws ResolutionException - { - @SuppressWarnings("unchecked") - List filenames = (List) json.get( "filenames" ); - if( filenames == null ) - return; - for( String filename : filenames ) - addFilename( filename ); - } - - // ////////////////////////////////////////////////////////////////////////// - // Private - - private static final ConcurrentMap lexers = new ConcurrentHashMap(); - - private static final ConcurrentMap lexerMap = new ConcurrentHashMap(); - - private final List filters = new ArrayList(); - - private boolean stripNewLines; - - private boolean stripAll; - - private int tabSize; - - private final List aliases = new ArrayList(); - - private final List filenames = new ArrayList(); - - private final List mimeTypes = new ArrayList(); -} diff --git a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/PatternRule.java b/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/PatternRule.java deleted file mode 100644 index f49e8c9bb..000000000 --- a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/PatternRule.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license - */ - -package org.sikuli.idesupport.syntaxhighlight.grammar; - -import java.util.regex.Pattern; - -/** - * @author Tal Liron - */ -public abstract class PatternRule extends Rule -{ - // - // Construction - // - - public PatternRule( Pattern pattern ) - { - this.pattern = pattern; - } - - // - // Attributes - // - - public Pattern getPattern() - { - return pattern; - } - - // ////////////////////////////////////////////////////////////////////////// - // Private - - private final Pattern pattern; -} diff --git a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/RegexLexer.java b/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/RegexLexer.java deleted file mode 100644 index b74ddb0b6..000000000 --- a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/RegexLexer.java +++ /dev/null @@ -1,384 +0,0 @@ -/* - * Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license - */ - -package org.sikuli.idesupport.syntaxhighlight.grammar; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.sikuli.idesupport.syntaxhighlight.ResolutionException; -import org.sikuli.idesupport.syntaxhighlight.grammar.def.ChangeStateTokenRuleDef; -import org.sikuli.idesupport.syntaxhighlight.grammar.def.SaveDef; -import org.sikuli.idesupport.syntaxhighlight.grammar.def.TokenRuleDef; -import org.sikuli.idesupport.syntaxhighlight.grammar.def.UsingRuleDef; - -/** - * @author Tal Liron - */ -public class RegexLexer extends Lexer -{ - // ////////////////////////////////////////////////////////////////////////// - // Protected - - @Override - public List getTokensUnprocessed( String text ) - { - List tokens = new ArrayList(); - - // Start at root state - LinkedList stateStack = new LinkedList(); - State state = getState( "root" ); - stateStack.add( state ); - - int pos = 0; - int length = text.length(); - while( pos < length ) - { - int eol = text.indexOf( '\n', pos ); - // int endRegion = eol >= 0 ? eol + 2 : length; - // if( endRegion > length ) - // endRegion = length; - int endRegion = length; - boolean matches = false; - - // Does any rule in the current state match at the current position? - // System.out.println("Text: " + text.substring( pos )); - for( Rule rule : new ArrayList( state.getRules() ) ) - { - if( rule instanceof PatternRule ) - { - PatternRule patternRule = (PatternRule) rule; - // System.out.println( "Trying pattern: " + - // rule.getPattern().pattern() ); - Matcher matcher = patternRule.getPattern().matcher( text ); - // From current position to end of line - // matcher.useTransparentBounds( true ); - matcher.region( pos, endRegion ); - if( matcher.lookingAt() ) - { - // System.out.println( "Match! " + matcher.group() + " " - // + - // rule ); - - // Yes, so apply it! - if( rule instanceof TokenRule ) - { - TokenRule tokenRule = (TokenRule) rule; - List tokenTypes = tokenRule.getTokenTypes(); - if( tokenTypes.size() == 1 ) - // Single token - tokens.add( new Token( pos, tokenTypes.get( 0 ), matcher.group() ) ); - else - { - if( tokenTypes.size() != matcher.groupCount() ) - throw new RuntimeException( "The number of token types in the rule does not match the number of groups in the regular expression" ); - - // Multiple tokens by group - int group = 1; - for( TokenType tokenType : tokenTypes ) - { - String value = matcher.group( group ); - // System.out.println( matcher.pattern() + - // " " + - // value + " " + tokenType ); - // pos = matcher.start( group ); - tokens.add( new Token( pos, tokenType, value ) ); - // pos = matcher.end( group ); - group++; - } - } - - // Change state - List nextStates = tokenRule.getNextStates(); - if( nextStates != null ) - { - for( State nextState : nextStates ) - { - if( nextState instanceof RelativeState ) - { - RelativeState relativeState = (RelativeState) nextState; - if( relativeState.isPush() ) - // Push - stateStack.addLast( state ); - else - // Pop - for( int depth = relativeState.getDepth(); ( depth > 0 ) && !stateStack.isEmpty(); depth-- ) - state = stateStack.removeLast(); - } - else - { - // Push and switch - stateStack.addLast( state ); - state = nextState; - } - } - } - /* - * else { // Pop if( stateStack.size() > 1 ) state = - * stateStack.removeLast(); } - */ - } - else if( rule instanceof UsingRule ) - { - UsingRule usingRule = (UsingRule) rule; - // System.err.println( "!!!!!!!" + - // rule.getPattern().pattern() ); - // System.err.println( "!!!!!!!!!!!!!!" + - // matcher.group().length() ); - Iterable usingTokens = usingRule.getLexer().getTokensUnprocessed( matcher.group() ); - for( Token usingToken : usingTokens ) - tokens.add( usingToken ); - } - - pos = matcher.end(); - // System.out.println( pos ); - matches = true; - - // Don't process other rules here - break; - } - } - else if( rule instanceof SaveRule ) - { - SaveRule saveRule = (SaveRule) rule; - State saveState = saveRule.getState(); - if( saveState != state ) - { - saveState.getRules().clear(); - saveState.include( state ); - } - } - } - - if( !matches ) - { - // tokens.add( new Token( pos, TokenType.Error, state.getName() - // ) ); - if( pos != eol ) - { - // Unmatched character - tokens.add( new Token( pos, TokenType.Error, text.substring( pos, pos + 1 ) ) ); - } - else - { - // Fallback for states that don't explicitly match new - // lines. - - tokens.add( new Token( pos, TokenType.Text, "\n" ) ); - - // Reset state stack - /* - * state = getState( "root" ); stateStack.clear(); - * stateStack.addLast( state ); - */ - } - - pos += 1; - } - } - - return tokens; - } - - @SuppressWarnings("unchecked") - @Override - protected void addJson( Map json ) throws ResolutionException - { - super.addJson( json ); - - // Initialize constants - Object constantsObject = json.get( "constants" ); - Map> constants = new HashMap>(); - if( constantsObject != null ) - { - if( !( constantsObject instanceof Map ) ) - throw new ResolutionException( "\"constants\" must be a map" ); - - for( Map.Entry entry : ( (Map) constantsObject ).entrySet() ) - { - String constantName = entry.getKey(); - Object constantObject = entry.getValue(); - ArrayList strings = new ArrayList(); - constants.put( constantName, strings ); - if( constantObject instanceof List ) - { - StringBuilder pattern = new StringBuilder(); - for( String patternElement : (List) constantObject ) - pattern.append( patternElement ); - strings.add( pattern.toString() ); - } - else if( constantObject instanceof String ) - strings.add( (String) constantObject ); - else - throw new ResolutionException( "Unexpected value in \"constants\" map: " + constantObject ); - } - } - - // Flags - int defaultFlags = Pattern.MULTILINE; - Object flagsObject = json.get( "flags" ); - if( flagsObject != null ) - { - if( !( flagsObject instanceof List ) ) - throw new ResolutionException( "\"flags\" must be an array of strings" ); - - for( Object flagObject : (List) flagsObject ) - { - if( !( flagObject instanceof String ) ) - throw new ResolutionException( "\"flags\" must be an array of strings" ); - - String flag = (String) flagObject; - if( flag.equalsIgnoreCase( "CANON_EQ" ) ) - defaultFlags |= Pattern.CANON_EQ; - else if( flag.equalsIgnoreCase( "CASE_INSENSITIVE" ) || flag.equalsIgnoreCase( "IGNORECASE" ) ) - defaultFlags |= Pattern.CASE_INSENSITIVE; - else if( flag.equalsIgnoreCase( "COMMENTS" ) ) - defaultFlags |= Pattern.COMMENTS; - else if( flag.equalsIgnoreCase( "DOTALL" ) ) - defaultFlags |= Pattern.DOTALL; - else if( flag.equalsIgnoreCase( "LITERAL" ) ) - defaultFlags |= Pattern.LITERAL; - else if( flag.equalsIgnoreCase( "MULTILINE" ) ) - defaultFlags |= Pattern.MULTILINE; - else if( flag.equalsIgnoreCase( "UNICODE_CASE" ) ) - defaultFlags |= Pattern.UNICODE_CASE; - else if( flag.equalsIgnoreCase( "UNIX_LINES" ) ) - defaultFlags |= Pattern.UNIX_LINES; - else - throw new ResolutionException( "\"flags\" contains an unrecognized flag: " + flag ); - } - } - - Object statesObject = json.get( "states" ); - if( statesObject == null ) - throw new ResolutionException( "Grammar does not contain \"states\" map" ); - - if( !( statesObject instanceof Map ) ) - throw new ResolutionException( "\"states\" must be a map" ); - - for( Map.Entry entry : ( (Map) statesObject ).entrySet() ) - { - String stateName = entry.getKey(); - Object stateObject = entry.getValue(); - if( !( stateObject instanceof Iterable ) ) - throw new ResolutionException( "State \"" + stateName + "\" must be an array" ); - - for( Iterable arguments : (Iterable>) stateObject ) - { - List argumentsList = new ArrayList(); - for( Object argument : (List) arguments ) - argumentsList.add( argument ); - - if( argumentsList.isEmpty() ) - throw new ResolutionException( "Entry in state \"" + stateName + "\" must have at least one argument" ); - - Object command = argumentsList.get( 0 ); - if( !( command instanceof String ) ) - throw new ResolutionException( "Entry in state \"" + stateName + "\" must have a string as the first argument" ); - - if( command.equals( "#include" ) ) - { - if( argumentsList.size() != 2 ) - throw new ResolutionException( "\"#include\" command in state \"" + stateName + "\" must have a string as an argument" ); - - Object includedState = argumentsList.get( 1 ); - if( !( includedState instanceof String ) ) - throw new ResolutionException( "\"#include\" command in state \"" + stateName + "\" must have a string as an argument" ); - - include( stateName, (String) includedState ); - } - else if( command.equals( "#using" ) ) - { - if( argumentsList.size() != 3 ) - throw new ResolutionException( "\"#using\" command in state \"" + stateName + "\" must have two strings as arguments" ); - - Object pattern = argumentsList.get( 1 ); - if( !( pattern instanceof String ) ) - throw new ResolutionException( "\"#using\" command in state \"" + stateName + "\" must have two strings as arguments" ); - - Object usingLexerName = argumentsList.get( 2 ); - if( !( usingLexerName instanceof String ) ) - throw new ResolutionException( "\"#using\" command in state \"" + stateName + "\" must have two strings as arguments" ); - - getState( stateName ).addDef( new UsingRuleDef( stateName, (String) pattern, (String) usingLexerName ) ); - } - else if( command.equals( "#save" ) ) - { - if( argumentsList.size() != 2 ) - throw new ResolutionException( "\"#save\" command in state \"" + stateName + "\" must have one string as an argument" ); - - Object savedStateName = argumentsList.get( 1 ); - if( !( savedStateName instanceof String ) ) - throw new ResolutionException( "\"#save\" command in state \"" + stateName + "\" must have one string as an argument" ); - - getState( stateName ).addDef( new SaveDef( stateName, (String) savedStateName ) ); - } - else - { - // Command is a pattern - String pattern = (String) command; - - if( pattern.startsWith( "#constant:" ) ) - { - // Concatenate - StringBuilder builder = new StringBuilder(); - String[] concatArguments = pattern.substring( 10 ).split( "," ); - for( String concatArgument : concatArguments ) - { - List strings = constants.get( concatArgument ); - if( strings == null ) - throw new ResolutionException( "Unknown constant \"" + concatArgument + "\" for #pattern in state \"" + stateName + "\" must have at least a token type as an argument" ); - for( String string : strings ) - builder.append( string ); - } - pattern = builder.toString(); - } - - if( argumentsList.size() < 2 ) - throw new ResolutionException( "Rule in state \"" + stateName + "\" must have at least a token type as an argument" ); - - Object tokenTypeNames = argumentsList.get( 1 ); - if( tokenTypeNames instanceof String ) - { - ArrayList list = new ArrayList( 1 ); - list.add( (String) tokenTypeNames ); - tokenTypeNames = list; - } - - if( !( tokenTypeNames instanceof List ) ) - throw new ResolutionException( "Expected token type name or array of token type names in rule in state \"" + stateName + "\"" ); - - if( argumentsList.size() == 2 ) - { - // Token rule - getState( stateName ).addDef( new TokenRuleDef( stateName, pattern, defaultFlags, (List) tokenTypeNames ) ); - } - else if( argumentsList.size() == 3 ) - { - // Change state token rule - Object nextStateNames = argumentsList.get( 2 ); - if( nextStateNames instanceof String ) - { - ArrayList list = new ArrayList( 1 ); - list.add( (String) nextStateNames ); - nextStateNames = list; - } - - if( !( nextStateNames instanceof List ) ) - throw new ResolutionException( "Expected state name or array of state names in rule in state \"" + stateName + "\"" ); - - getState( stateName ).addDef( new ChangeStateTokenRuleDef( stateName, pattern, defaultFlags, (List) tokenTypeNames, (List) nextStateNames ) ); - } - else - throw new ResolutionException( "Too many arguments for rule in state \"" + stateName + "\"" ); - } - } - } - } -} diff --git a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/RelativeState.java b/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/RelativeState.java deleted file mode 100644 index 25c0ca64c..000000000 --- a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/RelativeState.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license - */ - -package org.sikuli.idesupport.syntaxhighlight.grammar; - -/** - * @author Tal Liron - */ -public class RelativeState extends State -{ - // - // Construction - // - - public RelativeState( boolean push, int depth ) - { - super( push ? "#push" : "#pop" + ( depth > 1 ? ":" + depth : "" ) ); - this.push = push; - this.depth = depth; - } - - // - // Attributes - // - - public boolean isPush() - { - return push; - } - - public int getDepth() - { - return depth; - } - - // ////////////////////////////////////////////////////////////////////////// - // Private - - private final boolean push; - - private final int depth; -} diff --git a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/Rule.java b/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/Rule.java deleted file mode 100644 index 7739bf00b..000000000 --- a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/Rule.java +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license - */ - -package org.sikuli.idesupport.syntaxhighlight.grammar; - -/** - * @author Tal Liron - */ -public class Rule -{ -} diff --git a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/SaveRule.java b/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/SaveRule.java deleted file mode 100644 index 2eb944369..000000000 --- a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/SaveRule.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license - */ - -package org.sikuli.idesupport.syntaxhighlight.grammar; - -/** - * @author Tal Liron - */ -public class SaveRule extends Rule -{ - // - // Construction - // - - public SaveRule( State state ) - { - super(); - this.state = state; - } - - // - // Attributes - // - - public State getState() - { - return state; - } - - // ////////////////////////////////////////////////////////////////////////// - // Private - - private final State state; -} diff --git a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/State.java b/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/State.java deleted file mode 100644 index 24944e3d5..000000000 --- a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/State.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license - */ - -package org.sikuli.idesupport.syntaxhighlight.grammar; - -import java.util.ArrayList; -import java.util.List; - -import org.sikuli.idesupport.syntaxhighlight.NestedDef; - -/** - * @author Tal Liron - */ -public class State extends NestedDef -{ - // - // Construction - // - - public State( String name ) - { - super(); - this.name = name; - } - - public State( State state1, State state2 ) - { - this( state1.getName() + "+" + state2.getName() ); - include( state1 ); - include( state2 ); - } - - // - // Attributes - // - - public String getName() - { - return name; - } - - public List getRules() - { - return rules; - } - - // - // Operations - // - - public void addRule( Rule rule ) - { - rules.add( rule ); - } - - public void addRuleAt( int location, Rule rule ) - { - rules.add( location, rule ); - } - - public void include( State includedState ) - { - rules.addAll( includedState.rules ); - } - - public void includeAt( int location, State includedState ) - { - rules.addAll( location, includedState.rules ); - } - - // ////////////////////////////////////////////////////////////////////////// - // Private - - private final String name; - - private final List rules = new ArrayList(); -} diff --git a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/Token.java b/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/Token.java deleted file mode 100644 index c0013e419..000000000 --- a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/Token.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license - */ - -package org.sikuli.idesupport.syntaxhighlight.grammar; - -/** - * @author Tal Liron - */ -public class Token -{ - // - // Construction - // - - public Token( int pos, TokenType tokenType, String value ) - { - this.pos = pos; - this.tokenType = tokenType; - this.value = value; - } - - // - // Attributes - // - - public int getPos() - { - return pos; - } - - public TokenType getType() - { - return tokenType; - } - - public String getValue() - { - return value; - } - - // ////////////////////////////////////////////////////////////////////////// - // Private - - private final int pos; - - private final TokenType tokenType; - - private final String value; -} diff --git a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/TokenRule.java b/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/TokenRule.java deleted file mode 100644 index 534dead01..000000000 --- a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/TokenRule.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license - */ - -package org.sikuli.idesupport.syntaxhighlight.grammar; - -import java.util.List; -import java.util.regex.Pattern; - -/** - * @author Tal Liron - */ -public class TokenRule extends PatternRule -{ - // - // Construction - // - - public TokenRule( Pattern pattern, List tokenTypes ) - { - this( pattern, tokenTypes, (List) null ); - } - - public TokenRule( Pattern pattern, List tokenTypes, List nextStates ) - { - super( pattern ); - this.nextStates = nextStates; - this.tokenTypes = tokenTypes; - } - - // - // Attributes - // - - public List getTokenTypes() - { - return tokenTypes; - } - - public List getNextStates() - { - return nextStates; - } - - // ////////////////////////////////////////////////////////////////////////// - // Private - - private final List tokenTypes; - - private final List nextStates; -} diff --git a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/TokenType.java b/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/TokenType.java deleted file mode 100644 index 3aac8eb7e..000000000 --- a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/TokenType.java +++ /dev/null @@ -1,267 +0,0 @@ -/* - * Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license - */ - -package org.sikuli.idesupport.syntaxhighlight.grammar; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -/** - * @author Tal Liron - */ -public class TokenType -{ - // - // Constants - // - - public static final TokenType Token = create( "Token", "" ); - - // Main - - public static final TokenType Whitespace = create( "Whitespace", "w", Token ); - - public static final TokenType Text = create( "Text", "", Token ); - - public static final TokenType Error = create( "Error", "err", Token ); - - public static final TokenType Other = create( "Other", "x", Token ); - - // Keywords - - public static final TokenType Keyword = create( "Keyword", "k", Text ); - - public static final TokenType Keyword_Constant = create( "Keyword.Constant", "kc", Keyword ); - - public static final TokenType Keyword_Declaration = create( "Keyword.Declaration", "kd", Keyword ); - - public static final TokenType Keyword_Namespace = create( "Keyword.Namespace", "kn", Keyword ); - - public static final TokenType Keyword_Pseudo = create( "Keyword.Pseudo", "kp", Keyword ); - - public static final TokenType Keyword_Reserved = create( "Keyword.Reserved", "kr", Keyword ); - - public static final TokenType Keyword_Type = create( "Keyword.Type", "kt", Keyword ); - - // Names - - public static final TokenType Name = create( "Name", "n", Text ); - - public static final TokenType Name_Attribute = create( "Name.Attribute", "na", Name ); - - public static final TokenType Name_Builtin = create( "Name.Builtin", "nb", Name ); - - public static final TokenType Name_Builtin_Pseudo = create( "Name.Builtin.Pseudo", "bp", Name_Builtin ); - - public static final TokenType Name_Class = create( "Name.Class", "nc", Name ); - - public static final TokenType Name_Constant = create( "Name.Constant", "no", Name ); - - public static final TokenType Name_Decorator = create( "Name.Decorator", "nd", Name ); - - public static final TokenType Name_Entity = create( "Name.Entity", "ni", Name ); - - public static final TokenType Name_Exception = create( "Name.Exception", "ne", Name ); - - public static final TokenType Name_Function = create( "Name.Function", "nf", Name ); - - public static final TokenType Name_Property = create( "Name.Property", "py", Name ); - - public static final TokenType Name_Label = create( "Name.Label", "nl", Name ); - - public static final TokenType Name_Namespace = create( "Name.Namespace", "nn", Name ); - - public static final TokenType Name_Other = create( "Name.Other", "nx", Name ); - - public static final TokenType Name_Tag = create( "Name.Tag", "nt", Name ); - - public static final TokenType Name_Variable = create( "Name.Variable", "nv", Name ); - - public static final TokenType Name_Variable_Class = create( "Name.Variable.Class", "vc", Name_Variable ); - - public static final TokenType Name_Variable_Global = create( "Name.Variable.Global", "vg", Name_Variable ); - - public static final TokenType Name_Variable_Instance = create( "Name.Variable.Instance", "vi", Name_Variable ); - - // Literals - - public static final TokenType Literal = create( "Literal", "l", Text ); - - public static final TokenType Literal_Date = create( "Literal.Date", "ld", Literal ); - - // Strings - - public static final TokenType String = create( "String", "s", Text ); - - public static final TokenType String_Backtick = create( "String.Backtick", "sb", String ); - - public static final TokenType String_Char = create( "String.Char", "sc", String ); - - public static final TokenType String_Doc = create( "String.Doc", "sd", String ); - - public static final TokenType String_Double = create( "String.Double", "s2", String ); - - public static final TokenType String_Escape = create( "String.Escape", "se", String ); - - public static final TokenType String_Heredoc = create( "String.Heredoc", "sh", String ); - - public static final TokenType String_Interpol = create( "String.Interpol", "si", String ); - - public static final TokenType String_Other = create( "String.Other", "sx", String ); - - public static final TokenType String_Regex = create( "String.Regex", "sr", String ); - - public static final TokenType String_Single = create( "String.Single", "s1", String ); - - public static final TokenType String_Symbol = create( "String.Symbol", "ss", String ); - - // Numbers - - public static final TokenType Number = create( "Number", "m", Text ); - - public static final TokenType Number_Float = create( "Number.Float", "mf", Number ); - - public static final TokenType Number_Hex = create( "Number.Hex", "mh", Number ); - - public static final TokenType Number_Integer = create( "Number.Integer", "mi", Number ); - - public static final TokenType Number_Integer_Long = create( "Number.Integer.Long", "il", Number_Integer ); - - public static final TokenType Number_Oct = create( "Number.Oct", "mo", Number ); - - // Operators - - public static final TokenType Operator = create( "Operator", "o", Text ); - - public static final TokenType Operator_Word = create( "Operator.Word", "ow", Operator ); - - // Punctuation - - public static final TokenType Punctuation = create( "Punctuation", "p", Text ); - - // Comments - - public static final TokenType Comment = create( "Comment", "c", Text ); - - public static final TokenType Comment_Multiline = create( "Comment.Multiline", "cm", Comment ); - - public static final TokenType Comment_Preproc = create( "Comment.Preproc", "cp", Comment ); - - public static final TokenType Comment_Single = create( "Comment.Single", "c1", Comment ); - - public static final TokenType Comment_Special = create( "Comment.Special", "cs", Comment ); - - // Generics - - public static final TokenType Generic = create( "Generic", "g", Text ); - - public static final TokenType Generic_Deleted = create( "Generic.Deleted", "gd", Generic ); - - public static final TokenType Generic_Emph = create( "Generic.Emph", "ge", Generic ); - - public static final TokenType Generic_Error = create( "Generic.Error", "gr", Generic ); - - public static final TokenType Generic_Heading = create( "Generic.Heading", "gh", Generic ); - - public static final TokenType Generic_Inserted = create( "Generic.Inserted", "gi", Generic ); - - public static final TokenType Generic_Output = create( "Generic.Output", "go", Generic ); - - public static final TokenType Generic_Prompt = create( "Generic.Prompt", "gp", Generic ); - - public static final TokenType Generic_Strong = create( "Generic.Strong", "gs", Generic ); - - public static final TokenType Generic_Subheading = create( "Generic.Subheading", "gu", Generic ); - - public static final TokenType Generic_Traceback = create( "Generic.Traceback", "gt", Generic ); - - // - // Static attributes - // - - public static TokenType getTokenTypeByName( String name ) - { - return tokenTypesByName.get( name ); - } - - public static TokenType getTokenTypeByShortName( String shortName ) - { - return tokenTypesByShortName.get( shortName ); - } - - public static Collection getTokenTypes() - { - return tokenTypesByName.values(); - } - - // - // Attributes - // - - public String getName() - { - return name; - } - - public String getShortName() - { - return shortName; - } - - public TokenType getParent() - { - return parent; - } - - // - // Object - // - - @Override - public String toString() - { - return name; - } - - // ////////////////////////////////////////////////////////////////////////// - // Private - - private static Map tokenTypesByName; - - private static Map tokenTypesByShortName; - - private static final TokenType create( String name, String shortName ) - { - return create( name, shortName, null ); - } - - private static final TokenType create( String name, String shortName, TokenType parent ) - { - TokenType tokenType = new TokenType( name, shortName, parent ); - - if( tokenTypesByName == null ) - tokenTypesByName = new HashMap(); - if( tokenTypesByShortName == null ) - tokenTypesByShortName = new HashMap(); - - tokenTypesByName.put( name, tokenType ); - tokenTypesByShortName.put( shortName, tokenType ); - - return tokenType; - } - - private final String name; - - private final String shortName; - - private final TokenType parent; - - private TokenType( String name, String shortName, TokenType parent ) - { - this.name = name; - this.shortName = shortName; - this.parent = parent; - } -} diff --git a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/UsingRule.java b/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/UsingRule.java deleted file mode 100644 index 97a0df981..000000000 --- a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/UsingRule.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license - */ - -package org.sikuli.idesupport.syntaxhighlight.grammar; - -import java.util.regex.Pattern; - -/** - * @author Tal Liron - */ -public class UsingRule extends PatternRule -{ - // - // Construction - // - - public UsingRule( Pattern pattern, Lexer lexer ) - { - super( pattern ); - this.lexer = lexer; - } - - // - // Attributes - // - - public Lexer getLexer() - { - return lexer; - } - - // ////////////////////////////////////////////////////////////////////////// - // Private - - private final Lexer lexer; -} diff --git a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/def/ChangeStateTokenRuleDef.java b/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/def/ChangeStateTokenRuleDef.java deleted file mode 100644 index 867a1f406..000000000 --- a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/def/ChangeStateTokenRuleDef.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license - */ - -package org.sikuli.idesupport.syntaxhighlight.grammar.def; - -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Pattern; - -import org.sikuli.idesupport.syntaxhighlight.ResolutionException; -import org.sikuli.idesupport.syntaxhighlight.grammar.Grammar; -import org.sikuli.idesupport.syntaxhighlight.grammar.Rule; -import org.sikuli.idesupport.syntaxhighlight.grammar.State; -import org.sikuli.idesupport.syntaxhighlight.grammar.TokenRule; -import org.sikuli.idesupport.syntaxhighlight.grammar.TokenType; - -/** - * @author Tal Liron - */ -public class ChangeStateTokenRuleDef extends TokenRuleDef -{ - // - // Construction - // - - public ChangeStateTokenRuleDef( String stateName, String pattern, int flags, List tokenTypeNames, List nextStateNames ) - { - super( stateName, pattern, flags, tokenTypeNames ); - this.nextStateNames = nextStateNames; - } - - public ChangeStateTokenRuleDef( String stateName, String pattern, int flags, String[] tokenTypeNames, String... nextStateNames ) - { - super( stateName, pattern, flags, tokenTypeNames ); - ArrayList list = new ArrayList( nextStateNames.length ); - for( String nextStateName : nextStateNames ) - list.add( nextStateName ); - this.nextStateNames = list; - } - - // - // Def - // - - @Override - public boolean resolve( Grammar grammar ) throws ResolutionException - { - if( grammar.resolveStates( nextStateNames ) != null ) - return super.resolve( grammar ); - else - { - if( placeHolder == null ) - { - placeHolder = new Rule(); - State state = grammar.getState( stateName ); - state.addRule( placeHolder ); - } - return false; - } - } - - // - // TokenRuleDef - // - - @Override - protected TokenRule createTokenRule( Pattern pattern, List tokenTypes, Grammar grammar ) throws ResolutionException - { - return new TokenRule( pattern, tokenTypes, grammar.resolveStates( nextStateNames ) ); - } - - // ////////////////////////////////////////////////////////////////////////// - // Private - - private final List nextStateNames; -} diff --git a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/def/IncludeDef.java b/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/def/IncludeDef.java deleted file mode 100644 index fd1bb96c1..000000000 --- a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/def/IncludeDef.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license - */ - -package org.sikuli.idesupport.syntaxhighlight.grammar.def; - -import org.sikuli.idesupport.syntaxhighlight.Def; -import org.sikuli.idesupport.syntaxhighlight.ResolutionException; -import org.sikuli.idesupport.syntaxhighlight.grammar.Grammar; -import org.sikuli.idesupport.syntaxhighlight.grammar.Rule; -import org.sikuli.idesupport.syntaxhighlight.grammar.State; - -/** - * @author Tal Liron - */ -public class IncludeDef extends StateDef -{ - public IncludeDef( String stateName, String includedStateName ) - { - super( stateName ); - this.includedStateName = includedStateName; - } - - // - // Def - // - - @Override - public boolean resolve( Grammar grammar ) throws ResolutionException - { - State state = grammar.getState( stateName ); - State includedState = grammar.getState( includedStateName ); - - // Only include a resolved state - if( includedState.isResolved() ) - { - if( placeHolder != null ) - { - int location = state.getRules().indexOf( placeHolder ); - state.getRules().remove( placeHolder ); - state.includeAt( location, includedState ); - } - else - state.include( includedState ); - - resolved = true; - return true; - } - else if( placeHolder == null ) - { - // Remember location - placeHolder = new Rule(); - state.addRule( placeHolder ); - } - - return false; - } - - @Override - public Def getCause( Grammar grammar ) - { - return grammar.getState( includedStateName ).getCause( grammar ); - } - - // - // Object - // - - @Override - public String toString() - { - return super.toString() + " " + stateName + ", " + includedStateName; - } - - // ////////////////////////////////////////////////////////////////////////// - // Private - - private final String includedStateName; -} diff --git a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/def/SaveDef.java b/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/def/SaveDef.java deleted file mode 100644 index c9dc041e3..000000000 --- a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/def/SaveDef.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license - */ - -package org.sikuli.idesupport.syntaxhighlight.grammar.def; - -import org.sikuli.idesupport.syntaxhighlight.ResolutionException; -import org.sikuli.idesupport.syntaxhighlight.grammar.Grammar; -import org.sikuli.idesupport.syntaxhighlight.grammar.Rule; -import org.sikuli.idesupport.syntaxhighlight.grammar.SaveRule; -import org.sikuli.idesupport.syntaxhighlight.grammar.State; - -/** - * @author Tal Liron - */ -public class SaveDef extends StateDef -{ - public SaveDef( String stateName, String savedStateName ) - { - super( stateName ); - this.savedStateName = savedStateName; - } - - // - // Def - // - - @Override - public boolean resolve( Grammar grammar ) throws ResolutionException - { - State state = grammar.getState( stateName ); - State savedState = grammar.getState( savedStateName ); - - // Only include a resolved state - if( savedState.isResolved() ) - { - if( placeHolder != null ) - { - int location = state.getRules().indexOf( placeHolder ); - state.getRules().remove( placeHolder ); - state.addRuleAt( location, new SaveRule( savedState ) ); - } - else - state.addRule( new SaveRule( savedState ) ); - - resolved = true; - return true; - } - else if( placeHolder == null ) - { - // Remember location - placeHolder = new Rule(); - state.addRule( placeHolder ); - } - - return false; - } - - // - // Object - // - - @Override - public String toString() - { - return super.toString() + " " + stateName + ", " + savedStateName; - } - - // ////////////////////////////////////////////////////////////////////////// - // Private - - private final String savedStateName; -} diff --git a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/def/StateDef.java b/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/def/StateDef.java deleted file mode 100644 index 8c7411795..000000000 --- a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/def/StateDef.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license - */ - -package org.sikuli.idesupport.syntaxhighlight.grammar.def; - -import org.sikuli.idesupport.syntaxhighlight.Def; -import org.sikuli.idesupport.syntaxhighlight.grammar.Grammar; -import org.sikuli.idesupport.syntaxhighlight.grammar.Rule; - -public abstract class StateDef extends Def -{ - // - // Construction - // - - public StateDef( String stateName ) - { - this.stateName = stateName; - } - - // - // Attributes - // - - public String getStateName() - { - return stateName; - } - - // - // Object - // - - @Override - public String toString() - { - return super.toString() + " " + stateName; - } - - // ////////////////////////////////////////////////////////////////////////// - // Protected - - protected final String stateName; - - protected Rule placeHolder = null; -} diff --git a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/def/TokenRuleDef.java b/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/def/TokenRuleDef.java deleted file mode 100644 index 6d3142613..000000000 --- a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/def/TokenRuleDef.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license - */ - -package org.sikuli.idesupport.syntaxhighlight.grammar.def; - -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Pattern; -import java.util.regex.PatternSyntaxException; - -import org.sikuli.idesupport.syntaxhighlight.ResolutionException; -import org.sikuli.idesupport.syntaxhighlight.grammar.Grammar; -import org.sikuli.idesupport.syntaxhighlight.grammar.State; -import org.sikuli.idesupport.syntaxhighlight.grammar.TokenRule; -import org.sikuli.idesupport.syntaxhighlight.grammar.TokenType; - -/** - * @author Tal Liron - */ -public class TokenRuleDef extends StateDef -{ - // - // Construction - // - - public TokenRuleDef( String stateName, String pattern, int flags, List tokenTypeNames ) - { - super( stateName ); - this.pattern = pattern; - this.flags = flags; - this.tokenTypeNames = tokenTypeNames; - } - - public TokenRuleDef( String stateName, String pattern, int flags, String... tokenTypeNames ) - { - super( stateName ); - this.pattern = pattern; - this.flags = flags; - ArrayList list = new ArrayList( tokenTypeNames.length ); - for( String tokenTypeName : tokenTypeNames ) - list.add( tokenTypeName ); - this.tokenTypeNames = list; - } - - // - // Attributes - // - - public String getPattern() - { - return pattern; - } - - public List getTokenTypeNames() - { - return tokenTypeNames; - } - - // - // Def - // - - @Override - public boolean resolve( Grammar grammar ) throws ResolutionException - { - Pattern pattern; - try - { - //pattern = Pattern.compile( this.pattern, Pattern.MULTILINE | Pattern.DOTALL ); - pattern = Pattern.compile( this.pattern, flags ); - } - catch( PatternSyntaxException x ) - { - throw new ResolutionException( "RegEx syntax error: " + this.pattern, x ); - } - - ArrayList tokenTypes = new ArrayList(); - for( String tokenTypeName : tokenTypeNames ) - { - TokenType tokenType = TokenType.getTokenTypeByName( tokenTypeName ); - if( tokenType == null ) - throw new ResolutionException( "Unknown token type: " + tokenTypeName ); - tokenTypes.add( tokenType ); - } - - TokenRule rule = createTokenRule( pattern, tokenTypes, grammar ); - State state = grammar.getState( stateName ); - if( placeHolder != null ) - { - int location = state.getRules().indexOf( placeHolder ); - state.getRules().remove( placeHolder ); - state.addRuleAt( location, rule ); - } - else - state.addRule( rule ); - - resolved = true; - return true; - } - - // - // Object - // - - @Override - public String toString() - { - return super.toString() + ", " + pattern + ", " + tokenTypeNames; - } - - // ////////////////////////////////////////////////////////////////////////// - // Protected - - protected TokenRule createTokenRule( Pattern pattern, List tokenTypes, Grammar grammar ) throws ResolutionException - { - return new TokenRule( pattern, tokenTypes ); - } - - // ////////////////////////////////////////////////////////////////////////// - // Private - - private final String pattern; - - private final int flags; - - private final List tokenTypeNames; -} diff --git a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/def/UsingRuleDef.java b/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/def/UsingRuleDef.java deleted file mode 100644 index f90c41ff2..000000000 --- a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/grammar/def/UsingRuleDef.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license - */ - -package org.sikuli.idesupport.syntaxhighlight.grammar.def; - -import java.util.regex.Pattern; -import java.util.regex.PatternSyntaxException; - -import org.sikuli.idesupport.syntaxhighlight.ResolutionException; -import org.sikuli.idesupport.syntaxhighlight.grammar.Grammar; -import org.sikuli.idesupport.syntaxhighlight.grammar.Lexer; -import org.sikuli.idesupport.syntaxhighlight.grammar.State; -import org.sikuli.idesupport.syntaxhighlight.grammar.UsingRule; - -/** - * @author Tal Liron - */ -public class UsingRuleDef extends StateDef -{ - // - // Construction - // - - public UsingRuleDef( String stateName, String pattern, String usingLexerName ) - { - super( stateName ); - this.pattern = pattern; - this.usingLexerName = usingLexerName; - } - - // - // Attributes - // - - public String getPattern() - { - return pattern; - } - - public String getUsingLexerName() - { - return usingLexerName; - } - - // - // Def - // - - @Override - public boolean resolve( Grammar grammar ) throws ResolutionException - { - Pattern pattern; - try - { - pattern = Pattern.compile( this.pattern, Pattern.MULTILINE | Pattern.DOTALL ); - } - catch( PatternSyntaxException x ) - { - throw new ResolutionException( "RegEx syntax error: " + this.pattern, x ); - } - - Lexer usingLexer = Lexer.getByName( usingLexerName ); - UsingRule rule = new UsingRule( pattern, usingLexer ); - State state = grammar.getState( stateName ); - state.addRule( rule ); - - resolved = true; - return true; - } - - // - // Object - // - - @Override - public String toString() - { - return super.toString() + ", " + pattern + ", " + usingLexerName; - } - - // ////////////////////////////////////////////////////////////////////////// - // Protected - - // ////////////////////////////////////////////////////////////////////////// - // Private - - private final String pattern; - - private final String usingLexerName; -} diff --git a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/scan/EndOfText.java b/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/scan/EndOfText.java deleted file mode 100644 index 966068ff0..000000000 --- a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/scan/EndOfText.java +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license - */ - -package org.sikuli.idesupport.syntaxhighlight.scan; - -/** - * @author Tal Liron - */ -public class EndOfText extends Exception -{ - private static final long serialVersionUID = 1L; -} diff --git a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/scan/Scanner.java b/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/scan/Scanner.java deleted file mode 100644 index 713ff1586..000000000 --- a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/scan/Scanner.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license - */ - -package org.sikuli.idesupport.syntaxhighlight.scan; - -import java.util.HashMap; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * @author Tal Liron - */ -public abstract class Scanner -{ - // - // Construction - // - - public Scanner( String text, int flags ) - { - this.data = text; - this.flags = flags; - dataLength = data.length(); - } - - // - // Attributes - // - - public int getStartPos() - { - return startPos; - } - - public int getPos() - { - return pos; - } - - public String getLast() - { - return last; - } - - public String getMatch() - { - return match; - } - - public boolean isEos() - { - return pos >= dataLength; - } - - public Matcher check( String pattern ) throws EndOfText - { - if( isEos() ) - throw new EndOfText(); - Pattern re = patternCache.get( pattern ); - if( re == null ) - { - re = Pattern.compile( pattern, flags ); - patternCache.put( pattern, re ); - } - return re.matcher( data.substring( pos ) ); - } - - public boolean test( String pattern ) throws EndOfText - { - return check( pattern ).matches(); - } - - public boolean scan( String pattern ) throws EndOfText - { - if( isEos() ) - throw new EndOfText(); - Pattern re = patternCache.get( pattern ); - if( re == null ) - { - re = Pattern.compile( pattern, flags ); - patternCache.put( pattern, re ); - } - last = match; - Matcher matcher = re.matcher( data.substring( pos ) ); - if( !matcher.matches() ) - return false; - startPos = matcher.start(); - pos = matcher.end(); - match = matcher.group(); - return true; - } - - public boolean getChar() throws EndOfText - { - return scan( "." ); - } - - // ////////////////////////////////////////////////////////////////////////// - // Private - - private static final Map patternCache = new HashMap(); - - private final int flags; - - private final int dataLength; - - private String data; - - private int startPos, pos; - - private String match, last; -} diff --git a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/style/ColorStyleElement.java b/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/style/ColorStyleElement.java deleted file mode 100644 index be0c96f8f..000000000 --- a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/style/ColorStyleElement.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license - */ - -package org.sikuli.idesupport.syntaxhighlight.style; - -/** - * @author Tal Liron - */ -public class ColorStyleElement extends StyleElement -{ - // - // Types - // - - public enum Type - { - Foreground, Background, Border - } - - // - // Static attributes - // - - public static ColorStyleElement getColorStyleElementByName( String name ) - { - if( name.startsWith( "bg:" ) ) - return background( name.substring( 3 ) ); - if( name.startsWith( "border:" ) ) - return border( name.substring( 7 ) ); - return foreground( name ); - } - - public static ColorStyleElement foreground( String color ) - { - return new ColorStyleElement( color, Type.Foreground, color ); - } - - public static ColorStyleElement background( String color ) - { - return new ColorStyleElement( "bg:" + color, Type.Background, color ); - } - - public static ColorStyleElement border( String color ) - { - return new ColorStyleElement( "border:" + color, Type.Border, color ); - } - - // - // Attributes - // - - public String getColor() - { - return color; - } - - public Type getType() - { - return type; - } - - // ////////////////////////////////////////////////////////////////////////// - // Protected - - protected ColorStyleElement( String name, Type type, String color ) - { - super( name ); - this.type = type; - this.color = color; - } - - // ////////////////////////////////////////////////////////////////////////// - // Private - - private final String color; - - private final Type type; -} diff --git a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/style/EffectStyleElement.java b/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/style/EffectStyleElement.java deleted file mode 100644 index 12c5dcae9..000000000 --- a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/style/EffectStyleElement.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license - */ - -package org.sikuli.idesupport.syntaxhighlight.style; - -/** - * @author Tal Liron - */ -public class EffectStyleElement extends StyleElement -{ - // - // Constants - // - - public static final EffectStyleElement Bold = create( "bold" ); - - public static final EffectStyleElement NoBold = create( "nobold" ); - - public static final EffectStyleElement Italic = create( "italic" ); - - public static final EffectStyleElement NoItalic = create( "noitalic" ); - - public static final EffectStyleElement Underline = create( "underline" ); - - public static final EffectStyleElement NoUnderline = create( "nounderline" ); - - // ////////////////////////////////////////////////////////////////////////// - // Protected - - protected EffectStyleElement( String name ) - { - super( name ); - } - - private static EffectStyleElement create( String name ) - { - EffectStyleElement fontStyleElement = new EffectStyleElement( name ); - add( fontStyleElement ); - return fontStyleElement; - } -} diff --git a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/style/FontStyleElement.java b/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/style/FontStyleElement.java deleted file mode 100644 index e822ae1f2..000000000 --- a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/style/FontStyleElement.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license - */ - -package org.sikuli.idesupport.syntaxhighlight.style; - -/** - * @author Tal Liron - */ -public class FontStyleElement extends StyleElement -{ - // - // Constants - // - - public static final FontStyleElement Roman = create( "roman" ); - - public static final FontStyleElement Sans = create( "sans" ); - - public static final FontStyleElement Mono = create( "mono" ); - - // ////////////////////////////////////////////////////////////////////////// - // Protected - - protected FontStyleElement( String name ) - { - super( name ); - } - - private static FontStyleElement create( String name ) - { - FontStyleElement fontStyleElement = new FontStyleElement( name ); - add( fontStyleElement ); - return fontStyleElement; - } -} diff --git a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/style/Style.java b/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/style/Style.java deleted file mode 100644 index a50969a1a..000000000 --- a/IDE/src/main/java/org/sikuli/idesupport/syntaxhighlight/style/Style.java +++ /dev/null @@ -1,239 +0,0 @@ -/* - * Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license - */ - -package org.sikuli.idesupport.syntaxhighlight.style; - -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.sikuli.idesupport.syntaxhighlight.Jygments; -import org.sikuli.idesupport.syntaxhighlight.NestedDef; -import org.sikuli.idesupport.syntaxhighlight.ResolutionException; -import org.sikuli.idesupport.syntaxhighlight.Util; -import org.sikuli.idesupport.syntaxhighlight.grammar.TokenType; -import org.sikuli.idesupport.syntaxhighlight.style.def.StyleElementDef; - -/** - * @author Tal Liron - */ -public class Style extends NestedDef