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

org.lockss.tdb.TdbLexer Maven / Gradle / Ivy

// Generated from org/lockss/tdb/TdbLexer.g4 by ANTLR 4.7.2
package org.lockss.tdb;


/* ===================================================================

WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING

If you are modifying a Java file with this warning in it, you are
making changes in the wrong place. This Java file was generated by
ANTLR from a grammar file. You should be editing the grammar file
instead.

=================================================================== */


import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.misc.*;

@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
public class TdbLexer extends Lexer {
	static { RuntimeMetaData.checkVersion("4.7.2", RuntimeMetaData.VERSION); }

	protected static final DFA[] _decisionToDFA;
	protected static final PredictionContextCache _sharedContextCache =
		new PredictionContextCache();
	public static final int
		STRING=1, PUBLISHER=2, TITLE=3, AU=4, IMPLICIT=5, CURLY_OPEN=6, CURLY_CLOSE=7, 
		ANGLE_OPEN=8, ANGLE_CLOSE=9, SEMICOLON=10, EQUALS=11, IDENTIFIER=12, WHITESPACE=13, 
		COMMENT=14;
	public static final int
		COMMENT_MODE=1;
	public static String[] channelNames = {
		"DEFAULT_TOKEN_CHANNEL", "HIDDEN"
	};

	public static String[] modeNames = {
		"DEFAULT_MODE", "COMMENT_MODE"
	};

	private static String[] makeRuleNames() {
		return new String[] {
			"STRING", "PUBLISHER", "TITLE", "AU", "IMPLICIT", "CURLY_OPEN", "CURLY_CLOSE", 
			"ANGLE_OPEN", "ANGLE_CLOSE", "SEMICOLON", "EQUALS", "IDENTIFIER", "WHITESPACE", 
			"COMMENT", "COMMENT_SKIP", "COMMENT_END"
		};
	}
	public static final String[] ruleNames = makeRuleNames();

	private static String[] makeLiteralNames() {
		return new String[] {
			null, null, "'publisher'", "'title'", "'au'", "'implicit'", "'{'", "'}'", 
			"'<'", "'>'", "';'", "'='", null, null, "'#'"
		};
	}
	private static final String[] _LITERAL_NAMES = makeLiteralNames();
	private static String[] makeSymbolicNames() {
		return new String[] {
			null, "STRING", "PUBLISHER", "TITLE", "AU", "IMPLICIT", "CURLY_OPEN", 
			"CURLY_CLOSE", "ANGLE_OPEN", "ANGLE_CLOSE", "SEMICOLON", "EQUALS", "IDENTIFIER", 
			"WHITESPACE", "COMMENT"
		};
	}
	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;
	}



	  private static void syntaxError(String src, int line, int col, String fmt, Object... args) {
	    String msg = String.format("%s:%d:%d: %s", src, line, col, String.format(fmt, args));
	    throw new RuntimeException(msg);
	  }

	  enum SMode { NONE, AU, ANGLE, EQUALS }
	  SMode sMode = SMode.NONE;
	  SMode getSMode() { return sMode; }
	  void setSMode(SMode sMode) { this.sMode = sMode; }
	  boolean isNone() { return getSMode() == SMode.NONE; }
	  void modeNone() { setSMode(SMode.NONE); }
	  boolean isAu() { return getSMode() == SMode.AU; }
	  void modeAu() { setSMode(SMode.AU); }
	  boolean isAngle() { return getSMode() == SMode.ANGLE; }
	  void modeAngle() { setSMode(SMode.ANGLE); }
	  boolean isEquals() { return getSMode() == SMode.EQUALS; }
	  void modeEquals() { setSMode(SMode.EQUALS); }

	  enum SType { NONE, QUOTED, BARE, EMPTY }
	  SType sType = SType.NONE;
	  SType getSType() { return sType; }
	  void setSType(SType sType) { this.sType = sType; }
	  void typeQuoted() { setSType(SType.QUOTED); }
	  boolean isQuoted() { return getSType() == SType.QUOTED; }
	  void typeBare() { setSType(SType.BARE); }
	  boolean isBare() { return getSType() == SType.BARE; }
	  void typeEmpty() { setSType(SType.EMPTY); }
	  boolean isEmpty() { return getSType() == SType.EMPTY; }

	  boolean emitEpsilon = false;
	  java.util.LinkedList myTokens = new java.util.LinkedList();

	  boolean expectString() {
	    return isAngle() || isEquals();
	  }

	  void adjustStringMode() {
	    if (isAngle()) {
	      modeAu();
	    }
	    else if (isEquals()) {
	      modeNone();
	    }
	  }

	  boolean isQString() {
	    CharStream cs = getInputStream();
	    for (int i = 1 ; /*nothing*/ ; ++i) {
	      switch (cs.LA(i)) {
	        case ' ': case '\t': break;
	        case '"': typeQuoted(); return true;
	        default: return false;
	      }
	    }
	  }

	  boolean isBString() {
	    if (isQuoted()) {
	      return false;
	    }
	    CharStream cs = getInputStream();
	    for (int i = 1 ; /*nothing*/ ; ++i) {
	      switch (cs.LA(i)) {
	        case ' ': case '\t': break;
	        case '\\':
	          switch (cs.LA(i + 1)) {
	            case '\\': case ';': case '>': case '#': case '"': case ' ': typeBare(); return true;
	            default: return false;
	          }
	        case ';': case '>': case '#': case '\r': case '\n': case EOF: return false;
	        default: typeBare(); return true;
	      }
	    }
	  }

	  boolean isEmptyBString() {
	    if (isBare() || isQuoted()) {
	      return false;
	    }
	    CharStream cs = getInputStream();
	    for (int i = 1 ; /*nothing*/ ; ++i) {
	      switch (cs.LA(i)) {
	        case ' ': case '\t': break;
	        case ';': case '>': case '#': case '\r': case '\n': case EOF: typeEmpty(); return true;
	        default: return false;
	      }
	    }
	  }

	  void processString() {
	    switch (getSType()) {
	      case QUOTED: processQString(); adjustStringMode(); break;
	      case BARE: processBString(); adjustStringMode(); break;
	      case EMPTY: processEmptyBString(); break;
	      default: throw new RuntimeException("Error: expected string but got invalid string type");
	    }
	    setSType(SType.NONE);
	  }
	  void processQString() {
	    String ret = getText().trim();
	    ret = ret.substring(1, ret.length() - 1);
	    int ind = ret.indexOf('\\');
	    if (ind >= 0) {
	      StringBuilder sb = new StringBuilder();
	      for (int i = 0 ; i < ret.length() ; ++i) {
	        char ch = ret.charAt(i);
	        switch (ch) {
	          case '\\':
	            char ch2 = ret.charAt(i + 1);
	            switch (ch2) {
	              case '\\': case '"':
	                sb.append(ch2);
	                break;
	              default:
	                syntaxError(getSourceName(), getLine(), getCharPositionInLine(),
	                            "Bad quoted string escape: %s", getCharErrorDisplay(ch2));
	            }
	            ++i;
	            break;
	          default:
	            sb.append(ch);
	            break;
	        }
	      }
	      ret = sb.toString();
	    }
	    setText(ret);
	  }

	  void processBString() {
	    String ret = getText().trim();
	    if (ret.charAt(ret.length() - 1) == '\\') {
	      ret = ret + " "; // re-inject trailing escaped space
	    }
	    int ind = ret.indexOf('\\');
	    if (ind >= 0) {
	      StringBuilder sb = new StringBuilder();
	      for (int i = 0 ; i < ret.length() ; ++i) {
	        char ch = ret.charAt(i);
	        switch (ch) {
	          case '\\':
	            char ch2 = ret.charAt(i + 1);
	            switch (ch2) {
	              case '\\': case ';': case '>': case '#': case ' ':
	                sb.append(ch2);
	                break;
	              case '"':
	                if (i == 0) {
	                  sb.append(ch2);
	                  break;
	                }
	                // else drop down to error below (only valid at beginning of string)
	              default:
	                syntaxError(getSourceName(), getLine(), getCharPositionInLine(),
	                            "Bad bare string escape: %s", getCharErrorDisplay(ch2));
	            }
	            ++i;
	            break;
	          default:
	            sb.append(ch);
	            break;
	        }
	      }
	      ret = sb.toString();
	    }
	    setText(ret);
	  }

	  void processEmptyBString() {
	    adjustStringMode();
	    String ret = getText();
	    emitEpsilon = true;
	    char ch = ret.charAt(ret.length() - 1);
	    switch (ch) {
	      case ';': setType(SEMICOLON); actionSemicolon(); break;
	      case '>': setType(ANGLE_CLOSE); actionAngleClose(); break;
	      case '#': setType(COMMENT); pushMode(COMMENT_MODE); skip(); break;
	      case '\r': case '\n': setType(WHITESPACE); skip(); break;
	      default: syntaxError(getSourceName(), getLine(), getCharPositionInLine(),
	                           "Expected end of string but got %s", getCharErrorDisplay(ch));
	    }
	  }

	  @Override
	  public void emit(Token token) {
	    if (emitEpsilon) {
	      emitEpsilon = false;
	      Token epsilon = getTokenFactory().create(_tokenFactorySourcePair,        // source pair
	                                               STRING,                         // type
	                                               "",                             // text
	                                               token.getChannel(),             // channel
	                                               token.getStartIndex(),          // start index
	                                               token.getStartIndex(),          // stop index
	                                               token.getLine(),                // line
	                                               token.getCharPositionInLine()); // column
	      myTokens.add(epsilon);
	    }
	    myTokens.addLast(token);
	    setToken(token);
	  }

	  @Override
	  public Token nextToken() {
	    super.nextToken();
	    if (myTokens.isEmpty()) {
	      return emitEOF();
	    }
	    return myTokens.removeFirst();
	  }

	  void actionSemicolon() {
	    if (isAu()) {
	      modeAngle();
	    }
	  }

	  void actionAngleOpen() {
	    if (isAu()) {
	      modeAngle();
	    }
	  }

	  void actionAngleClose() {
	    if (isAu()) {
	      modeNone();
	    }
	  }



	public TdbLexer(CharStream input) {
		super(input);
		_interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
	}

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

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

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

	@Override
	public String[] getChannelNames() { return channelNames; }

	@Override
	public String[] getModeNames() { return modeNames; }

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

	@Override
	public void action(RuleContext _localctx, int ruleIndex, int actionIndex) {
		switch (ruleIndex) {
		case 0:
			STRING_action((RuleContext)_localctx, actionIndex);
			break;
		case 3:
			AU_action((RuleContext)_localctx, actionIndex);
			break;
		case 7:
			ANGLE_OPEN_action((RuleContext)_localctx, actionIndex);
			break;
		case 8:
			ANGLE_CLOSE_action((RuleContext)_localctx, actionIndex);
			break;
		case 9:
			SEMICOLON_action((RuleContext)_localctx, actionIndex);
			break;
		case 10:
			EQUALS_action((RuleContext)_localctx, actionIndex);
			break;
		}
	}
	private void STRING_action(RuleContext _localctx, int actionIndex) {
		switch (actionIndex) {
		case 0:
			processString();
			break;
		case 1:
			processString();
			break;
		case 2:
			processString();
			break;
		}
	}
	private void AU_action(RuleContext _localctx, int actionIndex) {
		switch (actionIndex) {
		case 3:
			modeAu();
			break;
		}
	}
	private void ANGLE_OPEN_action(RuleContext _localctx, int actionIndex) {
		switch (actionIndex) {
		case 4:
			actionAngleOpen();
			break;
		}
	}
	private void ANGLE_CLOSE_action(RuleContext _localctx, int actionIndex) {
		switch (actionIndex) {
		case 5:
			actionAngleClose();
			break;
		}
	}
	private void SEMICOLON_action(RuleContext _localctx, int actionIndex) {
		switch (actionIndex) {
		case 6:
			actionSemicolon();
			break;
		}
	}
	private void EQUALS_action(RuleContext _localctx, int actionIndex) {
		switch (actionIndex) {
		case 7:
			modeEquals();
			break;
		}
	}
	@Override
	public boolean sempred(RuleContext _localctx, int ruleIndex, int predIndex) {
		switch (ruleIndex) {
		case 0:
			return STRING_sempred((RuleContext)_localctx, predIndex);
		case 12:
			return WHITESPACE_sempred((RuleContext)_localctx, predIndex);
		}
		return true;
	}
	private boolean STRING_sempred(RuleContext _localctx, int predIndex) {
		switch (predIndex) {
		case 0:
			return expectString() && isQString();
		case 1:
			return expectString() && isBString();
		case 2:
			return expectString() && isEmptyBString();
		}
		return true;
	}
	private boolean WHITESPACE_sempred(RuleContext _localctx, int predIndex) {
		switch (predIndex) {
		case 3:
			return !expectString();
		}
		return true;
	}

	public static final String _serializedATN =
		"\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\2\20\u00b0\b\1\b\1"+
		"\4\2\t\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t"+
		"\n\4\13\t\13\4\f\t\f\4\r\t\r\4\16\t\16\4\17\t\17\4\20\t\20\4\21\t\21\3"+
		"\2\3\2\7\2\'\n\2\f\2\16\2*\13\2\3\2\3\2\3\2\3\2\7\2\60\n\2\f\2\16\2\63"+
		"\13\2\3\2\3\2\3\2\3\2\7\29\n\2\f\2\16\2<\13\2\3\2\3\2\3\2\5\2A\n\2\3\2"+
		"\3\2\3\2\7\2F\n\2\f\2\16\2I\13\2\3\2\3\2\3\2\7\2N\n\2\f\2\16\2Q\13\2\3"+
		"\2\3\2\5\2U\n\2\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\4\3\4\3\4\3"+
		"\4\3\4\3\4\3\5\3\5\3\5\3\5\3\5\3\6\3\6\3\6\3\6\3\6\3\6\3\6\3\6\3\6\3\7"+
		"\3\7\3\b\3\b\3\t\3\t\3\t\3\n\3\n\3\n\3\13\3\13\3\13\3\f\3\f\3\f\3\r\3"+
		"\r\7\r\u0087\n\r\f\r\16\r\u008a\13\r\3\r\3\r\3\r\7\r\u008f\n\r\f\r\16"+
		"\r\u0092\13\r\3\r\5\r\u0095\n\r\3\16\3\16\6\16\u0099\n\16\r\16\16\16\u009a"+
		"\3\16\3\16\3\17\3\17\3\17\3\17\3\17\3\20\6\20\u00a5\n\20\r\20\16\20\u00a6"+
		"\3\20\3\20\3\21\3\21\3\21\3\21\3\21\3\21\2\2\22\4\3\6\4\b\5\n\6\f\7\16"+
		"\b\20\t\22\n\24\13\26\f\30\r\32\16\34\17\36\20 \2\"\2\4\2\3\17\4\2\13"+
		"\13\"\"\4\2$$^^\7\2\"\"$%==@@^^\t\2\13\f\17\17\"\"$%==@@^^\7\2\"\"%%="+
		"=@@^^\b\2\f\f\17\17%%==@@^^\7\2\f\f\17\17%%==@@\4\2C\\c|\7\2\60\60\62"+
		";C\\aac|\5\2\62;C\\c|\6\2\60;C\\aac|\5\2\13\f\17\17\"\"\4\2\f\f\17\17"+
		"\2\u00bd\2\4\3\2\2\2\2\6\3\2\2\2\2\b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K\3\2\2"+
		"\2U\5\3\2\2\2VW\7r\2\2WX\7w\2\2XY\7d\2\2YZ\7n\2\2Z[\7k\2\2[\\\7u\2\2\\"+
		"]\7j\2\2]^\7g\2\2^_\7t\2\2_\7\3\2\2\2`a\7v\2\2ab\7k\2\2bc\7v\2\2cd\7n"+
		"\2\2de\7g\2\2e\t\3\2\2\2fg\7c\2\2gh\7w\2\2hi\3\2\2\2ij\b\5\5\2j\13\3\2"+
		"\2\2kl\7k\2\2lm\7o\2\2mn\7r\2\2no\7n\2\2op\7k\2\2pq\7e\2\2qr\7k\2\2rs"+
		"\7v\2\2s\r\3\2\2\2tu\7}\2\2u\17\3\2\2\2vw\7\177\2\2w\21\3\2\2\2xy\7>\2"+
		"\2yz\b\t\6\2z\23\3\2\2\2{|\7@\2\2|}\b\n\7\2}\25\3\2\2\2~\177\7=\2\2\177"+
		"\u0080\b\13\b\2\u0080\27\3\2\2\2\u0081\u0082\7?\2\2\u0082\u0083\b\f\t"+
		"\2\u0083\31\3\2\2\2\u0084\u0088\t\t\2\2\u0085\u0087\t\n\2\2\u0086\u0085"+
		"\3\2\2\2\u0087\u008a\3\2\2\2\u0088\u0086\3\2\2\2\u0088\u0089\3\2\2\2\u0089"+
		"\u0094\3\2\2\2\u008a\u0088\3\2\2\2\u008b\u008c\7]\2\2\u008c\u0090\t\13"+
		"\2\2\u008d\u008f\t\f\2\2\u008e\u008d\3\2\2\2\u008f\u0092\3\2\2\2\u0090"+
		"\u008e\3\2\2\2\u0090\u0091\3\2\2\2\u0091\u0093\3\2\2\2\u0092\u0090\3\2"+
		"\2\2\u0093\u0095\7_\2\2\u0094\u008b\3\2\2\2\u0094\u0095\3\2\2\2\u0095"+
		"\33\3\2\2\2\u0096\u0098\6\16\5\2\u0097\u0099\t\r\2\2\u0098\u0097\3\2\2"+
		"\2\u0099\u009a\3\2\2\2\u009a\u0098\3\2\2\2\u009a\u009b\3\2\2\2\u009b\u009c"+
		"\3\2\2\2\u009c\u009d\b\16\n\2\u009d\35\3\2\2\2\u009e\u009f\7%\2\2\u009f"+
		"\u00a0\3\2\2\2\u00a0\u00a1\b\17\13\2\u00a1\u00a2\b\17\f\2\u00a2\37\3\2"+
		"\2\2\u00a3\u00a5\n\16\2\2\u00a4\u00a3\3\2\2\2\u00a5\u00a6\3\2\2\2\u00a6"+
		"\u00a4\3\2\2\2\u00a6\u00a7\3\2\2\2\u00a7\u00a8\3\2\2\2\u00a8\u00a9\b\20"+
		"\13\2\u00a9!\3\2\2\2\u00aa\u00ab\t\16\2\2\u00ab\u00ac\3\2\2\2\u00ac\u00ad"+
		"\b\21\r\2\u00ad\u00ae\b\21\n\2\u00ae\u00af\b\21\16\2\u00af#\3\2\2\2\22"+
		"\2\3(/\61:@EGOT\u0088\u0090\u0094\u009a\u00a6\17\3\2\2\3\2\3\3\2\4\3\5"+
		"\5\3\t\6\3\n\7\3\13\b\3\f\t\b\2\2\5\2\2\7\3\2\t\20\2\6\2\2";
	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 - 2024 Weber Informatics LLC | Privacy Policy