Class Lexer


  • public class Lexer
    extends java.lang.Object
    JavaScript lexer that is able to parse JavaScript code and return its tokens.

    The algorithm for distinguishing between division operators and regex literals was taken from the RESS lexer.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Lexer.ParsedToken
      Parsed token, containing the token and its position in the input string
    • Constructor Summary

      Constructors 
      Constructor Description
      Lexer​(java.lang.String js)
      Create a new JavaScript lexer with the given source code
      Lexer​(java.lang.String js, int languageVersion)
      Create a new JavaScript lexer with the given source code
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Lexer.ParsedToken getNextToken()
      Continue parsing and return the next token
      boolean isBalanced()
      Check if the parser is balanced (equal amount of open and closed parentheses and braces)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Lexer

        public Lexer​(java.lang.String js,
                     int languageVersion)
        Create a new JavaScript lexer with the given source code
        Parameters:
        js - JavaScript code
        languageVersion - JavaScript version (from Rhino)
      • Lexer

        public Lexer​(java.lang.String js)
        Create a new JavaScript lexer with the given source code
        Parameters:
        js - JavaScript code
    • Method Detail

      • isBalanced

        public boolean isBalanced()
        Check if the parser is balanced (equal amount of open and closed parentheses and braces)
        Returns:
        true if balanced