Permalink
Browse files

Add keyword support to reflect_pull

  • Loading branch information...
LadyCailin committed Sep 12, 2018
1 parent 34a6f3f commit 75dc6d0fa923678d95a73ce704ff5a0e3b9def00
Showing with 26 additions and 1 deletion.
  1. +26 −1 src/main/java/com/laytonsmith/core/functions/Reflection.java
@@ -16,6 +16,8 @@
import com.laytonsmith.core.Script;
import com.laytonsmith.core.Static;
import com.laytonsmith.core.compiler.FileOptions;
import com.laytonsmith.core.compiler.Keyword;
import com.laytonsmith.core.compiler.KeywordList;
import com.laytonsmith.core.constructs.CArray;
import com.laytonsmith.core.constructs.CFunction;
import com.laytonsmith.core.constructs.CInt;
@@ -31,6 +33,7 @@
import com.laytonsmith.core.events.EventList;
import com.laytonsmith.core.exceptions.CRE.CREFormatException;
import com.laytonsmith.core.exceptions.CRE.CREIOException;
import com.laytonsmith.core.exceptions.CRE.CREIllegalArgumentException;
import com.laytonsmith.core.exceptions.CRE.CREInsufficientArgumentsException;
import com.laytonsmith.core.exceptions.CRE.CREThrowable;
import com.laytonsmith.core.exceptions.ConfigCompileException;
@@ -47,6 +50,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -97,7 +101,10 @@ public String docs() {
+ "<tr><td>col</td><td></td><td>The current column number</td></tr>"
+ "<tr><td>datasources</td><td></td><td>An array of data source protocols available</td></tr>"
+ "<tr><td>enum</td><td>[enum name]</td><td>An array of enum names, or if one is provided, a list of all"
+ " the values in that enum</td></tr>"
+ " the values in that enum</td>"
+ "<tr><td>keywords</td><td>[keyword name]</td><td>Lists the keywords, if no parameter is provided, otherwise"
+ " provides the documentation for the specified keyword</td>"
+ "</tr>"
+ "</table>";
//+ "<tr><td></td><td></td><td></td></tr>"
}
@@ -195,6 +202,24 @@ public Construct exec(Target t, Environment env, Construct... args) throws Confi
}
}
return a;
} else if("keywords".equalsIgnoreCase(param)) {
if(args.length == 1) {
CArray a = new CArray(t);
List<Keyword> l = new ArrayList<>(KeywordList.getKeywordList());
l.forEach(new Consumer<Keyword>() {
@Override
public void accept(Keyword t) {
a.push(new CString(t.getKeywordName(), Target.UNKNOWN), Target.UNKNOWN);
}
});
return new ArrayHandling.array_sort().exec(t, env, a);
} else if(args.length == 2) {
Keyword k = KeywordList.getKeywordByName(args[1].val());
if(k == null) {
throw new CREIllegalArgumentException(args[1].val() + " is not a valid keyword", t);
}
return new CString(k.docs(), Target.UNKNOWN);
}
}
throw new CREFormatException("The arguments passed to " + getName() + " are incorrect. Please check them and try again.", t);

0 comments on commit 75dc6d0

Please sign in to comment.