Skip to content
Snippets Groups Projects
Commit f87a83f3 authored by klorpa's avatar klorpa
Browse files

Commit

parents aeab44b4 43a8c98b
No related branches found
No related tags found
No related merge requests found
Showing
with 382 additions and 92 deletions
...@@ -103,4 +103,5 @@ package.json ...@@ -103,4 +103,5 @@ package.json
fc-pregmod fc-pregmod
*.outline *.outline
*.todo *.todo
TODO.txt TODO.txt
\ No newline at end of file .vscode/settings.json
{ {
"eslint.enable": false
} }
\ No newline at end of file
No preview for this file type
@echo off
:: Free Cities Basic Compiler - Windows
:: Set working directory
pushd %~dp0
:: See if we can find a git installation
setlocal enabledelayedexpansion
for %%k in (HKCU HKLM) do (
for %%w in (\ \Wow6432Node\) do (
for /f "skip=2 delims=: tokens=1*" %%a in ('reg query "%%k\SOFTWARE%%wMicrosoft\Windows\CurrentVersion\Uninstall\Git_is1" /v InstallLocation 2^> nul') do (
for /f "tokens=3" %%z in ("%%a") do (
set GIT=%%z:%%b
set GITFOUND=yes
goto FOUND
)
)
)
)
:FOUND
if %GITFOUND% == yes (
set "PATH=%GIT%bin;%PATH%"
bash --login -c ./java+gitGrep-sanityCheck.sh
)
:: Compile the game
call "%~dp0compile.bat"
if %GITFOUND% == yes (
:: Make the output prettier, replacing \t with a tab and \n with a newline
bash -c "sed -i -e '/^.*<div id=\"store-area\".*$/s/\\\t/\t/g' -e '/^.*<div id=\"store-area\".*$/s/\\\n/\n/g' bin/FC_pregmod.html"
:: Revert ./src/init/storyInit.tw for next compilation
git checkout -- ./src/init/storyInit.tw
)
popd
PAUSE
#!/bin/bash
# Run sanity check.
./java+gitGrep-sanityCheck.sh
HASH="$(git rev-list -n 1 --abbrev-commit HEAD)"
export TWEEGO_PATH=devTools/tweeGo/storyFormats
TWEEGO_EXE="tweego"
if hash $TWEEGO_EXE 2>/dev/null; then
echo "system tweego binary"
else
case "$(uname -m)" in
x86_64|amd64)
echo "x64 arch"
if [ "$(uname -s)" = "Darwin" ]; then
TWEEGO_EXE="./devTools/tweeGo/tweego_osx64"
else
TWEEGO_EXE="./devTools/tweeGo/tweego_nix64"
fi
;;
x86|i[3-6]86)
echo "x86 arch"
if [ "$(uname -s)" = "Darwin" ]; then
TWEEGO_EXE="./devTools/tweeGo/tweego_osx86"
else
TWEEGO_EXE="./devTools/tweeGo/tweego_nix86"
fi
;;
*)
echo "No system tweego binary found, and no precompiled binary for your platform available"
echo "Please compile tweego and put the executable in PATH"
exit 2
esac
fi
$TWEEGO_EXE -o "bin/FC_pregmod_${HASH}_tmp.html" src/
#Make the output prettier, replacing \t with a tab and \n with a newline
sed -i -e '/^<div id="store-area".*$/s/\\t/\t/g' -e '/^<div id="store-area".*$/s/\\n/\n/g' "bin/FC_pregmod_${HASH}_tmp.html" \
&& mv "bin/FC_pregmod_${HASH}_tmp.html" "bin/FC_pregmod_${HASH}.html"
echo "FC_pregmod_$HASH.html compilation finished."
...@@ -623,3 +623,35 @@ div.tab button.active { ...@@ -623,3 +623,35 @@ div.tab button.active {
opacity: 1; opacity: 1;
} }
} }
/*:: Options Macro [stylesheet]*/
.optionMacroDescription {
}
.optionMacroOption {
}
/* Separate each option with a | */
.optionMacroOption::after {
content: " | ";
}
/* But don't add the | after the last one */
.optionMacroOption:last-child::after {
content: unset;
}
.optionMacroOption a {
}
.optionMacroOption:hover {
}
.optionMacroSelected {
}
/* Container div of the list of options */
.optionMacroOptionsList {
}
...@@ -3,14 +3,4 @@ ...@@ -3,14 +3,4 @@
# #
src/art/ src/art/
src/gui/svgFilters.tw src/gui/svgFilters.tw
#
#excluded to reduce false positives until better solution:
src/pregmod/basenationalitiesControls.tw
src/pregmod/editGenetics.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
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#included to reduce false positives until better solution #included to reduce false positives until better solution
!-- !--
http://www.gnu.org/licenses/ http://www.gnu.org/licenses/
-400
#html tags #html tags
a;1 a;1
b;1 b;1
......
...@@ -12,6 +12,9 @@ import java.nio.file.Path; ...@@ -12,6 +12,9 @@ import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.*; import java.util.*;
/**
* @author Arkerthan
*/
public class Main { public class Main {
public static TagSearchTree<Tag> htmlTags, twineTags; public static TagSearchTree<Tag> htmlTags, twineTags;
...@@ -22,6 +25,7 @@ public class Main { ...@@ -22,6 +25,7 @@ public class Main {
private static String[] excluded; private static String[] excluded;
public static void main(String[] args) { public static void main(String[] args) {
//setup //setup
setupExclude(); setupExclude();
setupHtmlTags(); setupHtmlTags();
...@@ -31,7 +35,7 @@ public class Main { ...@@ -31,7 +35,7 @@ public class Main {
//actual sanityCheck //actual sanityCheck
runSanityCheckInDirectory(workingDir, new File("src/")); runSanityCheckInDirectory(workingDir, new File("src/"));
//handle errors //output errors
for (SyntaxError e : for (SyntaxError e :
errors) { errors) {
System.out.println(e.getError()); System.out.println(e.getError());
...@@ -41,7 +45,7 @@ public class Main { ...@@ -41,7 +45,7 @@ public class Main {
/** /**
* Goes through the whole directory including subdirectories and runs * Goes through the whole directory including subdirectories and runs
* sanityCheck() on all .tw files * {@link Main#sanityCheck(Path)} on all .tw files
* *
* @param dir to be checked * @param dir to be checked
*/ */
...@@ -61,7 +65,7 @@ public class Main { ...@@ -61,7 +65,7 @@ public class Main {
} }
} catch (NullPointerException e) { } catch (NullPointerException e) {
e.printStackTrace(); e.printStackTrace();
System.err.println("Couldn't find directory " + currentFile); System.err.println("Couldn't read directory " + currentFile);
System.exit(-1); System.exit(-1);
} }
} }
...@@ -78,42 +82,33 @@ public class Main { ...@@ -78,42 +82,33 @@ public class Main {
Charset encoding = Charset.defaultCharset(); Charset encoding = Charset.defaultCharset();
if (!excluded(file.getPath())) { if (!excluded(file.getPath())) {
try { currentFile = file.getPath();
currentFile = file.getPath(); currentLine = 1;
currentLine = 1; stack = new Stack<>();
stack = new Stack<>();
//actually opening and reading the file
//actually opening and reading the file try (InputStream in = new FileInputStream(file);
try (InputStream in = new FileInputStream(file); Reader reader = new InputStreamReader(in, encoding);
Reader reader = new InputStreamReader(in, encoding); // buffer for efficiency
// buffer for efficiency Reader buffer = new BufferedReader(reader)) {
Reader buffer = new BufferedReader(reader)) { handleCharacters(buffer);
handleCharacters(buffer);
}
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace();
System.err.println("Couldn't read " + file); System.err.println("Couldn't read " + file);
} }
} }
} }
/** /**
* sets up the alphabetical search tree for fast access of HTML tags later * sets up a {@link TagSearchTree<Tag>} for fast access of HTML tags later
*/ */
private static void setupHtmlTags() { private static void setupHtmlTags() {
//load HTML tags into a list //load HTML tags into a list
List<Tag> TagsList = new LinkedList<>(); List<Tag> TagsList = loadTags("devTools/javaSanityCheck/htmlTags");
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 //turn List into alphabetical search tree
try { try {
htmlTags = new TagSearchTree(TagsList); htmlTags = new TagSearchTree<>(TagsList);
} catch (ArrayIndexOutOfBoundsException e) { } catch (ArrayIndexOutOfBoundsException e) {
System.err.println("Illegal Character in devTools/javaSanityCheck/htmlTags"); System.err.println("Illegal Character in devTools/javaSanityCheck/htmlTags");
System.exit(-1); System.exit(-1);
...@@ -121,29 +116,39 @@ public class Main { ...@@ -121,29 +116,39 @@ public class Main {
} }
/** /**
* sets up the alphabetical search tree for fast access of twine tags later * sets up a {@link TagSearchTree<Tag>} for fast access of twine tags later
*/ */
private static void setupTwineTags() { private static void setupTwineTags() {
//load twine tags into a list //load twine tags into a list
List<Tag> TagsList = new LinkedList<>(); List tagsList = loadTags("devTools/javaSanityCheck/twineTags");
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 //turn List into alphabetical search tree
try { try {
twineTags = new TagSearchTree(TagsList); twineTags = new TagSearchTree<>(tagsList);
} catch (ArrayIndexOutOfBoundsException e) { } catch (ArrayIndexOutOfBoundsException e) {
System.err.println("Illegal Character in devTools/javaSanityCheck/twineTags"); System.err.println("Illegal Character in devTools/javaSanityCheck/twineTags");
System.exit(-1); 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 * Turns a string into a Tag
* ";1" at the end of the String indicates that the tag needs to be closed later * ";1" at the end of the String indicates that the tag needs to be closed later
...@@ -160,7 +165,7 @@ public class Main { ...@@ -160,7 +165,7 @@ public class Main {
} }
/** /**
* sets up the excluded array. * sets up the excluded files array.
*/ */
private static void setupExclude() { private static void setupExclude() {
//load excluded files //load excluded files
...@@ -173,7 +178,7 @@ public class Main { ...@@ -173,7 +178,7 @@ public class Main {
System.err.println("Couldn't read devTools/javaSanityCheck/excluded"); System.err.println("Couldn't read devTools/javaSanityCheck/excluded");
} }
//turn excluded files into an array and change them to windows style if needed //turn excluded files into an array and change path to windows style if needed
if (isWindows()) { if (isWindows()) {
excluded = new String[excludedList.size()]; excluded = new String[excludedList.size()];
int i = 0; int i = 0;
...@@ -252,33 +257,37 @@ public class Main { ...@@ -252,33 +257,37 @@ public class Main {
stack.pop(); stack.pop();
return; return;
} }
//3 means the Element is complete and part of a two tag system //3 means the Element is complete and part of a two or more tag system
if (change == 3) { if (change == 3) {
//remove the topmost element from stack since it is complete //remove the topmost element from stack since it is complete
KnownElement k = stack.pop().getKnownElement(); KnownElement k = stack.pop().getKnownElement();
/*if (k.isOpening()) { //if KnownElement k is closing another element, check if there is one and remove it
stack.push(k);
} else */
if (k.isClosing()) { if (k.isClosing()) {
if (stack.empty()) { if (stack.empty()) { //there are no open elements at all
addError(new SyntaxError("Closed tag " + k.getShortDescription() + " without having any open tags.", -2)); addError(new SyntaxError("Closed tag " + k.getShortDescription() + " without " +
"having any open tags.", -2));
} else if (stack.peek() instanceof KnownElement) { } else if (stack.peek() instanceof KnownElement) {
//get opening tag
KnownElement kFirst = (KnownElement) stack.pop(); KnownElement kFirst = (KnownElement) stack.pop();
//check if closing element matches the opening element
if (!kFirst.isMatchingElement(k)) { if (!kFirst.isMatchingElement(k)) {
addError(new SyntaxError("Opening tag " + kFirst.getShortDescription() + addError(new SyntaxError("Opening tag " + kFirst.getShortDescription() +
" does not match closing tag " + k.getShortDescription() + ".", -2)); " does not match closing tag " + k.getShortDescription() + ".", -2));
} }
//stack.pop();
} else { } else {
//There closing tag inside another not Known element: <div </html>
addError(new SyntaxError("Closing tag " + k.getShortDescription() + " inside " + addError(new SyntaxError("Closing tag " + k.getShortDescription() + " inside " +
"another tag: " + stack.peek().getShortDescription(), -2, true)); "another tag " + stack.peek().getShortDescription() + " without opening first.",
-2, true));
} }
} }
//check if the element needs to be closed by another
if (k.isOpening()) { if (k.isOpening()) {
stack.push(k); stack.push(k);
} }
return; return;
} }
//means the element couldn't do anything with it and is finished
if (change == 4) { if (change == 4) {
stack.pop(); stack.pop();
} else { } else {
...@@ -291,7 +300,7 @@ public class Main { ...@@ -291,7 +300,7 @@ public class Main {
//innermost element was uninterested, trying to find matching element //innermost element was uninterested, trying to find matching element
switch (c) { switch (c) {
//case '@': //case '@':
// stack.push(new AtElement(currentLine, currentPosition)); //stack.push(new AtElement(currentLine, currentPosition));
//break; //break;
case '<': case '<':
stack.push(new AngleBracketElement(currentLine, currentPosition)); stack.push(new AngleBracketElement(currentLine, currentPosition));
......
...@@ -7,33 +7,57 @@ public class SyntaxError extends Exception { ...@@ -7,33 +7,57 @@ public class SyntaxError extends Exception {
private int change; //see Element for values; -2 means not thrown private int change; //see Element for values; -2 means not thrown
private boolean warning = false; private boolean warning = false;
/**
* @param description description of error
* @param change state change as specified in Element
*/
public SyntaxError(String description, int change) { public SyntaxError(String description, int change) {
this.description = description; this.description = description;
this.change = change; 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) { public SyntaxError(String description, int change, boolean warning) {
this(description, change); this(description, change);
this.warning = warning; this.warning = warning;
} }
/**
* @param file at which the error occurred
*/
public void setFile(String file) { public void setFile(String file) {
this.file = file; this.file = file;
} }
/**
* @param line in which the error occurred
*/
public void setLine(int line) { public void setLine(int line) {
this.line = line; this.line = line;
} }
/**
* @param position at which the error occurred
*/
public void setPosition(int position) { public void setPosition(int position) {
this.position = position; this.position = position;
} }
/**
* @return error message
*/
public String getError() { public String getError() {
String s = warning ? "Warning: " : "Error: "; String s = warning ? "Warning: " : "Error: ";
return s + file + ": " + line + ":" + position + " : "+ description; return s + file + ": " + line + ":" + position + " : " + description;
} }
/**
* @return change that happened in Element before it was thrown. -1 if not thrown.
*/
public int getChange() { public int getChange() {
return change; return change;
} }
......
...@@ -64,7 +64,7 @@ public class AngleBracketElement extends Element { ...@@ -64,7 +64,7 @@ public class AngleBracketElement extends Element {
return handleOpeningHTML(c); return handleOpeningHTML(c);
} catch (SyntaxError e) { } catch (SyntaxError e) {
state = 1; state = 1;
throw new SyntaxError("Opening \"<\" missing, found " + c + " [debug:initialCase]", 1); throw new SyntaxError("Opening \"<\" missing, found " + c, 1);
} }
} }
case 1: case 1:
...@@ -105,7 +105,7 @@ public class AngleBracketElement extends Element { ...@@ -105,7 +105,7 @@ public class AngleBracketElement extends Element {
state = 3; state = 3;
return 1; return 1;
} else { } else {
throw new SyntaxError("Closing \">\" missing, opened [" + line + ":" + pos + "]", 2); throw new SyntaxError("Closing \">\" missing, opened tag at [" + line + ":" + pos + "]", 2);
} }
case 4: case 4:
if (c == '>') { if (c == '>') {
...@@ -120,20 +120,20 @@ public class AngleBracketElement extends Element { ...@@ -120,20 +120,20 @@ public class AngleBracketElement extends Element {
state = 4; state = 4;
return 1; return 1;
} else { } else {
throw new SyntaxError("Closing \">\" missing, opened [" + line + ":" + pos + "]", 2); throw new SyntaxError("Closing \">\" missing, opened tag at[" + line + ":" + pos + "]", 2);
} }
case 5: case 5:
if (c == '>') { if (c == '>') {
state = -5; state = -5;
return 1; return 1;
} else { } else {
throw new SyntaxError("Closing \">\" missing, opened [" + line + ":" + pos + "]", 2); throw new SyntaxError("Closing \">\" missing, opened tag at [" + line + ":" + pos + "]", 2);
} }
case -5: case -5:
if (c == '>') { if (c == '>') {
return 2; return 2;
} }
throw new SyntaxError("Closing \">\" missing, opened [" + line + ":" + pos + "]", 2); throw new SyntaxError("Closing \">\" missing, opened tag at [" + line + ":" + pos + "]", 2);
case 6: case 6:
if (c == '>') { if (c == '>') {
return 3; return 3;
...@@ -141,13 +141,13 @@ public class AngleBracketElement extends Element { ...@@ -141,13 +141,13 @@ public class AngleBracketElement extends Element {
state = 3; state = 3;
return 1; return 1;
} else { } else {
throw new SyntaxError("Closing \">\" missing, opened [" + line + ":" + pos + "]", 3); throw new SyntaxError("Closing \">\" missing, opened tag at [" + line + ":" + pos + "]", 3);
} }
case -6: case -6:
if (c == '>') { if (c == '>') {
return 3; return 3;
} }
throw new SyntaxError("Closing \">\" missing, opened [" + line + ":" + pos + "]", 3); throw new SyntaxError("Closing \">\" missing, opened tag at [" + line + ":" + pos + "]", 3);
case -9: case -9:
if (c == '>') { if (c == '>') {
...@@ -218,7 +218,7 @@ public class AngleBracketElement extends Element { ...@@ -218,7 +218,7 @@ public class AngleBracketElement extends Element {
private int handleClosingHTML(char c) throws SyntaxError { private int handleClosingHTML(char c) throws SyntaxError {
if (c == '>') { if (c == '>') {
if (tree.getElement() == null) { if (tree.getElement() == null) {
throw new SyntaxError("Unknown HTML tag", 2); throw new SyntaxError("Unknown HTML tag: " + tree.getPath(), 2);
} }
if (tree.getElement().single) { if (tree.getElement().single) {
throw new SyntaxError("Single HTML tag used as closing Tag: " + tree.getElement().tag, 2); throw new SyntaxError("Single HTML tag used as closing Tag: " + tree.getElement().tag, 2);
...@@ -243,7 +243,6 @@ public class AngleBracketElement extends Element { ...@@ -243,7 +243,6 @@ public class AngleBracketElement extends Element {
if (tree.getElement() == null) { if (tree.getElement() == null) {
//assuming not listed means widget until better solution //assuming not listed means widget until better solution
return 1; return 1;
//throw new SyntaxError("Unknown Twine tag or closing \">>\" missing, found " + tree.getPath(), 1);
} }
if (!tree.getElement().single) { if (!tree.getElement().single) {
if (logicTags.contains(tree.getElement().tag)) { if (logicTags.contains(tree.getElement().tag)) {
...@@ -260,7 +259,6 @@ public class AngleBracketElement extends Element { ...@@ -260,7 +259,6 @@ public class AngleBracketElement extends Element {
state = -5; state = -5;
if (tree.getElement() == null) { if (tree.getElement() == null) {
//assuming not listed means widget until better solution //assuming not listed means widget until better solution
//throw new SyntaxError("Unknown Twine tag or closing \">>\" missing, found " + tree.getPath(), 1);
return 1; return 1;
} }
if (!tree.getElement().single) { if (!tree.getElement().single) {
...@@ -279,7 +277,6 @@ public class AngleBracketElement extends Element { ...@@ -279,7 +277,6 @@ public class AngleBracketElement extends Element {
if (tree == null) { if (tree == null) {
//assuming not listed means widget until better solution //assuming not listed means widget until better solution
state = 3; state = 3;
//throw new SyntaxError("Unknown Twine tag or closing \">>\" missing, found " + c, 1);
} }
return 1; return 1;
...@@ -288,7 +285,7 @@ public class AngleBracketElement extends Element { ...@@ -288,7 +285,7 @@ public class AngleBracketElement extends Element {
private int handleClosingTwine(char c) throws SyntaxError { private int handleClosingTwine(char c) throws SyntaxError {
if (c == '>') { if (c == '>') {
if (tree.getElement() == null) { if (tree.getElement() == null) {
throw new SyntaxError("Unknown Twine tag", 2); throw new SyntaxError("Unknown Twine tag: " + tree.getPath(), 2);
} }
if (tree.getElement().single) { if (tree.getElement().single) {
throw new SyntaxError("Single Twine tag used as closing Tag: " + tree.getElement().tag, 2); throw new SyntaxError("Single Twine tag used as closing Tag: " + tree.getElement().tag, 2);
...@@ -319,6 +316,7 @@ public class AngleBracketElement extends Element { ...@@ -319,6 +316,7 @@ public class AngleBracketElement extends Element {
case 0: case 0:
builder.append("<"); builder.append("<");
break; break;
//TWINE
case 1: case 1:
builder.append("<<"); builder.append("<<");
break; break;
...@@ -332,28 +330,49 @@ public class AngleBracketElement extends Element { ...@@ -332,28 +330,49 @@ public class AngleBracketElement extends Element {
builder.append("<</").append(tree.getPath()); builder.append("<</").append(tree.getPath());
break; break;
case 3: case 3:
builder.append("<<??? ???"); builder.append("<<???");
break;
case 4:
builder.append("<<?").append(tree.getPath()).append(" ???");
break; break;
case -3: case -3:
builder.append("<<??? ???>"); builder.append("<<???>");
break;
case 4:
builder.append("<<").append(tree.getPath()).append(" ???");
break; break;
case -4: case -4:
builder.append("<<?").append(tree.getPath()).append(" ???>"); builder.append("<<").append(tree.getPath()).append(" ???>");
break; break;
case 5: case 5:
builder.append("<").append(tree.getPath()).append(" ???"); builder.append("<<???");
break; break;
case -5: case -5:
builder.append("</").append(tree.getPath()); builder.append("<<").append(tree == null ? "???" : tree.getPath()).append(">");
break; break;
case 6: case 6:
builder.append("<").append(tree.getPath()).append(" ???"); builder.append("<<").append(tree.getPath()).append(" ???>");
break;
case -6:
builder.append("<</").append(tree.getPath()).append(">");
break;
//HTML
case -9:
builder.append("</");
break; break;
case 10:
builder.append("<").append(tree.getPath());
break;
case -10:
builder.append("</").append(tree.getPath());
break;
case 11:
builder.append("<?").append(tree == null ? "???" : tree.getPath());
break;
case -11:
builder.append("</").append(tree == null ? "???" : tree.getPath());
break;
case 12:
builder.append("<").append(tree.getPath()).append(" ???");
default: default:
//throw new UnknownStateException(state); throw new UnknownStateException(state);
} }
return builder.toString(); return builder.toString();
} }
......
...@@ -4,7 +4,7 @@ import org.arkerthan.sanityCheck.SyntaxError; ...@@ -4,7 +4,7 @@ import org.arkerthan.sanityCheck.SyntaxError;
import org.arkerthan.sanityCheck.UnknownStateException; import org.arkerthan.sanityCheck.UnknownStateException;
public class CommentElement extends Element { public class CommentElement extends Element {
int state = 0; private int state = 0;
/* /*
0 - / 0 - /
1 - /*??? 1 - /*???
...@@ -13,6 +13,10 @@ public class CommentElement extends Element { ...@@ -13,6 +13,10 @@ public class CommentElement extends Element {
4 - /%???% 4 - /%???%
*/ */
/**
* @param line line in which comment starts
* @param pos position in line where comment starts
*/
public CommentElement(int line, int pos) { public CommentElement(int line, int pos) {
super(line, pos); super(line, pos);
} }
......
...@@ -23,12 +23,15 @@ public abstract class Element { ...@@ -23,12 +23,15 @@ public abstract class Element {
* 3 - the Element is finished and a KnownHtmlElement was generated * 3 - the Element is finished and a KnownHtmlElement was generated
* 4 - the Element is finished and the char is still open for use * 4 - the Element is finished and the char is still open for use
* *
* @param c * @param c char to be parsed
* @return * @return state change
* @throws Error * @throws SyntaxError thrown when an syntax error is detected
*/ */
public abstract int handleChar(char c) throws SyntaxError; public abstract int handleChar(char c) throws SyntaxError;
/**
* @return the constructed KnownElement. null if none was constructed yet.
*/
public KnownElement getKnownElement() { public KnownElement getKnownElement() {
return k; return k;
} }
......
...@@ -4,6 +4,10 @@ import org.arkerthan.sanityCheck.SyntaxError; ...@@ -4,6 +4,10 @@ import org.arkerthan.sanityCheck.SyntaxError;
public abstract class KnownElement extends Element { public abstract class KnownElement extends Element {
/**
* @param line at which it begins
* @param pos at which it begins
*/
public KnownElement(int line, int pos) { public KnownElement(int line, int pos) {
super(line, pos); super(line, pos);
} }
......
...@@ -5,6 +5,12 @@ public class KnownHtmlElement extends KnownElement { ...@@ -5,6 +5,12 @@ public class KnownHtmlElement extends KnownElement {
private boolean opening; private boolean opening;
private String statement; private String 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) { public KnownHtmlElement(int line, int pos, boolean opening, String statement) {
super(line, pos); super(line, pos);
this.opening = opening; this.opening = opening;
......
...@@ -5,6 +5,13 @@ public class KnownTwineElement extends KnownElement { ...@@ -5,6 +5,13 @@ public class KnownTwineElement extends KnownElement {
private boolean opening; private boolean opening;
private String statement; private String 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) { public KnownTwineElement(int line, int pos, boolean opening, String statement) {
super(line, pos); super(line, pos);
this.opening = opening; this.opening = opening;
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
#Effectively everything that is allowed in a statements like this: #Effectively everything that is allowed in a statements like this:
#<<tag>> or <<tag ???>> #<<tag>> or <<tag ???>>
#when ;1 is specified it expects a matching closing tag like this: <</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. #Do not add HTML Tags here.
#Characters outside of ASCII scope are not supported. #Characters outside of ASCII scope are not supported.
# #
...@@ -11,19 +9,20 @@ ...@@ -11,19 +9,20 @@
capture;1 capture;1
continue;0 continue;0
for;1 for;1
#does foreach really exist?
foreach;1 foreach;1
goto;0 goto;0
htag;1 htag;1
include;0 include;0
link;1 link;1
nobr;1 nobr;1
options;1
print;0 print;0
replace;1 replace;1
run;0 run;0
script;1 script;1
set;0 set;0
silently;1 silently;1
span;1
textbox;0 textbox;0
timed;1 timed;1
unset;0 unset;0
......
#!/bin/bash
if [ ! -d ".git" ]; then
#not running in git repo, so can't use git commands :-)
echo "No .git repo found - skipping sanity checks"
exit 0
fi
WARNING='\033[93m'
WARNING='\033[93m'
ENDC='\033[0m'
myprint() {
while read data; do
echo -n -e "[$1]$WARNING"
echo "$data"
done
}
GREP="git grep -n --color"
# Check for missing right angle bracket: <</if>
#$GREP "<</[^>]*>[^>]" -- 'src/*' | myprint "MissingClosingAngleBracket"
#$GREP "<<[^>()]*>[^()<>"$'\r]*\r'"\?$" -- 'src/*' | myprint "MissingClosingAngleBracket"
# Check for missing left angle bracket: </if>>
#$GREP "\([^<]\|^\)</\?\(if\|else\|case\|set\|print\|elseif\)" -- 'src/*' | myprint "MissingOpeningAngleBracket2"
# Check for accidental assignment. e.g.: <<if $foo = "hello">>
$GREP "<<[ ]*if[^>=]*[^><\!=]=[^=][^>]*>>" -- 'src/*' | myprint "AccidentalAssignmentInIf"
# Check for accidental assignment. e.g.: <<elseif $foo = "hello">>
$GREP "<<[ ]*elseif[^>=]*[^><\!=]=[^=][^>]*>>" -- 'src/*' | myprint "AccidentalAssignmentInElseIf"
# Check for missing ". e.g.: <<if $foo == "hello>>
$GREP "<<[^\"<>]*\"[^\"<>]*>>" -- 'src/*' | myprint "MissingSpeechMark"
# Check for missing ". e.g.: <<if $foo = "hello)
$GREP -e "<<[^\"<>]*\([^\"<>]*\"[^><\"]*\"\| [<>] \)*\"\([^\"<>]*\"[^><\"]*\"\| [<>] \)*\([^\"<>]\| [<>] \)*>>" --and --not -e "*[^']*" -- 'src/*' | myprint "MissingSpeechMark2"
# Check for colors like: @@color:red - should be @@.red
$GREP -e "@@color:" --and --not -e "@@color:rgb([0-9 ]\+,[0-9 ]\+,[0-9 ]\+)" -- "src/*" | myprint "UseCssColors"
# Check for missing $ in activeSlave or PC
$GREP "<<[ ]*[^\$><_\[]*\(activeSlave\|PC\)[.]" -- "src/*" | myprint "MissingDollar"
# Check for closing bracket without opening bracket. e.g.: <<if foo)>> (but <<case "foo")>> is valid, so ignore those
$GREP -e "<<[ a-zA-Z]\+\([^()<>]\|[^()<>][<>][^()<>]\)*)" --and --not -e "<< *case" -- "src/*" | myprint "MissingOpeningBracket"
# Check for opening bracket without closing bracket. e.g.: <<if (foo>>
$GREP -e "<<[ a-zA-Z]\([^<>]\|[^<>][<>][^<>]\)\+(\([^()<>]\|[^<>()][<>][^<>()]\|([^<>()]*])\)*>>" -- "src/*" | myprint "MissingClosingBracket"
# Check for two closing brackets but one opening bracket. e.g.: <<if (foo))>>
$GREP -e "<<[ a-zA-Z]\+[^()<>]*([^()]*)[^()]*)[^()<>]*>>" -- "src/*" | myprint "MissingOpeningBracket2"
# Check for one closing bracket but two opening brackets. e.g.: <<if ((foo)>>
$GREP -e "<<[ a-zA-Z]\+[^()<>]*([^()]*([^()]*)[^()<>]*>>" -- "src/*" | myprint "MissingClosingBracket2"
$GREP -e "<<.*[(][^<>)]*[(][^<>)]*)\?[^<>)]*>>" -- "src/*" | myprint "MissingClosingBracket3"
# Check for missing >>. e.g.: <<if $foo
#$GREP "<<[^<>]*[^,\"\[{"$'\r]\r'"\?$" -- 'src/*' | myprint "MissingClosingAngleBrackets"
# Check for too many >>>. e.g.: <</if>>>
$GREP "<<[^<>]*[<>]\?[^<>]*>>>" -- "src/*.tw" | myprint "TooManyAngleBrackets"
# Check for too many <<<. e.g.: <<</if>>
#$GREP "<<<[^<>]*[<>]\?[^<>]*>>" -- "src/*.tw" | myprint "TooManyAngleBrackets"
# Check for wrong capitalization on 'activeslave' and other common typos
$GREP -e "\$act" --and --not -e "\$\(activeSlave\|activeChild\|activeArcology\|activeStandard\|activeOrgan\|activeLimbs\|activeUnits\|activeCanine\|activeHooved\|activeFeline\)" -- "src/*" | myprint "WrongCapitilization"
$GREP "\(csae\|[a-z] She \|attepmts\|youreslf\|advnaces\|canAcheive\|setBellySize\|SetbellySize\|setbellySize\|bellypreg\|pregBelly\|bellyimplant\|bellyfluid\|pronounCaps\|carress\|hormonebalance\|fetishknown\)" -- 'src/*' | myprint "SpellCheck"
$GREP "\(recieve\|recieves\)" -- 'src/*' | myprint "PregmodderCannotSpellReceive"
$GREP "\$slave\[" -- 'src/*' | myprint "ShouldBeSlaves"
# Check for strange spaces e.g. $slaves[$i]. lips
$GREP "\$slaves\[\$i\]\. " -- 'src/*' | myprint "MissingPropertyAfterSlaves"
# Check using refreshmentType instead of refreshment
$GREP "\$PC.refreshmentType[^ =]" -- 'src/*' | myprint "ShouldBeRefreshment"
# Check, e.g., <<//if>>
$GREP "<</[a-zA-Z]*[^a-zA-Z<>]\+[a-zA-Z]*>>" -- 'src/*' | myprint "DoubleSlash"
# Check, e.g. <<else $foo==4
#$GREP "<<else >\?[^>]" -- 'src/*' | myprint "ShouldBeElseIf"
# Check, e.g., =to
$GREP "=to" -- 'src/*' | myprint "EqualAndTo"
# Check doing $slaves.foo instead of $slaves[i].foo
$GREP -e "[$]slaves[.]" --and --not -e '[$]slaves[.]\(length\|random\|map\|filter\|deleteAt\|push\|find\|includes\|delete\|forEach\)' -- 'src/*' | myprint "MissingSlavesIndex"
# Try to check for accidentally mixing slaves[] and activeSlave. This can have a lot of false matches, but has caught a lot of bugs so it's worth the pain
$GREP -e "activeSlave[.]" --and -e "slaves\[..\?\][.]" --and --not -e '[.]ID' --and --not -e 'slaves\[..\?\][.]\(slaveName\|slaveSurname\|actualAge\|relation\|assignment\|age\|devotion\|trust\|vagina\|mother\|father\|training\)' -- 'src/*' | myprint "MaybeAccidentalMixingOfSlavesAndActiveSlave"
# Check, e.g. <<set foo == 4>>
$GREP "<<set[^{>=]*==" -- 'src/*' | myprint "DoubleEqualsInSet"
# Check for, e.g <<if slaves[foo]>>
$GREP "<<\([^>]\|[^>]>[^>]\)*[^$]slaves\[" -- 'src/*' | myprint "MissingDollar"
# Check for missing $ or _ in variable name:
$GREP -e "<<[a-zA-Z]\([^>\"]\|[^>]>[^>]\|\"[^\"]*\"\)* [a-zA-Z]\+ * =" -- src/*.tw | myprint "MissingDollar2"
# Check for missing command, e.g. <<foo =
$GREP -e "<<[a-zA-Z]* = *" -- src/*.tw | myprint "BadCommand"
# Check for duplicate words, e.g. with with
$GREP -e " \(\b[a-zA-Z][a-zA-Z]\+\) \1\b " --and --not -e " her her " --and --not -e " you you " --and --not -e " New New " --and --not -e "Slave Slave " --and --not -e " that that " --and --not -e " in in " --and --not -e " is is " -- 'src/*' | myprint "Duplicate words"
# Check for obsolete SugarCube macros
$GREP -E "<<display |<<click|<<.*\.contains" -- src/*.tw | myprint "ObsoleteMacro"
# Check for double articles
$GREP -E "\Wa an\W" -- src/*.tw | myprint "DoubleArticle"
# Check for incorrect articles
$GREP -i -E "\Wa (a|e|i|o|u)." -- src/*.tw | grep -a -i -vE "\Wa (un|eu|us|ut|on|ur|in)." | grep -a -i -vE "(&|<<s>>|UM)." | myprint "IncorrectArticle"
$GREP -i -E "\Wan (b|c|d|f|g|j|k|l|m|n|p|q|r|s|t|v|w|x|y|z)\w." -- src/*.tw | grep -a -i -vE "[A-Z]{3}" | myprint "IncorrectArticle"
# Check for $ sign mid-word
$GREP -i "\w$\w" -- src/*.tw | myprint "VarSignMidWord"
# check for $ sign at beginning of macro
$GREP '<<\s*\$' -- 'src/*' | myprint "VarSignAtMacroStart"
# check for missing ; before statement
$GREP 'if $ ' -- 'src/*' | myprint "missing ; before statement"
$GREP 'elseif $ ' -- 'src/*' | myprint "missing ; before statement"
# Check for a . inside a <<>>
$GREP "<<[a-zA-Z]\([^\"'>]\|[^\"'>]>[^\"'>]\)*[a-zA-Z][.][^a-zA-Z]" | myprint "StrangeCharacterAfterDot"
# Check for @@. instead of .@@
$GREP -E "@@(\.|,|;|:)\s" -- src/*.tw | myprint "WrongSelectorPunctuation"
# Check that we do not have any variables that we use only once. e.g. $onlyUsedOnce
# Ignore *Nationalities
(
cd src/
cat $(find . -name "*.tw" ) | tr -c '$a-zA-Z' '\n' | sed -n '/^[$]/p' | grep -v "Nationalities" | sort | uniq -u | sed 's/^[$]/-e[$]/' | sed 's/$/\\\\W/' | xargs -r git grep -n --color | myprint "OnlyUsedOnce"
cat $(find . -name "*.tw" ) | tr -c '.$a-zA-Z[]_' '\n' | sed 's/SugarCube\.State\.variables\./$/g' | sed -n -e 's/^[$]\(PC\|activeSlave\|\(slaves\|tanks\)\[[^]]*\]*\)[.]\([a-zA-Z]\+\).*$/[.]\3/p' | sort | uniq -u |sed 's/^\(.*\)$/-e\1\\\\\b/' | xargs -r git grep -n --color | myprint "SlaveAttributeUsedOnce"
$GREP "\$\(PC\|activeSlave\|slaves\|tanks\)[.][^a-zA-Z]" | myprint "UnexpectedCharAfterDot"
)
#run the java sanity check
java -jar SanityCheck.jar
java -jar SanityCheck.jar
java -jar SanityCheck.jar
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment