@jbrowse/jexl 3.1.0 → 3.2.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.
Files changed (45) hide show
  1. package/README.md +15 -0
  2. package/dist/Expression.d.ts +3 -1
  3. package/dist/Expression.js +3 -8
  4. package/dist/Expression.js.map +1 -1
  5. package/dist/Lexer.d.ts +0 -1
  6. package/dist/Lexer.js +5 -8
  7. package/dist/Lexer.js.map +1 -1
  8. package/dist/evaluator/compile.js +34 -16
  9. package/dist/evaluator/compile.js.map +1 -1
  10. package/dist/grammar.js +8 -8
  11. package/dist/grammar.js.map +1 -1
  12. package/dist/parser/Parser.d.ts +2 -1
  13. package/dist/parser/Parser.js +29 -12
  14. package/dist/parser/Parser.js.map +1 -1
  15. package/dist/parser/handlers.d.ts +8 -2
  16. package/dist/parser/handlers.js +32 -7
  17. package/dist/parser/handlers.js.map +1 -1
  18. package/dist/parser/states.js +19 -20
  19. package/dist/parser/states.js.map +1 -1
  20. package/esm/Expression.d.ts +3 -1
  21. package/esm/Expression.js +3 -8
  22. package/esm/Expression.js.map +1 -1
  23. package/esm/Lexer.d.ts +0 -1
  24. package/esm/Lexer.js +5 -8
  25. package/esm/Lexer.js.map +1 -1
  26. package/esm/evaluator/compile.js +34 -16
  27. package/esm/evaluator/compile.js.map +1 -1
  28. package/esm/grammar.js +8 -8
  29. package/esm/grammar.js.map +1 -1
  30. package/esm/parser/Parser.d.ts +2 -1
  31. package/esm/parser/Parser.js +29 -12
  32. package/esm/parser/Parser.js.map +1 -1
  33. package/esm/parser/handlers.d.ts +8 -2
  34. package/esm/parser/handlers.js +29 -7
  35. package/esm/parser/handlers.js.map +1 -1
  36. package/esm/parser/states.js +19 -20
  37. package/esm/parser/states.js.map +1 -1
  38. package/package.json +1 -1
  39. package/src/Expression.ts +3 -9
  40. package/src/Lexer.ts +5 -8
  41. package/src/evaluator/compile.ts +51 -44
  42. package/src/grammar.ts +8 -9
  43. package/src/parser/Parser.ts +35 -17
  44. package/src/parser/handlers.ts +33 -10
  45. package/src/parser/states.ts +20 -20
@@ -22,6 +22,20 @@ interface StateDefinition {
22
22
 
23
23
  type States = Record<string, StateDefinition>
24
24
 
25
+ /**
26
+ * The tokens that may follow a finished operand: an operator to combine it
27
+ * with, a dot or subscript to keep drilling into it, a question mark opening a
28
+ * ternary, or a semicolon ending the statement. Shared by every state that
29
+ * sits on a complete value, which is also why each of them is completable.
30
+ */
31
+ const afterOperand: Record<string, TokenTypeOptions> = {
32
+ binaryOp: { toState: 'expectOperand' },
33
+ dot: { toState: 'traverse' },
34
+ openBracket: { toState: 'filter' },
35
+ question: { toState: 'ternaryMid', handler: h.ternaryStart },
36
+ semicolon: { handler: h.semicolon }
37
+ }
38
+
25
39
  /**
26
40
  * A mapping of all states in the finite state machine to a set of instructions
27
41
  * for handling or transitioning into other states. Each state can be handled
@@ -68,13 +82,7 @@ export const states: States = {
68
82
  }
69
83
  },
70
84
  expectBinOp: {
71
- tokenTypes: {
72
- binaryOp: { toState: 'expectOperand' },
73
- dot: { toState: 'traverse' },
74
- openBracket: { toState: 'filter' },
75
- question: { toState: 'ternaryMid', handler: h.ternaryStart },
76
- semicolon: { handler: h.semicolon }
77
- },
85
+ tokenTypes: afterOperand,
78
86
  completable: true
79
87
  },
80
88
  expectObjKey: {
@@ -90,23 +98,15 @@ export const states: States = {
90
98
  }
91
99
  },
92
100
  postArgs: {
93
- tokenTypes: {
94
- binaryOp: { toState: 'expectOperand' },
95
- dot: { toState: 'traverse' },
96
- openBracket: { toState: 'filter' },
97
- question: { toState: 'ternaryMid', handler: h.ternaryStart },
98
- semicolon: { handler: h.semicolon }
99
- },
101
+ tokenTypes: afterOperand,
100
102
  completable: true
101
103
  },
102
104
  identifier: {
103
105
  tokenTypes: {
104
- binaryOp: { toState: 'expectOperand' },
105
- dot: { toState: 'traverse' },
106
- openBracket: { toState: 'filter' },
107
- openParen: { toState: 'argVal', handler: h.functionCall },
108
- question: { toState: 'ternaryMid', handler: h.ternaryStart },
109
- semicolon: { handler: h.semicolon }
106
+ ...afterOperand,
107
+ // a name is the only operand that can be followed by an argument list,
108
+ // since a function is called by name rather than evaluated as a value
109
+ openParen: { toState: 'argVal', handler: h.functionCall }
110
110
  },
111
111
  completable: true
112
112
  },