-
Notifications
You must be signed in to change notification settings - Fork 2
/
TDCommentState.j
73 lines (62 loc) · 2.06 KB
/
TDCommentState.j
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
@import "TDTokenizerState.j"
@import "TDToken.j"
@import "TDReader.j"
@import "TDSymbolRootNode.j"
@import "TDMultiLineCommentState.j"
@import "TDSingleLineCommentState.j"
@implementation TDCommentState : TDTokenizerState
{
TDSymbolRootNode rootNode;
TDSingleLineCommentState singleLineState;
TDMultiLineCommentState multiLineState;
BOOL reportsCommentTokens;
BOOL balancesEOFTerminatedComments;
}
- (id)init
{
self = [super init];
if (self) {
rootNode = [[TDSymbolRootNode alloc] init];
singleLineState = [[TDSingleLineCommentState alloc] init];
multiLineState = [[TDMultiLineCommentState alloc] init];
}
return self;
}
- (void)addSingleLineStartSymbol:(CPString)start
{
[rootNode add:start];
[singleLineState addStartSymbol:start];
}
- (void)removeSingleLineStartSymbol:(CPString)start
{
[rootNode remove:start];
[singleLineState removeStartSymbol:start];
}
- (void)addMultiLineStartSymbol:(CPString)start endSymbol:(CPString)end
{
[rootNode add:start];
[rootNode add:end];
[multiLineState addStartSymbol:start endSymbol:end];
}
- (void)removeMultiLineStartSymbol:(CPString)start
{
[rootNode remove:start];
[multiLineState removeStartSymbol:start];
}
- (TDToken)nextTokenFromReader:(TDReader)r startingWith:(int)cin tokenizer:(TDTokenizer)t
{
var symbol = [rootNode nextSymbol:r startingWith:cin];
if ([multiLineState.startSymbols containsObject:symbol]) {
multiLineState.currentStartSymbol = symbol;
return [multiLineState nextTokenFromReader:r startingWith:cin tokenizer:t];
} else if ([singleLineState.startSymbols containsObject:symbol]) {
singleLineState.currentStartSymbol = symbol;
return [singleLineState nextTokenFromReader:r startingWith:cin tokenizer:t];
} else {
for (var i=0, length = symbol.length ; i < symbol.length - 1; i++) {
[r unread];
}
return [TDToken tokenWithTokenType:TDTokenTypeSymbol stringValue:[CPString stringWithFormat:@"%C", cin] floatValue:0.0];
}
}
@end