Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSource.ts
More file actions
Latest commit
70 lines (69 loc) · 2.22 KB
/
Copy pathSource.ts
File metadata and controls
70 lines (69 loc) · 2.22 KB
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
import{mendly}from"mendly"
import{CommentStripper}from"./CommentStripper.js"
import{Importer}from"./Importer.js"
exportclassSourceextendsmendly.Reader.Bufferedimplementsmendly.Error.Handler{
privateconstructor(
reader: mendly.Reader,
privateerrorHandler: mendly.Error.Handler=newmendly.Error.Handler.Console(),
privateimporter?: Importer
){
super(reader)
}
raise(message: mendly.Error): void
raise(message: string,level?: mendly.Error.Level,type?: string,region?: mendly.Error.Region): void
raise(
message: string|mendly.Error,
level?: mendly.Error.Level,
type="lexical",
region?: mendly.Error.Region
): void{
if(!(messageinstanceofmendly.Error)){
if(!level)level="critical"
if(!region)region=this.region
message=newmendly.Error(messageasstring,level,type,region)
}
this.errorHandler.raise(messageasmendly.Error)
}
requirePrefix(prefix: string|string[]): Source{
returnnewSource(newmendly.Reader.Prefix(this,prefix),this.errorHandler,this.importer)
}
till(endMark: string|string[]): Source{
returnnewSource(mendly.Reader.Till.create(this,endMark),this.errorHandler,this.importer)
}
until(endMark: string|string[]): Source{
returnnewSource(mendly.Reader.Until.create(this,endMark),this.errorHandler,this.importer)
}
readIfAny(...patterns: string[]): string|undefined{
letresult: string|undefined
for(constpatternofpatterns)
if(this.readIf(pattern)){
result=pattern
break
}
returnresult
}
open(locator: mendly.Uri): Source|string|undefined{
return(
this.importer
??((locator: mendly.Uri): Source|string|undefined=>{
constlocation=locator.resolve(this.region.resource)
constreader=mendly.Reader.open(location)
returnSource.from(reader,this.errorHandler,this.importer)
})
)(locator)
}
staticfrom(
content: string|mendly.Reader|undefined,
handler?: mendly.Error.Handler|undefined,
importer?: Importer
): Source|undefined{
returncontent
? newthis(
newCommentStripper(typeofcontent=="string" ? mendly.Reader.String.create(content) : content),
handler,
importer
)
: undefined
}
}
exportnamespaceSource{}