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

Unified Diff: src/json-parser.h

Issue 7020018: Remove scanner abstraction layer from JSON parsing. The change in api.cc is t... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 7 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
« no previous file with comments | « no previous file | src/json-parser.cc » ('j') | src/json-parser.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/json-parser.h
===================================================================
--- src/json-parser.h (revision 8119)
+++ src/json-parser.h (working copy)
@@ -47,41 +47,53 @@
Handle<Object> ParseJson(Handle<String> source);
inline void Advance() {
- if (position_ >= source_length_) {
- position_++;
+ position_++;
+ if (position_ > source_length_) {
c0_ = kEndOfString;
} else if (is_sequential_ascii_) {
Lasse Reichstein 2011/06/01 11:03:58 This was changed?
sandholm 2011/06/01 13:45:20 r8142 ensures this was not changed.
- position_++;
c0_ = seq_source_->SeqAsciiStringGet(position_);
} else {
- position_++;
c0_ = source_->Get(position_);
}
}
- inline Isolate* isolate() { return isolate_; }
+ // The JSON lexical grammar is specified in the ECMAScript 5 standard,
+ // section 15.12.1.1. The only allowed whitespace characters between tokens
+ // are tab, carriage-return, newline and space.
- // Get the string for the current string token.
- Handle<String> GetString(bool hint_symbol);
- Handle<String> GetString();
- Handle<String> GetSymbol();
+ inline bool AdvanceWS() {
Lasse Reichstein 2011/06/01 11:03:58 Don't abbreviate unless necessary. Call this Advan
sandholm 2011/06/01 13:45:20 Done.
+ do {
+ Advance();
+ } while (c0_ == '\t' || c0_ == '\r' || c0_ == '\n' || c0_ == ' ');
+ return true;
Lasse Reichstein 2011/06/01 11:03:58 Why the return true? If it always returns the same
sandholm 2011/06/01 13:45:20 Done.
+ }
- // Scan a single JSON token. The JSON lexical grammar is specified in the
- // ECMAScript 5 standard, section 15.12.1.1.
- // Recognizes all of the single-character tokens directly, or calls a function
- // to scan a number, string or identifier literal.
- // The only allowed whitespace characters between tokens are tab,
- // carriage-return, newline and space.
- void ScanJson();
+ inline void SkipWS() {
Lasse Reichstein 2011/06/01 11:03:58 And just SkipWhitespace.
sandholm 2011/06/01 13:45:20 Done.
+ while (c0_ == '\t' || c0_ == '\r' || c0_ == '\n' || c0_ == ' ') {
+ Advance();
+ }
+ }
+ inline uc32 AdvanceGetChar() {
+ Advance();
+ return c0_;
+ }
+
// A JSON string (production JSONString) is subset of valid JavaScript string
// literals. The string must only be double-quoted (not single-quoted), and
// the only allowed backslash-escapes are ", /, \, b, f, n, r, t and
// four-digit hex escapes (uXXXX). Any other use of backslashes is invalid.
- Token::Value ScanJsonString();
+ Handle<Object> ParseJsonString() {
+ return ScanJsonString<false>();
+ }
+ Handle<Object> ParseJsonSymbol() {
+ return ScanJsonString<true>();
+ }
+ template <bool is_symbol>
+ Handle<Object> ScanJsonString();
// Slow version for unicode support, uses the first ascii_count characters,
// as first part of a ConsString
- Token::Value SlowScanJsonString();
+ Handle<Object> SlowScanJsonString();
// A JSON number (production JSONNumber) is a subset of the valid JavaScript
// decimal number literals.
@@ -89,13 +101,8 @@
// digit before and after a decimal point, may not have prefixed zeros (unless
// the integer part is zero), and may include an exponent part (e.g., "e-10").
// Hexadecimal and octal numbers are not allowed.
- Token::Value ScanJsonNumber();
+ Handle<Object> ParseJsonNumber();
- // Used to recognizes one of the literals "true", "false", or "null". These
- // are the only valid JSON identifiers (productions JSONBooleanLiteral,
- // JSONNullLiteral).
- Token::Value ScanJsonIdentifier(const char* text, Token::Value token);
-
// Parse a single JSON value from input (grammar production JSONValue).
// A JSON value is either a (double-quoted) string literal, a number literal,
// one of "true", "false", or "null", or an object or array literal.
@@ -119,22 +126,12 @@
// Mark that a parsing error has happened at the current token, and
// return a null handle. Primarily for readability.
- Handle<Object> ReportUnexpectedToken() { return Handle<Object>::null(); }
+ inline Handle<Object> ReportUnexpectedToken() {
+ return Handle<Object>::null();
+ }
- // Peek at the next token.
- Token::Value Peek() { return next_.token; }
- // Scan the next token and return the token scanned on the last call.
- Token::Value Next();
+ inline Isolate* isolate() { return isolate_; }
- struct TokenInfo {
- TokenInfo() : token(Token::ILLEGAL),
- beg_pos(0),
- end_pos(0) { }
- Token::Value token;
- int beg_pos;
- int end_pos;
- };
-
static const int kInitialSpecialStringSize = 1024;
@@ -144,15 +141,14 @@
Handle<SeqAsciiString> seq_source_;
bool is_sequential_ascii_;
- // Current and next token
- TokenInfo current_;
- TokenInfo next_;
+ // begin and end position of scanned string or number
+ int beg_pos_;
+ int end_pos_;
+
Isolate* isolate_;
uc32 c0_;
int position_;
-
- Handle<String> string_val_;
double number_;
};
« no previous file with comments | « no previous file | src/json-parser.cc » ('j') | src/json-parser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698