spec: accept RFC 0013 and add spec 15, the .aji source language 0.1
Owner decisions D1-D7 and the boundary rule (source may hide representation mechanics, never authority, allocation, ownership transfer, synchronization, external effects or recoverable failure). spec 15 normative: items, types, statements, expressions, places and borrows, explicit move (named values), outcome matches and 'or trap', scope/shield/lock blocks (lock lowering defined exactly), select, channels, allocation, frame storage, lexical borrow scopes, inferred features, one canonical spelling per construct. grammar.ebnf replaced; E7001-E7007; E3101 gains suggested_effects; spec 01 examples updated.
This commit is contained in:
1 parent
0e25a17e9d
commit
65b10e3fb5
9 files changed
+471
-56
No files matched your search
+85
-42
@@ -1,51 +1,94 @@
|
||||
(* Aji draft grammar sketch. This is intentionally incomplete until syntax stabilizes. *)
|
||||
(* Aji source language `.aji` 0.1 (Phase 6A). Normative together with
|
||||
docs/spec/15-source-language.md. Decision record: RFC 0013.
|
||||
|
||||
program = { module_decl | import_decl | type_decl | function_decl } ;
|
||||
Lexical conventions
|
||||
-------------------
|
||||
- `//` starts a comment that runs to the end of the line.
|
||||
- Whitespace and line breaks separate tokens and are otherwise insignificant.
|
||||
- Keywords: module type struct enum fn effects trusted from let var zero
|
||||
if else while for in loop break continue return trap match select
|
||||
scope shield lock as cancelled ref mut move unchecked or and not
|
||||
true false recv send.
|
||||
- Every construct has one canonical spelling (spec 15 §1).
|
||||
*)
|
||||
|
||||
module_decl = "module" qualified_name ";" ;
|
||||
import_decl = "use" qualified_name [ "as" identifier ] ";" ;
|
||||
module = "module" path { item } ;
|
||||
item = type_decl | fn_decl ;
|
||||
path = ident { "." ident } ;
|
||||
|
||||
function_decl = [ "pub" ] [ "unsafe" ] "fn" identifier
|
||||
[ generic_params ]
|
||||
"(" [ parameter_list ] ")"
|
||||
[ "->" type ]
|
||||
effect_decl
|
||||
[ contract_block ]
|
||||
block ;
|
||||
type_decl = "type" ident "=" ( struct_body | enum_body ) ;
|
||||
struct_body = "struct" "{" [ field { "," field } [ "," ] ] "}" ;
|
||||
field = ident ":" type ;
|
||||
enum_body = "enum" "{" [ variant { "," variant } [ "," ] ] "}" ;
|
||||
variant = ident [ "(" type { "," type } ")" ] ;
|
||||
|
||||
effect_decl = "effects" "[" [ effect_list ] "]" ;
|
||||
fn_decl = "fn" ident "(" [ param { "," param } ] ")" "->" type [ "from" ident ]
|
||||
"effects" "[" [ path { "," path } ] "]"
|
||||
[ "trusted" string ]
|
||||
block ;
|
||||
param = ident ":" type ;
|
||||
|
||||
parameter_list = parameter { "," parameter } ;
|
||||
parameter = identifier ":" param_type ;
|
||||
param_type = [ "move" ] type
|
||||
| "ref" "<" type ">"
|
||||
| "mut" "<" type ">" ;
|
||||
type = int_type | "bool" | "void" | "never" | ident
|
||||
| "[" type ";" int_lit "]"
|
||||
| wrapper "<" type ">"
|
||||
| "cap" "<" path ">"
|
||||
| "file" "<" ( "read" | "write" | "append" ) ">" ;
|
||||
wrapper = "ref" | "mut" | "slice" | "slice_mut" | "own" | "own_array"
|
||||
| "task" | "sender" | "receiver" | "mutex" ;
|
||||
int_type = "u8" | "u16" | "u32" | "u64" | "u128" | "usize"
|
||||
| "i8" | "i16" | "i32" | "i64" | "i128" | "isize" ;
|
||||
(* `region`, `listener`, `stream`, `io_error`, `alloc_error`,
|
||||
`cap_error` are built-in type names (ident). *)
|
||||
|
||||
type = primitive_type
|
||||
| qualified_name
|
||||
| "Option" "<" type ">"
|
||||
| "Result" "<" type "," type ">"
|
||||
| "Own" "<" type ">"
|
||||
| "Island" "<" type ">"
|
||||
| "Frozen" "<" type ">"
|
||||
| "Arc" "<" type ">"
|
||||
| "slice" "<" type ">"
|
||||
| "slice_mut" "<" type ">"
|
||||
| "ref" "<" type ">"
|
||||
| "mut" "<" type ">"
|
||||
| "[" type ";" integer_literal "]" ;
|
||||
block = "{" { statement } [ expr ] "}" ; (* optional tail expression: the block's value *)
|
||||
statement = "let" binding [ ":" type ] "=" expr ";"
|
||||
| "var" ident ":" type "=" ( expr | "zero" ) ";"
|
||||
| place "=" expr ";"
|
||||
| "break" ";" | "continue" ";" | "return" [ expr ] ";" | "trap" ";"
|
||||
| expr ";"
|
||||
| block_stmt ;
|
||||
binding = ident | "(" ident "," ident ")" ; (* the pair form only for `split_at` *)
|
||||
block_stmt = if_expr | match_expr | select_stmt | block
|
||||
| "while" expr block
|
||||
| "for" ident "in" expr ".." expr block
|
||||
| "loop" block
|
||||
| "scope" ident block
|
||||
| "shield" block
|
||||
| "lock" "ref" place "as" ident block "cancelled" block ;
|
||||
|
||||
primitive_type = "bool" | "byte" | "void" | "never"
|
||||
| "u8" | "u16" | "u32" | "u64" | "u128" | "usize"
|
||||
| "i8" | "i16" | "i32" | "i64" | "i128" | "isize"
|
||||
| "f32" | "f64" ;
|
||||
if_expr = "if" expr block [ "else" ( if_expr | block ) ] ;
|
||||
match_expr = "match" expr "{" { arm } "}" ;
|
||||
arm = pattern "=>" ( block | expr "," ) ;
|
||||
pattern = "_" | int_lit
|
||||
| ident [ "(" ident { "," ident } ")" ] ; (* variant or outcome: ok(n), closed, Shape.Rect(w, h) is written Rect(w, h) *)
|
||||
|
||||
block = "{" { statement } "}" ;
|
||||
statement = let_stmt | var_stmt | return_stmt | expr_stmt | block ;
|
||||
let_stmt = "let" identifier [ ":" type ] "=" expression ";" ;
|
||||
var_stmt = "var" identifier [ ":" type ] "=" expression ";" ;
|
||||
return_stmt = "return" [ expression ] ";" ;
|
||||
expr_stmt = expression ";" ;
|
||||
select_stmt = "select" "{" { select_arm } "cancelled" [ "(" ident { "," ident } ")" ] "=>" ( block | expr "," ) "}" ;
|
||||
select_arm = "recv" "(" ident ")" "{" { arm } "}"
|
||||
| "send" "(" ident "," expr ")" "{" { arm } "}" ;
|
||||
|
||||
qualified_name = identifier { "." identifier } ;
|
||||
identifier = letter { letter | digit | "_" } ;
|
||||
expr = or_expr ;
|
||||
or_expr = and_expr { "or" ( and_expr | "trap" ) } ; (* `e or trap`: the only fallible shorthand *)
|
||||
and_expr = cmp_expr { "and" cmp_expr } ;
|
||||
cmp_expr = bit_expr [ ( "==" | "!=" | "<" | "<=" | ">" | ">=" ) bit_expr ] ;
|
||||
bit_expr = shift_expr { ( "&" | "|" | "^" ) shift_expr } ;
|
||||
shift_expr = add_expr { ( "<<" | ">>" ) add_expr } ;
|
||||
add_expr = mul_expr { ( "+" | "-" | "+%" | "-%" ) mul_expr } ;
|
||||
mul_expr = cast_expr { ( "*" | "/" | "%" | "*%" ) cast_expr } ;
|
||||
cast_expr = unary { ( "as" | "as!" | "as%" ) type } ;
|
||||
unary = ( "-" | "not" | "*" ) unary
|
||||
| ( "ref" | "mut" ) [ "unchecked" ] place
|
||||
| "move" ident
|
||||
| postfix ;
|
||||
postfix = primary { "." ident | "[" expr [ ".." expr ] "]" | call_args } ;
|
||||
call_args = [ "<" type ">" ] "(" [ expr { "," expr } ] ")" ;
|
||||
primary = int_lit | "true" | "false" | string
|
||||
| ident [ "{" field_init { "," field_init } [ "," ] "}" ] (* struct literal *)
|
||||
| "[" expr ";" int_lit "]"
|
||||
| "(" expr ")"
|
||||
| if_expr | match_expr | block ;
|
||||
field_init = ident ":" expr ;
|
||||
place = ident { "." ident | "[" expr [ ".." expr ] "]" } | "*" unary ;
|
||||
|
||||
int_lit = digit { digit | "_" } [ int_type ] | "0x" hexdigit { hexdigit | "_" } [ int_type ] ;
|
||||
string = 'b"' { char | escape } '"' ; (* byte string; escapes \n \t \\ \" \xHH *)
|
||||
ident = ( letter | "_" ) { letter | digit | "_" } ;
|
||||
Reference in new issue
Block a user