Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 79 lines (68 sloc) 2.179 kb
05eedb5 @itod initial add
authored
1 // Copyright 2010 Todd Ditchendorf
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #import <ParseKit/TDSlashStarState.h>
16 #import <ParseKit/TDSlashState.h>
17 #import <ParseKit/PKReader.h>
18 #import <ParseKit/PKTokenizer.h>
19 #import <ParseKit/PKToken.h>
20 #import <ParseKit/PKTypes.h>
21
22 @interface PKTokenizerState ()
23 - (void)resetWithReader:(PKReader *)r;
24 - (void)append:(PKUniChar)c;
25 - (NSString *)bufferedString;
26 @end
27
28 @implementation TDSlashStarState
29
30 - (PKToken *)nextTokenFromReader:(PKReader *)r startingWith:(PKUniChar)cin tokenizer:(PKTokenizer *)t {
31 NSParameterAssert(r);
32 NSParameterAssert(t);
33
34 BOOL reportTokens = t.slashState.reportsCommentTokens;
35 if (reportTokens) {
36 [self resetWithReader:r];
37 [self append:'/'];
38 }
39
40 NSInteger c = cin;
41 while (-1 != c) {
42 if (reportTokens) {
43 [self append:c];
44 }
45 c = [r read];
46
47 if ('*' == c) {
48 NSInteger peek = [r read];
49 if ('/' == peek) {
50 if (reportTokens) {
51 [self append:c];
52 [self append:peek];
53 }
54 c = [r read];
55 break;
56 } else if ('*' == peek) {
57 [r unread];
58 } else {
59 if (reportTokens) {
60 [self append:c];
61 }
62 c = peek;
63 }
64 }
65 }
66
67 if (-1 != c) {
68 [r unread];
69 }
70
71 if (reportTokens) {
72 return [PKToken tokenWithTokenType:PKTokenTypeComment stringValue:[self bufferedString] floatValue:0.0];
73 } else {
74 return [t nextToken];
75 }
76 }
77
78 @end
Something went wrong with that request. Please try again.