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

92.77% Statements 77/83
76.92% Branches 20/26
100% Functions 2/2
92.77% Lines 77/83

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 79 80 81 82 831x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 12x 12x 25x 25x 12x 12x 12x 3x 3x 3x 3x 3x 3x 3x 1x 3x 2x 2x 3x 12x 12x 12x 7x 6x 6x 7x 12x 12x 12x     12x 12x 12x     12x 12x 12x 4x 4x 12x 12x 7x 18x 4x 18x 4x 4x 18x 18x 7x 18x 3x 3x 18x 7x 12x 1x 1x 1x 1x 13x 13x 13x 13x     13x 1x 1x
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})},
      ], "MATCH_RESULT");
      if (node.concatTokens().toUpperCase().startsWith("FIND FIRST")) {
        this.inline(rfound, scope, filename, type);
      } else {
        this.inline(rfound, scope, filename, new TableType(type, {withHeader: false}, "MATCH_RESULT_TAB"));
      }
    }
 
    const ofound = node.findExpressionsAfterToken("OFFSET");
    for (const o of ofound) {
      if (o.get() instanceof Expressions.Target) {
        this.inline(o, scope, filename, new IntegerType());
      }
    }
 
    const lfound = node.findExpressionAfterToken("LINE");
    if (lfound && lfound.get() instanceof Expressions.Target) {
      this.inline(lfound, scope, filename, new IntegerType());
    }
 
    const cfound = node.findExpressionAfterToken("COUNT");
    if (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 === lfound || t === cfound || t === lnfound) {
          continue;
        } else if (ofound.indexOf(t) >= 0) {
          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);
    if (inline) {
      new InlineData().runSyntax(inline, scope, filename, type);
    } else {
      new Target().runSyntax(node, scope, filename);
    }
  }
 
}