-
Notifications
You must be signed in to change notification settings - Fork 0
Statements
See basic syntax for variable setting, variable getting, and invocation statements.
Shnap has a registry of native statements that are implemented in the interpreter rather than the standard library. The syntax to obtain a copy of one of these functions is native::<name>
, where name is the name of the function. For example, the print
function can be obtained like so: native::sys.print
. Most, if not all, native functions are already set in the standard library, and exist as bultins, so you shouldn't have to use this statement.
Shnap statements, along with a value, always return a state. There are five states: NORMAL, THROWING, BREAKING, CONTINUING, and RETURNING. Some statements can return the THROWING state (such as function calls), but the other states can only be created with a state change. State changes have the syntax <state>
or <state>: <value>
. The state names are normal, throw, break, continue, and return. If <state>
is not given a <value>
, it will default to void.
- Setting the state to normal doesn't do anything.
- Setting the state to throw will throw the given value as an exception.
- Setting the state to break will break the loop with the given value as their name (or the nearest loop if the value is void)
- Setting the state to continue will continue the loop with the given value as their name (or the nearest loop if the value is void)
- Setting the state to return will return the given value in a function
A function invocation will always produce either a throw state or a normal state. A try-catch block will change throw states to normal states.
Examples:
return: 5
break
continue
break: "namedLoop"
normal: "this doesn't do much"
After a variable is created, it can be flagged to apply different behavior. There are three flags: noimport, private, and final. The flag statement has the syntax <flag> <variableReference>
.
- The noimport flag prevents the field from being imported as a builtin. It is only useful if the script is a builtin script.
- The private flag has the same behavior as the noimport flag AND prevents the field from being accessed outside of the script it is declared in
- The final flag prevents the variable from being set after the flag is applied.
Examples:
internal_value = 5
noimport internal_value
final_value = 10
final final_value
final_value = 5 //this will error
secret_message = "Lol"
private secret_message
Home | New Issue | Contact Me