gsh/input/buffer

The buffer module handles multiline input detection for the REPL.

When a user enters code spanning multiple lines (like a case block, anonymous function, or complex data structure), this module analyzes the surface AST to determine if the statement is complete or requires additional input via the continuation prompt (...>).

Values

pub fn is_complete(input: String) -> Bool

Analyzes a string of Gleam source code to determine if it is structurally complete.

Verification Strategy:

  • String Termination: Lexes the string to check for UnterminatedString tokens. If an unclosed string is found, evaluation is deferred.
  • Delimiter Balancing: Tracks opening and closing delimiters—parentheses (), brackets [], and braces {}—using token streams. Because matching relies on lexer output rather than raw characters, delimiters enclosed within strings or comments are safely ignored.
  • Completion Criteria: Returns True only when all delimiter depth counts reach zero or less, signaling that the statement is ready for evaluation.
Search Document