|
Syntax
|
Rules
|
|
Comment
|
Any text on a line that follows a number sign (#) is a comment. For example: # this is a comment.
|
|
Identifier rules
|
-
Identifiers are case-sensitive and can contain letters, digits, and underscores (_). An identifier cannot start with a digit.
-
These rules apply to all variable and function names, whether built-in or custom.
|
|
Data types
|
-
String
Literal constant: enclosed in single quotation marks. For example: 'hello, EdgeScript'.
-
Number
Literal constant: a decimal number. For example: 10, -99, or 1.1.
-
Boolean
Literal constant: true or false.
-
Dictionary
The following are literal constants:
-
[]: an empty dictionary.
-
['key1', 'key2', 100]: an indexed dictionary (similar to an array).
-
1 -> 'key1'
-
2 -> 'key2'
-
3 -> 100
-
['key1' = 'value1', 'key2' = '1000']: a key-value dictionary.
-
'key1' -> 'value1'
-
'key2' -> '1000'
|
|
Variables
|
|
|
Operators
|
-
= : The assignment operator.
-
- : The unary minus operator.
Example: inum = -10
-
All other data type operations use built-in functions instead of operators. For more information, see Conditional logic functions.
|
|
Statements
|
-
Conditional statement if condition {
...
}
if condition1 {
if condition2 {
...
}
}
if condition {
...
} else {
...
}
-
Explanation
-
The condition can consist of the following elements:
-
Literal constants
-
Variables
-
Function calls
-
Body
-
Multiple levels of nesting are supported.
-
Coding style
The opening brace ({) must be on the same line as the if condition.
-
for loop # Example 1: Iterate over an indexed dictionary.
# This loop iterates through an indexed dictionary and returns true if it finds the value 'c'.
a = ['a', 'b', 'c', 'd']
def for_func () {
for k, v in a {
if eq(v, 'c') {
return true
}
}
}
for_func()
# Example 2: Iterate over a key-value dictionary.
# This loop iterates through a key-value dictionary and returns true if it finds the key 'c'.
a = ['a' = 1, 'b' = 2, 'c' = 3, 'd' = 4, 'e' = 5, 'f' = 6]
def for_func () {
for k, v in a {
if eq(k, 'c') {
return true
}
}
}
for_func()
# Example 3: Use nested loops.
# This example demonstrates nested loops that iterate through three dictionaries.
num = 0
def for_func () {
a = [0,1,2,3,4,5,6,7,8,9]
for k ,v in a {
b = [0,1,2,3,4,5,6,7,8,9]
for k1 ,v1 in b {
c = [0,1,2,3,4,5,6,7,8,9]
for k2 ,v2 in c {
num = add(num, 1)
if and(eq(v, 3), eq(v1, 5), eq(v2, 7)) {
return true
}
}
}
}
}
for_func()
-
Notes:
-
A for loop can only iterate over a dictionary or an indexed dictionary.
-
The break keyword is not supported. To exit a loop, use a return statement within a custom function.
-
Nested loops are supported.
-
Coding style
The opening brace ({) must be on the same line as the for statement.
|
|
Functions
|
|