java.lang.Object
org.schabi.newpipe.extractor.utils.jsextractor.Lexer

public class Lexer extends 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 
    Parsed token, containing the token and its position in the input string
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a new JavaScript lexer with the given source code
  • Method Summary

    Modifier and Type
    Method
    Description
    Continue parsing and return the next token
    boolean
    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 Details

    • Lexer

      public Lexer(String js)
      Create a new JavaScript lexer with the given source code
      Parameters:
      js - JavaScript code
  • Method Details

    • getNextToken

      public Lexer.ParsedToken getNextToken() throws ParsingException
      Continue parsing and return the next token
      Returns:
      next token
      Throws:
      ParsingException
    • isBalanced

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