diff --git a/devTools/javaSanityCheck/src/DisallowedTagException.java b/devTools/javaSanityCheck/src/DisallowedTagException.java index f4cc75e736b162192a5f18bbc55a10edb21eaa38..cd479fbdf5f9c8b42a9271b8c0049cba10bcb72a 100644 --- a/devTools/javaSanityCheck/src/DisallowedTagException.java +++ b/devTools/javaSanityCheck/src/DisallowedTagException.java @@ -2,7 +2,7 @@ package org.arkerthan.sanityCheck; public class DisallowedTagException extends RuntimeException { - public DisallowedTagException(String tag) { - super(tag); - } + public DisallowedTagException(String tag) { + super(tag); + } } diff --git a/devTools/javaSanityCheck/src/Main.java b/devTools/javaSanityCheck/src/Main.java index eea3a4ff611203b0025cd29ce1fe431447f80e1c..d8af45777314f08b03eb5f471be4cdb9ba72f703 100644 --- a/devTools/javaSanityCheck/src/Main.java +++ b/devTools/javaSanityCheck/src/Main.java @@ -14,306 +14,306 @@ import java.util.*; public class Main { - public static TagSearchTree<Tag> htmlTags, twineTags; - private static String currentFile; - private static int currentLine, currentPosition; - private static Stack<Element> stack; - private static List<SyntaxError> errors = new LinkedList<>(); - private static String[] excluded; - - public static void main(String[] args) { - //setup - setupExclude(); - setupHtmlTags(); - setupTwineTags(); - Path workingDir = Paths.get("").toAbsolutePath(); - - //actual sanityCheck - runSanityCheckInDirectory(workingDir, new File("src/")); - - //handle errors - for (SyntaxError e : - errors) { - System.out.println(e.getError()); - } - } - - - /** - * Goes through the whole directory including subdirectories and runs - * sanityCheck() on all .tw files - * - * @param dir to be checked - */ - private static void runSanityCheckInDirectory(Path workingDir, File dir) { - //subdirectories are checked recursively - - try { - for (File file : dir.listFiles()) { - if (file.isFile()) { //run sanityCheck if file is a .tw file - String path = file.getAbsolutePath(); - if (path.endsWith(".tw")) { - sanityCheck(workingDir.relativize(file.toPath())); - } - } else if (file.isDirectory()) { - runSanityCheckInDirectory(workingDir, file.getAbsoluteFile()); - } - } - } catch (NullPointerException e) { - e.printStackTrace(); - System.err.println("Couldn't find directory " + currentFile); - System.exit(-1); - } - } - - /** - * Runs the sanity check for one file. Does not run if file is excluded. - * - * @param path file to be checked - */ - private static void sanityCheck(Path path) { - File file = path.toFile(); - - // replace this with a known encoding if possible - Charset encoding = Charset.defaultCharset(); - - if (!excluded(file.getPath())) { - try { - currentFile = file.getPath(); - currentLine = 1; - stack = new Stack<>(); - - //actually opening and reading the file - try (InputStream in = new FileInputStream(file); - Reader reader = new InputStreamReader(in, encoding); - // buffer for efficiency - Reader buffer = new BufferedReader(reader)) { - handleCharacters(buffer); - } - } catch (IOException e) { - System.err.println("Couldn't read " + file); - } - } - } - - /** - * sets up the alphabetical search tree for fast access of HTML tags later - */ - private static void setupHtmlTags() { - //load HTML tags into a list - List<Tag> TagsList = new LinkedList<>(); - try { - - Files.lines(new File("devTools/javaSanityCheck/htmlTags").toPath()).map(String::trim) - .filter(s -> !s.startsWith("#")) - .forEach(s -> TagsList.add(parseTag(s))); - } catch (IOException e) { - System.err.println("Couldn't read devTools/javaSanityCheck/htmlTags"); - } - - //turn List into alphabetical search tree - try { - htmlTags = new TagSearchTree(TagsList); - } catch (ArrayIndexOutOfBoundsException e) { - System.err.println("Illegal Character in devTools/javaSanityCheck/htmlTags"); - System.exit(-1); - } - } - - /** - * sets up the alphabetical search tree for fast access of twine tags later - */ - private static void setupTwineTags() { - //load twine tags into a list - List<Tag> TagsList = new LinkedList<>(); - try { - - Files.lines(new File("devTools/javaSanityCheck/twineTags").toPath()).map(String::trim) - .filter(s -> !s.startsWith("#")) - .forEach(s -> TagsList.add(parseTag(s))); - } catch (IOException e) { - System.err.println("Couldn't read devTools/javaSanityCheck/twineTags"); - } - - //turn List into alphabetical search tree - try { - twineTags = new TagSearchTree(TagsList); - } catch (ArrayIndexOutOfBoundsException e) { - System.err.println("Illegal Character in devTools/javaSanityCheck/twineTags"); - System.exit(-1); - } - } - - /** - * Turns a string into a Tag - * ";1" at the end of the String indicates that the tag needs to be closed later - * - * @param s tag as String - * @return tag as Tag - */ - private static Tag parseTag(String s) { - String[] st = s.split(";"); - if (st.length > 1 && st[1].equals("1")) { - return new Tag(st[0], false); - } - return new Tag(st[0], true); - } - - /** - * sets up the excluded array. - */ - private static void setupExclude() { - //load excluded files - List<String> excludedList = new ArrayList<>(); - try { - Files.lines(new File("devTools/javaSanityCheck/excluded").toPath()).map(String::trim) - .filter(s -> !s.startsWith("#")) - .forEach(excludedList::add); - } catch (IOException e) { - System.err.println("Couldn't read devTools/javaSanityCheck/excluded"); - } - - //turn excluded files into an array and change them to windows style if needed - if (isWindows()) { - excluded = new String[excludedList.size()]; - int i = 0; - for (String s : - excludedList) { - excluded[i++] = s.replaceAll("/", "\\\\"); - } - } else { - excluded = excludedList.toArray(new String[0]); - } - } - - /** - * @return whether OS is Windows or not - */ - private static boolean isWindows() { - return (System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("windows")); - } - - /** - * checks if a file or directory is excluded from the sanity check - * - * @param s file/directory to be checked - * @return whether it is excluded or not - */ - private static boolean excluded(String s) { - for (String ex : - excluded) { - if (s.startsWith(ex)) return true; - } - return false; - } - - /** - * Reads the file character by character. - * - * @param reader reader that is read - * @throws IOException thrown if the file can't be read - */ - private static void handleCharacters(Reader reader) throws IOException { - int r; - while ((r = reader.read()) != -1) { - char c = (char) r; - handleCharacter(c); - } - } - - /** - * Handles a single character - * - * @param c next character - */ - private static void handleCharacter(char c) { - //updating position - currentPosition++; - if (c == '\n') { - currentLine++; - currentPosition = 1; - } - - //try applying to the innermost element - if (!stack.empty()) { - int change; - try { - change = stack.peek().handleChar(c); - } catch (SyntaxError e) { - change = e.getChange(); - addError(e); - } - - //change greater 0 means the innermost element did some work - if (change > 0) { - //2 means the Element is complete - if (change == 2) { - //remove the topmost element from stack since it is complete - stack.pop(); - return; - } - //3 means the Element is complete and part of a two tag system - if (change == 3) { - //remove the topmost element from stack since it is complete - KnownElement k = stack.pop().getKnownElement(); - /*if (k.isOpening()) { - stack.push(k); - } else */ - if (k.isClosing()) { - if (stack.empty()) { - addError(new SyntaxError("Closed tag " + k.getShortDescription() + " without having any open tags.", -2)); - } else if (stack.peek() instanceof KnownElement) { - KnownElement kFirst = (KnownElement) stack.pop(); - if (!kFirst.isMatchingElement(k)) { - addError(new SyntaxError("Opening tag " + kFirst.getShortDescription() + - " does not match closing tag " + k.getShortDescription() + ".", -2)); - } - //stack.pop(); - } else { - addError(new SyntaxError("Closing tag " + k.getShortDescription() + " inside " + - "another tag: " + stack.peek().getShortDescription(), -2, true)); - } - } - if (k.isOpening()) { - stack.push(k); - } - return; - } - if (change == 4) { - stack.pop(); - } else { - return; - } - } - } - - - //innermost element was uninterested, trying to find matching element - switch (c) { - //case '@': - // stack.push(new AtElement(currentLine, currentPosition)); - //break; - case '<': - stack.push(new AngleBracketElement(currentLine, currentPosition)); - break; - //case '>': - //addError(new SyntaxError("Dangling \">\", current innermost: " + (stack.empty() ? "null" : stack.peek().getShortDescription()), -2)); - //break; - case '/': - stack.push(new CommentElement(currentLine, currentPosition)); - break; - } - } - - /** - * add an error to the error list - * - * @param e new error - */ - private static void addError(SyntaxError e) { - e.setFile(currentFile); - e.setLine(currentLine); - e.setPosition(currentPosition); - errors.add(e); - } + public static TagSearchTree<Tag> htmlTags, twineTags; + private static String currentFile; + private static int currentLine, currentPosition; + private static Stack<Element> stack; + private static List<SyntaxError> errors = new LinkedList<>(); + private static String[] excluded; + + public static void main(String[] args) { + //setup + setupExclude(); + setupHtmlTags(); + setupTwineTags(); + Path workingDir = Paths.get("").toAbsolutePath(); + + //actual sanityCheck + runSanityCheckInDirectory(workingDir, new File("src/")); + + //handle errors + for (SyntaxError e : + errors) { + System.out.println(e.getError()); + } + } + + + /** + * Goes through the whole directory including subdirectories and runs + * sanityCheck() on all .tw files + * + * @param dir to be checked + */ + private static void runSanityCheckInDirectory(Path workingDir, File dir) { + //subdirectories are checked recursively + + try { + for (File file : dir.listFiles()) { + if (file.isFile()) { //run sanityCheck if file is a .tw file + String path = file.getAbsolutePath(); + if (path.endsWith(".tw")) { + sanityCheck(workingDir.relativize(file.toPath())); + } + } else if (file.isDirectory()) { + runSanityCheckInDirectory(workingDir, file.getAbsoluteFile()); + } + } + } catch (NullPointerException e) { + e.printStackTrace(); + System.err.println("Couldn't find directory " + currentFile); + System.exit(-1); + } + } + + /** + * Runs the sanity check for one file. Does not run if file is excluded. + * + * @param path file to be checked + */ + private static void sanityCheck(Path path) { + File file = path.toFile(); + + // replace this with a known encoding if possible + Charset encoding = Charset.defaultCharset(); + + if (!excluded(file.getPath())) { + try { + currentFile = file.getPath(); + currentLine = 1; + stack = new Stack<>(); + + //actually opening and reading the file + try (InputStream in = new FileInputStream(file); + Reader reader = new InputStreamReader(in, encoding); + // buffer for efficiency + Reader buffer = new BufferedReader(reader)) { + handleCharacters(buffer); + } + } catch (IOException e) { + System.err.println("Couldn't read " + file); + } + } + } + + /** + * sets up the alphabetical search tree for fast access of HTML tags later + */ + private static void setupHtmlTags() { + //load HTML tags into a list + List<Tag> TagsList = new LinkedList<>(); + try { + + Files.lines(new File("devTools/javaSanityCheck/htmlTags").toPath()).map(String::trim) + .filter(s -> !s.startsWith("#")) + .forEach(s -> TagsList.add(parseTag(s))); + } catch (IOException e) { + System.err.println("Couldn't read devTools/javaSanityCheck/htmlTags"); + } + + //turn List into alphabetical search tree + try { + htmlTags = new TagSearchTree(TagsList); + } catch (ArrayIndexOutOfBoundsException e) { + System.err.println("Illegal Character in devTools/javaSanityCheck/htmlTags"); + System.exit(-1); + } + } + + /** + * sets up the alphabetical search tree for fast access of twine tags later + */ + private static void setupTwineTags() { + //load twine tags into a list + List<Tag> TagsList = new LinkedList<>(); + try { + + Files.lines(new File("devTools/javaSanityCheck/twineTags").toPath()).map(String::trim) + .filter(s -> !s.startsWith("#")) + .forEach(s -> TagsList.add(parseTag(s))); + } catch (IOException e) { + System.err.println("Couldn't read devTools/javaSanityCheck/twineTags"); + } + + //turn List into alphabetical search tree + try { + twineTags = new TagSearchTree(TagsList); + } catch (ArrayIndexOutOfBoundsException e) { + System.err.println("Illegal Character in devTools/javaSanityCheck/twineTags"); + System.exit(-1); + } + } + + /** + * Turns a string into a Tag + * ";1" at the end of the String indicates that the tag needs to be closed later + * + * @param s tag as String + * @return tag as Tag + */ + private static Tag parseTag(String s) { + String[] st = s.split(";"); + if (st.length > 1 && st[1].equals("1")) { + return new Tag(st[0], false); + } + return new Tag(st[0], true); + } + + /** + * sets up the excluded array. + */ + private static void setupExclude() { + //load excluded files + List<String> excludedList = new ArrayList<>(); + try { + Files.lines(new File("devTools/javaSanityCheck/excluded").toPath()).map(String::trim) + .filter(s -> !s.startsWith("#")) + .forEach(excludedList::add); + } catch (IOException e) { + System.err.println("Couldn't read devTools/javaSanityCheck/excluded"); + } + + //turn excluded files into an array and change them to windows style if needed + if (isWindows()) { + excluded = new String[excludedList.size()]; + int i = 0; + for (String s : + excludedList) { + excluded[i++] = s.replaceAll("/", "\\\\"); + } + } else { + excluded = excludedList.toArray(new String[0]); + } + } + + /** + * @return whether OS is Windows or not + */ + private static boolean isWindows() { + return (System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("windows")); + } + + /** + * checks if a file or directory is excluded from the sanity check + * + * @param s file/directory to be checked + * @return whether it is excluded or not + */ + private static boolean excluded(String s) { + for (String ex : + excluded) { + if (s.startsWith(ex)) return true; + } + return false; + } + + /** + * Reads the file character by character. + * + * @param reader reader that is read + * @throws IOException thrown if the file can't be read + */ + private static void handleCharacters(Reader reader) throws IOException { + int r; + while ((r = reader.read()) != -1) { + char c = (char) r; + handleCharacter(c); + } + } + + /** + * Handles a single character + * + * @param c next character + */ + private static void handleCharacter(char c) { + //updating position + currentPosition++; + if (c == '\n') { + currentLine++; + currentPosition = 1; + } + + //try applying to the innermost element + if (!stack.empty()) { + int change; + try { + change = stack.peek().handleChar(c); + } catch (SyntaxError e) { + change = e.getChange(); + addError(e); + } + + //change greater 0 means the innermost element did some work + if (change > 0) { + //2 means the Element is complete + if (change == 2) { + //remove the topmost element from stack since it is complete + stack.pop(); + return; + } + //3 means the Element is complete and part of a two tag system + if (change == 3) { + //remove the topmost element from stack since it is complete + KnownElement k = stack.pop().getKnownElement(); + /*if (k.isOpening()) { + stack.push(k); + } else */ + if (k.isClosing()) { + if (stack.empty()) { + addError(new SyntaxError("Closed tag " + k.getShortDescription() + " without having any open tags.", -2)); + } else if (stack.peek() instanceof KnownElement) { + KnownElement kFirst = (KnownElement) stack.pop(); + if (!kFirst.isMatchingElement(k)) { + addError(new SyntaxError("Opening tag " + kFirst.getShortDescription() + + " does not match closing tag " + k.getShortDescription() + ".", -2)); + } + //stack.pop(); + } else { + addError(new SyntaxError("Closing tag " + k.getShortDescription() + " inside " + + "another tag: " + stack.peek().getShortDescription(), -2, true)); + } + } + if (k.isOpening()) { + stack.push(k); + } + return; + } + if (change == 4) { + stack.pop(); + } else { + return; + } + } + } + + + //innermost element was uninterested, trying to find matching element + switch (c) { + //case '@': + // stack.push(new AtElement(currentLine, currentPosition)); + //break; + case '<': + stack.push(new AngleBracketElement(currentLine, currentPosition)); + break; + //case '>': + //addError(new SyntaxError("Dangling \">\", current innermost: " + (stack.empty() ? "null" : stack.peek().getShortDescription()), -2)); + //break; + case '/': + stack.push(new CommentElement(currentLine, currentPosition)); + break; + } + } + + /** + * add an error to the error list + * + * @param e new error + */ + private static void addError(SyntaxError e) { + e.setFile(currentFile); + e.setLine(currentLine); + e.setPosition(currentPosition); + errors.add(e); + } } diff --git a/devTools/javaSanityCheck/src/SyntaxError.java b/devTools/javaSanityCheck/src/SyntaxError.java index 150f2bd449b8c318b5a05884868a71538554ec67..2eaf24c6ec434192048c93891d72897c29dea9a6 100644 --- a/devTools/javaSanityCheck/src/SyntaxError.java +++ b/devTools/javaSanityCheck/src/SyntaxError.java @@ -1,40 +1,40 @@ package org.arkerthan.sanityCheck; public class SyntaxError extends Exception { - private String file; - private int line, position; - private String description; - private int change; //see Element for values; -2 means not thrown - private boolean warning = false; - - public SyntaxError(String description, int change) { - this.description = description; - this.change = change; - } - - public SyntaxError(String description, int change, boolean warning) { - this(description, change); - this.warning = warning; - } - - public void setFile(String file) { - this.file = file; - } - - public void setLine(int line) { - this.line = line; - } - - public void setPosition(int position) { - this.position = position; - } - - public String getError() { - String s = warning ? "Warning: " : "Error: "; - return s + file + ": " + line + ":" + position + " : "+ description; - } - - public int getChange() { - return change; - } + private String file; + private int line, position; + private String description; + private int change; //see Element for values; -2 means not thrown + private boolean warning = false; + + public SyntaxError(String description, int change) { + this.description = description; + this.change = change; + } + + public SyntaxError(String description, int change, boolean warning) { + this(description, change); + this.warning = warning; + } + + public void setFile(String file) { + this.file = file; + } + + public void setLine(int line) { + this.line = line; + } + + public void setPosition(int position) { + this.position = position; + } + + public String getError() { + String s = warning ? "Warning: " : "Error: "; + return s + file + ": " + line + ":" + position + " : "+ description; + } + + public int getChange() { + return change; + } } diff --git a/devTools/javaSanityCheck/src/Tag.java b/devTools/javaSanityCheck/src/Tag.java index 8a13ee4f7a178399db3eaf626b693e8a12ae71df..5c3c92651a71beb8a4e3cba73d1eb64238fc9908 100644 --- a/devTools/javaSanityCheck/src/Tag.java +++ b/devTools/javaSanityCheck/src/Tag.java @@ -1,11 +1,11 @@ package org.arkerthan.sanityCheck; public class Tag { - public final String tag; - public final boolean single; + public final String tag; + public final boolean single; - public Tag(String tag, boolean single) { - this.tag = tag; - this.single = single; - } + public Tag(String tag, boolean single) { + this.tag = tag; + this.single = single; + } } diff --git a/devTools/javaSanityCheck/src/TagSearchTree.java b/devTools/javaSanityCheck/src/TagSearchTree.java index dde49df879a346f124d15647cfeb821d0e0735fb..71e89ec769ff658b246886a179976055f2633709 100644 --- a/devTools/javaSanityCheck/src/TagSearchTree.java +++ b/devTools/javaSanityCheck/src/TagSearchTree.java @@ -9,72 +9,72 @@ import java.util.List; * @param <E> Tag class to be stored */ public class TagSearchTree<E extends Tag> { - private static final int SIZE = 128; - private final TagSearchTree<E>[] branches; - private E element = null; - private String path; + private static final int SIZE = 128; + private final TagSearchTree<E>[] branches; + private E element = null; + private String path; - /** - * creates a new empty TagSearchTree - */ - private TagSearchTree() { - branches = new TagSearchTree[SIZE]; - } + /** + * creates a new empty TagSearchTree + */ + private TagSearchTree() { + branches = new TagSearchTree[SIZE]; + } - /** - * Creates a new filled TagSearchTree - * - * @param list Tags to be inserted - */ - public TagSearchTree(List<E> list) { - this(); - for (E e : list) { - this.add(e, 0); - } - } + /** + * Creates a new filled TagSearchTree + * + * @param list Tags to be inserted + */ + public TagSearchTree(List<E> list) { + this(); + for (E e : list) { + this.add(e, 0); + } + } - /** - * adds a new Tag to the TagSearchTree - * - * @param e Tag to be stored - * @param index index of relevant char for adding in tag - */ - private void add(E e, int index) { - //set the path to here - path = e.tag.substring(0, index); - //checks if tag has to be stored here or further down - if (e.tag.length() == index) { - element = e; - } else { - //store tag in correct branch - char c = e.tag.charAt(index); - if (branches[c] == null) { - branches[c] = new TagSearchTree<>(); - } - branches[c].add(e, index + 1); - } - } + /** + * adds a new Tag to the TagSearchTree + * + * @param e Tag to be stored + * @param index index of relevant char for adding in tag + */ + private void add(E e, int index) { + //set the path to here + path = e.tag.substring(0, index); + //checks if tag has to be stored here or further down + if (e.tag.length() == index) { + element = e; + } else { + //store tag in correct branch + char c = e.tag.charAt(index); + if (branches[c] == null) { + branches[c] = new TagSearchTree<>(); + } + branches[c].add(e, index + 1); + } + } - /** - * @param c character of branch needed - * @return branch or null if branch doesn't exist - */ - public TagSearchTree<E> getBranch(char c) { - if (c >= SIZE) return null; - return branches[c]; - } + /** + * @param c character of branch needed + * @return branch or null if branch doesn't exist + */ + public TagSearchTree<E> getBranch(char c) { + if (c >= SIZE) return null; + return branches[c]; + } - /** - * @return stored Tag, null if empty - */ - public E getElement() { - return element; - } + /** + * @return stored Tag, null if empty + */ + public E getElement() { + return element; + } - /** - * @return path inside full tree to get to this Branch - */ - public String getPath() { - return path; - } + /** + * @return path inside full tree to get to this Branch + */ + public String getPath() { + return path; + } } diff --git a/devTools/javaSanityCheck/src/UnknownStateException.java b/devTools/javaSanityCheck/src/UnknownStateException.java index dceb35bc3d5b57fa3d710e9e61d3ce427a3499c3..80dbe598682d23875efe5517170f4f1c91a96246 100644 --- a/devTools/javaSanityCheck/src/UnknownStateException.java +++ b/devTools/javaSanityCheck/src/UnknownStateException.java @@ -2,7 +2,7 @@ package org.arkerthan.sanityCheck; public class UnknownStateException extends RuntimeException { - public UnknownStateException(int state) { - super(String.valueOf(state)); - } + public UnknownStateException(int state) { + super(String.valueOf(state)); + } } diff --git a/devTools/javaSanityCheck/src/element/AngleBracketElement.java b/devTools/javaSanityCheck/src/element/AngleBracketElement.java index e4819ba37ea48e4924dc944827d651fa14e02ad1..99549cda24411a29d1dfe32a0693cff99edbb46c 100644 --- a/devTools/javaSanityCheck/src/element/AngleBracketElement.java +++ b/devTools/javaSanityCheck/src/element/AngleBracketElement.java @@ -6,355 +6,355 @@ import java.util.Arrays; import java.util.List; public class AngleBracketElement extends Element { - private static final List<String> logicTags = Arrays.asList("if", "elseif", "else", "switch", "case", "default"); - private int state = 0; - /* - 0 - initial: < - TWINE - 1 - << - -1 - <</ - 2 - trying to complete twine tag: <<tag ???>> - -2 - trying to complete twine tag: <</tag>> - 3 - waiting for >> - -3 - expecting > from 3 - 4 - waiting for >> with KnownElement - -4 - expecting > from 4 - 5 - expecting >> - -5 - expecting > - 6 - expecting > with KnownElement opening; comparison? - -6 - expecting > with KnownElement closing + private static final List<String> logicTags = Arrays.asList("if", "elseif", "else", "switch", "case", "default"); + private int state = 0; + /* + 0 - initial: < + TWINE + 1 - << + -1 - <</ + 2 - trying to complete twine tag: <<tag ???>> + -2 - trying to complete twine tag: <</tag>> + 3 - waiting for >> + -3 - expecting > from 3 + 4 - waiting for >> with KnownElement + -4 - expecting > from 4 + 5 - expecting >> + -5 - expecting > + 6 - expecting > with KnownElement opening; comparison? + -6 - expecting > with KnownElement closing - HTML - -9 - </ - 10 - trying to complete HTML tag: <tag ???> + HTML + -9 - </ + 10 - trying to complete HTML tag: <tag ???> -10 - trying to complete HTML tag: </tag> - 11 - waiting for > + 11 - waiting for > -11 - expecting > - 12 - waiting for > with KnownElement - */ + 12 - waiting for > with KnownElement + */ - private TagSearchTree<Tag> tree; + private TagSearchTree<Tag> tree; - public AngleBracketElement(int line, int pos) { - super(line, pos); - } + public AngleBracketElement(int line, int pos) { + super(line, pos); + } - @Override - public int handleChar(char c) throws SyntaxError { - switch (state) { - case 0: - switch (c) { - case '<': - state = 1; - return 1; - case '>': - throw new SyntaxError("Empty Statement?", 2); - case '/': - state = -9; - return 1; - case ' ':// assume comparison - case '=':// " - return 2; - case '3'://a heart: <3 - return 2; - default: - try { - state = 10; - tree = Main.htmlTags; - return handleOpeningHTML(c); - } catch (SyntaxError e) { - state = 1; - throw new SyntaxError("Opening \"<\" missing, found " + c + " [debug:initialCase]", 1); - } - } - case 1: - if (c == '<') { - throw new SyntaxError("Too many \"<\".", 1); - } else if (c == '>') { - state = 3; - throw new SyntaxError("Empty Statement?", 1); - } else if (c == '/') { - state = -1; - return 1; - } - state = 2; - tree = Main.twineTags; - return handleOpeningTwine(c); - case -1: - if (c == '>') { - throw new SyntaxError("Empty Statement?", 2, true); - } - state = -2; - tree = Main.twineTags; - return handleClosingTwine(c); + @Override + public int handleChar(char c) throws SyntaxError { + switch (state) { + case 0: + switch (c) { + case '<': + state = 1; + return 1; + case '>': + throw new SyntaxError("Empty Statement?", 2); + case '/': + state = -9; + return 1; + case ' ':// assume comparison + case '=':// " + return 2; + case '3'://a heart: <3 + return 2; + default: + try { + state = 10; + tree = Main.htmlTags; + return handleOpeningHTML(c); + } catch (SyntaxError e) { + state = 1; + throw new SyntaxError("Opening \"<\" missing, found " + c + " [debug:initialCase]", 1); + } + } + case 1: + if (c == '<') { + throw new SyntaxError("Too many \"<\".", 1); + } else if (c == '>') { + state = 3; + throw new SyntaxError("Empty Statement?", 1); + } else if (c == '/') { + state = -1; + return 1; + } + state = 2; + tree = Main.twineTags; + return handleOpeningTwine(c); + case -1: + if (c == '>') { + throw new SyntaxError("Empty Statement?", 2, true); + } + state = -2; + tree = Main.twineTags; + return handleClosingTwine(c); - case 2: - return handleOpeningTwine(c); - case -2: - return handleClosingTwine(c); - case 3: - if (c == '>') { - state = -3; - return 1; - } - break; - case -3: - if (c == '>') { - return 2; - } else if (c == ' ' || c == '=') { // assuming comparison - state = 3; - return 1; - } else { - throw new SyntaxError("Closing \">\" missing, opened [" + line + ":" + pos + "]", 2); - } - case 4: - if (c == '>') { - state = -4; - return 1; - } - break; - case -4: - if (c == '>') { - return 3; - } else if (c == ' ' || c == '=') { // assuming comparison - state = 4; - return 1; - } else { - throw new SyntaxError("Closing \">\" missing, opened [" + line + ":" + pos + "]", 2); - } - case 5: - if (c == '>') { - state = -5; - return 1; - } else { - throw new SyntaxError("Closing \">\" missing, opened [" + line + ":" + pos + "]", 2); - } - case -5: - if (c == '>') { - return 2; - } - throw new SyntaxError("Closing \">\" missing, opened [" + line + ":" + pos + "]", 2); - case 6: - if (c == '>') { - return 3; - } else if (c == ' ' || c == '=') { - state = 3; - return 1; - } else { - throw new SyntaxError("Closing \">\" missing, opened [" + line + ":" + pos + "]", 3); - } - case -6: - if (c == '>') { - return 3; - } - throw new SyntaxError("Closing \">\" missing, opened [" + line + ":" + pos + "]", 3); + case 2: + return handleOpeningTwine(c); + case -2: + return handleClosingTwine(c); + case 3: + if (c == '>') { + state = -3; + return 1; + } + break; + case -3: + if (c == '>') { + return 2; + } else if (c == ' ' || c == '=') { // assuming comparison + state = 3; + return 1; + } else { + throw new SyntaxError("Closing \">\" missing, opened [" + line + ":" + pos + "]", 2); + } + case 4: + if (c == '>') { + state = -4; + return 1; + } + break; + case -4: + if (c == '>') { + return 3; + } else if (c == ' ' || c == '=') { // assuming comparison + state = 4; + return 1; + } else { + throw new SyntaxError("Closing \">\" missing, opened [" + line + ":" + pos + "]", 2); + } + case 5: + if (c == '>') { + state = -5; + return 1; + } else { + throw new SyntaxError("Closing \">\" missing, opened [" + line + ":" + pos + "]", 2); + } + case -5: + if (c == '>') { + return 2; + } + throw new SyntaxError("Closing \">\" missing, opened [" + line + ":" + pos + "]", 2); + case 6: + if (c == '>') { + return 3; + } else if (c == ' ' || c == '=') { + state = 3; + return 1; + } else { + throw new SyntaxError("Closing \">\" missing, opened [" + line + ":" + pos + "]", 3); + } + case -6: + if (c == '>') { + return 3; + } + throw new SyntaxError("Closing \">\" missing, opened [" + line + ":" + pos + "]", 3); - case -9: - if (c == '>') { - throw new SyntaxError("Empty Statement?", 2, true); - } - state = -10; - tree = Main.htmlTags; - return handleClosingHTML(c); - case 10: - return handleOpeningHTML(c); - case -10: - return handleClosingHTML(c); - case 11: - if (c == '>') - return 2; - if (c == '@') //@ inside HTML tags is allowed - return 1; - break; - case -11: - if (c == '>') - return 2; - throw new SyntaxError("Closing \">\" missing [2]", 2); - case 12: - if (c == '>') - return 3; - if (c == '@') //@ inside HTML tags is allowed - return 1; - break; - default: - throw new UnknownStateException(state); - } - return 0; - } + case -9: + if (c == '>') { + throw new SyntaxError("Empty Statement?", 2, true); + } + state = -10; + tree = Main.htmlTags; + return handleClosingHTML(c); + case 10: + return handleOpeningHTML(c); + case -10: + return handleClosingHTML(c); + case 11: + if (c == '>') + return 2; + if (c == '@') //@ inside HTML tags is allowed + return 1; + break; + case -11: + if (c == '>') + return 2; + throw new SyntaxError("Closing \">\" missing [2]", 2); + case 12: + if (c == '>') + return 3; + if (c == '@') //@ inside HTML tags is allowed + return 1; + break; + default: + throw new UnknownStateException(state); + } + return 0; + } - private int handleOpeningHTML(char c) throws SyntaxError { - if (c == ' ') { - state = 11; - if (tree.getElement() == null) { - throw new SyntaxError("Unknown HTML tag", 1); - } - if (!tree.getElement().single) { - k = new KnownHtmlElement(line, pos, true, tree.getElement().tag); - state = 12; - return 1; - } - return 1; - } - if (c == '>') { - if (tree.getElement() == null) { - throw new SyntaxError("Unknown HTML tag", 2); - } - if (!tree.getElement().single) { - k = new KnownHtmlElement(line, pos, true, tree.getElement().tag); - return 3; - } - return 2; - } + private int handleOpeningHTML(char c) throws SyntaxError { + if (c == ' ') { + state = 11; + if (tree.getElement() == null) { + throw new SyntaxError("Unknown HTML tag", 1); + } + if (!tree.getElement().single) { + k = new KnownHtmlElement(line, pos, true, tree.getElement().tag); + state = 12; + return 1; + } + return 1; + } + if (c == '>') { + if (tree.getElement() == null) { + throw new SyntaxError("Unknown HTML tag", 2); + } + if (!tree.getElement().single) { + k = new KnownHtmlElement(line, pos, true, tree.getElement().tag); + return 3; + } + return 2; + } - tree = tree.getBranch(c); - if (tree == null) { - state = 11; - throw new SyntaxError("Unknown HTML tag or closing \">\" missing, found " + c, 1); - } + tree = tree.getBranch(c); + if (tree == null) { + state = 11; + throw new SyntaxError("Unknown HTML tag or closing \">\" missing, found " + c, 1); + } - return 1; - } + return 1; + } - private int handleClosingHTML(char c) throws SyntaxError { - if (c == '>') { - if (tree.getElement() == null) { - throw new SyntaxError("Unknown HTML tag", 2); - } - if (tree.getElement().single) { - throw new SyntaxError("Single HTML tag used as closing Tag: " + tree.getElement().tag, 2); - } - k = new KnownHtmlElement(line, pos, false, tree.getElement().tag); - return 3; - } + private int handleClosingHTML(char c) throws SyntaxError { + if (c == '>') { + if (tree.getElement() == null) { + throw new SyntaxError("Unknown HTML tag", 2); + } + if (tree.getElement().single) { + throw new SyntaxError("Single HTML tag used as closing Tag: " + tree.getElement().tag, 2); + } + k = new KnownHtmlElement(line, pos, false, tree.getElement().tag); + return 3; + } - tree = tree.getBranch(c); - if (tree == null) { - state = -11; - throw new SyntaxError("Unknown HTML tag or closing \">\" missing, found " + c, 1); - } + tree = tree.getBranch(c); + if (tree == null) { + state = -11; + throw new SyntaxError("Unknown HTML tag or closing \">\" missing, found " + c, 1); + } - return 1; - } + return 1; + } - private int handleOpeningTwine(char c) throws SyntaxError { - if (c == ' ') { - state = 3; - if (tree.getElement() == null) { - //assuming not listed means widget until better solution - return 1; - //throw new SyntaxError("Unknown Twine tag or closing \">>\" missing, found " + tree.getPath(), 1); - } - if (!tree.getElement().single) { - if (logicTags.contains(tree.getElement().tag)) { - k = new KnownLogicElement(line, pos, tree.getElement().tag, false); - } else { - k = new KnownTwineElement(line, pos, true, tree.getElement().tag); - } - state = 4; - return 1; - } - return 1; - } - if (c == '>') { - state = -5; - if (tree.getElement() == null) { - //assuming not listed means widget until better solution - //throw new SyntaxError("Unknown Twine tag or closing \">>\" missing, found " + tree.getPath(), 1); - return 1; - } - if (!tree.getElement().single) { - if (logicTags.contains(tree.getElement().tag)) { - k = new KnownLogicElement(line, pos, tree.getElement().tag, false); - } else { - k = new KnownTwineElement(line, pos, true, tree.getElement().tag); - } - state = 6; - return 1; - } - return 2; - } + private int handleOpeningTwine(char c) throws SyntaxError { + if (c == ' ') { + state = 3; + if (tree.getElement() == null) { + //assuming not listed means widget until better solution + return 1; + //throw new SyntaxError("Unknown Twine tag or closing \">>\" missing, found " + tree.getPath(), 1); + } + if (!tree.getElement().single) { + if (logicTags.contains(tree.getElement().tag)) { + k = new KnownLogicElement(line, pos, tree.getElement().tag, false); + } else { + k = new KnownTwineElement(line, pos, true, tree.getElement().tag); + } + state = 4; + return 1; + } + return 1; + } + if (c == '>') { + state = -5; + if (tree.getElement() == null) { + //assuming not listed means widget until better solution + //throw new SyntaxError("Unknown Twine tag or closing \">>\" missing, found " + tree.getPath(), 1); + return 1; + } + if (!tree.getElement().single) { + if (logicTags.contains(tree.getElement().tag)) { + k = new KnownLogicElement(line, pos, tree.getElement().tag, false); + } else { + k = new KnownTwineElement(line, pos, true, tree.getElement().tag); + } + state = 6; + return 1; + } + return 2; + } - tree = tree.getBranch(c); - if (tree == null) { - //assuming not listed means widget until better solution - state = 3; - //throw new SyntaxError("Unknown Twine tag or closing \">>\" missing, found " + c, 1); - } + tree = tree.getBranch(c); + if (tree == null) { + //assuming not listed means widget until better solution + state = 3; + //throw new SyntaxError("Unknown Twine tag or closing \">>\" missing, found " + c, 1); + } - return 1; - } + return 1; + } - private int handleClosingTwine(char c) throws SyntaxError { - if (c == '>') { - if (tree.getElement() == null) { - throw new SyntaxError("Unknown Twine tag", 2); - } - if (tree.getElement().single) { - throw new SyntaxError("Single Twine tag used as closing Tag: " + tree.getElement().tag, 2); - } - if (logicTags.contains(tree.getElement().tag)) { - k = new KnownLogicElement(line, pos, tree.getElement().tag, true); - } else { - k = new KnownTwineElement(line, pos, false, tree.getElement().tag); - } - state = -6; - return 1; - } + private int handleClosingTwine(char c) throws SyntaxError { + if (c == '>') { + if (tree.getElement() == null) { + throw new SyntaxError("Unknown Twine tag", 2); + } + if (tree.getElement().single) { + throw new SyntaxError("Single Twine tag used as closing Tag: " + tree.getElement().tag, 2); + } + if (logicTags.contains(tree.getElement().tag)) { + k = new KnownLogicElement(line, pos, tree.getElement().tag, true); + } else { + k = new KnownTwineElement(line, pos, false, tree.getElement().tag); + } + state = -6; + return 1; + } - tree = tree.getBranch(c); - if (tree == null) { - state = 3; - throw new SyntaxError("Unknown Twine closing tag or closing \">>\" missing, found " + c, 1); - } + tree = tree.getBranch(c); + if (tree == null) { + state = 3; + throw new SyntaxError("Unknown Twine closing tag or closing \">>\" missing, found " + c, 1); + } - return 1; - } + return 1; + } - @Override - public String getShortDescription() { - StringBuilder builder = new StringBuilder(); - builder.append('[').append(line).append(":").append(pos).append("] "); - switch (state) { - case 0: - builder.append("<"); - break; - case 1: - builder.append("<<"); - break; - case -1: - builder.append("<</"); - break; - case 2: - builder.append("<<").append(tree.getPath()); - break; - case -2: - builder.append("<</").append(tree.getPath()); - break; - case 3: - builder.append("<<??? ???"); - break; - case 4: - builder.append("<<?").append(tree.getPath()).append(" ???"); - break; - case -3: - builder.append("<<??? ???>"); - break; - case -4: - builder.append("<<?").append(tree.getPath()).append(" ???>"); - break; - case 5: - builder.append("<").append(tree.getPath()).append(" ???"); - break; - case -5: - builder.append("</").append(tree.getPath()); - break; - case 6: - builder.append("<").append(tree.getPath()).append(" ???"); - break; - default: - //throw new UnknownStateException(state); - } - return builder.toString(); - } + @Override + public String getShortDescription() { + StringBuilder builder = new StringBuilder(); + builder.append('[').append(line).append(":").append(pos).append("] "); + switch (state) { + case 0: + builder.append("<"); + break; + case 1: + builder.append("<<"); + break; + case -1: + builder.append("<</"); + break; + case 2: + builder.append("<<").append(tree.getPath()); + break; + case -2: + builder.append("<</").append(tree.getPath()); + break; + case 3: + builder.append("<<??? ???"); + break; + case 4: + builder.append("<<?").append(tree.getPath()).append(" ???"); + break; + case -3: + builder.append("<<??? ???>"); + break; + case -4: + builder.append("<<?").append(tree.getPath()).append(" ???>"); + break; + case 5: + builder.append("<").append(tree.getPath()).append(" ???"); + break; + case -5: + builder.append("</").append(tree.getPath()); + break; + case 6: + builder.append("<").append(tree.getPath()).append(" ???"); + break; + default: + //throw new UnknownStateException(state); + } + return builder.toString(); + } } diff --git a/devTools/javaSanityCheck/src/element/AtElement.java b/devTools/javaSanityCheck/src/element/AtElement.java index 0dad04247c50f2a9a77bb9ce584ded8de0377ed2..168e340a4326b24c0dff912c64d25ec5042d6fe5 100644 --- a/devTools/javaSanityCheck/src/element/AtElement.java +++ b/devTools/javaSanityCheck/src/element/AtElement.java @@ -4,102 +4,102 @@ import org.arkerthan.sanityCheck.SyntaxError; import org.arkerthan.sanityCheck.UnknownStateException; public class AtElement extends Element { - private int state = 0; - // 0 = @ - // 1 = @@ - // 2 = @@. - // 3 = @@.a -- @@.ab -- @@.abc - // 4 = @@.abc;abc - // 5 = @@.abc;abc@ + private int state = 0; + // 0 = @ + // 1 = @@ + // 2 = @@. + // 3 = @@.a -- @@.ab -- @@.abc + // 4 = @@.abc;abc + // 5 = @@.abc;abc@ - // example: @@.red;some text@@ + // example: @@.red;some text@@ - public AtElement(int line, int pos) { - super(line, pos); - } + public AtElement(int line, int pos) { + super(line, pos); + } - @Override - public int handleChar(char c) throws SyntaxError { - switch (state) { - case 0: - state = 1; - if (c == '@') { - return 1; - } else { - if (c == '.') { - state = 2; - } - throw new SyntaxError("Opening \"@\" missing.", 1); - } - case 1: - if (c == '.') { - state = 2; - return 1; - } else { - state = 4; - throw new SyntaxError("\".\" missing, found \"" + c + "\". This might also indicate a " + - "missing closure in the previous color code.", 0, true); - } - case 2: - state = 3; - if (Character.isAlphabetic(c)) { - return 1; - } else { - throw new SyntaxError("Identifier might be wrong.", 1, true); - } - case 3: - if (c == ';') { - state = 4; - return 1; - } else if (c == ' ') { - state = 4; - throw new SyntaxError("\";\" missing or wrong space.", 1); - } - break; - case 4: - if (c == '@') { - state = 5; - return 1; - } - break; - case 5: - if (c == '@') { - return 2; - } else { - throw new SyntaxError("Closing \"@\" missing.", 2); - } - default: - throw new UnknownStateException(state); - } - return 0; - } + @Override + public int handleChar(char c) throws SyntaxError { + switch (state) { + case 0: + state = 1; + if (c == '@') { + return 1; + } else { + if (c == '.') { + state = 2; + } + throw new SyntaxError("Opening \"@\" missing.", 1); + } + case 1: + if (c == '.') { + state = 2; + return 1; + } else { + state = 4; + throw new SyntaxError("\".\" missing, found \"" + c + "\". This might also indicate a " + + "missing closure in the previous color code.", 0, true); + } + case 2: + state = 3; + if (Character.isAlphabetic(c)) { + return 1; + } else { + throw new SyntaxError("Identifier might be wrong.", 1, true); + } + case 3: + if (c == ';') { + state = 4; + return 1; + } else if (c == ' ') { + state = 4; + throw new SyntaxError("\";\" missing or wrong space.", 1); + } + break; + case 4: + if (c == '@') { + state = 5; + return 1; + } + break; + case 5: + if (c == '@') { + return 2; + } else { + throw new SyntaxError("Closing \"@\" missing.", 2); + } + default: + throw new UnknownStateException(state); + } + return 0; + } - @Override - public String getShortDescription() { - StringBuilder builder = new StringBuilder(); - builder.append(line).append(":").append(pos).append(" "); - switch (state) { - case 0: - builder.append("@"); - break; - case 1: - builder.append("@@"); - break; - case 2: - builder.append("@@."); - break; - case 3: - builder.append("@@.???"); - break; - case 4: - builder.append("@@???"); - break; - case 5: - builder.append("@@???@"); - break; - default: - throw new UnknownStateException(state); - } - return builder.toString(); - } + @Override + public String getShortDescription() { + StringBuilder builder = new StringBuilder(); + builder.append(line).append(":").append(pos).append(" "); + switch (state) { + case 0: + builder.append("@"); + break; + case 1: + builder.append("@@"); + break; + case 2: + builder.append("@@."); + break; + case 3: + builder.append("@@.???"); + break; + case 4: + builder.append("@@???"); + break; + case 5: + builder.append("@@???@"); + break; + default: + throw new UnknownStateException(state); + } + return builder.toString(); + } } diff --git a/devTools/javaSanityCheck/src/element/CommentElement.java b/devTools/javaSanityCheck/src/element/CommentElement.java index 3a3cc12aff9f3c2e4b06cc7240d14824575cc96e..7906986e3dae2c3829d3ff5bd2bf76eddcbbd5c7 100644 --- a/devTools/javaSanityCheck/src/element/CommentElement.java +++ b/devTools/javaSanityCheck/src/element/CommentElement.java @@ -4,63 +4,63 @@ import org.arkerthan.sanityCheck.SyntaxError; import org.arkerthan.sanityCheck.UnknownStateException; public class CommentElement extends Element { - int state = 0; - /* - 0 - / - 1 - /*??? - 2 - /*???* - 3 - /%??? - 4 - /%???% - */ + int state = 0; + /* + 0 - / + 1 - /*??? + 2 - /*???* + 3 - /%??? + 4 - /%???% + */ - public CommentElement(int line, int pos) { - super(line, pos); - } + public CommentElement(int line, int pos) { + super(line, pos); + } - @Override - public int handleChar(char c) throws SyntaxError { - switch (state) { - case 0: - if (c == '*') { - state = 1; - } else if (c == '%') { - state = 3; - } else if (c == '>') { - throw new SyntaxError("XHTML style closure", 4, true); - } else { - return 4; - } - break; - case 1: - if (c == '*') { - state = 2; - } - break; - case 2: - if (c == '/') { - return 2; - } - state = 1; - break; - case 3: - if (c == '%') { - state = 4; - } - break; - case 4: - if (c == '/') { - return 2; - } - state = 3; - break; - default: - throw new UnknownStateException(state); - } - return 1; - } + @Override + public int handleChar(char c) throws SyntaxError { + switch (state) { + case 0: + if (c == '*') { + state = 1; + } else if (c == '%') { + state = 3; + } else if (c == '>') { + throw new SyntaxError("XHTML style closure", 4, true); + } else { + return 4; + } + break; + case 1: + if (c == '*') { + state = 2; + } + break; + case 2: + if (c == '/') { + return 2; + } + state = 1; + break; + case 3: + if (c == '%') { + state = 4; + } + break; + case 4: + if (c == '/') { + return 2; + } + state = 3; + break; + default: + throw new UnknownStateException(state); + } + return 1; + } - @Override - public String getShortDescription() { - return null; - } + @Override + public String getShortDescription() { + return null; + } } diff --git a/devTools/javaSanityCheck/src/element/Element.java b/devTools/javaSanityCheck/src/element/Element.java index b0f99fa904f66a6a9ebcecb5ffdfb7040493b08b..f80a85f8c1800ca4cb3422f9a29c91938900b39f 100644 --- a/devTools/javaSanityCheck/src/element/Element.java +++ b/devTools/javaSanityCheck/src/element/Element.java @@ -3,38 +3,38 @@ package org.arkerthan.sanityCheck.element; import org.arkerthan.sanityCheck.SyntaxError; public abstract class Element { - protected KnownElement k; - protected int line, pos; + protected KnownElement k; + protected int line, pos; - /** - * @param line Line the instance was created - * @param pos Position in line the instance was created - */ - protected Element(int line, int pos) { - this.line = line; - this.pos = pos; - } + /** + * @param line Line the instance was created + * @param pos Position in line the instance was created + */ + protected Element(int line, int pos) { + this.line = line; + this.pos = pos; + } - /** - * Parses a Char and returns an int depending on the state of the element - * 0 - the Element did nothing - * 1 - the Element changed state - * 2 - the Element is finished - * 3 - the Element is finished and a KnownHtmlElement was generated - * 4 - the Element is finished and the char is still open for use - * - * @param c - * @return - * @throws Error - */ - public abstract int handleChar(char c) throws SyntaxError; + /** + * Parses a Char and returns an int depending on the state of the element + * 0 - the Element did nothing + * 1 - the Element changed state + * 2 - the Element is finished + * 3 - the Element is finished and a KnownHtmlElement was generated + * 4 - the Element is finished and the char is still open for use + * + * @param c + * @return + * @throws Error + */ + public abstract int handleChar(char c) throws SyntaxError; - public KnownElement getKnownElement() { - return k; - } + public KnownElement getKnownElement() { + return k; + } - /** - * @return a short description usually based on state and position of the Element - */ - public abstract String getShortDescription(); + /** + * @return a short description usually based on state and position of the Element + */ + public abstract String getShortDescription(); } diff --git a/devTools/javaSanityCheck/src/element/KnownElement.java b/devTools/javaSanityCheck/src/element/KnownElement.java index 305be2fe65210b191d96ead352487b35e448ce39..b3164c2a5890f646bbf75207827049d7ae5d5658 100644 --- a/devTools/javaSanityCheck/src/element/KnownElement.java +++ b/devTools/javaSanityCheck/src/element/KnownElement.java @@ -4,28 +4,28 @@ import org.arkerthan.sanityCheck.SyntaxError; public abstract class KnownElement extends Element { - public KnownElement(int line, int pos) { - super(line, pos); - } + public KnownElement(int line, int pos) { + super(line, pos); + } - /** - * @return true, if it needs another Known Element to close it. - */ - public abstract boolean isOpening(); + /** + * @return true, if it needs another Known Element to close it. + */ + public abstract boolean isOpening(); - /** - * @return true if it closes another Element. - */ - public abstract boolean isClosing(); + /** + * @return true if it closes another Element. + */ + public abstract boolean isClosing(); - /** - * @param k Element to be checked - * @return true if given Element closes Element - */ - public abstract boolean isMatchingElement(KnownElement k); + /** + * @param k Element to be checked + * @return true if given Element closes Element + */ + public abstract boolean isMatchingElement(KnownElement k); - @Override - public int handleChar(char c) throws SyntaxError { - return 0; - } + @Override + public int handleChar(char c) throws SyntaxError { + return 0; + } } diff --git a/devTools/javaSanityCheck/src/element/KnownHtmlElement.java b/devTools/javaSanityCheck/src/element/KnownHtmlElement.java index d086a74bc547a0aa90520e50c4398f5cf6dc365e..51abacd60ac47a000fa47b2fe88f61ca8daf2bc6 100644 --- a/devTools/javaSanityCheck/src/element/KnownHtmlElement.java +++ b/devTools/javaSanityCheck/src/element/KnownHtmlElement.java @@ -2,40 +2,40 @@ package org.arkerthan.sanityCheck.element; public class KnownHtmlElement extends KnownElement { - private boolean opening; - private String statement; + private boolean opening; + private String statement; - public KnownHtmlElement(int line, int pos, boolean opening, String statement) { - super(line, pos); - this.opening = opening; - this.statement = statement; - } + public KnownHtmlElement(int line, int pos, boolean opening, String statement) { + super(line, pos); + this.opening = opening; + this.statement = statement; + } - @Override - public String getShortDescription() { - StringBuilder builder = new StringBuilder(); - builder.append('[').append(line).append(":").append(pos).append("] <"); - if (!opening) { - builder.append("/"); - } - return builder.append(statement).append(">").toString(); - } + @Override + public String getShortDescription() { + StringBuilder builder = new StringBuilder(); + builder.append('[').append(line).append(":").append(pos).append("] <"); + if (!opening) { + builder.append("/"); + } + return builder.append(statement).append(">").toString(); + } - @Override - public boolean isOpening() { - return opening; - } + @Override + public boolean isOpening() { + return opening; + } - @Override - public boolean isClosing() { - return !opening; - } + @Override + public boolean isClosing() { + return !opening; + } - @Override - public boolean isMatchingElement(KnownElement k) { - if (k instanceof KnownHtmlElement) { - return ((KnownHtmlElement) k).statement.equals(this.statement); - } - return false; - } + @Override + public boolean isMatchingElement(KnownElement k) { + if (k instanceof KnownHtmlElement) { + return ((KnownHtmlElement) k).statement.equals(this.statement); + } + return false; + } } diff --git a/devTools/javaSanityCheck/src/element/KnownLogicElement.java b/devTools/javaSanityCheck/src/element/KnownLogicElement.java index 502abde93a296c3dffb2391b75b08893aeecd2c5..994201c5a9ba40a4aea01252bb0ba6765a5841b7 100644 --- a/devTools/javaSanityCheck/src/element/KnownLogicElement.java +++ b/devTools/javaSanityCheck/src/element/KnownLogicElement.java @@ -7,111 +7,111 @@ import java.util.Arrays; import java.util.List; public class KnownLogicElement extends KnownElement { - private static final List<String> allowedTags = Arrays.asList("if", "elseif", "else"); - private final int state; - private boolean last; - /* - 0 - if - 1 - elseif - 2 - else - 3 - switch - 4 - case - 5 - default - */ + private static final List<String> allowedTags = Arrays.asList("if", "elseif", "else"); + private final int state; + private boolean last; + /* + 0 - if + 1 - elseif + 2 - else + 3 - switch + 4 - case + 5 - default + */ - public KnownLogicElement(int line, int pos, String tag, boolean last) { - this(line, pos, tag); - this.last = last; - } + public KnownLogicElement(int line, int pos, String tag, boolean last) { + this(line, pos, tag); + this.last = last; + } - public KnownLogicElement(int line, int pos, String tag) { - super(line, pos); - switch (tag) { - case "if": - state = 0; - break; - case "elseif": - state = 1; - break; - case "else": - state = 2; - break; - case "switch": - state = 3; - break; - case "case": - state = 4; - break; - case "default": - state = 5; - break; - default: - throw new DisallowedTagException(tag); - } - last = false; - } + public KnownLogicElement(int line, int pos, String tag) { + super(line, pos); + switch (tag) { + case "if": + state = 0; + break; + case "elseif": + state = 1; + break; + case "else": + state = 2; + break; + case "switch": + state = 3; + break; + case "case": + state = 4; + break; + case "default": + state = 5; + break; + default: + throw new DisallowedTagException(tag); + } + last = false; + } - @Override - public boolean isOpening() { - return !last; - } + @Override + public boolean isOpening() { + return !last; + } - @Override - public boolean isClosing() { - return (state != 0 && state != 3) || last; - } + @Override + public boolean isClosing() { + return (state != 0 && state != 3) || last; + } - @Override - public boolean isMatchingElement(KnownElement k) { - if (!(k instanceof KnownLogicElement)) { - return false; - } - KnownLogicElement l = (KnownLogicElement) k; - switch (state) { - case 0: - case 1: - return l.state == 1 || l.state == 2 || (l.state == 0 && l.last); - case 2: - return l.state == 0 && l.last; - case 3: - case 4: - return l.state == 3 || l.state == 4; - case 5: - return l.state == 3 && l.last; - default: - throw new UnknownStateException(state); - } - } + @Override + public boolean isMatchingElement(KnownElement k) { + if (!(k instanceof KnownLogicElement)) { + return false; + } + KnownLogicElement l = (KnownLogicElement) k; + switch (state) { + case 0: + case 1: + return l.state == 1 || l.state == 2 || (l.state == 0 && l.last); + case 2: + return l.state == 0 && l.last; + case 3: + case 4: + return l.state == 3 || l.state == 4; + case 5: + return l.state == 3 && l.last; + default: + throw new UnknownStateException(state); + } + } - @Override - public String getShortDescription() { - StringBuilder builder = new StringBuilder(); - builder.append("[").append(line).append(":").append(pos).append("] <<"); - if (last) { - builder.append('/'); - } - switch (state) { - case 0: - builder.append("if"); - break; - case 1: - builder.append("elseif"); - break; - case 2: - builder.append("else"); - break; - case 3: - builder.append("switch"); - break; - case 4: - builder.append("case"); - break; - case 5: - builder.append("default"); - break; - default: - throw new UnknownStateException(state); - } - return builder.append(">>").toString(); - } + @Override + public String getShortDescription() { + StringBuilder builder = new StringBuilder(); + builder.append("[").append(line).append(":").append(pos).append("] <<"); + if (last) { + builder.append('/'); + } + switch (state) { + case 0: + builder.append("if"); + break; + case 1: + builder.append("elseif"); + break; + case 2: + builder.append("else"); + break; + case 3: + builder.append("switch"); + break; + case 4: + builder.append("case"); + break; + case 5: + builder.append("default"); + break; + default: + throw new UnknownStateException(state); + } + return builder.append(">>").toString(); + } } diff --git a/devTools/javaSanityCheck/src/element/KnownTwineElement.java b/devTools/javaSanityCheck/src/element/KnownTwineElement.java index 24003fd00be0bb79aa6a01b2fbd2d9a91439ac6a..399fa5192181044e589ffd5d4222941b001f3066 100644 --- a/devTools/javaSanityCheck/src/element/KnownTwineElement.java +++ b/devTools/javaSanityCheck/src/element/KnownTwineElement.java @@ -2,40 +2,40 @@ package org.arkerthan.sanityCheck.element; public class KnownTwineElement extends KnownElement { - private boolean opening; - private String statement; + private boolean opening; + private String statement; - public KnownTwineElement(int line, int pos, boolean opening, String statement) { - super(line, pos); - this.opening = opening; - this.statement = statement; - } + public KnownTwineElement(int line, int pos, boolean opening, String statement) { + super(line, pos); + this.opening = opening; + this.statement = statement; + } - @Override - public String getShortDescription() { - StringBuilder builder = new StringBuilder(); - builder.append("[").append(line).append(":").append(pos).append("] <<"); - if (!opening) { - builder.append("/"); - } - return builder.append(statement).append(">>").toString(); - } + @Override + public String getShortDescription() { + StringBuilder builder = new StringBuilder(); + builder.append("[").append(line).append(":").append(pos).append("] <<"); + if (!opening) { + builder.append("/"); + } + return builder.append(statement).append(">>").toString(); + } - @Override - public boolean isOpening() { - return opening; - } + @Override + public boolean isOpening() { + return opening; + } - @Override - public boolean isClosing() { - return !opening; - } + @Override + public boolean isClosing() { + return !opening; + } - @Override - public boolean isMatchingElement(KnownElement k) { - if (k instanceof KnownTwineElement) { - return ((KnownTwineElement) k).statement.equals(this.statement); - } - return false; - } + @Override + public boolean isMatchingElement(KnownElement k) { + if (k instanceof KnownTwineElement) { + return ((KnownTwineElement) k).statement.equals(this.statement); + } + return false; + } } diff --git a/src/js/slaveStatsChecker.js b/src/js/slaveStatsChecker.js index c9fd17b4d5e24f359da2b6fabe0a11b82dee1d04..87ba3f18033a475d023a16a3a2c1a762dba89bf6 100644 --- a/src/js/slaveStatsChecker.js +++ b/src/js/slaveStatsChecker.js @@ -5,7 +5,7 @@ window.SlaveStatsChecker = (function() { piercingScore: piercingScore, tatScore: tatScore }; - + function hasLisp(slave) { if (State.variables.disableLisping === 1) { return false;