From 1c41f98aabc20fce8a1eb8fd7d1b6baabfa1dea5 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 20 Jan 2016 11:22:09 +0000 Subject: 37705: don't turn - to Dash after start of brace parameter --- Src/lex.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'Src/lex.c') diff --git a/Src/lex.c b/Src/lex.c index 3ea878c7b..23b0a1cd9 100644 --- a/Src/lex.c +++ b/Src/lex.c @@ -1026,8 +1026,10 @@ gettokstr(int c, int sub) c = Inbrace; ++bct; cmdpush(CS_BRACEPAR); - if (!in_brace_param) - in_brace_param = bct; + if (!in_brace_param) { + if ((in_brace_param = bct)) + seen_brct = 0; + } } else { hungetc(e); lexstop = 0; -- cgit v1.2.3 From bced1beb8cc530ea28aa994808707043dd156fb8 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 20 Jan 2016 07:47:53 +0000 Subject: 37700: Teach ${(z)} the 'repeat WORD SUBLIST' syntax. --- ChangeLog | 4 ++++ Src/lex.c | 9 +++++++-- Src/parse.c | 10 ++++++++++ Src/zsh.h | 1 + Test/D04parameter.ztst | 16 ++++++++++++++++ 5 files changed, 38 insertions(+), 2 deletions(-) (limited to 'Src/lex.c') diff --git a/ChangeLog b/ChangeLog index eaf8f838c..b843f5d71 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2016-01-29 Daniel Shahaf + * 37700: Src/lex.c, Src/parse.c, Src/zsh.h, + Test/D04parameter.ztst: Teach ${(z)} the 'repeat WORD SUBLIST' + syntax. + * unposted: Completion/Unix/Command/_init_d: _init_d: Report failure to caller. diff --git a/Src/lex.c b/Src/lex.c index 23b0a1cd9..d4132fe76 100644 --- a/Src/lex.c +++ b/Src/lex.c @@ -267,9 +267,13 @@ zshlex(void) { if (tok == LEXERR) return; - do + do { + if (inrepeat_) + ++inrepeat_; + if (inrepeat_ == 3 && isset(SHORTLOOPS)) + incmdpos = 1; tok = gettok(); - while (tok != ENDINPUT && exalias()); + } while (tok != ENDINPUT && exalias()); nocorrect &= 1; if (tok == NEWLIN || tok == ENDINPUT) { while (hdocs) { @@ -1899,6 +1903,7 @@ exalias(void) zshlextext[0] == '}' && !zshlextext[1])) && (rw = (Reswd) reswdtab->getnode(reswdtab, zshlextext))) { tok = rw->token; + inrepeat_ = (tok == REPEAT); if (tok == DINBRACK) incond = 1; } else if (incond && !strcmp(zshlextext, "]]")) { diff --git a/Src/parse.c b/Src/parse.c index 4829e3a6d..628a9aa2d 100644 --- a/Src/parse.c +++ b/Src/parse.c @@ -63,6 +63,12 @@ int isnewlin; /**/ int infor; +/* != 0 if we are after a repeat keyword; if it's nonzero it's a 1-based index + * of the current token from the last-seen command position */ + +/**/ +int inrepeat_; /* trailing underscore because of name clash with Zle/zle_vi.c */ + /* != 0 if parsing arguments of typeset etc. */ /**/ @@ -271,6 +277,7 @@ parse_context_save(struct parse_stack *ps, int toplevel) ps->incasepat = incasepat; ps->isnewlin = isnewlin; ps->infor = infor; + ps->inrepeat_ = inrepeat_; ps->intypeset = intypeset; ps->hdocs = hdocs; @@ -305,6 +312,7 @@ parse_context_restore(const struct parse_stack *ps, int toplevel) incasepat = ps->incasepat; isnewlin = ps->isnewlin; infor = ps->infor; + inrepeat_ = ps->inrepeat_; intypeset = ps->intypeset; hdocs = ps->hdocs; @@ -447,6 +455,7 @@ init_parse_status(void) * using the lexical analyser for strings as well as here. */ incasepat = incond = inredir = infor = intypeset = 0; + inrepeat_ = 0; incmdpos = 1; } @@ -1482,6 +1491,7 @@ par_while(int *cmplx) static void par_repeat(int *cmplx) { + /* ### what to do about inrepeat_ here? */ int oecused = ecused, p; p = ecadd(0); diff --git a/Src/zsh.h b/Src/zsh.h index b83b8bdbb..eee31dad1 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -2921,6 +2921,7 @@ struct parse_stack { int incasepat; int isnewlin; int infor; + int inrepeat_; int intypeset; int eclen, ecused, ecnpats; diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst index a6817fe22..458c5bbe1 100644 --- a/Test/D04parameter.ztst +++ b/Test/D04parameter.ztst @@ -479,6 +479,8 @@ '(( 3 + 1 == 8 / 2 ))' 'for (( i = 1 ; i < 10 ; i++ ))' '((0.25542 * 60) - 15)*60' + 'repeat 3 (x)' + 'repeat 3 (echo foo; echo bar)' ) for string in $strings; do array=(${(z)string}) @@ -514,6 +516,20 @@ >8:15: >9:): >10:*60: +>1:repeat: +>2:3: +>3:(: +>4:x: +>5:): +>1:repeat: +>2:3: +>3:(: +>4:echo: +>5:foo: +>6:;: +>7:echo: +>8:bar: +>9:): line=$'A line with # someone\'s comment\nanother line # (1 more\nanother one' -- cgit v1.2.3 From b9113980642f37d780d646fcbf4ef90dca69ae3f Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Thu, 7 Apr 2016 20:24:43 -0700 Subject: 38248: fix word position calculation when completing on or just before a redirection operator The completion result is still in need of some repair; e.g., if the first thing on the line is the redirection, completion before it is not taken to be in command position, and in this and other cases a necessary space is not inserted between the completed word and the redirection. --- ChangeLog | 6 ++++++ Src/Zle/zle_tricky.c | 15 +++++++++++++++ Src/lex.c | 10 +++++++--- 3 files changed, 28 insertions(+), 3 deletions(-) (limited to 'Src/lex.c') diff --git a/ChangeLog b/ChangeLog index 7aca23750..b6fb070ca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2016-04-07 Barton E. Schaefer + + * 38248: Src/Zle/zle_tricky.c: fix word position calculation + when completing on or just before a redirection operator; the + completion result is still in need of some repair + 2016-04-03 Barton E. Schaefer * 38229: Src/Zle/zle_tricky.c: fix cursor placement calculation diff --git a/Src/Zle/zle_tricky.c b/Src/Zle/zle_tricky.c index b1709c117..1d4e1d284 100644 --- a/Src/Zle/zle_tricky.c +++ b/Src/Zle/zle_tricky.c @@ -1161,6 +1161,7 @@ get_comp_string(void) inpush(dupstrspace(linptr), 0, NULL); strinbeg(0); wordpos = cp = rd = ins = oins = linarr = parct = ia = redirpos = 0; + we = wb = zlemetacs; tt0 = NULLTOK; /* This loop is possibly the wrong way to do this. It goes through * @@ -1238,6 +1239,20 @@ get_comp_string(void) /* Record if we haven't had the command word yet */ if (wordpos == redirpos) redirpos++; + if (zlemetacs < (zlemetall - inbufct) && + zlemetacs >= wordbeg && wb == we) { + /* Cursor is in the middle of a redirection, treat as a word */ + we = zlemetall - (inbufct + addedx); + if (addedx && we > wb) { + /* Assume we are in {param}> form, wb points at "{" */ + wb++; + /* Should complete parameter names here */ + } else { + /* In "2>" form, zlemetacs points at "2" */ + wb = zlemetacs; + /* Should insert a space under cursor here */ + } + } } if (tok == DINPAR) tokstr = NULL; diff --git a/Src/lex.c b/Src/lex.c index d4132fe76..25b372a3c 100644 --- a/Src/lex.c +++ b/Src/lex.c @@ -1789,9 +1789,13 @@ parse_subst_string(char *s) static void gotword(void) { - we = zlemetall + 1 - inbufct + (addedx == 2 ? 1 : 0); - if (zlemetacs <= we) { - wb = zlemetall - wordbeg + addedx; + int nwe = zlemetall + 1 - inbufct + (addedx == 2 ? 1 : 0); + if (zlemetacs <= nwe) { + int nwb = zlemetall - wordbeg + addedx; + if (zlemetacs >= nwb) { + wb = nwb; + we = nwe; + } lexflags = 0; } } -- cgit v1.2.3 From c712e7511a6b450e6833aead65ef8b8c0bc70ff1 Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Tue, 10 May 2016 23:17:19 -0700 Subject: 38468: wb,we values in gotword() needed assignment in additional case to avoid core dump Bug introduced by 38248. Also fix ChangeLog entry for 38248 to correctly reference Src/lex.c --- ChangeLog | 9 ++++++--- Src/lex.c | 4 ++++ 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'Src/lex.c') diff --git a/ChangeLog b/ChangeLog index 4c10e772a..048b355b8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2016-05-10 Barton E. Schaefer + * 38468: Src/lex.c: wb,we values in gotword() needed assignment in + additional case to avoid core dump (bug introduced by 38248) + * 38463: Src/Zle/zle_keymap.c: use immortal widgets in .safe keymap 2016-05-10 Daniel Shahaf @@ -200,9 +203,9 @@ 2016-04-07 Barton E. Schaefer - * 38248: Src/Zle/zle_tricky.c: fix word position calculation - when completing on or just before a redirection operator; the - completion result is still in need of some repair + * 38248: Src/lex.c, Src/Zle/zle_tricky.c: fix word position + calculation when completing on or just before a redirection + operator; the completion result is still in need of some repair 2016-04-03 Barton E. Schaefer diff --git a/Src/lex.c b/Src/lex.c index 25b372a3c..e36a01ec8 100644 --- a/Src/lex.c +++ b/Src/lex.c @@ -1795,6 +1795,10 @@ gotword(void) if (zlemetacs >= nwb) { wb = nwb; we = nwe; + } else { + wb = zlemetacs + addedx; + if (we < wb) + we = wb; } lexflags = 0; } -- cgit v1.2.3 From 954cdd77d77136e572fc4896f3c0ba16f5c933ec Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 22 Jun 2016 13:10:22 +0100 Subject: 38746: Fix suffix alias expansion recursion. This was problematic if the expansion landed you back in command position. Delay marking the alias as out of use until the text that caused the expansion is finished. --- ChangeLog | 5 +++++ Src/lex.c | 7 ++++--- Test/A02alias.ztst | 6 ++++++ 3 files changed, 15 insertions(+), 3 deletions(-) (limited to 'Src/lex.c') diff --git a/ChangeLog b/ChangeLog index d352067e7..146f7b882 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-06-22 Peter Stephenson + + * 38746: Src/lex.c, Test/A02alias.ztst: Delay marking + a suffix alias as free until the last minute. + 2016-06-22 Oliver Kiddle * 38714: Src/Zle/complete.c, Doc/Zsh/compsys.yo, diff --git a/Src/lex.c b/Src/lex.c index e36a01ec8..5ad3474fe 100644 --- a/Src/lex.c +++ b/Src/lex.c @@ -1842,10 +1842,11 @@ checkalias(void) if ((suf = strrchr(zshlextext, '.')) && suf[1] && suf > zshlextext && suf[-1] != Meta && (an = (Alias)sufaliastab->getnode(sufaliastab, suf+1)) && - !an->inuse && incmdpos) { - inpush(dupstring(zshlextext), INP_ALIAS, NULL); + !an->inuse && incmdpos && + !(inbufflags & INP_ALSUFF)) { + inpush(dupstring(zshlextext), INP_ALIAS, an); inpush(" ", INP_ALIAS, NULL); - inpush(an->text, INP_ALIAS, an); + inpush(an->text, INP_ALIAS, NULL); lexstop = 0; return 1; } diff --git a/Test/A02alias.ztst b/Test/A02alias.ztst index 49e47567c..1e09cd3f1 100644 --- a/Test/A02alias.ztst +++ b/Test/A02alias.ztst @@ -104,3 +104,9 @@ >0 ?(eval):2: invalid alias 'x=y' encountered while printing aliases # Currently, 'alias -L' returns 0 in this case. Perhaps it should return 1. + + alias -s mysuff='print -r "You said it.";' + eval 'thingummy.mysuff' +127:No endless loop with suffix alias in command position +>You said it. +?(eval):1: command not found: thingummy.mysuff -- cgit v1.2.3 From 7ae2deb4378d50d81774e73c2574375a0f934797 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 22 Jun 2016 14:03:38 +0100 Subject: unposted: remove flag unneded from previous fix --- ChangeLog | 3 +++ Src/lex.c | 3 +-- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'Src/lex.c') diff --git a/ChangeLog b/ChangeLog index 146f7b882..a3b91cf4b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2016-06-22 Peter Stephenson + * unposted: Src/lex.c: remove unused and no longer defined flag + from experiments for previous fix. + * 38746: Src/lex.c, Test/A02alias.ztst: Delay marking a suffix alias as free until the last minute. diff --git a/Src/lex.c b/Src/lex.c index 5ad3474fe..6b20e14b5 100644 --- a/Src/lex.c +++ b/Src/lex.c @@ -1842,8 +1842,7 @@ checkalias(void) if ((suf = strrchr(zshlextext, '.')) && suf[1] && suf > zshlextext && suf[-1] != Meta && (an = (Alias)sufaliastab->getnode(sufaliastab, suf+1)) && - !an->inuse && incmdpos && - !(inbufflags & INP_ALSUFF)) { + !an->inuse && incmdpos) { inpush(dupstring(zshlextext), INP_ALIAS, an); inpush(" ", INP_ALIAS, NULL); inpush(an->text, INP_ALIAS, NULL); -- cgit v1.2.3 From ef862262e72c51621aa4d9400a2395fdc4f2324f Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 7 Sep 2016 18:51:01 +0100 Subject: 39185: Only set word begin for completion word if not alias. This is consistent with other ZLE code in lex.c and fixes a crash in some completions involving aliases, e.g. if uncompleted quotes. --- ChangeLog | 5 +++++ Src/lex.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'Src/lex.c') diff --git a/ChangeLog b/ChangeLog index cb7405a85..c7c863c96 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-09-07 Peter Stephenson + + * 39185: Src/lex.c: wordbeg only set for ZLE if not alias. + Fixes crash on completion in some obscure alias expansions. + 2016-09-07 Peter Stephenson * Matthew Martin: 39221: Completion/Unix/Command/_rm: update for diff --git a/Src/lex.c b/Src/lex.c index 6b20e14b5..e0935bf05 100644 --- a/Src/lex.c +++ b/Src/lex.c @@ -613,7 +613,7 @@ gettok(void) if (lexstop) return (errflag) ? LEXERR : ENDINPUT; isfirstln = 0; - if ((lexflags & LEXFLAGS_ZLE)) + if ((lexflags & LEXFLAGS_ZLE) && !(inbufflags & INP_ALIAS)) wordbeg = inbufct - (qbang && c == bangchar); hwbegin(-1-(qbang && c == bangchar)); /* word includes the last character read and possibly \ before ! */ -- cgit v1.2.3 From 4073a6655cafc78728cb126cfe44e89cc7ba720a Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Thu, 3 Nov 2016 10:30:00 +0000 Subject: 39815: Read input to end on parse error in $(...) inside a string. This allows ${(z)} to output the whole string, although we can't do word splitting from the error onwards. --- ChangeLog | 5 +++++ Src/lex.c | 13 +++++++++++-- Test/D04parameter.ztst | 8 ++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) (limited to 'Src/lex.c') diff --git a/ChangeLog b/ChangeLog index a5ac3713e..3ed655135 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-11-03 Peter Stephenson + + * 39815: Src/lex.c, Test/D04parameter.ztst: read input to end + on parse error in $(...) inside a string. + 2016-11-02 Barton E. Schaefer * 39811: Src/Zle/zle_vi.c: vi-repeat-change must not be the diff --git a/Src/lex.c b/Src/lex.c index e0935bf05..889612825 100644 --- a/Src/lex.c +++ b/Src/lex.c @@ -2138,8 +2138,17 @@ skipcomm(void) lexflags &= ~LEXFLAGS_ZLE; dbparens = 0; /* restored by zcontext_restore_partial() */ - if (!parse_event(OUTPAR) || tok != OUTPAR) - lexstop = 1; + if (!parse_event(OUTPAR) || tok != OUTPAR) { + if (strin) { + /* + * Get the rest of the string raw since we don't + * know where this token ends. + */ + while (!lexstop) + (void)ingetc(); + } else + lexstop = 1; + } /* Outpar lexical token gets added in caller if present */ /* diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst index 762305197..97c8ba3fc 100644 --- a/Test/D04parameter.ztst +++ b/Test/D04parameter.ztst @@ -631,6 +631,14 @@ >; >(( echo 42 + # From parse error on it's not possible to split. + # Just check we get the complete string. + foo='echo $(|||) bar' + print -rl ${(z)foo} +0:$($(z)} with parse error in command substitution. +>echo +>$(|||) bar + psvar=(dog) setopt promptsubst foo='It shouldn'\''t $(happen) to a %1v.' -- cgit v1.2.3