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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 31x 31x 31x 31x 31x 26x 26x 31x 9x 9x 31x 5x 5x 31x 3x 3x 28x 28x 1x 1x 28x 28x 203x 89x 89x 203x 203x 203x 203x 53x 53x 53x 203x 4x 4x 203x 4x 4x 4x 4x 49x 45x 45x 45x 45x 203x 28x 28x 28x 28x 28x 28x 28x 28x 28x 1x 1x 130x 130x 130x 1x 1x 53x 56x 56x 56x 53x 56x 27x 56x 1x 1x 53x 53x 220x 220x 220x 220x 27x 27x 1x 1x 28x 28x 28x 28x 17x 17x 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/cds_lexer";
import * as Expressions from "./expressions";
export enum DDLKind {
Structure = "structure",
Table = "table",
Aspect = "aspect",
ExtendType = "extend-type",
}
export interface IDDLParserResultField {
key: boolean,
name: string,
type: string,
notNull: boolean,
}
export interface IDDLParserResult {
name: string,
kind: DDLKind,
fields: IDDLParserResultField[];
}
export class DDLParser {
public parse(file: IFile): IDDLParserResult | undefined {
let tokens = CDSLexer.run(file);
tokens = tokens.filter(t => !(t instanceof Comment));
let res = Combi.run(new Expressions.DDLStructure(), tokens, defaultRelease);
if (res === undefined) {
res = Combi.run(new Expressions.DDLTable(), tokens, defaultRelease);
}
if (res === undefined) {
res = Combi.run(new Expressions.DDLAspect(), tokens, defaultRelease);
}
if (res === undefined) {
res = Combi.run(new Expressions.DDLExtendType(), tokens, defaultRelease);
}
if (res === undefined || !(res[0] instanceof ExpressionNode)) {
return undefined;
}
return this.parsedToResult(res[0]);
}
private parsedToResult(node: ExpressionNode): IDDLParserResult {
const fields: IDDLParserResultField[] = [];
for (const child of node.getChildren()) {
if (!(child instanceof ExpressionNode)) { continue; }
const expr = child.get();
const isField = expr instanceof Expressions.DDLStructureField
|| expr instanceof Expressions.DDLTableField
|| expr instanceof Expressions.DDLInclude
|| expr instanceof Expressions.DDLNamedInclude;
if (!isField) { continue; }
const key = this.hasKey(child);
const notNull = this.hasNotNull(child);
if (expr instanceof Expressions.DDLInclude) {
const target = this.compactTokens(child.findDirectExpression(Expressions.DDLName));
fields.push({name: ".INCLUDE", type: target, key, notNull});
} else if (expr instanceof Expressions.DDLNamedInclude) {
const names = child.findDirectExpressions(Expressions.DDLName);
const alias = this.compactTokens(names[0]);
const target = this.compactTokens(names[1]);
fields.push({name: alias, type: target, key, notNull});
} else {
const name = this.compactTokens(child.findDirectExpression(Expressions.DDLName));
const type = this.compactTokens(child.findDirectExpression(Expressions.DDLType));
fields.push({name, type, key, notNull});
}
}
const result: IDDLParserResult = {
name: this.compactTokens(node.findDirectExpression(Expressions.DDLName)),
kind: this.kindOf(node),
fields,
};
return result;
}
private compactTokens(node: ExpressionNode | undefined): string {
if (node === undefined) {
return "";
}
return node.concatTokens().replace(/\s+/g, "");
}
private hasKey(node: ExpressionNode): boolean {
for (const c of node.getChildren()) {
const expr = (c as any).get?.();
const ctor = expr?.constructor?.name;
if (ctor === "CDSAnnotation") { continue; }
const tok = c.concatTokens().toUpperCase().trim();
if (tok === "KEY") { return true; }
if (tok !== "") { return false; }
}
return false;
}
private hasNotNull(node: ExpressionNode): boolean {
const children = node.getChildren();
for (let i = 0; i < children.length - 1; i++) {
const a = (children[i] as any).concatTokens?.().toUpperCase().trim();
const b = (children[i + 1] as any).concatTokens?.().toUpperCase().trim();
if (a === "NOT" && b === "NULL") { return true; }
}
return false;
}
private kindOf(node: ExpressionNode): DDLKind {
const expr = node.get();
if (expr instanceof Expressions.DDLStructure) { return DDLKind.Structure; }
if (expr instanceof Expressions.DDLAspect) { return DDLKind.Aspect; }
if (expr instanceof Expressions.DDLExtendType) { return DDLKind.ExtendType; }
return DDLKind.Table;
}
}
|