tw5-typed 0.5.4 → 0.5.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tw5-typed",
3
- "version": "0.5.4",
3
+ "version": "0.5.5",
4
4
  "scripts": {
5
5
  "check": "tsc --noEmit && eslint src/**/*.ts",
6
6
  "docs": "docs-ts",
@@ -154,4 +154,25 @@ declare module 'tiddlywiki' {
154
154
  | ICustomParseTreeNode
155
155
  | IMacroParseTreeNode
156
156
  | IParseTreeAttribute;
157
+
158
+ export interface FilterParseTreeNode {
159
+ operators: FilterOperatorParseTreeNode[];
160
+ prefix: string;
161
+ }
162
+ export interface FilterOperatorParseTreeNode {
163
+ operands: FilterOperandParseTreeNode[];
164
+ operator: string;
165
+ suffix: string;
166
+ suffixes: string[][];
167
+ }
168
+ export interface FilterOperandParseTreeNode {
169
+ text: string;
170
+ }
171
+
172
+ export interface Wiki {
173
+ /**
174
+ * Parse a filter string
175
+ */
176
+ parseFilter(filter: string): FilterParseTreeNode[];
177
+ }
157
178
  }
@@ -22,6 +22,7 @@ declare module 'tiddlywiki' {
22
22
  import * as performance from '$:/core/modules/utils/performance.js';
23
23
  // import the class directly, to fix: Property 'log' does not exist on type 'typeof Logger'.ts(2339)
24
24
  import * as parsetree from '$:/core/modules/utils/parsetree.js';
25
+ import * as parseutils from '$:/core/modules/utils/parseutils.js';
25
26
  import * as pluginMaker from '$:/core/modules/utils/pluginmaker.js';
26
27
  import * as transliterate from '$:/core/modules/utils/transliterate.js';
27
28
  import * as crypto from '$:/core/modules/utils/crypto.js';
@@ -37,6 +38,7 @@ declare module 'tiddlywiki' {
37
38
  & Pick<typeof LinkedList, keyof typeof LinkedList>
38
39
  & Pick<typeof performance, keyof typeof performance>
39
40
  & Pick<typeof parsetree, keyof typeof parsetree>
41
+ & Pick<typeof parseutils, keyof typeof parseutils>
40
42
  & Pick<typeof pluginMaker, keyof typeof pluginMaker>
41
43
  & Pick<typeof transliterate, keyof typeof transliterate>
42
44
  & Pick<typeof crypto, keyof typeof crypto>
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Utility functions concerned with parsing text into tokens.
3
+ * Most functions have the following pattern:
4
+ * - The parameters are:
5
+ * - `source`: the source string being parsed
6
+ * - `pos`: the current parse position within the string
7
+ * - Any further parameters are used to identify the token that is being parsed
8
+ * - The return value is:
9
+ * - null if the token was not found at the specified position
10
+ * - an object representing the token with the following standard fields:
11
+ * - `type`: string indicating the type of the token
12
+ * - `start`: start position of the token in the source string
13
+ * - `end`: end position of the token in the source string
14
+ * - Any further fields required to describe the token
15
+ * The exception is `skipWhiteSpace`, which just returns the position after the whitespace.
16
+ */
17
+ declare module '$:/core/modules/utils/parseutils.js' {
18
+ /**
19
+ * Look for a whitespace token. Returns null if not found, otherwise returns an object.
20
+ */
21
+ export function parseWhiteSpace(source: string, pos: number): { end: number; start: number; type: 'whitespace' } | null;
22
+
23
+ /**
24
+ * Convenience wrapper for parseWhiteSpace. Returns the position after the whitespace.
25
+ */
26
+ export function skipWhiteSpace(source: string, pos: number): number;
27
+
28
+ /**
29
+ * Look for a given string token. Returns null if not found, otherwise returns an object.
30
+ */
31
+ export function parseTokenString(source: string, pos: number, token: string): { end: number; start: number; type: 'token'; value: string } | null;
32
+
33
+ /**
34
+ * Look for a token matching a regex. Returns null if not found, otherwise returns an object.
35
+ */
36
+ export function parseTokenRegExp(source: string, pos: number, reToken: RegExp): { end: number; match: RegExpExecArray; start: number; type: 'regexp' } | null;
37
+
38
+ /**
39
+ * Look for a string literal. Returns null if not found, otherwise returns an object.
40
+ */
41
+ export function parseStringLiteral(source: string, pos: number): { end: number; start: number; type: 'string'; value: string } | null;
42
+
43
+ /**
44
+ * Returns an array of {name:} with an optional "default" property. Options include `requireParenthesis`.
45
+ */
46
+ export function parseParameterDefinition(parameterString: string, options?: { requireParenthesis?: boolean }): Array<{ default?: string; name: string }>;
47
+
48
+ /**
49
+ * Process parameters for macro invocation.
50
+ */
51
+ export function parseMacroParameters(node: any, source: string, pos: number): any;
52
+
53
+ /**
54
+ * Look for a macro invocation parameter. Returns null if not found.
55
+ */
56
+ export function parseMacroParameter(source: string, pos: number): { end: number; name?: string; start: number; type: 'macro-parameter'; value: string } | null;
57
+
58
+ /**
59
+ * Look for a macro invocation. Returns null if not found.
60
+ */
61
+ export function parseMacroInvocation(source: string, pos: number): { end: number; name: string; params: any[]; start: number; type: 'macrocall' } | null;
62
+
63
+ /**
64
+ * Look for a macro invocation as transclusion. Returns null if not found.
65
+ */
66
+ export function parseMacroInvocationAsTransclusion(source: string, pos: number): { attributes: any; end: number; start: number; type: 'transclude' } | null;
67
+
68
+ export interface FilterVariableParseTreeNode {
69
+ name: string;
70
+ params: FilterVariableParameterParseTreeNode[];
71
+ }
72
+ export interface FilterVariableParameterParseTreeNode {
73
+ end: number;
74
+ start: number;
75
+ type: string;
76
+ value: string;
77
+ }
78
+ /**
79
+ * Parse filter variable parameters.
80
+ */
81
+ export function parseFilterVariable(source: string): FilterVariableParseTreeNode;
82
+
83
+ /**
84
+ * Look for an HTML attribute definition. Returns null if not found, otherwise returns an object.
85
+ */
86
+ export function parseAttribute(
87
+ source: string,
88
+ pos: number,
89
+ ): { end: number; filter?: string; name: string; start: number; textReference?: string; type: 'attribute'; value?: string } | null;
90
+ }
File without changes