octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: More GUI talk...


From: Søren Hauberg
Subject: Re: More GUI talk...
Date: Sun, 30 Mar 2008 20:16:12 +0200

søn, 30 03 2008 kl. 18:50 +0200, skrev Søren Hauberg:
> søn, 30 03 2008 kl. 10:34 -0400, skrev John W. Eaton:
> > The problem with this method is that it fails for partial statements.
> > You won't be able to write
> > 
> >   if (some_condition) RET
> >     do_something (); RET
> >   endif
> > 
> > in your GUI input box.
> 
> Would it be possible to have a function:
> 
>   bool eval_line (std::string line)
> 
> that parsed 'line'. If 'line' is fully parsed such that the actual
> computations begins, the function returns 'true'. If instead 'line' is
> not fully parsed (such as in your example above) it is saved, and the
> function returns 'false'. Wouldn't that make it possible to work with
> partial statements?
To see if the above was in anyway sensible I implemented the following
hack (I've simplified the function a bit, but it should illustrate what
it does):

bool GUI_input::eval_line (std::string cmd)
{
  const int len = cmd.length ();
  if (cmd[len-1] == '\\')
    {
      eval_buffer += std::string(" ") + cmd.substr(0, len-2);
      return false;
    }
  else
    eval_buffer += cmd;

  int parse_status;
  eval_string(eval_buffer, false, parse_status);
  return true;
}

It basically checks if the last character of a command is '\'. If it is
the command is buffered. If it is not the command is buffered, and the
entire buffer is evaluated. This allows the following kind of partial
statements:
  
  if (true) \
    disp("Hello, World"); \
  endif

Of course, the check for '\' is way too simple, but I think it
illustrates the this idea might work.

Søren




reply via email to

[Prev in Thread] Current Thread [Next in Thread]