Mercurial > projects > ddmd
comparison dmd/Lexer.d @ 8:d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
author | dkoroskin <> |
---|---|
date | Mon, 14 Dec 2009 17:43:43 +0300 |
parents | d706d958e4e8 |
children | 544b922227c7 |
comparison
equal
deleted
inserted
replaced
7:89cc05dbdae1 | 8:d42cd5917df4 |
---|---|
1559 return c; | 1559 return c; |
1560 } | 1560 } |
1561 | 1561 |
1562 TOK wysiwygStringConstant(Token* t, int tc) | 1562 TOK wysiwygStringConstant(Token* t, int tc) |
1563 { | 1563 { |
1564 uint c; | |
1565 Loc start = loc; | |
1566 | |
1567 p++; | |
1568 stringbuffer.reset(); | |
1569 while (true) | |
1570 { | |
1571 c = *p++; | |
1572 switch (c) | |
1573 { | |
1574 case '\n': | |
1575 loc.linnum++; | |
1576 break; | |
1577 | |
1578 case '\r': | |
1579 if (*p == '\n') | |
1580 continue; // ignore | |
1581 c = '\n'; // treat EndOfLine as \n character | |
1582 loc.linnum++; | |
1583 break; | |
1584 | |
1585 case 0: | |
1586 case 0x1A: | |
1587 error("unterminated string constant starting at %s", start.toChars()); | |
1588 t.ustring = "".ptr; | |
1589 t.len = 0; | |
1590 t.postfix = 0; | |
1591 return TOKstring; | |
1592 | |
1593 case '"': | |
1594 case '`': | |
1595 if (c == tc) | |
1596 { | |
1597 t.len = stringbuffer.offset; | |
1598 stringbuffer.writeByte(0); | |
1599 char* tmp = cast(char*)GC.malloc(stringbuffer.offset); | |
1600 memcpy(tmp, stringbuffer.data, stringbuffer.offset); | |
1601 t.ustring = tmp; | |
1602 stringPostfix(t); | |
1603 return TOKstring; | |
1604 } | |
1605 break; | |
1606 | |
1607 default: | |
1608 if (c & 0x80) | |
1609 { p--; | |
1610 uint u = decodeUTF(); | |
1611 p++; | |
1612 if (u == PS || u == LS) | |
1613 loc.linnum++; | |
1614 stringbuffer.writeUTF8(u); | |
1615 continue; | |
1616 } | |
1617 break; | |
1618 } | |
1619 stringbuffer.writeByte(c); | |
1620 } | |
1621 | |
1564 assert(false); | 1622 assert(false); |
1565 } | 1623 } |
1566 | 1624 |
1567 TOK hexStringConstant(Token* t) | 1625 TOK hexStringConstant(Token* t) |
1568 { | 1626 { |
1573 TOK delimitedStringConstant(Token* t) | 1631 TOK delimitedStringConstant(Token* t) |
1574 { | 1632 { |
1575 assert(false); | 1633 assert(false); |
1576 } | 1634 } |
1577 | 1635 |
1636 /************************************** | |
1637 * Lex delimited strings: | |
1638 * q{ foo(xxx) } // " foo(xxx) " | |
1639 * q{foo(} // "foo(" | |
1640 * q{{foo}"}"} // "{foo}"}"" | |
1641 * Input: | |
1642 * p is on the q | |
1643 */ | |
1578 TOK tokenStringConstant(Token* t) | 1644 TOK tokenStringConstant(Token* t) |
1579 { | 1645 { |
1580 assert(false); | 1646 uint nest = 1; |
1647 Loc start = loc; | |
1648 ubyte* pstart = ++p; | |
1649 | |
1650 while (true) | |
1651 { | |
1652 Token tok; | |
1653 | |
1654 scan(&tok); | |
1655 switch (tok.value) | |
1656 { | |
1657 case TOKlcurly: | |
1658 nest++; | |
1659 continue; | |
1660 | |
1661 case TOKrcurly: | |
1662 if (--nest == 0) | |
1663 goto Ldone; | |
1664 continue; | |
1665 | |
1666 case TOKeof: | |
1667 goto Lerror; | |
1668 | |
1669 default: | |
1670 continue; | |
1671 } | |
1672 } | |
1673 | |
1674 Ldone: | |
1675 t.len = p - 1 - pstart; | |
1676 char* tmp = cast(char*)GC.malloc(t.len + 1); | |
1677 memcpy(tmp, pstart, t.len); | |
1678 tmp[t.len] = 0; | |
1679 t.ustring = tmp; | |
1680 stringPostfix(t); | |
1681 return TOKstring; | |
1682 | |
1683 Lerror: | |
1684 error("unterminated token string constant starting at %s", start.toChars()); | |
1685 t.ustring = "".ptr; | |
1686 t.len = 0; | |
1687 t.postfix = 0; | |
1688 return TOKstring; | |
1581 } | 1689 } |
1582 } | 1690 } |
1583 TOK escapeStringConstant(Token* t, int wide) | 1691 TOK escapeStringConstant(Token* t, int wide) |
1584 { | 1692 { |
1585 uint c; | 1693 uint c; |