forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.ts
More file actions
105 lines (91 loc) · 2.47 KB
/
types.ts
File metadata and controls
105 lines (91 loc) · 2.47 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
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
102
103
104
105
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
export interface ITextRange {
readonly start: number;
readonly end: number;
readonly length: number;
contains(position: number): boolean;
}
export class TextRange implements ITextRange {
public static readonly empty = TextRange.fromBounds(0, 0);
public readonly start: number;
public readonly length: number;
constructor(start: number, length: number) {
if (start < 0) {
throw new Error('start must be non-negative');
}
if (length < 0) {
throw new Error('length must be non-negative');
}
this.start = start;
this.length = length;
}
public static fromBounds(start: number, end: number) {
return new TextRange(start, end - start);
}
public get end(): number {
return this.start + this.length;
}
public contains(position: number): boolean {
return position >= this.start && position < this.end;
}
}
export interface ITextRangeCollection<T> extends ITextRange {
count: number;
getItemAt(index: number): T;
getItemAtPosition(position: number): number;
getItemContaining(position: number): number;
}
export interface ITextIterator {
readonly length: number;
charCodeAt(index: number): number;
getText(): string;
}
export interface ICharacterStream extends ITextIterator {
position: number;
readonly currentChar: number;
readonly nextChar: number;
readonly prevChar: number;
getText(): string;
isEndOfStream(): boolean;
lookAhead(offset: number): number;
advance(offset: number): void;
moveNext(): boolean;
isAtWhiteSpace(): boolean;
isAtLineBreak(): boolean;
isAtString(): boolean;
skipLineBreak(): void;
skipWhitespace(): void;
skipToEol(): void;
skipToWhitespace(): void;
}
export enum TokenType {
Unknown,
String,
Comment,
Keyword,
Number,
Identifier,
Operator,
Colon,
Semicolon,
Comma,
OpenBrace,
CloseBrace,
OpenBracket,
CloseBracket,
OpenCurly,
CloseCurly
}
export interface IToken extends ITextRange {
readonly type: TokenType;
}
export enum TokenizerMode {
CommentsAndStrings,
Full
}
export interface ITokenizer {
tokenize(text: string): ITextRangeCollection<IToken>;
tokenize(text: string, start: number, length: number, mode: TokenizerMode): ITextRangeCollection<IToken>;
}