| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // | 4 // |
| 5 // Scanner class for the Dart language. The scanner reads source text | 5 // Scanner class for the Dart language. The scanner reads source text |
| 6 // and produces a stream of tokens which is used by the parser. | 6 // and produces a stream of tokens which is used by the parser. |
| 7 // | 7 // |
| 8 | 8 |
| 9 #ifndef VM_SCANNER_H_ | 9 #ifndef VM_SCANNER_H_ |
| 10 #define VM_SCANNER_H_ | 10 #define VM_SCANNER_H_ |
| 11 | 11 |
| 12 #include "vm/growable_array.h" | 12 #include "vm/growable_array.h" |
| 13 #include "vm/token.h" | 13 #include "vm/token.h" |
| 14 | 14 |
| 15 namespace dart { | 15 namespace dart { |
| 16 | 16 |
| 17 // Forward declarations. | 17 // Forward declarations. |
| 18 class Array; | 18 class Array; |
| 19 class Library; | 19 class Library; |
| 20 class RawString; | 20 class RawString; |
| 21 class ScanContext; |
| 21 class String; | 22 class String; |
| 22 | 23 |
| 23 // A call to Scan() scans the source one token at at time. | 24 // A call to Scan() scans the source one token at at time. |
| 24 // The scanned token is returned by cur_token(). | 25 // The scanned token is returned by cur_token(). |
| 25 // GetStream() scans the entire source text and returns a stream of tokens. | 26 // GetStream() scans the entire source text and returns a stream of tokens. |
| 26 class Scanner : ValueObject { | 27 class Scanner : ValueObject { |
| 27 public: | 28 public: |
| 28 typedef int32_t (*CharAtFunc)(const String& str, intptr_t index); | 29 typedef int32_t (*CharAtFunc)(const String& str, intptr_t index); |
| 29 | 30 |
| 30 // SourcePosition describes a text location in user friendly | 31 // SourcePosition describes a text location in user friendly |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 bool IsIdent(const String& str); | 81 bool IsIdent(const String& str); |
| 81 | 82 |
| 82 // Does the token stream contain a valid literal. This is used to implement | 83 // Does the token stream contain a valid literal. This is used to implement |
| 83 // the Dart methods int.parse and double.parse. | 84 // the Dart methods int.parse and double.parse. |
| 84 static bool IsValidLiteral(const Scanner::GrowableTokenStream& tokens, | 85 static bool IsValidLiteral(const Scanner::GrowableTokenStream& tokens, |
| 85 Token::Kind literal_kind, | 86 Token::Kind literal_kind, |
| 86 bool* is_positive, | 87 bool* is_positive, |
| 87 const String** value); | 88 const String** value); |
| 88 | 89 |
| 89 private: | 90 private: |
| 91 friend class ScanContext; |
| 92 |
| 90 static const int kNumLowercaseChars = 26; | 93 static const int kNumLowercaseChars = 26; |
| 91 | 94 |
| 92 struct ScanContext { | |
| 93 ScanContext* next; | |
| 94 char string_delimiter; | |
| 95 bool string_is_multiline; | |
| 96 int brace_level; | |
| 97 }; | |
| 98 | |
| 99 struct KeywordTable { | 95 struct KeywordTable { |
| 100 Token::Kind kind; | 96 Token::Kind kind; |
| 101 const char* keyword_chars; | 97 const char* keyword_chars; |
| 102 int keyword_len; | 98 int keyword_len; |
| 103 const String* keyword_symbol; | 99 const String* keyword_symbol; |
| 104 }; | 100 }; |
| 105 | 101 |
| 106 // Rewind scanner position to token 0. | 102 // Rewind scanner position to token 0. |
| 107 void Reset(); | 103 void Reset(); |
| 108 | 104 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 Isolate* isolate_; | 214 Isolate* isolate_; |
| 219 | 215 |
| 220 static KeywordTable keywords_[Token::kNumKeywords]; | 216 static KeywordTable keywords_[Token::kNumKeywords]; |
| 221 static int keywords_char_offset_[kNumLowercaseChars]; | 217 static int keywords_char_offset_[kNumLowercaseChars]; |
| 222 }; | 218 }; |
| 223 | 219 |
| 224 | 220 |
| 225 } // namespace dart | 221 } // namespace dart |
| 226 | 222 |
| 227 #endif // VM_SCANNER_H_ | 223 #endif // VM_SCANNER_H_ |
| OLD | NEW |