OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 // Get the elements array of a compile time value returned by GetValue(). | 753 // Get the elements array of a compile time value returned by GetValue(). |
754 static Handle<FixedArray> GetElements(Handle<FixedArray> value); | 754 static Handle<FixedArray> GetElements(Handle<FixedArray> value); |
755 | 755 |
756 private: | 756 private: |
757 static const int kTypeSlot = 0; | 757 static const int kTypeSlot = 0; |
758 static const int kElementsSlot = 1; | 758 static const int kElementsSlot = 1; |
759 | 759 |
760 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 760 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
761 }; | 761 }; |
762 | 762 |
763 | |
764 // ---------------------------------------------------------------------------- | |
765 // JSON PARSING | |
766 | |
767 // JSON is a subset of JavaScript, as specified in, e.g., the ECMAScript 5 | |
768 // specification section 15.12.1 (and appendix A.8). | |
769 // The grammar is given section 15.12.1.2 (and appendix A.8.2). | |
770 class JsonParser BASE_EMBEDDED { | |
771 public: | |
772 // Parse JSON input as a single JSON value. | |
773 // Returns null handle and sets exception if parsing failed. | |
774 static Handle<Object> Parse(Handle<String> source) { | |
775 if (source->IsExternalTwoByteString()) { | |
776 ExternalTwoByteStringUC16CharacterStream stream( | |
777 Handle<ExternalTwoByteString>::cast(source), 0, source->length()); | |
778 return JsonParser().ParseJson(source, &stream); | |
779 } else { | |
780 GenericStringUC16CharacterStream stream(source, 0, source->length()); | |
781 return JsonParser().ParseJson(source, &stream); | |
782 } | |
783 } | |
784 | |
785 private: | |
786 JsonParser() | |
787 : isolate_(Isolate::Current()), | |
788 scanner_(isolate_->unicode_cache()) { } | |
789 ~JsonParser() { } | |
790 | |
791 Isolate* isolate() { return isolate_; } | |
792 | |
793 // Parse a string containing a single JSON value. | |
794 Handle<Object> ParseJson(Handle<String> script, UC16CharacterStream* source); | |
795 // Parse a single JSON value from input (grammar production JSONValue). | |
796 // A JSON value is either a (double-quoted) string literal, a number literal, | |
797 // one of "true", "false", or "null", or an object or array literal. | |
798 Handle<Object> ParseJsonValue(); | |
799 // Parse a JSON object literal (grammar production JSONObject). | |
800 // An object literal is a squiggly-braced and comma separated sequence | |
801 // (possibly empty) of key/value pairs, where the key is a JSON string | |
802 // literal, the value is a JSON value, and the two are separated by a colon. | |
803 // A JSON array dosn't allow numbers and identifiers as keys, like a | |
804 // JavaScript array. | |
805 Handle<Object> ParseJsonObject(); | |
806 // Parses a JSON array literal (grammar production JSONArray). An array | |
807 // literal is a square-bracketed and comma separated sequence (possibly empty) | |
808 // of JSON values. | |
809 // A JSON array doesn't allow leaving out values from the sequence, nor does | |
810 // it allow a terminal comma, like a JavaScript array does. | |
811 Handle<Object> ParseJsonArray(); | |
812 | |
813 // Mark that a parsing error has happened at the current token, and | |
814 // return a null handle. Primarily for readability. | |
815 Handle<Object> ReportUnexpectedToken() { return Handle<Object>::null(); } | |
816 // Converts the currently parsed literal to a JavaScript String. | |
817 Handle<String> GetString(); | |
818 // Converts the currently parsed literal to a JavaScript Symbol String. | |
819 Handle<String> GetSymbol(); | |
820 | |
821 Isolate* isolate_; | |
822 JsonScanner scanner_; | |
823 bool stack_overflow_; | |
824 }; | |
825 } } // namespace v8::internal | 763 } } // namespace v8::internal |
826 | 764 |
827 #endif // V8_PARSER_H_ | 765 #endif // V8_PARSER_H_ |
OLD | NEW |