forked from ground/ground
Merge pull request 'Add Error Function' (#18) from DiamondNether90/ground_fork:master into master
Reviewed-on: max/ground#18
This commit is contained in:
@@ -15,7 +15,7 @@ def isnumber(num):
|
||||
|
||||
allstr = ""
|
||||
color = ""
|
||||
keywords = ["if", "jump", "end", "stdin", "stdout", "stdlnout", "set", "gettype", "exists", "setlist", "setlistat", "getlistat", "getlistsize", "listappend", "getstrsize", "getstrcharat", "add", "subtract", "multiply", "divide", "equal", "inequal", "not", "greater", "lesser", "stoi", "stod", "tostring", "fun", "return", "endfun", "pusharg", "call", "use", "extern"]
|
||||
keywords = ["if", "jump", "end", "stdin", "stdout", "stdlnout", "set", "gettype", "exists", "setlist", "setlistat", "getlistat", "getlistsize", "listappend", "getstrsize", "getstrcharat", "add", "subtract", "multiply", "divide", "equal", "inequal", "not", "greater", "lesser", "stoi", "stod", "tostring", "fun", "return", "endfun", "pusharg", "call", "use", "extern", "error"]
|
||||
|
||||
for line in thefile:
|
||||
allstr += line + " <br> "
|
||||
|
22
src/main.cpp
22
src/main.cpp
@@ -78,7 +78,8 @@ enum class Instructions {
|
||||
Getstrcharat, Getstrsize,
|
||||
Stoi, Stod, Tostring,
|
||||
Fun, Return, Endfun, Pusharg, Call, Local,
|
||||
Use, Extern
|
||||
Use, Extern,
|
||||
Error
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -636,6 +637,24 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
|
||||
error("Argument of stdlnout must be a value (literal or a value reference)");
|
||||
}
|
||||
break;
|
||||
/*
|
||||
error instruction
|
||||
This instruction outputs a custom error message.
|
||||
*/
|
||||
|
||||
case Instructions::Error:
|
||||
if (l.args.size() < 1) {
|
||||
error("Could not find argument for Error inbuilt");
|
||||
}
|
||||
if (holds_alternative<Literal>(l.args[0])) {
|
||||
if (holds_alternative<string>(get<Literal>(l.args[0]).val)) {
|
||||
error(get<string>(get<Literal>(l.args[0]).val));
|
||||
} else {
|
||||
error("Argument of error must be a string");
|
||||
}
|
||||
} else {
|
||||
}
|
||||
break;
|
||||
/*
|
||||
set instruction
|
||||
This instruction sets a variable to a provided value.
|
||||
@@ -2232,6 +2251,7 @@ vector<Instruction> parser(vector<vector<string>> in) {
|
||||
else if (i == "stdin") newInst.inst = Instructions::Stdin;
|
||||
else if (i == "stdout") newInst.inst = Instructions::Stdout;
|
||||
else if (i == "stdlnout") newInst.inst = Instructions::Stdlnout;
|
||||
else if (i == "error") newInst.inst = Instructions::Error;
|
||||
else if (i == "jump") newInst.inst = Instructions::Jump;
|
||||
else if (i == "if") newInst.inst = Instructions::If;
|
||||
else if (i == "add") newInst.inst = Instructions::Add;
|
||||
|
1
tests/error.grnd
Normal file
1
tests/error.grnd
Normal file
@@ -0,0 +1 @@
|
||||
error "Hello, world!"
|
Reference in New Issue
Block a user