Skip to content

Commit

Permalink
🚧 Add escape one line comment & remove color clash
Browse files Browse the repository at this point in the history
  • Loading branch information
WeeskyBDW committed Aug 28, 2021
1 parent 287b341 commit 05dd2fe
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions src/main/java/io/github/syst3ms/skriptparser/file/FileParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,11 @@ public static List<FileElement> parseFileLines(String fileName, List<String> lin
var line = lines.get(i);
String content = removeComments(line);

if (content == null) {
content = line.replace("##", "#").strip();
}
else if (content.isEmpty()) {
if (content.isEmpty()) {
elements.add(new VoidElement(fileName, lastLine + i, expectedIndentation));
continue;
}

//System.out.println(content);

var lineIndentation = FileUtils.getIndentationLevel(line, false);
if (lineIndentation > expectedIndentation) { // The line is indented too much
logger.error(
Expand Down Expand Up @@ -102,19 +97,17 @@ private static String removeComments(String string) {
for (char c : string.toCharArray()) {
if (c == '#') {
int index = string.indexOf(c);
//System.out.println(c + " : " + COMMENT_STATUS);
//Checking if it isn't color hex and if no double # (for escaping first #)
for (int i : new int[]{3, 6, 9}) {
if (index + i <= string.length())
if (!Color.COLOR_PATTERN.matcher(string.substring(index, index + i)).matches() || string.charAt(index + 1) != '#') {
if (index + 1 >= string.length()) return "";
if (string.charAt(index + 1) != '#') { //double # escape the first #
//Checking if it isn't color hex and if no double # (for escaping first #)
for (int i : new int[]{3, 6, 9}) {
if (index + i <= string.length() - 1 && !Color.COLOR_PATTERN.matcher(string.substring(index + 1, index + i + 1)).matches())
COMMENT_STATUS = 1;
System.out.println(COMMENT_STATUS);
}
}
}
//System.out.println(string.substring(index, index + 2));
//set start or end of a block comment ("###" characters)
if (index + 2 <= string.length() && string.substring(index, index + 2).equals("##")) {
COMMENT_STATUS = COMMENT_STATUS == 2 ? 0 : 2;
System.out.println(COMMENT_STATUS);
}

}
Expand All @@ -123,7 +116,6 @@ private static String removeComments(String string) {
}
}
if (COMMENT_STATUS == 1) COMMENT_STATUS = 0;
//System.out.println(stringBuilder.toString());
return stringBuilder.toString().strip();

}
Expand Down

0 comments on commit 05dd2fe

Please sign in to comment.