OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 12 matching lines...) Expand all Loading... |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 // Features shared by parsing and pre-parsing scanners. | 28 // Features shared by parsing and pre-parsing scanners. |
29 | 29 |
30 #ifndef V8_SCANNER_BASE_H_ | 30 #ifndef V8_SCANNER_BASE_H_ |
31 #define V8_SCANNER_BASE_H_ | 31 #define V8_SCANNER_BASE_H_ |
32 | 32 |
| 33 #include "globals.h" |
| 34 #include "checks.h" |
| 35 #include "allocation.h" |
33 #include "token.h" | 36 #include "token.h" |
34 #include "unicode.h" | 37 #include "unicode-inl.h" |
| 38 #include "char-predicates.h" |
| 39 #include "utils.h" |
35 | 40 |
36 namespace v8 { | 41 namespace v8 { |
37 namespace internal { | 42 namespace internal { |
38 | 43 |
| 44 class ScannerConstants : AllStatic { |
| 45 public: |
| 46 typedef unibrow::Utf8InputBuffer<1024> Utf8Decoder; |
| 47 |
| 48 static StaticResource<Utf8Decoder>* utf8_decoder() { |
| 49 return &utf8_decoder_; |
| 50 } |
| 51 |
| 52 static unibrow::Predicate<IdentifierStart, 128> kIsIdentifierStart; |
| 53 static unibrow::Predicate<IdentifierPart, 128> kIsIdentifierPart; |
| 54 static unibrow::Predicate<unibrow::LineTerminator, 128> kIsLineTerminator; |
| 55 static unibrow::Predicate<unibrow::WhiteSpace, 128> kIsWhiteSpace; |
| 56 |
| 57 static bool IsIdentifier(unibrow::CharacterStream* buffer); |
| 58 |
| 59 private: |
| 60 static StaticResource<Utf8Decoder> utf8_decoder_; |
| 61 }; |
| 62 |
| 63 |
39 class KeywordMatcher { | 64 class KeywordMatcher { |
40 // Incrementally recognize keywords. | 65 // Incrementally recognize keywords. |
41 // | 66 // |
42 // Recognized keywords: | 67 // Recognized keywords: |
43 // break case catch const* continue debugger* default delete do else | 68 // break case catch const* continue debugger* default delete do else |
44 // finally false for function if in instanceof native* new null | 69 // finally false for function if in instanceof native* new null |
45 // return switch this throw true try typeof var void while with | 70 // return switch this throw true try typeof var void while with |
46 // | 71 // |
47 // *: Actually "future reserved keywords". These are the only ones we | 72 // *: Actually "future reserved keywords". These are the only ones we |
48 // recognized, the remaining are allowed as identifiers. | 73 // recognize, the remaining are allowed as identifiers. |
| 74 // In ES5 strict mode, we should disallow all reserved keywords. |
49 public: | 75 public: |
50 KeywordMatcher() | 76 KeywordMatcher() |
51 : state_(INITIAL), | 77 : state_(INITIAL), |
52 token_(Token::IDENTIFIER), | 78 token_(Token::IDENTIFIER), |
53 keyword_(NULL), | 79 keyword_(NULL), |
54 counter_(0), | 80 counter_(0), |
55 keyword_token_(Token::ILLEGAL) {} | 81 keyword_token_(Token::ILLEGAL) {} |
56 | 82 |
57 Token::Value token() { return token_; } | 83 Token::Value token() { return token_; } |
58 | 84 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 Token::Value token_; | 175 Token::Value token_; |
150 | 176 |
151 // Matching a specific keyword string (there is only one possible valid | 177 // Matching a specific keyword string (there is only one possible valid |
152 // keyword with the current prefix). | 178 // keyword with the current prefix). |
153 const char* keyword_; | 179 const char* keyword_; |
154 int counter_; | 180 int counter_; |
155 Token::Value keyword_token_; | 181 Token::Value keyword_token_; |
156 }; | 182 }; |
157 | 183 |
158 | 184 |
159 | |
160 | |
161 | |
162 | |
163 } } // namespace v8::internal | 185 } } // namespace v8::internal |
164 | 186 |
165 #endif // V8_SCANNER_BASE_H_ | 187 #endif // V8_SCANNER_BASE_H_ |
OLD | NEW |