src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/Lexer.java

Print this page




  76     private final boolean scripting;
  77 
  78     /** True if a nested scan. (scan to completion, no EOF.) */
  79     private final boolean nested;
  80 
  81     /** Pending new line number and position. */
  82     int pendingLine;
  83 
  84     /** Position of last EOL + 1. */
  85     private int linePosition;
  86 
  87     /** Type of last token added. */
  88     private TokenType last;
  89 
  90     private final boolean pauseOnFunctionBody;
  91     private boolean pauseOnNextLeftBrace;
  92 
  93     private static final String SPACETAB = " \t";  // ASCII space and tab
  94     private static final String LFCR     = "\n\r"; // line feed and carriage return (ctrl-m)
  95 
  96     private static final String JSON_WHITESPACE_EOL = LFCR;
  97     private static final String JSON_WHITESPACE     = SPACETAB + LFCR;
  98 
  99     private static final String JAVASCRIPT_WHITESPACE_EOL =
 100         LFCR +
 101         "\u2028" + // line separator
 102         "\u2029"   // paragraph separator
 103         ;
 104     private static final String JAVASCRIPT_WHITESPACE =
 105         SPACETAB +
 106         JAVASCRIPT_WHITESPACE_EOL +
 107         "\u000b" + // tabulation line
 108         "\u000c" + // ff (ctrl-l)
 109         "\u00a0" + // Latin-1 space
 110         "\u1680" + // Ogham space mark
 111         "\u180e" + // separator, Mongolian vowel
 112         "\u2000" + // en quad
 113         "\u2001" + // em quad
 114         "\u2002" + // en space
 115         "\u2003" + // em space
 116         "\u2004" + // three-per-em space
 117         "\u2005" + // four-per-em space
 118         "\u2006" + // six-per-em space


 365         // Skip over end of line.
 366         skipEOL(addEOL);
 367     }
 368 
 369     /**
 370      * Test whether a char is valid JavaScript whitespace
 371      * @param ch a char
 372      * @return true if valid JavaScript whitespace
 373      */
 374     public static boolean isJSWhitespace(final char ch) {
 375         return JAVASCRIPT_WHITESPACE.indexOf(ch) != -1;
 376     }
 377 
 378     /**
 379      * Test whether a char is valid JavaScript end of line
 380      * @param ch a char
 381      * @return true if valid JavaScript end of line
 382      */
 383     public static boolean isJSEOL(final char ch) {
 384         return JAVASCRIPT_WHITESPACE_EOL.indexOf(ch) != -1;
 385     }
 386 
 387     /**
 388      * Test whether a char is valid JSON whitespace
 389      * @param ch a char
 390      * @return true if valid JSON whitespace
 391      */
 392     public static boolean isJsonWhitespace(final char ch) {
 393         return JSON_WHITESPACE.indexOf(ch) != -1;
 394     }
 395 
 396     /**
 397      * Test whether a char is valid JSON end of line
 398      * @param ch a char
 399      * @return true if valid JSON end of line
 400      */
 401     public static boolean isJsonEOL(final char ch) {
 402         return JSON_WHITESPACE_EOL.indexOf(ch) != -1;
 403     }
 404 
 405     /**
 406      * Test if char is a string delimiter, e.g. '\' or '"'.  Also scans exec
 407      * strings ('`') in scripting mode.
 408      * @param ch a char
 409      * @return true if string delimiter
 410      */
 411     protected boolean isStringDelimiter(final char ch) {
 412         return ch == '\'' || ch == '"' || (scripting && ch == '`');
 413     }
 414 
 415     /**
 416      * Test whether a char is valid JavaScript whitespace
 417      * @param ch a char
 418      * @return true if valid JavaScript whitespace
 419      */
 420     protected boolean isWhitespace(final char ch) {
 421         return Lexer.isJSWhitespace(ch);
 422     }




  76     private final boolean scripting;
  77 
  78     /** True if a nested scan. (scan to completion, no EOF.) */
  79     private final boolean nested;
  80 
  81     /** Pending new line number and position. */
  82     int pendingLine;
  83 
  84     /** Position of last EOL + 1. */
  85     private int linePosition;
  86 
  87     /** Type of last token added. */
  88     private TokenType last;
  89 
  90     private final boolean pauseOnFunctionBody;
  91     private boolean pauseOnNextLeftBrace;
  92 
  93     private static final String SPACETAB = " \t";  // ASCII space and tab
  94     private static final String LFCR     = "\n\r"; // line feed and carriage return (ctrl-m)
  95 



  96     private static final String JAVASCRIPT_WHITESPACE_EOL =
  97         LFCR +
  98         "\u2028" + // line separator
  99         "\u2029"   // paragraph separator
 100         ;
 101     private static final String JAVASCRIPT_WHITESPACE =
 102         SPACETAB +
 103         JAVASCRIPT_WHITESPACE_EOL +
 104         "\u000b" + // tabulation line
 105         "\u000c" + // ff (ctrl-l)
 106         "\u00a0" + // Latin-1 space
 107         "\u1680" + // Ogham space mark
 108         "\u180e" + // separator, Mongolian vowel
 109         "\u2000" + // en quad
 110         "\u2001" + // em quad
 111         "\u2002" + // en space
 112         "\u2003" + // em space
 113         "\u2004" + // three-per-em space
 114         "\u2005" + // four-per-em space
 115         "\u2006" + // six-per-em space


 362         // Skip over end of line.
 363         skipEOL(addEOL);
 364     }
 365 
 366     /**
 367      * Test whether a char is valid JavaScript whitespace
 368      * @param ch a char
 369      * @return true if valid JavaScript whitespace
 370      */
 371     public static boolean isJSWhitespace(final char ch) {
 372         return JAVASCRIPT_WHITESPACE.indexOf(ch) != -1;
 373     }
 374 
 375     /**
 376      * Test whether a char is valid JavaScript end of line
 377      * @param ch a char
 378      * @return true if valid JavaScript end of line
 379      */
 380     public static boolean isJSEOL(final char ch) {
 381         return JAVASCRIPT_WHITESPACE_EOL.indexOf(ch) != -1;


















 382     }
 383 
 384     /**
 385      * Test if char is a string delimiter, e.g. '\' or '"'.  Also scans exec
 386      * strings ('`') in scripting mode.
 387      * @param ch a char
 388      * @return true if string delimiter
 389      */
 390     protected boolean isStringDelimiter(final char ch) {
 391         return ch == '\'' || ch == '"' || (scripting && ch == '`');
 392     }
 393 
 394     /**
 395      * Test whether a char is valid JavaScript whitespace
 396      * @param ch a char
 397      * @return true if valid JavaScript whitespace
 398      */
 399     protected boolean isWhitespace(final char ch) {
 400         return Lexer.isJSWhitespace(ch);
 401     }