Skip to content

Commit 7a61292

Browse files
committed
🚧 Add escape one line comment & remove color clash
1 parent 54edd72 commit 7a61292

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

src/main/java/io/github/syst3ms/skriptparser/file/FileParser.java

+8-16
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,11 @@ public static List<FileElement> parseFileLines(String fileName, List<String> lin
3737
var line = lines.get(i);
3838
String content = removeComments(line);
3939

40-
if (content == null) {
41-
content = line.replace("##", "#").strip();
42-
}
43-
else if (content.isEmpty()) {
40+
if (content.isEmpty()) {
4441
elements.add(new VoidElement(fileName, lastLine + i, expectedIndentation));
4542
continue;
4643
}
4744

48-
//System.out.println(content);
49-
5045
var lineIndentation = FileUtils.getIndentationLevel(line, false);
5146
if (lineIndentation > expectedIndentation) { // The line is indented too much
5247
logger.error(
@@ -102,19 +97,17 @@ private static String removeComments(String string) {
10297
for (char c : string.toCharArray()) {
10398
if (c == '#') {
10499
int index = string.indexOf(c);
105-
//System.out.println(c + " : " + COMMENT_STATUS);
106-
//Checking if it isn't color hex and if no double # (for escaping first #)
107-
for (int i : new int[]{3, 6, 9}) {
108-
if (index + i <= string.length())
109-
if (!Color.COLOR_PATTERN.matcher(string.substring(index, index + i)).matches() || string.charAt(index + 1) != '#') {
100+
if (index + 1 >= string.length()) return "";
101+
if (string.charAt(index + 1) != '#') { //double # escape the first #
102+
//Checking if it isn't color hex and if no double # (for escaping first #)
103+
for (int i : new int[]{3, 6, 9}) {
104+
if (index + i <= string.length() - 1 && !Color.COLOR_PATTERN.matcher(string.substring(index + 1, index + i + 1)).matches())
110105
COMMENT_STATUS = 1;
111-
System.out.println(COMMENT_STATUS);
112-
}
106+
}
113107
}
114-
//System.out.println(string.substring(index, index + 2));
108+
//set start or end of a block comment ("###" characters)
115109
if (index + 2 <= string.length() && string.substring(index, index + 2).equals("##")) {
116110
COMMENT_STATUS = COMMENT_STATUS == 2 ? 0 : 2;
117-
System.out.println(COMMENT_STATUS);
118111
}
119112

120113
}
@@ -123,7 +116,6 @@ private static String removeComments(String string) {
123116
}
124117
}
125118
if (COMMENT_STATUS == 1) COMMENT_STATUS = 0;
126-
//System.out.println(stringBuilder.toString());
127119
return stringBuilder.toString().strip();
128120

129121
}

0 commit comments

Comments
 (0)