/
handler.ts
101 lines (78 loc) · 2.1 KB
/
handler.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
export interface IMappingHandler {
/**
* Called when the mapping start (inline / block) and must return
* something that store key / value pairs
*/
onMappingStart(offset: number): any
/**
* Called when the mapping parsed and return value used as final
* mapping object
*/
onMappingEnd(mapping: any): any
/**
* Called when a mapping key found
*/
onMappingKey(offset: number, mapping: any, key: any, value: any): void
}
export interface ISequenceHandler {
/**
* Called when a sequence start (inline / block) and must return
* sumething that store numerical indexed entries
*/
onSequenceStart(offset: number): any
/**
* Called when the sequence parsed and return value uased as final
* sequence object
*/
onSequenceEnd(sequence: any): any
/**
* Called when an sequence entry is found
*/
onSequenceEntry(offset: number, sequence: any, entry: any): void
}
export interface IScalarHandler {
/**
* Called when an unqouted string found
*/
onScalar(offset: number, value: string | null): any
/**
* Called when a single or double qouted string found
*/
onQuotedString(offset: number, value: string, quote: string): any
/**
* Called when a block string found
*/
onBlockString(offset: number, value: string): any
}
export interface ITagHandler {
/**
* Called when a tag start, and must return a factory function
* or NULL when not found a factory function
*/
onTagStart(offset: number, qname: string): ITypeFactory
/**
* Called when a tag is parsed and return value uased as final
* tag object
*/
onTagEnd(value: any): any
}
export interface IReferenceHandler {
/**
* Called when a anchor found (&anchor)
*/
onAnchor(offset: number, name: string, value: any): void
/**
* Called when an alias found (*alias)
*/
onAlias(offset: number, name: string): any
}
export interface ITypeFactory extends
IMappingHandler,
ISequenceHandler,
IScalarHandler,
ITagHandler {
}
export interface IDocumentHandler extends
ITypeFactory,
IReferenceHandler {
}