Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (102)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (322)
Collections:
Other Resources:
ANTLR Runtime Source Code
ANTLR is a powerful parser generator for multiple programming languages
including Java.
ANTLR contains 2 major modules:
ANTLR Runtime Source Code files are provided in the distribution packge (antlr4-4.10.1.zip). You can download them at ANTLR Website.
You can also browse the source code below:
✍: FYIcenter
⏎ org/antlr/v4/runtime/tree/xpath/XPathLexer.java
/*
* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
* Use of this file is governed by the BSD 3-clause license that
* can be found in the LICENSE.txt file in the project root.
*/
package org.antlr.v4.runtime.tree.xpath;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CommonToken;
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.LexerNoViableAltException;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.Vocabulary;
import org.antlr.v4.runtime.VocabularyImpl;
import org.antlr.v4.runtime.atn.ATN;
import org.antlr.v4.runtime.misc.Interval;
/** Mimic the old XPathLexer from .g4 file */
public class XPathLexer extends Lexer {
public static final int
TOKEN_REF=1, RULE_REF=2, ANYWHERE=3, ROOT=4, WILDCARD=5, BANG=6, ID=7,
STRING=8;
public static String[] modeNames = {
"DEFAULT_MODE"
};
public static final String[] ruleNames = {
"ANYWHERE", "ROOT", "WILDCARD", "BANG", "ID", "NameChar", "NameStartChar",
"STRING"
};
private static final String[] _LITERAL_NAMES = {
null, null, null, "'//'", "'/'", "'*'", "'!'"
};
private static final String[] _SYMBOLIC_NAMES = {
null, "TOKEN_REF", "RULE_REF", "ANYWHERE", "ROOT", "WILDCARD", "BANG",
"ID", "STRING"
};
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] = "<INVALID>";
}
}
}
@Override
public String getGrammarFileName() { return "XPathLexer.g4"; }
@Override
public String[] getRuleNames() { return ruleNames; }
@Override
public String[] getModeNames() { return modeNames; }
@Override
@Deprecated
public String[] getTokenNames() {
return tokenNames;
}
@Override
public Vocabulary getVocabulary() {
return VOCABULARY;
}
@Override
public ATN getATN() {
return null;
}
protected int line = 1;
protected int charPositionInLine = 0;
public XPathLexer(CharStream input) {
super(input);
}
@Override
public Token nextToken() {
_tokenStartCharIndex = _input.index();
CommonToken t = null;
while ( t==null ) {
switch ( _input.LA(1) ) {
case '/':
consume();
if ( _input.LA(1)=='/' ) {
consume();
t = new CommonToken(ANYWHERE, "//");
}
else {
t = new CommonToken(ROOT, "/");
}
break;
case '*':
consume();
t = new CommonToken(WILDCARD, "*");
break;
case '!':
consume();
t = new CommonToken(BANG, "!");
break;
case '\'':
String s = matchString();
t = new CommonToken(STRING, s);
break;
case CharStream.EOF :
return new CommonToken(EOF, "<EOF>");
default:
if ( isNameStartChar(_input.LA(1)) ) {
String id = matchID();
if ( Character.isUpperCase(id.charAt(0)) ) t = new CommonToken(TOKEN_REF, id);
else t = new CommonToken(RULE_REF, id);
}
else {
throw new LexerNoViableAltException(this, _input, _tokenStartCharIndex, null);
}
break;
}
}
t.setStartIndex(_tokenStartCharIndex);
t.setCharPositionInLine(_tokenStartCharIndex);
t.setLine(line);
return t;
}
public void consume() {
int curChar = _input.LA(1);
if ( curChar=='\n' ) {
line++;
charPositionInLine=0;
}
else {
charPositionInLine++;
}
_input.consume();
}
@Override
public int getCharPositionInLine() {
return charPositionInLine;
}
public String matchID() {
int start = _input.index();
consume(); // drop start char
while ( isNameChar(_input.LA(1)) ) {
consume();
}
return _input.getText(Interval.of(start,_input.index()-1));
}
public String matchString() {
int start = _input.index();
consume(); // drop first quote
while ( _input.LA(1)!='\'' ) {
consume();
}
consume(); // drop last quote
return _input.getText(Interval.of(start,_input.index()-1));
}
public boolean isNameChar(int c) { return Character.isUnicodeIdentifierPart(c); }
public boolean isNameStartChar(int c) { return Character.isUnicodeIdentifierStart(c); }
}
⏎ org/antlr/v4/runtime/tree/xpath/XPathLexer.java
Or download all of them as a single archive file:
File name: antlr-runtime-4.10.1-sources.jar File size: 308953 bytes Release date: 2022-04-15 Download
⇐ What Is ANTLR Parser Generator
2018-10-21, ≈62🔥, 0💬
Popular Posts:
What Is commons-io-2.11.jar? commons-io-2.11.jar is the JAR file for Commons IO 2.5, which is a libr...
commons-net-1.4.1.jar is the JAR file for Apache Commons Net 1.4.1, which implements the client side...
JAX-WS is an API for building web services and clients. It is the next generation Web Services API r...
How to perform XML Schema validation with dom\Writer.java provided in the Apache Xerces package? You...
Apache Log4j Core Implementation provides the functional components of the logging system. Users are...