Search in sources :

Example 21 with ConfigCompileException

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());
}
Also used : PersistenceNetwork(com.laytonsmith.persistence.PersistenceNetwork) ConfigCompileException(com.laytonsmith.core.exceptions.ConfigCompileException) TaskManager(com.laytonsmith.core.taskmanager.TaskManager) Profiler(com.laytonsmith.core.profiler.Profiler) Profiles(com.laytonsmith.core.Profiles) ConnectionMixinFactory(com.laytonsmith.persistence.io.ConnectionMixinFactory) MethodScriptExecutionQueue(com.laytonsmith.core.MethodScriptExecutionQueue) CommandHelperEnvironment(com.laytonsmith.core.environments.CommandHelperEnvironment) Environment(com.laytonsmith.core.environments.Environment) CommandHelperEnvironment(com.laytonsmith.core.environments.CommandHelperEnvironment) GlobalEnv(com.laytonsmith.core.environments.GlobalEnv) ConfigCompileGroupException(com.laytonsmith.core.exceptions.ConfigCompileGroupException)

Example 22 with ConfigCompileException

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());
    }
}
Also used : Script(com.laytonsmith.core.Script) AliasCore(com.laytonsmith.core.AliasCore) ArrayList(java.util.ArrayList) ConfigCompileGroupException(com.laytonsmith.core.exceptions.ConfigCompileGroupException) File(java.io.File) ConfigCompileException(com.laytonsmith.core.exceptions.ConfigCompileException)

Example 23 with ConfigCompileException

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);
    }
}
Also used : EmptyStackException(java.util.EmptyStackException) ConfigCompileException(com.laytonsmith.core.exceptions.ConfigCompileException)

Example 24 with ConfigCompileException

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;
}
Also used : CFunction(com.laytonsmith.core.constructs.CFunction) ConfigCompileException(com.laytonsmith.core.exceptions.ConfigCompileException) ParseTree(com.laytonsmith.core.ParseTree)

Example 25 with ConfigCompileException

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;
}
Also used : CFunction(com.laytonsmith.core.constructs.CFunction) CKeyword(com.laytonsmith.core.constructs.CKeyword) ConfigCompileException(com.laytonsmith.core.exceptions.ConfigCompileException) ParseTree(com.laytonsmith.core.ParseTree) CString(com.laytonsmith.core.constructs.CString)

Aggregations

ConfigCompileException (com.laytonsmith.core.exceptions.ConfigCompileException)37 ParseTree (com.laytonsmith.core.ParseTree)16 CFunction (com.laytonsmith.core.constructs.CFunction)14 ArrayList (java.util.ArrayList)13 ConfigCompileGroupException (com.laytonsmith.core.exceptions.ConfigCompileGroupException)12 CString (com.laytonsmith.core.constructs.CString)11 Construct (com.laytonsmith.core.constructs.Construct)8 Token (com.laytonsmith.core.constructs.Token)8 IVariable (com.laytonsmith.core.constructs.IVariable)7 Target (com.laytonsmith.core.constructs.Target)6 GlobalEnv (com.laytonsmith.core.environments.GlobalEnv)6 Function (com.laytonsmith.core.functions.Function)6 Variable (com.laytonsmith.core.constructs.Variable)5 CommandHelperEnvironment (com.laytonsmith.core.environments.CommandHelperEnvironment)5 Environment (com.laytonsmith.core.environments.Environment)5 ConfigRuntimeException (com.laytonsmith.core.exceptions.ConfigRuntimeException)5 FunctionBase (com.laytonsmith.core.functions.FunctionBase)5 File (java.io.File)5 List (java.util.List)5 FunctionList (com.laytonsmith.core.functions.FunctionList)4