zsh-workers
 help / color / mirror / code / Atom feed
* SH_GLOB influence on a script and on an autoload function
@ 2016-06-11  5:11 Sebastian Gniazdowski
  2016-06-11 17:14 ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Sebastian Gniazdowski @ 2016-06-11  5:11 UTC (permalink / raw)
  To: Zsh hackers list

Hello
Below is a simple script (save to file rtest1) that works well despite
SH_GLOB should or could stop the pattern from parsing. The same
doesn't work for autoload. If one does:

setopt shglob
FPATH=$FPATH:`pwd`
autoload rtest1
rtest1

then error occurs:

rtest1:8: parse error near `('

Why does this happen? Probably no workaround for this?

Best regards,
Sebastian Gniazdowski

================================

#!/usr/local/bin/zsh-5.2-dev-1 --shglob

emulate -LR zsh
setopt extendedglob

tmp="something txt=1234 something"

if [[ "$tmp" = *txt=(#b)([0-9]##)(|[[:blank:]]*) ]]; then
    echo "Matched, match is: $match[1]"
else
    echo "No match"
fi


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: SH_GLOB influence on a script and on an autoload function
  2016-06-11  5:11 SH_GLOB influence on a script and on an autoload function Sebastian Gniazdowski
@ 2016-06-11 17:14 ` Bart Schaefer
  2016-09-07 10:39   ` Sebastian Gniazdowski
  0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2016-06-11 17:14 UTC (permalink / raw)
  To: Zsh hackers list

On Jun 11,  7:11am, Sebastian Gniazdowski wrote:
}
} Below is a simple script (save to file rtest1) that works well despite
} SH_GLOB should or could stop the pattern from parsing. The same
} doesn't work for autoload.

A script is executed line by line as it is parsed.  An autoloaded function
is fully parsed first, then executed.  Hence in the script, the "emulate"
command resets the parsing rules before the expression is encountered.

This is one of the drawbacks to attempting to accurately emulate parsing
rules that are inherently contradictory.

} setopt shglob
} FPATH=$FPATH:`pwd`
} autoload rtest1
} rtest1
} 
} Probably no workaround for this?

In "recent" zsh (since roughly 2009) you can do this:

    emulate zsh -c 'autoload rtest1'

but of course you have to know a priori what emulation mode the function
is going to want.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: SH_GLOB influence on a script and on an autoload function
  2016-06-11 17:14 ` Bart Schaefer
@ 2016-09-07 10:39   ` Sebastian Gniazdowski
  2016-09-07 18:28     ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Sebastian Gniazdowski @ 2016-09-07 10:39 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 543 bytes --]

On 11 June 2016 at 19:14, Bart Schaefer <schaefer@brasslantern.com> wrote:

> This is one of the drawbacks to attempting to accurately emulate parsing
> rules that are inherently contradictory.


It seems that pat="<full-featured zsh pattern here>" and then using
GLOB_SUBST via $~pat with SH_GLOB temporarily turned off should solve this?
But what about (N[1]) etc. modifiers... I'm thinking about a far away
possibility that one could fully work with emulate sh, having completions
not reporting errors.

Best regards,
Sebastian Gniazdowski

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: SH_GLOB influence on a script and on an autoload function
  2016-09-07 10:39   ` Sebastian Gniazdowski
@ 2016-09-07 18:28     ` Bart Schaefer
  2016-09-07 19:01       ` Sebastian Gniazdowski
  0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2016-09-07 18:28 UTC (permalink / raw)
  To: Zsh hackers list

On Sep 7, 12:39pm, Sebastian Gniazdowski wrote:
}
} It seems that pat="<full-featured zsh pattern here>" and then using
} GLOB_SUBST via $~pat with SH_GLOB temporarily turned off should solve this?
} But what about (N[1]) etc. modifiers...

If SH_GLOB is turned off, glob qualifiers are handled like any other
part of the pattern, so no difference here.

I'm thinking about a far away
} possibility that one could fully work with emulate sh, having completions
} not reporting errors.

I've lost track of this thread.  What present error is being addressed?
Seems to me that completion uses zsh syntax internally, so you'd be more
likely to have an error in the other direction, i.e., the command line
expects SH_GLOB but the internals treat it like zsh ...?


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: SH_GLOB influence on a script and on an autoload function
  2016-09-07 18:28     ` Bart Schaefer
@ 2016-09-07 19:01       ` Sebastian Gniazdowski
  2016-09-07 23:48         ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Sebastian Gniazdowski @ 2016-09-07 19:01 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 1721 bytes --]

On 7 September 2016 at 20:28, Bart Schaefer <schaefer@brasslantern.com>
wrote:

> On Sep 7, 12:39pm, Sebastian Gniazdowski wrote:
> I'm thinking about a far away
> } possibility that one could fully work with emulate sh, having completions
> } not reporting errors.
>
> I've lost track of this thread.  What present error is being addressed?
> Seems to me that completion uses zsh syntax internally, so you'd be more
> likely to have an error in the other direction, i.e., the command line
> expects SH_GLOB but the internals treat it like zsh ...?
>

I sometimes think about making emulate sh a possible interactive setting.
Let it just be that one would be able to temporarily switch to sh to check
something and then switch back. Currently there are errors reported:

# zsh -f
% autoload compinit
% compinit
% cd<Tab>
Applications/                      PRINT/
Save/                              github/                            test/
...
<Ctrl-C>
% emulate sh
% cd<Tab>
_cd:63: bad math expression: operator expected at `tmpcdpath '
_description:63: bad math expression: operator expected at `comp_ignor...'
_next_label:63: bad math expression: operator expected at `funcstack ...'
_description:63: bad math expression: operator expected at `comp_ignor...'
_path_files:63: bad math expression: operator expected at `pfx '
_path_files:63: bad math expression: operator expected at `prepaths '
_path_files:63: bad math expression: operator expected at `ignore '
_path_files:63: bad math expression: operator expected at `ignore'
_main_complete:332: bad math expression: operator expected at `lastdescr'
_main_complete:372: bad math expression: operator expected at
`comp_color...'

Best regards,
Sebastian Gniazdowski

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: SH_GLOB influence on a script and on an autoload function
  2016-09-07 19:01       ` Sebastian Gniazdowski
@ 2016-09-07 23:48         ` Bart Schaefer
  0 siblings, 0 replies; 6+ messages in thread
From: Bart Schaefer @ 2016-09-07 23:48 UTC (permalink / raw)
  To: Zsh hackers list

On Sep 7,  9:01pm, Sebastian Gniazdowski wrote:
}
} I sometimes think about making emulate sh a possible interactive setting.
} Let it just be that one would be able to temporarily switch to sh to check
} something and then switch back. Currently there are errors reported

Oh.  Try this:

    emulate zsh -c 'autoload compinit'

This makes zsh emulation "sticky" for all of the completion functions,
and all the functions loaded from the completion functions, etc., etc.,
which assures those functions are parsed in zsh native mode no matter
what setopts may end up in effect during their execution.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-09-07 23:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-11  5:11 SH_GLOB influence on a script and on an autoload function Sebastian Gniazdowski
2016-06-11 17:14 ` Bart Schaefer
2016-09-07 10:39   ` Sebastian Gniazdowski
2016-09-07 18:28     ` Bart Schaefer
2016-09-07 19:01       ` Sebastian Gniazdowski
2016-09-07 23:48         ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).