capri, a script language

Home | Documentation | Releases | Sources | Contact

Syntax description

This page contains the syntax description in ebnf-style form.

unit:
  statement+
  
statement:
  load-statement |
  import-statement |
  run-statement |
  version-statement |
  project-declaration |
  task-declaration |
  empty-statement |
  for-statement |
  foreach-statement |
  assert-statement |
  if-statement |
  jump-statement |
  while-statement |
  specialization-statement |
  body-statement |
  expression-statement
  
load-statement:
  "load" expression ";"
  
import-statement:
  "import" (identifier | expression) ";"
  
run-statement:
  "run" expression ";"

version-statement:
  "version" (number | literal) ";" 
  
project-declaration:
  ("project" | "class") identifier ["default" identifier] "{" statement+ "}"

task-declaration:
  ("task" | "function") ["native"] identifier ["(" parameter-name-list ")"]  ["depends" task-dependencies] statement

parameter-name-list:
  (identifier [","])+ identifier

task-dependencies:
  (expression [","])+ expression

for-statement:
  "for" "(" expression ";" expression ";" expression ")" statement

foreach-statement:
  "foreach" "(" [identifier ","] identifier ("in" | ":") expression ")" statement

if-statement:
  "if" "(" expression ")" statement ["else" statement]

jump-statement:
  ("break" ";") |
  ("continue" ";") |
  ("return" [statement] ";")

while-statement:
  "while" "(" expression ")" statement

assert-statement:
  "assert" expression ";"

specialization-statement:
  "on" literal ((identifier | literal) ",")+ (identifier | literal) statement ["else" statement]

body-statement:
  "{" statement+ "}"

expression-statement:
  expression ";"

empty-statement:
  ";"

expression:
  concurrent-expression |
  join-expression |
  clone-expression |
  new-object-expression |
  new-array-expression |
  assignment-or-ternary-expression

array-initializer-expression:
  (identifier ":" expression) | ([expression ":"] expression)

concurrent-expression:
  "concurrent" ["(" parameter-name-list ")"] statement

join-expression:
  "join" expression

clone-expression:
  "clone" expression
  
new-object-expression:
  "object" "(" ")"
  
new-array-expression:
  "array" ["<" number ">"] "[" expression "]"

assignment-or-ternary-expression:
  logical-or-expression [( "?" expression ":" expression) | (("=" | "+=" | "-=" | "%=" | "*=" | "/=" | "&=" | "^=" | "|=") assignment-or-ternary-expression))]

logical-or-expression:
  logical-and-expression ["||" logical-or-expression]

logical-and-expression:
  bitwise-inclusive-or-expression ["&&" logical-and-expression]

bitwise-inclusive-or-expression:
  bitwise-exclusive-or-expression ["|" bitwise-inclusive-or-expression]

bitwise-exclusive-or-expression:
  bitwise-and-expression ["^" bitwise-exclusive-or-expression]

bitwise-and-expression:
  equality-expression ["&" bitwise-and-expression]

equality-expression:
  relational-expression [("==" | "!=") equality-expression]

relational-expression:
  shift-expression [("<" | ">" | "<=" | ">=") relational-expression]

shift-expression:
  additive-expression [("<<" | ">>") shift-expression]

additive-expression:
  multiplicative-expression [("+" | "-") additive-expression]

multiplicative-expression:
  unary-expression [("*" | "/" | "%") multiplicative-expression]

unary-expression:
  [("++" | "--" | "!" | "~" | "+" | "-")] postfix-expression

postfix-expression:
  primary-expression ["++" | "--" | ("." identifier) | ("[" expression "]") | ("(" expression+ ")")]

primary-expression:
  ["def"] identifier |
  bool |
  number |
  literal |
  ("(" expression ")") |
  null |
  ("{" (array-initializer-expression ",")+ array-initializer-expression "}")

bool:
  "true" |
  "false"

null:
  "null"

literal:
  /*
  string literal enclosed by ' or " escapable with \
  */
  
number:
  /*
  numeric literals
  decimal:      43.210
  hexadecimal:  0xDEADBEEF
  binary:       0b10010110
  */

identifier:
  /*
  starts with a-z, A-Z, _, $
  may also contain 0-9
  */