<commit_before>import File from "./file";
import * as Statements from "./statements/";

export default class Nesting {

  public static run(file: File): Array<Statements.Statement> {
// todo: save END statement references?
// todo: more events, INITIALIZATION, AT SELECTION SCREEN OUTPUT etc.
// todo: try-catch

    let result = [];
    let stack: Array<Statements.Statement> = [];

    for (let statement of file.getStatements()) {

      let top = stack[stack.length - 1];

// todo, refactor
      if (statement instanceof Statements.Endform
          || statement instanceof Statements.Endmethod
          || statement instanceof Statements.Enddo
          || statement instanceof Statements.Endwhile
          || statement instanceof Statements.Enddefine
          || statement instanceof Statements.Endinterface
          || statement instanceof Statements.Endif
          || statement instanceof Statements.Endat
          || statement instanceof Statements.Endloop) {
        stack.pop();
        continue;
      } else if (statement instanceof Statements.Endcase) {
        if (top instanceof Statements.When) {
          stack.pop();
        }
        stack.pop();
        continue;
      } else if (statement instanceof Statements.Endclass) {
        if (top instanceof Statements.Private
            || top instanceof Statements.Protected
            || top instanceof Statements.Public) {
          stack.pop();
        }
        stack.pop();
        continue;
      } else if (statement instanceof Statements.Endtry) {
        if (top instanceof Statements.Catch) {
          stack.pop();
        }
        stack.pop();
        continue;
      } else if ((statement instanceof Statements.Else
          || statement instanceof Statements.Elseif)
          && (top instanceof Statements.If
          || top instanceof Statements.Elseif)) {
        stack.pop();
      } else if (top instanceof Statements.When
          && statement instanceof Statements.When) {
        stack.pop();
      } else if ((top instanceof Statements.Private
          || top instanceof Statements.Protected
          || top instanceof Statements.Public)
          && (statement instanceof Statements.Private
          || statement instanceof Statements.Protected
          || statement instanceof Statements.Public)) {
        stack.pop();
      } else if (top instanceof Statements.Start
          && (statement instanceof Statements.Class
          || statement instanceof Statements.Form)) {
        stack.pop();
      } else if (top instanceof Statements.AtSelectionScreen
          && (statement instanceof Statements.AtSelectionScreen
          || statement instanceof Statements.Class
          || statement instanceof Statements.Form)) {
        stack.pop();
      }

      top = stack[stack.length - 1];

      if (statement instanceof Statements.Catch
          && top instanceof Statements.Catch) {
        stack.pop();
        top = stack[stack.length - 1];
      }

      if (stack.length > 0) {
        top.addChild(statement);
        statement.setParent(top);
      } else {
        result.push(statement);
      }

      if (statement instanceof Statements.If
          || statement instanceof Statements.Form
          || (statement instanceof Statements.Class
          && /DEFINITION DEFERRED/.test(statement.concatTokens().toUpperCase()) == false)
          || statement instanceof Statements.Interface
          || statement instanceof Statements.Method
          || statement instanceof Statements.Case
          || statement instanceof Statements.Do
          || statement instanceof Statements.While
          || statement instanceof Statements.When
          || statement instanceof Statements.Else
          || statement instanceof Statements.Elseif
          || statement instanceof Statements.Private
          || statement instanceof Statements.Protected
          || statement instanceof Statements.Public
          || statement instanceof Statements.At
          || statement instanceof Statements.AtSelectionScreen
          || statement instanceof Statements.Define
          || statement instanceof Statements.Loop
          || statement instanceof Statements.Start<commit_msg>fix error from tslint<commit_after>import File from "./file";
import * as Statements from "./statements/";

export default class Nesting {

  public static run(file: File): Array<Statements.Statement> {
// todo: save END statement references?
// todo: more events, INITIALIZATION, AT SELECTION SCREEN OUTPUT etc.
// todo: try-catch

    let result = [];
    let stack: Array<Statements.Statement> = [];

    for (let statement of file.getStatements()) {

      let top = stack[stack.length - 1];

// todo, refactor
      if (statement instanceof Statements.Endform
          || statement instanceof Statements.Endmethod
          || statement instanceof Statements.Enddo
          || statement instanceof Statements.Endwhile
          || statement instanceof Statements.Enddefine
          || statement instanceof Statements.Endinterface
          || statement instanceof Statements.Endif
          || statement instanceof Statements.Endat
          || statement instanceof Statements.Endloop) {
        stack.pop();
        continue;
      } else if (statement instanceof Statements.Endcase) {
        if (top instanceof Statements.When) {
          stack.pop();
        }
        stack.pop();
        continue;
      } else if (statement instanceof Statements.Endclass) {
        if (top instanceof Statements.Private
            || top instanceof Statements.Protected
            || top instanceof Statements.Public) {
          stack.pop();
        }
        stack.pop();
        continue;
      } else if (statement instanceof Statements.Endtry) {
        if (top instanceof Statements.Catch) {
          stack.pop();
        }
        stack.pop();
        continue;
      } else if ((statement instanceof Statements.Else
          || statement instanceof Statements.Elseif)
          && (top instanceof Statements.If
          || top instanceof Statements.Elseif)) {
        stack.pop();
      } else if (top instanceof Statements.When
          && statement instanceof Statements.When) {
        stack.pop();
      } else if ((top instanceof Statements.Private
          || top instanceof Statements.Protected
          || top instanceof Statements.Public)
          && (statement instanceof Statements.Private
          || statement instanceof Statements.Protected
          || statement instanceof Statements.Public)) {
        stack.pop();
      } else if (top instanceof Statements.Start
          && (statement instanceof Statements.Class
          || statement instanceof Statements.Form)) {
        stack.pop();
      } else if (top instanceof Statements.AtSelectionScreen
          && (statement instanceof Statements.AtSelectionScreen
          || statement instanceof Statements.Class
          || statement instanceof Statements.Form)) {
        stack.pop();
      }

      top = stack[stack.length - 1];

      if (statement instanceof Statements.Catch
          && top instanceof Statements.Catch) {
        stack.pop();
        top = stack[stack.length - 1];
      }

      if (stack.length > 0) {
        top.addChild(statement);
        statement.setParent(top);
      } else {
        result.push(statement);
      }

      if (statement instanceof Statements.If
          || statement instanceof Statements.Form
          || (statement instanceof Statements.Class
          && /DEFINITION DEFERRED/.test(statement.concatTokens().toUpperCase()) === false)
          || statement instanceof Statements.Interface
          || statement instanceof Statements.Method
          || statement instanceof Statements.Case
          || statement instanceof Statements.Do
          || statement instanceof Statements.While
          || statement instanceof Statements.When
          || statement instanceof Statements.Else
          || statement instanceof Statements.Elseif
          || statement instanceof Statements.Private
          || statement instanceof Statements.Protected
          || statement instanceof Statements.Public
          || statement instanceof Statements.At
          || statement instanceof Statements.AtSelectionScreen
          || statement instanceof Statements.Define
          || statement instanceof Statements.Loop
          || statement instanceof Statements.Start
{'fraction_non_alphanumeric': 0.08997979317722572, 'fraction_numerical': 0.0009509093070248425, 'mean_word_length': 2.3073899371069184, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7436605', 'n_tokens_mistral': 1950, 'n_tokens_neox': 1911, 'n_words': 554}