|
1 /* |
|
2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. Oracle designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Oracle in the LICENSE file that accompanied this code. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 * or visit www.oracle.com if you need additional information or have any |
|
23 * questions. |
|
24 */ |
1 |
25 |
|
26 /* |
|
27 * This is the JavaCC grammar file for a JSON parser. The productions are |
|
28 * based on syntax diagrams as specified at json.org |
|
29 * Every type of JSON is represent by a JSONElement. JSON Objects are mapped to |
|
30 * by LinkedHashMap via JSONObject. JSON Arrays are mapped to ArrayList via JSONArray |
|
31 * String, Number, Boolean and null are wrapped into a JSONPrimitive. |
|
32 * Control characters inside a string (JSONPrimitive(String)) are not escaped and are passed through |
|
33 * to ouput JSON string generated by toJsonString method of JSONElement. |
|
34 * Inside a String, only backslash ('\') and double quote ('"') characters |
|
35 * are escaped by a backslash, if they are not already escaped. |
|
36 * Applications consuming json string generated by JSON* objects must take care |
|
37 * to escape control characters within strings by prefixing with a backslash character, |
|
38 * if not already escaped. |
|
39 */ |
2 options { |
40 options { |
3 STATIC=false; |
41 STATIC=false; |
4 ERROR_REPORTING=true; |
42 ERROR_REPORTING=true; |
5 JAVA_UNICODE_ESCAPE=true; |
43 JAVA_UNICODE_ESCAPE=true; |
6 UNICODE_INPUT=true; |
44 UNICODE_INPUT=true; |
|
45 IGNORE_CASE=true; |
|
46 CACHE_TOKENS=true; |
|
47 // DEBUG_PARSER=true; |
|
48 // DEBUG_LOOKAHEAD=true; |
|
49 // DEBUG_TOKEN_MANAGER=true; |
7 } |
50 } |
8 |
51 |
9 PARSER_BEGIN(JSONParser) |
52 PARSER_BEGIN(JSONParser) |
10 |
53 |
11 package com.oracle.jmx.remote.rest.json.parser; |
54 package com.oracle.jmx.remote.rest.json.parser; |
42 | < #DIGITS : (<DIGIT>)+> |
85 | < #DIGITS : (<DIGIT>)+> |
43 | < #DIGIT: ["0"-"9"]> |
86 | < #DIGIT: ["0"-"9"]> |
44 | <QUOTED_STRING: "\"" ((~["\"","\\"]) | ("\\" ( ["n","t","b","r","f","\\","\""])))* "\""> |
87 | <QUOTED_STRING: "\"" ((~["\"","\\"]) | ("\\" ( ["n","t","b","r","f","\\","\""])))* "\""> |
45 | <BOOL_LITERAL : "true" | "false"> |
88 | <BOOL_LITERAL : "true" | "false"> |
46 | <NULL: "null"> |
89 | <NULL: "null"> |
47 | <IDENTIFIER: ["_","a"-"z", "A"-"Z"] (["a"-"z", "A"-"Z","0"-"9","_","-"])* > |
|
48 } |
90 } |
49 |
91 |
50 JSONElement jsonValue() : { |
92 JSONElement jsonValue() : { |
51 JSONElement x; |
93 JSONElement x; |
52 }{ |
94 }{ |