OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "stdio.h" | 8 #include "stdio.h" |
9 #include "SkSLParser.h" | 9 #include "SkSLParser.h" |
10 #include "SkSLToken.h" | 10 #include "SkSLToken.h" |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 } | 150 } |
151 | 151 |
152 Token Parser::nextToken() { | 152 Token Parser::nextToken() { |
153 if (fPushback.fKind != Token::INVALID_TOKEN) { | 153 if (fPushback.fKind != Token::INVALID_TOKEN) { |
154 Token result = fPushback; | 154 Token result = fPushback; |
155 fPushback.fKind = Token::INVALID_TOKEN; | 155 fPushback.fKind = Token::INVALID_TOKEN; |
156 fPushback.fText = ""; | 156 fPushback.fText = ""; |
157 return result; | 157 return result; |
158 } | 158 } |
159 int token = sksllex(fScanner); | 159 int token = sksllex(fScanner); |
160 return Token(Position(skslget_lineno(fScanner), -1), (Token::Kind) token, | 160 std::string text; |
161 token == Token::END_OF_FILE ? "<end of file>" : | 161 switch ((Token::Kind) token) { |
162 std::string(skslget_text(fScanner
))); | 162 case Token::IDENTIFIER: // fall through |
| 163 case Token::INT_LITERAL: // fall through |
| 164 case Token::FLOAT_LITERAL: // fall through |
| 165 case Token::DIRECTIVE: |
| 166 text = std::string(skslget_text(fScanner)); |
| 167 break; |
| 168 default: |
| 169 break; |
| 170 } |
| 171 return Token(Position(skslget_lineno(fScanner), -1), (Token::Kind) token, te
xt); |
163 } | 172 } |
164 | 173 |
165 void Parser::pushback(Token t) { | 174 void Parser::pushback(Token t) { |
166 ASSERT(fPushback.fKind == Token::INVALID_TOKEN); | 175 ASSERT(fPushback.fKind == Token::INVALID_TOKEN); |
167 fPushback = t; | 176 fPushback = t; |
168 } | 177 } |
169 | 178 |
170 Token Parser::peek() { | 179 Token Parser::peek() { |
171 fPushback = this->nextToken(); | 180 fPushback = this->nextToken(); |
172 return fPushback; | 181 return fPushback; |
(...skipping 1305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1478 bool Parser::identifier(std::string* dest) { | 1487 bool Parser::identifier(std::string* dest) { |
1479 Token t; | 1488 Token t; |
1480 if (this->expect(Token::IDENTIFIER, "identifier", &t)) { | 1489 if (this->expect(Token::IDENTIFIER, "identifier", &t)) { |
1481 *dest = t.fText; | 1490 *dest = t.fText; |
1482 return true; | 1491 return true; |
1483 } | 1492 } |
1484 return false; | 1493 return false; |
1485 } | 1494 } |
1486 | 1495 |
1487 } // namespace | 1496 } // namespace |
OLD | NEW |