simple-graph-query 1.1.2 → 1.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.
- package/README.md +2 -112
- package/dist/ForgeExprEvaluator.d.ts +1 -0
- package/dist/forge-antlr/ForgeLexer.d.ts +19 -18
- package/dist/forge-antlr/ForgeParser.d.ts +20 -18
- package/dist/simple-graph-query.bundle.js +505 -421
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,118 +1,8 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Simple Graph Expression Evaluator
|
|
2
2
|
|
|
3
|
-
A TypeScript library for evaluating
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install forge-expr-evaluator
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Usage
|
|
12
|
-
|
|
13
|
-
### Browser (UMD Bundle)
|
|
14
|
-
```html
|
|
15
|
-
<script src="node_modules/forge-expr-evaluator/dist/forge-expr-evaluator.bundle.js"></script>
|
|
16
|
-
<script>
|
|
17
|
-
const evaluator = new ForgeExprEvaluator.ForgeExprEvaluatorUtil(datum, sourceCode);
|
|
18
|
-
const result = evaluator.evaluateExpression("some Board", 0);
|
|
19
|
-
console.log(result);
|
|
20
|
-
</script>
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
### Node.js
|
|
24
|
-
```javascript
|
|
25
|
-
const { ForgeExprEvaluatorUtil } = require('forge-expr-evaluator');
|
|
26
|
-
|
|
27
|
-
const evaluator = new ForgeExprEvaluatorUtil(datum, sourceCode);
|
|
28
|
-
const result = evaluator.evaluateExpression("some Board", 0);
|
|
29
|
-
console.log(result);
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
### TypeScript
|
|
33
|
-
```typescript
|
|
34
|
-
import { ForgeExprEvaluatorUtil, DatumParsed } from 'forge-expr-evaluator';
|
|
35
|
-
|
|
36
|
-
const datum: DatumParsed = {
|
|
37
|
-
parsed: {
|
|
38
|
-
instances: [/* your data */],
|
|
39
|
-
bitwidth: 4
|
|
40
|
-
},
|
|
41
|
-
data: "<alloy>...</alloy>"
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const sourceCode = `
|
|
45
|
-
sig Board { ... }
|
|
46
|
-
// your Forge signatures and predicates
|
|
47
|
-
`;
|
|
48
|
-
|
|
49
|
-
const evaluator = new ForgeExprEvaluatorUtil(datum, sourceCode);
|
|
50
|
-
const result = evaluator.evaluateExpression("some Board", 0);
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
## API
|
|
54
|
-
|
|
55
|
-
### `ForgeExprEvaluatorUtil`
|
|
56
|
-
|
|
57
|
-
#### Constructor
|
|
58
|
-
```typescript
|
|
59
|
-
new ForgeExprEvaluatorUtil(datum: DatumParsed, sourceCode: string)
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
#### Methods
|
|
63
|
-
```typescript
|
|
64
|
-
evaluateExpression(expression: string, instanceIndex?: number): EvaluationResult
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
### Types
|
|
68
|
-
- `DatumParsed`: Data structure containing Forge model instances
|
|
69
|
-
- `EvaluationResult`: Result of expression evaluation (value or error)
|
|
70
|
-
- `EvalResult`: Successful evaluation result (string | number | boolean | Tuple[])
|
|
71
|
-
|
|
72
|
-
## Features
|
|
73
|
-
|
|
74
|
-
- ✅ Browser-compatible UMD bundle (~688 KiB)
|
|
75
|
-
- ✅ TypeScript support with full type definitions
|
|
76
|
-
- ✅ Evaluates Forge expressions against model data
|
|
77
|
-
- ✅ No external dependencies in the bundle
|
|
78
|
-
- ✅ Works with Sterling/Alloy data formats
|
|
79
|
-
|
|
80
|
-
## Development
|
|
81
|
-
|
|
82
|
-
```bash
|
|
83
|
-
# Install dependencies
|
|
84
|
-
npm install
|
|
85
|
-
|
|
86
|
-
# Build the bundle
|
|
87
|
-
npm run build
|
|
88
|
-
|
|
89
|
-
# Run tests
|
|
90
|
-
npm test
|
|
91
|
-
|
|
92
|
-
# Serve demo locally
|
|
93
|
-
npm run serve
|
|
94
|
-
```
|
|
3
|
+
A TypeScript library for evaluating relational + some more expressions with a browser-compatible UMD bundle.
|
|
95
4
|
|
|
96
5
|
## License
|
|
97
6
|
|
|
98
7
|
MIT
|
|
99
8
|
|
|
100
|
-
## Contributing
|
|
101
|
-
|
|
102
|
-
1. Fork the repository
|
|
103
|
-
2. Create a feature branch
|
|
104
|
-
3. Make your changes
|
|
105
|
-
4. Add tests if needed
|
|
106
|
-
5. Submit a pull request
|
|
107
|
-
|
|
108
|
-
## Credits
|
|
109
|
-
|
|
110
|
-
_Note_: The evaluator makes use of a Forge parser built using ANTLR; this is largely taken from
|
|
111
|
-
the [parser developed by Siddhartha Prasad](https://github.com/sidprasad/forge-antlr/)
|
|
112
|
-
with some minor modifications to the grammar.
|
|
113
|
-
|
|
114
|
-
## Related
|
|
115
|
-
|
|
116
|
-
- [Forge Language](https://forge.binghamton.edu/)
|
|
117
|
-
- [Alloy](https://alloytools.org/)
|
|
118
|
-
- [Sterling Visualizer](https://sterling-js.github.io/)
|
|
@@ -20,6 +20,7 @@ export declare class ForgeExprEvaluator extends AbstractParseTreeVisitor<EvalRes
|
|
|
20
20
|
constructor(datum: IDataInstance);
|
|
21
21
|
private updateFreeVariables;
|
|
22
22
|
private constructFreeVariableKey;
|
|
23
|
+
private getLabelForValue;
|
|
23
24
|
private cacheResult;
|
|
24
25
|
private getIden;
|
|
25
26
|
protected aggregateResult(aggregate: EvalResult, nextResult: EvalResult): EvalResult;
|
|
@@ -94,24 +94,25 @@ export declare class ForgeLexer extends Lexer {
|
|
|
94
94
|
static readonly EXAMPLE_TOK = 89;
|
|
95
95
|
static readonly ARROW_TOK = 90;
|
|
96
96
|
static readonly EQ_TOK = 91;
|
|
97
|
-
static readonly
|
|
98
|
-
static readonly
|
|
99
|
-
static readonly
|
|
100
|
-
static readonly
|
|
101
|
-
static readonly
|
|
102
|
-
static readonly
|
|
103
|
-
static readonly
|
|
104
|
-
static readonly
|
|
105
|
-
static readonly
|
|
106
|
-
static readonly
|
|
107
|
-
static readonly
|
|
108
|
-
static readonly
|
|
109
|
-
static readonly
|
|
110
|
-
static readonly
|
|
111
|
-
static readonly
|
|
112
|
-
static readonly
|
|
113
|
-
static readonly
|
|
114
|
-
static readonly
|
|
97
|
+
static readonly LABEL_EQ_TOK = 92;
|
|
98
|
+
static readonly LT_TOK = 93;
|
|
99
|
+
static readonly GT_TOK = 94;
|
|
100
|
+
static readonly LEQ_TOK = 95;
|
|
101
|
+
static readonly GEQ_TOK = 96;
|
|
102
|
+
static readonly NI_TOK = 97;
|
|
103
|
+
static readonly NO_TOK = 98;
|
|
104
|
+
static readonly SUM_TOK = 99;
|
|
105
|
+
static readonly INT_TOK = 100;
|
|
106
|
+
static readonly OPTION_TOK = 101;
|
|
107
|
+
static readonly COMMA_TOK = 102;
|
|
108
|
+
static readonly SLASH_TOK = 103;
|
|
109
|
+
static readonly NUM_CONST_TOK = 104;
|
|
110
|
+
static readonly IDENTIFIER_TOK = 105;
|
|
111
|
+
static readonly WS = 106;
|
|
112
|
+
static readonly CCOMMENT = 107;
|
|
113
|
+
static readonly COMMENT = 108;
|
|
114
|
+
static readonly MULTCOMMENT = 109;
|
|
115
|
+
static readonly LANG_DECL = 110;
|
|
115
116
|
static readonly channelNames: string[];
|
|
116
117
|
static readonly modeNames: string[];
|
|
117
118
|
static readonly ruleNames: string[];
|
|
@@ -100,24 +100,25 @@ export declare class ForgeParser extends Parser {
|
|
|
100
100
|
static readonly EXAMPLE_TOK = 89;
|
|
101
101
|
static readonly ARROW_TOK = 90;
|
|
102
102
|
static readonly EQ_TOK = 91;
|
|
103
|
-
static readonly
|
|
104
|
-
static readonly
|
|
105
|
-
static readonly
|
|
106
|
-
static readonly
|
|
107
|
-
static readonly
|
|
108
|
-
static readonly
|
|
109
|
-
static readonly
|
|
110
|
-
static readonly
|
|
111
|
-
static readonly
|
|
112
|
-
static readonly
|
|
113
|
-
static readonly
|
|
114
|
-
static readonly
|
|
115
|
-
static readonly
|
|
116
|
-
static readonly
|
|
117
|
-
static readonly
|
|
118
|
-
static readonly
|
|
119
|
-
static readonly
|
|
120
|
-
static readonly
|
|
103
|
+
static readonly LABEL_EQ_TOK = 92;
|
|
104
|
+
static readonly LT_TOK = 93;
|
|
105
|
+
static readonly GT_TOK = 94;
|
|
106
|
+
static readonly LEQ_TOK = 95;
|
|
107
|
+
static readonly GEQ_TOK = 96;
|
|
108
|
+
static readonly NI_TOK = 97;
|
|
109
|
+
static readonly NO_TOK = 98;
|
|
110
|
+
static readonly SUM_TOK = 99;
|
|
111
|
+
static readonly INT_TOK = 100;
|
|
112
|
+
static readonly OPTION_TOK = 101;
|
|
113
|
+
static readonly COMMA_TOK = 102;
|
|
114
|
+
static readonly SLASH_TOK = 103;
|
|
115
|
+
static readonly NUM_CONST_TOK = 104;
|
|
116
|
+
static readonly IDENTIFIER_TOK = 105;
|
|
117
|
+
static readonly WS = 106;
|
|
118
|
+
static readonly CCOMMENT = 107;
|
|
119
|
+
static readonly COMMENT = 108;
|
|
120
|
+
static readonly MULTCOMMENT = 109;
|
|
121
|
+
static readonly LANG_DECL = 110;
|
|
121
122
|
static readonly RULE_predDecl = 0;
|
|
122
123
|
static readonly RULE_parseExpr = 1;
|
|
123
124
|
static readonly RULE_alloyModule = 2;
|
|
@@ -769,6 +770,7 @@ export declare class ArrowOpContext extends ParserRuleContext {
|
|
|
769
770
|
export declare class CompareOpContext extends ParserRuleContext {
|
|
770
771
|
IN_TOK(): TerminalNode | undefined;
|
|
771
772
|
EQ_TOK(): TerminalNode | undefined;
|
|
773
|
+
LABEL_EQ_TOK(): TerminalNode | undefined;
|
|
772
774
|
LT_TOK(): TerminalNode | undefined;
|
|
773
775
|
GT_TOK(): TerminalNode | undefined;
|
|
774
776
|
LEQ_TOK(): TerminalNode | undefined;
|