@malloydata/malloy 0.0.55-dev230707013046 → 0.0.55-dev230707183945

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.
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2023 Google LLC
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining
6
+ * a copy of this software and associated documentation files
7
+ * (the "Software"), to deal in the Software without restriction,
8
+ * including without limitation the rights to use, copy, modify, merge,
9
+ * publish, distribute, sublicense, and/or sell copies of the Software,
10
+ * and to permit persons to whom the Software is furnished to do so,
11
+ * subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be
14
+ * included in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ */
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.parseString = void 0;
26
+ var ParseState;
27
+ (function (ParseState) {
28
+ ParseState[ParseState["Normal"] = 0] = "Normal";
29
+ ParseState[ParseState["ReverseVirgule"] = 1] = "ReverseVirgule";
30
+ ParseState[ParseState["Unicode"] = 2] = "Unicode";
31
+ })(ParseState || (ParseState = {}));
32
+ /**
33
+ * Parses the interior of a string, doing all \ substitutions. In most cases
34
+ * a lexical analyzer has already recognized this as a string. As a convenience,
35
+ * strip off the quoting outer chartacters if asked, then parse the interior of
36
+ * the string. The intention is to be compatible with JSON strings, in terms
37
+ * of which \X substitutions are processed.
38
+ * @param str is the string to parse
39
+ * @param surround is the quoting character, default means quotes already stripped
40
+ * @returns a string with the \ processing completed
41
+ */
42
+ function parseString(str, surround = '') {
43
+ let inner = str.slice(surround.length);
44
+ let state = ParseState.Normal;
45
+ if (surround.length) {
46
+ inner = inner.slice(0, -surround.length);
47
+ }
48
+ let out = '';
49
+ let unicode = '';
50
+ for (const c of inner) {
51
+ switch (state) {
52
+ case ParseState.Normal: {
53
+ if (c === '\\') {
54
+ state = ParseState.ReverseVirgule;
55
+ }
56
+ else {
57
+ out += c;
58
+ }
59
+ break;
60
+ }
61
+ case ParseState.ReverseVirgule: {
62
+ let outc = c;
63
+ if (c === 'u') {
64
+ state = ParseState.Unicode;
65
+ unicode = '';
66
+ continue;
67
+ }
68
+ if (c === 'b') {
69
+ outc = '\b';
70
+ }
71
+ else if (c === 'f') {
72
+ outc = '\f';
73
+ }
74
+ else if (c === 'n') {
75
+ outc = '\n';
76
+ }
77
+ else if (c === 'r') {
78
+ outc = '\r';
79
+ }
80
+ else if (c === 't') {
81
+ outc = '\t';
82
+ }
83
+ out += outc;
84
+ state = ParseState.Normal;
85
+ break;
86
+ }
87
+ case ParseState.Unicode: {
88
+ if ('ABCDEFabcdef0123456789'.includes(c)) {
89
+ unicode += c;
90
+ if (unicode.length === 4) {
91
+ out += String.fromCharCode(parseInt(unicode, 16));
92
+ state = ParseState.Normal;
93
+ }
94
+ }
95
+ else {
96
+ // Don't think we ever get here ...
97
+ state = ParseState.Normal;
98
+ }
99
+ }
100
+ }
101
+ }
102
+ return out;
103
+ }
104
+ exports.parseString = parseString;
105
+ //# sourceMappingURL=string-parser.js.map
@@ -1106,7 +1106,10 @@ describe('literals', () => {
1106
1106
  expect((0, test_translator_1.expr) `42`).toTranslate();
1107
1107
  });
1108
1108
  test('string', () => {
1109
- expect((0, test_translator_1.expr) `'fortywo-two'`).toTranslate();
1109
+ const m = new test_translator_1.BetaExpression("'forty two'");
1110
+ expect(m).toTranslate();
1111
+ const m42 = m.generated().value[0];
1112
+ expect(m42).toMatchObject({ literal: 'forty two' });
1110
1113
  });
1111
1114
  test('string with quoted quote', () => {
1112
1115
  const str = "'Isn" + '\\' + "'t this nice'";
@@ -2785,6 +2788,34 @@ describe('sql expressions', () => {
2785
2788
  expect(m).toTranslate();
2786
2789
  }
2787
2790
  });
2791
+ test('sql expression legal with single quote', () => {
2792
+ const m = (0, test_translator_1.model) `
2793
+ source: na is bigquery.sql('SELECT 1 as one')
2794
+ `;
2795
+ expect(m).toParse();
2796
+ const compileSql = m.translator.translate().compileSQL;
2797
+ expect(compileSql).toBeDefined();
2798
+ if (compileSql) {
2799
+ m.translator.update({
2800
+ compileSQL: { [compileSql.name]: getSelectOneStruct(compileSql) },
2801
+ });
2802
+ expect(m).toTranslate();
2803
+ }
2804
+ });
2805
+ test('sql expression legal with double quote', () => {
2806
+ const m = (0, test_translator_1.model) `
2807
+ source: na is bigquery.sql("SELECT 1 as one")
2808
+ `;
2809
+ expect(m).toParse();
2810
+ const compileSql = m.translator.translate().compileSQL;
2811
+ expect(compileSql).toBeDefined();
2812
+ if (compileSql) {
2813
+ m.translator.update({
2814
+ compileSQL: { [compileSql.name]: getSelectOneStruct(compileSql) },
2815
+ });
2816
+ expect(m).toTranslate();
2817
+ }
2818
+ });
2788
2819
  test('reference to sql expression in extended source', () => {
2789
2820
  const m = (0, test_translator_1.model) `
2790
2821
  source: na is bigquery.sql("""SELECT 1 as one""") {
@@ -0,0 +1 @@
1
+ import './parse-expects';
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2023 Google LLC
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining
6
+ * a copy of this software and associated documentation files
7
+ * (the "Software"), to deal in the Software without restriction,
8
+ * including without limitation the rights to use, copy, modify, merge,
9
+ * publish, distribute, sublicense, and/or sell copies of the Software,
10
+ * and to permit persons to whom the Software is furnished to do so,
11
+ * subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be
14
+ * included in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ */
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ require("./parse-expects");
26
+ const string_parser_1 = require("../string-parser");
27
+ describe('test internal string parsing', () => {
28
+ test('\\b', () => {
29
+ expect((0, string_parser_1.parseString)('\\b')).toEqual('\b');
30
+ });
31
+ test('\\f', () => {
32
+ expect((0, string_parser_1.parseString)('\\f')).toEqual('\f');
33
+ });
34
+ test('\\n', () => {
35
+ expect((0, string_parser_1.parseString)('\\n')).toEqual('\n');
36
+ });
37
+ test('\\r', () => {
38
+ expect((0, string_parser_1.parseString)('\\r')).toEqual('\r');
39
+ });
40
+ test('\\t', () => {
41
+ expect((0, string_parser_1.parseString)('\\t')).toEqual('\t');
42
+ });
43
+ test('unicode ?', () => {
44
+ expect((0, string_parser_1.parseString)('\\u003f')).toEqual('?');
45
+ expect((0, string_parser_1.parseString)('\\u003F')).toEqual('?');
46
+ });
47
+ test('normal stuff', () => {
48
+ expect((0, string_parser_1.parseString)('normal stuff')).toEqual('normal stuff');
49
+ });
50
+ test('stuff & nonsense', () => {
51
+ expect((0, string_parser_1.parseString)('stuff \\u0026 nonsense')).toEqual('stuff & nonsense');
52
+ });
53
+ test('one thing\\nnext thing', () => {
54
+ expect((0, string_parser_1.parseString)('one thing\\nnext thing')).toEqual('one thing\nnext thing');
55
+ });
56
+ test('quote stripping works', () => {
57
+ expect((0, string_parser_1.parseString)('|42|', '|')).toEqual('42');
58
+ });
59
+ });
60
+ //# sourceMappingURL=strings.spec.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloy",
3
- "version": "0.0.55-dev230707013046",
3
+ "version": "0.0.55-dev230707183945",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",