Lexical structure

Rook — 1.0 specification

Comments

// to the end of the line and /* block */.

The compiler copies code comments to JavaScript near the statements they describe. Comments inside expressions or attached to erased declarations may move to a nearby generated line. File headers also appear in worker modules, along with comments on the declarations they copy.

Semicolons

They are written only to separate several statements on one line. Otherwise the lexer inserts them by Go's rule: at the end of a line if its last token is

Hence, as in Go:

Unlike Go, no semicolon is inserted if the next line starts

A line may end with > too: after the type arguments of a declaration, votes Map<string, number>, the line break ends it, while a > with a value on the next line goes on, as other operators do. A line that ends with x! (see "null and null safety") ends there too.

const names = users
    .filter(u => u.active)
    .map(u => u.name)

const point = {
    x: 1,
    y: 2
}

const label = count == 0
    ? "empty"
    : `${count} items`

Literals

Keywords

func  comp  return  let  const  interface  class  extends  new  this  super
if  else  for  in  break  continue  switch  case  default  defer
try  catch  finally  throw  import  export  async  await  go  chan
null  true  false  typeof  instanceof

Inside a class declaration static, private, protected, public, readonly, abstract and implements are keywords too, and so are get and set before the name of a method; at the start of a statement before a name type declares a type, type Id string, and elsewhere it is a name, const type = blob.type; before class so are data and abstract, in import and export so is from, at the start of a statement in a component's body state, derived, ref, style, mount and effect, at the start of a top-level declaration dec, after its parameters needs and includes, in a decorator's body public, before { at the start of a statement select, and queue in a type before the type of its values and before the < that makes a queue. Elsewhere they are ordinary names. Decorators are written before comp: @html-tag (see "Web components") and those declared with dec (see "Decorators").

After . and in object keys, keywords can be used as ordinary names: xs.map(f), event.type, { default: 1 }.

Predeclared identifiers (not keywords, they can be redeclared): the types number, string, bool, any, error, void, never and the functions error(), close() (of channels) and the others of goroutines and channels: transfer(), after(), tick(), cancel() and stream().

Names that start with $$ are reserved for generated code ($$defer, $$0). Names that are valid in Rook but not in JS (delete, static, function…) get a $ suffix in the output: delete → delete$.

Markdown source on GitHub