Annotation Parser for CDS
npm install @sap-ux/cds-annotation-parser 
@sap-ux/cds-annotation-parsernpm install --save @sap-ux/cds-annotation-parserYarnyarn add @sap-ux/cds-annotation-parser
Pnpmpnpm add @sap-ux/cds-annotation-parser
``Typescript
import { parse, findAnnotationNode, getAstNodes, getNode } from '@sap-ux/cds-annotation-parser';
const ast = parse(
UI.LineItem #table1 : [
{
$type: 'UI.DataField',
value: some.path,
Label: 'Sample column'
}
]';);
if (ast !== undefined) {
// Expected pathToLabel: "/value/items/0/properties/2/value"
const pathToLabel = findAnnotationNode(ast, {
position: { line: 5, character: 15 },
includeDelimiterCharacters: true
});
// An array of nodes matching each segment of the path.
const nodes = getAstNodes(ast, pathToLabel);
const serializedNodes = nodes.map((n) =>
Array.isArray(n) ? ' : n
);
/* Expected serializedNodes:
[
"Node of type 'collection'",
"
"Node of type 'record'",
"
"Node of type 'record-property'",
"Node of type 'string'",
]
*/
const termNode = getNode(ast, '/term');
if (termNode.type === 'path') {
// expected termName: "UI.LineItem"
const termName = termNode.value;
}
const qualifierNode = getNode(ast, '/qualifier');
if (qualifierNode.type === 'qualifier') {
// expected qualifier: "table1"
const qualifier = qualifierNode.value;
}
const propertyValueNode = getNode(ast, '/value/items/0/properties/1/value');
if (propertyValueNode.type === 'path') {
// expected value: "some.path"
const value = propertyValueNode.value;
}
}
``