All files / src/ddl ddl_lexer.ts

93.93% Statements 31/33
88.88% Branches 8/9
100% Functions 1/1
93.93% Lines 31/33

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 331x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x     3x 3x 1x 1x 1x 18x 10x 18x 1x 1x 8x 7x 7x 18x 1x 1x 1x 1x
import {Identifier} from "../abap/1_lexer/tokens";
import {AbstractToken} from "../abap/1_lexer/tokens/abstract_token";
import {IFile} from "../files/_ifile";
import {Position} from "../position";
 
export class DDLLexer {
  public static run(file: IFile): AbstractToken[] {
    const step1: string[] = [];
 
    const lines = file.getRaw().replace(/\r/g, "").split("\n");
 
    for (const l of lines) {
      if (l.startsWith("@")) {
        continue; // skip annotations for now
      }
      step1.push(...l.split(" "));
    }
 
    const step2: string[] = [];
    for (const t of step1) {
      if (t === "") {
        continue;
      } else if (t.endsWith(";")) {
        step2.push(t.substr(0, t.length - 1));
        step2.push(";");
      } else {
        step2.push(t);
      }
    }
 
    return step2.map(t => new Identifier(new Position(1, 1), t));
  }
}