Parsing User Input Interactively

USAGE:

parseSome(con, prev = character(), n = 1)
parseClass(obj)

REQUIRED ARGUMENTS:

con
an S connection, available for input.
obj
an object (of class parse), typically returned from parseSome.

OPTIONAL ARGUMENTS:

prev
if a previous call to parseSome returned a result of parseClass equal to "partial", more input on con can be used to continue or complete this expression but providing the previous object as argument prev in the next call to parseSome.
n
how many lines to read from con, default = 1. In any case, input will not continue past the point where one complete S expression is parsed.

VALUE:

the object returned by parseSome is always of class parse, with slots "expr", "text", and "message". The "expr" slot is of class expression; if parsing was complete, it is of length 1 and contains the parsed S expression. Otherwise, it is of length 0. If there was a parse error, the error message is in slot "message". No actual S error is generated by parseSome if a syntax error occurs (which means the calling function had better check for such errors, or an endless loop will likely occur with the calling function asking for more input but just generating the same syntax error each time). To find out the result of the last parse, call parseClass(obj) with obj the last value returned from parseSome. The call to parseClass returns one of the three strings "complete", "partial", or "error".

SEE ALSO:

for forcing in a whole expression (more for non-interactive parsing).

EXAMPLES:

obj = new("parse") 
repeat { 
  obj = parseSome(myCon, obj) 
  switch(parseClass(obj), 
    complete = break, 
    partial = { doMyprompt(obj); continue} 
    error = {doMyerror(obj); obj = new("parse"); continue} 
  ) 
}