|
| 1 | +/* |
| 2 | +BSD License |
| 3 | +
|
| 4 | +Copyright (c) 2013, Rainer Schuster |
| 5 | +All rights reserved. |
| 6 | +
|
| 7 | +Redistribution and use in source and binary forms, with or without |
| 8 | +modification, are permitted provided that the following conditions |
| 9 | +are met: |
| 10 | +
|
| 11 | +1. Redistributions of source code must retain the above copyright |
| 12 | + notice, this list of conditions and the following disclaimer. |
| 13 | +2. Redistributions in binary form must reproduce the above copyright |
| 14 | + notice, this list of conditions and the following disclaimer in the |
| 15 | + documentation and/or other materials provided with the distribution. |
| 16 | +3. Neither the name of Rainer Schuster nor the names of its contributors |
| 17 | + may be used to endorse or promote products derived from this software |
| 18 | + without specific prior written permission. |
| 19 | +
|
| 20 | +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | +HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | +
|
| 32 | +JSON grammar derived from: |
| 33 | +
|
| 34 | + http://tools.ietf.org/html/rfc4627 |
| 35 | +
|
| 36 | + The application/json Media Type for JavaScript Object Notation (JSON) |
| 37 | + July 2006 |
| 38 | +
|
| 39 | +Terminal rules mainly created by ANTLRWorks 1.5 sample code. |
| 40 | + */ |
| 41 | +grammar Json; |
| 42 | + |
| 43 | +jsonText |
| 44 | + : jsonObject |
| 45 | + | jsonArray |
| 46 | +; |
| 47 | + |
| 48 | +jsonValue |
| 49 | + : 'false' |
| 50 | + | 'null' |
| 51 | + | 'true' |
| 52 | + | jsonObject |
| 53 | + | jsonArray |
| 54 | + | jsonNumber |
| 55 | + | jsonString |
| 56 | +; |
| 57 | + |
| 58 | +jsonNumber |
| 59 | + : NUMBER |
| 60 | +; |
| 61 | + |
| 62 | +jsonString |
| 63 | + : STRING |
| 64 | +; |
| 65 | + |
| 66 | +jsonObject |
| 67 | + : '{' (member (',' member)*)? '}' |
| 68 | +; |
| 69 | + |
| 70 | +member |
| 71 | + : STRING ':' jsonValue |
| 72 | +; |
| 73 | + |
| 74 | +jsonArray |
| 75 | + : '[' (jsonValue (',' jsonValue)*)? ']' |
| 76 | +; |
| 77 | + |
| 78 | +fragment |
| 79 | +INT |
| 80 | + : '0'..'9'+ |
| 81 | +; |
| 82 | + |
| 83 | +NUMBER |
| 84 | + : '-'? ('0' | ( '1'..'9' INT* )) ('.' INT+)? EXPONENT? |
| 85 | +; |
| 86 | + |
| 87 | +WS |
| 88 | + : ( ' ' |
| 89 | + | '\t' |
| 90 | + | '\n' |
| 91 | + | '\r' |
| 92 | + ) -> channel(HIDDEN) |
| 93 | +; |
| 94 | + |
| 95 | +STRING |
| 96 | + : '"' ( ESC_SEQ | ~('\\'|'"') )* '"' |
| 97 | +; |
| 98 | + |
| 99 | +fragment |
| 100 | +EXPONENT |
| 101 | + : ('e'|'E') ('+'|'-')? ('0'..'9')+ |
| 102 | +; |
| 103 | + |
| 104 | +fragment |
| 105 | +HEX_DIGIT |
| 106 | + : ('0'..'9'|'a'..'f'|'A'..'F') |
| 107 | +; |
| 108 | + |
| 109 | +fragment |
| 110 | +ESC_SEQ |
| 111 | + : '\\' ('\"'|'\\'|'/'|'b'|'f'|'n'|'r'|'t') |
| 112 | + | UNICODE_ESC |
| 113 | +; |
| 114 | + |
| 115 | +fragment |
| 116 | +UNICODE_ESC |
| 117 | + : '\\' 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT |
| 118 | +; |
0 commit comments