This commit is contained in:
2026-09-23 00:36:22 -04:00
commit 6e4f9cd65a
74 changed files with 57163 additions and 0 deletions
+235
View File
@@ -0,0 +1,235 @@
==================
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?}: [nil, 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
(nil_literal))
(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)))))
+2
View File
@@ -0,0 +1,2 @@
value := 0
value=-1
+1
View File
@@ -0,0 +1 @@
identity :: @ value { value }
+1
View File
@@ -0,0 +1 @@
text :: 'bad\qescape'
+1
View File
@@ -0,0 +1 @@
different :: left != right
+1
View File
@@ -0,0 +1 @@
->initialize
+1
View File
@@ -0,0 +1 @@
Point :: &{ x: i32:, y: i32: }
+1
View File
@@ -0,0 +1 @@
value: i32:
+1
View File
@@ -0,0 +1 @@
outer := inner := 1
+1
View File
@@ -0,0 +1 @@
text :: "double quoted"
+1
View File
@@ -0,0 +1 @@
values := [1,, 2]
+1
View File
@@ -0,0 +1 @@
(left, right): (i32, i32): (1, 2)
+2
View File
@@ -0,0 +1,2 @@
identity :: @ value: i32
{ value }
+1
View File
@@ -0,0 +1 @@
in := 1
+1
View File
@@ -0,0 +1 @@
answer: () -> i32: @ 42
+2
View File
@@ -0,0 +1,2 @@
identity: i32 -> i32:
@ value: i32 { value }
+1
View File
@@ -0,0 +1 @@
identity: i32 -> i32: value@ value
+9
View File
@@ -0,0 +1,9 @@
Choice :: |{
one
}
describe :: @ choice: Choice -> str { match choice {
|.one =>
'one'
}
}
+1
View File
@@ -0,0 +1 @@
{start as {line}} :: value
+1
View File
@@ -0,0 +1 @@
value :: 1__000
+1
View File
@@ -0,0 +1 @@
value :: 1.0f
+1
View File
@@ -0,0 +1 @@
StringIterator :: Iter(str)
+2
View File
@@ -0,0 +1,2 @@
Error :: |{ failed }
Bad :: i32? ! Error
+2
View File
@@ -0,0 +1,2 @@
Error :: |{ failed }
Bad :: i32 ! Error?
+1
View File
@@ -0,0 +1 @@
value :: (1 + 2)
+3
View File
@@ -0,0 +1,3 @@
value := 1
->to_str
+3
View File
@@ -0,0 +1,3 @@
value := 1
# this line terminates the preceding expression
->to_str
+1
View File
@@ -0,0 +1 @@
value :: 1 + 2->to_str
+3
View File
@@ -0,0 +1,3 @@
FirstError :: |{ failed }
SecondError :: |{ failed }
Bad :: i32 ! FirstError ! SecondError
+4
View File
@@ -0,0 +1,4 @@
value := {
first;
second
}
+2
View File
@@ -0,0 +1,2 @@
value := 1
value >>= 1
+1
View File
@@ -0,0 +1 @@
value :: 1 << 2
+1
View File
@@ -0,0 +1 @@
identity :: @ (value: i32) { value }
@@ -0,0 +1 @@
identity :: @ (value: i32,) -> i32 { value }
+1
View File
@@ -0,0 +1 @@
value :: (1,)
+1
View File
@@ -0,0 +1 @@
value :: if true then 1 else 2
+2
View File
@@ -0,0 +1,2 @@
value := 1->
to_str
+1
View File
@@ -0,0 +1 @@
value: i32 =
+1
View File
@@ -0,0 +1 @@
value := { 1; }
@@ -0,0 +1 @@
iterator: Iter<i32>=
+1
View File
@@ -0,0 +1 @@
Bad :: (i32,)
+1
View File
@@ -0,0 +1 @@
value :=
+1
View File
@@ -0,0 +1 @@
use module.*
+19
View File
@@ -0,0 +1,19 @@
numbers := [1, 2, 3]
more_numbers := [0, ...numbers, 4]
codes := ['ok' => 200, 'missing' => 404]
more_codes := [...codes, 'failed' => 500]
empty_numbers: []i32: []
empty_codes: [str]i32: []
optional_numbers: []i32?: nil
optional_elements: []{i32?}: [nil, 1->|.some]
Options :: &{
name: str: 'default'
count: i32 = 0
}
defaults := &Options.{}
overridden := &Options.{ ...defaults; count = 2 }
anonymous := &.{ label: 'value'; count = 1 }
+28
View File
@@ -0,0 +1,28 @@
choose: (bit, i32, i32) -> i32: @ (condition: bit, when_true: i32, when_false: i32) { if condition { when_true } else { when_false } }
choose_block: (bit, i32, i32) -> i32: @ (condition: bit, when_true: i32, when_false: i32) { if condition {
when_true
} else if not condition {
when_false
} else {
0
} }
first_positive: []i32 -> i32?: @ values: []i32 {
for value in values {
if value > 0 {
return value->|.some
}
}
nil
}
labelled_search: []i32 -> i32: @ values: []i32 { loop `outer {
for value in values `items {
if value > 0 {
break `outer value
}
continue `items
}
break 0
} }
+18
View File
@@ -0,0 +1,18 @@
immutable :: 1
mutable := 2
typed_immutable: i32: 3
typed_mutable: i32 = 4
deferred: i32
deferred = 5
then :: 6
(left, right) :: (1, 2)
(mutable_left, mutable_right) := (3, 4)
Point :: &{
x: i32:
y: i32 =
}
point := &Point.{ x: 10; y = 20 }
{x as horizontal, y} :: point
+18
View File
@@ -0,0 +1,18 @@
double: i32 -> i32: @ value: i32 { value * 2 }
square: i32 => i32: @ value: i32 { value * value }
add: (i32, i32) -> i32: @ (left: i32, right: i32) { left + right }
normalize: i32 -> i32: @ value: i32 {
adjusted := value + 1
adjusted->double
}
apply: (i32, i32 -> i32) -> i32: @ (value, operation): {(i32, i32 -> i32)} { value->operation }
factory: i32 => i32 -> i32: @ offset: i32 { @ value: i32 { value + offset } }
initialize: () -> i32: @ () { 1 }
computed := (4, @ value: i32 { value + 1 })->apply
+18
View File
@@ -0,0 +1,18 @@
inline_array := [1, 2, 3]
newline_array := [
1
2
3
]
comma_array := [
1,
2,
3,
]
inline_block := { first := 1; second := 2; first + second }
InlinePoint :: &{ x: i32:; y: i32: }
inline_point := &InlinePoint.{ x: 1; y: 2 }
+17
View File
@@ -0,0 +1,17 @@
decimal :: 1_000_000
binary :: 0b1010_0101
octal :: 0o755
hexadecimal :: 0xCAFE_beef
leading_zeroes :: 007
fraction_without_integer :: .5
fraction_without_digits :: 1.
scientific :: 1.25e-10
scientific_integer :: 1E+4
negative_minimum: i8: -128
spaced_negative: i8: - 127
text :: 'can\'t\nstop'
letter :: c'é'
escaped_letter :: c'\u{1f642}'
nul :: c'\0'
+14
View File
@@ -0,0 +1,14 @@
use math
use math as arithmetic
use math.{pi, sqrt as square_root}
ExportedType :: distinct i32
exported :: 1
circle: f64: pi
root: f64: 4.0->square_root
qualified_root: f64: 9.0->arithmetic.sqrt
pub {
ExportedType
exported
}
+27
View File
@@ -0,0 +1,27 @@
ready: bit: true
connected: bit: true
busy: bit: false
can_run :: ready
and connected
and not busy
one: i32: 1
two: i32: 2
three: i32: 3
sum :: one
+ two
* three
eight: i32: 8
five: i32: 5
difference :: eight -
five
first_mask: u8: 1
second_mask: u8: 2
mask :: first_mask |
second_mask
is_ordered :: sum
> difference
+26
View File
@@ -0,0 +1,26 @@
Location :: |{
unknown
known: (f32, f32)
}
describe: Location -> str: @ location: Location { match location {
|.unknown => 'unknown'
|.known (latitude, longitude) if latitude >= 0.0 => 'known'
|.known (_, _) => 'known'
} }
Point :: &{
x: i32:
y: i32:
}
sum_point: Point -> i32: @ point: Point {
{x as horizontal, y as vertical} :: point
horizontal + vertical
}
classify_array: []i32 -> str: @ values: []i32 { match values {
[] => 'empty'
[only] => 'one'
[first, ...rest] => 'many'
} }
+23
View File
@@ -0,0 +1,23 @@
Error :: distinct |{
failed
}
reversed := 'value'->reverse_chrs
sum_text := {1 + 2}->to_str
continued := 'value'
->reverse_chrs
->reverse_chrs
commented := 'value' # an inline comment preserves continuation
->reverse_chrs
computed := 1 + 2
->to_str
fallible: i32 -> i32 ! Error: @ value: i32 { value! }
propagate: i32 -> i32 ! Error: @ value: i32 {
result := {value->fallible}?
result!
}
+21
View File
@@ -0,0 +1,21 @@
double :: @ value: i32 { value * 2 }
add :: @ (a: i32, b: i32) { a + b }
square :: @ value: i32 => i32 { value * value }
constant :: @ () -> i32 { 42 }
unit :: @ { () }
apply :: @ (value: i32, callback: i32 -> i32) {
value->callback
}
sum :: @ (left: i32, right: i32) { left + right }
multiline :: @ (
first: i32
second: i32
) -> i32 { first + second }
explicit: i32 -> i32: @ value: i32 { value + 1 }
mutable := @ value: i32 { value + 1 }
run_callback :: @ callback: {() -> i32} { ()->callback }
callback_result := @ () -> i32 { 42 }->run_callback
+22
View File
@@ -0,0 +1,22 @@
Error :: distinct |{
failed
}
OptionalArray :: []u8?
OptionalElements :: []{u8?}
OptionalMap :: [str]i32?
OptionalValues :: [str]{i32?}
OptionalSuccessResult :: {i32?} ! Error
OptionalResult :: {i32 ! Error}?
OptionalErrorResult :: i32 ! {Error?}
Curried :: i32 -> str -> bit
PureTransform :: str => str
MixedTransform :: i32 => str -> bit
ReturningResult :: str -> i32 ! Error
IntegerRange :: Range<i32>
StringIterator :: Iter<str>
NestedIterator :: Iter<Iter<str>>
TupleIterator :: Iter<(i32, str)>