@@ -146,7 +146,7 @@ export class DisplayFile {
146
146
this . currentField . keywords . push ( {
147
147
name : `DATE` ,
148
148
value : undefined ,
149
- conditions : [ ]
149
+ conditional : new Conditional ( )
150
150
} ) ;
151
151
break ;
152
152
case `T` : //Time
@@ -155,17 +155,15 @@ export class DisplayFile {
155
155
this . currentField . keywords . push ( {
156
156
name : `TIME` ,
157
157
value : undefined ,
158
- conditions : [ ]
158
+ conditional : new Conditional ( )
159
159
} ) ;
160
160
break ;
161
161
default :
162
162
this . currentField . primitiveType = `char` ;
163
163
break ;
164
164
}
165
165
166
- this . currentField . conditions . push (
167
- ...DisplayFile . parseConditionals ( conditionals )
168
- ) ;
166
+ this . currentField . conditional . push ( conditionals ) ;
169
167
}
170
168
this . HandleKeywords ( keywords , conditionals ) ;
171
169
}
@@ -178,9 +176,7 @@ export class DisplayFile {
178
176
this . currentField . length = this . currentField . value . length ;
179
177
this . currentField . displayType = `const` ;
180
178
181
- this . currentField . conditions . push (
182
- ...DisplayFile . parseConditionals ( conditionals )
183
- ) ;
179
+ this . currentField . conditional . push ( conditionals ) ;
184
180
}
185
181
}
186
182
this . HandleKeywords ( keywords , conditionals ) ;
@@ -227,42 +223,11 @@ export class DisplayFile {
227
223
228
224
}
229
225
230
- static parseConditionals ( conditionColumns : string ) : Conditional [ ] {
231
- if ( conditionColumns . trim ( ) === "" ) { return [ ] ; }
232
-
233
- /** @type {Conditional[] } */
234
- let conditionals = [ ] ;
235
-
236
- //TODO: something with condition
237
- //const condition = conditionColumns.substring(0, 1); //A (and) or O (or)
238
-
239
- let current = "" ;
240
- let negate = false ;
241
- let indicator = 0 ;
242
-
243
- let cIndex = 1 ;
244
-
245
- while ( cIndex <= 7 ) {
246
- current = conditionColumns . substring ( cIndex , cIndex + 3 ) ;
247
-
248
- if ( current . trim ( ) !== "" ) {
249
- negate = ( conditionColumns . substring ( cIndex , cIndex + 1 ) === "N" ) ;
250
- indicator = Number ( conditionColumns . substring ( cIndex + 1 , cIndex + 3 ) ) ;
251
-
252
- conditionals . push ( { indicator, negate} ) ;
253
- }
254
-
255
- cIndex += 3 ;
256
- }
257
-
258
- return conditionals ;
259
- }
260
-
261
226
static parseKeywords ( keywordStrings : string [ ] , conditionalStrings ?: { [ line : number ] : string } ) {
262
- let result : { value : string , keywords : Keyword [ ] , conditions : Conditional [ ] } = {
227
+ let result : { value : string , keywords : Keyword [ ] , conditional : Conditional } = {
263
228
value : `` ,
264
229
keywords : [ ] ,
265
- conditions : [ ]
230
+ conditional : new Conditional ( )
266
231
} ;
267
232
268
233
const newLineMark = `~` ;
@@ -330,7 +295,7 @@ export class DisplayFile {
330
295
result . keywords . push ( {
331
296
name : word . toUpperCase ( ) ,
332
297
value : innerValue . length > 0 ? innerValue : undefined ,
333
- conditions : conditionals ? DisplayFile . parseConditionals ( conditionals ) : [ ]
298
+ conditional : new Conditional ( conditionals )
334
299
} ) ;
335
300
336
301
word = `` ;
@@ -564,7 +529,7 @@ export class RecordInfo {
564
529
}
565
530
}
566
531
567
- export interface Keyword { name : string , value ?: string , conditions : Conditional [ ] } ;
532
+ export interface Keyword { name : string , value ?: string , conditional : Conditional } ;
568
533
569
534
export type DisplayType = "input" | "output" | "both" | "const" | "hidden" ;
570
535
@@ -577,7 +542,7 @@ export class FieldInfo {
577
542
public decimals : number = 0 ;
578
543
public position : { x : number , y : number } = { x : 0 , y : 0 } ;
579
544
public keywordStrings : { keywordLines : string [ ] , conditionalLines : { [ lineIndex : number ] : string } } = { keywordLines : [ ] , conditionalLines : { } } ;
580
- public conditions : Conditional [ ] = [ ] ;
545
+ public conditional : Conditional = new Conditional ( ) ;
581
546
public keywords : Keyword [ ] = [ ] ;
582
547
583
548
constructor ( public startRange : number , public name ?: string ) { }
@@ -593,7 +558,66 @@ export class FieldInfo {
593
558
}
594
559
}
595
560
596
- export interface Conditional {
597
- indicator : number ,
598
- negate : boolean
599
- }
561
+ export interface Condition {
562
+ indicators : Indicator [ ] ;
563
+ }
564
+
565
+ export interface Indicator {
566
+ indicator : number ,
567
+ negate : boolean
568
+ }
569
+
570
+ export class Conditional {
571
+ private conditions : Condition [ ] = [ {
572
+ indicators : [ ]
573
+ } ] ;
574
+
575
+ constructor ( indicatorStr ?: string ) {
576
+ if ( indicatorStr !== undefined ) {
577
+ this . push ( indicatorStr ) ;
578
+ }
579
+ }
580
+
581
+ push ( indicatorStr : string ) {
582
+ if ( indicatorStr . substring ( 0 , 1 ) === `O` && this . conditions [ this . conditions . length - 1 ] . indicators . length > 0 ) {
583
+ if ( this . conditions . length >= 8 ) {
584
+ throw new Error ( "Too many conditions" ) ;
585
+ }
586
+ this . conditions . push ( { indicators : [ ] } ) ;
587
+ }
588
+
589
+ let cIndex = 1 ;
590
+ let current = `` ;
591
+ let negate = false ;
592
+ let indicator = 0 ;
593
+
594
+ while ( cIndex <= 7 ) {
595
+ current = indicatorStr . substring ( cIndex , cIndex + 3 ) ;
596
+
597
+ if ( current . trim ( ) !== "" ) {
598
+ negate = ( indicatorStr . substring ( cIndex , cIndex + 1 ) === "N" ) ;
599
+ indicator = Number ( indicatorStr . substring ( cIndex + 1 , cIndex + 3 ) ) ;
600
+ if ( indicator !== 0 ) {
601
+ if ( this . conditions [ this . conditions . length - 1 ] . indicators . length >= 8 ) {
602
+ throw new Error ( "Too many option indicators specified for one condition" ) ;
603
+ }
604
+ this . conditions [ this . conditions . length - 1 ] . indicators . push ( {
605
+ indicator : indicator ,
606
+ negate : negate
607
+ } )
608
+ }
609
+ }
610
+
611
+ cIndex += 3 ;
612
+ }
613
+ }
614
+
615
+ getConditions ( ) : Condition [ ] {
616
+ return this . conditions ;
617
+ }
618
+
619
+ getLines ( line : string ) : string [ ] {
620
+ return [ ] ;
621
+ }
622
+
623
+ }
0 commit comments