Skip to main content

Indentation

Fuyu is indentation‑sensitive, and its layout rules describe how indentation works. All scoping and control structures are realized by indentation.

Rules

Indentation is managed by a stack that keeps track of the number of spaces used for each block.

  • The let and match tokens begin a context where, if the following token appears on the next line, that token starts a new indented block and its indentation level is pushed onto the indentation stack.
  • If a line starts at the same indentation as the top of the indentation stack, the previous expression ends and the token begins a new one in the same block.
  • If a line starts at a smaller indentation than the top of the indentation stack, pop entries from the stack until the current indentation level matches the top of the stack, closing each preceding block along the way.
  • If a line starts at a greater indentation than the top of the stack under any other circumstance, do nothing (the line is part of the current block).

Tabs are not allowed

Tabs and spaces present challenges for whitespace-sensitive languages. Which do you use? Are both allowed? Can they be mixed? How wide is a tab? Different languages answer this question in different ways.

It is simple in Fuyu: literal tabs are not allowed in a Fuyu source text.

The reasoning is that literal tabs are not allowed anywhere that they may affect indentation. The emphasis is on may because even tabs that are not at the start of a line or are inside of string literals have the potential to affect indentation! For these reasons, tabs are completely disallowed, and the age-old tab versus spaces debate does not exist in Fuyu.