diff options
author | Peter Stephenson <pws@zsh.org> | 2015-06-18 14:54:41 +0100 |
---|---|---|
committer | Peter Stephenson <pws@zsh.org> | 2015-06-24 10:21:12 +0100 |
commit | 39b28980f38e83e15cdeb19a489b5659af97fe93 (patch) | |
tree | e68f09fc59fc7008ff732704cbabed7e3df5f188 /Src/text.c | |
parent | a68d22eb00ea5c85422d70d1be7efa42acfda739 (diff) | |
download | zsh-39b28980f38e83e15cdeb19a489b5659af97fe93.tar.gz zsh-39b28980f38e83e15cdeb19a489b5659af97fe93.tar.xz zsh-39b28980f38e83e15cdeb19a489b5659af97fe93.zip |
various posts: Implement assignment parsing for typeset.
Typeset assignments now work like raw assignments except for no "+=" and no GLOB_ASSIGN. Documented in typeset builtin doc and mentioned in release notes. Tests to ensure basic sanity. Enabled by default, can be turned off by "disable -r" with typeset family of commands.
Diffstat (limited to 'Src/text.c')
-rw-r--r-- | Src/text.c | 57 |
1 files changed, 46 insertions, 11 deletions
diff --git a/Src/text.c b/Src/text.c index 850879699..a72ab33e6 100644 --- a/Src/text.c +++ b/Src/text.c @@ -155,6 +155,46 @@ taddlist(Estate state, int num) } } +/* add an assignment */ + +static void +taddassign(wordcode code, Estate state, int typeset) +{ + /* name */ + taddstr(ecgetstr(state, EC_NODUP, NULL)); + /* value... maybe */ + if (WC_ASSIGN_TYPE2(code) == WC_ASSIGN_INC) { + if (typeset) { + /* dummy assignment --- just var name */ + (void)ecgetstr(state, EC_NODUP, NULL); + taddchr(' '); + return; + } + taddchr('+'); + } + taddchr('='); + if (WC_ASSIGN_TYPE(code) == WC_ASSIGN_ARRAY) { + taddchr('('); + taddlist(state, WC_ASSIGN_NUM(code)); + taddstr(") "); + } else { + taddstr(ecgetstr(state, EC_NODUP, NULL)); + taddchr(' '); + } +} + +/* add a number of assignments from typeset */ + +/**/ +static void +taddassignlist(Estate state, wordcode count) +{ + while (count--) { + wordcode code = *state->pc++; + taddassign(code, state, 1); + } +} + /* add a newline, or something equivalent, to the text buffer */ /**/ @@ -439,22 +479,17 @@ gettext2(Estate state) } break; case WC_ASSIGN: - taddstr(ecgetstr(state, EC_NODUP, NULL)); - if (WC_ASSIGN_TYPE2(code) == WC_ASSIGN_INC) taddchr('+'); - taddchr('='); - if (WC_ASSIGN_TYPE(code) == WC_ASSIGN_ARRAY) { - taddchr('('); - taddlist(state, WC_ASSIGN_NUM(code)); - taddstr(") "); - } else { - taddstr(ecgetstr(state, EC_NODUP, NULL)); - taddchr(' '); - } + taddassign(code, state, 0); break; case WC_SIMPLE: taddlist(state, WC_SIMPLE_ARGC(code)); stack = 1; break; + case WC_TYPESET: + taddlist(state, WC_TYPESET_ARGC(code)); + taddassignlist(state, *state->pc++); + stack = 1; + break; case WC_SUBSH: if (!s) { taddstr("("); |