@malloydata/malloy 0.0.237-dev250224215546 → 0.0.237-dev250225144145
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/dist/annotation.d.ts +15 -0
- package/dist/annotation.js +86 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +5 -3
- package/dist/lang/ast/types/annotation-elements.d.ts +1 -1
- package/dist/lang/ast/types/annotation-elements.js +2 -2
- package/dist/lang/ast/types/malloy-element.d.ts +1 -1
- package/dist/lang/ast/types/malloy-element.js +2 -2
- package/dist/lang/malloy-to-ast.d.ts +1 -1
- package/dist/lang/malloy-to-ast.js +2 -2
- package/dist/lang/parse-malloy.d.ts +1 -1
- package/dist/lang/parse-malloy.js +4 -3
- package/dist/lang/parse-utils.d.ts +0 -11
- package/dist/lang/parse-utils.js +4 -82
- package/dist/lang/test/literals.spec.js +0 -34
- package/dist/malloy.d.ts +13 -8
- package/dist/malloy.js +23 -23
- package/dist/model/malloy_query.d.ts +3 -1
- package/dist/model/malloy_query.js +18 -3
- package/dist/model/materialization/utils.js +2 -2
- package/dist/to_stable.d.ts +3 -0
- package/dist/to_stable.js +170 -0
- package/package.json +3 -1
- package/dist/lang/lib/Malloy/MalloyTagLexer.d.ts +0 -42
- package/dist/lang/lib/Malloy/MalloyTagLexer.js +0 -385
- package/dist/lang/lib/Malloy/MalloyTagParser.d.ts +0 -180
- package/dist/lang/lib/Malloy/MalloyTagParser.js +0 -1051
- package/dist/lang/lib/Malloy/MalloyTagVisitor.d.ts +0 -120
- package/dist/lang/lib/Malloy/MalloyTagVisitor.js +0 -4
- package/dist/tags.d.ts +0 -72
- package/dist/tags.js +0 -512
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Tag } from '@malloydata/malloy-tag';
|
|
2
|
+
import { Annotation } from './model';
|
|
3
|
+
import { LogMessage } from './lang';
|
|
4
|
+
export interface TagParseSpec {
|
|
5
|
+
prefix?: RegExp;
|
|
6
|
+
extending?: Tag;
|
|
7
|
+
scopes?: Tag[];
|
|
8
|
+
}
|
|
9
|
+
export declare function addModelScope(spec: TagParseSpec | undefined, modelScope: Tag): TagParseSpec;
|
|
10
|
+
export declare function annotationToTaglines(annote: Annotation | undefined, prefix?: RegExp): string[];
|
|
11
|
+
export interface MalloyTagParse {
|
|
12
|
+
tag: Tag;
|
|
13
|
+
log: LogMessage[];
|
|
14
|
+
}
|
|
15
|
+
export declare function annotationToTag(annote: Annotation | undefined, spec?: TagParseSpec): MalloyTagParse;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.annotationToTag = exports.annotationToTaglines = exports.addModelScope = void 0;
|
|
4
|
+
const malloy_tag_1 = require("@malloydata/malloy-tag");
|
|
5
|
+
function addModelScope(spec, modelScope) {
|
|
6
|
+
const useSpec = spec ? { ...spec } : {};
|
|
7
|
+
if (useSpec.scopes) {
|
|
8
|
+
useSpec.scopes = useSpec.scopes.concat(modelScope);
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
useSpec.scopes = [modelScope];
|
|
12
|
+
}
|
|
13
|
+
return useSpec;
|
|
14
|
+
}
|
|
15
|
+
exports.addModelScope = addModelScope;
|
|
16
|
+
function annotationToTaglines(annote, prefix) {
|
|
17
|
+
annote || (annote = {});
|
|
18
|
+
const tagLines = annote.inherits
|
|
19
|
+
? annotationToTaglines(annote.inherits, prefix)
|
|
20
|
+
: [];
|
|
21
|
+
function prefixed(na) {
|
|
22
|
+
const ret = [];
|
|
23
|
+
for (const n of na || []) {
|
|
24
|
+
if (prefix === undefined || n.text.match(prefix)) {
|
|
25
|
+
ret.push(n.text);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return ret;
|
|
29
|
+
}
|
|
30
|
+
return tagLines.concat(prefixed(annote.blockNotes), prefixed(annote.notes));
|
|
31
|
+
}
|
|
32
|
+
exports.annotationToTaglines = annotationToTaglines;
|
|
33
|
+
function annotationToTag(annote, spec = {}) {
|
|
34
|
+
var _a;
|
|
35
|
+
let extending = spec.extending || new malloy_tag_1.Tag();
|
|
36
|
+
const prefix = spec.prefix || /^##? /;
|
|
37
|
+
annote || (annote = {});
|
|
38
|
+
const allErrs = [];
|
|
39
|
+
if (annote.inherits) {
|
|
40
|
+
const inherits = annotationToTag(annote.inherits, spec);
|
|
41
|
+
allErrs.push(...inherits.log);
|
|
42
|
+
extending = inherits.tag;
|
|
43
|
+
}
|
|
44
|
+
const allNotes = [];
|
|
45
|
+
if (annote.blockNotes) {
|
|
46
|
+
allNotes.push(...annote.blockNotes);
|
|
47
|
+
}
|
|
48
|
+
if (annote.notes) {
|
|
49
|
+
allNotes.push(...annote.notes);
|
|
50
|
+
}
|
|
51
|
+
const matchingNotes = [];
|
|
52
|
+
for (const note of allNotes) {
|
|
53
|
+
if (note.text.match(prefix)) {
|
|
54
|
+
matchingNotes.push(note);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
for (let i = 0; i < matchingNotes.length; i++) {
|
|
58
|
+
const note = matchingNotes[i];
|
|
59
|
+
if (note.text.match(prefix)) {
|
|
60
|
+
const noteParse = malloy_tag_1.Tag.fromTagLine(note.text, i, extending, ...((_a = spec.scopes) !== null && _a !== void 0 ? _a : []));
|
|
61
|
+
extending = noteParse.tag;
|
|
62
|
+
allErrs.push(...noteParse.log.map((e) => mapMalloyError(e, note)));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return { tag: extending, log: allErrs };
|
|
66
|
+
}
|
|
67
|
+
exports.annotationToTag = annotationToTag;
|
|
68
|
+
function mapMalloyError(e, note) {
|
|
69
|
+
const loc = {
|
|
70
|
+
line: note.at.range.start.line,
|
|
71
|
+
character: note.at.range.start.character + e.offset,
|
|
72
|
+
};
|
|
73
|
+
return {
|
|
74
|
+
code: 'tag-parse-error',
|
|
75
|
+
severity: 'error',
|
|
76
|
+
message: e.message,
|
|
77
|
+
at: {
|
|
78
|
+
url: note.at.url,
|
|
79
|
+
range: {
|
|
80
|
+
start: loc,
|
|
81
|
+
end: loc,
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=annotation.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -10,4 +10,5 @@ export type { QueryOptionsReader, RunSQLOptions } from './run_sql_options';
|
|
|
10
10
|
export type { EventStream, ModelString, ModelURL, QueryString, QueryURL, URLReader, InvalidationKey, } from './runtime_types';
|
|
11
11
|
export type { Connection, ConnectionConfig, ConnectionFactory, ConnectionParameter, ConnectionParameterValue, ConnectionConfigSchema, FetchSchemaOptions, InfoConnection, LookupConnection, PersistSQLResults, PooledConnection, TestableConnection, StreamingConnection, } from './connection/types';
|
|
12
12
|
export { toAsyncGenerator } from './connection_utils';
|
|
13
|
-
export {
|
|
13
|
+
export { modelDefToModelInfo } from './to_stable';
|
|
14
|
+
export { annotationToTag } from './annotation';
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InMemoryURLReader = exports.EmptyURLReader = exports.SingleConnectionRuntime = exports.ConnectionRuntime = exports.AtomicFieldType = exports.Runtime = exports.Malloy = exports.Model = exports.MalloyTranslator = exports.composeSQLExpr = exports.indent = exports.expressionIsUngroupedAggregate = exports.expressionIsScalar = exports.expressionIsCalculation = exports.expressionIsAnalytic = exports.expressionIsAggregate = exports.mkFieldDef = exports.mkArrayDef = exports.isScalarArray = exports.isRepeatedRecord = exports.isSamplingRows = exports.isSamplingPercent = exports.isSamplingEnable = exports.isJoinedSource = exports.isJoined = exports.isLeafAtomic = exports.Segment = exports.isSourceDef = exports.TinyParser = exports.Dialect = exports.spread = exports.literal = exports.variadicParam = exports.param = exports.makeParam = exports.sql = exports.maxScalar = exports.minAggregate = exports.anyExprType = exports.minScalar = exports.overload = exports.qtz = exports.arg = exports.registerDialect = exports.MySQLDialect = exports.SnowflakeDialect = exports.PostgresDialect = exports.TrinoDialect = exports.StandardSQLDialect = exports.DuckDBDialect = void 0;
|
|
4
|
-
exports.
|
|
4
|
+
exports.annotationToTag = exports.modelDefToModelInfo = exports.toAsyncGenerator = exports.CacheManager = exports.InMemoryModelCache = exports.Explore = exports.DataWriter = exports.Parse = exports.JSONWriter = exports.CSVWriter = exports.QueryMaterializer = exports.Result = exports.PreparedResult = exports.TimestampTimeframe = exports.DateTimeframe = exports.SourceRelationship = exports.JoinRelationship = exports.MalloyError = exports.FixedConnectionMap = void 0;
|
|
5
5
|
/*
|
|
6
6
|
* Copyright 2023 Google LLC
|
|
7
7
|
*
|
|
@@ -98,6 +98,8 @@ Object.defineProperty(exports, "InMemoryModelCache", { enumerable: true, get: fu
|
|
|
98
98
|
Object.defineProperty(exports, "CacheManager", { enumerable: true, get: function () { return malloy_1.CacheManager; } });
|
|
99
99
|
var connection_utils_1 = require("./connection_utils");
|
|
100
100
|
Object.defineProperty(exports, "toAsyncGenerator", { enumerable: true, get: function () { return connection_utils_1.toAsyncGenerator; } });
|
|
101
|
-
var
|
|
102
|
-
Object.defineProperty(exports, "
|
|
101
|
+
var to_stable_1 = require("./to_stable");
|
|
102
|
+
Object.defineProperty(exports, "modelDefToModelInfo", { enumerable: true, get: function () { return to_stable_1.modelDefToModelInfo; } });
|
|
103
|
+
var annotation_1 = require("./annotation");
|
|
104
|
+
Object.defineProperty(exports, "annotationToTag", { enumerable: true, get: function () { return annotation_1.annotationToTag; } });
|
|
103
105
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Note } from '../../../model/malloy_types';
|
|
2
|
-
import { Tag } from '
|
|
2
|
+
import { Tag } from '@malloydata/malloy-tag';
|
|
3
3
|
import { MessageLogger } from '../../parse-log';
|
|
4
4
|
import { Document, DocStatement, MalloyElement } from './malloy-element';
|
|
5
5
|
import { QueryPropertyInterface } from './query-property-interface';
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
*/
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
25
|
exports.ModelAnnotation = exports.ObjectAnnotation = void 0;
|
|
26
|
-
const tags_1 = require("../../../tags");
|
|
27
26
|
const malloy_element_1 = require("./malloy-element");
|
|
27
|
+
const annotation_1 = require("../../../annotation");
|
|
28
28
|
class ObjectAnnotation extends malloy_element_1.MalloyElement {
|
|
29
29
|
constructor(notes) {
|
|
30
30
|
super();
|
|
@@ -42,7 +42,7 @@ class ModelAnnotation extends ObjectAnnotation {
|
|
|
42
42
|
this.elementType = 'modelAnnotation';
|
|
43
43
|
}
|
|
44
44
|
getCompilerFlags(existing, logTo) {
|
|
45
|
-
const tagParse =
|
|
45
|
+
const tagParse = (0, annotation_1.annotationToTag)({ notes: this.notes }, {
|
|
46
46
|
prefix: /^##! /,
|
|
47
47
|
extending: existing,
|
|
48
48
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Annotation, DocumentLocation, DocumentReference, ModelDef, ModelAnnotation, NamedModelObject, Query, StructDef } from '../../../model/malloy_types';
|
|
2
|
-
import { Tag } from '
|
|
2
|
+
import { Tag } from '@malloydata/malloy-tag';
|
|
3
3
|
import { LogMessageOptions, MessageLogger, MessageParameterType, MessageCode } from '../../parse-log';
|
|
4
4
|
import { MalloyTranslation } from '../../parse-malloy';
|
|
5
5
|
import { ModelDataRequest } from '../../translate-response';
|
|
@@ -25,7 +25,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
25
25
|
exports.Document = exports.DocStatementList = exports.ListOf = exports.isDocStatementOrDocStatementList = exports.isDocStatement = exports.ExperimentalExperiment = exports.ModelEntryReference = exports.Unimplemented = exports.MalloyElement = void 0;
|
|
26
26
|
const dialect_1 = require("../../../dialect");
|
|
27
27
|
const malloy_types_1 = require("../../../model/malloy_types");
|
|
28
|
-
const
|
|
28
|
+
const malloy_tag_1 = require("@malloydata/malloy-tag");
|
|
29
29
|
const parse_log_1 = require("../../parse-log");
|
|
30
30
|
const ast_utils_1 = require("../ast-utils");
|
|
31
31
|
const dialect_name_space_1 = require("./dialect-name-space");
|
|
@@ -432,7 +432,7 @@ class Document extends MalloyElement {
|
|
|
432
432
|
this.queryList = [];
|
|
433
433
|
this.didInitModel = false;
|
|
434
434
|
this.annotation = {};
|
|
435
|
-
this.experiments = new
|
|
435
|
+
this.experiments = new malloy_tag_1.Tag({});
|
|
436
436
|
this.modelAnnotationTodoList = [];
|
|
437
437
|
this.dialectNameSpaces = new Map();
|
|
438
438
|
this.statements = new DocStatementList(statements);
|
|
@@ -10,7 +10,7 @@ import { FieldDeclarationConstructor } from './ast';
|
|
|
10
10
|
import { HasString, HasID } from './parse-utils';
|
|
11
11
|
import { CastType } from '../model';
|
|
12
12
|
import { AccessModifierLabel, DocumentLocation, DocumentRange, Note } from '../model/malloy_types';
|
|
13
|
-
import { Tag } from '
|
|
13
|
+
import { Tag } from '@malloydata/malloy-tag';
|
|
14
14
|
declare class ErrorNode extends ast.SourceQueryElement {
|
|
15
15
|
elementType: string;
|
|
16
16
|
}
|
|
@@ -55,7 +55,7 @@ const Interval_1 = require("antlr4ts/misc/Interval");
|
|
|
55
55
|
const ast_1 = require("./ast");
|
|
56
56
|
const parse_utils_1 = require("./parse-utils");
|
|
57
57
|
const malloy_types_1 = require("../model/malloy_types");
|
|
58
|
-
const
|
|
58
|
+
const malloy_tag_1 = require("@malloydata/malloy-tag");
|
|
59
59
|
const constant_expression_1 = require("./ast/expressions/constant-expression");
|
|
60
60
|
const utils_1 = require("./utils");
|
|
61
61
|
class ErrorNode extends ast.SourceQueryElement {
|
|
@@ -83,7 +83,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
83
83
|
this.msgLog = msgLog;
|
|
84
84
|
this.compilerFlags = compilerFlags;
|
|
85
85
|
for (const flag of DEFAULT_COMPILER_FLAGS) {
|
|
86
|
-
const withNewTag =
|
|
86
|
+
const withNewTag = malloy_tag_1.Tag.fromTagLine(flag, 0, this.compilerFlags);
|
|
87
87
|
this.compilerFlags = withNewTag.tag;
|
|
88
88
|
}
|
|
89
89
|
}
|
|
@@ -4,7 +4,7 @@ import { BaseMessageLogger, LogMessage, LogMessageOptions, MessageCode, MessageP
|
|
|
4
4
|
import { Zone, ZoneData } from './zone';
|
|
5
5
|
import { ReferenceList } from './reference-list';
|
|
6
6
|
import { ASTResponse, CompletionsResponse, DataRequestResponse, ProblemResponse, FatalResponse, FinalResponse, HelpContextResponse, MetadataResponse, ModelDataRequest, NeedURLData, TranslateResponse, ModelAnnotationResponse, TablePathResponse } from './translate-response';
|
|
7
|
-
import { Tag } from '
|
|
7
|
+
import { Tag } from '@malloydata/malloy-tag';
|
|
8
8
|
import { MalloyParseInfo } from './malloy-parse-info';
|
|
9
9
|
import { EventStream } from '../runtime_types';
|
|
10
10
|
export type StepResponses = DataRequestResponse | ASTResponse | TranslateResponse | ParseResponse | MetadataResponse | PretranslatedResponse;
|
|
@@ -61,9 +61,10 @@ const document_help_context_walker_1 = require("./parse-tree-walkers/document-he
|
|
|
61
61
|
const reference_list_1 = require("./reference-list");
|
|
62
62
|
const translate_response_1 = require("./translate-response");
|
|
63
63
|
const utils_1 = require("./utils");
|
|
64
|
-
const
|
|
64
|
+
const malloy_tag_1 = require("@malloydata/malloy-tag");
|
|
65
65
|
const model_annotation_walker_1 = require("./parse-tree-walkers/model-annotation-walker");
|
|
66
66
|
const find_table_path_walker_1 = require("./parse-tree-walkers/find-table-path-walker");
|
|
67
|
+
const annotation_1 = require("../annotation");
|
|
67
68
|
const malloy_error_strategy_1 = require("./syntax-errors/malloy-error-strategy");
|
|
68
69
|
const malloy_parser_error_listener_1 = require("./syntax-errors/malloy-parser-error-listener");
|
|
69
70
|
/**
|
|
@@ -470,7 +471,7 @@ class TranslateStep {
|
|
|
470
471
|
}
|
|
471
472
|
// begin with the compiler flags of the model we are extending
|
|
472
473
|
if (extendingModel && !this.importedAnnotations) {
|
|
473
|
-
const tagParse =
|
|
474
|
+
const tagParse = (0, annotation_1.annotationToTag)(extendingModel.annotation, {
|
|
474
475
|
prefix: /^##! /,
|
|
475
476
|
});
|
|
476
477
|
that.compilerFlags = tagParse.tag;
|
|
@@ -530,7 +531,7 @@ class MalloyTranslation {
|
|
|
530
531
|
this.grammarRule = grammarRule;
|
|
531
532
|
this.sqlSources = [];
|
|
532
533
|
this.imports = [];
|
|
533
|
-
this.compilerFlags = new
|
|
534
|
+
this.compilerFlags = new malloy_tag_1.Tag();
|
|
534
535
|
this._urlIsFullPath = undefined;
|
|
535
536
|
/*
|
|
536
537
|
Experimental dialect support, not confident this is how this should work.
|
|
@@ -14,17 +14,6 @@ export type HasString = {
|
|
|
14
14
|
};
|
|
15
15
|
type StringPart = ParserRuleContext | string;
|
|
16
16
|
export declare function getStringParts(cx: SqlStringContext): Generator<StringPart>;
|
|
17
|
-
/**
|
|
18
|
-
* Parses the interior of a string, doing all \ substitutions. In most cases
|
|
19
|
-
* a lexical analyzer has already recognized this as a string. As a convenience,
|
|
20
|
-
* strip off the quoting outer chartacters if asked, then parse the interior of
|
|
21
|
-
* the string. The intention is to be compatible with JSON strings, in terms
|
|
22
|
-
* of which \X substitutions are processed.
|
|
23
|
-
* @param str is the string to parse
|
|
24
|
-
* @param surround is the quoting character, default means quotes already stripped
|
|
25
|
-
* @returns a string with the \ processing completed
|
|
26
|
-
*/
|
|
27
|
-
export declare function parseString(str: string, surround?: string): string;
|
|
28
17
|
export type HasID = ParserRuleContext & {
|
|
29
18
|
id: () => IdContext;
|
|
30
19
|
};
|
package/dist/lang/parse-utils.js
CHANGED
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.getPlainString = exports.unIndent = exports.getOptionalId = exports.idToStr = exports.getId = exports.
|
|
25
|
+
exports.getPlainString = exports.unIndent = exports.getOptionalId = exports.idToStr = exports.getId = exports.getStringParts = exports.getStringIfShort = exports.getShortString = void 0;
|
|
26
|
+
const malloy_tag_1 = require("@malloydata/malloy-tag");
|
|
26
27
|
/**
|
|
27
28
|
* Take the text of a matched string, including the matching quote
|
|
28
29
|
* characters, and return the actual contents of the string after
|
|
@@ -34,7 +35,7 @@ function getShortString(scx) {
|
|
|
34
35
|
var _a, _b;
|
|
35
36
|
const str = ((_a = scx.DQ_STRING()) === null || _a === void 0 ? void 0 : _a.text) || ((_b = scx.SQ_STRING()) === null || _b === void 0 ? void 0 : _b.text);
|
|
36
37
|
if (str) {
|
|
37
|
-
return parseString(str, str[0]);
|
|
38
|
+
return malloy_tag_1.ParseUtil.parseString(str, str[0]);
|
|
38
39
|
}
|
|
39
40
|
// shortString: DQ_STRING | SQ_STRING; So this will never happen
|
|
40
41
|
return '';
|
|
@@ -66,85 +67,6 @@ function* getStringParts(cx) {
|
|
|
66
67
|
}
|
|
67
68
|
}
|
|
68
69
|
exports.getStringParts = getStringParts;
|
|
69
|
-
var ParseState;
|
|
70
|
-
(function (ParseState) {
|
|
71
|
-
ParseState[ParseState["Normal"] = 0] = "Normal";
|
|
72
|
-
ParseState[ParseState["ReverseVirgule"] = 1] = "ReverseVirgule";
|
|
73
|
-
ParseState[ParseState["Unicode"] = 2] = "Unicode";
|
|
74
|
-
})(ParseState || (ParseState = {}));
|
|
75
|
-
/**
|
|
76
|
-
* Parses the interior of a string, doing all \ substitutions. In most cases
|
|
77
|
-
* a lexical analyzer has already recognized this as a string. As a convenience,
|
|
78
|
-
* strip off the quoting outer chartacters if asked, then parse the interior of
|
|
79
|
-
* the string. The intention is to be compatible with JSON strings, in terms
|
|
80
|
-
* of which \X substitutions are processed.
|
|
81
|
-
* @param str is the string to parse
|
|
82
|
-
* @param surround is the quoting character, default means quotes already stripped
|
|
83
|
-
* @returns a string with the \ processing completed
|
|
84
|
-
*/
|
|
85
|
-
function parseString(str, surround = '') {
|
|
86
|
-
let inner = str.slice(surround.length);
|
|
87
|
-
let state = ParseState.Normal;
|
|
88
|
-
if (surround.length) {
|
|
89
|
-
inner = inner.slice(0, -surround.length);
|
|
90
|
-
}
|
|
91
|
-
let out = '';
|
|
92
|
-
let unicode = '';
|
|
93
|
-
for (const c of inner) {
|
|
94
|
-
switch (state) {
|
|
95
|
-
case ParseState.Normal: {
|
|
96
|
-
if (c === '\\') {
|
|
97
|
-
state = ParseState.ReverseVirgule;
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
out += c;
|
|
101
|
-
}
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
case ParseState.ReverseVirgule: {
|
|
105
|
-
let outc = c;
|
|
106
|
-
if (c === 'u') {
|
|
107
|
-
state = ParseState.Unicode;
|
|
108
|
-
unicode = '';
|
|
109
|
-
continue;
|
|
110
|
-
}
|
|
111
|
-
if (c === 'b') {
|
|
112
|
-
outc = '\b';
|
|
113
|
-
}
|
|
114
|
-
else if (c === 'f') {
|
|
115
|
-
outc = '\f';
|
|
116
|
-
}
|
|
117
|
-
else if (c === 'n') {
|
|
118
|
-
outc = '\n';
|
|
119
|
-
}
|
|
120
|
-
else if (c === 'r') {
|
|
121
|
-
outc = '\r';
|
|
122
|
-
}
|
|
123
|
-
else if (c === 't') {
|
|
124
|
-
outc = '\t';
|
|
125
|
-
}
|
|
126
|
-
out += outc;
|
|
127
|
-
state = ParseState.Normal;
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
case ParseState.Unicode: {
|
|
131
|
-
if ('ABCDEFabcdef0123456789'.includes(c)) {
|
|
132
|
-
unicode += c;
|
|
133
|
-
if (unicode.length === 4) {
|
|
134
|
-
out += String.fromCharCode(parseInt(unicode, 16));
|
|
135
|
-
state = ParseState.Normal;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
// Don't think we ever get here ...
|
|
140
|
-
state = ParseState.Normal;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
return out;
|
|
146
|
-
}
|
|
147
|
-
exports.parseString = parseString;
|
|
148
70
|
/**
|
|
149
71
|
* An identifier is either a sequence of id characters or a `quoted`
|
|
150
72
|
* This parses either to simply the resulting text.
|
|
@@ -158,7 +80,7 @@ exports.getId = getId;
|
|
|
158
80
|
function idToStr(cx) {
|
|
159
81
|
const quoted = cx.BQ_STRING();
|
|
160
82
|
if (quoted) {
|
|
161
|
-
return parseString(quoted.text, '`');
|
|
83
|
+
return malloy_tag_1.ParseUtil.parseString(quoted.text, '`');
|
|
162
84
|
}
|
|
163
85
|
return cx.text;
|
|
164
86
|
}
|
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
*/
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
25
|
const test_translator_1 = require("./test-translator");
|
|
26
|
-
const parse_utils_1 = require("../parse-utils");
|
|
27
26
|
require("./parse-expects");
|
|
28
27
|
const granular_result_1 = require("../ast/types/granular-result");
|
|
29
28
|
describe('literals', () => {
|
|
@@ -154,39 +153,6 @@ describe('literals', () => {
|
|
|
154
153
|
test('regex', () => {
|
|
155
154
|
expect((0, test_translator_1.expr) `r'RegularExpression'`).toTranslate();
|
|
156
155
|
});
|
|
157
|
-
describe('quote comprehension inside strings', () => {
|
|
158
|
-
test('\\b', () => {
|
|
159
|
-
expect((0, parse_utils_1.parseString)('\\b')).toEqual('\b');
|
|
160
|
-
});
|
|
161
|
-
test('\\f', () => {
|
|
162
|
-
expect((0, parse_utils_1.parseString)('\\f')).toEqual('\f');
|
|
163
|
-
});
|
|
164
|
-
test('\\n', () => {
|
|
165
|
-
expect((0, parse_utils_1.parseString)('\\n')).toEqual('\n');
|
|
166
|
-
});
|
|
167
|
-
test('\\r', () => {
|
|
168
|
-
expect((0, parse_utils_1.parseString)('\\r')).toEqual('\r');
|
|
169
|
-
});
|
|
170
|
-
test('\\t', () => {
|
|
171
|
-
expect((0, parse_utils_1.parseString)('\\t')).toEqual('\t');
|
|
172
|
-
});
|
|
173
|
-
test('unicode ?', () => {
|
|
174
|
-
expect((0, parse_utils_1.parseString)('\\u003f')).toEqual('?');
|
|
175
|
-
expect((0, parse_utils_1.parseString)('\\u003F')).toEqual('?');
|
|
176
|
-
});
|
|
177
|
-
test('normal stuff', () => {
|
|
178
|
-
expect((0, parse_utils_1.parseString)('normal stuff')).toEqual('normal stuff');
|
|
179
|
-
});
|
|
180
|
-
test('stuff & nonsense', () => {
|
|
181
|
-
expect((0, parse_utils_1.parseString)('stuff \\u0026 nonsense')).toEqual('stuff & nonsense');
|
|
182
|
-
});
|
|
183
|
-
test('one thing\\nnext thing', () => {
|
|
184
|
-
expect((0, parse_utils_1.parseString)('one thing\\nnext thing')).toEqual('one thing\nnext thing');
|
|
185
|
-
});
|
|
186
|
-
test('quote stripping works', () => {
|
|
187
|
-
expect((0, parse_utils_1.parseString)('|42|', '|')).toEqual('42');
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
156
|
describe('string parsing in language', () => {
|
|
191
157
|
const tz = 'America/Mexico_City';
|
|
192
158
|
test('multi-line indent increasing', () => {
|
package/dist/malloy.d.ts
CHANGED
|
@@ -6,9 +6,14 @@ import { DocumentHelpContext } from './lang/parse-tree-walkers/document-help-con
|
|
|
6
6
|
import { CompiledQuery, DocumentLocation, DocumentReference, BooleanFieldDef, JSONFieldDef, NumberFieldDef, StringFieldDef, FilterCondition, Query as InternalQuery, ModelDef, DocumentPosition as ModelDocumentPosition, NamedQuery, QueryData, QueryDataRow, QueryResult, SearchIndexResult, SearchValueMapResult, StructDef, TurtleDef, NativeUnsupportedFieldDef, QueryRunStats, ImportLocation, Annotation, SQLSentence, SQLSourceDef, AtomicFieldDef, DateFieldDef, TimestampFieldDef, SourceDef, QueryToMaterialize } from './model';
|
|
7
7
|
import { EventStream, InvalidationKey, ModelString, ModelURL, QueryString, QueryURL, URLReader } from './runtime_types';
|
|
8
8
|
import { Connection, FetchSchemaOptions, InfoConnection, LookupConnection } from './connection/types';
|
|
9
|
-
import { Tag
|
|
9
|
+
import { Tag } from '@malloydata/malloy-tag';
|
|
10
10
|
import { Dialect } from './dialect';
|
|
11
11
|
import { PathInfo } from './lang/parse-tree-walkers/find-table-path-walker';
|
|
12
|
+
import { MalloyTagParse, TagParseSpec } from './annotation';
|
|
13
|
+
export interface Taggable {
|
|
14
|
+
tagParse: (spec?: TagParseSpec) => MalloyTagParse;
|
|
15
|
+
getTaglines: (prefix?: RegExp) => string[];
|
|
16
|
+
}
|
|
12
17
|
export interface Loggable {
|
|
13
18
|
debug: (message?: any, ...optionalParams: any[]) => void;
|
|
14
19
|
info: (message?: any, ...optionalParams: any[]) => void;
|
|
@@ -185,7 +190,7 @@ export declare class Model implements Taggable {
|
|
|
185
190
|
_referenceAt: (location: ModelDocumentPosition) => DocumentReference | undefined;
|
|
186
191
|
_importAt: (location: ModelDocumentPosition) => ImportLocation | undefined;
|
|
187
192
|
constructor(modelDef: ModelDef, problems: LogMessage[], fromSources: string[], referenceAt?: (location: ModelDocumentPosition) => DocumentReference | undefined, importAt?: (location: ModelDocumentPosition) => ImportLocation | undefined);
|
|
188
|
-
tagParse(spec?: TagParseSpec):
|
|
193
|
+
tagParse(spec?: TagParseSpec): MalloyTagParse;
|
|
189
194
|
getTaglines(prefix?: RegExp): string[];
|
|
190
195
|
/**
|
|
191
196
|
* Retrieve a document reference for the token at the given position within
|
|
@@ -260,7 +265,7 @@ export declare class PreparedQuery implements Taggable {
|
|
|
260
265
|
_modelDef: ModelDef;
|
|
261
266
|
_query: InternalQuery | NamedQuery;
|
|
262
267
|
constructor(query: InternalQuery, model: ModelDef, problems: LogMessage[], name?: string | undefined);
|
|
263
|
-
tagParse(spec?: TagParseSpec):
|
|
268
|
+
tagParse(spec?: TagParseSpec): MalloyTagParse;
|
|
264
269
|
getTaglines(prefix?: RegExp): string[];
|
|
265
270
|
/**
|
|
266
271
|
* Generate the SQL for this query.
|
|
@@ -457,7 +462,7 @@ export declare class PreparedResult implements Taggable {
|
|
|
457
462
|
protected inner: CompiledQuery;
|
|
458
463
|
constructor(query: CompiledQuery, modelDef: ModelDef);
|
|
459
464
|
static fromJson({ query, modelDef, }: PreparedResultJSON): PreparedResult;
|
|
460
|
-
tagParse(spec?: TagParseSpec):
|
|
465
|
+
tagParse(spec?: TagParseSpec): MalloyTagParse;
|
|
461
466
|
getTaglines(prefix?: RegExp): string[];
|
|
462
467
|
get annotation(): Annotation | undefined;
|
|
463
468
|
get modelAnnotation(): Annotation | undefined;
|
|
@@ -587,7 +592,7 @@ export declare class Explore extends Entity implements Taggable {
|
|
|
587
592
|
get source(): Explore | undefined;
|
|
588
593
|
isIntrinsic(): boolean;
|
|
589
594
|
isExploreField(): this is ExploreField;
|
|
590
|
-
tagParse(spec?: TagParseSpec):
|
|
595
|
+
tagParse(spec?: TagParseSpec): MalloyTagParse;
|
|
591
596
|
getTaglines(prefix?: RegExp): string[];
|
|
592
597
|
private parsedModelTag?;
|
|
593
598
|
get modelTag(): Tag;
|
|
@@ -632,7 +637,7 @@ export declare class AtomicField extends Entity implements Taggable {
|
|
|
632
637
|
protected parent: Explore;
|
|
633
638
|
constructor(fieldTypeDef: AtomicFieldDef, parent: Explore, source?: AtomicField);
|
|
634
639
|
get type(): AtomicFieldType;
|
|
635
|
-
tagParse(spec?: TagParseSpec):
|
|
640
|
+
tagParse(spec?: TagParseSpec): MalloyTagParse;
|
|
636
641
|
getTaglines(prefix?: RegExp): string[];
|
|
637
642
|
isIntrinsic(): boolean;
|
|
638
643
|
isQueryField(): this is QueryField;
|
|
@@ -723,7 +728,7 @@ export declare class Query extends Entity {
|
|
|
723
728
|
export declare class QueryField extends Query implements Taggable {
|
|
724
729
|
protected parent: Explore;
|
|
725
730
|
constructor(turtleDef: TurtleDef, parent: Explore, source?: Query);
|
|
726
|
-
tagParse(spec?: TagParseSpec):
|
|
731
|
+
tagParse(spec?: TagParseSpec): MalloyTagParse;
|
|
727
732
|
getTaglines(prefix?: RegExp): string[];
|
|
728
733
|
isQueryField(): this is QueryField;
|
|
729
734
|
isExploreField(): this is ExploreField;
|
|
@@ -744,7 +749,7 @@ export declare class ExploreField extends Explore {
|
|
|
744
749
|
get joinRelationship(): JoinRelationship;
|
|
745
750
|
get isRecord(): boolean;
|
|
746
751
|
get isArray(): boolean;
|
|
747
|
-
tagParse(spec?: TagParseSpec):
|
|
752
|
+
tagParse(spec?: TagParseSpec): MalloyTagParse;
|
|
748
753
|
isQueryField(): this is QueryField;
|
|
749
754
|
isExploreField(): this is ExploreField;
|
|
750
755
|
isAtomicField(): this is AtomicField;
|
package/dist/malloy.js
CHANGED
|
@@ -26,10 +26,10 @@ exports.InMemoryModelCache = exports.CacheManager = exports.CSVWriter = exports.
|
|
|
26
26
|
const lang_1 = require("./lang");
|
|
27
27
|
const model_1 = require("./model");
|
|
28
28
|
const luxon_1 = require("luxon");
|
|
29
|
-
const tags_1 = require("./tags");
|
|
30
29
|
const dialect_1 = require("./dialect");
|
|
31
30
|
const version_1 = require("./version");
|
|
32
31
|
const uuid_1 = require("uuid");
|
|
32
|
+
const annotation_1 = require("./annotation");
|
|
33
33
|
const MALLOY_INTERNAL_URL = 'internal://internal.malloy';
|
|
34
34
|
class Malloy {
|
|
35
35
|
static get version() {
|
|
@@ -446,10 +446,10 @@ class Model {
|
|
|
446
446
|
this._importAt = importAt;
|
|
447
447
|
}
|
|
448
448
|
tagParse(spec) {
|
|
449
|
-
return
|
|
449
|
+
return (0, annotation_1.annotationToTag)(this.modelDef.annotation, spec);
|
|
450
450
|
}
|
|
451
451
|
getTaglines(prefix) {
|
|
452
|
-
return
|
|
452
|
+
return (0, annotation_1.annotationToTaglines)(this.modelDef.annotation, prefix);
|
|
453
453
|
}
|
|
454
454
|
/**
|
|
455
455
|
* Retrieve a document reference for the token at the given position within
|
|
@@ -569,12 +569,12 @@ class PreparedQuery {
|
|
|
569
569
|
this._modelDef = model;
|
|
570
570
|
}
|
|
571
571
|
tagParse(spec) {
|
|
572
|
-
const modelScope =
|
|
573
|
-
spec =
|
|
574
|
-
return
|
|
572
|
+
const modelScope = (0, annotation_1.annotationToTag)(this._modelDef.annotation).tag;
|
|
573
|
+
spec = (0, annotation_1.addModelScope)(spec, modelScope);
|
|
574
|
+
return (0, annotation_1.annotationToTag)(this._query.annotation, spec);
|
|
575
575
|
}
|
|
576
576
|
getTaglines(prefix) {
|
|
577
|
-
return
|
|
577
|
+
return (0, annotation_1.annotationToTaglines)(this._query.annotation, prefix);
|
|
578
578
|
}
|
|
579
579
|
/**
|
|
580
580
|
* Generate the SQL for this query.
|
|
@@ -831,12 +831,12 @@ class PreparedResult {
|
|
|
831
831
|
return new PreparedResult(query, modelDef);
|
|
832
832
|
}
|
|
833
833
|
tagParse(spec) {
|
|
834
|
-
const modelScope =
|
|
835
|
-
spec =
|
|
836
|
-
return
|
|
834
|
+
const modelScope = (0, annotation_1.annotationToTag)(this.modelDef.annotation).tag;
|
|
835
|
+
spec = (0, annotation_1.addModelScope)(spec, modelScope);
|
|
836
|
+
return (0, annotation_1.annotationToTag)(this.inner.annotation, spec);
|
|
837
837
|
}
|
|
838
838
|
getTaglines(prefix) {
|
|
839
|
-
return
|
|
839
|
+
return (0, annotation_1.annotationToTaglines)(this.inner.annotation, prefix);
|
|
840
840
|
}
|
|
841
841
|
get annotation() {
|
|
842
842
|
return this.inner.annotation;
|
|
@@ -845,7 +845,7 @@ class PreparedResult {
|
|
|
845
845
|
return this.modelDef.annotation;
|
|
846
846
|
}
|
|
847
847
|
get modelTag() {
|
|
848
|
-
return
|
|
848
|
+
return (0, annotation_1.annotationToTag)(this.modelDef.annotation).tag;
|
|
849
849
|
}
|
|
850
850
|
/**
|
|
851
851
|
* @return The name of the connection this query should be run against.
|
|
@@ -1096,13 +1096,13 @@ class Explore extends Entity {
|
|
|
1096
1096
|
return false;
|
|
1097
1097
|
}
|
|
1098
1098
|
tagParse(spec) {
|
|
1099
|
-
return
|
|
1099
|
+
return (0, annotation_1.annotationToTag)(this._structDef.annotation, spec);
|
|
1100
1100
|
}
|
|
1101
1101
|
getTaglines(prefix) {
|
|
1102
|
-
return
|
|
1102
|
+
return (0, annotation_1.annotationToTaglines)(this._structDef.annotation, prefix);
|
|
1103
1103
|
}
|
|
1104
1104
|
get modelTag() {
|
|
1105
|
-
this.parsedModelTag || (this.parsedModelTag =
|
|
1105
|
+
this.parsedModelTag || (this.parsedModelTag = (0, annotation_1.annotationToTag)(this._structDef.modelAnnotation).tag);
|
|
1106
1106
|
return this.parsedModelTag;
|
|
1107
1107
|
}
|
|
1108
1108
|
/**
|
|
@@ -1343,11 +1343,11 @@ class AtomicField extends Entity {
|
|
|
1343
1343
|
}
|
|
1344
1344
|
}
|
|
1345
1345
|
tagParse(spec) {
|
|
1346
|
-
spec =
|
|
1347
|
-
return
|
|
1346
|
+
spec = (0, annotation_1.addModelScope)(spec, this.parent.modelTag);
|
|
1347
|
+
return (0, annotation_1.annotationToTag)(this.fieldTypeDef.annotation, spec);
|
|
1348
1348
|
}
|
|
1349
1349
|
getTaglines(prefix) {
|
|
1350
|
-
return
|
|
1350
|
+
return (0, annotation_1.annotationToTaglines)(this.fieldTypeDef.annotation, prefix);
|
|
1351
1351
|
}
|
|
1352
1352
|
isIntrinsic() {
|
|
1353
1353
|
return (0, model_1.fieldIsIntrinsic)(this.fieldTypeDef);
|
|
@@ -1573,11 +1573,11 @@ class QueryField extends Query {
|
|
|
1573
1573
|
this.parent = parent;
|
|
1574
1574
|
}
|
|
1575
1575
|
tagParse(spec) {
|
|
1576
|
-
spec =
|
|
1577
|
-
return
|
|
1576
|
+
spec = (0, annotation_1.addModelScope)(spec, this.parent.modelTag);
|
|
1577
|
+
return (0, annotation_1.annotationToTag)(this.turtleDef.annotation, spec);
|
|
1578
1578
|
}
|
|
1579
1579
|
getTaglines(prefix) {
|
|
1580
|
-
return
|
|
1580
|
+
return (0, annotation_1.annotationToTaglines)(this.turtleDef.annotation, prefix);
|
|
1581
1581
|
}
|
|
1582
1582
|
isQueryField() {
|
|
1583
1583
|
return true;
|
|
@@ -1633,8 +1633,8 @@ class ExploreField extends Explore {
|
|
|
1633
1633
|
return this.joinRelationship !== JoinRelationship.OneToOne;
|
|
1634
1634
|
}
|
|
1635
1635
|
tagParse(spec) {
|
|
1636
|
-
spec =
|
|
1637
|
-
return
|
|
1636
|
+
spec = (0, annotation_1.addModelScope)(spec, this._parentExplore.modelTag);
|
|
1637
|
+
return (0, annotation_1.annotationToTag)(this._structDef.annotation, spec);
|
|
1638
1638
|
}
|
|
1639
1639
|
isQueryField() {
|
|
1640
1640
|
return false;
|