All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.groupon.lex.metrics.grammar.StringSubstitutionParser Maven / Gradle / Ivy

The newest version!
// Generated from com/groupon/lex/metrics/grammar/StringSubstitution.g4 by ANTLR 4.7
package com.groupon.lex.metrics.grammar;

    import java.util.ArrayList;
    import java.util.List;
    import com.groupon.lex.metrics.lib.StringTemplate;

import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.misc.*;
import org.antlr.v4.runtime.tree.*;
import java.util.List;
import java.util.Iterator;
import java.util.ArrayList;

@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
public class StringSubstitutionParser extends Parser {
	static { RuntimeMetaData.checkVersion("4.7", RuntimeMetaData.VERSION); }

	protected static final DFA[] _decisionToDFA;
	protected static final PredictionContextCache _sharedContextCache =
		new PredictionContextCache();
	public static final int
		DOLLAR_INDEX=1, DOLLAR_CURLY_BRACKET_OPEN=2, CURLY_BRACKET_CLOSE=3, DOLLAR_DOLLAR=4, 
		INDEX=5, IDENTIFIER=6, ANY=7;
	public static final int
		RULE_expr = 0, RULE_elements = 1, RULE_element = 2, RULE_index = 3, RULE_literal = 4, 
		RULE_literal_fragment = 5;
	public static final String[] ruleNames = {
		"expr", "elements", "element", "index", "literal", "literal_fragment"
	};

	private static final String[] _LITERAL_NAMES = {
	};
	private static final String[] _SYMBOLIC_NAMES = {
		null, "DOLLAR_INDEX", "DOLLAR_CURLY_BRACKET_OPEN", "CURLY_BRACKET_CLOSE", 
		"DOLLAR_DOLLAR", "INDEX", "IDENTIFIER", "ANY"
	};
	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 "StringSubstitution.g4"; }

	@Override
	public String[] getRuleNames() { return ruleNames; }

	@Override
	public String getSerializedATN() { return _serializedATN; }

	@Override
	public ATN getATN() { return _ATN; }

	public StringSubstitutionParser(TokenStream input) {
		super(input);
		_interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
	}
	public static class ExprContext extends ParserRuleContext {
		public StringTemplate s;
		public ElementsContext s_elems;
		public TerminalNode EOF() { return getToken(StringSubstitutionParser.EOF, 0); }
		public ElementsContext elements() {
			return getRuleContext(ElementsContext.class,0);
		}
		public ExprContext(ParserRuleContext parent, int invokingState) {
			super(parent, invokingState);
		}
		@Override public int getRuleIndex() { return RULE_expr; }
		@Override
		public void enterRule(ParseTreeListener listener) {
			if ( listener instanceof StringSubstitutionListener ) ((StringSubstitutionListener)listener).enterExpr(this);
		}
		@Override
		public void exitRule(ParseTreeListener listener) {
			if ( listener instanceof StringSubstitutionListener ) ((StringSubstitutionListener)listener).exitExpr(this);
		}
	}

	public final ExprContext expr() throws RecognitionException {
		ExprContext _localctx = new ExprContext(_ctx, getState());
		enterRule(_localctx, 0, RULE_expr);
		try {
			enterOuterAlt(_localctx, 1);
			{
			setState(12);
			((ExprContext)_localctx).s_elems = elements();
			setState(13);
			match(EOF);
			 ((ExprContext)_localctx).s =  new StringTemplate(((ExprContext)_localctx).s_elems.s); 
			}
		}
		catch (RecognitionException re) {
			_localctx.exception = re;
			_errHandler.reportError(this, re);
			_errHandler.recover(this, re);
		}
		finally {
			exitRule();
		}
		return _localctx;
	}

	public static class ElementsContext extends ParserRuleContext {
		public List s = new ArrayList<>();;
		public ElementContext s0;
		public List element() {
			return getRuleContexts(ElementContext.class);
		}
		public ElementContext element(int i) {
			return getRuleContext(ElementContext.class,i);
		}
		public ElementsContext(ParserRuleContext parent, int invokingState) {
			super(parent, invokingState);
		}
		@Override public int getRuleIndex() { return RULE_elements; }
		@Override
		public void enterRule(ParseTreeListener listener) {
			if ( listener instanceof StringSubstitutionListener ) ((StringSubstitutionListener)listener).enterElements(this);
		}
		@Override
		public void exitRule(ParseTreeListener listener) {
			if ( listener instanceof StringSubstitutionListener ) ((StringSubstitutionListener)listener).exitElements(this);
		}
	}

	public final ElementsContext elements() throws RecognitionException {
		ElementsContext _localctx = new ElementsContext(_ctx, getState());
		enterRule(_localctx, 2, RULE_elements);
		int _la;
		try {
			enterOuterAlt(_localctx, 1);
			{
			setState(21);
			_errHandler.sync(this);
			_la = _input.LA(1);
			while ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << DOLLAR_INDEX) | (1L << DOLLAR_CURLY_BRACKET_OPEN) | (1L << DOLLAR_DOLLAR) | (1L << ANY))) != 0)) {
				{
				{
				setState(16);
				((ElementsContext)_localctx).s0 = element();
				 _localctx.s.add(((ElementsContext)_localctx).s0.s); 
				}
				}
				setState(23);
				_errHandler.sync(this);
				_la = _input.LA(1);
			}
			}
		}
		catch (RecognitionException re) {
			_localctx.exception = re;
			_errHandler.reportError(this, re);
			_errHandler.recover(this, re);
		}
		finally {
			exitRule();
		}
		return _localctx;
	}

	public static class ElementContext extends ParserRuleContext {
		public StringTemplate.Element s;
		public IndexContext s_idx;
		public LiteralContext s_lit;
		public IndexContext index() {
			return getRuleContext(IndexContext.class,0);
		}
		public LiteralContext literal() {
			return getRuleContext(LiteralContext.class,0);
		}
		public ElementContext(ParserRuleContext parent, int invokingState) {
			super(parent, invokingState);
		}
		@Override public int getRuleIndex() { return RULE_element; }
		@Override
		public void enterRule(ParseTreeListener listener) {
			if ( listener instanceof StringSubstitutionListener ) ((StringSubstitutionListener)listener).enterElement(this);
		}
		@Override
		public void exitRule(ParseTreeListener listener) {
			if ( listener instanceof StringSubstitutionListener ) ((StringSubstitutionListener)listener).exitElement(this);
		}
	}

	public final ElementContext element() throws RecognitionException {
		ElementContext _localctx = new ElementContext(_ctx, getState());
		enterRule(_localctx, 4, RULE_element);
		try {
			setState(30);
			_errHandler.sync(this);
			switch (_input.LA(1)) {
			case DOLLAR_INDEX:
			case DOLLAR_CURLY_BRACKET_OPEN:
				enterOuterAlt(_localctx, 1);
				{
				setState(24);
				((ElementContext)_localctx).s_idx = index();
				 ((ElementContext)_localctx).s =  ((ElementContext)_localctx).s_idx.s; 
				}
				break;
			case DOLLAR_DOLLAR:
			case ANY:
				enterOuterAlt(_localctx, 2);
				{
				setState(27);
				((ElementContext)_localctx).s_lit = literal();
				 ((ElementContext)_localctx).s =  ((ElementContext)_localctx).s_lit.s; 
				}
				break;
			default:
				throw new NoViableAltException(this);
			}
		}
		catch (RecognitionException re) {
			_localctx.exception = re;
			_errHandler.reportError(this, re);
			_errHandler.recover(this, re);
		}
		finally {
			exitRule();
		}
		return _localctx;
	}

	public static class IndexContext extends ParserRuleContext {
		public StringTemplate.Element s;
		public Token s1;
		public Token s2_idx;
		public Token s2_nam;
		public TerminalNode DOLLAR_INDEX() { return getToken(StringSubstitutionParser.DOLLAR_INDEX, 0); }
		public TerminalNode DOLLAR_CURLY_BRACKET_OPEN() { return getToken(StringSubstitutionParser.DOLLAR_CURLY_BRACKET_OPEN, 0); }
		public TerminalNode CURLY_BRACKET_CLOSE() { return getToken(StringSubstitutionParser.CURLY_BRACKET_CLOSE, 0); }
		public TerminalNode INDEX() { return getToken(StringSubstitutionParser.INDEX, 0); }
		public TerminalNode IDENTIFIER() { return getToken(StringSubstitutionParser.IDENTIFIER, 0); }
		public IndexContext(ParserRuleContext parent, int invokingState) {
			super(parent, invokingState);
		}
		@Override public int getRuleIndex() { return RULE_index; }
		@Override
		public void enterRule(ParseTreeListener listener) {
			if ( listener instanceof StringSubstitutionListener ) ((StringSubstitutionListener)listener).enterIndex(this);
		}
		@Override
		public void exitRule(ParseTreeListener listener) {
			if ( listener instanceof StringSubstitutionListener ) ((StringSubstitutionListener)listener).exitIndex(this);
		}
	}

	public final IndexContext index() throws RecognitionException {
		IndexContext _localctx = new IndexContext(_ctx, getState());
		enterRule(_localctx, 6, RULE_index);
		try {
			setState(42);
			_errHandler.sync(this);
			switch ( getInterpreter().adaptivePredict(_input,2,_ctx) ) {
			case 1:
				enterOuterAlt(_localctx, 1);
				{
				setState(32);
				((IndexContext)_localctx).s1 = match(DOLLAR_INDEX);
				 ((IndexContext)_localctx).s =  new StringTemplate.SubstituteElement(Integer.valueOf(((IndexContext)_localctx).s1.getText().substring(1))); 
				}
				break;
			case 2:
				enterOuterAlt(_localctx, 2);
				{
				setState(34);
				match(DOLLAR_CURLY_BRACKET_OPEN);
				setState(35);
				((IndexContext)_localctx).s2_idx = match(INDEX);
				setState(36);
				match(CURLY_BRACKET_CLOSE);
				 ((IndexContext)_localctx).s =  new StringTemplate.SubstituteElement(Integer.valueOf(((IndexContext)_localctx).s2_idx.getText())); 
				}
				break;
			case 3:
				enterOuterAlt(_localctx, 3);
				{
				setState(38);
				match(DOLLAR_CURLY_BRACKET_OPEN);
				setState(39);
				((IndexContext)_localctx).s2_nam = match(IDENTIFIER);
				setState(40);
				match(CURLY_BRACKET_CLOSE);
				 ((IndexContext)_localctx).s =  new StringTemplate.SubstituteNameElement(((IndexContext)_localctx).s2_nam.getText()); 
				}
				break;
			}
		}
		catch (RecognitionException re) {
			_localctx.exception = re;
			_errHandler.reportError(this, re);
			_errHandler.recover(this, re);
		}
		finally {
			exitRule();
		}
		return _localctx;
	}

	public static class LiteralContext extends ParserRuleContext {
		public StringTemplate.LiteralElement s;
		public Literal_fragmentContext s0;
		public Literal_fragmentContext literal_fragment() {
			return getRuleContext(Literal_fragmentContext.class,0);
		}
		public LiteralContext(ParserRuleContext parent, int invokingState) {
			super(parent, invokingState);
		}
		@Override public int getRuleIndex() { return RULE_literal; }
		@Override
		public void enterRule(ParseTreeListener listener) {
			if ( listener instanceof StringSubstitutionListener ) ((StringSubstitutionListener)listener).enterLiteral(this);
		}
		@Override
		public void exitRule(ParseTreeListener listener) {
			if ( listener instanceof StringSubstitutionListener ) ((StringSubstitutionListener)listener).exitLiteral(this);
		}
	}

	public final LiteralContext literal() throws RecognitionException {
		LiteralContext _localctx = new LiteralContext(_ctx, getState());
		enterRule(_localctx, 8, RULE_literal);
		try {
			enterOuterAlt(_localctx, 1);
			{
			setState(44);
			((LiteralContext)_localctx).s0 = literal_fragment();
			 ((LiteralContext)_localctx).s =  new StringTemplate.LiteralElement(((LiteralContext)_localctx).s0.s); 
			}
		}
		catch (RecognitionException re) {
			_localctx.exception = re;
			_errHandler.reportError(this, re);
			_errHandler.recover(this, re);
		}
		finally {
			exitRule();
		}
		return _localctx;
	}

	public static class Literal_fragmentContext extends ParserRuleContext {
		public String s;
		public Token s1;
		public TerminalNode ANY() { return getToken(StringSubstitutionParser.ANY, 0); }
		public TerminalNode DOLLAR_DOLLAR() { return getToken(StringSubstitutionParser.DOLLAR_DOLLAR, 0); }
		public Literal_fragmentContext(ParserRuleContext parent, int invokingState) {
			super(parent, invokingState);
		}
		@Override public int getRuleIndex() { return RULE_literal_fragment; }
		@Override
		public void enterRule(ParseTreeListener listener) {
			if ( listener instanceof StringSubstitutionListener ) ((StringSubstitutionListener)listener).enterLiteral_fragment(this);
		}
		@Override
		public void exitRule(ParseTreeListener listener) {
			if ( listener instanceof StringSubstitutionListener ) ((StringSubstitutionListener)listener).exitLiteral_fragment(this);
		}
	}

	public final Literal_fragmentContext literal_fragment() throws RecognitionException {
		Literal_fragmentContext _localctx = new Literal_fragmentContext(_ctx, getState());
		enterRule(_localctx, 10, RULE_literal_fragment);
		try {
			setState(51);
			_errHandler.sync(this);
			switch (_input.LA(1)) {
			case ANY:
				enterOuterAlt(_localctx, 1);
				{
				setState(47);
				((Literal_fragmentContext)_localctx).s1 = match(ANY);
				 ((Literal_fragmentContext)_localctx).s =  ((Literal_fragmentContext)_localctx).s1.getText(); 
				}
				break;
			case DOLLAR_DOLLAR:
				enterOuterAlt(_localctx, 2);
				{
				setState(49);
				((Literal_fragmentContext)_localctx).s1 = match(DOLLAR_DOLLAR);
				 ((Literal_fragmentContext)_localctx).s =  "$"; 
				}
				break;
			default:
				throw new NoViableAltException(this);
			}
		}
		catch (RecognitionException re) {
			_localctx.exception = re;
			_errHandler.reportError(this, re);
			_errHandler.recover(this, re);
		}
		finally {
			exitRule();
		}
		return _localctx;
	}

	public static final String _serializedATN =
		"\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\3\t8\4\2\t\2\4\3\t"+
		"\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\3\2\3\2\3\2\3\2\3\3\3\3\3\3\7\3\26"+
		"\n\3\f\3\16\3\31\13\3\3\4\3\4\3\4\3\4\3\4\3\4\5\4!\n\4\3\5\3\5\3\5\3\5"+
		"\3\5\3\5\3\5\3\5\3\5\3\5\5\5-\n\5\3\6\3\6\3\6\3\7\3\7\3\7\3\7\5\7\66\n"+
		"\7\3\7\2\2\b\2\4\6\b\n\f\2\2\2\66\2\16\3\2\2\2\4\27\3\2\2\2\6 \3\2\2\2"+
		"\b,\3\2\2\2\n.\3\2\2\2\f\65\3\2\2\2\16\17\5\4\3\2\17\20\7\2\2\3\20\21"+
		"\b\2\1\2\21\3\3\2\2\2\22\23\5\6\4\2\23\24\b\3\1\2\24\26\3\2\2\2\25\22"+
		"\3\2\2\2\26\31\3\2\2\2\27\25\3\2\2\2\27\30\3\2\2\2\30\5\3\2\2\2\31\27"+
		"\3\2\2\2\32\33\5\b\5\2\33\34\b\4\1\2\34!\3\2\2\2\35\36\5\n\6\2\36\37\b"+
		"\4\1\2\37!\3\2\2\2 \32\3\2\2\2 \35\3\2\2\2!\7\3\2\2\2\"#\7\3\2\2#-\b\5"+
		"\1\2$%\7\4\2\2%&\7\7\2\2&\'\7\5\2\2\'-\b\5\1\2()\7\4\2\2)*\7\b\2\2*+\7"+
		"\5\2\2+-\b\5\1\2,\"\3\2\2\2,$\3\2\2\2,(\3\2\2\2-\t\3\2\2\2./\5\f\7\2/"+
		"\60\b\6\1\2\60\13\3\2\2\2\61\62\7\t\2\2\62\66\b\7\1\2\63\64\7\6\2\2\64"+
		"\66\b\7\1\2\65\61\3\2\2\2\65\63\3\2\2\2\66\r\3\2\2\2\6\27 ,\65";
	public static final ATN _ATN =
		new ATNDeserializer().deserialize(_serializedATN.toCharArray());
	static {
		_decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
		for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
			_decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy