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

Unified Diff: src/scanner.h

Issue 549207: Added validating JSON parser mode to parser. (Closed)
Patch Set: Created 10 years, 11 months 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 side-by-side diff with in-line comments
Download patch
Index: src/scanner.h
diff --git a/src/scanner.h b/src/scanner.h
index 9d7b34e7cadf2e335f0d27992c7855d0f9019e7a..8c35df690d233e7df0b91b626de44f64070c02a7 100644
--- a/src/scanner.h
+++ b/src/scanner.h
@@ -252,18 +252,22 @@ class KeywordMatcher {
};
+enum ParserMode { PARSE, PREPARSE };
+enum ParserLanguage { JAVASCRIPT, JSON };
+
+
class Scanner {
public:
-
typedef unibrow::Utf8InputBuffer<1024> Utf8Decoder;
// Construction
- explicit Scanner(bool is_pre_parsing);
+ explicit Scanner(ParserMode parse_mode);
// Initialize the Scanner to scan source:
void Init(Handle<String> source,
unibrow::CharacterStream* stream,
- int position);
+ int position,
+ ParserLanguage language);
// Returns the next token.
Token::Value Next();
@@ -377,6 +381,7 @@ class Scanner {
TokenDesc next_; // desc for next token (one token look-ahead)
bool has_line_terminator_before_next_;
bool is_pre_parsing_;
+ bool is_parsing_json_;
// Literal buffer support
void StartLiteral();
@@ -391,14 +396,35 @@ class Scanner {
c0_ = ch;
}
- bool SkipWhiteSpace();
+ bool SkipWhiteSpace() {
+ if (is_parsing_json_) {
+ return SkipJsonWhiteSpace();
+ } else {
+ return SkipJavaScriptWhiteSpace();
+ }
+ }
+ bool SkipJavaScriptWhiteSpace();
+ bool SkipJsonWhiteSpace();
Token::Value SkipSingleLineComment();
Token::Value SkipMultiLineComment();
inline Token::Value Select(Token::Value tok);
inline Token::Value Select(uc32 next, Token::Value then, Token::Value else_);
- void Scan();
+ inline void Scan() {
+ if (is_parsing_json_) {
+ ScanJson();
+ } else {
+ ScanJavaScript();
+ }
+ }
+ void ScanJson();
+ void ScanJavaScript();
+
+ Token::Value ScanJsonNumber();
Mads Ager (chromium) 2010/02/01 08:42:19 For each of these Scan functions, please add a com
+ Token::Value ScanJsonString();
+ Token::Value ScanJsonIdentifier(const char* text, Token::Value token);
+
void ScanDecimalDigits();
Token::Value ScanNumber(bool seen_period);
Token::Value ScanIdentifier();

Powered by Google App Engine
This is Rietveld 408576698