tree-sitter-tony
Version:
Tony grammar for tree-sitter
475 lines (403 loc) • 10.2 kB
Plain Text
==================
struct type
==================
a :: {
a: Type,
b: Type
} := 1
(program
term: (assignment
pattern: (identifier_pattern
name: (identifier_pattern_name)
type: (struct_type
member: (member_type
key: (shorthand_member_identifier)
value: (parametric_type
name: (type)))
member: (member_type
key: (shorthand_member_identifier)
value: (parametric_type
name: (type)))))
value: (number)))
==================
tagged struct type
==================
a :: <constructor>{ a: Type, b: Type } := 1
(program
term: (assignment
pattern: (identifier_pattern
name: (identifier_pattern_name)
type: (tagged_type
name: (identifier)
type: (struct_type
member: (member_type
key: (shorthand_member_identifier)
value: (parametric_type
name: (type)))
member: (member_type
key: (shorthand_member_identifier)
value: (parametric_type
name: (type))))))
value: (number)))
==================
map type
==================
a :: { [Type]: Type } := 1
a :: { [a in Type]: a } := 1
(program
term: (assignment
pattern: (identifier_pattern
name: (identifier_pattern_name)
type: (map_type
key: (parametric_type
name: (type))
value: (parametric_type
name: (type))))
value: (number))
term: (assignment
pattern: (identifier_pattern
name: (identifier_pattern_name)
type: (map_type
property: (type_variable_declaration_name)
key: (parametric_type
name: (type))
value: (type_variable)))
value: (number)))
==================
tuple type
==================
a :: (Type, Type) := 1
(program
term: (assignment
pattern: (identifier_pattern
name: (identifier_pattern_name)
type: (tuple_type
element: (parametric_type
name: (type))
element: (parametric_type
name: (type))))
value: (number)))
==================
tagged tuple type
==================
a :: <constructor>(Type, Type) := 1
(program
term: (assignment
pattern: (identifier_pattern
name: (identifier_pattern_name)
type: (tagged_type
name: (identifier)
type: (tuple_type
element: (parametric_type
name: (type))
element: (parametric_type
name: (type)))))
value: (number)))
==================
list type
==================
a :: [Type] := 1
(program
term: (assignment
pattern: (identifier_pattern
name: (identifier_pattern_name)
type: (list_type
element: (parametric_type
name: (type))))
value: (number)))
==================
tagged list type
==================
a :: <constructor>[Type] := 1
(program
term: (assignment
pattern: (identifier_pattern
name: (identifier_pattern_name)
type: (tagged_type
name: (identifier)
type: (list_type
element: (parametric_type
name: (type)))))
value: (number)))
==================
access type
==================
a as Type[b]
a as a[0]
(program
term: (type_hint
value: (identifier)
type: (access_type
type: (parametric_type
name: (type))
value: (identifier)))
term: (type_hint
value: (identifier)
type: (access_type
type: (type_variable)
value: (number))))
==================
curried type
==================
a :: Type -> [Type] -> Type := 1
a :: Type -> (Type -> Type) -> a := 1
(program
term: (assignment
pattern: (identifier_pattern
name: (identifier_pattern_name)
type: (curried_type
from: (parametric_type
name: (type))
to: (curried_type
from: (list_type
element: (parametric_type
name: (type)))
to: (parametric_type
name: (type)))))
value: (number))
term: (assignment
pattern: (identifier_pattern
name: (identifier_pattern_name)
type: (curried_type
from: (parametric_type
name: (type))
to: (curried_type
from: (type_group
type: (curried_type
from: (parametric_type
name: (type))
to: (parametric_type
name: (type))))
to: (type_variable))))
value: (number)))
==================
parametric type
==================
a as Type
a as Type(5)
a as Type<a>
a as Type<a>(5, 'string')
a as Type<Type, a, typeof b, typeof 'string', typeof 5>
(program
term: (type_hint
value: (identifier)
type: (parametric_type
name: (type)))
term: (type_hint
value: (identifier)
type: (parametric_type
name: (type)
element: (number)))
term: (type_hint
value: (identifier)
type: (parametric_type
name: (type)
argument: (type_variable)))
term: (type_hint
value: (identifier)
type: (parametric_type
name: (type)
argument: (type_variable)
element: (number)
element: (string)))
term: (type_hint
value: (identifier)
type: (parametric_type
name: (type)
argument: (parametric_type
name: (type))
argument: (type_variable)
argument: (typeof
value: (identifier))
argument: (typeof
value: (string))
argument: (typeof
value: (number)))))
==================
tagged parametric type
==================
a as <constructor>Type
a as <constructor>Type<a>
a as <constructor>Type<Type, a, typeof b, typeof 'string', typeof 5>
(program
term: (type_hint
value: (identifier)
type: (tagged_type
name: (identifier)
type: (parametric_type
name: (type))))
term: (type_hint
value: (identifier)
type: (tagged_type
name: (identifier)
type: (parametric_type
name: (type)
argument: (type_variable))))
term: (type_hint
value: (identifier)
type: (tagged_type
name: (identifier)
type: (parametric_type
name: (type)
argument: (parametric_type
name: (type))
argument: (type_variable)
argument: (typeof
value: (identifier))
argument: (typeof
value: (string))
argument: (typeof
value: (number))))))
==================
intersection/union type
==================
a :: Type | Type & Type | Type := 1
(program
term: (assignment
pattern: (identifier_pattern
name: (identifier_pattern_name)
type: (union_type
left: (parametric_type
name: (type))
right: (union_type
left: (intersection_type
left: (parametric_type
name: (type))
right: (parametric_type
name: (type)))
right: (parametric_type
name: (type)))))
value: (number)))
==================
subtraction type
==================
a :: Type | Type \ Type := 1
(program
term: (assignment
pattern: (identifier_pattern
name: (identifier_pattern_name)
type: (subtraction_type
left: (union_type
left: (parametric_type
name: (type))
right: (parametric_type
name: (type)))
right: (parametric_type
name: (type))))
value: (number)))
==================
conditional type
==================
a :: if Type <: (Type; Type) then if Type <: Type then Type else Type else if Type <: Type then Type else Type := 1
(program
term: (assignment
pattern: (identifier_pattern
name: (identifier_pattern_name)
type: (conditional_type
type: (parametric_type
name: (type))
constraint: (parametric_type
name: (type))
constraint: (parametric_type
name: (type))
consequence: (conditional_type
type: (parametric_type
name: (type))
constraint: (parametric_type
name: (type))
consequence: (parametric_type
name: (type))
alternative: (parametric_type
name: (type)))
alternative: (conditional_type
type: (parametric_type
name: (type))
constraint: (parametric_type
name: (type))
consequence: (parametric_type
name: (type))
alternative: (parametric_type
name: (type)))))
value: (number)))
==================
tagged type
==================
a :: <constructor> := 1
(program
term: (assignment
pattern: (identifier_pattern
name: (identifier_pattern_name)
type: (tagged_type
name: (identifier)))
value: (number)))
==================
keyof
==================
a :: keyof Type := 1
(program
term: (assignment
pattern: (identifier_pattern
name: (identifier_pattern_name)
type: (keyof
type: (parametric_type
name: (type))))
value: (number)))
==================
refinement type
==================
a :: Type<[(a :: Type, Type) | a > 0, a < 10]> := 1
(program
term: (assignment
pattern: (identifier_pattern
name: (identifier_pattern_name)
type: (parametric_type
name: (type)
argument: (refinement_type
generator: (tuple_type
element: (refinement_type_declaration
name: (identifier_pattern_name)
type: (parametric_type
name: (type)))
element: (parametric_type
name: (type)))
predicate: (infix_application
left: (identifier)
name: (identifier)
right: (number))
predicate: (infix_application
left: (identifier)
name: (identifier)
right: (number)))))
value: (number)))
==================
type
==================
a as Type
a as AaA0Z
(program
term: (type_hint
value: (identifier)
type: (parametric_type
name: (type)))
term: (type_hint
value: (identifier)
type: (parametric_type
name: (type))))