org.openrewrite.json.internal.grammar.JSON5Parser Maven / Gradle / Ivy
Show all versions of rewrite-json Show documentation
/*
* Copyright 2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Generated from java-escape by ANTLR 4.11.1
package org.openrewrite.json.internal.grammar;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.atn.ATN;
import org.antlr.v4.runtime.atn.ATNDeserializer;
import org.antlr.v4.runtime.atn.ParserATNSimulator;
import org.antlr.v4.runtime.atn.PredictionContextCache;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.tree.ParseTreeListener;
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
import org.antlr.v4.runtime.tree.TerminalNode;
import java.util.List;
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast", "CheckReturnValue"})
public class JSON5Parser extends Parser {
static { RuntimeMetaData.checkVersion("4.11.1", RuntimeMetaData.VERSION); }
protected static final DFA[] _decisionToDFA;
protected static final PredictionContextCache _sharedContextCache =
new PredictionContextCache();
public static final int
T__0=1, T__1=2, T__2=3, T__3=4, T__4=5, T__5=6, SINGLE_LINE_COMMENT=7,
MULTI_LINE_COMMENT=8, LITERAL=9, STRING=10, NUMBER=11, NUMERIC_LITERAL=12,
SYMBOL=13, IDENTIFIER=14, WS=15, UTF_8_BOM=16;
public static final int
RULE_json5 = 0, RULE_obj = 1, RULE_member = 2, RULE_key = 3, RULE_value = 4,
RULE_arr = 5, RULE_number = 6;
private static String[] makeRuleNames() {
return new String[] {
"json5", "obj", "member", "key", "value", "arr", "number"
};
}
public static final String[] ruleNames = makeRuleNames();
private static String[] makeLiteralNames() {
return new String[] {
null, "'{'", "','", "'}'", "':'", "'['", "']'", null, null, null, null,
null, null, null, null, null, "'\\uFEFF'"
};
}
private static final String[] _LITERAL_NAMES = makeLiteralNames();
private static String[] makeSymbolicNames() {
return new String[] {
null, null, null, null, null, null, null, "SINGLE_LINE_COMMENT", "MULTI_LINE_COMMENT",
"LITERAL", "STRING", "NUMBER", "NUMERIC_LITERAL", "SYMBOL", "IDENTIFIER",
"WS", "UTF_8_BOM"
};
}
private static final String[] _SYMBOLIC_NAMES = makeSymbolicNames();
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
/**
* @deprecated Use {@link #VOCABULARY} instead.
*/
@Deprecated
public static final String[] tokenNames;
static {
tokenNames = new String[_SYMBOLIC_NAMES.length];
for (int i = 0; i < tokenNames.length; i++) {
tokenNames[i] = VOCABULARY.getLiteralName(i);
if (tokenNames[i] == null) {
tokenNames[i] = VOCABULARY.getSymbolicName(i);
}
if (tokenNames[i] == null) {
tokenNames[i] = "";
}
}
}
@Override
@Deprecated
public String[] getTokenNames() {
return tokenNames;
}
@Override
public Vocabulary getVocabulary() {
return VOCABULARY;
}
@Override
public String getGrammarFileName() { return "java-escape"; }
@Override
public String[] getRuleNames() { return ruleNames; }
@Override
public String getSerializedATN() { return _serializedATN; }
@Override
public ATN getATN() { return _ATN; }
public JSON5Parser(TokenStream input) {
super(input);
_interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
}
@SuppressWarnings("CheckReturnValue")
public static class Json5Context extends ParserRuleContext {
public TerminalNode EOF() { return getToken(JSON5Parser.EOF, 0); }
public ValueContext value() {
return getRuleContext(ValueContext.class,0);
}
public Json5Context(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_json5; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof JSON5Listener ) ((JSON5Listener)listener).enterJson5(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof JSON5Listener ) ((JSON5Listener)listener).exitJson5(this);
}
@Override
public T accept(ParseTreeVisitor extends T> visitor) {
if ( visitor instanceof JSON5Visitor ) return ((JSON5Visitor extends T>)visitor).visitJson5(this);
else return visitor.visitChildren(this);
}
}
public final Json5Context json5() throws RecognitionException {
Json5Context _localctx = new Json5Context(_ctx, getState());
enterRule(_localctx, 0, RULE_json5);
int _la;
try {
enterOuterAlt(_localctx, 1);
{
setState(15);
_errHandler.sync(this);
_la = _input.LA(1);
if (((_la) & ~0x3f) == 0 && ((1L << _la) & 15906L) != 0) {
{
setState(14);
value();
}
}
setState(17);
match(EOF);
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
@SuppressWarnings("CheckReturnValue")
public static class ObjContext extends ParserRuleContext {
public List member() {
return getRuleContexts(MemberContext.class);
}
public MemberContext member(int i) {
return getRuleContext(MemberContext.class,i);
}
public ObjContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_obj; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof JSON5Listener ) ((JSON5Listener)listener).enterObj(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof JSON5Listener ) ((JSON5Listener)listener).exitObj(this);
}
@Override
public T accept(ParseTreeVisitor extends T> visitor) {
if ( visitor instanceof JSON5Visitor ) return ((JSON5Visitor extends T>)visitor).visitObj(this);
else return visitor.visitChildren(this);
}
}
public final ObjContext obj() throws RecognitionException {
ObjContext _localctx = new ObjContext(_ctx, getState());
enterRule(_localctx, 2, RULE_obj);
int _la;
try {
int _alt;
setState(35);
_errHandler.sync(this);
switch ( getInterpreter().adaptivePredict(_input,3,_ctx) ) {
case 1:
enterOuterAlt(_localctx, 1);
{
setState(19);
match(T__0);
setState(20);
member();
setState(25);
_errHandler.sync(this);
_alt = getInterpreter().adaptivePredict(_input,1,_ctx);
while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) {
if ( _alt==1 ) {
{
{
setState(21);
match(T__1);
setState(22);
member();
}
}
}
setState(27);
_errHandler.sync(this);
_alt = getInterpreter().adaptivePredict(_input,1,_ctx);
}
setState(29);
_errHandler.sync(this);
_la = _input.LA(1);
if (_la==T__1) {
{
setState(28);
match(T__1);
}
}
setState(31);
match(T__2);
}
break;
case 2:
enterOuterAlt(_localctx, 2);
{
setState(33);
match(T__0);
setState(34);
match(T__2);
}
break;
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
@SuppressWarnings("CheckReturnValue")
public static class MemberContext extends ParserRuleContext {
public KeyContext key() {
return getRuleContext(KeyContext.class,0);
}
public ValueContext value() {
return getRuleContext(ValueContext.class,0);
}
public MemberContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_member; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof JSON5Listener ) ((JSON5Listener)listener).enterMember(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof JSON5Listener ) ((JSON5Listener)listener).exitMember(this);
}
@Override
public T accept(ParseTreeVisitor extends T> visitor) {
if ( visitor instanceof JSON5Visitor ) return ((JSON5Visitor extends T>)visitor).visitMember(this);
else return visitor.visitChildren(this);
}
}
public final MemberContext member() throws RecognitionException {
MemberContext _localctx = new MemberContext(_ctx, getState());
enterRule(_localctx, 4, RULE_member);
try {
enterOuterAlt(_localctx, 1);
{
setState(37);
key();
setState(38);
match(T__3);
setState(39);
value();
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
@SuppressWarnings("CheckReturnValue")
public static class KeyContext extends ParserRuleContext {
public TerminalNode STRING() { return getToken(JSON5Parser.STRING, 0); }
public TerminalNode IDENTIFIER() { return getToken(JSON5Parser.IDENTIFIER, 0); }
public KeyContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_key; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof JSON5Listener ) ((JSON5Listener)listener).enterKey(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof JSON5Listener ) ((JSON5Listener)listener).exitKey(this);
}
@Override
public T accept(ParseTreeVisitor extends T> visitor) {
if ( visitor instanceof JSON5Visitor ) return ((JSON5Visitor extends T>)visitor).visitKey(this);
else return visitor.visitChildren(this);
}
}
public final KeyContext key() throws RecognitionException {
KeyContext _localctx = new KeyContext(_ctx, getState());
enterRule(_localctx, 6, RULE_key);
int _la;
try {
enterOuterAlt(_localctx, 1);
{
setState(41);
_la = _input.LA(1);
if ( !(_la==STRING || _la==IDENTIFIER) ) {
_errHandler.recoverInline(this);
}
else {
if ( _input.LA(1)==Token.EOF ) matchedEOF = true;
_errHandler.reportMatch(this);
consume();
}
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
@SuppressWarnings("CheckReturnValue")
public static class ValueContext extends ParserRuleContext {
public TerminalNode STRING() { return getToken(JSON5Parser.STRING, 0); }
public NumberContext number() {
return getRuleContext(NumberContext.class,0);
}
public ObjContext obj() {
return getRuleContext(ObjContext.class,0);
}
public ArrContext arr() {
return getRuleContext(ArrContext.class,0);
}
public TerminalNode LITERAL() { return getToken(JSON5Parser.LITERAL, 0); }
public ValueContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_value; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof JSON5Listener ) ((JSON5Listener)listener).enterValue(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof JSON5Listener ) ((JSON5Listener)listener).exitValue(this);
}
@Override
public T accept(ParseTreeVisitor extends T> visitor) {
if ( visitor instanceof JSON5Visitor ) return ((JSON5Visitor extends T>)visitor).visitValue(this);
else return visitor.visitChildren(this);
}
}
public final ValueContext value() throws RecognitionException {
ValueContext _localctx = new ValueContext(_ctx, getState());
enterRule(_localctx, 8, RULE_value);
try {
setState(48);
_errHandler.sync(this);
switch (_input.LA(1)) {
case STRING:
enterOuterAlt(_localctx, 1);
{
setState(43);
match(STRING);
}
break;
case NUMBER:
case NUMERIC_LITERAL:
case SYMBOL:
enterOuterAlt(_localctx, 2);
{
setState(44);
number();
}
break;
case T__0:
enterOuterAlt(_localctx, 3);
{
setState(45);
obj();
}
break;
case T__4:
enterOuterAlt(_localctx, 4);
{
setState(46);
arr();
}
break;
case LITERAL:
enterOuterAlt(_localctx, 5);
{
setState(47);
match(LITERAL);
}
break;
default:
throw new NoViableAltException(this);
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
@SuppressWarnings("CheckReturnValue")
public static class ArrContext extends ParserRuleContext {
public List value() {
return getRuleContexts(ValueContext.class);
}
public ValueContext value(int i) {
return getRuleContext(ValueContext.class,i);
}
public ArrContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_arr; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof JSON5Listener ) ((JSON5Listener)listener).enterArr(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof JSON5Listener ) ((JSON5Listener)listener).exitArr(this);
}
@Override
public T accept(ParseTreeVisitor extends T> visitor) {
if ( visitor instanceof JSON5Visitor ) return ((JSON5Visitor extends T>)visitor).visitArr(this);
else return visitor.visitChildren(this);
}
}
public final ArrContext arr() throws RecognitionException {
ArrContext _localctx = new ArrContext(_ctx, getState());
enterRule(_localctx, 10, RULE_arr);
int _la;
try {
int _alt;
setState(66);
_errHandler.sync(this);
switch ( getInterpreter().adaptivePredict(_input,7,_ctx) ) {
case 1:
enterOuterAlt(_localctx, 1);
{
setState(50);
match(T__4);
setState(51);
value();
setState(56);
_errHandler.sync(this);
_alt = getInterpreter().adaptivePredict(_input,5,_ctx);
while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) {
if ( _alt==1 ) {
{
{
setState(52);
match(T__1);
setState(53);
value();
}
}
}
setState(58);
_errHandler.sync(this);
_alt = getInterpreter().adaptivePredict(_input,5,_ctx);
}
setState(60);
_errHandler.sync(this);
_la = _input.LA(1);
if (_la==T__1) {
{
setState(59);
match(T__1);
}
}
setState(62);
match(T__5);
}
break;
case 2:
enterOuterAlt(_localctx, 2);
{
setState(64);
match(T__4);
setState(65);
match(T__5);
}
break;
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
@SuppressWarnings("CheckReturnValue")
public static class NumberContext extends ParserRuleContext {
public TerminalNode NUMERIC_LITERAL() { return getToken(JSON5Parser.NUMERIC_LITERAL, 0); }
public TerminalNode NUMBER() { return getToken(JSON5Parser.NUMBER, 0); }
public TerminalNode SYMBOL() { return getToken(JSON5Parser.SYMBOL, 0); }
public NumberContext(ParserRuleContext parent, int invokingState) {
super(parent, invokingState);
}
@Override public int getRuleIndex() { return RULE_number; }
@Override
public void enterRule(ParseTreeListener listener) {
if ( listener instanceof JSON5Listener ) ((JSON5Listener)listener).enterNumber(this);
}
@Override
public void exitRule(ParseTreeListener listener) {
if ( listener instanceof JSON5Listener ) ((JSON5Listener)listener).exitNumber(this);
}
@Override
public T accept(ParseTreeVisitor extends T> visitor) {
if ( visitor instanceof JSON5Visitor ) return ((JSON5Visitor extends T>)visitor).visitNumber(this);
else return visitor.visitChildren(this);
}
}
public final NumberContext number() throws RecognitionException {
NumberContext _localctx = new NumberContext(_ctx, getState());
enterRule(_localctx, 12, RULE_number);
int _la;
try {
enterOuterAlt(_localctx, 1);
{
setState(69);
_errHandler.sync(this);
_la = _input.LA(1);
if (_la==SYMBOL) {
{
setState(68);
match(SYMBOL);
}
}
setState(71);
_la = _input.LA(1);
if ( !(_la==NUMBER || _la==NUMERIC_LITERAL) ) {
_errHandler.recoverInline(this);
}
else {
if ( _input.LA(1)==Token.EOF ) matchedEOF = true;
_errHandler.reportMatch(this);
consume();
}
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static final String _serializedATN =
"\u0004\u0001\u0010J\u0002\u0000\u0007\u0000\u0002\u0001\u0007\u0001\u0002"+
"\u0002\u0007\u0002\u0002\u0003\u0007\u0003\u0002\u0004\u0007\u0004\u0002"+
"\u0005\u0007\u0005\u0002\u0006\u0007\u0006\u0001\u0000\u0003\u0000\u0010"+
"\b\u0000\u0001\u0000\u0001\u0000\u0001\u0001\u0001\u0001\u0001\u0001\u0001"+
"\u0001\u0005\u0001\u0018\b\u0001\n\u0001\f\u0001\u001b\t\u0001\u0001\u0001"+
"\u0003\u0001\u001e\b\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001"+
"\u0003\u0001$\b\u0001\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0002"+
"\u0001\u0003\u0001\u0003\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004"+
"\u0001\u0004\u0003\u00041\b\u0004\u0001\u0005\u0001\u0005\u0001\u0005"+
"\u0001\u0005\u0005\u00057\b\u0005\n\u0005\f\u0005:\t\u0005\u0001\u0005"+
"\u0003\u0005=\b\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005"+
"\u0003\u0005C\b\u0005\u0001\u0006\u0003\u0006F\b\u0006\u0001\u0006\u0001"+
"\u0006\u0001\u0006\u0000\u0000\u0007\u0000\u0002\u0004\u0006\b\n\f\u0000"+
"\u0002\u0002\u0000\n\n\u000e\u000e\u0001\u0000\u000b\fN\u0000\u000f\u0001"+
"\u0000\u0000\u0000\u0002#\u0001\u0000\u0000\u0000\u0004%\u0001\u0000\u0000"+
"\u0000\u0006)\u0001\u0000\u0000\u0000\b0\u0001\u0000\u0000\u0000\nB\u0001"+
"\u0000\u0000\u0000\fE\u0001\u0000\u0000\u0000\u000e\u0010\u0003\b\u0004"+
"\u0000\u000f\u000e\u0001\u0000\u0000\u0000\u000f\u0010\u0001\u0000\u0000"+
"\u0000\u0010\u0011\u0001\u0000\u0000\u0000\u0011\u0012\u0005\u0000\u0000"+
"\u0001\u0012\u0001\u0001\u0000\u0000\u0000\u0013\u0014\u0005\u0001\u0000"+
"\u0000\u0014\u0019\u0003\u0004\u0002\u0000\u0015\u0016\u0005\u0002\u0000"+
"\u0000\u0016\u0018\u0003\u0004\u0002\u0000\u0017\u0015\u0001\u0000\u0000"+
"\u0000\u0018\u001b\u0001\u0000\u0000\u0000\u0019\u0017\u0001\u0000\u0000"+
"\u0000\u0019\u001a\u0001\u0000\u0000\u0000\u001a\u001d\u0001\u0000\u0000"+
"\u0000\u001b\u0019\u0001\u0000\u0000\u0000\u001c\u001e\u0005\u0002\u0000"+
"\u0000\u001d\u001c\u0001\u0000\u0000\u0000\u001d\u001e\u0001\u0000\u0000"+
"\u0000\u001e\u001f\u0001\u0000\u0000\u0000\u001f \u0005\u0003\u0000\u0000"+
" $\u0001\u0000\u0000\u0000!\"\u0005\u0001\u0000\u0000\"$\u0005\u0003\u0000"+
"\u0000#\u0013\u0001\u0000\u0000\u0000#!\u0001\u0000\u0000\u0000$\u0003"+
"\u0001\u0000\u0000\u0000%&\u0003\u0006\u0003\u0000&\'\u0005\u0004\u0000"+
"\u0000\'(\u0003\b\u0004\u0000(\u0005\u0001\u0000\u0000\u0000)*\u0007\u0000"+
"\u0000\u0000*\u0007\u0001\u0000\u0000\u0000+1\u0005\n\u0000\u0000,1\u0003"+
"\f\u0006\u0000-1\u0003\u0002\u0001\u0000.1\u0003\n\u0005\u0000/1\u0005"+
"\t\u0000\u00000+\u0001\u0000\u0000\u00000,\u0001\u0000\u0000\u00000-\u0001"+
"\u0000\u0000\u00000.\u0001\u0000\u0000\u00000/\u0001\u0000\u0000\u0000"+
"1\t\u0001\u0000\u0000\u000023\u0005\u0005\u0000\u000038\u0003\b\u0004"+
"\u000045\u0005\u0002\u0000\u000057\u0003\b\u0004\u000064\u0001\u0000\u0000"+
"\u00007:\u0001\u0000\u0000\u000086\u0001\u0000\u0000\u000089\u0001\u0000"+
"\u0000\u00009<\u0001\u0000\u0000\u0000:8\u0001\u0000\u0000\u0000;=\u0005"+
"\u0002\u0000\u0000<;\u0001\u0000\u0000\u0000<=\u0001\u0000\u0000\u0000"+
"=>\u0001\u0000\u0000\u0000>?\u0005\u0006\u0000\u0000?C\u0001\u0000\u0000"+
"\u0000@A\u0005\u0005\u0000\u0000AC\u0005\u0006\u0000\u0000B2\u0001\u0000"+
"\u0000\u0000B@\u0001\u0000\u0000\u0000C\u000b\u0001\u0000\u0000\u0000"+
"DF\u0005\r\u0000\u0000ED\u0001\u0000\u0000\u0000EF\u0001\u0000\u0000\u0000"+
"FG\u0001\u0000\u0000\u0000GH\u0007\u0001\u0000\u0000H\r\u0001\u0000\u0000"+
"\u0000\t\u000f\u0019\u001d#08