org.antlr.v4.runtime.atn.LexerATNSimulator Java Examples

The following examples show how to use org.antlr.v4.runtime.atn.LexerATNSimulator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JavaFileParser.java    From depends with MIT License 6 votes vote down vote up
@Override
public void parse() throws IOException {
       CharStream input = CharStreams.fromFileName(fileFullPath);
       Lexer lexer = new JavaLexer(input);
       lexer.setInterpreter(new LexerATNSimulator(lexer, lexer.getATN(), lexer.getInterpreter().decisionToDFA, new PredictionContextCache()));
       CommonTokenStream tokens = new CommonTokenStream(lexer);
       JavaParser parser = new JavaParser(tokens);
       ParserATNSimulator interpreter = new ParserATNSimulator(parser, parser.getATN(), parser.getInterpreter().decisionToDFA, new PredictionContextCache());
       parser.setInterpreter(interpreter);
       JavaListener bridge = new JavaListener(fileFullPath, entityRepo,inferer);
    ParseTreeWalker walker = new ParseTreeWalker();
    try {
    	walker.walk(bridge, parser.compilationUnit());
		Entity fileEntity = entityRepo.getEntity(fileFullPath);
		((FileEntity)fileEntity).cacheAllExpressions();
		interpreter.clearDFA();
		bridge.done();
    	
    }catch (Exception e) {
    	System.err.println("error encountered during parse..." );
    	e.printStackTrace();
    }
    
   }
 
Example #2
Source File: ParseHelper.java    From graphicsfuzz with Apache License 2.0 6 votes vote down vote up
private static GLSLParser getParser(
      InputStream inputStream,
      ParseTreeListener listener) throws IOException {

  ANTLRInputStream input = new ANTLRInputStream(inputStream);
  GLSLLexer lexer = new GLSLLexer(input);
  PredictionContextCache cache = new PredictionContextCache();
  lexer.setInterpreter(
        new LexerATNSimulator(lexer, lexer.getATN(),
              lexer.getInterpreter().decisionToDFA, cache));
  CommonTokenStream tokens = new CommonTokenStream(lexer);
  GLSLParser parser = new GLSLParser(tokens);
  // Remove error listeners, otherwise errors get output to the console.
  parser.removeErrorListeners();
  if (listener != null) {
    parser.addParseListener(listener);
  }
  parser.setInterpreter(
        new ParserATNSimulator(parser, parser.getATN(),
              parser.getInterpreter().decisionToDFA,
              cache));
  return parser;
}
 
Example #3
Source File: AntlrATNCacheFields.java    From presto with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("ObjectEquality")
public void configureLexer(Lexer lexer)
{
    requireNonNull(lexer, "lexer is null");
    // Intentional identity equals comparison
    checkArgument(atn == lexer.getATN(), "Lexer ATN mismatch: expected %s, found %s", atn, lexer.getATN());
    lexer.setInterpreter(new LexerATNSimulator(lexer, atn, decisionToDFA, predictionContextCache));
}
 
Example #4
Source File: JavaLexer.java    From rewrite with Apache License 2.0 4 votes vote down vote up
public JavaLexer(CharStream input) {
	super(input);
	_interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
}
 
Example #5
Source File: CSSTokenRecovery.java    From jStyleParser with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Implements Lexer's next token with extra token passing from
 * recovery function
 */
public Token nextToken() {

    if(lexer._input == null) {
        throw new IllegalStateException("nextToken requires a non-null input stream.");
    } else {
        int tokenStartMarker = lexer._input.mark();

        try {
            Token ttype1;
            label110:
            while(!lexer._hitEOF) {
                lexer._token = null;
                lexer._channel = Token.DEFAULT_CHANNEL;
                lexer._tokenStartCharIndex = lexer._input.index();
                lexer._tokenStartCharPositionInLine = ((LexerATNSimulator)lexer.getInterpreter()).getCharPositionInLine();
                lexer._tokenStartLine = ((LexerATNSimulator)lexer.getInterpreter()).getLine();
                lexer._text = null;


                do {
                    lexer._type = 0;

                    int ttype;
                    try {
                        ttype = ((LexerATNSimulator)lexer.getInterpreter()).match(lexer._input, lexer._mode);
                    } catch (LexerNoViableAltException var7) {
                        lexer.notifyListeners(var7);
                        lexer.recover(var7);
                        ttype = -3;
                    }

                    if(lexer._input.LA(1) == -1) {
                        lexer._hitEOF = true;
                    }

                    if(lexer._type == 0) {
                        lexer._type = ttype;
                    }

                    if(lexer._type == -3) {
                        continue label110;
                    }
                } while(lexer._type == -2);

                if(lexer._token == null) {
                    lexer.emit();
                }

                ttype1 = lexer._token;
                //log.trace("return token: >" + ttype1.getText()+"< " + ttype1.getType());
                return ttype1;
            }
            // recover from unexpected EOF
            eof = true;
            if (!ls.isBalanced()) {
                return generateEOFRecover();
            }
            log.trace("lexer state is balanced - emitEOF");
            lexer.emitEOF();
            ttype1 = lexer._token;
            return ttype1;
        } finally {
            lexer._input.release(tokenStartMarker);
        }
    }
}
 
Example #6
Source File: EditorConfigLexer.java    From editorconfig-netbeans with MIT License 4 votes vote down vote up
public EditorConfigLexer(CharStream input) {
  super(input);
  _interp = new LexerATNSimulator(this, _ATN, _decisionToDFA, _sharedContextCache);
}
 
Example #7
Source File: XpathLexer.java    From JsoupXpath with Apache License 2.0 4 votes vote down vote up
public XpathLexer(CharStream input) {
	super(input);
	_interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
}
 
Example #8
Source File: JaybirdSqlLexer.java    From jaybird with GNU Lesser General Public License v2.1 4 votes vote down vote up
public JaybirdSqlLexer(CharStream input) {
	super(input);
	_interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
}
 
Example #9
Source File: SoqlLexer.java    From components with Apache License 2.0 4 votes vote down vote up
public SoqlLexer(CharStream input) {
	super(input);
	_interp = new LexerATNSimulator(this, _ATN, _decisionToDFA, _sharedContextCache);
}
 
Example #10
Source File: CQLCFLexer.java    From chronix.server with Apache License 2.0 4 votes vote down vote up
public CQLCFLexer(CharStream input) {
    super(input);
    _interp = new LexerATNSimulator(this, _ATN, _decisionToDFA, _sharedContextCache);
}
 
Example #11
Source File: FWPolicyLexer.java    From development with Apache License 2.0 4 votes vote down vote up
public FWPolicyLexer(CharStream input) {
    super(input);
    _interp = new LexerATNSimulator(this, _ATN, _decisionToDFA,
            _sharedContextCache);
}
 
Example #12
Source File: FunctionExpressionLexer.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
public FunctionExpressionLexer(CharStream input) {
	super(input);
	_interp = new LexerATNSimulator(this, _ATN, _decisionToDFA, _sharedContextCache);
}
 
Example #13
Source File: KalangLexer.java    From kalang with MIT License 4 votes vote down vote up
public KalangLexer(CharStream input) {
	super(input);
	_interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
}
 
Example #14
Source File: AspectJLexer.java    From rewrite with Apache License 2.0 4 votes vote down vote up
public AspectJLexer(CharStream input) {
	super(input);
	_interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
}
 
Example #15
Source File: XMLLexer.java    From manifold with Apache License 2.0 4 votes vote down vote up
public XMLLexer( CharStream input )
{
  super( input );
  _interp = new LexerATNSimulator( this, _ATN, _decisionToDFA, _sharedContextCache );
}
 
Example #16
Source File: SQLiteLexer.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public SQLiteLexer(CharStream input) {
	super(input);
	_interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
}
 
Example #17
Source File: Recovery.java    From netbeans with Apache License 2.0 4 votes vote down vote up
void recover(
@NonNull CharStream in,
@NonNull LexerATNSimulator interpreter);
 
Example #18
Source File: AtlasDSLLexer.java    From atlas with Apache License 2.0 4 votes vote down vote up
public AtlasDSLLexer(CharStream input) {
	super(input);
	_interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
}
 
Example #19
Source File: DataModelLexer.java    From wecube-platform with Apache License 2.0 4 votes vote down vote up
public DataModelLexer(CharStream input) {
    super(input);
    _interp = new LexerATNSimulator(this, _ATN, _decisionToDFA, _sharedContextCache);
}
 
Example #20
Source File: OoxxLexer.java    From BigDataArchitect with Apache License 2.0 4 votes vote down vote up
public OoxxLexer(CharStream input) {
	super(input);
	_interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
}
 
Example #21
Source File: XGBoostModelLexer.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs a new instance of XGBoost model lexer.
 *
 * @param input Character stream.
 */
public XGBoostModelLexer(CharStream input) {
    super(input);
    _interp = new LexerATNSimulator(this, _ATN, _decisionToDFA, _sharedContextCache);
}