diff --git a/SanityCheck.jar b/SanityCheck.jar index bebdf1da3e6277f966e8fff78ea96d884fe27b0b..36c886155cf61858bb6e54466cb88efc05f615cd 100644 Binary files a/SanityCheck.jar and b/SanityCheck.jar differ diff --git a/devTools/javaSanityCheck/excluded b/devTools/javaSanityCheck/excluded index 28ff834dcbab00ca86653880aa605a6a64163fd2..eb522cb6bac88f489da3aeae75878591398e5838 100644 --- a/devTools/javaSanityCheck/excluded +++ b/devTools/javaSanityCheck/excluded @@ -3,14 +3,4 @@ # src/art/ src/gui/svgFilters.tw -# -#excluded to reduce false positives until better solution: -src/pregmod/basenationalitiesControls.tw src/pregmod/editGenetics.tw -src/pregmod/widgets/bodySwapReaction.tw -src/uncategorized/costsBudget.tw -src/uncategorized/initRules.tw -src/uncategorized/slaveAssignmentsReport.tw -src/uncategorized/storyCaption.tw -src/cheats/ -src/pregmod/customizeSlaveTrade.tw diff --git a/devTools/javaSanityCheck/htmlTags b/devTools/javaSanityCheck/htmlTags index 751b084ff5822f4162e3f79ea622b91f60c5472b..466a9b301e715f5b896bd84c38941bf61c4ec985 100644 --- a/devTools/javaSanityCheck/htmlTags +++ b/devTools/javaSanityCheck/htmlTags @@ -8,6 +8,7 @@ #included to reduce false positives until better solution !-- http://www.gnu.org/licenses/ +-400 #html tags a;1 b;1 diff --git a/devTools/javaSanityCheck/src/DisallowedTagException.java b/devTools/javaSanityCheck/src/DisallowedTagException.java index cd479fbdf5f9c8b42a9271b8c0049cba10bcb72a..f4cc75e736b162192a5f18bbc55a10edb21eaa38 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 d8af45777314f08b03eb5f471be4cdb9ba72f703..87b18682d2391fc678a383ccc4b47480278c0473 100644 --- a/devTools/javaSanityCheck/src/Main.java +++ b/devTools/javaSanityCheck/src/Main.java @@ -12,308 +12,310 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.*; +/** + * @author Arkerthan + */ 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/")); + + //output errors + for (SyntaxError e : + errors) { + System.out.println(e.getError()); + } + } + + + /** + * Goes through the whole directory including subdirectories and runs + * {@link Main#sanityCheck(Path)} 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 read 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())) { + 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) { + e.printStackTrace(); + System.err.println("Couldn't read " + file); + } + } + } + + /** + * sets up a {@link TagSearchTree<Tag>} for fast access of HTML tags later + */ + private static void setupHtmlTags() { + //load HTML tags into a list + List<Tag> TagsList = loadTags("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 a {@link TagSearchTree<Tag>} for fast access of twine tags later + */ + private static void setupTwineTags() { + //load twine tags into a list + List tagsList = loadTags("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); + } + } + + /** + * Loads a list of tags from a file + * + * @param filePath file to load tags from + * @return loaded tags + */ + private static List<Tag> loadTags(String filePath) { + List<Tag> tagsList = new LinkedList<>(); + try { + Files.lines(new File(filePath).toPath()).map(String::trim) + .filter(s -> !s.startsWith("#")) + .forEach(s -> tagsList.add(parseTag(s))); + } catch (IOException e) { + System.err.println("Couldn't read " + filePath); + } + return tagsList; + } + + /** + * 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 files 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 path 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 or more tag system + if (change == 3) { + //remove the topmost element from stack since it is complete + KnownElement k = stack.pop().getKnownElement(); + //if KnownElement k is closing another tag check if there is one and remove it + if (k.isClosing()) { + if (stack.empty()) { //there are no open tags at all + 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)); + } + } 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 2eaf24c6ec434192048c93891d72897c29dea9a6..ad7aa7cdf3c2c2f01caa4f552f01180861d3569a 100644 --- a/devTools/javaSanityCheck/src/SyntaxError.java +++ b/devTools/javaSanityCheck/src/SyntaxError.java @@ -1,40 +1,64 @@ 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; + + /** + * @param description description of error + * @param change state change as specified in Element + */ + public SyntaxError(String description, int change) { + this.description = description; + this.change = change; + } + + /** + * @param description description of error + * @param change state change as specified in Element + * @param warning whether it is a warning or an error + */ + public SyntaxError(String description, int change, boolean warning) { + this(description, change); + this.warning = warning; + } + + /** + * @param file at which the error occurred + */ + public void setFile(String file) { + this.file = file; + } + + /** + * @param line in which the error occurred + */ + public void setLine(int line) { + this.line = line; + } + + /** + * @param position at which the error occurred + */ + public void setPosition(int position) { + this.position = position; + } + + /** + * @return error message + */ + public String getError() { + String s = warning ? "Warning: " : "Error: "; + return s + file + ": " + line + ":" + position + " : " + description; + } + + /** + * @return change that happened in Element before it was thrown. -1 if not thrown. + */ + public int getChange() { + return change; + } } diff --git a/devTools/javaSanityCheck/src/Tag.java b/devTools/javaSanityCheck/src/Tag.java index 5c3c92651a71beb8a4e3cba73d1eb64238fc9908..8a13ee4f7a178399db3eaf626b693e8a12ae71df 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 71e89ec769ff658b246886a179976055f2633709..dde49df879a346f124d15647cfeb821d0e0735fb 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 80dbe598682d23875efe5517170f4f1c91a96246..dceb35bc3d5b57fa3d710e9e61d3ce427a3499c3 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 99549cda24411a29d1dfe32a0693cff99edbb46c..233c4f303205ab5e24b7c7ffd8c45088002ed471 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, 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 tag at [" + 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 tag at[" + line + ":" + pos + "]", 2); + } + case 5: + if (c == '>') { + state = -5; + return 1; + } else { + throw new SyntaxError("Closing \">\" missing, opened tag at [" + line + ":" + pos + "]", 2); + } + case -5: + if (c == '>') { + return 2; + } + throw new SyntaxError("Closing \">\" missing, opened tag at [" + line + ":" + pos + "]", 2); + case 6: + if (c == '>') { + return 3; + } else if (c == ' ' || c == '=') { + state = 3; + return 1; + } else { + throw new SyntaxError("Closing \">\" missing, opened tag at [" + line + ":" + pos + "]", 3); + } + case -6: + if (c == '>') { + return 3; + } + throw new SyntaxError("Closing \">\" missing, opened tag at [" + 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 168e340a4326b24c0dff912c64d25ec5042d6fe5..0dad04247c50f2a9a77bb9ce584ded8de0377ed2 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 7906986e3dae2c3829d3ff5bd2bf76eddcbbd5c7..159b92afcd56f36b21952f173fa417276880b4c4 100644 --- a/devTools/javaSanityCheck/src/element/CommentElement.java +++ b/devTools/javaSanityCheck/src/element/CommentElement.java @@ -4,63 +4,67 @@ import org.arkerthan.sanityCheck.SyntaxError; import org.arkerthan.sanityCheck.UnknownStateException; public class CommentElement extends Element { - int state = 0; - /* - 0 - / - 1 - /*??? - 2 - /*???* - 3 - /%??? - 4 - /%???% - */ + private int state = 0; + /* + 0 - / + 1 - /*??? + 2 - /*???* + 3 - /%??? + 4 - /%???% + */ - public CommentElement(int line, int pos) { - super(line, pos); - } + /** + * @param line line in which comment starts + * @param pos position in line where comment starts + */ + 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 f80a85f8c1800ca4cb3422f9a29c91938900b39f..96f71976f3dd99e0ff49d69de72b18db7153aa9d 100644 --- a/devTools/javaSanityCheck/src/element/Element.java +++ b/devTools/javaSanityCheck/src/element/Element.java @@ -3,38 +3,41 @@ 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 char to be parsed + * @return state change + * @throws SyntaxError thrown when an syntax error is detected + */ + public abstract int handleChar(char c) throws SyntaxError; - public KnownElement getKnownElement() { - return k; - } + /** + * @return the constructed KnownElement. null if none was constructed yet. + */ + 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 b3164c2a5890f646bbf75207827049d7ae5d5658..7bc0b7a1ee7d746855cc8fe34354c099f66e5b30 100644 --- a/devTools/javaSanityCheck/src/element/KnownElement.java +++ b/devTools/javaSanityCheck/src/element/KnownElement.java @@ -4,28 +4,32 @@ import org.arkerthan.sanityCheck.SyntaxError; public abstract class KnownElement extends Element { - public KnownElement(int line, int pos) { - super(line, pos); - } + /** + * @param line at which it begins + * @param pos at which it begins + */ + 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 51abacd60ac47a000fa47b2fe88f61ca8daf2bc6..c262263b9b79886dfa229b6b29b79c7a6e2f8b2d 100644 --- a/devTools/javaSanityCheck/src/element/KnownHtmlElement.java +++ b/devTools/javaSanityCheck/src/element/KnownHtmlElement.java @@ -2,40 +2,46 @@ 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; - } + /** + * @param line at which it begins + * @param pos at which it begins + * @param opening if it opens a tag: <tag> or closes it: </tag> + * @param statement statement inside the tag + */ + 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 994201c5a9ba40a4aea01252bb0ba6765a5841b7..502abde93a296c3dffb2391b75b08893aeecd2c5 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 399fa5192181044e589ffd5d4222941b001f3066..765d9b682ee32cc9ac54cf095d318e241af2af5d 100644 --- a/devTools/javaSanityCheck/src/element/KnownTwineElement.java +++ b/devTools/javaSanityCheck/src/element/KnownTwineElement.java @@ -2,40 +2,47 @@ 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; - } + /** + * + * @param line at which it begins + * @param pos at which it begins + * @param opening if it opens a tag: <<tag>> or closes it: <</tag>> + * @param statement statement inside the tag + */ + 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/devTools/javaSanityCheck/twineTags b/devTools/javaSanityCheck/twineTags index e1dea71621bd818041d6aad43d7b3053b2c78132..d0c5e0c6f9ee32f472d3a5d3a9453961de54b729 100644 --- a/devTools/javaSanityCheck/twineTags +++ b/devTools/javaSanityCheck/twineTags @@ -2,8 +2,6 @@ #Effectively everything that is allowed in a statements like this: #<<tag>> or <<tag ???>> #when ;1 is specified it expects a matching closing tag like this: <</tag>> -#Everything belonging to if and switch statements is hard coded and does not -#need to be included here. #Do not add HTML Tags here. #Characters outside of ASCII scope are not supported. # @@ -11,7 +9,6 @@ capture;1 continue;0 for;1 -#does foreach really exist? foreach;1 goto;0 htag;1 @@ -24,6 +21,7 @@ run;0 script;1 set;0 silently;1 +span;1 textbox;0 timed;1 unset;0 diff --git a/src/SpecialForce/WeeklyChoices.tw b/src/SpecialForce/WeeklyChoices.tw index 03c38a19a4617e29c505ebeb39f9f977b7407fb7..cd9bcf4ddc1bf8910dcb4b7e1fb26bdd83cd51b4 100644 --- a/src/SpecialForce/WeeklyChoices.tw +++ b/src/SpecialForce/WeeklyChoices.tw @@ -212,7 +212,7 @@ <br> <<link "All three holes">> <<replace "#result6">> <<include "SFColonelSexDec">> <</replace>> <<set $SF.Colonel.Fun += 3>> <</link>> - </span> <</replace>> </span> <</link>> + </span> <</replace>> <</link>> </span> <</replace>> <</link>> <</if>> /*Closes fun*/ </span> <</replace>> <</link>> /*Closes talk*/ -</span> <</if>> /*Closes spend time with The Colonel*/ \ No newline at end of file +</span> <</if>> /*Closes spend time with The Colonel*/ diff --git a/src/pregmod/basenationalitiesControls.tw b/src/pregmod/basenationalitiesControls.tw index e090c5ba894608cd26a53442bf767fc1d8d13ec4..4ca9e7efdf5a4239543800e3c606546d0a08694b 100644 --- a/src/pregmod/basenationalitiesControls.tw +++ b/src/pregmod/basenationalitiesControls.tw @@ -31,7 +31,7 @@ /* Fine control tweaking of populations */ Adjust slave populations: -<br style="clear:both" /><hr style="margin:0"> +<br style="clear:both"><hr style="margin:0"> /* Filter controls */ Filter by Race: @@ -69,7 +69,7 @@ Filter by Region: | <</if>> <</for>> -<br style="clear:both" /><hr style="margin:0"> +<br style="clear:both"><hr style="margin:0"> <div style="white-space: nowrap"> /* Unfiltered pop controls */ diff --git a/src/pregmod/csec.tw b/src/pregmod/csec.tw index 59b1cf6921e103d22e66e90a8ac0d63c7972e6ef..668b4e14855b0cfe57f764080d6e48a4d1a4a1e9 100644 --- a/src/pregmod/csec.tw +++ b/src/pregmod/csec.tw @@ -481,8 +481,8 @@ Since $his <<if $activeSlave.mpreg == 1>>ass<<else>>vagina<</if>> was spared fro <<if $activeSlave.broodmother == 0 && $bellyImplants == 1>> <br><br> <span id="bir">Since $he is already in surgery and $his body already stretched, it would be possible to preserve $his pregnant appearance via fillable implant. - <<link "Do it.">> </span> + <<link "Do it.">> <<replace "#bir">> <<if $PC.medicine >= 100>><<set $activeSlave.health -= 5>><<else>><<set $activeSlave.health -= 10>><</if>> Installation of belly implant is relatively simple procedure. Using the fact that $his body and internal organs have already adapted to pregnancy, it's possible to greatly expand the initial size of implant. $He will still look pregnant post surgery and recovery. diff --git a/src/pregmod/customizeSlaveTrade.tw b/src/pregmod/customizeSlaveTrade.tw index 9bed5816c428666b447cbccbe7483faa8761b2dc..ee3ba43a421b90297edbddbd721abc83c09621fc 100644 --- a/src/pregmod/customizeSlaveTrade.tw +++ b/src/pregmod/customizeSlaveTrade.tw @@ -17,7 +17,7 @@ When civilization turned upon itself, some countries readily took to enslaving t <span id="PopControl"><<include "Basenationalities Controls">></span> <br> [[Reset filters|passage()][$baseControlsFilter = "all"]] | [[Clear all nationalities|passage()][$nationalities = {}]] -<br style="clear:both" /><hr style="margin:0"> +<br style="clear:both"><hr style="margin:0"> Vanilla presets: <span id="vanilla-presets"></span> <<script>> diff --git a/src/uncategorized/costsBudget.tw b/src/uncategorized/costsBudget.tw index 91585b2133dcb644703afde1c4fd4bac89b3fd93..abbbf1ca67bfb2f65d9789adb3ce6579090fdaa2 100644 --- a/src/uncategorized/costsBudget.tw +++ b/src/uncategorized/costsBudget.tw @@ -12,7 +12,7 @@ <br> //Here you can view many of the financial details of your arcology, <<= properTitle()>>. The detailed list of slaves and their costs (food, hormones) that you may remember can now be found in the "Slave maintenance" link. Other links will allow you to directly control areas of your arcology to adjust spending to suit your tastes. -<br style="clear:both" /><<if $lineSeparations == 0>><br><<else>><hr style="margin:0"><</if>> +<br style="clear:both"><<if $lineSeparations == 0>><br><<else>><hr style="margin:0"><</if>> <br> Your weekly costs are as follows:// diff --git a/src/uncategorized/seWeddingDouble.tw b/src/uncategorized/seWeddingDouble.tw index 1d7421074727d9b646e938d97aba763a394f73a4..0cdfcb93f079927fcccb8f683a1f5eb23b24bd20 100644 --- a/src/uncategorized/seWeddingDouble.tw +++ b/src/uncategorized/seWeddingDouble.tw @@ -1841,7 +1841,6 @@ <<set _slave1.devotion -= 5, _slave1.trust -= 5>> <</if>> <</if>> - <</if>> <<else>> <<if _slave1.devotion+_slave1.trust >= 175>> <<if _slave1.relationship > 0>> @@ -1895,6 +1894,7 @@ <</if>> <</if>> <</if>> + <</if>> <<set _slave1.relationship = -3>> <<set _slave1.oralCount += 50>> @@ -2551,4 +2551,4 @@ <</if>> <<set $trinkets.push($desc)>> -<</if>> \ No newline at end of file +<</if>>