octave-maintainers
[Top][All Lists]
Advanced

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

[changeset] parsing nested functions


From: John W. Eaton
Subject: [changeset] parsing nested functions
Date: Wed, 29 Jul 2009 15:59:32 -0400

On 29-Jul-2009, David Grundberg wrote:

| Hi all,
| 
| I've modified the parser to be able to properly parse nested functions. 
| So now a function body can contain nested functions anywhere, and not 
| just in the beginning. The nested function still work like subfunctions 
| to the primary function though, regardless where they are declared (or 
| in which depth). This changeset adds a warning message if any nested 
| function has been declared. Since they work as subfunctions, I thought 
| it reasonable.
| 
| An error is raised if the functionends are incorrectly balanced. If one 
| function is explicitly ended, so must all the others.
| 
| One mayor syntax change is that eval_string will require all function to 
| be explicitly ended. I removed the condition in the action of 
| function_end that allowed implicit ends (at END_OF_INPUT). Since Matlab 
| do not allow function declarations in eval strings, I think Octave could 
| be stricter.
| 
| The parser now have a special way of parsing function files, and 
| statements are not allowed outside first-level functions.
| 
| As I worked on this, I removed some intelligence from the lexer and 
| moved them into the parser. I also removed the parent_scope property 
| from the symbol table, since I couldn't find it used anywhere else than 
| in the parser.

Thanks for looking at this.  I'd like to apply it, but before I do,
can you look at the following problem?

If I have a file containing

  # This is a doc string

  function fcn ()
    if (nargin == 0)
      sub ();
    else
      print_usage ();
    endif

  function sub ()
    printf ("foobar:sub!\n");

and call it with

  fcn ()

it works, but if I call it with

  fcn (1)

I see

  error: print_usage: `fcn' is not documented

Instead of this message, I expect to get the usual print_usage help
text and the doc string for fcn.  If I change the function file to be


  # This is a doc string

  function fcn ()
    if (nargin == 0)
      sub ();
    else
      print_usage ();
    endif
  end

  function sub ()
    printf ("foobar:sub!\n");
  end

then it works as expected, but I think these two cases should be
equivalent (and need to be, for compatibility with Matlab).

I haven't tried to debug this yet, but it seems that the doc string is
somehow not attached to the main function when the structure is
rearranged when no endfunction tokens are found.  Can you take a look
and see if this is easy to fix?

Thanks,

jwe


reply via email to

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