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

io.rivulet.BasicSQLParser Maven / Gradle / Ivy

The newest version!
// Generated from io/rivulet/BasicSQL.g4 by ANTLR 4.0
package io.rivulet;

    import java.util.LinkedList;

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 BasicSQLParser extends Parser {
	protected static final DFA[] _decisionToDFA;
	protected static final PredictionContextCache _sharedContextCache =
		new PredictionContextCache();
	public static final int
		MULTILINE_COMMENT=1, SINGLE_LINE_COMMENT=2, DOUBLE_QUOTE_STRING=3, SINGLE_QUOTE_STRING=4, 
		BACKTICK_STRING=5, OTHER=6;
	public static final String[] tokenNames = {
		"", "MULTILINE_COMMENT", "SINGLE_LINE_COMMENT", "DOUBLE_QUOTE_STRING", 
		"SINGLE_QUOTE_STRING", "BACKTICK_STRING", "OTHER"
	};
	public static final int
		RULE_parse = 0, RULE_text = 1, RULE_commented = 2, RULE_quoted = 3, RULE_unquoted = 4;
	public static final String[] ruleNames = {
		"parse", "text", "commented", "quoted", "unquoted"
	};

	@Override
	public String getGrammarFileName() { return "BasicSQL.g4"; }

	@Override
	public String[] getTokenNames() { return tokenNames; }

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

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


	  private StringBuilder codeBuilder = new StringBuilder();
	  public LinkedList code = new LinkedList<>();
	  public LinkedList commented = new LinkedList<>();
	  public LinkedList quoted  = new LinkedList<>();

	  private void resetBuilder() {
	    if(codeBuilder.length() != 0) {
	      code.add(codeBuilder.toString());
	      codeBuilder = new StringBuilder();
	    }
	  }

	public BasicSQLParser(TokenStream input) {
		super(input);
		_interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
	}
	public static class ParseContext extends ParserRuleContext {
		public TextContext text() {
			return getRuleContext(TextContext.class,0);
		}
		public ParseContext parse() {
			return getRuleContext(ParseContext.class,0);
		}
		public TerminalNode EOF() { return getToken(BasicSQLParser.EOF, 0); }
		public ParseContext(ParserRuleContext parent, int invokingState) {
			super(parent, invokingState);
		}
		@Override public int getRuleIndex() { return RULE_parse; }
		@Override
		public void enterRule(ParseTreeListener listener) {
			if ( listener instanceof BasicSQLListener ) ((BasicSQLListener)listener).enterParse(this);
		}
		@Override
		public void exitRule(ParseTreeListener listener) {
			if ( listener instanceof BasicSQLListener ) ((BasicSQLListener)listener).exitParse(this);
		}
	}

	public final ParseContext parse() throws RecognitionException {
		ParseContext _localctx = new ParseContext(_ctx, getState());
		enterRule(_localctx, 0, RULE_parse);
		try {
			setState(15);
			switch (_input.LA(1)) {
			case MULTILINE_COMMENT:
			case SINGLE_LINE_COMMENT:
			case DOUBLE_QUOTE_STRING:
			case SINGLE_QUOTE_STRING:
			case BACKTICK_STRING:
			case OTHER:
				enterOuterAlt(_localctx, 1);
				{
				setState(10); text();
				setState(11); parse();
				}
				break;
			case EOF:
				enterOuterAlt(_localctx, 2);
				{
				setState(13); match(EOF);
				resetBuilder();
				}
				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 TextContext extends ParserRuleContext {
		public CommentedContext commented;
		public QuotedContext quoted;
		public UnquotedContext unquoted;
		public QuotedContext quoted() {
			return getRuleContext(QuotedContext.class,0);
		}
		public CommentedContext commented() {
			return getRuleContext(CommentedContext.class,0);
		}
		public UnquotedContext unquoted() {
			return getRuleContext(UnquotedContext.class,0);
		}
		public TextContext(ParserRuleContext parent, int invokingState) {
			super(parent, invokingState);
		}
		@Override public int getRuleIndex() { return RULE_text; }
		@Override
		public void enterRule(ParseTreeListener listener) {
			if ( listener instanceof BasicSQLListener ) ((BasicSQLListener)listener).enterText(this);
		}
		@Override
		public void exitRule(ParseTreeListener listener) {
			if ( listener instanceof BasicSQLListener ) ((BasicSQLListener)listener).exitText(this);
		}
	}

	public final TextContext text() throws RecognitionException {
		TextContext _localctx = new TextContext(_ctx, getState());
		enterRule(_localctx, 2, RULE_text);
		try {
			setState(26);
			switch (_input.LA(1)) {
			case MULTILINE_COMMENT:
			case SINGLE_LINE_COMMENT:
				enterOuterAlt(_localctx, 1);
				{
				setState(17); ((TextContext)_localctx).commented = commented();
				resetBuilder(); commented.add((((TextContext)_localctx).commented!=null?_input.getText(((TextContext)_localctx).commented.start,((TextContext)_localctx).commented.stop):null));
				}
				break;
			case DOUBLE_QUOTE_STRING:
			case SINGLE_QUOTE_STRING:
			case BACKTICK_STRING:
				enterOuterAlt(_localctx, 2);
				{
				setState(20); ((TextContext)_localctx).quoted = quoted();
				resetBuilder(); quoted.add((((TextContext)_localctx).quoted!=null?_input.getText(((TextContext)_localctx).quoted.start,((TextContext)_localctx).quoted.stop):null));
				}
				break;
			case OTHER:
				enterOuterAlt(_localctx, 3);
				{
				setState(23); ((TextContext)_localctx).unquoted = unquoted();
				codeBuilder.append((((TextContext)_localctx).unquoted!=null?_input.getText(((TextContext)_localctx).unquoted.start,((TextContext)_localctx).unquoted.stop):null));
				}
				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 CommentedContext extends ParserRuleContext {
		public TerminalNode SINGLE_LINE_COMMENT() { return getToken(BasicSQLParser.SINGLE_LINE_COMMENT, 0); }
		public TerminalNode MULTILINE_COMMENT() { return getToken(BasicSQLParser.MULTILINE_COMMENT, 0); }
		public CommentedContext(ParserRuleContext parent, int invokingState) {
			super(parent, invokingState);
		}
		@Override public int getRuleIndex() { return RULE_commented; }
		@Override
		public void enterRule(ParseTreeListener listener) {
			if ( listener instanceof BasicSQLListener ) ((BasicSQLListener)listener).enterCommented(this);
		}
		@Override
		public void exitRule(ParseTreeListener listener) {
			if ( listener instanceof BasicSQLListener ) ((BasicSQLListener)listener).exitCommented(this);
		}
	}

	public final CommentedContext commented() throws RecognitionException {
		CommentedContext _localctx = new CommentedContext(_ctx, getState());
		enterRule(_localctx, 4, RULE_commented);
		int _la;
		try {
			enterOuterAlt(_localctx, 1);
			{
			setState(28);
			_la = _input.LA(1);
			if ( !(_la==MULTILINE_COMMENT || _la==SINGLE_LINE_COMMENT) ) {
			_errHandler.recoverInline(this);
			}
			consume();
			}
		}
		catch (RecognitionException re) {
			_localctx.exception = re;
			_errHandler.reportError(this, re);
			_errHandler.recover(this, re);
		}
		finally {
			exitRule();
		}
		return _localctx;
	}

	public static class QuotedContext extends ParserRuleContext {
		public TerminalNode BACKTICK_STRING() { return getToken(BasicSQLParser.BACKTICK_STRING, 0); }
		public TerminalNode DOUBLE_QUOTE_STRING() { return getToken(BasicSQLParser.DOUBLE_QUOTE_STRING, 0); }
		public TerminalNode SINGLE_QUOTE_STRING() { return getToken(BasicSQLParser.SINGLE_QUOTE_STRING, 0); }
		public QuotedContext(ParserRuleContext parent, int invokingState) {
			super(parent, invokingState);
		}
		@Override public int getRuleIndex() { return RULE_quoted; }
		@Override
		public void enterRule(ParseTreeListener listener) {
			if ( listener instanceof BasicSQLListener ) ((BasicSQLListener)listener).enterQuoted(this);
		}
		@Override
		public void exitRule(ParseTreeListener listener) {
			if ( listener instanceof BasicSQLListener ) ((BasicSQLListener)listener).exitQuoted(this);
		}
	}

	public final QuotedContext quoted() throws RecognitionException {
		QuotedContext _localctx = new QuotedContext(_ctx, getState());
		enterRule(_localctx, 6, RULE_quoted);
		int _la;
		try {
			enterOuterAlt(_localctx, 1);
			{
			setState(30);
			_la = _input.LA(1);
			if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << DOUBLE_QUOTE_STRING) | (1L << SINGLE_QUOTE_STRING) | (1L << BACKTICK_STRING))) != 0)) ) {
			_errHandler.recoverInline(this);
			}
			consume();
			}
		}
		catch (RecognitionException re) {
			_localctx.exception = re;
			_errHandler.reportError(this, re);
			_errHandler.recover(this, re);
		}
		finally {
			exitRule();
		}
		return _localctx;
	}

	public static class UnquotedContext extends ParserRuleContext {
		public List OTHER() { return getTokens(BasicSQLParser.OTHER); }
		public TerminalNode OTHER(int i) {
			return getToken(BasicSQLParser.OTHER, i);
		}
		public UnquotedContext(ParserRuleContext parent, int invokingState) {
			super(parent, invokingState);
		}
		@Override public int getRuleIndex() { return RULE_unquoted; }
		@Override
		public void enterRule(ParseTreeListener listener) {
			if ( listener instanceof BasicSQLListener ) ((BasicSQLListener)listener).enterUnquoted(this);
		}
		@Override
		public void exitRule(ParseTreeListener listener) {
			if ( listener instanceof BasicSQLListener ) ((BasicSQLListener)listener).exitUnquoted(this);
		}
	}

	public final UnquotedContext unquoted() throws RecognitionException {
		UnquotedContext _localctx = new UnquotedContext(_ctx, getState());
		enterRule(_localctx, 8, RULE_unquoted);
		try {
			int _alt;
			enterOuterAlt(_localctx, 1);
			{
			setState(33); 
			_errHandler.sync(this);
			_alt = getInterpreter().adaptivePredict(_input,2,_ctx);
			do {
				switch (_alt) {
				case 1:
					{
					{
					setState(32); match(OTHER);
					}
					}
					break;
				default:
					throw new NoViableAltException(this);
				}
				setState(35); 
				_errHandler.sync(this);
				_alt = getInterpreter().adaptivePredict(_input,2,_ctx);
			} while ( _alt!=2 && _alt!=-1 );
			}
		}
		catch (RecognitionException re) {
			_localctx.exception = re;
			_errHandler.reportError(this, re);
			_errHandler.recover(this, re);
		}
		finally {
			exitRule();
		}
		return _localctx;
	}

	public static final String _serializedATN =
		"\2\3\b(\4\2\t\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\3\2\3\2\3\2\3\2\3\2\5"+
		"\2\22\n\2\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\5\3\35\n\3\3\4\3\4\3\5\3"+
		"\5\3\6\6\6$\n\6\r\6\16\6%\3\6\2\7\2\4\6\b\n\2\4\3\3\4\3\5\7&\2\21\3\2"+
		"\2\2\4\34\3\2\2\2\6\36\3\2\2\2\b \3\2\2\2\n#\3\2\2\2\f\r\5\4\3\2\r\16"+
		"\5\2\2\2\16\22\3\2\2\2\17\20\7\1\2\2\20\22\b\2\1\2\21\f\3\2\2\2\21\17"+
		"\3\2\2\2\22\3\3\2\2\2\23\24\5\6\4\2\24\25\b\3\1\2\25\35\3\2\2\2\26\27"+
		"\5\b\5\2\27\30\b\3\1\2\30\35\3\2\2\2\31\32\5\n\6\2\32\33\b\3\1\2\33\35"+
		"\3\2\2\2\34\23\3\2\2\2\34\26\3\2\2\2\34\31\3\2\2\2\35\5\3\2\2\2\36\37"+
		"\t\2\2\2\37\7\3\2\2\2 !\t\3\2\2!\t\3\2\2\2\"$\7\b\2\2#\"\3\2\2\2$%\3\2"+
		"\2\2%#\3\2\2\2%&\3\2\2\2&\13\3\2\2\2\5\21\34%";
	public static final ATN _ATN =
		ATNSimulator.deserialize(_serializedATN.toCharArray());
	static {
		_decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy