All files / src/abap abap_parser.ts

100% Statements 70/70
100% Branches 8/8
100% Functions 2/2
100% Lines 70/70

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 701x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 6425x 6425x 6425x 6425x 1x 1x 1x 6425x 6425x 6425x 6425x 6425x 6425x 6425x 6425x 6425x 6425x 6425x 6425x 6425x 6425x 6425x 6425x 6425x 6425x 6447x 6447x 6447x 6447x 6447x 6447x 6447x 6447x 6425x 6425x 6425x 6425x 6425x 6425x 6425x 6425x 6425x 6425x 1x 1x
import {IFile} from "../files/_ifile";
import {Issue} from "../issue";
import {Version, defaultVersion} from "../version";
import {Lexer} from "./1_lexer/lexer";
import {StatementParser} from "./2_statements/statement_parser";
import {StructureParser} from "./3_structures/structure_parser";
import {IABAPLexerResult} from "./1_lexer/lexer_result";
import {ABAPFileInformation} from "./4_file_information/abap_file_information";
import {ABAPFile} from "./abap_file";
import {IRegistry} from "../_iregistry";
 
export interface IABAPParserResult {
  issues: readonly Issue[],
  output: readonly ABAPFile[],
  /** runtime in milliseconds */
  runtime: number,
  runtimeExtra: {lexing: number, statements: number, structure: number},
}
 
export class ABAPParser {
  private readonly version: Version;
  private readonly globalMacros: readonly string[];
  private readonly reg?: IRegistry;
 
  public constructor(version?: Version, globalMacros?: readonly string[], reg?: IRegistry) {
    this.version = version ? version : defaultVersion;
    this.globalMacros = globalMacros ? globalMacros : [];
    this.reg = reg;
  }
 
  // files is input for a single object
  public parse(files: readonly IFile[]): IABAPParserResult {
    const issues: Issue[] = [];
    const output: ABAPFile[] = [];
 
    const start = Date.now();
 
// 1: lexing
    const b1 = Date.now();
    const lexerResult: readonly IABAPLexerResult[] = files.map(f => Lexer.run(f));
    const lexingRuntime = Date.now() - b1;
 
// 2: statements
    const b2 = Date.now();
    const statementResult = new StatementParser(this.version, this.reg).run(lexerResult, this.globalMacros);
    const statementsRuntime = Date.now() - b2;
 
// 3: structures
    const b3 = Date.now();
    for (const f of statementResult) {
      const result = StructureParser.run(f);
 
// 4: file information
      const info = new ABAPFileInformation(result.node, f.file.getFilename());
 
      output.push(new ABAPFile(f.file, f.tokens, f.statements, result.node, info));
      issues.push(...result.issues);
    }
    const structuresRuntime = Date.now() - b3;
 
    const end = Date.now();
 
    return {issues,
      output,
      runtime: end - start,
      runtimeExtra: {lexing: lexingRuntime, statements: statementsRuntime, structure: structuresRuntime},
    };
  }
 
}