@malloydata/malloy-tag 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.
Files changed (42) hide show
  1. package/README.md +0 -0
  2. package/dist/index.d.ts +2 -0
  3. package/dist/index.js +38 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/lib/Malloy/MalloyTagLexer.d.ts +42 -0
  6. package/dist/lib/Malloy/MalloyTagLexer.js +385 -0
  7. package/dist/lib/Malloy/MalloyTagLexer.js.map +1 -0
  8. package/dist/lib/Malloy/MalloyTagParser.d.ts +180 -0
  9. package/dist/lib/Malloy/MalloyTagParser.js +1051 -0
  10. package/dist/lib/Malloy/MalloyTagParser.js.map +1 -0
  11. package/dist/lib/Malloy/MalloyTagVisitor.d.ts +120 -0
  12. package/dist/lib/Malloy/MalloyTagVisitor.js +4 -0
  13. package/dist/lib/Malloy/MalloyTagVisitor.js.map +1 -0
  14. package/dist/tags.d.ts +90 -0
  15. package/dist/tags.js +654 -0
  16. package/dist/tags.js.map +1 -0
  17. package/dist/tags.spec.d.ts +8 -0
  18. package/dist/tags.spec.js +318 -0
  19. package/dist/tags.spec.js.map +1 -0
  20. package/dist/util.d.ts +11 -0
  21. package/dist/util.js +84 -0
  22. package/dist/util.js.map +1 -0
  23. package/dist/util.spec.d.ts +1 -0
  24. package/dist/util.spec.js +43 -0
  25. package/dist/util.spec.js.map +1 -0
  26. package/package.json +30 -0
  27. package/scripts/build_parser.js +98 -0
  28. package/src/MalloyTag.g4 +102 -0
  29. package/src/index.ts +8 -0
  30. package/src/lib/Malloy/MalloyTag.interp +61 -0
  31. package/src/lib/Malloy/MalloyTag.tokens +32 -0
  32. package/src/lib/Malloy/MalloyTagLexer.interp +85 -0
  33. package/src/lib/Malloy/MalloyTagLexer.tokens +32 -0
  34. package/src/lib/Malloy/MalloyTagLexer.ts +386 -0
  35. package/src/lib/Malloy/MalloyTagParser.ts +1048 -0
  36. package/src/lib/Malloy/MalloyTagVisitor.ts +141 -0
  37. package/src/lib/Malloy/_BUILD_DIGEST_ +1 -0
  38. package/src/tags.spec.ts +331 -0
  39. package/src/tags.ts +761 -0
  40. package/src/util.spec.ts +43 -0
  41. package/src/util.ts +73 -0
  42. package/tsconfig.json +11 -0
@@ -0,0 +1,43 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import {parseString} from './util';
8
+
9
+ describe('quote comprehension inside strings', () => {
10
+ test('\\b', () => {
11
+ expect(parseString('\\b')).toEqual('\b');
12
+ });
13
+ test('\\f', () => {
14
+ expect(parseString('\\f')).toEqual('\f');
15
+ });
16
+ test('\\n', () => {
17
+ expect(parseString('\\n')).toEqual('\n');
18
+ });
19
+ test('\\r', () => {
20
+ expect(parseString('\\r')).toEqual('\r');
21
+ });
22
+ test('\\t', () => {
23
+ expect(parseString('\\t')).toEqual('\t');
24
+ });
25
+ test('unicode ?', () => {
26
+ expect(parseString('\\u003f')).toEqual('?');
27
+ expect(parseString('\\u003F')).toEqual('?');
28
+ });
29
+ test('normal stuff', () => {
30
+ expect(parseString('normal stuff')).toEqual('normal stuff');
31
+ });
32
+ test('stuff & nonsense', () => {
33
+ expect(parseString('stuff \\u0026 nonsense')).toEqual('stuff & nonsense');
34
+ });
35
+ test('one thing\\nnext thing', () => {
36
+ expect(parseString('one thing\\nnext thing')).toEqual(
37
+ 'one thing\nnext thing'
38
+ );
39
+ });
40
+ test('quote stripping works', () => {
41
+ expect(parseString('|42|', '|')).toEqual('42');
42
+ });
43
+ });
package/src/util.ts ADDED
@@ -0,0 +1,73 @@
1
+ enum ParseState {
2
+ Normal,
3
+ ReverseVirgule,
4
+ Unicode,
5
+ }
6
+
7
+ // TODO this should probably live in it's own package, `malloy-common` or something
8
+ /**
9
+ * Parses the interior of a string, doing all \ substitutions. In most cases
10
+ * a lexical analyzer has already recognized this as a string. As a convenience,
11
+ * strip off the quoting outer chartacters if asked, then parse the interior of
12
+ * the string. The intention is to be compatible with JSON strings, in terms
13
+ * of which \X substitutions are processed.
14
+ * @param str is the string to parse
15
+ * @param surround is the quoting character, default means quotes already stripped
16
+ * @returns a string with the \ processing completed
17
+ */
18
+ export function parseString(str: string, surround = ''): string {
19
+ let inner = str.slice(surround.length);
20
+ let state = ParseState.Normal;
21
+ if (surround.length) {
22
+ inner = inner.slice(0, -surround.length);
23
+ }
24
+ let out = '';
25
+ let unicode = '';
26
+ for (const c of inner) {
27
+ switch (state) {
28
+ case ParseState.Normal: {
29
+ if (c === '\\') {
30
+ state = ParseState.ReverseVirgule;
31
+ } else {
32
+ out += c;
33
+ }
34
+ break;
35
+ }
36
+ case ParseState.ReverseVirgule: {
37
+ let outc = c;
38
+ if (c === 'u') {
39
+ state = ParseState.Unicode;
40
+ unicode = '';
41
+ continue;
42
+ }
43
+ if (c === 'b') {
44
+ outc = '\b';
45
+ } else if (c === 'f') {
46
+ outc = '\f';
47
+ } else if (c === 'n') {
48
+ outc = '\n';
49
+ } else if (c === 'r') {
50
+ outc = '\r';
51
+ } else if (c === 't') {
52
+ outc = '\t';
53
+ }
54
+ out += outc;
55
+ state = ParseState.Normal;
56
+ break;
57
+ }
58
+ case ParseState.Unicode: {
59
+ if ('ABCDEFabcdef0123456789'.includes(c)) {
60
+ unicode += c;
61
+ if (unicode.length === 4) {
62
+ out += String.fromCharCode(parseInt(unicode, 16));
63
+ state = ParseState.Normal;
64
+ }
65
+ } else {
66
+ // Don't think we ever get here ...
67
+ state = ParseState.Normal;
68
+ }
69
+ }
70
+ }
71
+ }
72
+ return out;
73
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "../../tsconfig.packages.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "dist",
6
+ "composite": true
7
+ },
8
+ "include": [
9
+ "src/**/*.ts"
10
+ ]
11
+ }