| 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 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 // Helper to parse a comma separated list, optionally allowing trailing | 66 // Helper to parse a comma separated list, optionally allowing trailing |
| 67 // commas (allowed in [] lists, not in function calls). | 67 // commas (allowed in [] lists, not in function calls). |
| 68 scoped_ptr<ListNode> ParseList(Token::Type stop_before, | 68 scoped_ptr<ListNode> ParseList(Token::Type stop_before, |
| 69 bool allow_trailing_comma); | 69 bool allow_trailing_comma); |
| 70 | 70 |
| 71 scoped_ptr<ParseNode> ParseFile(); | 71 scoped_ptr<ParseNode> ParseFile(); |
| 72 scoped_ptr<ParseNode> ParseStatement(); | 72 scoped_ptr<ParseNode> ParseStatement(); |
| 73 scoped_ptr<BlockNode> ParseBlock(); | 73 scoped_ptr<BlockNode> ParseBlock(); |
| 74 scoped_ptr<ParseNode> ParseCondition(); | 74 scoped_ptr<ParseNode> ParseCondition(); |
| 75 | 75 |
| 76 // Generates a pre- and post-order traversal of the tree. |
| 77 void TraverseOrder(const ParseNode* root, |
| 78 std::vector<const ParseNode*>* pre, |
| 79 std::vector<const ParseNode*>* post); |
| 80 |
| 81 // Attach comments to nearby syntax. |
| 82 void AssignComments(ParseNode* file); |
| 83 |
| 76 bool IsAssignment(const ParseNode* node) const; | 84 bool IsAssignment(const ParseNode* node) const; |
| 77 bool IsStatementBreak(Token::Type token_type) const; | 85 bool IsStatementBreak(Token::Type token_type) const; |
| 78 | 86 |
| 79 bool LookAhead(Token::Type type); | 87 bool LookAhead(Token::Type type); |
| 80 bool Match(Token::Type type); | 88 bool Match(Token::Type type); |
| 81 Token Consume(Token::Type type, const char* error_message); | 89 Token Consume(Token::Type type, const char* error_message); |
| 82 Token Consume(Token::Type* types, | 90 Token Consume(Token::Type* types, |
| 83 size_t num_types, | 91 size_t num_types, |
| 84 const char* error_message); | 92 const char* error_message); |
| 85 Token Consume(); | 93 Token Consume(); |
| 86 | 94 |
| 87 const Token& cur_token() const { return tokens_[cur_]; } | 95 const Token& cur_token() const { return tokens_[cur_]; } |
| 88 | 96 |
| 89 bool done() const { return at_end() || has_error(); } | 97 bool done() const { return at_end() || has_error(); } |
| 90 bool at_end() const { return cur_ >= tokens_.size(); } | 98 bool at_end() const { return cur_ >= tokens_.size(); } |
| 91 bool has_error() const { return err_->has_error(); } | 99 bool has_error() const { return err_->has_error(); } |
| 92 | 100 |
| 93 const std::vector<Token>& tokens_; | 101 std::vector<Token> tokens_; |
| 102 std::vector<Token> line_comment_tokens_; |
| 103 std::vector<Token> suffix_comment_tokens_; |
| 94 | 104 |
| 95 static ParserHelper expressions_[Token::NUM_TYPES]; | 105 static ParserHelper expressions_[Token::NUM_TYPES]; |
| 96 | 106 |
| 97 Err* err_; | 107 Err* err_; |
| 98 | 108 |
| 99 // Current index into the tokens. | 109 // Current index into the tokens. |
| 100 size_t cur_; | 110 size_t cur_; |
| 101 | 111 |
| 102 FRIEND_TEST_ALL_PREFIXES(Parser, BinaryOp); | 112 FRIEND_TEST_ALL_PREFIXES(Parser, BinaryOp); |
| 103 FRIEND_TEST_ALL_PREFIXES(Parser, Block); | 113 FRIEND_TEST_ALL_PREFIXES(Parser, Block); |
| 104 FRIEND_TEST_ALL_PREFIXES(Parser, Condition); | 114 FRIEND_TEST_ALL_PREFIXES(Parser, Condition); |
| 105 FRIEND_TEST_ALL_PREFIXES(Parser, Expression); | 115 FRIEND_TEST_ALL_PREFIXES(Parser, Expression); |
| 106 FRIEND_TEST_ALL_PREFIXES(Parser, FunctionCall); | 116 FRIEND_TEST_ALL_PREFIXES(Parser, FunctionCall); |
| 107 FRIEND_TEST_ALL_PREFIXES(Parser, List); | 117 FRIEND_TEST_ALL_PREFIXES(Parser, List); |
| 108 FRIEND_TEST_ALL_PREFIXES(Parser, ParenExpression); | 118 FRIEND_TEST_ALL_PREFIXES(Parser, ParenExpression); |
| 109 FRIEND_TEST_ALL_PREFIXES(Parser, UnaryOp); | 119 FRIEND_TEST_ALL_PREFIXES(Parser, UnaryOp); |
| 110 | 120 |
| 111 DISALLOW_COPY_AND_ASSIGN(Parser); | 121 DISALLOW_COPY_AND_ASSIGN(Parser); |
| 112 }; | 122 }; |
| 113 | 123 |
| 114 #endif // TOOLS_GN_PARSER_H_ | 124 #endif // TOOLS_GN_PARSER_H_ |
| OLD | NEW |