File tree Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -43,5 +43,8 @@ export default {
43
43
main : "./lib.js" ,
44
44
typings : "./lib.d.ts"
45
45
} , null , 4 ) ) ;
46
+ } ,
47
+ async "build:readme.md" ( config ) {
48
+ await fs . writeFile ( config . out . join ( 'pkg/README.md' ) , await fs . readFile ( './dist.md' , { encoding : 'utf8' } ) ) ;
46
49
}
47
50
}
Original file line number Diff line number Diff line change
1
+ # expressions
2
+
3
+ Parser for the expression language used in the spreadsheet plugin. This document outlines the JavaScript portion of the
4
+ library. For Rust see [ the Rust crate] ( ../README.md ) .
5
+
6
+ ## Quickstart
7
+
8
+ In order to evaluate expressions, three things must happen;
9
+
10
+ 1 . A context object containing a [ Data Provider] (#Data Provider) must be registered
11
+ 2 . The list of all functions, variables and operators needs to be defined
12
+ 3 . The expression needs to be passed into the parser.
13
+
14
+ ## Data Provider
15
+
16
+ A data provider is an object which converts addresses into values. Addresses are arbitrary text tokens wrapped in
17
+ braces. The provider determines their meaning. [ See the ` repl.ts ` ] ( examples/repl.ts ) for a feature-complete REPL.
18
+
19
+ ``` typescript
20
+ import * as expr from ' expression' ;
21
+
22
+ class Table implements expr .DataSource {
23
+ query(cx : any , query : string ) {
24
+ // Parse the query however you need to.
25
+ // For example, the format `column:row`
26
+
27
+ return " Hey!" ;
28
+ }
29
+ }
30
+ ```
31
+
32
+ ## Context
33
+
34
+ Next you'll need a context object which holds state and variables and acts as an API to the expression engine. You can
35
+ define your own functions, globals and operators here.
36
+
37
+ ``` typescript
38
+ import * as assert from ' node:assert' ;
39
+ import * as expr from ' expression' ;
40
+
41
+ const cx = new expr .Context (new Table ())
42
+ .withGlobal (" twelve" , 12 )
43
+ .withGlobal (" print" , args => console .log (args ));
44
+
45
+ assert .eq (cx .evaluateStr (" twelve" ) == 12 );
46
+ ```
You can’t perform that action at this time.
0 commit comments