@cnrs/hel 0.4.0 → 0.5.0

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/README.md CHANGED
@@ -28,8 +28,8 @@ For example, combined with [Heimdall.js](https://gitlab.huma-num.fr/datasphere/h
28
28
 
29
29
  ## Why should I use it?
30
30
 
31
- Well really your shouldn't, or Hel may drain your soul and take it along the twelve rivers all the way to the Halls of the Dead for an eternity of suffering.
32
- Anyways, it's up to you. ¯\\_(ツ)_/¯
31
+ Well really y̴̖̿̓ö̶͕͕͝ǘ̶͖͍ ̵̺̫́s̵̼͝h̷͓͂ò̸̠ü̸͍̈́ḽ̷̋͊ḏ̷̽ṅ̷̘'̷̺́̈́ṭ̶̬́͋,̸͔̥̾ ̴̪̌ô̶̤̇r̴̳̅̀ ̶͚̫͒̕H̶̹̿͜e̵̛̞̒l̵̖͗ ̵̪͓͘m̷̰̦̾a̵̠̱̽y̴͙̝͑ ̷͈̙͌d̵̯͝ř̷̟̓ͅa̷̟͖͗i̸͔̮̎n̶̗̠͂͋ ̶̢̦̿̕y̶̖̼̎o̵̖͉͐̎ú̴̧̕r̶͙̳͆ ̸̟͈͋s̶̰̫̿̀o̵̲͕̐ṳ̸̠̋͠l̷͔̫͘ ̴̦̇̐ ̶̧̤̑̂̃͐ä̵̡̙́̀n̵̞͓̬̅d̷̛͕̞̈̂͘ ̸̧͖̘̘̀t̵͖̓̿̆͂ą̵̳̘͉̿͂̈̎k̴̳̘̖̉͆͠ě̴̠̫ ̴̛̞̏̈́̕i̷̬̜̻͗́͒̽͜t̸̘̻̓ ̴̮̎̇̓a̶̦̪̰͈̍̍͝l̶͕̣̙̆̓ő̴̭͊͌͑ǹ̵̡͖̼̗̚g̷͖̙̤̐̂ ̷̝̞̣͑͜ẗ̸̯́h̶̙̒̊e̶̟͓̖͆̄ͅ ̴̣̰͋t̸̙̭́ẅ̷̨̹́ͅẻ̵̗͍̑l̶̪̏͊͌v̴̼̣̾͑͜͠é̷͇͈̥̣́̇ ̸͈̤̱̗͌̃́r̶̬̼͓̕͝ͅi̷̪̎v̵͍͎̦͂͊̓e̴̗̠͖̍̅͝r̸̡̩̘͝s̷̢̝̞͆ ̸̮̒̎̏̕a̴̳̖̔́̕ḷ̷̨͇͙͌͂̓l̴͖̺̤͓͌̓ ̶̢̩̑̃̅t̷̤͙̙̅̓h̸̢̙̰̋ḙ̶͎̰̀ ̵̢̪̿̍w̶͈͚̺̋̃á̵͈̑̅y̷͇̍ ̷̧̠͍̈́̾͑͝t̴̨̨͕̪̎͋̂ȏ̸̳ͅ ̴̡͓̀̔̓̐t̵͖̖̤̽h̴̞͑́ȇ̵̹̰̫̞ ̸̧̻̻̻̌͗H̷̪̜̐́a̴͎̜͖̞͒̋̉̃l̵͖̀̿́͂ḽ̸͛͌ş̶̜̤͐͌ ̴̧̜̞̊̂o̴̥͚̩̐͜f̶̤̦́̔ ̵̳̰̈́͌ṫ̶̡̩͈h̸̳̳̯̏̈́́͒ḙ̶̣̈͊̎̕ ̴̢͓͇̬̍̽D̷̩̋̈́͝͝e̶̲̥̲̐̀͠a̶̪̐d̷͙̉͑ ̸̣̪̥͠f̷̨͈̰̎̿̓ͅỏ̶͓̬͉̘̀͝r̸̫͍̘̪̍͑̋̕ ̸̱̤̎a̵̺̻̿́ṅ̸̢̡̮̹͘̕ ̴̳̻̮̣̊̍̔e̷͚̠̜̠̽t̵̮͚͈̙̋ę̶̭͔͕͛r̶̼̿̋̕n̷̞̼͈̻̒ḭ̴͚̔͛͊͊ͅṱ̴̣͆͘y̸̤̝̘̲͝ ̴̧͓̩̈́̍͐̀ö̵́́̽͠ͅf̴̼͎̣̂̔̔ ̷̨̝͋̕s̸̫͐͝u̴̦͇̙̤̓f̷̥̙̆f̴̡̲̠̽́̎ě̶̡͍̀r̸̛̹͎̭͔̽i̷̖͕͋̚n̴͓̊́͜ģ̶͉̭̈́̅̌̇.̶̝̓̕ ̵̝̣̞͋̋̽̚
32
+ Anyways, what was I saying? Oh well, it's up to you I guess. ¯\\_(ツ)_/¯
33
33
 
34
34
 
35
35
 
@@ -47,12 +47,28 @@ Once installed, you can start using it with a few simple calls:
47
47
  import { * as hel } from '@cnrs/hel';
48
48
 
49
49
  const query = '!(type != "cat") & (subtype == "bobcat" | danger > "high")';
50
- const filter = hel.str2fun(query); // filter function
51
- const tree = hel.str2ast(query); // Abstract Syntax Tree (AST)
52
- const equivalent_query = hel.ast2str(tree); // equivalent to query
50
+ const filter = hel.fromStringToFilter(query); // filter function
51
+ const tree = hel.fromStringToTree(query); // Abstract Syntax Tree (AST)
52
+ const equivalent_query = hel.fromTreeToString(tree); // equivalent to query
53
53
  ```
54
54
 
55
55
 
56
+ The equivalences between the HEL query language syntax and the corresponding [AST (Abstract Syntax Tree)](https://en.wikipedia.org/wiki/Abstract_syntax_tree) JavaScript nodes :
57
+
58
+ | Name | Syntax | AST node | Atom? | Notes |
59
+ | --------- | ------------- | -------------------- | ----- | ------------------------------------------ |
60
+ | Entity |`eid VALUE` |`{ eid: 'VALUE'}` | No | An item of entity ID `VALUE`:String. |
61
+ | Attribute |`aid VALUE` |`{ aid: 'VALUE'}` | Yes | A metadata of attribute ID `VALUE`:String. |
62
+ | Property |`pid VALUE` |`{ pid: 'VALUE'}` | Yes | A metadata of property ID `VALUE`:String. |
63
+ | Number |`VALUE` |`VALUE` | Yes | A litteral numeric equals to `VALUE`. |
64
+ | String |`"VALUE"` |`"VALUE"` | Yes | A litteral string equals to `VALUE`. |
65
+ | Relation |`ATOM OP ATOM` |`{ left: ATOM, operator: OP, right: ATOM}`| No | A relation between a left and a right `ATOM`, using a binary relationnal operator `OP`. |
66
+ | And |`N¹ & N² & …` |`{ and: [ N¹, N², …]}`| No | True if all nodes `N¹`,`N²`,… are true. |
67
+ | Or |`N¹ \| N² \| …`|`{ or: [ N¹, N², …]}` | No | True if any node `N¹`,`N²`,… is true. |
68
+ | Not |`!( N )` |`{ not: N }` | No | The negated value of node `N`. |
69
+ | Parentheses |`( N )` |`N` | No | Used for priority between And and Or. |
70
+
71
+
56
72
 
57
73
  ## Is it documented?
58
74
 
package/package.json CHANGED
@@ -28,7 +28,7 @@
28
28
  "https://medium.com/sapioit/why-having-3-numbers-in-the-version-name-is-bad-92fc1f6bc73c",
29
29
  "https://gist.github.com/jashkenas/cbd2b088e20279ae2c8e"
30
30
  ],
31
- "version": "0.4.0",
31
+ "version": "0.5.0",
32
32
  "keywords": [
33
33
  "hera",
34
34
  "hecate",
package/src/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { toString as ast2str } from './ast2str.js';
2
- import { toAst as str2ast } from './str2ast.js';
3
- import { toFunction as str2fun } from './str2fun.js';
1
+ import { toString as fromTreeToString } from './ast2str.js';
2
+ import { toAst as fromStringToTree } from './str2ast.js';
3
+ import { toFunction as fromStringToFilter } from './str2fun.js';
4
4
 
5
5
  import { operators as ops } from './tokens.js';
6
6
 
@@ -12,8 +12,8 @@ for (const [key, token] of Object.entries(ops)) {
12
12
  }
13
13
 
14
14
  export {
15
- ast2str,
16
- str2ast,
17
- str2fun,
15
+ fromTreeToString,
16
+ fromStringToTree,
17
+ fromStringToFilter,
18
18
  operators,
19
19
  };
package/src/str2ast.js CHANGED
@@ -71,7 +71,8 @@ class StringToAstVisitor extends CstVisitor {
71
71
  if (context.attribute) return this.visit(context.attribute);
72
72
  if (context.property) return this.visit(context.property);
73
73
  if (context.Integer) return parseInt(context.Integer[0].image);
74
- return context.String[0].image;
74
+ const value = context.String[0].image;
75
+ return value.substring(1, value.length-1);
75
76
  }
76
77
 
77
78
  relationalOperator(context) {