@borgar/fx 4.7.0 → 4.8.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/dist/fx.d.ts +80 -34
- package/dist/fx.js +1 -1
- package/docs/API.md +168 -82
- package/docs/AST_format.md +45 -15
- package/docs/Prefixes.md +1 -1
- package/lib/a1.js +2 -0
- package/lib/astTypes.js +96 -0
- package/lib/constants.js +3 -0
- package/lib/index.spec.js +67 -0
- package/lib/lexer.js +51 -0
- package/lib/lexer.spec.js +63 -0
- package/lib/lexerParts.js +5 -0
- package/lib/parser.js +235 -33
- package/lib/parser.spec.js +380 -89
- package/lib/rc.js +2 -0
- package/package.json +1 -1
package/docs/API.md
CHANGED
|
@@ -5,9 +5,7 @@
|
|
|
5
5
|
- [addA1RangeBounds( range )](#addA1RangeBounds)
|
|
6
6
|
- [addTokenMeta( tokenlist, _\[context\]_ )](#addTokenMeta)
|
|
7
7
|
- [fixRanges( formula, _\[options\]_ )](#fixRanges)
|
|
8
|
-
- [fromA1( rangeString )](#fromA1)
|
|
9
8
|
- [fromCol( columnString )](#fromCol)
|
|
10
|
-
- [fromR1C1( rangeString )](#fromR1C1)
|
|
11
9
|
- [isError( token )](#isError)
|
|
12
10
|
- [isFunction( token )](#isFunction)
|
|
13
11
|
- [isFxPrefix( token )](#isFxPrefix)
|
|
@@ -24,9 +22,7 @@
|
|
|
24
22
|
- [stringifyA1Ref( refObject, _\[options\]_ )](#stringifyA1Ref)
|
|
25
23
|
- [stringifyR1C1Ref( refObject, _\[options\]_ )](#stringifyR1C1Ref)
|
|
26
24
|
- [stringifyStructRef( refObject, _\[options\]_ )](#stringifyStructRef)
|
|
27
|
-
- [toA1( range )](#toA1)
|
|
28
25
|
- [toCol( columnIndex )](#toCol)
|
|
29
|
-
- [toR1C1( range )](#toR1C1)
|
|
30
26
|
- [tokenize( formula, _\[options\]_ )](#tokenize)
|
|
31
27
|
- [translateToA1( formula, anchorCell, _\[options\]_ )](#translateToA1)
|
|
32
28
|
- [translateToR1C1( formula, anchorCell, _\[options\]_ )](#translateToR1C1)
|
|
@@ -38,13 +34,26 @@
|
|
|
38
34
|
|
|
39
35
|
**Types**
|
|
40
36
|
|
|
37
|
+
- [AstExpression](#AstExpression)
|
|
38
|
+
- [BinaryExpression](#BinaryExpression)
|
|
39
|
+
- [CallExpression](#CallExpression)
|
|
40
|
+
- [ErrorLiteral](#ErrorLiteral)
|
|
41
|
+
- [Identifier](#Identifier)
|
|
42
|
+
- [LambdaExpression](#LambdaExpression)
|
|
43
|
+
- [LetDeclarator](#LetDeclarator)
|
|
44
|
+
- [LetExpression](#LetExpression)
|
|
45
|
+
- [Literal](#Literal)
|
|
46
|
+
- [MatrixExpression](#MatrixExpression)
|
|
41
47
|
- [RangeA1](#RangeA1)
|
|
42
48
|
- [RangeR1C1](#RangeR1C1)
|
|
43
49
|
- [ReferenceA1](#ReferenceA1)
|
|
50
|
+
- [ReferenceIdentifier](#ReferenceIdentifier)
|
|
44
51
|
- [ReferenceR1C1](#ReferenceR1C1)
|
|
45
52
|
- [ReferenceStruct](#ReferenceStruct)
|
|
53
|
+
- [SourceLocation](#SourceLocation)
|
|
46
54
|
- [Token](#Token)
|
|
47
55
|
- [TokenEnhanced](#TokenEnhanced)
|
|
56
|
+
- [UnaryExpression](#UnaryExpression)
|
|
48
57
|
|
|
49
58
|
## Functions
|
|
50
59
|
|
|
@@ -177,24 +186,6 @@ Returns the same formula with the ranges updated. If an array of tokens was supp
|
|
|
177
186
|
|
|
178
187
|
---
|
|
179
188
|
|
|
180
|
-
### <a id="fromA1" href="#fromA1">#</a> fromA1( rangeString ) ⇒ [`RangeA1`](#RangeA1) | `null`
|
|
181
|
-
|
|
182
|
-
Parse a simple string reference to an A1 range into a range object. Will accept `A1`, `A2`, `A:A`, or `1:1`.
|
|
183
|
-
|
|
184
|
-
**See also:** [parseA1Ref](#parseA1Ref).
|
|
185
|
-
|
|
186
|
-
##### Parameters
|
|
187
|
-
|
|
188
|
-
| Name | Type | Description |
|
|
189
|
-
| ----------- | -------- | -------------- |
|
|
190
|
-
| rangeString | `string` | A range string |
|
|
191
|
-
|
|
192
|
-
##### Returns
|
|
193
|
-
|
|
194
|
-
[`RangeA1`](#RangeA1) | `null` – An object representing a valid range or null if it is invalid.
|
|
195
|
-
|
|
196
|
-
---
|
|
197
|
-
|
|
198
189
|
### <a id="fromCol" href="#fromCol">#</a> fromCol( columnString ) ⇒ `number`
|
|
199
190
|
|
|
200
191
|
Convert a column string representation to a 0 based offset number (`"C"` = `2`).
|
|
@@ -213,24 +204,6 @@ The method expects a valid column identifier made up of _only_ A-Z letters, whic
|
|
|
213
204
|
|
|
214
205
|
---
|
|
215
206
|
|
|
216
|
-
### <a id="fromR1C1" href="#fromR1C1">#</a> fromR1C1( rangeString ) ⇒ [`RangeR1C1`](#RangeR1C1) | `null`
|
|
217
|
-
|
|
218
|
-
Parse a simple string reference to an R1C1 range into a range object.
|
|
219
|
-
|
|
220
|
-
**See also:** [parseA1Ref](#parseA1Ref).
|
|
221
|
-
|
|
222
|
-
##### Parameters
|
|
223
|
-
|
|
224
|
-
| Name | Type | Description |
|
|
225
|
-
| ----------- | -------- | -------------- |
|
|
226
|
-
| rangeString | `string` | A range string |
|
|
227
|
-
|
|
228
|
-
##### Returns
|
|
229
|
-
|
|
230
|
-
[`RangeR1C1`](#RangeR1C1) | `null` – An object representing a valid reference or null if it is invalid.
|
|
231
|
-
|
|
232
|
-
---
|
|
233
|
-
|
|
234
207
|
### <a id="isError" href="#isError">#</a> isError( token ) ⇒ `boolean`
|
|
235
208
|
|
|
236
209
|
Determines whether the specified token is an error.
|
|
@@ -391,7 +364,7 @@ When given a tokenlist, this function returns a new list with ranges returned as
|
|
|
391
364
|
|
|
392
365
|
---
|
|
393
366
|
|
|
394
|
-
### <a id="parse" href="#parse">#</a> parse( formula, _[options = `{}`]_ ) ⇒ `
|
|
367
|
+
### <a id="parse" href="#parse">#</a> parse( formula, _[options = `{}`]_ ) ⇒ [`AstExpression`](#AstExpression)
|
|
395
368
|
|
|
396
369
|
Parses a string formula or list of tokens into an AST.
|
|
397
370
|
|
|
@@ -399,7 +372,7 @@ The parser requires `mergeRefs` to have been `true` in tokenlist options, becaus
|
|
|
399
372
|
|
|
400
373
|
The AST Abstract Syntax Tree's format is documented in [AST_format.md](./AST_format.md)
|
|
401
374
|
|
|
402
|
-
**See also:**
|
|
375
|
+
**See also:** [nodeTypes](#nodeTypes).
|
|
403
376
|
|
|
404
377
|
##### Parameters
|
|
405
378
|
|
|
@@ -418,7 +391,7 @@ The AST Abstract Syntax Tree's format is documented in [AST_format.md](./AST_for
|
|
|
418
391
|
|
|
419
392
|
##### Returns
|
|
420
393
|
|
|
421
|
-
`
|
|
394
|
+
[`AstExpression`](#AstExpression) – An AST of nodes
|
|
422
395
|
|
|
423
396
|
---
|
|
424
397
|
|
|
@@ -626,24 +599,6 @@ stringifyStructRef({
|
|
|
626
599
|
|
|
627
600
|
---
|
|
628
601
|
|
|
629
|
-
### <a id="toA1" href="#toA1">#</a> toA1( range ) ⇒ `string`
|
|
630
|
-
|
|
631
|
-
Stringify a range object into A1 syntax.
|
|
632
|
-
|
|
633
|
-
**See also:** [parseA1Ref](#parseA1Ref).
|
|
634
|
-
|
|
635
|
-
##### Parameters
|
|
636
|
-
|
|
637
|
-
| Name | Type | Description |
|
|
638
|
-
| ----- | --------------------- | -------------- |
|
|
639
|
-
| range | [`RangeA1`](#RangeA1) | A range object |
|
|
640
|
-
|
|
641
|
-
##### Returns
|
|
642
|
-
|
|
643
|
-
`string` – An A1-style string represenation of a range
|
|
644
|
-
|
|
645
|
-
---
|
|
646
|
-
|
|
647
602
|
### <a id="toCol" href="#toCol">#</a> toCol( columnIndex ) ⇒ `string`
|
|
648
603
|
|
|
649
604
|
Convert a 0 based offset number to a column string representation (`2` = `"C"`).
|
|
@@ -662,24 +617,6 @@ The method expects a number between 0 and 16383. Other input will return garbage
|
|
|
662
617
|
|
|
663
618
|
---
|
|
664
619
|
|
|
665
|
-
### <a id="toR1C1" href="#toR1C1">#</a> toR1C1( range ) ⇒ `string`
|
|
666
|
-
|
|
667
|
-
Stringify a range object into R1C1 syntax.
|
|
668
|
-
|
|
669
|
-
**See also:** [parseR1C1Ref](#parseR1C1Ref).
|
|
670
|
-
|
|
671
|
-
##### Parameters
|
|
672
|
-
|
|
673
|
-
| Name | Type | Description |
|
|
674
|
-
| ----- | ------------------------- | -------------- |
|
|
675
|
-
| range | [`RangeR1C1`](#RangeR1C1) | A range object |
|
|
676
|
-
|
|
677
|
-
##### Returns
|
|
678
|
-
|
|
679
|
-
`string` – An R1C1-style string represenation of a range
|
|
680
|
-
|
|
681
|
-
---
|
|
682
|
-
|
|
683
620
|
### <a id="tokenize" href="#tokenize">#</a> tokenize( formula, _[options = `{}`]_ ) ⇒ `Array<Token>`
|
|
684
621
|
|
|
685
622
|
Breaks a string formula into a list of tokens.
|
|
@@ -707,7 +644,7 @@ To support syntax highlighting as you type, `STRING` tokens are allowed to be "u
|
|
|
707
644
|
]
|
|
708
645
|
```
|
|
709
646
|
|
|
710
|
-
**See also:**
|
|
647
|
+
**See also:** [tokenTypes](#tokenTypes).
|
|
711
648
|
|
|
712
649
|
##### Parameters
|
|
713
650
|
|
|
@@ -802,7 +739,7 @@ translateToR1C1("=SUM(E10,$E$2,Sheet!$E$3)", "D10");
|
|
|
802
739
|
|
|
803
740
|
A dictionary of the types used to identify AST node variants.
|
|
804
741
|
|
|
805
|
-
**See also:**
|
|
742
|
+
**See also:** [parse](#parse).
|
|
806
743
|
|
|
807
744
|
##### Properties
|
|
808
745
|
|
|
@@ -823,7 +760,7 @@ A dictionary of the types used to identify AST node variants.
|
|
|
823
760
|
|
|
824
761
|
A dictionary of the types used to identify token variants.
|
|
825
762
|
|
|
826
|
-
**See also:**
|
|
763
|
+
**See also:** [tokenize](#tokenize).
|
|
827
764
|
|
|
828
765
|
##### Properties
|
|
829
766
|
|
|
@@ -851,6 +788,125 @@ A dictionary of the types used to identify token variants.
|
|
|
851
788
|
|
|
852
789
|
## Types
|
|
853
790
|
|
|
791
|
+
### <a id="AstExpression" href="#AstExpression">#</a> AstExpression = [`ReferenceIdentifier`](#ReferenceIdentifier) | [`Literal`](#Literal) | [`ErrorLiteral`](#ErrorLiteral) | [`UnaryExpression`](#UnaryExpression) | [`BinaryExpression`](#BinaryExpression) | [`CallExpression`](#CallExpression) | [`MatrixExpression`](#MatrixExpression) | [`LambdaExpression`](#LambdaExpression) | [`LetExpression`](#LetExpression)
|
|
792
|
+
|
|
793
|
+
---
|
|
794
|
+
|
|
795
|
+
### <a id="BinaryExpression" href="#BinaryExpression">#</a> BinaryExpression = `Node`
|
|
796
|
+
|
|
797
|
+
##### Properties
|
|
798
|
+
|
|
799
|
+
| Name | Type |
|
|
800
|
+
| --------- | -------------------------------------------------------------------------------------------------------------------------------------- |
|
|
801
|
+
| arguments | `Array<AstExpression>` |
|
|
802
|
+
| [loc] | [`SourceLocation`](#SourceLocation) |
|
|
803
|
+
| operator | `"="` \| `"<"` \| `">"` \| `"<="` \| `">="` \| `"<>"` \| `"-"` \| `"+"` \| `"*"` \| `"/"` \| `"^"` \| `":"` \| `" "` \| `","` \| `"&"` |
|
|
804
|
+
| type | `"BinaryExpression"` |
|
|
805
|
+
|
|
806
|
+
---
|
|
807
|
+
|
|
808
|
+
### <a id="CallExpression" href="#CallExpression">#</a> CallExpression = `Node`
|
|
809
|
+
|
|
810
|
+
##### Properties
|
|
811
|
+
|
|
812
|
+
| Name | Type |
|
|
813
|
+
| --------- | ----------------------------------- |
|
|
814
|
+
| arguments | `Array<AstExpression>` |
|
|
815
|
+
| callee | [`Identifier`](#Identifier) |
|
|
816
|
+
| [loc] | [`SourceLocation`](#SourceLocation) |
|
|
817
|
+
| type | `"CallExpression"` |
|
|
818
|
+
|
|
819
|
+
---
|
|
820
|
+
|
|
821
|
+
### <a id="ErrorLiteral" href="#ErrorLiteral">#</a> ErrorLiteral = `Node`
|
|
822
|
+
|
|
823
|
+
##### Properties
|
|
824
|
+
|
|
825
|
+
| Name | Type |
|
|
826
|
+
| ----- | ----------------------------------- |
|
|
827
|
+
| [loc] | [`SourceLocation`](#SourceLocation) |
|
|
828
|
+
| raw | `string` |
|
|
829
|
+
| type | `"ErrorLiteral"` |
|
|
830
|
+
| value | `string` |
|
|
831
|
+
|
|
832
|
+
---
|
|
833
|
+
|
|
834
|
+
### <a id="Identifier" href="#Identifier">#</a> Identifier = `Node`
|
|
835
|
+
|
|
836
|
+
##### Properties
|
|
837
|
+
|
|
838
|
+
| Name | Type |
|
|
839
|
+
| ----- | ----------------------------------- |
|
|
840
|
+
| [loc] | [`SourceLocation`](#SourceLocation) |
|
|
841
|
+
| name | `string` |
|
|
842
|
+
| type | `"Identifier"` |
|
|
843
|
+
|
|
844
|
+
---
|
|
845
|
+
|
|
846
|
+
### <a id="LambdaExpression" href="#LambdaExpression">#</a> LambdaExpression = `Node`
|
|
847
|
+
|
|
848
|
+
##### Properties
|
|
849
|
+
|
|
850
|
+
| Name | Type |
|
|
851
|
+
| ------ | ------------------------------------------- |
|
|
852
|
+
| body | `null` \| [`AstExpression`](#AstExpression) |
|
|
853
|
+
| [loc] | [`SourceLocation`](#SourceLocation) |
|
|
854
|
+
| params | `Array<Identifier>` |
|
|
855
|
+
| type | `"LambdaExpression"` |
|
|
856
|
+
|
|
857
|
+
---
|
|
858
|
+
|
|
859
|
+
### <a id="LetDeclarator" href="#LetDeclarator">#</a> LetDeclarator = `Node`
|
|
860
|
+
|
|
861
|
+
##### Properties
|
|
862
|
+
|
|
863
|
+
| Name | Type |
|
|
864
|
+
| ----- | ------------------------------------------- |
|
|
865
|
+
| id | [`Identifier`](#Identifier) |
|
|
866
|
+
| init | `null` \| [`AstExpression`](#AstExpression) |
|
|
867
|
+
| [loc] | [`SourceLocation`](#SourceLocation) |
|
|
868
|
+
| type | `"LetDeclarator"` |
|
|
869
|
+
|
|
870
|
+
---
|
|
871
|
+
|
|
872
|
+
### <a id="LetExpression" href="#LetExpression">#</a> LetExpression = `Node`
|
|
873
|
+
|
|
874
|
+
##### Properties
|
|
875
|
+
|
|
876
|
+
| Name | Type |
|
|
877
|
+
| ------------ | ------------------------------------------- |
|
|
878
|
+
| body | `null` \| [`AstExpression`](#AstExpression) |
|
|
879
|
+
| declarations | `Array<LetDeclarator>` |
|
|
880
|
+
| [loc] | [`SourceLocation`](#SourceLocation) |
|
|
881
|
+
| type | `"LetExpression"` |
|
|
882
|
+
|
|
883
|
+
---
|
|
884
|
+
|
|
885
|
+
### <a id="Literal" href="#Literal">#</a> Literal = `Node`
|
|
886
|
+
|
|
887
|
+
##### Properties
|
|
888
|
+
|
|
889
|
+
| Name | Type |
|
|
890
|
+
| ----- | ----------------------------------- |
|
|
891
|
+
| [loc] | [`SourceLocation`](#SourceLocation) |
|
|
892
|
+
| raw | `string` |
|
|
893
|
+
| type | `"Literal"` |
|
|
894
|
+
| value | `string` \| `number` \| `boolean` |
|
|
895
|
+
|
|
896
|
+
---
|
|
897
|
+
|
|
898
|
+
### <a id="MatrixExpression" href="#MatrixExpression">#</a> MatrixExpression = `Node`
|
|
899
|
+
|
|
900
|
+
##### Properties
|
|
901
|
+
|
|
902
|
+
| Name | Type |
|
|
903
|
+
| --------- | ------------------------------------------------------------------------------- |
|
|
904
|
+
| arguments | `Array<Array<(ReferenceIdentifier | Literal | ErrorLiteral | CallExpression)>>` |
|
|
905
|
+
| [loc] | [`SourceLocation`](#SourceLocation) |
|
|
906
|
+
| type | `"ArrayExpression"` |
|
|
907
|
+
|
|
908
|
+
---
|
|
909
|
+
|
|
854
910
|
### <a id="RangeA1" href="#RangeA1">#</a> RangeA1
|
|
855
911
|
|
|
856
912
|
A range in A1 style coordinates.
|
|
@@ -904,6 +960,19 @@ A reference containing an A1 style range. See [Prefixes.md] for documentation
|
|
|
904
960
|
|
|
905
961
|
---
|
|
906
962
|
|
|
963
|
+
### <a id="ReferenceIdentifier" href="#ReferenceIdentifier">#</a> ReferenceIdentifier = `Node`
|
|
964
|
+
|
|
965
|
+
##### Properties
|
|
966
|
+
|
|
967
|
+
| Name | Type |
|
|
968
|
+
| ----- | ---------------------------------------------- |
|
|
969
|
+
| kind | `"name"` \| `"range"` \| `"beam"` \| `"table"` |
|
|
970
|
+
| [loc] | [`SourceLocation`](#SourceLocation) |
|
|
971
|
+
| type | `"ReferenceIdentifier"` |
|
|
972
|
+
| value | `string` |
|
|
973
|
+
|
|
974
|
+
---
|
|
975
|
+
|
|
907
976
|
### <a id="ReferenceR1C1" href="#ReferenceR1C1">#</a> ReferenceR1C1
|
|
908
977
|
|
|
909
978
|
A reference containing a R1C1 style range. See [Prefixes.md] for documentation on how scopes work in Fx.
|
|
@@ -936,6 +1005,10 @@ A reference containing a table slice definition. See [Prefixes.md] for documen
|
|
|
936
1005
|
|
|
937
1006
|
---
|
|
938
1007
|
|
|
1008
|
+
### <a id="SourceLocation" href="#SourceLocation">#</a> SourceLocation = `Array<number>`
|
|
1009
|
+
|
|
1010
|
+
---
|
|
1011
|
+
|
|
939
1012
|
### <a id="Token" href="#Token">#</a> Token extends `Record<string, any>`
|
|
940
1013
|
|
|
941
1014
|
A formula language token.
|
|
@@ -966,4 +1039,17 @@ A token with extra meta data.
|
|
|
966
1039
|
|
|
967
1040
|
---
|
|
968
1041
|
|
|
1042
|
+
### <a id="UnaryExpression" href="#UnaryExpression">#</a> UnaryExpression = `Node`
|
|
1043
|
+
|
|
1044
|
+
##### Properties
|
|
1045
|
+
|
|
1046
|
+
| Name | Type |
|
|
1047
|
+
| --------- | ----------------------------------------- |
|
|
1048
|
+
| arguments | `Array<AstExpression>` |
|
|
1049
|
+
| [loc] | [`SourceLocation`](#SourceLocation) |
|
|
1050
|
+
| operator | `"+"` \| `"-"` \| `"%"` \| `"#"` \| `"@"` |
|
|
1051
|
+
| type | `"UnaryExpression"` |
|
|
1052
|
+
|
|
1053
|
+
---
|
|
1054
|
+
|
|
969
1055
|
|
package/docs/AST_format.md
CHANGED
|
@@ -6,7 +6,7 @@ This document specifies the core AST node types that support the Excel grammar.
|
|
|
6
6
|
|
|
7
7
|
All AST nodes are represented by `Node` objects. They may have any prototype inheritance but implement the following basic interface:
|
|
8
8
|
|
|
9
|
-
```
|
|
9
|
+
```ts
|
|
10
10
|
interface Node {
|
|
11
11
|
type: string;
|
|
12
12
|
loc?: Location | null;
|
|
@@ -17,7 +17,7 @@ The `type` field is a string representing the AST variant type. Each subtype of
|
|
|
17
17
|
|
|
18
18
|
The `loc` field represents the source location information of the node. If the node contains no information about the source location, the field is `null`; otherwise it is an array consisting of a two numbers: A start offset (the position of the first character of the parsed source region) and an end offset (the position of the first character after the parsed source region):
|
|
19
19
|
|
|
20
|
-
```
|
|
20
|
+
```ts
|
|
21
21
|
interface Location extends Array<number> {
|
|
22
22
|
0: number;
|
|
23
23
|
1: number;
|
|
@@ -26,30 +26,31 @@ interface Location extends Array<number> {
|
|
|
26
26
|
|
|
27
27
|
## Identifier
|
|
28
28
|
|
|
29
|
-
```
|
|
29
|
+
```ts
|
|
30
30
|
interface Identifier extends Node {
|
|
31
31
|
type: "Identifier";
|
|
32
32
|
name: string;
|
|
33
33
|
}
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
An identifier. These
|
|
36
|
+
An identifier. These appear on `CallExpression`, `LambdaExpression`, and `LetExpression` and will always be a static string representing the name of a function call or parameter.
|
|
37
37
|
|
|
38
38
|
## ReferenceIdentifier
|
|
39
39
|
|
|
40
|
-
```
|
|
40
|
+
```ts
|
|
41
41
|
interface ReferenceIdentifier extends Node {
|
|
42
42
|
type: "ReferenceIdentifier";
|
|
43
43
|
value: string;
|
|
44
|
+
kind: "name" | "range" | "beam" | "table";
|
|
44
45
|
}
|
|
45
46
|
```
|
|
46
47
|
|
|
47
|
-
|
|
48
|
+
An identifier for a range or a named. The
|
|
48
49
|
|
|
49
50
|
|
|
50
51
|
## Literal
|
|
51
52
|
|
|
52
|
-
```
|
|
53
|
+
```ts
|
|
53
54
|
interface Literal extends Node {
|
|
54
55
|
type: "Literal";
|
|
55
56
|
raw: string;
|
|
@@ -61,7 +62,7 @@ A literal token. Captures numbers, strings, and booleans. Literal errors have th
|
|
|
61
62
|
|
|
62
63
|
## ErrorLiteral
|
|
63
64
|
|
|
64
|
-
```
|
|
65
|
+
```ts
|
|
65
66
|
interface ErrorLiteral extends Node {
|
|
66
67
|
type: "ErrorLiteral";
|
|
67
68
|
raw: string;
|
|
@@ -73,7 +74,7 @@ An Error expression.
|
|
|
73
74
|
|
|
74
75
|
## UnaryExpression
|
|
75
76
|
|
|
76
|
-
```
|
|
77
|
+
```ts
|
|
77
78
|
interface UnaryExpression extends Node {
|
|
78
79
|
type: "UnaryExpression";
|
|
79
80
|
operator: UnaryOperator;
|
|
@@ -85,7 +86,7 @@ A unary operator expression.
|
|
|
85
86
|
|
|
86
87
|
### UnaryOperator
|
|
87
88
|
|
|
88
|
-
```
|
|
89
|
+
```ts
|
|
89
90
|
type UnaryOperator = (
|
|
90
91
|
"+" | "-" | "%" | "#" | "@"
|
|
91
92
|
)
|
|
@@ -95,7 +96,7 @@ A unary operator token.
|
|
|
95
96
|
|
|
96
97
|
## BinaryExpression
|
|
97
98
|
|
|
98
|
-
```
|
|
99
|
+
```ts
|
|
99
100
|
interface BinaryExpression extends Node {
|
|
100
101
|
type: "BinaryExpression";
|
|
101
102
|
operator: BinaryOperator;
|
|
@@ -107,7 +108,7 @@ A binary operator expression.
|
|
|
107
108
|
|
|
108
109
|
### BinaryOperator
|
|
109
110
|
|
|
110
|
-
```
|
|
111
|
+
```ts
|
|
111
112
|
type BinaryOperator = (
|
|
112
113
|
"=" | "<" | ">" | "<=" | ">=" | "<>" |
|
|
113
114
|
"-" | "+" | "*" | "/" | "^" |
|
|
@@ -120,7 +121,7 @@ A binary operator token. Note that Excels union operator is whitespace so a pars
|
|
|
120
121
|
|
|
121
122
|
## CallExpression
|
|
122
123
|
|
|
123
|
-
```
|
|
124
|
+
```ts
|
|
124
125
|
interface CallExpression extends Node {
|
|
125
126
|
type: "CallExpression";
|
|
126
127
|
callee: Identifier;
|
|
@@ -132,13 +133,42 @@ A function call expression.
|
|
|
132
133
|
|
|
133
134
|
## ArrayExpression
|
|
134
135
|
|
|
135
|
-
```
|
|
136
|
+
```ts
|
|
136
137
|
interface ArrayExpression extends Node {
|
|
137
138
|
type: "ArrayExpression";
|
|
138
|
-
elements: Array<Array<Literal |
|
|
139
|
+
elements: Array<Array<ReferenceIdentifier | Literal | ErrorLiteral | CallExpression>>;
|
|
139
140
|
}
|
|
140
141
|
```
|
|
141
142
|
|
|
142
143
|
An array expression. Excel does not have empty or sparse arrays and restricts array elements to literals. Google Sheets allows `ReferenceIdentifier`s as elements of arrays, the fx parser as an option for this but it is off by default.
|
|
143
144
|
|
|
145
|
+
## LambdaExpression
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
interface LambdaExpression extends Node {
|
|
149
|
+
type: "LambdaExpression";
|
|
150
|
+
params: Array<Identifier>;
|
|
151
|
+
body: null | Node;
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## LetExpression
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
interface LetExpression extends Node {
|
|
159
|
+
type: "LetExpression";
|
|
160
|
+
declarations: Array<LetDeclarator>;
|
|
161
|
+
body: null | Node;
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## LetDeclarator
|
|
166
|
+
|
|
167
|
+
```ts
|
|
168
|
+
interface LetDeclarator extends Node {
|
|
169
|
+
type: "LetDeclarator";
|
|
170
|
+
id: Identifier;
|
|
171
|
+
init: null | Node;
|
|
172
|
+
}
|
|
173
|
+
```
|
|
144
174
|
|
package/docs/Prefixes.md
CHANGED
|
@@ -63,7 +63,7 @@ When Excel saves a workbook to one of its XML formats (most commonly as .xlsx) i
|
|
|
63
63
|
* `[a]!`
|
|
64
64
|
* `[a]b!`
|
|
65
65
|
|
|
66
|
-
Since the XML files only ever emitted with positive integer indexes instead of workbook names, whether the syntax allows anything else is
|
|
66
|
+
Since the XML files only ever emitted with positive integer indexes instead of workbook names, whether the syntax allows anything else is speculative. _Fx_ chooses to be permissive in handling this variant and allows `[Workbook.xlsx]!A1` forms as well as `[1]!A1`.
|
|
67
67
|
|
|
68
68
|
Why the formula language does not use this unambiguous and somewhat more intuitive variant rather than the above form is a question for Excel historians, likely this later form was introduced with the XML format to eliminate the ambiguity?
|
|
69
69
|
|
package/lib/a1.js
CHANGED
|
@@ -84,6 +84,7 @@ export function toAbsolute (range) {
|
|
|
84
84
|
* Stringify a range object into A1 syntax.
|
|
85
85
|
*
|
|
86
86
|
* @private
|
|
87
|
+
* @ignore
|
|
87
88
|
* @see parseA1Ref
|
|
88
89
|
* @param {RangeA1} range A range object
|
|
89
90
|
* @returns {string} An A1-style string represenation of a range
|
|
@@ -161,6 +162,7 @@ function splitA1 (str) {
|
|
|
161
162
|
* Will accept `A1`, `A2`, `A:A`, or `1:1`.
|
|
162
163
|
*
|
|
163
164
|
* @private
|
|
165
|
+
* @ignore
|
|
164
166
|
* @see parseA1Ref
|
|
165
167
|
* @param {string} rangeString A range string
|
|
166
168
|
* @returns {(RangeA1|null)} An object representing a valid range or null if it is invalid.
|
package/lib/astTypes.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/* eslint-disable jsdoc/require-property-description */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {number[]} SourceLocation
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {Node} Identifier
|
|
9
|
+
* @property {"Identifier"} type
|
|
10
|
+
* @property {SourceLocation} [loc]
|
|
11
|
+
* @property {string} name
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @typedef {Node} ReferenceIdentifier
|
|
16
|
+
* @property {"ReferenceIdentifier"} type
|
|
17
|
+
* @property {SourceLocation} [loc]
|
|
18
|
+
* @property {string} value
|
|
19
|
+
* @property {"name" | "range" | "beam" | "table"} kind
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @typedef {Node} Literal
|
|
24
|
+
* @property {"Literal"} type
|
|
25
|
+
* @property {SourceLocation} [loc]
|
|
26
|
+
* @property {string} raw
|
|
27
|
+
* @property {string | number | boolean} value
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @typedef {Node} ErrorLiteral
|
|
32
|
+
* @property {"ErrorLiteral"} type
|
|
33
|
+
* @property {SourceLocation} [loc]
|
|
34
|
+
* @property {string} raw
|
|
35
|
+
* @property {string} value
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @typedef {Node} UnaryExpression
|
|
40
|
+
* @property {"UnaryExpression"} type
|
|
41
|
+
* @property {SourceLocation} [loc]
|
|
42
|
+
* @property {"+" | "-" | "%" | "#" | "@"} operator
|
|
43
|
+
* @property {AstExpression[]} arguments
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @typedef {Node} BinaryExpression
|
|
48
|
+
* @property {"BinaryExpression"} type
|
|
49
|
+
* @property {SourceLocation} [loc]
|
|
50
|
+
* @property {"=" | "<" | ">" | "<=" | ">=" | "<>" | "-" | "+" | "*" | "/" | "^" | ":" | " " | "," | "&"} operator
|
|
51
|
+
* @property {AstExpression[]} arguments
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @typedef {Node} CallExpression
|
|
56
|
+
* @property {"CallExpression"} type
|
|
57
|
+
* @property {SourceLocation} [loc]
|
|
58
|
+
* @property {Identifier} callee
|
|
59
|
+
* @property {AstExpression[]} arguments
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
// FIXME: the awkward naming is because tooling fails, fix tooling :)
|
|
63
|
+
/**
|
|
64
|
+
* @typedef {Node} MatrixExpression
|
|
65
|
+
* @property {"ArrayExpression"} type
|
|
66
|
+
* @property {SourceLocation} [loc]
|
|
67
|
+
* @property {Array<Array<ReferenceIdentifier | Literal | ErrorLiteral | CallExpression>>} arguments
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @typedef {Node} LambdaExpression
|
|
72
|
+
* @property {"LambdaExpression"} type
|
|
73
|
+
* @property {SourceLocation} [loc]
|
|
74
|
+
* @property {Identifier[]} params
|
|
75
|
+
* @property {null | AstExpression} body
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @typedef {Node} LetExpression
|
|
80
|
+
* @property {"LetExpression"} type
|
|
81
|
+
* @property {SourceLocation} [loc]
|
|
82
|
+
* @property {LetDeclarator[]} declarations
|
|
83
|
+
* @property {null | AstExpression} body
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @typedef {Node} LetDeclarator
|
|
88
|
+
* @property {"LetDeclarator"} type
|
|
89
|
+
* @property {SourceLocation} [loc]
|
|
90
|
+
* @property {Identifier} id
|
|
91
|
+
* @property {null | AstExpression} init
|
|
92
|
+
*/
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @typedef {ReferenceIdentifier | Literal | ErrorLiteral | UnaryExpression | BinaryExpression | CallExpression | MatrixExpression | LambdaExpression | LetExpression} AstExpression
|
|
96
|
+
*/
|
package/lib/constants.js
CHANGED
|
@@ -22,8 +22,11 @@ export const REFERENCE = 'ReferenceIdentifier';
|
|
|
22
22
|
export const LITERAL = 'Literal';
|
|
23
23
|
export const ERROR_LITERAL = 'ErrorLiteral';
|
|
24
24
|
export const CALL = 'CallExpression';
|
|
25
|
+
export const LAMBDA = 'LambdaExpression';
|
|
26
|
+
export const LET = 'LetExpression';
|
|
25
27
|
export const ARRAY = 'ArrayExpression';
|
|
26
28
|
export const IDENTIFIER = 'Identifier';
|
|
29
|
+
export const LET_DECL = 'LetDeclarator';
|
|
27
30
|
|
|
28
31
|
export const MAX_COLS = (2 ** 14) - 1; // 16383
|
|
29
32
|
export const MAX_ROWS = (2 ** 20) - 1; // 1048575
|