Skip to content

Commit 47a7ebd

Browse files
committed
feat(parser): add support for parsing custom functions
1 parent df81e4a commit 47a7ebd

File tree

11 files changed

+1329
-717
lines changed

11 files changed

+1329
-717
lines changed

src/markProcessor.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type {CustomFunctions} from './rawParser'
12
import type {ParseOptions} from './types'
23

34
export type MarkName =
@@ -20,6 +21,7 @@ export type MarkName =
2021
| 'float'
2122
| 'func_args_end'
2223
| 'func_call'
24+
| 'func_decl'
2325
| 'ident'
2426
| 'inc_range'
2527
| 'integer'
@@ -53,19 +55,28 @@ export interface Mark {
5355
position: number
5456
}
5557

58+
export type FunctionId = `${string}::${string}`
59+
5660
export type MarkVisitor<T> = Record<string, MarkVisitorFunc<T>>
5761
export type MarkVisitorFunc<T> = (p: MarkProcessor, mark: Mark) => T
5862

5963
export class MarkProcessor {
60-
private string: string
64+
private _string: string
6165
private marks: Mark[]
6266
private index: number
67+
customFunctions: CustomFunctions
6368
parseOptions: ParseOptions
6469
allowBoost = false
6570

66-
constructor(string: string, marks: Mark[], parseOptions: ParseOptions) {
67-
this.string = string
71+
constructor(
72+
string: string,
73+
marks: Mark[],
74+
customFunctions: CustomFunctions,
75+
parseOptions: ParseOptions,
76+
) {
77+
this._string = string
6878
this.marks = marks
79+
this.customFunctions = customFunctions
6980
this.index = 0
7081
this.parseOptions = parseOptions
7182
}
@@ -108,4 +119,8 @@ export class MarkProcessor {
108119
const pos = this.marks[this.index].position
109120
return this.string.slice(pos, pos + len)
110121
}
122+
123+
get string(): string {
124+
return this._string
125+
}
111126
}

src/nodeTypes.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,14 @@ export interface ValueNode<P = any> {
272272
value: P
273273
}
274274

275+
export interface FunctionDeclarationNode {
276+
type: 'FuncDeclaration'
277+
namespace: string
278+
name: string
279+
params: ParameterNode[]
280+
body: ExprNode
281+
}
282+
275283
export interface FlatMapNode extends BaseNode {
276284
type: 'FlatMap'
277285
base: ExprNode

0 commit comments

Comments
 (0)