@kogeet/scapin-core-agent 0.1.7 → 0.1.8

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.
@@ -1,15 +1,11 @@
1
- import { type varType } from '../models/parameter.model.js';
2
- import type { RunParamModel } from '../models/run.model.js';
1
+ import type { varType } from "../models/parameter.model.js";
3
2
  /**
4
3
  * La classe **Context** stocke les variables utilisées lors du test
5
4
  */
6
5
  export declare class Context {
7
- idxStep: number;
8
6
  private variables;
9
7
  getVariable(varname: string): varType;
10
8
  setVariable(varname: string, value: varType): void;
11
- loadVariable(params: RunParamModel[]): void;
12
- valorize(param: RunParamModel): void;
13
9
  dump(): [string, varType][];
14
10
  resetVariables(rVars?: {
15
11
  name: string;
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/core/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,OAAO,EAAC,MAAM,8BAA8B,CAAA;AACxE,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,wBAAwB,CAAC;AAE1D;;GAEG;AACH,qBAAa,OAAO;IACX,OAAO,EAAE,MAAM,CAAM;IAE5B,OAAO,CAAC,SAAS,CAA6B;IAEvC,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAIrC,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO;IAM3C,YAAY,CAAC,MAAM,EAAE,aAAa,EAAE;IAgBpC,QAAQ,CAAC,KAAK,EAAE,aAAa;IAiB7B,IAAI;IAIJ,cAAc,CAAC,KAAK,GAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,EAAO;CAMrE;AAED,eAAO,MAAM,OAAO,SAAgB,CAAA"}
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/core/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,8BAA8B,CAAC;AAE1D;;GAEG;AACH,qBAAa,OAAO;IAElB,OAAO,CAAC,SAAS,CAA6B;IAEvC,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAIrC,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO;IAM3C,IAAI;IAIJ,cAAc,CAAC,KAAK,GAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,EAAO;CAMrE;AAED,eAAO,MAAM,OAAO,SAAgB,CAAA"}
@@ -1,9 +1,7 @@
1
- import { enumParamType } from '../models/parameter.model.js';
2
1
  /**
3
2
  * La classe **Context** stocke les variables utilisées lors du test
4
3
  */
5
4
  export class Context {
6
- idxStep = -1;
7
5
  variables = new Map();
8
6
  getVariable(varname) {
9
7
  return this.variables.get(varname);
@@ -13,37 +11,6 @@ export class Context {
13
11
  this.variables.set(varname, value);
14
12
  }
15
13
  }
16
- loadVariable(params) {
17
- const regex = /\$\w+/g;
18
- params.forEach((p) => {
19
- if (p && p.value && typeof p.value === 'string') {
20
- const found = p.value.match(regex);
21
- if (found) {
22
- found.forEach((name) => {
23
- if (!this.variables.has(name)) {
24
- this.variables.set(name, undefined);
25
- }
26
- });
27
- }
28
- }
29
- });
30
- }
31
- valorize(param) {
32
- // console.log('Valorize input :', param)
33
- const quot = param.type === enumParamType.textdata || param.type === enumParamType.options ? '"' : '';
34
- if (param.type !== enumParamType.receipt && param.value && typeof param.value === 'string') {
35
- const found = param.value.match(/\$\w+/g);
36
- if (found) {
37
- found.forEach((vname) => {
38
- if (this.variables.has(vname)) {
39
- const vvalue = this.variables.get(vname);
40
- param.value = param.value.replace(vname, quot + vvalue + quot);
41
- }
42
- });
43
- }
44
- }
45
- // console.log('Valorize output :', param)
46
- }
47
14
  dump() {
48
15
  return [...this.variables.entries()];
49
16
  }
@@ -1,12 +1,13 @@
1
1
  import type { RunDataStepModel, Variable } from '../models/run.model.js';
2
2
  export declare class RunSteps {
3
3
  private runData;
4
- private runstep;
4
+ private runStep;
5
5
  private stepCtx;
6
6
  stop: boolean;
7
7
  constructor(rData: RunDataStepModel[], rVars: Variable[]);
8
8
  run(pos: number, end: number): Promise<void>;
9
9
  size(): number;
10
+ close(): void;
10
11
  private runAStep;
11
12
  }
12
13
  //# sourceMappingURL=runsteps.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"runsteps.d.ts","sourceRoot":"","sources":["../../src/core/runsteps.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,gBAAgB,EAAE,QAAQ,EAAC,MAAM,wBAAwB,CAAA;AAEtE,qBAAa,QAAQ;IACnB,OAAO,CAAC,OAAO,CAAoB;IACnC,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,OAAO,CAA2B;IACnC,IAAI,EAAE,OAAO,CAAQ;gBAET,KAAK,EAAE,gBAAgB,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE;IAKlD,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM;IAgBlC,IAAI;YAEG,QAAQ;CAwBvB"}
1
+ {"version":3,"file":"runsteps.d.ts","sourceRoot":"","sources":["../../src/core/runsteps.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,gBAAgB,EAAE,QAAQ,EAAC,MAAM,wBAAwB,CAAA;AAEtE,qBAAa,QAAQ;IACnB,OAAO,CAAC,OAAO,CAAoB;IACnC,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,OAAO,CAA2B;IACnC,IAAI,EAAE,OAAO,CAAQ;gBAET,KAAK,EAAE,gBAAgB,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE;IAKlD,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM;IAkBlC,IAAI;IAEJ,KAAK;YAKE,QAAQ;CAwBvB"}
@@ -4,7 +4,7 @@ import StepContext from './step.context.js';
4
4
  import RunStep from './runstep.js';
5
5
  export class RunSteps {
6
6
  runData;
7
- runstep;
7
+ runStep = new RunStep();
8
8
  stepCtx = null;
9
9
  stop = false;
10
10
  constructor(rData, rVars) {
@@ -12,12 +12,14 @@ export class RunSteps {
12
12
  context.resetVariables(rVars);
13
13
  }
14
14
  async run(pos, end) {
15
- if (this.runData.length != 0 && pos != end) {
15
+ if (this.runData.length != 0) {
16
16
  for (let i = pos; i < end; i++) {
17
- const step = this.runData[i];
18
- await this.runAStep(step);
19
- if (this.stop) {
20
- break;
17
+ if (i < this.runData.length) {
18
+ const step = this.runData[i];
19
+ await this.runAStep(step);
20
+ if (this.stop) {
21
+ break;
22
+ }
21
23
  }
22
24
  }
23
25
  }
@@ -27,12 +29,16 @@ export class RunSteps {
27
29
  }
28
30
  }
29
31
  size() { return this.runData.length; }
32
+ close() {
33
+ this.runData = [];
34
+ context.resetVariables();
35
+ }
30
36
  async runAStep(step) {
31
37
  let stepResult;
32
38
  report.stepStart(step.pos);
33
39
  try {
34
40
  this.stepCtx = new StepContext(step);
35
- stepResult = await this.runstep.run(this.stepCtx, step.lib, step.fn);
41
+ stepResult = await this.runStep.run(this.stepCtx, step.lib, step.fn);
36
42
  }
37
43
  catch (e) {
38
44
  const errMsg = e.message;
@@ -1,5 +1,5 @@
1
- import type { RunDataStepModel, RunParamModel } from '../models/run.model.js';
2
1
  import { type varType } from '../models/parameter.model.js';
2
+ import type { RunDataStepModel, RunParamModel } from '../models/run.model.js';
3
3
  /**
4
4
  * La classe **StepContext** gère les paramètres.
5
5
  *
@@ -1 +1 @@
1
- {"version":3,"file":"step.context.d.ts","sourceRoot":"","sources":["../../src/core/step.context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAE,aAAa,EAAC,MAAM,wBAAwB,CAAA;AAC3E,OAAO,EAAgB,KAAK,OAAO,EAAC,MAAM,8BAA8B,CAAC;AAIzE;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,OAAO,WAAW;IACvB,KAAK,EAAE,OAAO,CAAA;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkB;IACzC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkB;IACzC,SAAgB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;gBAE1B,IAAI,EAAE,gBAAgB;IAa3B,YAAY;IAIZ,aAAa;IAIb,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,OAAmB,GAAG,OAAO;IAI3D,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,GAAC,SAAqB,GAAG,MAAM;IAIzE,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,OAAmB,GAAG,OAAO;IAInE,OAAO,CAAC,GAAG;IAKX,OAAO,CAAC,WAAW;CAiCpB"}
1
+ {"version":3,"file":"step.context.d.ts","sourceRoot":"","sources":["../../src/core/step.context.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,KAAK,OAAO,EAAC,MAAM,8BAA8B,CAAC;AAC1D,OAAO,KAAK,EAAC,gBAAgB,EAAE,aAAa,EAAC,MAAM,wBAAwB,CAAA;AAE3E;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,OAAO,WAAW;IACvB,KAAK,EAAE,OAAO,CAAA;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkB;IACzC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkB;IACzC,SAAgB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;gBAE1B,IAAI,EAAE,gBAAgB;IAa3B,YAAY;IAIZ,aAAa;IAIb,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,OAAmB,GAAG,OAAO;IAI3D,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,GAAC,SAAqB,GAAG,MAAM;IAIzE,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,OAAmB,GAAG,OAAO;IAInE,OAAO,CAAC,GAAG;IAKX,OAAO,CAAC,WAAW;CA2BpB"}
@@ -1,6 +1,6 @@
1
- import { enumParamType } from '../models/parameter.model.js';
2
- import { JisonSolver } from './jison.parser.js';
1
+ import { parseParam } from "@kogeet/sapi-parser";
3
2
  import { context, report } from "../index.js";
3
+ import {} from '../models/parameter.model.js';
4
4
  /**
5
5
  * La classe **StepContext** gère les paramètres.
6
6
  *
@@ -19,7 +19,7 @@ export default class StepContext {
19
19
  this.istoy = step.istoy;
20
20
  this.toolid = step.toolid ? step.toolid : null;
21
21
  // Chargement si nécessaire des variables présentes dans les paramètres
22
- context.loadVariable(this.params);
22
+ // context.loadVariable(this.params)
23
23
  // Résolution des expressions
24
24
  this.solveParams();
25
25
  }
@@ -43,30 +43,24 @@ export default class StepContext {
43
43
  return par && typeof par.value !== 'undefined' ? par.value : defaut;
44
44
  }
45
45
  solveParams() {
46
+ const ctxVars = context.dump().map(v => {
47
+ return { name: v[0], value: v[1] };
48
+ });
49
+ // console.log('variables: ', [...ctxVars.map<string>(v => `${v.name}=${v.value}`)])
46
50
  this.params.map((param) => {
47
- context.valorize(param);
48
- if (param.value && param.type && param.options) {
49
- const solver = JisonSolver.builder(param.type, param.options);
50
- if (solver) {
51
- const strSolveVal = solver.exec(param.value);
52
- if (strSolveVal) {
53
- switch (param.type) {
54
- case enumParamType.booldata:
55
- param.value = strSolveVal.toLowerCase() === 'true';
56
- break;
57
- case enumParamType.numbdata:
58
- param.value = parseFloat(strSolveVal);
59
- break;
60
- case enumParamType.datetime:
61
- param.value = Date.parse(strSolveVal);
62
- break;
63
- default:
64
- param.value = strSolveVal;
65
- }
66
- }
67
- else {
68
- param.value = null;
69
- }
51
+ // console.log('Parameter ', {...param})
52
+ if (param.value[0] === "=" && param.type) {
53
+ let input = param.value;
54
+ if (input[0] === '=')
55
+ input = input.slice(1);
56
+ const result = parseParam(input, param.type, ctxVars, param.options);
57
+ if (result.isValid) {
58
+ const value = result.resolvedValue || '';
59
+ console.log(`Solve ${param.value} => ${value}`);
60
+ param.value = value;
61
+ }
62
+ else if (result.error && result.error.length > 0) {
63
+ report.error(`"${param.value}" parse error: ${result.error}`);
70
64
  }
71
65
  else {
72
66
  report.error(`Impossible to solve expression : ${param.value}`);
@@ -15,6 +15,7 @@ declare class WsocketIo {
15
15
  private onDebugData;
16
16
  /** Ordre d'exécution en mode Debug**/
17
17
  private onDebugRun;
18
+ private onDebugStop;
18
19
  /** Ordre d'exécution en mode Job **/
19
20
  private onRundata;
20
21
  private onStatus;
@@ -1 +1 @@
1
- {"version":3,"file":"wsocket.io.d.ts","sourceRoot":"","sources":["../../src/core/wsocket.io.ts"],"names":[],"mappings":"AAAA,OAAO,EAAK,MAAM,EAAC,MAAM,kBAAkB,CAAC;AAW5C,cAAM,SAAS;IACN,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAO;IACrC,OAAO,CAAC,QAAQ,CAAwB;IACxC,OAAO,CAAC,SAAS,CAAgB;IACjC,OAAO,CAAC,MAAM,CAAa;IAEpB,KAAK;IAiDL,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;IAQjD;;OAEG;IACI,GAAG;IAQV,OAAO,CAAC,OAAO,CAUd;IAED,uDAAuD;IACvD,OAAO,CAAC,WAAW,CAGlB;IAED,sCAAsC;IACtC,OAAO,CAAC,UAAU,CAWjB;IAED,qCAAqC;IACrC,OAAO,CAAC,SAAS,CAGhB;IAED,OAAO,CAAC,QAAQ,CAIf;IAED,OAAO,CAAC,MAAM,CAGb;IAED,OAAO,CAAC,SAAS,CAOhB;CAEF;AAED,QAAA,MAAM,SAAS,WAAkB,CAAA;AACjC,eAAe,SAAS,CAAA"}
1
+ {"version":3,"file":"wsocket.io.d.ts","sourceRoot":"","sources":["../../src/core/wsocket.io.ts"],"names":[],"mappings":"AAAA,OAAO,EAAK,MAAM,EAAC,MAAM,kBAAkB,CAAC;AAW5C,cAAM,SAAS;IACN,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAO;IACrC,OAAO,CAAC,QAAQ,CAAwB;IACxC,OAAO,CAAC,SAAS,CAAgB;IACjC,OAAO,CAAC,MAAM,CAAa;IAEpB,KAAK;IAkDL,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;IAQjD;;OAEG;IACI,GAAG;IASV,OAAO,CAAC,OAAO,CAUd;IAED,uDAAuD;IACvD,OAAO,CAAC,WAAW,CAGlB;IAED,sCAAsC;IACtC,OAAO,CAAC,UAAU,CAYjB;IAED,OAAO,CAAC,WAAW,CAGlB;IAED,qCAAqC;IACrC,OAAO,CAAC,SAAS,CAGhB;IAED,OAAO,CAAC,QAAQ,CAIf;IAED,OAAO,CAAC,MAAM,CAGb;IAED,OAAO,CAAC,SAAS,CAOhB;CAEF;AAED,QAAA,MAAM,SAAS,WAAkB,CAAA;AACjC,eAAe,SAAS,CAAA"}
@@ -39,6 +39,7 @@ class WsocketIo {
39
39
  this.ioClient.on('connect_error', this.onError);
40
40
  this.ioClient.on('data', this.onDebugData);
41
41
  this.ioClient.on('run', this.onDebugRun);
42
+ this.ioClient.on('stop-debugger', this.onDebugStop);
42
43
  this.ioClient.on('run-data', this.onRundata);
43
44
  this.ioClient.on('status', this.onStatus);
44
45
  this.ioClient.on('status-ping', this.onPing);
@@ -63,11 +64,12 @@ class WsocketIo {
63
64
  * Fin d'exécution d'un run
64
65
  */
65
66
  end() {
67
+ this.runSteps?.close();
68
+ this.runSteps = null;
69
+ report.clearStepLog();
66
70
  if (this.ioClient) {
67
71
  this.ioClient.emit('end');
68
72
  }
69
- this.runSteps = null;
70
- report.clearStepLog();
71
73
  }
72
74
  onError = (err) => {
73
75
  const msg = err.description ? err.description.message : '';
@@ -83,11 +85,13 @@ class WsocketIo {
83
85
  };
84
86
  /** Réception des données d'exécution en mode Debug **/
85
87
  onDebugData = (stepsData, runVar) => {
88
+ console.log(`Data of the run are: ${stepsData?.length || 0} steps and ${runVar?.length || 0} variables`);
86
89
  this.runSteps = stepsData && runVar ? new RunSteps(stepsData, runVar) : null;
87
90
  };
88
91
  /** Ordre d'exécution en mode Debug**/
89
92
  onDebugRun = async (pos, end) => {
90
- if (this.runSteps && pos && end) {
93
+ console.log(`Running in Debug mode from ${pos} to ${end}`);
94
+ if (this.runSteps && typeof pos === 'number' && typeof end === 'number') {
91
95
  try {
92
96
  await this.runSteps.run(pos, end);
93
97
  }
@@ -100,6 +104,10 @@ class WsocketIo {
100
104
  console.log("Invalid executive data");
101
105
  }
102
106
  };
107
+ onDebugStop = () => {
108
+ console.log("Arrêt du mode debug");
109
+ wSocketIo.end();
110
+ };
103
111
  /** Ordre d'exécution en mode Job **/
104
112
  onRundata = async (stepsData, runVars) => {
105
113
  this.onDebugData(stepsData, runVars);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kogeet/scapin-core-agent",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Scapin Core Agent",
5
5
  "author": "Loïc Griveau",
6
6
  "license": "MIT",
@@ -24,7 +24,7 @@
24
24
  "typescript": "^5.9.3"
25
25
  },
26
26
  "dependencies": {
27
- "jison": "^0.4.18",
27
+ "@kogeet/sapi-parser": "^1.0.4",
28
28
  "socket.io-client": "^4.8.3"
29
29
  },
30
30
  "type": "module"
@@ -1,16 +0,0 @@
1
- import { enumParamType } from '../models/parameter.model.js';
2
- export declare class JisonParser {
3
- error: string | null;
4
- result: never | null;
5
- private jparser;
6
- constructor(grammar: unknown);
7
- exec(exp: string): boolean | string;
8
- static builder(type: enumParamType, options: string[]): JisonParser | null;
9
- }
10
- export declare class JisonSolver {
11
- private jparser;
12
- constructor(grammar: unknown);
13
- exec(exp: string): string | null;
14
- static builder(type: enumParamType, options: string[]): JisonSolver | null;
15
- }
16
- //# sourceMappingURL=jison.parser.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"jison.parser.d.ts","sourceRoot":"","sources":["../../src/core/jison.parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,8BAA8B,CAAC;AAU3D,qBAAa,WAAW;IACf,KAAK,EAAE,MAAM,GAAG,IAAI,CAAQ;IAC5B,MAAM,EAAE,KAAK,GAAC,IAAI,CAAQ;IACjC,OAAO,CAAC,OAAO,CAAoC;gBAGhC,OAAO,EAAE,OAAO;IAI5B,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM;WAiB5B,OAAO,CAAC,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE;CAS7D;AAED,qBAAa,WAAW;IACtB,OAAO,CAAC,OAAO,CAA8C;gBAE1C,OAAO,EAAE,OAAO;IAI5B,IAAI,CAAC,GAAG,EAAE,MAAM;WAaT,OAAO,CAAC,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE;CAQ7D"}
@@ -1,82 +0,0 @@
1
- import { enumParamType } from '../models/parameter.model.js';
2
- import { variableGrammar } from '../jison/variable.grammar.js';
3
- import { logicalGrammar } from '../jison/logical.grammar.js';
4
- import { stringGrammar } from '../jison/string.grammar.js';
5
- import { calcGrammar } from '../jison/calc.grammar.js';
6
- import { datetimeGrammar } from '../jison/datetime.grammar.js';
7
- import { optionGrammar } from '../jison/option.grammar.js';
8
- import pkg from "jison";
9
- const { Parser } = pkg;
10
- export class JisonParser {
11
- error = null;
12
- result = null;
13
- jparser;
14
- constructor(grammar) {
15
- this.jparser = new Parser(grammar);
16
- }
17
- exec(exp) {
18
- try {
19
- this.jparser.parse(exp);
20
- return true;
21
- }
22
- catch (e) {
23
- const m = e.message.split('\n');
24
- if (m.length >= 2 && m[2].match(/^-*\^$/)) {
25
- const pos = m[2].length;
26
- return pos > exp.length
27
- ? 'Expression incomplete'
28
- : `Syntax error near character '${exp.charAt(pos - 1)}' at position ${pos}`;
29
- }
30
- else {
31
- return e.message;
32
- }
33
- }
34
- }
35
- static builder(type, options) {
36
- const grammar = typeGrammar(type, false, options);
37
- try {
38
- return new JisonParser(grammar);
39
- }
40
- catch (e) {
41
- return null;
42
- }
43
- }
44
- }
45
- export class JisonSolver {
46
- jparser;
47
- constructor(grammar) {
48
- this.jparser = new Parser(grammar);
49
- }
50
- exec(exp) {
51
- try {
52
- const ret = this.jparser.parse(exp);
53
- console.log(`Solve expression '${exp}' :`, ret);
54
- return ret ? ret : null;
55
- }
56
- catch (e) {
57
- const msg = e.message;
58
- console.log(`Solve erreur expression '${exp}' :`, msg);
59
- const errs = msg.split('\n');
60
- throw errs.length > 1 ? errs[1] : errs[0];
61
- }
62
- }
63
- static builder(type, options) {
64
- const grammar = typeGrammar(type, true, options);
65
- try {
66
- return new JisonSolver(grammar);
67
- }
68
- catch (e) {
69
- return null;
70
- }
71
- }
72
- }
73
- function typeGrammar(type, solve = false, options = []) {
74
- switch (type) {
75
- case enumParamType.receipt: return variableGrammar;
76
- case enumParamType.booldata: return logicalGrammar(solve);
77
- case enumParamType.textdata: return stringGrammar(solve);
78
- case enumParamType.numbdata: return calcGrammar(solve);
79
- case enumParamType.datetime: return datetimeGrammar(solve);
80
- case enumParamType.options: return optionGrammar(solve, options);
81
- }
82
- }
@@ -1,20 +0,0 @@
1
- export declare function calcGrammar(solve?: boolean): {
2
- lex: {
3
- rules: string[][];
4
- };
5
- operators: string[][];
6
- bnf: {
7
- expressions: string[][];
8
- e: (string | {
9
- prec: string;
10
- })[][];
11
- };
12
- };
13
- export declare const xxxGrammar: {
14
- lex: {
15
- rules: string[][];
16
- };
17
- operators: never[];
18
- bnf: {};
19
- };
20
- //# sourceMappingURL=calc.grammar.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"calc.grammar.d.ts","sourceRoot":"","sources":["../../src/jison/calc.grammar.ts"],"names":[],"mappings":"AAEA,wBAAgB,WAAW,CAAC,KAAK,GAAE,OAAe;;;;;;;;;;;EAyDjD;AAGC,eAAO,MAAM,UAAU;;;;;;CAStB,CAAC"}
@@ -1,66 +0,0 @@
1
- /* tslint:disable:quotemark trailing-comma */
2
- export function calcGrammar(solve = false) {
3
- const varValue = solve ? 'return null' : '$$ = 0';
4
- return {
5
- lex: {
6
- rules: [
7
- // Saute les espaces
8
- ['\\s+', '/* skip whitespace */'],
9
- ['[0-9]+(?:\\.[0-9]+)?\\b', 'return `NUMBER`'],
10
- ['\\$\\w+', 'return `VARIABLE`'],
11
- ['\\*', 'return `*`'],
12
- ['\\/', 'return `/`'],
13
- ['-', 'return `-`'],
14
- ['\\+', 'return `+`'],
15
- ['\\^', 'return `^`'],
16
- ['!', 'return `!`'],
17
- ['%', 'return `%`'],
18
- ['\\(', 'return `(`'],
19
- ['\\)', 'return `)`'],
20
- ['PI\\b', 'return `PI`'],
21
- ['E\\b', 'return `E`'],
22
- ['$', 'return `EOF`'],
23
- ['=', 'return `BEGEXP`']
24
- ]
25
- },
26
- operators: [
27
- ['left', '+', '-'],
28
- ['left', '*', '/'],
29
- ['left', '^'],
30
- ['right', '!'],
31
- ['right', '%'],
32
- ['left', 'UMINUS']
33
- ],
34
- bnf: {
35
- expressions: [['BEGEXP e EOF', 'return $2'], ['NUMBER EOF', 'return $1']],
36
- e: [
37
- ['e + e', '$$ = $1+$3'],
38
- ['e - e', '$$ = $1-$3'],
39
- ['e * e', '$$ = $1*$3'],
40
- ['e / e', '$$ = $1/$3'],
41
- ['e ^ e', '$$ = Math.pow($1, $3)'],
42
- ['e !', '$$ = (function(n) {if(n==0) return 1; return arguments.callee(n-1) * n})($1)'],
43
- ['e - e %', '$$ = $e1-($e1*($e2/100))'],
44
- ['e + e %', '$$ = $e1+($e1*($e2/100))'],
45
- ['e * e %', '$$ = $e1*($e2/100)'],
46
- ['( e % )', '$$ = $2/100'],
47
- ['- e', '$$ = -$2', { prec: 'UMINUS' }],
48
- ['( e )', '$$ = $2'],
49
- ['NUMBER', '$$ = Number(yytext)'],
50
- ['VARIABLE', varValue],
51
- ['E', '$$ = Math.E'],
52
- ['PI', '$$ = Math.PI']
53
- ]
54
- }
55
- };
56
- }
57
- export const xxxGrammar = {
58
- lex: {
59
- rules: [
60
- // Saute les espaces
61
- ['\\s+', '/* skip whitespace */'],
62
- ]
63
- },
64
- operators: [],
65
- bnf: {}
66
- };
@@ -1,11 +0,0 @@
1
- export declare function datetimeGrammar(solve: boolean): {
2
- lex: {
3
- rules: string[][];
4
- };
5
- operators: never[];
6
- bnf: {
7
- expressions: string[][];
8
- e: string[][];
9
- };
10
- };
11
- //# sourceMappingURL=datetime.grammar.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"datetime.grammar.d.ts","sourceRoot":"","sources":["../../src/jison/datetime.grammar.ts"],"names":[],"mappings":"AAAA,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO;;;;;;;;;EA2C7C"}
@@ -1,42 +0,0 @@
1
- export function datetimeGrammar(solve) {
2
- const varValue = solve ? 'return null' : '$$ = ``';
3
- return {
4
- lex: {
5
- rules: [
6
- ['\\s+', '/* skip whitespace */'],
7
- ['\\$\\w+', 'return `VARIABLE`'],
8
- ['=', 'return `BEGEXP`'],
9
- ['"', 'return `QUOT`'],
10
- ['\/', 'return `/`'],
11
- ['(0?[1-9]|1[012])', 'return `MM`'],
12
- ['(0?[1-9]|[12][0-9]|3[01])', 'return `DD`'],
13
- ['\\d\{4\}', 'return `YYYY`'],
14
- ['NOW|now', 'return `NOW`'],
15
- // ['0?[0-9]|[1][0-9]|2[01234]', 'return `HH`'],
16
- // ['0?[0-9]|[12345][0-9]', 'return `0-59`'],
17
- // ['\-', 'return `-`'],
18
- // ['[12]\\d\\d\\d\\-(0?[1-9]|1[012])\\-(0?[1-9]|[12][0-9]|3[01])', 'return USDATE'],
19
- // ['[1-9]+[Dd]', 'return `ADD`'],
20
- // ['\+', 'return `+`'],
21
- ['$', 'return `EOF`']
22
- ]
23
- },
24
- operators: [],
25
- bnf: {
26
- expressions: [['BEGEXP e EOF', 'return $2']],
27
- e: [
28
- ['DD / e', '$$ = $1'],
29
- ['e / YYYY', '$$ = $3'],
30
- ['/ MM /', '$$ = $2'],
31
- // ['YYYY - MM - DD', '$$ = new Date($e1, $e2, $e3)'],
32
- // ['DD / MM / YYYY', '$$ = new Date($e3, $e2, $e1)'],
33
- // ['HH : 0-59 : 0-59', '$$ = new Date(0, 0, 0, $e1, $e2, $e3)'],
34
- // ['QUOT MM QUOT', '$$ = 0'],
35
- ['NOW', '$$ = Date.now()'],
36
- // ['e + ADD', '$$ = ``'],
37
- // ['e + ADD', '$$ = {const ret = new Date($e1); return ret.setDate(ret.getDate() + parseInt($e2))}'],
38
- ['VARIABLE', varValue]
39
- ]
40
- }
41
- };
42
- }
@@ -1,11 +0,0 @@
1
- export declare function logicalGrammar(solve: boolean): {
2
- lex: {
3
- rules: string[][];
4
- };
5
- operators: string[][];
6
- bnf: {
7
- expressions: string[][];
8
- e: string[][];
9
- };
10
- };
11
- //# sourceMappingURL=logical.grammar.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"logical.grammar.d.ts","sourceRoot":"","sources":["../../src/jison/logical.grammar.ts"],"names":[],"mappings":"AACA,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO;;;;;;;;;EAsC5C"}
@@ -1,39 +0,0 @@
1
- export function logicalGrammar(solve) {
2
- const varValue = solve ? 'return null' : '$$ = 0';
3
- return {
4
- lex: {
5
- // startConditions: {
6
- // expression: 'return e',
7
- // value: 'return v'
8
- // },
9
- rules: [
10
- ['\\s+', '/* skip whitespace */'],
11
- ['[0-9]+(?:\\.[0-9]+)?\\b', 'return `NUMBER`'],
12
- ['\\$\\w+', 'return `VARIABLE`'],
13
- ['TRUE|true|FALSE|false', 'return `BOOLEAN`'],
14
- ['<=', 'return `INFEQ`'],
15
- ['>=', 'return `SUPEQ`'],
16
- ['<', 'return `INF`'],
17
- ['>', 'return `SUP`'],
18
- ['$', 'return `EOF`'],
19
- ['=', 'return `BEGEXP`']
20
- ]
21
- },
22
- operators: [
23
- ['left', 'INF', 'SUP', 'INFEQ', 'SUPEQ'],
24
- ['right', 'BEGEXP']
25
- ],
26
- bnf: {
27
- expressions: [['BEGEXP e EOF', 'return $2'], ['BOOLEAN EOF', 'return $1']],
28
- e: [
29
- ['NUMBER', '$$ = Number(yytext)'],
30
- ['VARIABLE', varValue],
31
- ['BOOLEAN', '$$ = yytext === `TRUE` || yytext === `true`'],
32
- ['e INF e', '$$ = $1<$3'],
33
- ['e SUP e', '$$ = $1 > $3'],
34
- ['e SUPEQ e', '$$ = $1 >= $3'],
35
- ['e INFEQ e', '$$ = $1 <= $3'],
36
- ]
37
- }
38
- };
39
- }
@@ -1,11 +0,0 @@
1
- export declare function optionGrammar(solve: boolean, options: string[]): {
2
- lex: {
3
- rules: string[][];
4
- };
5
- operators: never[];
6
- bnf: {
7
- expressions: string[][];
8
- e: string[][];
9
- };
10
- };
11
- //# sourceMappingURL=option.grammar.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"option.grammar.d.ts","sourceRoot":"","sources":["../../src/jison/option.grammar.ts"],"names":[],"mappings":"AAEA,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE;;;;;;;;;EAyB9D"}
@@ -1,24 +0,0 @@
1
- export function optionGrammar(solve, options) {
2
- const varValue = solve ? 'return null' : '$$ = ``';
3
- const optValue = options.join('|');
4
- return {
5
- lex: {
6
- rules: [
7
- ['\\s+', '/* skip whitespace */'],
8
- ['\\$\\w+', 'return `VARIABLE`'],
9
- ['"', 'return `QUOT`'],
10
- [optValue, 'return `OPTION`'],
11
- ['$', 'return `EOF`'],
12
- ['=', 'return `BEGEXP`']
13
- ]
14
- },
15
- operators: [],
16
- bnf: {
17
- expressions: [['BEGEXP e EOF', 'return $2'], ['OPTION EOF', 'return $1']],
18
- e: [
19
- ['QUOT OPTION QUOT', '$$ = $2'],
20
- ['VARIABLE', varValue]
21
- ]
22
- }
23
- };
24
- }
@@ -1,11 +0,0 @@
1
- export declare function stringGrammar(solve: boolean): {
2
- lex: {
3
- rules: string[][];
4
- };
5
- operators: string[][];
6
- bnf: {
7
- expressions: string[][];
8
- e: string[][];
9
- };
10
- };
11
- //# sourceMappingURL=string.grammar.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"string.grammar.d.ts","sourceRoot":"","sources":["../../src/jison/string.grammar.ts"],"names":[],"mappings":"AAEA,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO;;;;;;;;;EA+B3C"}
@@ -1,31 +0,0 @@
1
- /* tslint:disable:trailing-comma */
2
- export function stringGrammar(solve) {
3
- const varVariable = solve ? 'return null' : '$$ = ``';
4
- return {
5
- lex: {
6
- rules: [
7
- // Saute les espaces
8
- ['\\s+', '/* skip whitespace */'],
9
- ['\\$\\w+', 'return `VARIABLE`'],
10
- ['_', 'return `SPACE`'],
11
- ['"', 'return `QUOT`'],
12
- ['\\&', 'return `&`'],
13
- ['=', 'return `BEGEXP`'],
14
- ['[^"]+', 'return `STRING`'],
15
- ['$', 'return `EOF`'],
16
- ]
17
- },
18
- operators: [
19
- ['left', '&']
20
- ],
21
- bnf: {
22
- expressions: [['BEGEXP e EOF', 'return $2'], ['STRING EOF', 'return $1']],
23
- e: [
24
- ['e & e', '$$ = `${$1}${$3}`'],
25
- ['QUOT STRING QUOT', '$$ = $2'],
26
- ['SPACE', '$$ = ` `'],
27
- ['VARIABLE', varVariable]
28
- ]
29
- }
30
- };
31
- }
@@ -1,10 +0,0 @@
1
- export declare const variableGrammar: {
2
- lex: {
3
- rules: string[][];
4
- };
5
- operators: never[];
6
- bnf: {
7
- expressions: string[][];
8
- };
9
- };
10
- //# sourceMappingURL=variable.grammar.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"variable.grammar.d.ts","sourceRoot":"","sources":["../../src/jison/variable.grammar.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,eAAe;;;;;;;;CAa3B,CAAC"}
@@ -1,14 +0,0 @@
1
- export const variableGrammar = {
2
- lex: {
3
- rules: [
4
- // Saute les espaces
5
- ['\\s+', '/* skip whitespace */'],
6
- ['\\$\\w+', 'return `VARIABLE`'],
7
- ['$', 'return `EOF`']
8
- ]
9
- },
10
- operators: [],
11
- bnf: {
12
- expressions: [['VARIABLE EOF', 'return $1']]
13
- }
14
- };