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

Side by Side Diff: src/parser.h

Issue 4135004: Separate JSON parsing from the JavaScript parser. (Closed)
Patch Set: Rename GetSymbol. Move ZoneScope. Created 10 years, 1 month 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
« no previous file with comments | « src/objects.h ('k') | src/parser.cc » ('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 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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 void ReportMessage(const char* message, Vector<const char*> args); 211 void ReportMessage(const char* message, Vector<const char*> args);
212 virtual void ReportMessageAt(Scanner::Location loc, 212 virtual void ReportMessageAt(Scanner::Location loc,
213 const char* message, 213 const char* message,
214 Vector<const char*> args) = 0; 214 Vector<const char*> args) = 0;
215 215
216 216
217 // Returns NULL if parsing failed. 217 // Returns NULL if parsing failed.
218 FunctionLiteral* ParseProgram(Handle<String> source, 218 FunctionLiteral* ParseProgram(Handle<String> source,
219 bool in_global_context); 219 bool in_global_context);
220 FunctionLiteral* ParseLazy(Handle<SharedFunctionInfo> info); 220 FunctionLiteral* ParseLazy(Handle<SharedFunctionInfo> info);
221 FunctionLiteral* ParseJson(Handle<String> source);
222 221
223 // The minimum number of contiguous assignment that will 222 // The minimum number of contiguous assignment that will
224 // be treated as an initialization block. Benchmarks show that 223 // be treated as an initialization block. Benchmarks show that
225 // the overhead exceeds the savings below this limit. 224 // the overhead exceeds the savings below this limit.
226 static const int kMinInitializationBlock = 3; 225 static const int kMinInitializationBlock = 3;
227 226
228 protected: 227 protected:
229 228
230 enum Mode { 229 enum Mode {
231 PARSE_LAZILY, 230 PARSE_LAZILY,
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 // type. Both arguments must be non-null (in the handle sense). 403 // type. Both arguments must be non-null (in the handle sense).
405 Expression* NewThrowTypeError(Handle<String> type, 404 Expression* NewThrowTypeError(Handle<String> type,
406 Handle<Object> first, 405 Handle<Object> first,
407 Handle<Object> second); 406 Handle<Object> second);
408 407
409 // Generic AST generator for throwing errors from compiled code. 408 // Generic AST generator for throwing errors from compiled code.
410 Expression* NewThrowError(Handle<String> constructor, 409 Expression* NewThrowError(Handle<String> constructor,
411 Handle<String> type, 410 Handle<String> type,
412 Vector< Handle<Object> > arguments); 411 Vector< Handle<Object> > arguments);
413 412
414 // JSON is a subset of JavaScript, as specified in, e.g., the ECMAScript 5
415 // specification section 15.12.1 (and appendix A.8).
416 // The grammar is given section 15.12.1.2 (and appendix A.8.2).
417
418 // Parse JSON input as a single JSON value.
419 Expression* ParseJson(bool* ok);
420
421 // Parse a single JSON value from input (grammar production JSONValue).
422 // A JSON value is either a (double-quoted) string literal, a number literal,
423 // one of "true", "false", or "null", or an object or array literal.
424 Expression* ParseJsonValue(bool* ok);
425 // Parse a JSON object literal (grammar production JSONObject).
426 // An object literal is a squiggly-braced and comma separated sequence
427 // (possibly empty) of key/value pairs, where the key is a JSON string
428 // literal, the value is a JSON value, and the two are spearated by a colon.
429 // A JavaScript object also allows numbers and identifiers as keys.
430 Expression* ParseJsonObject(bool* ok);
431 // Parses a JSON array literal (grammar production JSONArray). An array
432 // literal is a square-bracketed and comma separated sequence (possibly empty)
433 // of JSON values.
434 // A JavaScript array allows leaving out values from the sequence.
435 Expression* ParseJsonArray(bool* ok);
436
437 friend class Target; 413 friend class Target;
438 friend class TargetScope; 414 friend class TargetScope;
439 friend class LexicalScope; 415 friend class LexicalScope;
440 friend class TemporaryScope; 416 friend class TemporaryScope;
441 }; 417 };
442 418
443 419
444 // Support for handling complex values (array and object literals) that 420 // Support for handling complex values (array and object literals) that
445 // can be fully handled at compile time. 421 // can be fully handled at compile time.
446 class CompileTimeValue: public AllStatic { 422 class CompileTimeValue: public AllStatic {
(...skipping 18 matching lines...) Expand all
465 static Handle<FixedArray> GetElements(Handle<FixedArray> value); 441 static Handle<FixedArray> GetElements(Handle<FixedArray> value);
466 442
467 private: 443 private:
468 static const int kTypeSlot = 0; 444 static const int kTypeSlot = 0;
469 static const int kElementsSlot = 1; 445 static const int kElementsSlot = 1;
470 446
471 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); 447 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue);
472 }; 448 };
473 449
474 450
451 // JSON is a subset of JavaScript, as specified in, e.g., the ECMAScript 5
452 // specification section 15.12.1 (and appendix A.8).
453 // The grammar is given section 15.12.1.2 (and appendix A.8.2).
454 class JsonParser BASE_EMBEDDED {
455 public:
456 // Parse JSON input as a single JSON value.
457 // Returns null handle and sets exception if parsing failed.
458 static Handle<Object> Parse(Handle<String> source) {
459 return JsonParser().ParseJson(source);
460 }
461
462 private:
463 JsonParser() { }
464 ~JsonParser() { }
465
466 // Parse a string containing a single JSON value.
467 Handle<Object> ParseJson(Handle<String>);
468 // Parse a single JSON value from input (grammar production JSONValue).
469 // A JSON value is either a (double-quoted) string literal, a number literal,
470 // one of "true", "false", or "null", or an object or array literal.
471 Handle<Object> ParseJsonValue();
472 // Parse a JSON object literal (grammar production JSONObject).
473 // An object literal is a squiggly-braced and comma separated sequence
474 // (possibly empty) of key/value pairs, where the key is a JSON string
475 // literal, the value is a JSON value, and the two are separated by a colon.
476 // A JSON array dosn't allow numbers and identifiers as keys, like a
477 // JavaScript array.
478 Handle<Object> ParseJsonObject();
479 // Parses a JSON array literal (grammar production JSONArray). An array
480 // literal is a square-bracketed and comma separated sequence (possibly empty)
481 // of JSON values.
482 // A JSON array doesn't allow leaving out values from the sequence, nor does
483 // it allow a terminal comma, like a JavaScript array does.
484 Handle<Object> ParseJsonArray();
485
486 // Mark that a parsing error has happened at the current token, and
487 // return a null handle. Primarily for readability.
488 Handle<Object> ReportUnexpectedToken() { return Handle<Object>::null(); }
489 // Converts the currently parsed literal to a JavaScript String.
490 Handle<String> GetString();
491
492 Scanner scanner_;
493 };
475 } } // namespace v8::internal 494 } } // namespace v8::internal
476 495
477 #endif // V8_PARSER_H_ 496 #endif // V8_PARSER_H_
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698