Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1239)

Side by Side Diff: src/lexer/experimental-scanner.h

Issue 83693002: Experimentar scanner: Unify the API to Scanner API some more. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/lexer/lexer_py.re » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 int end_pos; 77 int end_pos;
78 }; 78 };
79 79
80 explicit ExperimentalScanner( 80 explicit ExperimentalScanner(
81 YYCTYPE* source, 81 YYCTYPE* source,
82 YYCTYPE* source_end, 82 YYCTYPE* source_end,
83 Isolate* isolate); 83 Isolate* isolate);
84 84
85 ~ExperimentalScanner(); 85 ~ExperimentalScanner();
86 86
87 // Returns the next token and advances input.
87 Token::Value Next() { 88 Token::Value Next() {
89 has_line_terminator_before_next_ = false;
88 current_ = next_; 90 current_ = next_;
89 Scan(); // will fill in next_. 91 Scan(); // will fill in next_.
90 return current_.token; 92 return current_.token;
91 } 93 }
92 94
95 // Returns the current token again.
96 Token::Value current_token() { return current_.token; }
97
98 // Returns the location information for the current token
99 // (the token last returned by Next()).
93 Location location() { 100 Location location() {
94 return Location(current_.beg_pos, current_.end_pos); 101 return Location(current_.beg_pos, current_.end_pos);
95 } 102 }
96 103
104 // One token look-ahead (past the token returned by Next()).
105 Token::Value peek() const { return next_.token; }
106
107 Location peek_location() const { return next_.location; }
108
109 UnicodeCache* unicode_cache() { return unicode_cache_; }
110
111 bool HarmonyScoping() const {
112 return harmony_scoping_;
113 }
114 void SetHarmonyScoping(bool scoping) {
115 harmony_scoping_ = scoping;
116 }
117 bool HarmonyModules() const {
118 return harmony_modules_;
119 }
120 void SetHarmonyModules(bool modules) {
121 harmony_modules_ = modules;
122 }
123 bool HarmonyNumericLiterals() const {
124 return harmony_numeric_literals_;
125 }
97 void SetHarmonyNumericLiterals(bool numeric_literals) { 126 void SetHarmonyNumericLiterals(bool numeric_literals) {
98 harmony_numeric_literals_ = numeric_literals; 127 harmony_numeric_literals_ = numeric_literals;
99 } 128 }
100 129
101 void SetHarmonyModules(bool modules) { 130 // Returns true if there was a line terminator before the peek'ed token,
102 harmony_modules_ = modules; 131 // possibly inside a multi-line comment.
103 } 132 bool HasAnyLineTerminatorBeforeNext() const {
104 133 return has_line_terminator_before_next_;
105 void SetHarmonyScoping(bool scoping) { 134 // FIXME: do we need to distinguish between newlines inside and outside
106 harmony_scoping_ = scoping; 135 // multiline comments? Atm doesn't look like we need to.
107 } 136 }
108 137
109 private: 138 private:
110 struct TokenDesc { 139 struct TokenDesc {
111 Token::Value token; 140 Token::Value token;
112 int beg_pos; 141 int beg_pos;
113 int end_pos; 142 int end_pos;
114 LiteralBuffer* literal_chars; 143 LiteralBuffer* literal_chars;
115 }; 144 };
116 145
117 void Scan(); 146 void Scan();
118 147
119 bool ValidIdentifierStart(); 148 bool ValidIdentifierStart();
120 bool ValidIdentifierPart(); 149 bool ValidIdentifierPart();
121 uc32 ScanHexNumber(int length); 150 uc32 ScanHexNumber(int length);
122 151
123 UnicodeCache* unicode_cache_; 152 UnicodeCache* unicode_cache_;
124 153
125 YYCTYPE* buffer_; 154 YYCTYPE* buffer_;
126 YYCTYPE* buffer_end_; 155 YYCTYPE* buffer_end_;
127 YYCTYPE* start_; 156 YYCTYPE* start_;
128 YYCTYPE* cursor_; 157 YYCTYPE* cursor_;
129 YYCTYPE* marker_; 158 YYCTYPE* marker_;
130 bool just_seen_line_terminator_; 159 bool has_line_terminator_before_next_;
131 160
132 YYCTYPE yych; 161 YYCTYPE yych;
133 162
134 TokenDesc current_; // desc for current token (as returned by Next()) 163 TokenDesc current_; // desc for current token (as returned by Next())
135 TokenDesc next_; // desc for next token (one token look-ahead) 164 TokenDesc next_; // desc for next token (one token look-ahead)
136 165
137 bool harmony_numeric_literals_; 166 bool harmony_numeric_literals_;
138 bool harmony_modules_; 167 bool harmony_modules_;
139 bool harmony_scoping_; 168 bool harmony_scoping_;
140 }; 169 };
141 170
142 const byte* ReadFile(const char* name, Isolate* isolate, int* size, int repeat); 171 const byte* ReadFile(const char* name, Isolate* isolate, int* size, int repeat);
143 172
144 template<typename YYCTYPE> 173 template<typename YYCTYPE>
145 ExperimentalScanner<YYCTYPE>::ExperimentalScanner( 174 ExperimentalScanner<YYCTYPE>::ExperimentalScanner(
146 YYCTYPE* source, 175 YYCTYPE* source,
147 YYCTYPE* source_end, 176 YYCTYPE* source_end,
148 Isolate* isolate) 177 Isolate* isolate)
149 : unicode_cache_(isolate->unicode_cache()), 178 : unicode_cache_(isolate->unicode_cache()),
150 just_seen_line_terminator_(true), 179 has_line_terminator_before_next_(true),
151 harmony_numeric_literals_(false), 180 harmony_numeric_literals_(false),
152 harmony_modules_(false), 181 harmony_modules_(false),
153 harmony_scoping_(false) { 182 harmony_scoping_(false) {
154 buffer_ = source; 183 buffer_ = source;
155 buffer_end_ = source_end; 184 buffer_end_ = source_end;
156 start_ = buffer_; 185 start_ = buffer_;
157 cursor_ = buffer_; 186 cursor_ = buffer_;
158 marker_ = buffer_; 187 marker_ = buffer_;
159 Scan(); 188 Scan();
160 } 189 }
(...skipping 29 matching lines...) Expand all
190 219
191 220
192 template<typename YYCTYPE> 221 template<typename YYCTYPE>
193 bool ExperimentalScanner<YYCTYPE>::ValidIdentifierStart() { 222 bool ExperimentalScanner<YYCTYPE>::ValidIdentifierStart() {
194 return unicode_cache_->IsIdentifierStart(ScanHexNumber(4)); 223 return unicode_cache_->IsIdentifierStart(ScanHexNumber(4));
195 } 224 }
196 225
197 } } 226 } }
198 227
199 #endif // V8_LEXER_EXPERIMENTAL_SCANNER_H 228 #endif // V8_LEXER_EXPERIMENTAL_SCANNER_H
OLDNEW
« no previous file with comments | « no previous file | src/lexer/lexer_py.re » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698