Class Scanner


  • public class Scanner
    extends Object
    Splits up a character stream into tokens and returns them as String objects.

    The optionalFileName parameter passed to many constructors should point

    • Constructor Detail

      • Scanner

        public Scanner​(String optionalFileName,
                       InputStream is,
                       String optionalEncoding)
                throws CompileException,
                       IOException
        Set up a scanner that reads tokens from the given InputStream with the given optionalEncoding (null means platform default encoding).

        The optionalFileName is used for reporting errors during compilation and for source level debugging, and should name an existing file. If null is passed, and the system property org.codehaus.janino.source_debugging.enable is set to "true", then a temporary file in org.codehaus.janino.source_debugging.dir or the system's default temp dir is created in order to make the source code available to a debugger.

        Throws:
        CompileException
        IOException
      • Scanner

        public Scanner​(String optionalFileName,
                       Reader in)
                throws CompileException,
                       IOException
        Set up a scanner that reads tokens from the given Reader.

        The optionalFileName is used for reporting errors during compilation and for source level debugging, and should name an existing file. If null is passed, and the system property org.codehaus.janino.source_debugging.enable is set to "true", then a temporary file in org.codehaus.janino.source_debugging.dir or the system's default temp dir is created in order to make the source code available to a debugger.

        Throws:
        CompileException
        IOException
    • Method Detail

      • getFileName

        public String getFileName()
        Returns:
        The file name optionally passed to the constructor
      • close

        @Deprecated
        public void close()
                   throws IOException
        Deprecated.
        This method is deprecated, because the concept described above is confusing. An application should close the underlying InputStream or Reader itself.
        Closes the character source (file, InputStream, Reader) associated with this object. The results of future calls to produce() are undefined.
        Throws:
        IOException
      • doc

        public String doc()
        Get the text of the doc comment (a.k.a. "JAVADOC comment") preceeding the next token.
        Returns:
        null if the next token is not preceeded by a doc comment
      • location

        public Location location()
        Returns:
        The Location of the next character
      • getExpectGreater

        public boolean getExpectGreater()
        Returns:
        Whether the scanner is currently in 'expect greater' mode
      • setExpectGreater

        public boolean setExpectGreater​(boolean value)
        Sets or resets the 'expect greater' mode.
        Returns:
        Whether the 'expect greater' mode was previously active
      • setWarningHandler

        public void setWarningHandler​(WarningHandler optionalWarningHandler)
        By default, warnings are discarded, but an application my install a WarningHandler.

        Notice that there is no Scanner.setErrorHandler() method, but scan errors always throw a CompileException. The reason being is that there is no reasonable way to recover from scan errors and continue scanning, so there is no need to install a custom scan error handler.

        Parameters:
        optionalWarningHandler - null to indicate that no warnings be issued