use of com.laytonsmith.core.exceptions.ConfigCompileException in project CommandHelper by EngineHub.
the class Manager method start.
@SuppressWarnings("ResultOfObjectAllocationIgnored")
public static void start() throws IOException, DataSourceException, URISyntaxException, Profiles.InvalidProfileException {
Implementation.useAbstractEnumThread(false);
Implementation.forceServerType(Implementation.Type.BUKKIT);
ConnectionMixinFactory.ConnectionMixinOptions options = new ConnectionMixinFactory.ConnectionMixinOptions();
options.setWorkingDirectory(chDirectory);
persistenceNetwork = new PersistenceNetwork(CommandHelperFileLocations.getDefault().getPersistenceConfig(), CommandHelperFileLocations.getDefault().getDefaultPersistenceDBFile().toURI(), options);
Installer.Install(chDirectory);
CHLog.initialize(chDirectory);
profiler = new Profiler(CommandHelperFileLocations.getDefault().getProfilerConfigFile());
gEnv = new GlobalEnv(new MethodScriptExecutionQueue("Manager", "default"), profiler, persistenceNetwork, chDirectory, new Profiles(MethodScriptFileLocations.getDefault().getProfilesFile()), new TaskManager());
cls();
pl("\n" + Static.Logo() + "\n\n" + Static.DataManagerLogo());
pl("Starting the Data Manager...");
try {
Environment env = Environment.createEnvironment(gEnv, new CommandHelperEnvironment());
MethodScriptCompiler.execute(MethodScriptCompiler.compile(MethodScriptCompiler.lex("player()", null, true)), env, null, null);
} catch (ConfigCompileException | ConfigCompileGroupException ex) {
}
pl(GREEN + "Welcome to the CommandHelper " + CYAN + "Data Manager!");
pl(BLINKON + RED + "Warning!" + BLINKOFF + YELLOW + " Be sure your server is not running before using this tool to make changes to your database!");
pl("------------------------");
boolean finished = false;
do {
pl(YELLOW + "What function would you like to run? Type \"help\" for a full list of options.");
String input = prompt();
pl();
if (input.toLowerCase().startsWith("help")) {
help(input.replaceFirst("help ?", "").toLowerCase().split(" "));
} else if (input.equalsIgnoreCase("refactor")) {
refactor();
} else if (input.toLowerCase().startsWith("print")) {
print(input.replaceFirst("print ?", "").toLowerCase().split(" "));
} else if (input.equalsIgnoreCase("cleardb")) {
cleardb();
} else if (input.equalsIgnoreCase("edit")) {
edit();
} else if (input.equalsIgnoreCase("merge")) {
merge();
} else if (input.equalsIgnoreCase("interpreter")) {
new Interpreter(null, System.getProperty("user.dir"));
} else if (input.equalsIgnoreCase("hidden-keys")) {
hiddenKeys();
} else if (input.equalsIgnoreCase("exit")) {
pl("Thanks for using the " + CYAN + BOLD + "Data Manager!" + reset());
finished = true;
} else {
pl("I'm sorry, that's not a valid command. Here's the help:");
help(new String[] {});
}
} while (finished == false);
StreamUtils.GetSystemOut().println(TermColors.reset());
}
use of com.laytonsmith.core.exceptions.ConfigCompileException in project CommandHelper by EngineHub.
the class MSLPMaker method start.
public static void start(String path) throws IOException {
File start = new File(path);
if (!start.exists()) {
StreamUtils.GetSystemErr().println("The specified file does not exist!");
return;
}
File output = new File(start.getParentFile(), start.getName() + ".mslp");
if (output.exists()) {
pl("The file " + output.getName() + " already exists, would you like to overwrite? (Y/N)");
String overwrite = prompt();
if (!overwrite.equalsIgnoreCase("y")) {
return;
}
}
// First attempt to compile it, and make sure it doesn't fail
AliasCore.LocalPackage localPackage = new AliasCore.LocalPackage();
AliasCore.GetAuxAliases(start, localPackage);
boolean error = false;
for (AliasCore.LocalPackage.FileInfo fi : localPackage.getMSFiles()) {
try {
MethodScriptCompiler.compile(MethodScriptCompiler.lex(fi.contents(), fi.file(), true));
} catch (ConfigCompileException e) {
error = true;
ConfigRuntimeException.HandleUncaughtException(e, "Compile error in script. Compilation will attempt to continue, however.", null);
} catch (ConfigCompileGroupException ex) {
error = true;
ConfigRuntimeException.HandleUncaughtException(ex, null);
}
}
List<Script> allScripts = new ArrayList<>();
for (AliasCore.LocalPackage.FileInfo fi : localPackage.getMSAFiles()) {
List<Script> tempScripts;
try {
tempScripts = MethodScriptCompiler.preprocess(MethodScriptCompiler.lex(fi.contents(), fi.file(), false));
for (Script s : tempScripts) {
try {
s.compile();
s.checkAmbiguous(allScripts);
allScripts.add(s);
} catch (ConfigCompileException e) {
error = true;
ConfigRuntimeException.HandleUncaughtException(e, "Compile error in script. Compilation will attempt to continue, however.", null);
} catch (ConfigCompileGroupException e) {
error = true;
ConfigRuntimeException.HandleUncaughtException(e, "Compile errors in script. Compilation will attempt to continue, however.", null);
}
}
} catch (ConfigCompileException e) {
error = true;
ConfigRuntimeException.HandleUncaughtException(e, "Could not compile file " + fi.file() + " compilation will halt.", null);
}
}
if (!error) {
ZipMaker.MakeZip(start, output.getName());
pl(GREEN + "The MSLP file has been created at " + output.getAbsolutePath() + reset());
} else {
pl(RED + "MSLP file has not been created due to compile errors. Correct the errors, and try again." + reset());
}
}
use of com.laytonsmith.core.exceptions.ConfigCompileException in project CommandHelper by EngineHub.
the class CompilerObject method popNode.
private void popNode(Target t) throws ConfigCompileException {
try {
nodes.pop();
pointer = nodes.peek();
} catch (EmptyStackException e) {
throw new ConfigCompileException("Unmatched closing parenthesis. (Did you put too many right parenthesis?)", t);
}
}
use of com.laytonsmith.core.exceptions.ConfigCompileException in project CommandHelper by EngineHub.
the class InstanceofKeyword method process.
@Override
public int process(List<ParseTree> list, int keywordPosition) throws ConfigCompileException {
if (list.get(keywordPosition).getData() instanceof CFunction) {
// It's not a keyword, it's a function
return keywordPosition;
}
if (keywordPosition == 0) {
throw new ConfigCompileException("Expected value to proceed \"instanceof\" keyword, but no identifiers were found.", list.get(keywordPosition).getTarget());
}
if (list.size() <= keywordPosition + 1) {
throw new ConfigCompileException("Expected type to follow \"instanceof\" keyword, but no type was found.", list.get(keywordPosition).getTarget());
}
ParseTree node = new ParseTree(new CFunction(INSTANCEOF, list.get(keywordPosition).getTarget()), list.get(keywordPosition).getFileOptions());
node.addChild(list.get(keywordPosition - 1));
node.addChild(list.get(keywordPosition + 1));
// Overwrite the LHS
list.set(keywordPosition - 1, node);
// Remove the keyword
list.remove(keywordPosition);
// Remove the RHS
list.remove(keywordPosition);
return keywordPosition;
}
use of com.laytonsmith.core.exceptions.ConfigCompileException in project CommandHelper by EngineHub.
the class ProcKeyword method process.
@Override
public int process(List<ParseTree> list, int keywordPosition) throws ConfigCompileException {
if (list.get(keywordPosition).getData() instanceof CKeyword) {
// It's a lone keyword, so we expect some function to follow, which is the proc name + variables
if (list.get(keywordPosition + 1).getData() instanceof CFunction) {
ParseTree proc = new ParseTree(new CFunction(PROC, list.get(keywordPosition).getTarget()), list.get(keywordPosition).getFileOptions());
proc.addChild(new ParseTree(new CString(list.get(keywordPosition + 1).getData().val(), list.get(keywordPosition + 1).getTarget()), list.get(keywordPosition + 1).getFileOptions()));
// Grab the functions children, and put them on the stack
for (ParseTree child : list.get(keywordPosition + 1).getChildren()) {
proc.addChild(child);
}
if (list.size() > keywordPosition + 2) {
validateCodeBlock(list.get(keywordPosition + 2), "Expected braces to follow proc definition");
proc.addChild(getArgumentOrNull(list.get(keywordPosition + 2)));
} else {
throw new ConfigCompileException("Expected braces to follow proc definition", list.get(keywordPosition + 1).getTarget());
}
// Remove the keyword
list.remove(keywordPosition);
// Remove the function definition
list.remove(keywordPosition);
// Remove the cbrace
list.remove(keywordPosition);
// Add in the new proc definition
list.add(keywordPosition, proc);
} else {
throw new ConfigCompileException("Unexpected use of \"proc\" keyword", list.get(keywordPosition).getTarget());
}
} else if (nodeIsProcFunction(list.get(keywordPosition))) {
// It's the functional usage, possibly followed by a cbrace. If so, pull the cbrace in, and that's it
if (list.size() > keywordPosition + 1) {
if (isValidCodeBlock(list.get(keywordPosition + 1))) {
list.get(keywordPosition).addChild(getArgumentOrNull(list.get(keywordPosition + 1)));
list.remove(keywordPosition + 1);
}
}
} else {
// Random keyword in the middle of nowhere
throw new ConfigCompileException("Unexpected use of \"proc\" keyword", list.get(keywordPosition).getTarget());
}
return keywordPosition;
}
Aggregations