tree-sitter-tiger/test/corpus/declarations.txt

283 lines
8.1 KiB
Plaintext
Raw Normal View History

2022-06-01 20:37:24 +02:00
================================================================================
Empty declarations
================================================================================
--------------------------------------------------------------------------------
(source_file)
================================================================================
Type alias declaration
================================================================================
type alias = int
--------------------------------------------------------------------------------
(source_file
(type_declaration
name: (identifier)
value: (type_alias
(type_identifier))))
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
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
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
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
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
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)
type: (type_identifier)
2022-06-01 20:48:32 +02:00
name: (identifier)
type: (type_identifier))
2022-06-01 20:48:32 +02:00
body: (string_literal)))
================================================================================
Function declaration return type
================================================================================
function func(a: int, b: int) : string = "string"
--------------------------------------------------------------------------------
(source_file
(function_declaration
name: (identifier)
parameters: (parameters
name: (identifier)
type: (type_identifier)
name: (identifier)
type: (type_identifier))
return_type: (type_identifier)
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)
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)))
================================================================================
Primitive declaration with return type
================================================================================
primitive prim() : int
--------------------------------------------------------------------------------
(source_file
(primitive_declaration
name: (identifier)
parameters: (parameters)
return_type: (type_identifier)))
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)
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)))