2022-06-01 20:37:24 +02:00
|
|
|
================================================================================
|
|
|
|
Empty declarations
|
|
|
|
================================================================================
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file)
|
|
|
|
|
2022-06-01 20:52:20 +02:00
|
|
|
================================================================================
|
|
|
|
Type alias declaration
|
|
|
|
================================================================================
|
|
|
|
|
|
|
|
type alias = int
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(type_declaration
|
|
|
|
name: (identifier)
|
|
|
|
value: (type_alias
|
2022-06-03 10:15:37 +02:00
|
|
|
(type_identifier))))
|
2022-06-01 20:52:20 +02:00
|
|
|
|
2022-06-01 20:53:39 +02:00
|
|
|
================================================================================
|
|
|
|
Record type declaration
|
|
|
|
================================================================================
|
|
|
|
|
|
|
|
type record = { a: int, b: str }
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(type_declaration
|
|
|
|
name: (identifier)
|
|
|
|
value: (record_type
|
2022-06-03 10:40:14 +02:00
|
|
|
name: (field_identifier)
|
|
|
|
type: (type_identifier)
|
|
|
|
name: (field_identifier)
|
|
|
|
type: (type_identifier))))
|
2022-06-01 20:53:39 +02:00
|
|
|
|
|
|
|
================================================================================
|
|
|
|
Record type declaration single field
|
|
|
|
================================================================================
|
|
|
|
|
|
|
|
type record = { a: int }
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(type_declaration
|
|
|
|
name: (identifier)
|
|
|
|
value: (record_type
|
2022-06-03 10:40:14 +02:00
|
|
|
name: (field_identifier)
|
|
|
|
type: (type_identifier))))
|
2022-06-01 20:53:39 +02:00
|
|
|
|
|
|
|
================================================================================
|
|
|
|
Record type declaration no fields
|
|
|
|
================================================================================
|
|
|
|
|
|
|
|
type record = { }
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(type_declaration
|
|
|
|
name: (identifier)
|
|
|
|
value: (record_type)))
|
|
|
|
|
|
|
|
================================================================================
|
|
|
|
Record type declaration trailing comma
|
|
|
|
================================================================================
|
|
|
|
|
|
|
|
type record = { a: int, }
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(type_declaration
|
|
|
|
name: (identifier)
|
|
|
|
value: (record_type
|
2022-06-03 10:40:14 +02:00
|
|
|
name: (field_identifier)
|
|
|
|
type: (type_identifier)
|
2022-06-01 20:53:39 +02:00
|
|
|
(ERROR))))
|
|
|
|
|
2022-06-01 20:54:35 +02:00
|
|
|
================================================================================
|
|
|
|
Array type declaration
|
|
|
|
================================================================================
|
|
|
|
|
|
|
|
type array_of_int = array of int
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(type_declaration
|
|
|
|
name: (identifier)
|
|
|
|
value: (array_type
|
2022-06-03 10:35:53 +02:00
|
|
|
element_type: (type_identifier))))
|
2022-06-01 20:54:35 +02:00
|
|
|
|
|
|
|
================================================================================
|
|
|
|
Array type declaration non-associativity
|
|
|
|
================================================================================
|
|
|
|
|
|
|
|
type array_of_array_of_int = array of array of int
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(ERROR
|
|
|
|
(type_declaration
|
|
|
|
name: (identifier)
|
|
|
|
value: (array_type
|
2022-06-03 10:35:53 +02:00
|
|
|
element_type: (type_identifier)))
|
2022-06-01 20:54:35 +02:00
|
|
|
(identifier))
|
|
|
|
(identifier))
|
|
|
|
|
2022-06-01 20:48:32 +02:00
|
|
|
================================================================================
|
|
|
|
Function declaration
|
|
|
|
================================================================================
|
|
|
|
|
|
|
|
function func(a: int, b: int) = "string"
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(function_declaration
|
|
|
|
name: (identifier)
|
|
|
|
parameters: (parameters
|
|
|
|
name: (identifier)
|
2022-06-03 10:40:14 +02:00
|
|
|
type: (type_identifier)
|
2022-06-01 20:48:32 +02:00
|
|
|
name: (identifier)
|
2022-06-03 10:40:14 +02:00
|
|
|
type: (type_identifier))
|
2022-06-01 20:48:32 +02:00
|
|
|
body: (string_literal)))
|
|
|
|
|
2022-06-01 22:07:05 +02:00
|
|
|
================================================================================
|
|
|
|
Function declaration return type
|
|
|
|
================================================================================
|
|
|
|
|
|
|
|
function func(a: int, b: int) : string = "string"
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(function_declaration
|
|
|
|
name: (identifier)
|
|
|
|
parameters: (parameters
|
|
|
|
name: (identifier)
|
2022-06-03 10:40:14 +02:00
|
|
|
type: (type_identifier)
|
2022-06-01 22:07:05 +02:00
|
|
|
name: (identifier)
|
2022-06-03 10:40:14 +02:00
|
|
|
type: (type_identifier))
|
2022-06-03 10:15:37 +02:00
|
|
|
return_type: (type_identifier)
|
2022-06-01 22:07:05 +02:00
|
|
|
body: (string_literal)))
|
|
|
|
|
2022-06-01 20:48:32 +02:00
|
|
|
================================================================================
|
|
|
|
Function declaration single parameter
|
|
|
|
================================================================================
|
|
|
|
|
|
|
|
function func(a: int) = "string"
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(function_declaration
|
|
|
|
name: (identifier)
|
|
|
|
parameters: (parameters
|
|
|
|
name: (identifier)
|
2022-06-03 10:40:14 +02:00
|
|
|
type: (type_identifier))
|
2022-06-01 20:48:32 +02:00
|
|
|
body: (string_literal)))
|
|
|
|
|
|
|
|
================================================================================
|
|
|
|
Function declaration no parameters
|
|
|
|
================================================================================
|
|
|
|
|
|
|
|
function func() = "string"
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(function_declaration
|
|
|
|
name: (identifier)
|
|
|
|
parameters: (parameters)
|
|
|
|
body: (string_literal)))
|
|
|
|
|
|
|
|
================================================================================
|
|
|
|
Primitive declaration
|
|
|
|
================================================================================
|
|
|
|
|
|
|
|
primitive prim()
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(primitive_declaration
|
|
|
|
name: (identifier)
|
|
|
|
parameters: (parameters)))
|
|
|
|
|
2022-06-01 22:07:05 +02:00
|
|
|
================================================================================
|
|
|
|
Primitive declaration with return type
|
|
|
|
================================================================================
|
|
|
|
|
|
|
|
primitive prim() : int
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(primitive_declaration
|
|
|
|
name: (identifier)
|
|
|
|
parameters: (parameters)
|
2022-06-03 10:15:37 +02:00
|
|
|
return_type: (type_identifier)))
|
2022-06-01 22:07:05 +02:00
|
|
|
|
2022-06-01 20:41:25 +02:00
|
|
|
================================================================================
|
|
|
|
Variable declaration
|
|
|
|
================================================================================
|
|
|
|
|
|
|
|
var a := 12
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(variable_declaration
|
|
|
|
name: (identifier)
|
2022-06-03 11:42:57 +02:00
|
|
|
(operator)
|
2022-06-01 20:41:25 +02:00
|
|
|
value: (integer_literal)))
|
|
|
|
|
|
|
|
================================================================================
|
|
|
|
Variable declaration with type
|
|
|
|
================================================================================
|
|
|
|
|
|
|
|
var a : int := 27
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(variable_declaration
|
|
|
|
name: (identifier)
|
2022-06-03 10:15:37 +02:00
|
|
|
type: (type_identifier)
|
2022-06-03 11:42:57 +02:00
|
|
|
(operator)
|
2022-06-01 20:41:25 +02:00
|
|
|
value: (integer_literal)))
|
|
|
|
|
|
|
|
================================================================================
|
|
|
|
Multiple variable declarations
|
|
|
|
================================================================================
|
|
|
|
|
|
|
|
var a := 12
|
|
|
|
var b := 27
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(variable_declaration
|
|
|
|
name: (identifier)
|
2022-06-03 11:42:57 +02:00
|
|
|
(operator)
|
2022-06-01 20:41:25 +02:00
|
|
|
value: (integer_literal))
|
|
|
|
(variable_declaration
|
|
|
|
name: (identifier)
|
2022-06-03 11:42:57 +02:00
|
|
|
(operator)
|
2022-06-01 20:41:25 +02:00
|
|
|
value: (integer_literal)))
|
|
|
|
|
2022-06-01 20:37:24 +02:00
|
|
|
================================================================================
|
|
|
|
Import
|
|
|
|
================================================================================
|
|
|
|
|
|
|
|
import "a.tih"
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(import_declaration
|
|
|
|
file: (string_literal)))
|
|
|
|
|
|
|
|
================================================================================
|
|
|
|
Multiple imports
|
|
|
|
================================================================================
|
|
|
|
|
|
|
|
import "a.tih"
|
|
|
|
import "b.tih"
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(source_file
|
|
|
|
(import_declaration
|
|
|
|
file: (string_literal))
|
|
|
|
(import_declaration
|
|
|
|
file: (string_literal)))
|