All files / src/abap/5_syntax/statements find.ts

92.11% Statements 35/38
84.62% Branches 33/39
100% Functions 2/2
92.11% Lines 35/38

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 791x     1x 1x 1x 1x       1x     10x 20x     10x 10x 2x           2x 1x   1x       10x 10x 5x     10x 10x       10x 10x       10x 10x 4x     10x 7x 18x 8x   10x 10x 7x   3x                 11x 11x 11x            
import * as Expressions from "../../2_statements/expressions";
import {StatementNode, ExpressionNode} from "../../nodes";
import {CurrentScope} from "../_current_scope";
import {InlineData} from "../expressions/inline_data";
import {StringType, StructureType, IntegerType, TableType} from "../../types/basic";
import {Source} from "../expressions/source";
import {Target} from "../expressions/target";
import {AbstractType} from "../../types/basic/_abstract_type";
import {StatementSyntax} from "../_statement_syntax";
 
export class Find implements StatementSyntax {
  public runSyntax(node: StatementNode, scope: CurrentScope, filename: string): void {
 
    for (const s of node.findDirectExpressions(Expressions.Source)) {
      new Source().runSyntax(s, scope, filename);
    }
 
    const rfound = node.findExpressionAfterToken("RESULTS");
    if (rfound && rfound.get() instanceof Expressions.Target) {
      const type = new StructureType([
        {name: "LINE", type: new IntegerType()},
        {name: "OFFSET", type: new IntegerType()},
        {name: "LENGTH", type: new IntegerType()},
        {name: "SUBMATCHES", type: new TableType(new StringType(), {withHeader: false})},
      ]);
      if (node.concatTokens().toUpperCase().startsWith("FIND FIRST")) {
        this.inline(rfound, scope, filename, type);
      } else {
        this.inline(rfound, scope, filename, new TableType(type, {withHeader: false}));
      }
    }
 
    const ofound = node.findExpressionAfterToken("OFFSET");
    if (ofound && ofound.get() instanceof Expressions.Target) {
      this.inline(ofound, scope, filename, new IntegerType());
    }
 
    const lfound = node.findExpressionAfterToken("LINE");
    Iif (lfound && lfound.get() instanceof Expressions.Target) {
      this.inline(lfound, scope, filename, new IntegerType());
    }
 
    const cfound = node.findExpressionAfterToken("COUNT");
    Iif (cfound && cfound.get() instanceof Expressions.Target) {
      this.inline(cfound, scope, filename, new IntegerType());
    }
 
    const lnfound = node.findExpressionAfterToken("LENGTH");
    if (lnfound && lnfound.get() instanceof Expressions.Target) {
      this.inline(lnfound, scope, filename, new IntegerType());
    }
 
    if (node.findDirectTokenByText("SUBMATCHES")) {
      for (const t of node.findDirectExpressions(Expressions.Target)) {
        if (t === rfound || t === ofound || t === lfound || t === cfound || t === lnfound) {
          continue;
        }
        const inline = t?.findDirectExpression(Expressions.InlineData);
        if (inline) {
          new InlineData().runSyntax(inline, scope, filename, new StringType());
        } else {
          new Target().runSyntax(t, scope, filename);
        }
      }
    }
  }
 
/////////////////////
 
  private inline(node: ExpressionNode, scope: CurrentScope, filename: string, type: AbstractType): void {
    const inline = node.findDirectExpression(Expressions.InlineData);
    Eif (inline) {
      new InlineData().runSyntax(inline, scope, filename, type);
    } else {
      new Target().runSyntax(node, scope, filename);
    }
  }
 
}