On this page:
read
Read  Mode
Read  Mode.top
Read  Mode.interactive
Read  Mode.line
Read  Mode.text
8.17.0.6

13.7 Shrubbery Input🔗ℹ

 import: rhombus/shrubbery package: rhombus-lib

function

fun shrubbery.read(in :: Port.Input,

                   ~mode: mode :: shrubbery.ReadMode = #'top,

                   ~start_column: start_column :: Int = 0)

  :: Syntax || Port.eof

 

enumeration

enum shrubbery.ReadMode:

  top

  interactive

  line

  text

Reads a shrubbery form from in. The result can be Port.eof only in #'interactive or #'line modes.

  • #'top mode reads all shrubbery forms until an end-of-file, and it produces a term, group, or multi-group sequence.

  • #'interactive mode reads until an end-of-line, unless nothing has been read so far, an opener remains unclosed, or a [:] was encountered that not within an open-closer sequence. If reading continues due to a :, then it stops when a blank line is found (where a line containing a comment does not count as blank), as long as stopping does not create an empty block.

  • #'line mode is like #'interactive mode, except that it can stop and produce an empty term sequence if a newline is found without having read anything.

  • #'tex mode reads until an end-of-file, but starting as if inside @{}, and the result is a [] form.

import rhombus/shrubbery

> shrubbery.read(Port.Input.open_string("fun (x):\n  x + 1"))

'fun (x): x + 1'