All files / src/cds cds_parser.ts

95.55% Statements 43/45
94.44% Branches 17/18
100% Functions 1/1
95.55% Lines 43/45

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 451x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 113x     113x 113x 113x 113x 113x 113x 32x 32x 113x 27x 27x 113x 17x 17x 113x 15x 15x 113x 9x 9x 113x 7x 7x 113x 5x 5x 108x 108x 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 {defaultVersion} 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, defaultVersion);
    if (res === undefined || !(res[0] instanceof ExpressionNode)) {
      res = Combi.run(new Expressions.CDSDefineAbstract(), tokens, defaultVersion);
    }
    if (res === undefined || !(res[0] instanceof ExpressionNode)) {
      res = Combi.run(new Expressions.CDSDefineProjection(), tokens, defaultVersion);
    }
    if (res === undefined || !(res[0] instanceof ExpressionNode)) {
      res = Combi.run(new Expressions.CDSAnnotate(), tokens, defaultVersion);
    }
    if (res === undefined || !(res[0] instanceof ExpressionNode)) {
      res = Combi.run(new Expressions.CDSDefineCustom(), tokens, defaultVersion);
    }
    if (res === undefined || !(res[0] instanceof ExpressionNode)) {
      res = Combi.run(new Expressions.CDSDefineTableFunction(), tokens, defaultVersion);
    }
    if (res === undefined || !(res[0] instanceof ExpressionNode)) {
      res = Combi.run(new Expressions.CDSExtendView(), tokens, defaultVersion);
    }
    if (res === undefined || !(res[0] instanceof ExpressionNode)) {
      return undefined;
    }
    return res[0];
  }
 
}