All files / src/cds cds_parser.ts

96.29% Statements 52/54
95.83% Branches 23/24
100% Functions 1/1
96.29% Lines 52/54

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 551x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 451x     451x 451x 451x 451x 451x 451x 134x 134x 451x 110x 110x 451x 84x 84x 451x 82x 82x 451x 74x 74x 451x 68x 68x 451x 52x 52x 451x 25x 25x 451x 16x 16x 451x 5x 5x 446x 446x 1x 1x  
import {Comment} from "../abap/1_lexer/tokens";
import {Combi} from "../abap/2_statements/combi";
import {ExpressionNode} from "../abap/nodes";
import {IFile} from "../files/_ifile";
import {defaultRelease} from "../version";
import {CDSLexer} from "./cds_lexer";
import * as Expressions from "./expressions";
 
// todo: the names of the ABAP + CDS + DDL expressions might overlap, if overlapping the singleton will fail
 
export class CDSParser {
  public parse(file: IFile | undefined) {
    if (file === undefined) {
      return undefined;
    }
 
    let tokens = CDSLexer.run(file);
    tokens = tokens.filter(t => !(t instanceof Comment));
 
    let res = Combi.run(new Expressions.CDSDefineView(), tokens, defaultRelease);
    if (res === undefined || !(res[0] instanceof ExpressionNode)) {
      res = Combi.run(new Expressions.CDSDefineAbstract(), tokens, defaultRelease);
    }
    if (res === undefined || !(res[0] instanceof ExpressionNode)) {
      res = Combi.run(new Expressions.CDSDefineProjection(), tokens, defaultRelease);
    }
    if (res === undefined || !(res[0] instanceof ExpressionNode)) {
      res = Combi.run(new Expressions.CDSAnnotate(), tokens, defaultRelease);
    }
    if (res === undefined || !(res[0] instanceof ExpressionNode)) {
      res = Combi.run(new Expressions.CDSDefineCustom(), tokens, defaultRelease);
    }
    if (res === undefined || !(res[0] instanceof ExpressionNode)) {
      res = Combi.run(new Expressions.CDSDefineTableFunction(), tokens, defaultRelease);
    }
    if (res === undefined || !(res[0] instanceof ExpressionNode)) {
      res = Combi.run(new Expressions.CDSExtendView(), tokens, defaultRelease);
    }
    if (res === undefined || !(res[0] instanceof ExpressionNode)) {
      res = Combi.run(new Expressions.CDSDefineHierarchy(), tokens, defaultRelease);
    }
    if (res === undefined || !(res[0] instanceof ExpressionNode)) {
      res = Combi.run(new Expressions.CDSDefineExternalEntity(), tokens, defaultRelease);
    }
    if (res === undefined || !(res[0] instanceof ExpressionNode)) {
      res = Combi.run(new Expressions.CDSDefineTableEntity(), tokens, defaultRelease);
    }
    if (res === undefined || !(res[0] instanceof ExpressionNode)) {
      return undefined;
    }
    return res[0];
  }
 
}