660 lines
14 KiB
Plaintext
660 lines
14 KiB
Plaintext
==================
|
|
Declarations
|
|
==================
|
|
|
|
immutable :: 1
|
|
mutable := 2
|
|
typed: i32: 3
|
|
deferred: i32
|
|
|
|
---
|
|
|
|
(source_file
|
|
(declaration
|
|
(identifier)
|
|
(signed_numeric_literal
|
|
(integer_literal)))
|
|
(declaration
|
|
(identifier)
|
|
(signed_numeric_literal
|
|
(integer_literal)))
|
|
(declaration
|
|
(identifier)
|
|
(primitive_type)
|
|
(signed_numeric_literal
|
|
(integer_literal)))
|
|
(declaration
|
|
(identifier)
|
|
(primitive_type)))
|
|
|
|
==================
|
|
Types and constructors
|
|
==================
|
|
|
|
Point :: &{
|
|
x: i32:
|
|
y: i32 = 0
|
|
}
|
|
point := &Point.{ x: 1; y = 2 }
|
|
maybe: []{i32?}: [|.none, 1->|.some]
|
|
|
|
---
|
|
|
|
(source_file
|
|
(declaration
|
|
(identifier)
|
|
(type_definition
|
|
(product_type
|
|
(product_field
|
|
(identifier)
|
|
(primitive_type))
|
|
(product_field
|
|
(identifier)
|
|
(primitive_type)
|
|
(signed_numeric_literal
|
|
(integer_literal))))))
|
|
(declaration
|
|
(identifier)
|
|
(product_constructor
|
|
(identifier)
|
|
(product_entry
|
|
(identifier)
|
|
(signed_numeric_literal
|
|
(integer_literal)))
|
|
(product_entry
|
|
(identifier)
|
|
(signed_numeric_literal
|
|
(integer_literal)))))
|
|
(declaration
|
|
(identifier)
|
|
(array_type
|
|
(grouped_type
|
|
(optional_type
|
|
(primitive_type))))
|
|
(collection_literal
|
|
(collection_entry
|
|
(sum_constructor
|
|
(identifier)))
|
|
(collection_entry
|
|
(pipeline_expression
|
|
(signed_numeric_literal
|
|
(integer_literal))
|
|
(direct_pipeline_stage
|
|
(pipeline_callable
|
|
(sum_constructor
|
|
(identifier)))))))))
|
|
|
|
==================
|
|
Control flow and patterns
|
|
==================
|
|
|
|
describe: []i32 -> str: @ values: []i32 { match values {
|
|
[] => 'empty'
|
|
[first, ...rest] if first > 0 => 'positive'
|
|
_ => 'other'
|
|
} }
|
|
|
|
---
|
|
|
|
(source_file
|
|
(declaration
|
|
(identifier)
|
|
(function_type
|
|
(array_type
|
|
(primitive_type))
|
|
(primitive_type))
|
|
(function_literal
|
|
(typed_parameter
|
|
(identifier)
|
|
(array_type
|
|
(primitive_type)))
|
|
(block
|
|
(match_expression
|
|
(identifier)
|
|
(match_arm
|
|
(pattern
|
|
(array_pattern))
|
|
(string_literal))
|
|
(match_arm
|
|
(pattern
|
|
(array_pattern
|
|
(array_pattern_entry
|
|
(pattern
|
|
(identifier)))
|
|
(array_pattern_entry
|
|
(identifier))))
|
|
(binary_expression
|
|
(identifier)
|
|
(signed_numeric_literal
|
|
(integer_literal)))
|
|
(string_literal))
|
|
(match_arm
|
|
(pattern)
|
|
(string_literal)))))))
|
|
|
|
==================
|
|
Physical-line continuations
|
|
==================
|
|
|
|
value := 'text' # the newline remains significant
|
|
->reverse_chrs
|
|
|
|
ready :: first
|
|
and second
|
|
|
|
---
|
|
|
|
(source_file
|
|
(declaration
|
|
(identifier)
|
|
(pipeline_expression
|
|
(string_literal)
|
|
(comment)
|
|
(continuation_pipeline_stage
|
|
(pipeline_callable
|
|
(identifier)))))
|
|
(declaration
|
|
(identifier)
|
|
(binary_expression
|
|
(identifier)
|
|
(identifier))))
|
|
|
|
==================
|
|
Compact range after an integer
|
|
==================
|
|
|
|
slice :: (source,0..<limit)
|
|
trailing_dot :: 1.
|
|
|
|
---
|
|
|
|
(source_file
|
|
(declaration
|
|
(identifier)
|
|
(tuple_value
|
|
(identifier)
|
|
(range_expression
|
|
(signed_numeric_literal
|
|
(integer_literal))
|
|
(identifier))))
|
|
(declaration
|
|
(identifier)
|
|
(signed_numeric_literal
|
|
(float_literal))))
|
|
|
|
==================
|
|
Typed function declarations
|
|
==================
|
|
|
|
double :: @ value: i32 { value * 2 }
|
|
square :: @ value: i32 => i32 { value * value }
|
|
add :: @ (left: i32, right: i32) { left + right }
|
|
unit :: @ { () }
|
|
|
|
---
|
|
|
|
(source_file
|
|
(declaration
|
|
(identifier)
|
|
(function_literal
|
|
(typed_parameter
|
|
(identifier)
|
|
(primitive_type))
|
|
(block
|
|
(binary_expression
|
|
(identifier)
|
|
(signed_numeric_literal
|
|
(integer_literal))))))
|
|
(declaration
|
|
(identifier)
|
|
(function_literal
|
|
(typed_parameter
|
|
(identifier)
|
|
(primitive_type))
|
|
(primitive_type)
|
|
(block
|
|
(binary_expression
|
|
(identifier)
|
|
(identifier)))))
|
|
(declaration
|
|
(identifier)
|
|
(function_literal
|
|
(typed_tuple_pattern
|
|
(typed_tuple_component
|
|
(identifier)
|
|
(primitive_type))
|
|
(typed_tuple_component
|
|
(identifier)
|
|
(primitive_type)))
|
|
(block
|
|
(binary_expression
|
|
(identifier)
|
|
(identifier)))))
|
|
(declaration
|
|
(identifier)
|
|
(function_literal
|
|
(block
|
|
(unit_literal)))))
|
|
|
|
==================
|
|
Whole-argument function patterns
|
|
==================
|
|
|
|
pair :: @ (left, right): (i32, i32) { left + right }
|
|
product :: @ {value}: &{value: i32:} { value }
|
|
callback :: @ operation: {i32 -> i32} { 1->operation }
|
|
unit :: @ () -> i32 { 42 }
|
|
|
|
---
|
|
|
|
(source_file
|
|
(declaration
|
|
(identifier)
|
|
(function_literal
|
|
(typed_parameter
|
|
(tuple_pattern
|
|
(pattern
|
|
(identifier))
|
|
(pattern
|
|
(identifier)))
|
|
(tuple_type
|
|
(primitive_type)
|
|
(primitive_type)))
|
|
(block
|
|
(binary_expression
|
|
(identifier)
|
|
(identifier)))))
|
|
(declaration
|
|
(identifier)
|
|
(function_literal
|
|
(typed_parameter
|
|
(product_pattern
|
|
(product_pattern_field
|
|
(identifier)))
|
|
(product_type
|
|
(product_field
|
|
(identifier)
|
|
(primitive_type))))
|
|
(block
|
|
(identifier))))
|
|
(declaration
|
|
(identifier)
|
|
(function_literal
|
|
(typed_parameter
|
|
(identifier)
|
|
(grouped_type
|
|
(function_type
|
|
(primitive_type)
|
|
(primitive_type))))
|
|
(block
|
|
(pipeline_expression
|
|
(signed_numeric_literal
|
|
(integer_literal))
|
|
(direct_pipeline_stage
|
|
(pipeline_callable
|
|
(identifier)))))))
|
|
(declaration
|
|
(identifier)
|
|
(function_literal
|
|
(typed_parameter
|
|
(unit_pattern))
|
|
(primitive_type)
|
|
(block
|
|
(signed_numeric_literal
|
|
(integer_literal))))))
|
|
|
|
==================
|
|
Optional and result wrappers
|
|
==================
|
|
|
|
wrap :: @ value: i32 -> i32 ! str { value->|.ok }
|
|
first :: @ items: []i32 -> i32? {
|
|
match items {
|
|
[] => |.none
|
|
[head, ...rest] => head->|.some
|
|
}
|
|
}
|
|
unwrap :: @ result: i32 ! str -> i32 {
|
|
match result {
|
|
|.ok value => value
|
|
|.err _ => 0
|
|
}
|
|
}
|
|
|
|
---
|
|
|
|
(source_file
|
|
(declaration
|
|
(identifier)
|
|
(function_literal
|
|
(typed_parameter
|
|
(identifier)
|
|
(primitive_type))
|
|
(result_type
|
|
(primitive_type)
|
|
(primitive_type))
|
|
(block
|
|
(pipeline_expression
|
|
(identifier)
|
|
(direct_pipeline_stage
|
|
(pipeline_callable
|
|
(sum_constructor
|
|
(identifier))))))))
|
|
(declaration
|
|
(identifier)
|
|
(function_literal
|
|
(typed_parameter
|
|
(identifier)
|
|
(array_type
|
|
(primitive_type)))
|
|
(optional_type
|
|
(primitive_type))
|
|
(block
|
|
(match_expression
|
|
(identifier)
|
|
(match_arm
|
|
(pattern
|
|
(array_pattern))
|
|
(sum_constructor
|
|
(identifier)))
|
|
(match_arm
|
|
(pattern
|
|
(array_pattern
|
|
(array_pattern_entry
|
|
(pattern
|
|
(identifier)))
|
|
(array_pattern_entry
|
|
(identifier))))
|
|
(pipeline_expression
|
|
(identifier)
|
|
(direct_pipeline_stage
|
|
(pipeline_callable
|
|
(sum_constructor
|
|
(identifier))))))))))
|
|
(declaration
|
|
(identifier)
|
|
(function_literal
|
|
(typed_parameter
|
|
(identifier)
|
|
(result_type
|
|
(primitive_type)
|
|
(primitive_type)))
|
|
(primitive_type)
|
|
(block
|
|
(match_expression
|
|
(identifier)
|
|
(match_arm
|
|
(pattern
|
|
(sum_pattern
|
|
(identifier)
|
|
(identifier)))
|
|
(identifier))
|
|
(match_arm
|
|
(pattern
|
|
(sum_pattern
|
|
(identifier)))
|
|
(signed_numeric_literal
|
|
(integer_literal))))))))
|
|
|
|
==================
|
|
Untyped function inputs
|
|
==================
|
|
|
|
double :: @ value { value * 2 }
|
|
sum: (i32, i32) -> i32: @ (left, right) { left + right }
|
|
mixed :: @ (left: i32, right) -> i32 { left + right }
|
|
|
|
---
|
|
|
|
(source_file
|
|
(declaration
|
|
(identifier)
|
|
(function_literal
|
|
(typed_parameter
|
|
(identifier))
|
|
(block
|
|
(binary_expression
|
|
(identifier)
|
|
(signed_numeric_literal
|
|
(integer_literal))))))
|
|
(declaration
|
|
(identifier)
|
|
(function_type
|
|
(tuple_type
|
|
(primitive_type)
|
|
(primitive_type))
|
|
(primitive_type))
|
|
(function_literal
|
|
(typed_parameter
|
|
(tuple_pattern
|
|
(pattern
|
|
(identifier))
|
|
(pattern
|
|
(identifier))))
|
|
(block
|
|
(binary_expression
|
|
(identifier)
|
|
(identifier)))))
|
|
(declaration
|
|
(identifier)
|
|
(function_literal
|
|
(typed_tuple_pattern
|
|
(typed_tuple_component
|
|
(identifier)
|
|
(primitive_type))
|
|
(typed_tuple_component
|
|
(identifier)))
|
|
(primitive_type)
|
|
(block
|
|
(binary_expression
|
|
(identifier)
|
|
(identifier))))))
|
|
|
|
==================
|
|
Postfix pipeline stages
|
|
==================
|
|
|
|
mixed :: -3->add_ten + 2 * 3->double - {1 + 1}->double
|
|
checked :: not c->is_digit
|
|
unwrapped :: input->fallible?->next
|
|
|
|
---
|
|
|
|
(source_file
|
|
(declaration
|
|
(identifier)
|
|
(binary_expression
|
|
(binary_expression
|
|
(unary_expression
|
|
(pipeline_expression
|
|
(signed_numeric_literal
|
|
(integer_literal))
|
|
(direct_pipeline_stage
|
|
(pipeline_callable
|
|
(identifier)))))
|
|
(binary_expression
|
|
(signed_numeric_literal
|
|
(integer_literal))
|
|
(pipeline_expression
|
|
(signed_numeric_literal
|
|
(integer_literal))
|
|
(direct_pipeline_stage
|
|
(pipeline_callable
|
|
(identifier))))))
|
|
(pipeline_expression
|
|
(block
|
|
(binary_expression
|
|
(signed_numeric_literal
|
|
(integer_literal))
|
|
(signed_numeric_literal
|
|
(integer_literal))))
|
|
(direct_pipeline_stage
|
|
(pipeline_callable
|
|
(identifier))))))
|
|
(declaration
|
|
(identifier)
|
|
(unary_expression
|
|
(pipeline_expression
|
|
(identifier)
|
|
(direct_pipeline_stage
|
|
(pipeline_callable
|
|
(identifier))))))
|
|
(declaration
|
|
(identifier)
|
|
(pipeline_expression
|
|
(identifier)
|
|
(direct_pipeline_stage
|
|
(pipeline_callable
|
|
(identifier)))
|
|
(direct_pipeline_stage
|
|
(pipeline_callable
|
|
(identifier))))))
|
|
|
|
==================
|
|
Continuations after same-line stages
|
|
==================
|
|
|
|
flat := value->first->second
|
|
->third
|
|
whole := a + b->f
|
|
->g
|
|
|
|
---
|
|
|
|
(source_file
|
|
(declaration
|
|
(identifier)
|
|
(pipeline_expression
|
|
(identifier)
|
|
(direct_pipeline_stage
|
|
(pipeline_callable
|
|
(identifier)))
|
|
(direct_pipeline_stage
|
|
(pipeline_callable
|
|
(identifier)))
|
|
(continuation_pipeline_stage
|
|
(pipeline_callable
|
|
(identifier)))))
|
|
(declaration
|
|
(identifier)
|
|
(pipeline_expression
|
|
(binary_expression
|
|
(identifier)
|
|
(pipeline_expression
|
|
(identifier)
|
|
(direct_pipeline_stage
|
|
(pipeline_callable
|
|
(identifier)))))
|
|
(continuation_pipeline_stage
|
|
(pipeline_callable
|
|
(identifier))))))
|
|
|
|
==================
|
|
Generic binders and constraints
|
|
==================
|
|
|
|
Show :: <>{
|
|
to_str: str
|
|
...Display
|
|
}
|
|
pick: <T: Show, (T, T): Ordered> (T, T) -> T: @ (first, second): (T, T) { first }
|
|
Card :: &{ label: Output<make_label: Show>: }
|
|
|
|
---
|
|
|
|
(source_file
|
|
(declaration
|
|
(identifier)
|
|
(type_definition
|
|
(constraint_body
|
|
(constraint_entry
|
|
(identifier)
|
|
(primitive_type))
|
|
(constraint_spread
|
|
(identifier)))))
|
|
(declaration
|
|
(identifier)
|
|
(binder
|
|
(binder_entry
|
|
(identifier)
|
|
(identifier))
|
|
(binder_entry
|
|
(tuple_type
|
|
(identifier)
|
|
(identifier))
|
|
(identifier)))
|
|
(function_type
|
|
(tuple_type
|
|
(identifier)
|
|
(identifier))
|
|
(identifier))
|
|
(function_literal
|
|
(typed_parameter
|
|
(tuple_pattern
|
|
(pattern
|
|
(identifier))
|
|
(pattern
|
|
(identifier)))
|
|
(tuple_type
|
|
(identifier)
|
|
(identifier)))
|
|
(block
|
|
(identifier))))
|
|
(declaration
|
|
(identifier)
|
|
(type_definition
|
|
(product_type
|
|
(product_field
|
|
(identifier)
|
|
(output_type
|
|
(identifier)
|
|
(identifier)
|
|
(identifier)))))))
|
|
|
|
==================
|
|
Import filters
|
|
==================
|
|
|
|
use math.{sqrt for f64, pi as p}
|
|
use .shapes.area for Circle
|
|
pub { area for Circle; sqrt }
|
|
|
|
---
|
|
|
|
(source_file
|
|
(use_declaration
|
|
(module_path
|
|
(identifier))
|
|
(import_member
|
|
(identifier)
|
|
(import_filter
|
|
(primitive_type)))
|
|
(import_member
|
|
(identifier)
|
|
(identifier)))
|
|
(use_declaration
|
|
(module_path
|
|
(qualified_name
|
|
(identifier)
|
|
(identifier)))
|
|
(import_filter
|
|
(identifier)))
|
|
(pub_declaration
|
|
(pub_entry
|
|
(identifier)
|
|
(import_filter
|
|
(identifier)))
|
|
(pub_entry
|
|
(identifier))))
|
|
|
|
==================
|
|
Reserved word
|
|
:error
|
|
==================
|
|
|
|
context := 1
|
|
|
|
---
|
|
|
|
|