Re: function grammar

2010-07-20 Thread Linda Walsh



Ken Irving wrote:

So maybe the declaration could be fixed to show that, e.g., as either of:

name () compound-command [redirection]
function name [()] compound-command [redirection]

I can't see how to put that in one construct...

BNF would use:

 'function' NAME  |  NAME '()'  compound-command [redirection]

(ignoring that it would probably also specify SPACE where needed

maybe using bash syntax:

+(function _name_ | _name_ () ) compound-command [redirection]




BUG: grammar handler needs to be fixed to recognize Bash syntax.... (was Re: function grammar)

2010-07-20 Thread Linda Walsh

The following function is legal syntax, but yields an error:

function good_dir [[ -n $1  -d $1  -r $1   -x $1 ]]

bash: syntax error near unexpected token `[['


To which Andreas comments that it's a grammar bug:


Andreas Schwab wrote:

Bernd Eggink mono...@sudrala.de writes:


If the function reserved word is supplied,  the  parentheses  are
optional.


While the grammer has the right rules for this the handling inside of
special_case_tokens isn't right up to it, it only recognizes '{'
following 'function WORD'.

Andreas.





Re: function grammar

2010-07-20 Thread Chet Ramey
 from man bash, to define a function use;
 
 function name compound-command
   OR
 name () compound-command
 
 right?
 
 And Compound Commands are:
 
   ( list)
{ list; )
   (( expression ))
   [[ expression ]]
 ...et al
 
 so why do I get a syntax error for
 
 function good_dir [[ -n $1  -d $1  -r $1   -x $1 ]]
 
 bash: syntax error near unexpected token `[['

Good catch.  This will be fixed in bash-4.2.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/



Re: function grammar

2010-07-20 Thread Chet Ramey
 I see this in bash(1):
 
 SHELL GRAMMAR
 ...
 Shell Function Definitions
 ...
 [ function ] name () compound-command [redirection]
 
 and do not see the version you show without the parens.

Read the text following the definition.  It says, in part:

If  the  function reserved word is supplied, the
parentheses are optional.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/



Re: function grammar

2010-07-20 Thread Chet Ramey
 So maybe the declaration could be fixed to show that, e.g., as either of:
 
 name () compound-command [redirection]
 function name [()] compound-command [redirection]

I think this is a great suggestion.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/



Re: function grammar

2010-07-19 Thread Jan Schampera

Linda Walsh wrote:

The curly brackets are suposed to be optional.
They are line 2 of the Compound commands list below...


Don't ask me why, but it works when you don't use the function 
keyword, but () instead:


foo() [[ 1 ]]

Might be a parsing bug, though you shouldn't use function at all.



Re: function grammar

2010-07-19 Thread Ken Irving
On Sun, Jul 18, 2010 at 11:53:02AM -0700, Linda Walsh wrote:
 
 from man bash, to define a function use;
 
 function name compound-command
  OR
 name () compound-command
 
 right?
 
 And Compound Commands are:
 
  ( list)
   { list; )
  (( expression ))
  [[ expression ]]
 ...et al
 
 so why do I get a syntax error for
 
 function good_dir [[ -n $1  -d $1  -r $1   -x $1 ]]
 
 bash: syntax error near unexpected token `[['

I see this in bash(1):

SHELL GRAMMAR
...
Shell Function Definitions
...
[ function ] name () compound-command [redirection]

and do not see the version you show without the parens.

$ function good_dir() [[ -n $1  -d $1  -r $1   -x $1 ]]
$ good_dir; echo $?
1
$ good_dir /tmp; echo $?
0

Ken




Re: function grammar

2010-07-19 Thread Bernd Eggink

Am 19.07.2010 08:30, schrieb Ken Irving:

On Sun, Jul 18, 2010 at 11:53:02AM -0700, Linda Walsh wrote:


from man bash, to define a function use;

function namecompound-command
  OR
name ()compound-command

right?

And Compound Commands are:

  (list)
   {list; )
  (( expression ))
  [[ expression ]]
...et al

so why do I get a syntax error for

function good_dir [[ -n $1  -d $1  -r $1  -x $1 ]]

bash: syntax error near unexpected token `[['


I see this in bash(1):

 SHELL GRAMMAR
 ...
 Shell Function Definitions
 ...
 [ function ] name () compound-command [redirection]

and do not see the version you show without the parens.


It's there. Look at the 3rd sentence:

If the function reserved word is supplied,  the  parentheses  are 
optional.


Bernd

--
Bernd Eggink
http://sudrala.de



Re: function grammar

2010-07-19 Thread Andreas Schwab
Bernd Eggink mono...@sudrala.de writes:

 If the function reserved word is supplied,  the  parentheses  are
 optional.

While the grammer has the right rules for this the handling inside of
special_case_tokens isn't right up to it, it only recognizes '{'
following 'function WORD'.

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
And now for something completely different.



Re: function grammar

2010-07-19 Thread Ken Irving
On Mon, Jul 19, 2010 at 10:46:30AM +0200, Bernd Eggink wrote:
 Am 19.07.2010 08:30, schrieb Ken Irving:
 On Sun, Jul 18, 2010 at 11:53:02AM -0700, Linda Walsh wrote:
 
 from man bash, to define a function use;
 
 function namecompound-command
   OR
 name ()compound-command
 
 right?
 
 And Compound Commands are:
 
   (list)
{list; )
   (( expression ))
   [[ expression ]]
 ...et al
 
 so why do I get a syntax error for
 
 function good_dir [[ -n $1  -d $1  -r $1  -x $1 ]]
 
 bash: syntax error near unexpected token `[['
 
 I see this in bash(1):
 
  SHELL GRAMMAR
  ...
  Shell Function Definitions
  ...
  [ function ] name () compound-command [redirection]
 
 and do not see the version you show without the parens.
 
 It's there. Look at the 3rd sentence:
 
 If the function reserved word is supplied,  the  parentheses  are
 optional.

So maybe the declaration could be fixed to show that, e.g., as either of:

name () compound-command [redirection]
function name [()] compound-command [redirection]

I can't see how to put that in one construct...

Ken




Re: function grammar

2010-07-18 Thread Clark J. Wang
On Mon, Jul 19, 2010 at 2:53 AM, Linda Walsh b...@tlinx.org wrote:



 from man bash, to define a function use;

 function name compound-command
  OR
 name () compound-command

 right?

 And Compound Commands are:

  ( list)
  { list; )
  (( expression ))
  [[ expression ]]
 ...et al

 so why do I get a syntax error for

 function good_dir [[ -n $1  -d $1  -r $1   -x $1 ]]

 bash: syntax error near unexpected token `[['

 You should enclose the function body code in between `{' and `}':

function good_dir { [[ -n $1  -d $1  -r $1   -x $1 ]]; }


Re: function grammar

2010-07-18 Thread Linda Walsh
The curly brackets are suposed to be optional. 


They are line 2 of the Compound commands list below...

Clark J. Wang wrote:
On Mon, Jul 19, 2010 at 2:53 AM, Linda Walsh b...@tlinx.org 
mailto:b...@tlinx.org wrote:




from man bash, to define a function use;

function name compound-command
 OR
name () compound-command

right?

And Compound Commands are:

 ( list)
 { list; )
 (( expression ))
 [[ expression ]]
...et al

so why do I get a syntax error for

function good_dir [[ -n $1  -d $1  -r $1   -x $1 ]]

bash: syntax error near unexpected token `[['

You should enclose the function body code in between `{' and `}':

function good_dir { [[ -n $1  -d $1  -r $1   -x $1 ]]; }