Changeset 11879 in webkit for trunk/JavaScriptCore/kjs/lexer.cpp
- Timestamp:
- Jan 4, 2006, 1:44:25 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/lexer.cpp
r10933 r11879 42 42 #include <unicode/uchar.h> 43 43 44 static bool isDecimalDigit(unsigned short c); 45 44 46 // we can't specify the namespace in yacc's C output, so do it here 45 47 using namespace KJS; … … 134 136 do { 135 137 if (pos >= length) { 136 137 138 next3 = 0; 139 break; 138 140 } 139 141 next3 = code[pos++].uc; … … 215 217 state = InString; 216 218 stringType = current; 217 } else if (isIdent Letter(current)) {219 } else if (isIdentStart(current)) { 218 220 record16(current); 219 state = InIdentifier; 221 state = InIdentifierOrKeyword; 222 } else if (current == '\\') { 223 state = InIdentifierUnicodeEscapeStart; 220 224 } else if (current == '0') { 221 225 record8(current); … … 306 310 break; 307 311 case InUnicodeEscape: 308 if (isHexDigit(current) && isHexDigit(next1) && 309 isHexDigit(next2) && isHexDigit(next3)) { 312 if (isHexDigit(current) && isHexDigit(next1) && isHexDigit(next2) && isHexDigit(next3)) { 310 313 record16(convertUnicode(current, next1, next2, next3)); 311 314 shift(3); … … 342 345 } 343 346 break; 347 case InIdentifierOrKeyword: 344 348 case InIdentifier: 345 if (isIdent Letter(current) || isDecimalDigit(current)) {349 if (isIdentPart(current)) 346 350 record16(current); 347 break; 348 } 349 setDone(Identifier); 351 else if (current == '\\') 352 state = InIdentifierUnicodeEscapeStart; 353 else 354 setDone(state == InIdentifierOrKeyword ? IdentifierOrKeyword : Identifier); 350 355 break; 351 356 case InNum0: … … 421 426 } else 422 427 setDone(Number); 428 break; 429 case InIdentifierUnicodeEscapeStart: 430 if (current == 'u') 431 state = InIdentifierUnicodeEscape; 432 else 433 setDone(Bad); 434 break; 435 case InIdentifierUnicodeEscape: 436 if (isHexDigit(current) && isHexDigit(next1) && isHexDigit(next2) && isHexDigit(next3)) { 437 record16(convertUnicode(current, next1, next2, next3)); 438 shift(3); 439 state = InIdentifier; 440 } else { 441 setDone(Bad); 442 } 423 443 break; 424 444 default: … … 436 456 437 457 // no identifiers allowed directly after numeric literal, e.g. "3in" is bad 438 if ((state == Number || state == Octal || state == Hex) 439 && isIdentLetter(current)) 458 if ((state == Number || state == Octal || state == Hex) && isIdentStart(current)) 440 459 state = Bad; 441 460 … … 507 526 } 508 527 break; 528 case IdentifierOrKeyword: 529 if ((token = Lookup::find(&mainTable, buffer16, pos16)) < 0) { 509 530 case Identifier: 510 if ((token = Lookup::find(&mainTable, buffer16, pos16)) < 0) {511 531 // Lookup for keyword failed, means this is an identifier 512 532 // Apply anonymous-function hack below (eat the identifier) … … 553 573 bool Lexer::isWhiteSpace() const 554 574 { 555 return (current == ' ' || current == '\t' || 556 current == 0x0b || current == 0x0c || current == 0xa0); 575 return (current == '\t' || current == 0x0b || current == 0x0c || u_charType(current) == U_SPACE_SEPARATOR); 557 576 } 558 577 … … 565 584 else if (lf) 566 585 skipCR = true; 567 return cr || lf; 568 } 569 570 bool Lexer::isIdentLetter(unsigned short c) 571 { 572 /* TODO: allow other legitimate unicode chars */ 573 return (c >= 'a' && c <= 'z' || 574 c >= 'A' && c <= 'Z' || 575 c == '$' || c == '_'); 576 } 577 578 bool Lexer::isDecimalDigit(unsigned short c) 586 return cr || lf || current == 0x2028 || current == 0x2029; 587 } 588 589 bool Lexer::isIdentStart(unsigned short c) 590 { 591 return (U_GET_GC_MASK(c) & (U_GC_L_MASK | U_GC_NL_MASK)) || c == '$' || c == '_'; 592 } 593 594 bool Lexer::isIdentPart(unsigned short c) 595 { 596 return (U_GET_GC_MASK(c) & (U_GC_L_MASK | U_GC_NL_MASK | U_GC_MN_MASK | U_GC_MC_MASK | U_GC_ND_MASK | U_GC_PC_MASK)) || c == '$' || c == '_'; 597 } 598 599 static bool isDecimalDigit(unsigned short c) 579 600 { 580 601 return (c >= '0' && c <= '9'); … … 823 844 } 824 845 825 while (isIdent Letter(current)) {846 while (isIdentPart(current)) { 826 847 record16(current); 827 848 shift(1);
Note:
See TracChangeset
for help on using the changeset viewer.