forked from cucumber/gherkin-javascript
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAstNode.ts
35 lines (28 loc) · 938 Bytes
/
AstNode.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { RuleType, TokenType } from './Parser'
import IToken from './IToken'
export default class AstNode {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private readonly subItems = new Map<any, any[]>()
constructor(public readonly ruleType: RuleType) {}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public add(type: any, obj: any) {
let items = this.subItems.get(type)
if (items === undefined) {
items = []
this.subItems.set(type, items)
}
items.push(obj)
}
public getSingle(ruleType: RuleType) {
return (this.subItems.get(ruleType) || [])[0]
}
public getItems(ruleType: RuleType) {
return this.subItems.get(ruleType) || []
}
public getToken(tokenType: TokenType) {
return (this.subItems.get(tokenType) || [])[0]
}
public getTokens(tokenType: TokenType): IToken<TokenType>[] {
return this.subItems.get(tokenType) || []
}
}