Skip to content

Commit

Permalink
[BREAKING] Rewrite tag parser - no nested tags!
Browse files Browse the repository at this point in the history
<<player>.name> is NO LONGER VALID!
<player[<player>].name> however, remains valid.
Also, add dList to the comparable options.
  • Loading branch information
mcmonkey4eva committed Sep 21, 2014
1 parent fd5e484 commit dc991d7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
Expand Up @@ -412,11 +412,11 @@ public String log(String str) {
public String toString() {
return (logic != Logic.REGULAR ? "Logic='" + logic.toString() + "', " : "")
+ "Comparable='" + (comparable == null ? "null'" : (comparable instanceof Double ? "Decimal":
comparable instanceof String ? "Element": (comparable instanceof Long ? "Number": log(comparable.getClass().getSimpleName())))
comparable instanceof String ? "Element": (comparable instanceof Long ? "Number": (comparable instanceof dList ? "dList" :log(comparable.getClass().getSimpleName()))))
+ "(" + ChatColor.AQUA + comparable + ChatColor.WHITE + ")'")
+ ", Operator='" + operator.toString()
+ "', ComparedTo='" + (comparedto == null ? "null'" : (comparedto instanceof Double ? "Decimal":
comparedto instanceof String ? "Element": (comparedto instanceof Long ? "Number": log(comparedto.getClass().getSimpleName())))
comparedto instanceof String ? "Element": (comparedto instanceof Long ? "Number": (comparedto instanceof dList ? "dList" :log(comparedto.getClass().getSimpleName()))))
+ "(" + ChatColor.AQUA + comparedto + ChatColor.WHITE + ")' ")
+ ChatColor.YELLOW + "--> OUTCOME='" + outcome + "'";
}
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/net/aufdemrand/denizen/tags/Attribute.java
@@ -1,6 +1,8 @@
package net.aufdemrand.denizen.tags;


import net.aufdemrand.denizen.objects.dNPC;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.scripts.ScriptEntry;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -132,14 +134,28 @@ public boolean hasContext(int attribute) {
return text.endsWith("]") && text.contains("[");
}

private dPlayer getPlayer() {
if (getScriptEntry() == null)
return null;
return getScriptEntry().getPlayer();
}

private dNPC getNPC() {
if (getScriptEntry() == null)
return null;
return getScriptEntry().getNPC();
}

public String getContext(int attribute) {
if (hasContext(attribute)) {

String text = getAttribute(attribute);
Matcher contextMatcher = CONTEXT_PATTERN.matcher(text);

if (contextMatcher.find()) {
return TagManager.CleanOutputFully(text.substring(contextMatcher.start() + 1, contextMatcher.end() - 1));
return TagManager.CleanOutputFully(TagManager.tag(
getPlayer(), getNPC(), text.substring(contextMatcher.start() + 1,
contextMatcher.end() - 1), false, getScriptEntry()));
}
}
return null;
Expand Down
29 changes: 19 additions & 10 deletions src/main/java/net/aufdemrand/denizen/tags/TagManager.java
Expand Up @@ -221,17 +221,26 @@ public static String tag(dPlayer player, dNPC npc, String arg, boolean instant,
return CleanOutput(arg);
}

// Match all < > brackets that don't contain < > inside them
private static Pattern tagRegex = Pattern.compile("<([^<>]+)>", Pattern.DOTALL | Pattern.MULTILINE);

private static int[] locateTag(String arg) {
// find escaped brackets

// find tag brackets pattern
Matcher tagMatcher = tagRegex.matcher(arg);
if (tagMatcher.find())
return new int[]{tagMatcher.start(), tagMatcher.end() - 1};
// no matching brackets pattern, return null
int first = arg.indexOf('<');
if (first == -1)
return null;
int len = arg.length();
int bracks = 0;
int second = -1;
for (int i = first + 1; i < len; i++) {
if (arg.charAt(i) == '<')
bracks++;
else if (arg.charAt(i) == '>') {
bracks--;
if (bracks == -1) {
second = i;
break;
}
}
}
if (first > -1 && second > first)
return new int[]{first, second};
else return null;
}

Expand Down

0 comments on commit dc991d7

Please sign in to comment.