update .gitignore
[nedit-bw.git] / extend-if-key-in-array-syntax.patch
blob3a9e4a84589aa815a97fdd32dec66d351ff285ec
1 ---
3 doc/help.etx | 11 ++---------
4 source/interpret.c | 41 ++++++++++++++++++++++++++++++++++++++++-
5 source/interpret.h | 1 +
6 source/parse.y | 12 ++++++++++--
7 4 files changed, 53 insertions(+), 12 deletions(-)
9 diff --quilt old/source/interpret.c new/source/interpret.c
10 --- old/source/interpret.c
11 +++ new/source/interpret.c
12 @@ -143,10 +143,11 @@ static int anonArrayIndexVal(void);
13 static int anonArrayClose(void);
14 static int namedArg1(void);
15 static int namedArgN(void);
16 static int namedArg1orN(Boolean isFirst);
17 static int swapTop2(void);
18 +static int arrayIndex(void);
19 static int makeArrayKeyFromArgs(int nArgs, char **keyString, int leaveParams);
20 static void freeSymbolTable(Symbol *symTab);
21 static int errCheck(const char *s);
22 static int execError(const char *s1, const char *s2);
23 static rbTreeNode *arrayEmptyAllocator(void);
24 @@ -241,10 +242,11 @@ static int (*OpFns[N_OPS])() = {returnNo
25 anonArrayOpen, anonArraySkip, anonArrayNextVal, anonArrayIndexVal,
26 anonArrayClose, namedArg1, namedArgN, swapTop2,
27 callSubroutineStackedN,
28 unpackArrayToArgs,
29 typeOfIn, typeOfOut,
30 + arrayIndex,
33 /* Stack-> symN-sym0(FP), nArgs, oldFP, retPC, argArray, argN-arg1, next, ... */
34 #define FP_ARG_COUNT_INDEX (-1)
35 #define FP_FUNCTION_NAME (-2) /* !! */
36 @@ -1760,10 +1762,45 @@ static int assign(void)
38 return STAT_OK;
42 +**
43 +** Before: Prog-> [nDim], next, ...
44 +** TheStack-> [indnDim, ... ind1], next, ...
45 +** After: Prog-> nDim, [next], ...
46 +** TheStack-> kayValue, next, ...
47 +*/
48 +static int arrayIndex(void)
50 + int errNum;
51 + char *keyString = NULL;
52 + DataValue keyData;
53 + int nDim;
55 + nDim = PC->value;
56 + PC++;
58 + DISASM_RT(PC-2, 2);
59 + STACKDUMP(nDim+3, 3);
61 + /* the next nDim stack entries form the index */
62 + errNum = makeArrayKeyFromArgs(nDim, &keyString, False);
63 + if (errNum != STAT_OK) {
64 + return errNum;
65 + }
67 + keyData.tag = STRING_TAG;
68 + keyData.val.str.rep = keyString;
69 + keyData.val.str.len = strlen(keyString);
71 + PUSH(keyData)
73 + return STAT_OK;
76 +/*
77 ** copy the top value of the stack
78 ** Before: TheStack-> value, next, ...
79 ** After: TheStack-> value, value, next, ...
81 static int dupStack(void)
82 @@ -3770,10 +3807,11 @@ static void disasmInternal(Inst *inst, i
83 "SWAP_TOP2", /* swapTop2: cf namedArgN */
84 "SUBR_CALL_STACKED_N", /* callSubroutineStackedN */
85 "UNPACKTOARGS", /* unpackArrayToArgs */
86 "TYPEOF_IN", /* typeOfIn */
87 "TYPEOF_OUT", /* typeOfOut */
88 + "ARRAY_INDEX", /* arrayIndex */
90 int i, j;
91 static size_t opLen;
93 if (!opLen) {
94 @@ -3839,11 +3877,12 @@ static void disasmInternal(Inst *inst, i
95 else if (j == OP_ARRAY_REF ||
96 j == OP_ARRAY_DELETE ||
97 j == OP_ARRAY_ASSIGN ||
98 j == OP_ANONARRAY_INDEX_VAL ||
99 j == OP_NAMED_ARG1 ||
100 - j == OP_NAMED_ARGN) {
101 + j == OP_NAMED_ARGN ||
102 + j == OP_ARRAY_INDEX) {
103 printd(" nDim=%d", inst[i+1].value);
104 ++i;
106 else if (j == OP_ARRAY_REF_ASSIGN_SETUP) {
107 printd(" binOp=%s nDim=%d",
108 diff --quilt old/source/interpret.h new/source/interpret.h
109 --- old/source/interpret.h
110 +++ new/source/interpret.h
111 @@ -53,10 +53,11 @@ enum operations {OP_RETURN_NO_VAL, OP_RE
112 OP_ANONARRAY_INDEX_VAL, OP_ANONARRAY_CLOSE,
113 OP_NAMED_ARG1, OP_NAMED_ARGN, OP_SWAP_TOP2,
114 OP_SUBR_CALL_STACKED_N,
115 OP_UNPACKTOARGS,
116 OP_TYPEOF_IN, OP_TYPEOF_OUT,
117 + OP_ARRAY_INDEX,
118 N_OPS};
120 enum typeTags {NO_TAG, INT_TAG, STRING_TAG, ARRAY_TAG};
122 enum execReturnCodes {MACRO_TIME_LIMIT, MACRO_PREEMPT, MACRO_DONE, MACRO_ERROR};
123 diff --quilt old/source/parse.y new/source/parse.y
124 --- old/source/parse.y
125 +++ new/source/parse.y
126 @@ -467,18 +467,26 @@ numexpr: '(' blank expr blank ')'
128 | SYMBOL incrdecr %prec INCR {
129 ADD_OP(OP_PUSH_SYM); ADD_SYM($1); ADD_OP(OP_DUP);
130 ADD_OP($2); ADD_OP(OP_ASSIGN); ADD_SYM($1);
132 - | numexpr IN blank numexpr {
133 + | keyinexpr IN blank numexpr {
134 ADD_OP(OP_IN_ARRAY);
136 - | numexpr NOT IN blank numexpr %prec IN {
137 + | keyinexpr NOT IN blank numexpr %prec IN {
138 ADD_OP(OP_IN_ARRAY);
139 ADD_OP(OP_NOT);
142 +keyinexpr: numexpr
143 + | blank '[' arglist ']' blank {
144 + /* build the index from arglist and push to stack */
145 + ADD_OP(OP_ARRAY_INDEX);
146 + ADD_IMMED($3);
150 while: WHILE blank {
151 $$ = GetPC(); StartLoopAddrList();
154 do: DO blank {
155 diff --quilt old/doc/help.etx new/doc/help.etx
156 --- old/doc/help.etx
157 +++ new/doc/help.etx
158 @@ -2326,22 +2326,15 @@ Macro Language
159 $sub_sep as the separator.
161 You can also check for the existence of multi-dimensional array by
162 looking for $sub_sep in the key.
164 - Last, you need $sub_sep if you want to use the 'in' keyword.
165 + If you want to use the 'in' keyword, use this syntax:
167 - if ((1,2) in myArray)
168 + if ([1,2] in myArray)
169 {..}
171 - doesn't work, but
173 - if (("1" $sub_sep "2") in myArray)
174 - {..}
176 - does work.
178 Note that if an array contains a value that is itself an array, you can
179 apply the index operator more than once. For example
181 subarray["a"] = "value"
182 mainarray[1] = subarray