This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Commit 6945a72
Patterns: initial parser support.
The parser now supports the following subset of the parser grammar:
- logical-or and logical-and patterns (called "binary patterns" to
reflect analyzer nomenclature)
- extractor patterns
- cast patterns
- list patterns
- map patterns
- null-assert patterns
- null-check patterns
- variable patterns where the variable is preceded by `var`, `final`,
<type>, or `final <type>`
- if-case statements (and if-case within collections); without guards
- record patterns
- parenthesized patterns
- constant patterns where the constant is a plain expression not
beginning with `const` (booleanLiteral, nullLiteral, numericLiteral,
stringLiteral, identifier, or qualifiedName).
- relational patterns
- patterns in switch statements
- integration with the analyzer's AstBuilder class
Not implemented yet:
- constant patterns beginning with `const`
- variable patterns where the variable is a single identifier (note:
this means that `_` is currently interpreted as a constant pattern
rather than a "wildcard" variable pattern)
- guards (a.k.a. "when clauses")
- switch expressions
- pattern variable declarations
- patterns appearing in "for loop parts"
- pattern assignment
- several error checking and error recovery scenarios (see TODO
comments)
- integration with the front_end's BodyBuilder class
- front_end style parser tests (currently the feature is tested using
analyzer unit tests only)
Note that in patterns, `as` binds has higher precedence than `&` and
`|`, whereas in expressions, `&` and `|` have higher precedence than
`as`. To reflect this, a new precedence has been added,
CAST_PATTERN_PRECEDENCE.
To reduce the risk to users during parser development, the parser
currently only attempts to parse patterns when instructed to do so
(i.e. when the language feature is enabled). In the long term, I
intend to change the parser so that it always attempts to parse
patterns, and it is the responsibility of its listener to report
errors if patterns are used without enabling the language feature.
Change-Id: I360b535d2a6ebd35a0ee4d066b06e3ae8e3121ef
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/261020
Reviewed-by: Konstantin Shcheglov <[email protected]>
Reviewed-by: Jens Johansen <[email protected]>
Commit-Queue: Paul Berry <[email protected]>1 parent d7e130e commit 6945a72
File tree
22 files changed
+4183
-57
lines changed- pkg
- analyzer
- lib/src
- dart/ast
- fasta
- generated
- test_utilities
- test/generated
- front_end
- lib/src/fasta
- kernel
- macro
- util
- test
- fasta/parser
22 files changed
+4183
-57
lines changedLines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
| 49 | + | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| |||
Lines changed: 84 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
38 | 43 | | |
39 | 44 | | |
40 | 45 | | |
| |||
522 | 527 | | |
523 | 528 | | |
524 | 529 | | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
525 | 536 | | |
526 | 537 | | |
527 | 538 | | |
| |||
539 | 550 | | |
540 | 551 | | |
541 | 552 | | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
542 | 558 | | |
543 | 559 | | |
544 | 560 | | |
| |||
1254 | 1270 | | |
1255 | 1271 | | |
1256 | 1272 | | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
1257 | 1278 | | |
1258 | 1279 | | |
1259 | 1280 | | |
| |||
1561 | 1582 | | |
1562 | 1583 | | |
1563 | 1584 | | |
| 1585 | + | |
| 1586 | + | |
| 1587 | + | |
| 1588 | + | |
| 1589 | + | |
1564 | 1590 | | |
1565 | 1591 | | |
1566 | 1592 | | |
1567 | 1593 | | |
1568 | 1594 | | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
1569 | 1600 | | |
1570 | 1601 | | |
1571 | 1602 | | |
| |||
1585 | 1616 | | |
1586 | 1617 | | |
1587 | 1618 | | |
| 1619 | + | |
| 1620 | + | |
| 1621 | + | |
| 1622 | + | |
| 1623 | + | |
1588 | 1624 | | |
1589 | 1625 | | |
1590 | 1626 | | |
| |||
1600 | 1636 | | |
1601 | 1637 | | |
1602 | 1638 | | |
| 1639 | + | |
| 1640 | + | |
| 1641 | + | |
| 1642 | + | |
| 1643 | + | |
1603 | 1644 | | |
1604 | 1645 | | |
1605 | 1646 | | |
| |||
1680 | 1721 | | |
1681 | 1722 | | |
1682 | 1723 | | |
| 1724 | + | |
| 1725 | + | |
| 1726 | + | |
| 1727 | + | |
| 1728 | + | |
| 1729 | + | |
| 1730 | + | |
| 1731 | + | |
| 1732 | + | |
| 1733 | + | |
| 1734 | + | |
| 1735 | + | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
1683 | 1739 | | |
1684 | 1740 | | |
1685 | 1741 | | |
| |||
1716 | 1772 | | |
1717 | 1773 | | |
1718 | 1774 | | |
1719 | | - | |
1720 | | - | |
| 1775 | + | |
| 1776 | + | |
1721 | 1777 | | |
1722 | 1778 | | |
1723 | 1779 | | |
| |||
1730 | 1786 | | |
1731 | 1787 | | |
1732 | 1788 | | |
| 1789 | + | |
| 1790 | + | |
| 1791 | + | |
| 1792 | + | |
| 1793 | + | |
1733 | 1794 | | |
1734 | 1795 | | |
1735 | 1796 | | |
1736 | 1797 | | |
1737 | 1798 | | |
| 1799 | + | |
| 1800 | + | |
| 1801 | + | |
| 1802 | + | |
| 1803 | + | |
| 1804 | + | |
| 1805 | + | |
| 1806 | + | |
| 1807 | + | |
| 1808 | + | |
| 1809 | + | |
| 1810 | + | |
| 1811 | + | |
| 1812 | + | |
| 1813 | + | |
| 1814 | + | |
1738 | 1815 | | |
1739 | 1816 | | |
1740 | 1817 | | |
| |||
1839 | 1916 | | |
1840 | 1917 | | |
1841 | 1918 | | |
| 1919 | + | |
| 1920 | + | |
| 1921 | + | |
| 1922 | + | |
| 1923 | + | |
1842 | 1924 | | |
1843 | 1925 | | |
1844 | 1926 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
55 | 62 | | |
56 | 63 | | |
57 | 64 | | |
| |||
976 | 983 | | |
977 | 984 | | |
978 | 985 | | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
979 | 992 | | |
980 | 993 | | |
981 | 994 | | |
| |||
1371 | 1384 | | |
1372 | 1385 | | |
1373 | 1386 | | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
1374 | 1406 | | |
1375 | 1407 | | |
1376 | 1408 | | |
| |||
1518 | 1550 | | |
1519 | 1551 | | |
1520 | 1552 | | |
| 1553 | + | |
| 1554 | + | |
| 1555 | + | |
| 1556 | + | |
| 1557 | + | |
| 1558 | + | |
1521 | 1559 | | |
1522 | 1560 | | |
1523 | 1561 | | |
| |||
1532 | 1570 | | |
1533 | 1571 | | |
1534 | 1572 | | |
| 1573 | + | |
| 1574 | + | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
1535 | 1582 | | |
1536 | 1583 | | |
1537 | 1584 | | |
| |||
1706 | 1753 | | |
1707 | 1754 | | |
1708 | 1755 | | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
| 1760 | + | |
| 1761 | + | |
1709 | 1762 | | |
1710 | 1763 | | |
1711 | 1764 | | |
| |||
1718 | 1771 | | |
1719 | 1772 | | |
1720 | 1773 | | |
| 1774 | + | |
| 1775 | + | |
| 1776 | + | |
| 1777 | + | |
| 1778 | + | |
| 1779 | + | |
1721 | 1780 | | |
1722 | 1781 | | |
1723 | 1782 | | |
| |||
1730 | 1789 | | |
1731 | 1790 | | |
1732 | 1791 | | |
| 1792 | + | |
| 1793 | + | |
| 1794 | + | |
| 1795 | + | |
| 1796 | + | |
| 1797 | + | |
1733 | 1798 | | |
1734 | 1799 | | |
1735 | 1800 | | |
| |||
1784 | 1849 | | |
1785 | 1850 | | |
1786 | 1851 | | |
1787 | | - | |
| 1852 | + | |
1788 | 1853 | | |
1789 | 1854 | | |
1790 | 1855 | | |
| |||
1797 | 1862 | | |
1798 | 1863 | | |
1799 | 1864 | | |
| 1865 | + | |
| 1866 | + | |
| 1867 | + | |
| 1868 | + | |
| 1869 | + | |
| 1870 | + | |
1800 | 1871 | | |
1801 | 1872 | | |
1802 | 1873 | | |
1803 | 1874 | | |
1804 | 1875 | | |
1805 | 1876 | | |
1806 | 1877 | | |
| 1878 | + | |
| 1879 | + | |
| 1880 | + | |
| 1881 | + | |
| 1882 | + | |
| 1883 | + | |
| 1884 | + | |
| 1885 | + | |
| 1886 | + | |
| 1887 | + | |
| 1888 | + | |
| 1889 | + | |
| 1890 | + | |
| 1891 | + | |
| 1892 | + | |
| 1893 | + | |
| 1894 | + | |
| 1895 | + | |
| 1896 | + | |
| 1897 | + | |
| 1898 | + | |
1807 | 1899 | | |
1808 | 1900 | | |
1809 | 1901 | | |
| |||
1851 | 1943 | | |
1852 | 1944 | | |
1853 | 1945 | | |
| 1946 | + | |
| 1947 | + | |
| 1948 | + | |
| 1949 | + | |
| 1950 | + | |
| 1951 | + | |
1854 | 1952 | | |
1855 | 1953 | | |
1856 | 1954 | | |
| |||
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
147 | | - | |
| 147 | + | |
| 148 | + | |
148 | 149 | | |
149 | 150 | | |
150 | 151 | | |
| |||
0 commit comments