| 93 | } |
| 94 | |
| 95 | void TextProcessing::ReadToken(Token* token) |
| 96 | { |
| 97 | // Eat whitespaces |
| 98 | EatWhiteSpaces(); |
| 99 | |
| 100 | // Set token start but reset its length |
| 101 | token->Start = _cursor; |
| 102 | token->Length = 0; |
| 103 | token->Separator = { 0, 0 }; |
| 104 | |
| 105 | // Read until can |
| 106 | while (_position < _length) |
| 107 | { |
| 108 | // Read char |
| 109 | char c = moveForward(); |
| 110 | |
| 111 | // Check if it's a separator char |
| 112 | char c1 = PeekChar(); |
| 113 | for (int32 s = 0; s < Separators.Count(); s++) |
| 114 | { |
| 115 | if (Separators[s].C0 == c && Separators[s].C1 == c1) |
| 116 | { |
| 117 | /*if (*length == 0) |
| 118 | { |
| 119 | // Skip separator after separator case and start searching for new token |
| 120 | *token = _cursor; |
| 121 | *length = -1; |
| 122 | break; |
| 123 | }*/ |
| 124 | |
| 125 | token->Separator = Separators[s]; |
| 126 | ReadChar(); |
| 127 | |
| 128 | // Check for comments |
| 129 | if (token->Separator == SingleLineComment) |
| 130 | { |
| 131 | // Read whole line |
| 132 | ReadLine(); |
| 133 | |
| 134 | // Read another token |
| 135 | ReadToken(token); |
| 136 | } |
| 137 | else if (token->Separator == MultiLineCommentSeparator) |
| 138 | { |
| 139 | // Read tokens until end sequence |
| 140 | char prev = ' '; |
| 141 | while (CanRead()) |
| 142 | { |
| 143 | c = ReadChar(); |
| 144 | if (prev == '*' && c == '/') |
| 145 | break; |
| 146 | prev = c; |
| 147 | } |
| 148 | |
| 149 | // Check if comment is valid (has end before file end) |
| 150 | if (!CanRead()) |
| 151 | { |
| 152 | LOG(Warning, "Missing multiline comment ending"); |
no test coverage detected