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

279 lines
8 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
(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: (identifier)
type: (identifier)
name: (identifier)
type: (identifier))))
================================================================================
Record type declaration single field
================================================================================
type record = { a: int }
--------------------------------------------------------------------------------
(source_file
(type_declaration
name: (identifier)
value: (record_type
name: (identifier)
type: (identifier))))
================================================================================
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: (identifier)
type: (identifier)
(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: (identifier))))
================================================================================
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: (identifier)))
(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: (identifier)
name: (identifier)
type: (identifier))
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: (identifier)
name: (identifier)
type: (identifier))
return_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: (identifier))
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: (identifier)))
2022-06-01 20:41:25 +02:00
================================================================================
Variable declaration
================================================================================
var a := 12
--------------------------------------------------------------------------------
(source_file
(variable_declaration
name: (identifier)
value: (integer_literal)))
================================================================================
Variable declaration with type
================================================================================
var a : int := 27
--------------------------------------------------------------------------------
(source_file
(variable_declaration
name: (identifier)
type: (identifier)
value: (integer_literal)))
================================================================================
Multiple variable declarations
================================================================================
var a := 12
var b := 27
--------------------------------------------------------------------------------
(source_file
(variable_declaration
name: (identifier)
value: (integer_literal))
(variable_declaration
name: (identifier)
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)))