| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef TOOLS_GN_PARSER_H_ | 5 #ifndef TOOLS_GN_PARSER_H_ |
| 6 #define TOOLS_GN_PARSER_H_ | 6 #define TOOLS_GN_PARSER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "tools/gn/err.h" | 14 #include "tools/gn/err.h" |
| 15 #include "tools/gn/parse_tree.h" | 15 #include "tools/gn/parse_tree.h" |
| 16 | 16 |
| 17 class Parser; | 17 class Parser; |
| 18 typedef scoped_ptr<ParseNode> (Parser::*PrefixFunc)(Token token); | 18 typedef scoped_ptr<ParseNode> (Parser::*PrefixFunc)(Token token); |
| 19 typedef scoped_ptr<ParseNode> (Parser::*InfixFunc)(scoped_ptr<ParseNode> left, | 19 typedef scoped_ptr<ParseNode> (Parser::*InfixFunc)(scoped_ptr<ParseNode> left, |
| 20 Token token); | 20 Token token); |
| 21 | 21 |
| 22 extern const char kSyntax_Help[]; |
| 23 |
| 22 struct ParserHelper { | 24 struct ParserHelper { |
| 23 PrefixFunc prefix; | 25 PrefixFunc prefix; |
| 24 InfixFunc infix; | 26 InfixFunc infix; |
| 25 int precedence; | 27 int precedence; |
| 26 }; | 28 }; |
| 27 | 29 |
| 28 // Parses a series of tokens. The resulting AST will refer to the tokens passed | 30 // Parses a series of tokens. The resulting AST will refer to the tokens passed |
| 29 // to the input, so the tokens an the file data they refer to must outlive your | 31 // to the input, so the tokens an the file data they refer to must outlive your |
| 30 // use of the ParseNode. | 32 // use of the ParseNode. |
| 31 class Parser { | 33 class Parser { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 57 scoped_ptr<ParseNode> BlockComment(Token token); | 59 scoped_ptr<ParseNode> BlockComment(Token token); |
| 58 | 60 |
| 59 // |InfixFunc|s used in parsing expressions. | 61 // |InfixFunc|s used in parsing expressions. |
| 60 scoped_ptr<ParseNode> BinaryOperator(scoped_ptr<ParseNode> left, Token token); | 62 scoped_ptr<ParseNode> BinaryOperator(scoped_ptr<ParseNode> left, Token token); |
| 61 scoped_ptr<ParseNode> IdentifierOrCall(scoped_ptr<ParseNode> left, | 63 scoped_ptr<ParseNode> IdentifierOrCall(scoped_ptr<ParseNode> left, |
| 62 Token token); | 64 Token token); |
| 63 scoped_ptr<ParseNode> Assignment(scoped_ptr<ParseNode> left, Token token); | 65 scoped_ptr<ParseNode> Assignment(scoped_ptr<ParseNode> left, Token token); |
| 64 scoped_ptr<ParseNode> Subscript(scoped_ptr<ParseNode> left, Token token); | 66 scoped_ptr<ParseNode> Subscript(scoped_ptr<ParseNode> left, Token token); |
| 65 scoped_ptr<ParseNode> DotOperator(scoped_ptr<ParseNode> left, Token token); | 67 scoped_ptr<ParseNode> DotOperator(scoped_ptr<ParseNode> left, Token token); |
| 66 | 68 |
| 67 // Helper to parse a comma separated list, optionally allowing trailing | 69 // Helper to parse a comma separated list. |
| 68 // commas (allowed in [] lists, not in function calls). | |
| 69 scoped_ptr<ListNode> ParseList(Token start_token, | 70 scoped_ptr<ListNode> ParseList(Token start_token, |
| 70 Token::Type stop_before, | 71 Token::Type stop_before); |
| 71 bool allow_trailing_comma); | |
| 72 | 72 |
| 73 scoped_ptr<ParseNode> ParseFile(); | 73 scoped_ptr<ParseNode> ParseFile(); |
| 74 scoped_ptr<ParseNode> ParseStatement(); | 74 scoped_ptr<ParseNode> ParseStatement(); |
| 75 scoped_ptr<BlockNode> ParseBlock(); | 75 scoped_ptr<BlockNode> ParseBlock(); |
| 76 scoped_ptr<ParseNode> ParseCondition(); | 76 scoped_ptr<ParseNode> ParseCondition(); |
| 77 | 77 |
| 78 // Generates a pre- and post-order traversal of the tree. | 78 // Generates a pre- and post-order traversal of the tree. |
| 79 void TraverseOrder(const ParseNode* root, | 79 void TraverseOrder(const ParseNode* root, |
| 80 std::vector<const ParseNode*>* pre, | 80 std::vector<const ParseNode*>* pre, |
| 81 std::vector<const ParseNode*>* post); | 81 std::vector<const ParseNode*>* post); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 FRIEND_TEST_ALL_PREFIXES(Parser, Expression); | 117 FRIEND_TEST_ALL_PREFIXES(Parser, Expression); |
| 118 FRIEND_TEST_ALL_PREFIXES(Parser, FunctionCall); | 118 FRIEND_TEST_ALL_PREFIXES(Parser, FunctionCall); |
| 119 FRIEND_TEST_ALL_PREFIXES(Parser, List); | 119 FRIEND_TEST_ALL_PREFIXES(Parser, List); |
| 120 FRIEND_TEST_ALL_PREFIXES(Parser, ParenExpression); | 120 FRIEND_TEST_ALL_PREFIXES(Parser, ParenExpression); |
| 121 FRIEND_TEST_ALL_PREFIXES(Parser, UnaryOp); | 121 FRIEND_TEST_ALL_PREFIXES(Parser, UnaryOp); |
| 122 | 122 |
| 123 DISALLOW_COPY_AND_ASSIGN(Parser); | 123 DISALLOW_COPY_AND_ASSIGN(Parser); |
| 124 }; | 124 }; |
| 125 | 125 |
| 126 #endif // TOOLS_GN_PARSER_H_ | 126 #endif // TOOLS_GN_PARSER_H_ |
| OLD | NEW |