Skip to content

Commit 1bbeae0

Browse files
author
aafent
committed
SCLEAN now is part of Collections Interface
1 parent bdfaa7f commit 1bbeae0

File tree

5 files changed

+63
-34
lines changed

5 files changed

+63
-34
lines changed

FAST.FBasicInterpreter/Core/FBasicArray.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,12 @@ public void Reset()
314314
this.currentRow=0;
315315
}
316316

317+
public void ClearCollection()
318+
{
319+
Reset();
320+
ResetArray();
321+
}
322+
317323

318324
#endregion (+) IFBasicCollection Interface
319325
}

FAST.FBasicInterpreter/DataProviders/dataReaderCollection.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,9 @@ private static bool isNumericType(Type type)
140140
}
141141
}
142142

143+
public void ClearCollection()
144+
{
145+
Reset();
146+
}
143147
}
144148
}

FAST.FBasicInterpreter/DataProviders/staticDataCollection.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,11 @@ public void Reset()
6565
{
6666
index= indexInitialValue;
6767
}
68+
69+
public void ClearCollection()
70+
{
71+
Reset();
72+
data.Clear();
73+
}
6874
}
6975
}

FAST.FBasicInterpreter/Interfaces/IfbasicCollection.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,11 @@ public interface IBasicCollection : IEnumerator
1919
/// <returns>The Value</returns>
2020
Value getValue(string name);
2121

22+
/// <summary>
23+
/// This method used to clear (empty) the collection
24+
/// It is not the same with the Reset() from IEnumerator that it is used to jump to the first of the items.
25+
/// </summary>
26+
void ClearCollection();
27+
2228
}
2329
}

FAST.FBasicInterpreter/Libraries/BuiltInsForCollections.cs

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ public void InstallAll(Interpreter interpreter)
1414
interpreter.AddStatement("SSET", SSET);
1515
interpreter.AddStatement("SCLEAR", SCLEAR);
1616
}
17-
17+
18+
#region (+) Statements & Functions for both Collections and Arrays
19+
1820
private static Value EOD(Interpreter interpreter, List<Value> args)
1921
{
2022
if (args.Count != 1) throw new ArgumentException();
@@ -61,32 +63,62 @@ private static void RESET(Interpreter interpreter)
6163
collection.endOfData=false;
6264
}
6365

66+
private static void SCLEAR(Interpreter interpreter)
67+
{
68+
// Syntax: SCLEAR collection
69+
// Used to RESET and then to CLEAR a collection
70+
//
71+
interpreter.Match(Token.Identifier);
72+
string collectionName = interpreter.lex.Identifier;
73+
74+
interpreter.SetLastTokenToNewLine();
75+
76+
// (v) implementation
77+
if (!interpreter.IsCollectionOrArray(collectionName))
78+
interpreter.Error("SCLEAR", $"Collection/Array: ${collectionName} not found.");
79+
var collection = interpreter.GetCollectionOrArray(collectionName);
80+
81+
// (v) reset the collection
82+
collection.Reset();
83+
collection.ClearCollection();
84+
if (collection is staticDataCollection staticCollection)
85+
{
86+
// (v) clear the data of the collection
87+
staticCollection.data.Clear();
88+
}
89+
collection.endOfData = false;
90+
}
91+
92+
#endregion (+) Statements & Functions for both Collections and Arrays
93+
94+
#region (+) Statements & Functions for Collections only
95+
6496
private static void SSET(Interpreter interpreter)
6597
{
6698
// Syntax: SSET collection index value
6799
// Used to SSET a value at a specific index of a static collection
68100
//
69101
interpreter.Match(Token.Identifier);
70102
string collectionName = interpreter.lex.Identifier;
71-
103+
72104
interpreter.GetNextToken();
73-
int index=-1;
74-
switch(interpreter.lastToken)
105+
int index = -1;
106+
switch (interpreter.lastToken)
75107
{
76108
case Token.Value:
77-
index=interpreter.lex.Value.ToInt();
109+
index = interpreter.lex.Value.ToInt();
78110
break;
79111
case Token.Identifier:
80112
var name = interpreter.lex.Identifier;
81113
index = interpreter.GetValue(name).ToInt();
82114
break;
83115
default:
84116
interpreter.Match(Token.Value); // will produce error
85-
return;
117+
return;
86118
}
87119

88120
interpreter.GetNextToken();
89-
Value value=Value.Empty;
121+
Value value = Value.Empty;
90122
switch (interpreter.lastToken)
91123
{
92124
case Token.Value:
@@ -106,35 +138,9 @@ private static void SSET(Interpreter interpreter)
106138
if (index < 0)
107139
interpreter.Error("SSET", Errors.E130_OutOfRange($"Collection: {collectionName}", $"index={1 + index}"));
108140

109-
((staticDataCollection)interpreter.collections[collectionName]).data[index]=value;
141+
((staticDataCollection)interpreter.collections[collectionName]).data[index] = value;
110142
}
111143

112-
private static void SCLEAR(Interpreter interpreter)
113-
{
114-
// Syntax: SCLEAR collection
115-
// Used to RESET and then to CLEAR a collection
116-
//
117-
interpreter.Match(Token.Identifier);
118-
string collectionName = interpreter.lex.Identifier;
119-
120-
interpreter.SetLastTokenToNewLine();
121-
122-
// (v) implementation
123-
if (!interpreter.collections.ContainsKey(collectionName))
124-
interpreter.Error("SCLEAR", $"Collection: ${collectionName} not found.");
125-
var collection = interpreter.collections[collectionName];
126-
127-
// (v) reset the collection
128-
collection.Reset();
129-
if (collection is staticDataCollection staticCollection)
130-
{
131-
// (v) clear the data of the collection
132-
staticCollection.data.Clear();
133-
}
134-
collection.endOfData = false;
135-
}
136-
137-
138144
/// <summary>
139145
/// SCI() : Static Collection Item
140146
/// </summary>
@@ -163,6 +169,7 @@ private static Value StaticCollectionItem(Interpreter interpreter, List<Value> a
163169
return new Value(value);
164170
}
165171

172+
#endregion (+) Statements & Functions for Collections only
166173
}
167174

168175

0 commit comments

Comments
 (0)