Class Layout

java.lang.Object
org.clafer.frontend.Layout

public final class Layout extends Object
Turns indentation into blocks, as the compiler's layout resolver does (LayoutResolver.resolveLayout): a line indented more than the line before opens a block (TokenKind.INDENT), a line indented less closes the blocks it leaves (TokenKind.DEDENT), and a line at the indentation of a sibling is separated from the line before (TokenKind.SEPARATOR).

The rules are the compiler's, quirks included, so that the parser sees the tokens that the compiler's parser sees:

  • layout is off on a line that starts inside [ ] or { };
  • a line that starts with {} or {@code } has no layout;
  • a line that starts with a comment or an escape is indented at the column of the first of them, even one that starts on an earlier line;
  • a model whose brackets are open by more than one at its end has ']' bracket missing.
An inserted token has an empty span where the compiler puts it: after the token before it, past one space.
  • Method Details

    • resolve

      public static Layout.Result resolve(ClaferLexer.Result lexed)
      Resolves the layout of the tokens of a model.
      Parameters:
      lexed - the tokens, comments and escapes of ClaferLexer
      Returns:
      the tokens with the blocks and separators of the layout