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 788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
799 if (!this->expect(Token::FOR, "'for'", &start)) { | 799 if (!this->expect(Token::FOR, "'for'", &start)) { |
800 return nullptr; | 800 return nullptr; |
801 } | 801 } |
802 if (!this->expect(Token::LPAREN, "'('")) { | 802 if (!this->expect(Token::LPAREN, "'('")) { |
803 return nullptr; | 803 return nullptr; |
804 } | 804 } |
805 std::unique_ptr<ASTStatement> initializer; | 805 std::unique_ptr<ASTStatement> initializer; |
806 Token nextToken = this->peek(); | 806 Token nextToken = this->peek(); |
807 switch (nextToken.fKind) { | 807 switch (nextToken.fKind) { |
808 case Token::SEMICOLON: | 808 case Token::SEMICOLON: |
| 809 this->nextToken(); |
809 break; | 810 break; |
810 case Token::CONST: | 811 case Token::CONST: |
811 initializer = std::unique_ptr<ASTStatement>(new ASTVarDeclarationSta
tement( | 812 initializer = std::unique_ptr<ASTStatement>(new ASTVarDeclarationSta
tement( |
812 this->
varDeclarations())); | 813 this->
varDeclarations())); |
813 break; | 814 break; |
814 case Token::IDENTIFIER: | 815 case Token::IDENTIFIER: |
815 if (this->isType(nextToken.fText)) { | 816 if (this->isType(nextToken.fText)) { |
816 initializer = std::unique_ptr<ASTStatement>(new ASTVarDeclaratio
nStatement( | 817 initializer = std::unique_ptr<ASTStatement>(new ASTVarDeclaratio
nStatement( |
817 this->
varDeclarations())); | 818 this->
varDeclarations())); |
818 break; | 819 break; |
819 } | 820 } |
820 // fall through | 821 // fall through |
821 default: | 822 default: |
822 initializer = this->expressionStatement(); | 823 initializer = this->expressionStatement(); |
823 } | 824 } |
824 std::unique_ptr<ASTExpression> test; | 825 std::unique_ptr<ASTExpression> test; |
825 if (this->peek().fKind != Token::SEMICOLON) { | 826 if (this->peek().fKind != Token::SEMICOLON) { |
826 test = this->expression(); | 827 test = this->expression(); |
827 if (!test) { | 828 if (!test) { |
828 return nullptr; | 829 return nullptr; |
829 } | 830 } |
830 } | 831 } |
831 if (!this->expect(Token::SEMICOLON, "';'")) { | 832 if (!this->expect(Token::SEMICOLON, "';'")) { |
832 return nullptr; | 833 return nullptr; |
833 } | 834 } |
834 std::unique_ptr<ASTExpression> next; | 835 std::unique_ptr<ASTExpression> next; |
835 if (this->peek().fKind != Token::SEMICOLON) { | 836 if (this->peek().fKind != Token::RPAREN) { |
836 next = this->expression(); | 837 next = this->expression(); |
837 if (!next) { | 838 if (!next) { |
838 return nullptr; | 839 return nullptr; |
839 } | 840 } |
840 } | 841 } |
841 if (!this->expect(Token::RPAREN, "')'")) { | 842 if (!this->expect(Token::RPAREN, "')'")) { |
842 return nullptr; | 843 return nullptr; |
843 } | 844 } |
844 std::unique_ptr<ASTStatement> statement(this->statement()); | 845 std::unique_ptr<ASTStatement> statement(this->statement()); |
845 if (!statement) { | 846 if (!statement) { |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1434 bool Parser::identifier(std::string* dest) { | 1435 bool Parser::identifier(std::string* dest) { |
1435 Token t; | 1436 Token t; |
1436 if (this->expect(Token::IDENTIFIER, "identifier", &t)) { | 1437 if (this->expect(Token::IDENTIFIER, "identifier", &t)) { |
1437 *dest = t.fText; | 1438 *dest = t.fText; |
1438 return true; | 1439 return true; |
1439 } | 1440 } |
1440 return false; | 1441 return false; |
1441 } | 1442 } |
1442 | 1443 |
1443 } // namespace | 1444 } // namespace |
OLD | NEW |