Platypus Syntax Specification¶
The following is the definition of Pipeline processor language. Being supported by increasing syntax, the document would be adjusted to varying degrees.
Identifiers and Keywords¶
Identifiers¶
Identifiers, used to identify objects, can be used to represent a variable and function. Identifiers contain keywords.
Customized identifiers cannot duplicate keywords of Pipeline data processor language.
Identifiers consist of numbers (0-9
), letters (A-Z a-z
) and underscores (_
), but the first character cannot be a number and case sensitive:
_abc
abc
abc1
abc_1_
If you need to start with a letter or use the above characters in the identifier, you need to use reverse quotation marks:
`1abc`
`@some-variable`
`an emoticon variable👍`
Special Identifiers¶
The special identifier(_
)represents the external raw input data when the platypus script is triggered, and this parameter may be implicitly passed to some functions.
In some functions, _
is treated as an alias for message
for forward compatibility.
Keywords¶
Keywords have special meanings, such as if
, elif
, else
, for
, in
, break
and continue
.
Notes¶
With #
as a line comment character, inline comment is not supported.
Built-in Data Type¶
In the Pipeline data processor language, the type of the value of a variable can change dynamically. But each value has its data type, which can be one of the primitive types or a compound types.
Basic Types¶
Integer Type¶
Integers have a type length of 64bits with symbols. Currently, it is only supported to write integer literals in decimal form, such as -1
, 0
, 1
, +19
.
Float Type¶
Float types are 64bit long with symbols, and currently only support writing floating numeric quantities in decimal form, such as -1.00001
, 0.0
, 1.0
, +19.0
.
Boolean Type¶
Literals in boolean types only include true
和 false
.
String Type¶
String literals can be written in double or single quotation marks, and multi-line strings can be written in triple double or triple quotation marks.
-
"hello world"
-
'hello world'
-
"""hello world"""
-
''' hello world '''
Nil Type¶
Nil is a special data type that means no value. The literal of this type is nil
, When a variable is used without assignment, its value is nil.
Compound Type¶
Map type and list type are different from the base type. Multiple variables can point to the same map or list object. When assigning values, they do not make a memory copy of list or map but refer to it.
Map Type¶
Map type is key-value structure, only string type can be used as key, and the data type of value is not limited.
It can read and write elements in the map through index expressions.
List Type¶
The list type can store any number and any type of value in the list. It can read and write elements in the list through index expressions.
Operator¶
The followings are the operators currently supported by Platypus. The higher the value, the higher the priority.
Priority | Symbol | Combinability | Description |
---|---|---|---|
1 | = |
Right | Assignment; Named parameter; the lowest priority |
2 | \|\| |
Left | or |
3 | && |
Left | and |
4 | >= |
Left | greater than or equal |
4 | > |
Left | greater than |
4 | != |
Left | not equal |
4 | == |
Left | equal |
4 | <= |
Left | less than or equal |
4 | < |
Left | less than |
5 | + |
Left | plus |
5 | - |
Left | subtract |
6 | * |
Left | multiply |
6 | / |
Left | divide |
6 | % |
Left | remainder |
7 | [] |
Left | Use the list subscript or the key value of map |
7 | () |
None | Operator priority can be changed; function call |
Expression¶
Platypus uses the symbol comma ,
as the expression separator, such as the separation of expressions when passing parameters to invoke expressions and initializing maps and lists.
Call Expression¶
The following is a function call to take the number of elements in the list:
Binary Expression¶
An assignment expression belongs to a binary expression with a return value.
List Initialization Expression¶
Map Initialization Expression¶
Parenthesized Expression¶
Parenthesized expressions can change the precedence of operands in binary expressions, but they cannot change the combinability.
Statement¶
All expressions in the Platypus can be treated as value statements when expressions are ended by list seperators ;
or \n
, it would be treated as one statement, such as the following script content containing four statements.
Value Statement (Expression Statement)¶
An expression can be treated as a value statement when it is followed by a statement separator. Here are four legal statements.
Select Statement¶
Platypus supports the syntax of if/elif/else
.
Like most programming languages, enter the corresponding statement block according to whether the condition of if/elif
holds or not, and enter the else branch if none holds.
The current condition can be any expression as long as its value is one of the built-in data types. Here are the criteria:
-
When the condition is
int
type value, if it is0
the condition isfalse
, otherwisetrue
-
When the condition is
float
type value, if it is0.0
the condition isfalse
, otherwisetrue
-
When the condition is
string
type value, it is an empty string""
the condition isfalse
, otherwisetrue
-
When the condition is
bool
type value, the condition is the current value -
When the condition is
nil
type value, the condition isfalse
-
When the condition is
map
type value, the length is 0, and the condition isfalse
, otherwisetrue
-
When the condition is
list
type value, the length is 0, and the condition isfalse
, otherwisetrue
Loop Statement¶
Platypus supports the syntax of for
and for in
.
The following are two statements that are only allowed in loop statement blocks:
cotinue
statement, no further statements are executed, and the next loop continuesbreak
statement, loop ends
The use of for
statement can cause an infinite loop and should be used with caution, or use the statement for in
instead when possible.
Examples:
- Use
for
to run 10 loops.
- Using
for in
traverses all elements of a list.
- Using
for in
traverses all the keys of the map.
- Using
for in
traverses all characters of string.