@malloydata/malloy 0.0.55 → 0.0.56-dev230707230009

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.
@@ -22,7 +22,53 @@
22
22
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  */
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.parseString = void 0;
25
+ exports.getOptionalId = exports.getId = exports.getIsNotes = exports.getNotes = exports.parseString = exports.getStringParts = exports.getStringIfShort = exports.getShortString = void 0;
26
+ /**
27
+ * Take the text of a matched string, including the matching quote
28
+ * characters, and return the actual contents of the string after
29
+ * \ processing.
30
+ * @param cx Any parse context which contains a string
31
+ * @returns Decocded string
32
+ */
33
+ function getShortString(scx) {
34
+ var _a, _b;
35
+ 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
+ if (str) {
37
+ return parseString(str, str[0]);
38
+ }
39
+ // shortString: DQ_STRING | SQ_STRING; So this will never happen
40
+ return '';
41
+ }
42
+ exports.getShortString = getShortString;
43
+ function getStringIfShort(cx) {
44
+ const scx = cx.string().shortString();
45
+ if (scx) {
46
+ return getShortString(scx);
47
+ }
48
+ }
49
+ exports.getStringIfShort = getStringIfShort;
50
+ function getStringParts(cx) {
51
+ var _a;
52
+ if (cx) {
53
+ const strParts = [];
54
+ for (const part of cx.sqlInterpolation()) {
55
+ const upToOpen = part.OPEN_CODE().text;
56
+ if (upToOpen.length > 2) {
57
+ strParts.push(upToOpen.slice(0, upToOpen.length - 2));
58
+ }
59
+ if (part.query()) {
60
+ strParts.push(part.query());
61
+ }
62
+ }
63
+ const lastChars = (_a = cx.SQL_END()) === null || _a === void 0 ? void 0 : _a.text.slice(0, -3);
64
+ if (lastChars && lastChars.length > 0) {
65
+ strParts.push(lastChars);
66
+ }
67
+ return strParts;
68
+ }
69
+ return [];
70
+ }
71
+ exports.getStringParts = getStringParts;
26
72
  var ParseState;
27
73
  (function (ParseState) {
28
74
  ParseState[ParseState["Normal"] = 0] = "Normal";
@@ -102,4 +148,41 @@ function parseString(str, surround = '') {
102
148
  return out;
103
149
  }
104
150
  exports.parseString = parseString;
105
- //# sourceMappingURL=string-parser.js.map
151
+ /**
152
+ * Get all the possibly missing annotations from this parse rule
153
+ * @param cx Any parse context which has an ANNOTATION* rules
154
+ * @returns Array of texts for the annotations
155
+ */
156
+ function getNotes(cx) {
157
+ return cx.ANNOTATION().map(a => a.text);
158
+ }
159
+ exports.getNotes = getNotes;
160
+ function getIsNotes(cx) {
161
+ const before = getNotes(cx._beforeIs);
162
+ return before.concat(getNotes(cx._afterIs));
163
+ }
164
+ exports.getIsNotes = getIsNotes;
165
+ /**
166
+ * An identifier is either a sequence of id characters or a `quoted`
167
+ * This parses either to simply the resulting text.
168
+ * @param cx A context which has an identifier
169
+ * @returns The indenftifier text
170
+ */
171
+ function getId(cx) {
172
+ const quoted = cx.id().BQ_STRING();
173
+ if (quoted) {
174
+ return parseString(quoted.text, '`');
175
+ }
176
+ return cx.id().text;
177
+ }
178
+ exports.getId = getId;
179
+ function getOptionalId(cx) {
180
+ function containsID(cx) {
181
+ return 'id' in cx;
182
+ }
183
+ if (containsID(cx) && cx.id()) {
184
+ return getId(cx);
185
+ }
186
+ }
187
+ exports.getOptionalId = getOptionalId;
188
+ //# sourceMappingURL=parse-utils.js.map
@@ -23,38 +23,105 @@
23
23
  */
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  require("./parse-expects");
26
- const string_parser_1 = require("../string-parser");
26
+ const parse_utils_1 = require("../parse-utils");
27
+ const test_translator_1 = require("./test-translator");
27
28
  describe('test internal string parsing', () => {
28
29
  test('\\b', () => {
29
- expect((0, string_parser_1.parseString)('\\b')).toEqual('\b');
30
+ expect((0, parse_utils_1.parseString)('\\b')).toEqual('\b');
30
31
  });
31
32
  test('\\f', () => {
32
- expect((0, string_parser_1.parseString)('\\f')).toEqual('\f');
33
+ expect((0, parse_utils_1.parseString)('\\f')).toEqual('\f');
33
34
  });
34
35
  test('\\n', () => {
35
- expect((0, string_parser_1.parseString)('\\n')).toEqual('\n');
36
+ expect((0, parse_utils_1.parseString)('\\n')).toEqual('\n');
36
37
  });
37
38
  test('\\r', () => {
38
- expect((0, string_parser_1.parseString)('\\r')).toEqual('\r');
39
+ expect((0, parse_utils_1.parseString)('\\r')).toEqual('\r');
39
40
  });
40
41
  test('\\t', () => {
41
- expect((0, string_parser_1.parseString)('\\t')).toEqual('\t');
42
+ expect((0, parse_utils_1.parseString)('\\t')).toEqual('\t');
42
43
  });
43
44
  test('unicode ?', () => {
44
- expect((0, string_parser_1.parseString)('\\u003f')).toEqual('?');
45
- expect((0, string_parser_1.parseString)('\\u003F')).toEqual('?');
45
+ expect((0, parse_utils_1.parseString)('\\u003f')).toEqual('?');
46
+ expect((0, parse_utils_1.parseString)('\\u003F')).toEqual('?');
46
47
  });
47
48
  test('normal stuff', () => {
48
- expect((0, string_parser_1.parseString)('normal stuff')).toEqual('normal stuff');
49
+ expect((0, parse_utils_1.parseString)('normal stuff')).toEqual('normal stuff');
49
50
  });
50
51
  test('stuff & nonsense', () => {
51
- expect((0, string_parser_1.parseString)('stuff \\u0026 nonsense')).toEqual('stuff & nonsense');
52
+ expect((0, parse_utils_1.parseString)('stuff \\u0026 nonsense')).toEqual('stuff & nonsense');
52
53
  });
53
54
  test('one thing\\nnext thing', () => {
54
- expect((0, string_parser_1.parseString)('one thing\\nnext thing')).toEqual('one thing\nnext thing');
55
+ expect((0, parse_utils_1.parseString)('one thing\\nnext thing')).toEqual('one thing\nnext thing');
55
56
  });
56
57
  test('quote stripping works', () => {
57
- expect((0, string_parser_1.parseString)('|42|', '|')).toEqual('42');
58
+ expect((0, parse_utils_1.parseString)('|42|', '|')).toEqual('42');
59
+ });
60
+ });
61
+ describe('all strings are parsed in all places', () => {
62
+ const tz = 'America/Mexico_City';
63
+ test('timezone single quote', () => {
64
+ const m = new test_translator_1.TestTranslator(`run: a-> {timezone: '${tz}'; project: *}`);
65
+ expect(m).toParse();
66
+ });
67
+ test('timezone double quote', () => {
68
+ const m = new test_translator_1.TestTranslator(`run: a-> {timezone: "${tz}"; project: *}`);
69
+ expect(m).toParse();
70
+ });
71
+ test('timezone triple quote', () => {
72
+ const m = new test_translator_1.TestTranslator(`run: a->{timezone: """${tz}"""; project: *}`);
73
+ expect(m).toParse();
74
+ });
75
+ test('timezone with illegal query', () => {
76
+ expect(`run: a->{timezone: """${tz}%{ab->aturtle}%"""; project: *}`).translationToFailWith('%{ query }% illegal in this string');
77
+ });
78
+ test('table single quote', () => {
79
+ const m = new test_translator_1.TestTranslator("source: n is bigquery.table('n')");
80
+ expect(m).toParse();
81
+ });
82
+ test('table double quote', () => {
83
+ const m = new test_translator_1.TestTranslator('source: n is bigquery.table("n")');
84
+ expect(m).toParse();
85
+ });
86
+ test('table triple quote', () => {
87
+ const m = new test_translator_1.TestTranslator('source: n is bigquery.table("""n""")');
88
+ expect(m).toParse();
89
+ });
90
+ test('sql single quote', () => {
91
+ const m = new test_translator_1.TestTranslator("source: n is bigquery.sql('n')");
92
+ expect(m).toParse();
93
+ });
94
+ test('sql double quote', () => {
95
+ const m = new test_translator_1.TestTranslator('source: n is bigquery.sql("n")');
96
+ expect(m).toParse();
97
+ });
98
+ test('sql triple quote', () => {
99
+ const m = new test_translator_1.TestTranslator('source: n is bigquery.sql("""n""")');
100
+ expect(m).toParse();
101
+ });
102
+ test('import single quote', () => {
103
+ const m = new test_translator_1.TestTranslator("import 'a'");
104
+ expect(m).toParse();
105
+ });
106
+ test('import double quote', () => {
107
+ const m = new test_translator_1.TestTranslator('import "a"');
108
+ expect(m).toParse();
109
+ });
110
+ test('import triple quote', () => {
111
+ const m = new test_translator_1.TestTranslator('import """a"""');
112
+ expect(m).toParse();
113
+ });
114
+ test('literal single quote', () => {
115
+ const x = new test_translator_1.BetaExpression("'x'");
116
+ expect(x).toParse();
117
+ });
118
+ test('literal double quote', () => {
119
+ const x = new test_translator_1.BetaExpression('"x"');
120
+ expect(x).toParse();
121
+ });
122
+ test('literal triple quote', () => {
123
+ const x = new test_translator_1.BetaExpression('"""x"""');
124
+ expect(x).toParse();
58
125
  });
59
126
  });
60
127
  //# 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",
3
+ "version": "0.0.56-dev230707230009",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,11 +0,0 @@
1
- /**
2
- * Parses the interior of a string, doing all \ substitutions. In most cases
3
- * a lexical analyzer has already recognized this as a string. As a convenience,
4
- * strip off the quoting outer chartacters if asked, then parse the interior of
5
- * the string. The intention is to be compatible with JSON strings, in terms
6
- * of which \X substitutions are processed.
7
- * @param str is the string to parse
8
- * @param surround is the quoting character, default means quotes already stripped
9
- * @returns a string with the \ processing completed
10
- */
11
- export declare function parseString(str: string, surround?: string): string;