@@ -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