@sap/cds-compiler
Version:
CDS (Core Data Services) compiler and backends
32 lines (26 loc) • 950 B
JavaScript
;
const cdlKeywords = require('../gen/cdlKeywords.json').reserved;
/** RegEx identifying undelimited identifiers in CDL */
const undelimitedIdentifierRegex = /^[$_\p{ID_Start}][$\p{ID_Continue}\u200C\u200D]*$/u;
/**
* Functions without parentheses in CDL (common standard SQL-92 functions)
* (do not add more - make it part of the SQL renderer to remove parentheses for
* other funny SQL functions like CURRENT_UTCTIMESTAMP).
*/
const functionsWithoutParentheses = [
'CURRENT_DATE', 'CURRENT_TIME', 'CURRENT_TIMESTAMP',
'CURRENT_USER', 'SESSION_USER', 'SYSTEM_USER',
];
function isSimpleCdlIdentifier( id ) {
if (undelimitedIdentifierRegex.test(id))
return true;
const upperId = id.toUpperCase();
return !cdlKeywords.includes(upperId) &&
!functionsWithoutParentheses.includes(upperId);
}
module.exports = {
undelimitedIdentifierRegex,
cdlKeywords,
functionsWithoutParentheses,
isSimpleCdlIdentifier,
};