KScript documentação
PT

Idioma

Traduzido automaticamente do inglês, que é a versão original.

Tipos e validação

Em XML

No XML, os mesmos tipos são atributos e elementos de <type>:

<type name="Username" with="handle" max="16" not="@admin, @root">
  <validate test="not $value.name->starts_with('_')" message="A username cannot start with _" />
</type>
<type name="Admin" with="User, Auditable">
  <field name="level" type="int" default="1" />
</type>
<let name="who" type="Username" value="@joan" />
<type name="Point">
  <construct>
    <field name="x" type="number" />
    <set name="doubled" value="$x * 2" />
  </construct>
  <field name="doubled" type="number" />
</type>
type Username with [handle] {
  max: 16
  not: [@admin, @root]
  validate: not $value.name->starts_with('_'), 'A username cannot start with _'
}
type Admin with [User, Auditable] {
  level: int = 1
}
$who: Username = @joan
type Point {
  construct({ x: number }) {
    .doubled = .x * 2
  }
  doubled: number
}

Um <construct> contém os campos que um chamador pode passar e, em seguida, as instruções a executar. Um membro privado tem private="yes" em seu <field> ou <fn>. kscript convert converte uma forma na outra.

Edit this page on GitHub