< prev index next >

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

Print this page




  85     /** True if parsing in ECMAScript 6 mode. */
  86     private final boolean es6;
  87 
  88     /** True if a nested scan. (scan to completion, no EOF.) */
  89     private final boolean nested;
  90 
  91     /** Pending new line number and position. */
  92     int pendingLine;
  93 
  94     /** Position of last EOL + 1. */
  95     private int linePosition;
  96 
  97     /** Type of last token added. */
  98     private TokenType last;
  99 
 100     private final boolean pauseOnFunctionBody;
 101     private boolean pauseOnNextLeftBrace;
 102 
 103     private int templateExpressionOpenBraces;
 104 
 105     private static final String SPACETAB = " \t";  // ASCII space and tab
 106     private static final String LFCR     = "\n\r"; // line feed and carriage return (ctrl-m)
 107 
 108     private static final String JAVASCRIPT_WHITESPACE_EOL =
 109         LFCR +
 110         "\u2028" + // line separator
 111         "\u2029"   // paragraph separator
 112         ;
 113     private static final String JAVASCRIPT_WHITESPACE =
 114         SPACETAB +
 115         JAVASCRIPT_WHITESPACE_EOL +
 116         "\u000b" + // tabulation line
 117         "\u000c" + // ff (ctrl-l)
 118         "\u00a0" + // Latin-1 space
 119         "\u1680" + // Ogham space mark
 120         "\u180e" + // separator, Mongolian vowel
 121         "\u2000" + // en quad
 122         "\u2001" + // em quad
 123         "\u2002" + // en space
 124         "\u2003" + // em space
 125         "\u2004" + // three-per-em space
 126         "\u2005" + // four-per-em space
 127         "\u2006" + // six-per-em space
 128         "\u2007" + // figure space
 129         "\u2008" + // punctuation space
 130         "\u2009" + // thin space
 131         "\u200a" + // hair space
 132         "\u202f" + // narrow no-break space
 133         "\u205f" + // medium mathematical space
 134         "\u3000" + // ideographic space
 135         "\ufeff"   // byte order mark
 136         ;
 137 


 367     /**
 368      * Skip over rest of line including end of line.
 369      *
 370      * @param addEOL true if EOL token should be recorded.
 371      */
 372     private void skipLine(final boolean addEOL) {
 373         // Ignore characters.
 374         while (!isEOL(ch0) && !atEOF()) {
 375             skip(1);
 376         }
 377         // Skip over end of line.
 378         skipEOL(addEOL);
 379     }
 380 
 381     /**
 382      * Test whether a char is valid JavaScript whitespace
 383      * @param ch a char
 384      * @return true if valid JavaScript whitespace
 385      */
 386     public static boolean isJSWhitespace(final char ch) {
 387         return JAVASCRIPT_WHITESPACE.indexOf(ch) != -1;






 388     }
 389 
 390     /**
 391      * Test whether a char is valid JavaScript end of line
 392      * @param ch a char
 393      * @return true if valid JavaScript end of line
 394      */
 395     public static boolean isJSEOL(final char ch) {
 396         return JAVASCRIPT_WHITESPACE_EOL.indexOf(ch) != -1;



 397     }
 398 
 399     /**
 400      * Test if char is a string delimiter, e.g. '\' or '"'.
 401      * @param ch a char
 402      * @return true if string delimiter
 403      */
 404     protected boolean isStringDelimiter(final char ch) {
 405         return ch == '\'' || ch == '"';
 406     }
 407 
 408     /**
 409      * Test if char is a template literal delimiter ('`').
 410      */
 411     private static boolean isTemplateDelimiter(final char ch) {
 412         return ch == '`';
 413     }
 414 
 415     /**
 416      * Test whether a char is valid JavaScript whitespace




  85     /** True if parsing in ECMAScript 6 mode. */
  86     private final boolean es6;
  87 
  88     /** True if a nested scan. (scan to completion, no EOF.) */
  89     private final boolean nested;
  90 
  91     /** Pending new line number and position. */
  92     int pendingLine;
  93 
  94     /** Position of last EOL + 1. */
  95     private int linePosition;
  96 
  97     /** Type of last token added. */
  98     private TokenType last;
  99 
 100     private final boolean pauseOnFunctionBody;
 101     private boolean pauseOnNextLeftBrace;
 102 
 103     private int templateExpressionOpenBraces;
 104 
 105     private static final String JAVASCRIPT_OTHER_WHITESPACE =




 106         "\u2028" + // line separator
 107         "\u2029" + // paragraph separator






 108         "\u00a0" + // Latin-1 space
 109         "\u1680" + // Ogham space mark
 110         "\u180e" + // separator, Mongolian vowel
 111         "\u2000" + // en quad
 112         "\u2001" + // em quad
 113         "\u2002" + // en space
 114         "\u2003" + // em space
 115         "\u2004" + // three-per-em space
 116         "\u2005" + // four-per-em space
 117         "\u2006" + // six-per-em space
 118         "\u2007" + // figure space
 119         "\u2008" + // punctuation space
 120         "\u2009" + // thin space
 121         "\u200a" + // hair space
 122         "\u202f" + // narrow no-break space
 123         "\u205f" + // medium mathematical space
 124         "\u3000" + // ideographic space
 125         "\ufeff"   // byte order mark
 126         ;
 127 


 357     /**
 358      * Skip over rest of line including end of line.
 359      *
 360      * @param addEOL true if EOL token should be recorded.
 361      */
 362     private void skipLine(final boolean addEOL) {
 363         // Ignore characters.
 364         while (!isEOL(ch0) && !atEOF()) {
 365             skip(1);
 366         }
 367         // Skip over end of line.
 368         skipEOL(addEOL);
 369     }
 370 
 371     /**
 372      * Test whether a char is valid JavaScript whitespace
 373      * @param ch a char
 374      * @return true if valid JavaScript whitespace
 375      */
 376     public static boolean isJSWhitespace(final char ch) {
 377         return ch == ' '                  // space
 378             || ch >= '\t' && ch <= '\r'   // 0x09..0x0d: tab, line feed, tabulation line, ff, carriage return
 379             || ch >= 160 && isOtherJSWhitespace(ch);
 380     }
 381 
 382     private static boolean isOtherJSWhitespace(final char ch) {
 383         return JAVASCRIPT_OTHER_WHITESPACE.indexOf(ch) != -1;
 384     }
 385 
 386     /**
 387      * Test whether a char is valid JavaScript end of line
 388      * @param ch a char
 389      * @return true if valid JavaScript end of line
 390      */
 391     public static boolean isJSEOL(final char ch) {
 392         return ch == '\n'      // line feed
 393             || ch == '\r'      // carriage return (ctrl-m)
 394             || ch == '\u2028'  // line separator
 395             || ch == '\u2029'; // paragraph separator
 396     }
 397 
 398     /**
 399      * Test if char is a string delimiter, e.g. '\' or '"'.
 400      * @param ch a char
 401      * @return true if string delimiter
 402      */
 403     protected boolean isStringDelimiter(final char ch) {
 404         return ch == '\'' || ch == '"';
 405     }
 406 
 407     /**
 408      * Test if char is a template literal delimiter ('`').
 409      */
 410     private static boolean isTemplateDelimiter(final char ch) {
 411         return ch == '`';
 412     }
 413 
 414     /**
 415      * Test whether a char is valid JavaScript whitespace


< prev index next >