All files / src/abap abap_parser.ts

100% Statements 28/28
100% Branches 4/4
100% Functions 3/3
100% Lines 27/27

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    1x 1x 1x 1x   1x 1x                   1x         5018x 5018x         5018x 5018x   5018x     5018x 5036x 5018x     5018x 5018x 5018x     5018x 5018x 5036x     5036x   5036x 5036x   5018x   5018x   5018x              
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 {ILexerResult} from "./1_lexer/lexer_result";
import {ABAPFileInformation} from "./4_file_information/abap_file_information";
import {ABAPFile} from "./abap_file";
 
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[];
 
  public constructor(version?: Version, globalMacros?: readonly string[]) {
    this.version = version ? version : defaultVersion;
    this.globalMacros = globalMacros ? globalMacros : [];
  }
 
  // 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 ILexerResult[] = files.map(f => Lexer.run(f));
    const lexingRuntime = Date.now() - b1;
 
// 2: statements
    const b2 = Date.now();
    const statementResult = new StatementParser(this.version).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},
    };
  }
 
}