tobogganSe connecter

louise

The Louise language: compiler, runtime, std, tooling

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

Syntax: parens-free definitions and application (ADR 0061, issue #314)

Phase 1 of ADR 0061: the grammar and CST for parens-free functions.

- Definitions: `fn add :: a b { a + b }` — a `::` separates the name
  from space-separated parameters (patterns with optional `: T`;
  parentheses group a pattern, `(State(..) as state)`). Lambdas have no
  name and no `::` (`fn x { x + 1 }`); handler clauses keep bare
  patterns (`log m -> resume m`); effect operations and trait/impl
  methods take the `::`. Zero-parameter definitions are
  `fn main :: { .. }`.
- Application is juxtaposition, left-associative, tighter than every
  infix. Arguments are atoms (paths, literals, lists, tuples/parens, fn
  lambdas, tagged templates, if/match/handle/region, `~`-labelled args,
  `_`); blocks, HTML literals and prefix-operator expressions are not
  atoms. The call-paren adjacency rule dies; construction keeps its
  parentheses, keyed on the callee's case like patterns already do
  (`User(~name: "ada")`, `User(..base, ~name: "x")`).
- The fifth newline rule: an application (or parameter list, or
  attribute's arguments) continues on a following line that starts with an
  atom more indented than the statement/definition it belongs to. Inside
  parens, brackets and holes line breaks are free. A match arm's body is
  greedy to the end of its line and continues on more-indented lines; the
  reference indent is the arm's.
- Labels are `~name` (pun) / `~name: value` at calls, `~name` /
  `~name: T` / `~name:(p: T)` in parameters, `~name: pat` in
  constructor patterns, `~name: T` in fn types. A label's value is an
  atom everywhere (parenthesise anything bigger).
- Attributes go paren-free: `@derive Eq Show`,
  `@extern c "sym" (blocking io)`.
- Curried fn types need no grammar change: `fn(a) -> fn(b) -> c / <e>`
  nests via the return type, the row landing on the last arrow.
- `(pat)` with a single pattern is grouping, not a 1-tuple pattern
  (1-tuples never existed for expressions; the pattern side was dead).
- Migration-aid parse errors for the two most common old shapes:
  `fn f(` and a call's `name:` label.
- Formatter handles the new CST: definitions stack broken parameters
  under the `::` (one per line, then the return type and `where`), an
  application's arguments take the under-form (`f\n  a\n  b`, ADR 0059
  rev. 4's shape de facto), construction keeps hugging parentheses.
- Parser corpus and format tests migrated by hand; snapshots re-blessed.
  `doc_samples_parse` and the repo-wide format test are ignored until
  `louise migrate` (phase 5) rewrites the docs and the repo; tests/ui,
  tests/run and the HIR/type suites stay red until then (the .lse sources
  are still old syntax).
- cargo fmt picked up pre-existing drift in louise_hir/src/lower/mod.rs.

Decisions where the spec was silent (for the ADR's open-for-review list):
- After `~name:` in a parameter, `(` always starts a rename pattern
  group; otherwise a type follows (a pun with a type). A pun with a
  parenthesised or tuple type writes it as `~name:(name: (Int, Int))`.
- A label's value is an atom uniformly, inside construction parentheses
  too (`User(~name: (f x))`).
- A constructor's parentheses need no adjacency: `User (x)` is
  construction wherever the line break rule allows it.
- Lambda parameters continue on lines more indented than the enclosing
  statement (they have no item column of their own).

olivier · il y a 1 mois · bf8401d88f8d134ae24fcf62b6b7e4b819610a52

Parents 2bf0167

47 fichiers modifiés, 3909 ajouts, 3275 suppressions

Mcrates/louise_hir/src/lower/mod.rs+13−10
Mcrates/louise_syntax/src/format.rs+210−120
Mcrates/louise_syntax/src/grammar/expr.rs+320−119
Mcrates/louise_syntax/src/grammar/html.rs+1−1
Mcrates/louise_syntax/src/grammar/mod.rs+146−46
Mcrates/louise_syntax/src/grammar/pat.rs+37−16
Mcrates/louise_syntax/src/grammar/types.rs+15−2
Mcrates/louise_syntax/src/lexer.rs+2−0
Mcrates/louise_syntax/src/parser.rs+15−0
Mcrates/louise_syntax/src/syntax_kind.rs+4−0
Mcrates/louise_syntax/tests/ast.rs+4−4
Mcrates/louise_syntax/tests/data/err/bad_tokens.lse+1−1
Mcrates/louise_syntax/tests/data/err/chained_comparison.lse+1−1
Mcrates/louise_syntax/tests/data/err/garbage_between_items.lse+1−1
Mcrates/louise_syntax/tests/data/err/html_mismatch.lse+2−2
Mcrates/louise_syntax/tests/data/err/match_comma.lse+3−3
Mcrates/louise_syntax/tests/data/err/missing_brace.lse+2−2
Mcrates/louise_syntax/tests/data/err/return_as_name.lse+2−2
Mcrates/louise_syntax/tests/data/err/templates.lse+3−3
Mcrates/louise_syntax/tests/data/ok/exprs.lse+23−16
Mcrates/louise_syntax/tests/data/ok/html.lse+6−6
Mcrates/louise_syntax/tests/data/ok/items.lse+20−20
Mcrates/louise_syntax/tests/data/ok/patterns.lse+2−2
Mcrates/louise_syntax/tests/data/ok/placeholders.lse+4−4
Mcrates/louise_syntax/tests/data/ok/return.lse+5−5
Mcrates/louise_syntax/tests/data/ok/templates.lse+1−1
Mcrates/louise_syntax/tests/format.rs+1−0
Mcrates/louise_syntax/tests/fuzz.rs+3−0
Mcrates/louise_syntax/tests/parser.rs+11−1
Mcrates/louise_syntax/tests/snapshots/parser__err_corpus_recovers_with_errors@bad_tokens.lse.snap+41−41
Mcrates/louise_syntax/tests/snapshots/parser__err_corpus_recovers_with_errors@chained_comparison.lse.snap+15−16
Mcrates/louise_syntax/tests/snapshots/parser__err_corpus_recovers_with_errors@garbage_between_items.lse.snap+61−58
Acrates/louise_syntax/tests/snapshots/parser__err_corpus_recovers_with_errors@garbage_between_items.lse.snap.new+83−0
Mcrates/louise_syntax/tests/snapshots/parser__err_corpus_recovers_with_errors@html_mismatch.lse.snap+36−36
Mcrates/louise_syntax/tests/snapshots/parser__err_corpus_recovers_with_errors@match_comma.lse.snap+56−55
Mcrates/louise_syntax/tests/snapshots/parser__err_corpus_recovers_with_errors@missing_brace.lse.snap+46−45
Mcrates/louise_syntax/tests/snapshots/parser__err_corpus_recovers_with_errors@return_as_name.lse.snap+38−37
Mcrates/louise_syntax/tests/snapshots/parser__err_corpus_recovers_with_errors@templates.lse.snap+55−55
Mcrates/louise_syntax/tests/snapshots/parser__ok_corpus_parses_cleanly@exprs.lse.snap+664−630
Mcrates/louise_syntax/tests/snapshots/parser__ok_corpus_parses_cleanly@html.lse.snap+334−337
Mcrates/louise_syntax/tests/snapshots/parser__ok_corpus_parses_cleanly@items.lse.snap+883−883
Mcrates/louise_syntax/tests/snapshots/parser__ok_corpus_parses_cleanly@patterns.lse.snap+249−247
Mcrates/louise_syntax/tests/snapshots/parser__ok_corpus_parses_cleanly@placeholders.lse.snap+103−107
Mcrates/louise_syntax/tests/snapshots/parser__ok_corpus_parses_cleanly@return.lse.snap+176−177
Mcrates/louise_syntax/tests/snapshots/parser__ok_corpus_parses_cleanly@templates.lse.snap+155−155