@sap/cds-compiler 2.4.4 → 2.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +241 -1
- package/bin/.eslintrc.json +17 -0
- package/bin/cds_update_identifiers.js +8 -7
- package/bin/cdsc.js +180 -132
- package/bin/cdshi.js +18 -11
- package/bin/cdsse.js +38 -32
- package/bin/cdsv2m.js +8 -7
- package/doc/CHANGELOG_BETA.md +36 -1
- package/lib/api/main.js +81 -100
- package/lib/api/options.js +17 -11
- package/lib/api/validate.js +12 -8
- package/lib/backends.js +0 -81
- package/lib/base/keywords.js +32 -2
- package/lib/base/location.js +2 -2
- package/lib/base/message-registry.js +66 -4
- package/lib/base/messages.js +84 -27
- package/lib/base/model.js +2 -61
- package/lib/checks/arrayOfs.js +0 -1
- package/lib/checks/defaultValues.js +27 -2
- package/lib/checks/elements.js +1 -6
- package/lib/checks/enricher.js +8 -2
- package/lib/checks/foreignKeys.js +0 -6
- package/lib/checks/managedWithoutKeys.js +17 -0
- package/lib/checks/nonexpandableStructured.js +38 -0
- package/lib/checks/onConditions.js +9 -45
- package/lib/checks/queryNoDbArtifacts.js +27 -9
- package/lib/checks/selectItems.js +25 -2
- package/lib/checks/types.js +26 -2
- package/lib/checks/unknownMagic.js +38 -0
- package/lib/checks/utils.js +61 -0
- package/lib/checks/validator.js +66 -13
- package/lib/compiler/assert-consistency.js +24 -12
- package/lib/compiler/builtins.js +2 -0
- package/lib/compiler/checks.js +6 -4
- package/lib/compiler/definer.js +101 -39
- package/lib/compiler/index.js +88 -59
- package/lib/compiler/resolver.js +455 -209
- package/lib/compiler/shared.js +57 -33
- package/lib/edm/annotations/genericTranslation.js +183 -187
- package/lib/edm/csn2edm.js +128 -99
- package/lib/edm/edm.js +18 -21
- package/lib/edm/edmPreprocessor.js +361 -127
- package/lib/edm/edmUtils.js +103 -33
- package/lib/gen/Dictionary.json +74 -28
- package/lib/gen/language.checksum +1 -1
- package/lib/gen/language.interp +18 -4
- package/lib/gen/language.tokens +124 -118
- package/lib/gen/languageLexer.interp +13 -1
- package/lib/gen/languageLexer.js +870 -839
- package/lib/gen/languageLexer.tokens +116 -111
- package/lib/gen/languageParser.js +5894 -5614
- package/lib/json/from-csn.js +152 -67
- package/lib/json/to-csn.js +334 -135
- package/lib/language/antlrParser.js +4 -3
- package/lib/language/errorStrategy.js +1 -0
- package/lib/language/genericAntlrParser.js +24 -14
- package/lib/language/language.g4 +188 -128
- package/lib/main.d.ts +435 -0
- package/lib/main.js +31 -7
- package/lib/model/api.js +78 -0
- package/lib/model/csnRefs.js +463 -187
- package/lib/model/csnUtils.js +280 -136
- package/lib/model/enrichCsn.js +75 -4
- package/lib/model/revealInternalProperties.js +2 -1
- package/lib/modelCompare/compare.js +70 -25
- package/lib/optionProcessor.js +13 -10
- package/lib/render/.eslintrc.json +4 -1
- package/lib/render/DuplicateChecker.js +8 -5
- package/lib/render/toCdl.js +123 -40
- package/lib/render/toHdbcds.js +156 -65
- package/lib/render/toSql.js +87 -11
- package/lib/render/utils/common.js +55 -9
- package/lib/render/utils/sql.js +3 -3
- package/lib/sql-identifier.js +6 -1
- package/lib/transform/{sql → db}/.eslintrc.json +0 -0
- package/lib/transform/{sql → db}/assertUnique.js +7 -8
- package/lib/transform/{sql → db}/constraints.js +35 -20
- package/lib/transform/db/draft.js +353 -0
- package/lib/transform/db/expansion.js +582 -0
- package/lib/transform/db/flattening.js +325 -0
- package/lib/transform/{sql → db}/groupByOrderBy.js +8 -16
- package/lib/transform/{sql → db}/helpers.js +0 -0
- package/lib/transform/{sql → db}/transformExists.js +256 -60
- package/lib/transform/forHanaNew.js +216 -765
- package/lib/transform/forOdataNew.js +60 -56
- package/lib/transform/localized.js +48 -26
- package/lib/transform/odata/attachPath.js +19 -4
- package/lib/transform/odata/expandStructKeysInAssociations.js +2 -2
- package/lib/transform/odata/generateForeignKeyElements.js +13 -12
- package/lib/transform/odata/referenceFlattener.js +60 -36
- package/lib/transform/odata/sortByAssociationDependency.js +4 -4
- package/lib/transform/odata/structuralPath.js +76 -0
- package/lib/transform/odata/structureFlattener.js +21 -22
- package/lib/transform/odata/toFinalBaseType.js +5 -5
- package/lib/transform/odata/typesExposure.js +27 -17
- package/lib/transform/odata/utils.js +2 -2
- package/lib/transform/transformUtilsNew.js +141 -77
- package/lib/transform/translateAssocsToJoins.js +17 -14
- package/lib/transform/universalCsnEnricher.js +67 -0
- package/lib/utils/file.js +0 -11
- package/lib/utils/moduleResolve.js +6 -8
- package/lib/utils/timetrace.js +6 -1
- package/package.json +2 -1
- package/lib/base/deepCopy.js +0 -66
- package/lib/json/walker.js +0 -26
- package/lib/utils/string.js +0 -17
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
const antlr4 = require('antlr4');
|
|
12
12
|
|
|
13
|
-
const {
|
|
13
|
+
const { CompileMessage } = require('../base/messages');
|
|
14
14
|
const errorStrategy = require('./errorStrategy');
|
|
15
15
|
|
|
16
16
|
const Parser = require('../gen/languageParser').languageParser;
|
|
@@ -112,7 +112,7 @@ const rules = {
|
|
|
112
112
|
expr: { func: 'conditionEOF', returns: 'cond' }, // yes, condition
|
|
113
113
|
};
|
|
114
114
|
|
|
115
|
-
function parse( source, filename = '<undefined>.cds', options = {}, rule = 'cdl' ) {
|
|
115
|
+
function parse( source, filename = '<undefined>.cds', options = {}, messageFunctions, rule = 'cdl' ) {
|
|
116
116
|
const lexer = new Lexer( new antlr4.InputStream(source) );
|
|
117
117
|
const tokenStream = new RewriteTypeTokenStream(lexer);
|
|
118
118
|
/** @type {object} */
|
|
@@ -121,7 +121,7 @@ function parse( source, filename = '<undefined>.cds', options = {}, rule = 'cdl'
|
|
|
121
121
|
|
|
122
122
|
parser.filename = filename;
|
|
123
123
|
parser.options = options;
|
|
124
|
-
parser.$
|
|
124
|
+
parser.$messageFunctions = messageFunctions;
|
|
125
125
|
|
|
126
126
|
initTokenRewrite( parser, tokenStream );
|
|
127
127
|
// comment the following 2 lines if you want to output the parser errors directly:
|
|
@@ -162,6 +162,7 @@ function parse( source, filename = '<undefined>.cds', options = {}, rule = 'cdl'
|
|
|
162
162
|
if (rulespec.$frontend)
|
|
163
163
|
ast.$frontend = rulespec.$frontend;
|
|
164
164
|
|
|
165
|
+
// TODO: clarify with LSP colleagues: still necessary?
|
|
165
166
|
if (parser.messages) {
|
|
166
167
|
Object.defineProperty( ast, 'messages',
|
|
167
168
|
{ value: parser.messages, configurable: true, writable: true } );
|
|
@@ -13,6 +13,14 @@ const locUtils = require('../base/location');
|
|
|
13
13
|
const { parseDocComment } = require('./docCommentParser');
|
|
14
14
|
const { functionsWithoutParens, specialFunctions } = require('../compiler/builtins');
|
|
15
15
|
|
|
16
|
+
|
|
17
|
+
// Push message `msg` with location `loc` to array of errors:
|
|
18
|
+
function _message( parser, severity, id, loc, ...args ) {
|
|
19
|
+
const msg = parser.$messageFunctions[severity]; // set in antlrParser.js
|
|
20
|
+
return msg( id,
|
|
21
|
+
(loc instanceof antlr4.CommonToken) ? parser.tokenLocation(loc) : loc, ...args );
|
|
22
|
+
}
|
|
23
|
+
|
|
16
24
|
// Class which is to be used as grammar option with
|
|
17
25
|
// grammar <name> options { superclass = genericAntlrParser; }
|
|
18
26
|
//
|
|
@@ -34,10 +42,10 @@ function GenericAntlrParser( ...args ) {
|
|
|
34
42
|
|
|
35
43
|
GenericAntlrParser.prototype = Object.assign(
|
|
36
44
|
Object.create( antlr4.Parser.prototype ), {
|
|
37
|
-
message: function(...args) { return
|
|
38
|
-
error: function(...args) { return
|
|
39
|
-
warning: function(...args) { return
|
|
40
|
-
info: function(...args) { return
|
|
45
|
+
message: function(...args) { return _message( this, 'message', ...args ); },
|
|
46
|
+
error: function(...args) { return _message( this, 'error', ...args ); },
|
|
47
|
+
warning: function(...args) { return _message( this, 'warning', ...args ); },
|
|
48
|
+
info: function(...args) { return _message( this, 'info', ...args ); },
|
|
41
49
|
attachLocation,
|
|
42
50
|
startLocation,
|
|
43
51
|
tokenLocation,
|
|
@@ -69,6 +77,7 @@ GenericAntlrParser.prototype = Object.assign(
|
|
|
69
77
|
noAssignmentInSameLine,
|
|
70
78
|
noSemicolonHere,
|
|
71
79
|
setLocalToken,
|
|
80
|
+
setLocalTokenIfBefore,
|
|
72
81
|
excludeExpected,
|
|
73
82
|
isStraightBefore,
|
|
74
83
|
meltKeywordToIdentifier,
|
|
@@ -110,14 +119,6 @@ const quotedLiteralPatterns = {
|
|
|
110
119
|
},
|
|
111
120
|
};
|
|
112
121
|
|
|
113
|
-
|
|
114
|
-
// Push message `msg` with location `loc` to array of errors:
|
|
115
|
-
function message( severity, id, loc, ...args ) {
|
|
116
|
-
const msg = this.$message[severity];
|
|
117
|
-
return msg( id, // function $message is set in antlrParser.js
|
|
118
|
-
(loc instanceof antlr4.CommonToken) ? this.tokenLocation(loc) : loc, ...args );
|
|
119
|
-
}
|
|
120
|
-
|
|
121
122
|
// Use the following function for language constructs which we (currently)
|
|
122
123
|
// just being able to parse, in able to run tests from HANA CDS. As soon as we
|
|
123
124
|
// create ASTs for the language construct and put it into a CSN, a
|
|
@@ -183,6 +184,14 @@ function setLocalToken( string, tokenName, notBefore, inSameLine ) {
|
|
|
183
184
|
ll1.type = this.constructor[tokenName];
|
|
184
185
|
}
|
|
185
186
|
|
|
187
|
+
function setLocalTokenIfBefore( string, tokenName, before, inSameLine ) {
|
|
188
|
+
const ll1 = this.getCurrentToken();
|
|
189
|
+
if (ll1.text.toUpperCase() === string &&
|
|
190
|
+
(!inSameLine || this._input.LT(-1).line === ll1.line) &&
|
|
191
|
+
(!before || before && before.test( this._input.LT(2).text )))
|
|
192
|
+
ll1.type = this.constructor[tokenName];
|
|
193
|
+
}
|
|
194
|
+
|
|
186
195
|
// // Special function for rule `requiredSemi` before return $ctx
|
|
187
196
|
// function braceForSemi() {
|
|
188
197
|
// if (RBRACE == null)
|
|
@@ -305,7 +314,7 @@ function combinedLocation( start, end ) {
|
|
|
305
314
|
return locUtils.combinedLocation( start, end );
|
|
306
315
|
}
|
|
307
316
|
|
|
308
|
-
function surroundByParens( expr, open, close ) {
|
|
317
|
+
function surroundByParens( expr, open, close, asQuery = false ) {
|
|
309
318
|
if (!expr)
|
|
310
319
|
return expr;
|
|
311
320
|
const location = this.tokenLocation( open, close );
|
|
@@ -313,7 +322,7 @@ function surroundByParens( expr, open, close ) {
|
|
|
313
322
|
expr.$parens.push( location );
|
|
314
323
|
else
|
|
315
324
|
expr.$parens = [ location ];
|
|
316
|
-
return expr;
|
|
325
|
+
return (asQuery) ? { query: expr, location } : expr;
|
|
317
326
|
}
|
|
318
327
|
|
|
319
328
|
function unaryOpForParens( query, val ) {
|
|
@@ -362,6 +371,7 @@ function fragileAlias( ast, safe = false ) {
|
|
|
362
371
|
else // configurable error
|
|
363
372
|
this.message( 'syntax-fragile-alias', ast.location, { keyword: 'as' },
|
|
364
373
|
'Please add the keyword $(KEYWORD) in front of the alias name' );
|
|
374
|
+
return ast;
|
|
365
375
|
}
|
|
366
376
|
|
|
367
377
|
// Return AST for identifier token `token`. Also check that identifer is not empty.
|