fr.cenotelie.commons.utils.json.Json.gram Maven / Gradle / Ivy
/*******************************************************************************
* Copyright (c) 2016 Association Cénotélie (cenotelie.fr)
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this program.
* If not, see .
******************************************************************************/
grammar Json
{
options
{
Axiom = "document";
Separator = "BLANK";
}
terminals
{
NEW_LINE -> U+000D /* CR */
| U+000A /* LF */
| U+000D U+000A /* CR LF */
| U+2028 /* LS */
| U+2029 /* PS */ ;
WHITE_SPACE -> U+0020 | U+0009 | U+000B | U+000C ;
COMMENT -> '#' (.* - (.* NEW_LINE .*)) NEW_LINE ;
BLANK -> NEW_LINE | WHITE_SPACE | COMMENT ;
LITERAL_INTEGER -> ('+' | '-')? [0-9]+ ;
LITERAL_DECIMAL -> ('+' | '-')? [0-9]* '.' [0-9]+ ;
LITERAL_DOUBLE -> ('+' | '-')? ( [0-9]+ '.' [0-9]* [eE] ('+' | '-')? [0-9]+
| '.' [0-9]+ [eE] ('+' | '-')? [0-9]+
| [0-9]+ [eE] ('+' | '-')? [0-9]+
) ;
LITERAL_STRING -> '"' (
. - (U+0022 | U+005C | U+000A | U+000D)
| '\\' ([tbnrf"'] | '\\')
| '\\u' [a-fA-F0-9]{4}
| '\\U' [a-fA-F0-9]{8}
)* '"' ;
LITERAL_NULL -> 'null' ;
LITERAL_TRUE -> 'true' ;
LITERAL_FALSE -> 'false';
}
rules
{
document -> object^ | array^ ;
object -> '{'! (member (','! member)*)? '}'! ;
member -> LITERAL_STRING ':'! value ;
array -> '['! (value (','! value)*)? ']'! ;
value -> object^ | array^
| LITERAL_INTEGER^
| LITERAL_DECIMAL^
| LITERAL_DOUBLE^
| LITERAL_STRING^
| LITERAL_NULL^
| LITERAL_TRUE^
| LITERAL_FALSE^ ;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy