src/repl/reader

Source   Edit  

Types

Reader = object
Source   Edit  

Procs

proc close(self: var Reader) {....raises: [IOError], tags: [WriteIOEffect],
                               forbids: [].}
closes the reader, saving its history. Source   Edit  
proc newReader(output: Output; promptMessage: string = "reploid";
               promptSymbol: string = ">"; indentation: string = "  ";
               historyFile: string = ""): Reader {....raises: [IOError],
    tags: [ReadEnvEffect, ReadIOEffect], forbids: [].}
Creates a new Reader object with the given properties. output is used to output the prompt, which is composed by promptMessage and promptSymbol, defaults to "reploid>". indentation is used to auto-indent the lines, defaults to " ". historyFile is used to load and save the history, by default no history is saved or loaded. Source   Edit  
proc read(self: var Reader): Input {....raises: [IOError, EOFError, Exception,
    ValueError], tags: [WriteIOEffect, RootEffect, ReadIOEffect, ReadEnvEffect],
                                     forbids: [].}

Reads commands and signals.

Indentation: The next line will be auto-indented when the current ends with one of: ,, =, :, var, let, const, type, import, object, RootObj, enum and object of X The next line will be un-indented when a line is left empty. If the user manually indents or un-indents, the indentation will be adjusted accordingly.

Branching: Branching is opened when a non-indented line starts with one of the branching triggers: if, when, elif, try and except. When a non-indented line does not start with a branching trigger, branching is closed. This behavior gives space to introduce non-indented elif, else, except and finally branches.

Completion: The user's input is considered complete when either:

  • branching is closed and a non-indented line is finished without triggering an auto-indent.
  • branching is opened and an empty non-indented line is introduced.

EOF and Signals:

  • Ctrl+D is captured and returned as a Quit input.
  • Ctrl+C is captured and returned as a Reset input.
  • An EOF from stdin is returned as an EOF input.

History: Each line is added to the history file.

Source   Edit