| ... | @@ -1906,47 +1906,66 @@ const B = error{Two}; | ... | @@ -1906,47 +1906,66 @@ const B = error{Two}; |
| 1906 | {#code|ambiguous_precedence_orelse.zig#} | 1906 | {#code|ambiguous_precedence_orelse.zig#} |
| 1907 | | 1907 | |
| 1908 | <p> | 1908 | <p> |
| 1909 | Simplified operator precedence tables are provided below, each tailored to a general group of | 1909 | There is a set of operators (prefix operators, suffix operators, etc) that have unambiguously |
| 1910 | operators. For all of the groups shown below, the operators that have higher precedence are | 1910 | higher precedence than all other operators. That set of operators has the following precedence table: |
| 1911 | the same, and themselves have the following precedence table: | | |
| 1912 | </p> | 1911 | </p> |
| 1913 | | 1912 | |
| 1914 | <pre>{#syntax#}x() x[] x.y x.* x.? | 1913 | <pre>{#syntax#}x() x[] x.y x.* x.? |
| 1915 | a!b | 1914 | a!b |
| 1916 | x{} | 1915 | x{} |
| 1917 | !x -x -%x ~x &x ?x try{#endsyntax#}</pre> | 1916 | !x -x -%x ~x &x ?x try |
| | 1917 | // lower precedence operators omitted{#endsyntax#}</pre> |
| 1918 | | 1918 | |
| 1919 | <p> | 1919 | <p> |
| 1920 | For the tables below, the operators that have ambiguous precedence or semantic errors with the | 1920 | For the other operators, simplified operator precedence tables are provided below, each containing only |
| 1921 | given operators have been omitted, as have operators with higher precedence. | 1921 | the information that you'll need to know when reading/writing code that uses that particular category of operators. |
| 1922 | The operators colored <span style="color: #C54675;">red</span> and | 1922 | The operators that have ambiguous precedence or semantic errors with the relevant operators have been omitted, |
| 1923 | <span style="color: #419AFF;">blue</span> have ambiguous precedence with the other operators | 1923 | as have the operators with higher precedence (those shown above). |
| 1924 | on the same line. Those colored <span style="color: #C54675;">red</span> also have ambiguous | 1924 | </p> |
| | 1925 | |
| | 1926 | <details style="display:none;" id="ambig-details"> |
| | 1927 | <summary style="cursor:pointer;">Toggle operator precedence ambiguity details</summary> |
| | 1928 | <p> |
| | 1929 | The operators that look <span class="ambig-chain">like this</span> have ambiguous precedence with the other operators |
| | 1930 | on the same line. Those that look <span class="ambig-nonchain">like this</span> also have ambiguous |
| 1925 | precedence with themselves (they cannot be chained). | 1931 | precedence with themselves (they cannot be chained). |
| 1926 | </p> | 1932 | </p> |
| | 1933 | </details> |
| | 1934 | |
| | 1935 | <script> |
| | 1936 | let ambig_details = document.getElementById("ambig-details"); |
| | 1937 | ambig_details.style.display = 'block'; |
| | 1938 | ambig_details.addEventListener("toggle", (event) => { |
| | 1939 | document.querySelectorAll('.ambig-chain').forEach(e => { e.classList.toggle('tok-number'); }); |
| | 1940 | document.querySelectorAll('.ambig-nonchain').forEach(e => { |
| | 1941 | e.classList.toggle('tok-number'); |
| | 1942 | e.style.borderBottom = ambig_details.open ? '1px dotted' : ''; |
| | 1943 | }); |
| | 1944 | }); |
| | 1945 | </script> |
| 1927 | | 1946 | |
| 1928 | <p> | 1947 | <p> |
| 1929 | For arithmetic operators: | 1948 | For arithmetic operators: |
| 1930 | </p> | 1949 | </p> |
| 1931 | | 1950 | |
| 1932 | <pre><code>* / *% *| <span style="color: #C54675;">%</span> | 1951 | <pre><code>* / *% *| <span class="ambig-nonchain">%</span> |
| 1933 | + - +% -% +| -| | 1952 | + - +% -% +| -| |
| 1934 | <span style="color: #C54675;">== != &lt; > &lt;= >=</span> | 1953 | <span class="ambig-nonchain">==</span> <span class="ambig-nonchain">!=</span> <span class="ambig-nonchain">&lt;</span> <span class="ambig-nonchain">></span> <span class="ambig-nonchain">&lt;=</span> <span class="ambig-nonchain">>=</span> |
| 1935 | <span style="color: #419AFF;">and or</span></code></pre> | 1954 | <span class="ambig-chain">and or</span></code></pre> |
| 1936 | | 1955 | |
| 1937 | <p> | 1956 | <p> |
| 1938 | For bitwise operators: | 1957 | For bitwise operators: |
| 1939 | </p> | 1958 | </p> |
| 1940 | | 1959 | |
| 1941 | <pre><code><span style="color: #C54675;">&lt;&lt; &lt;&lt;| >></span> <span style="color: #419AFF;">& ^ |</span> | 1960 | <pre><code><span class="ambig-nonchain">&lt;&lt;</span> <span class="ambig-nonchain">&lt;&lt;|</span> <span class="ambig-nonchain">>></span> <span class="ambig-chain">& ^ |</span> |
| 1942 | <span style="color: #C54675;">== != &lt; > &lt;= >=</span> | 1961 | <span class="ambig-nonchain">==</span> <span class="ambig-nonchain">!=</span> <span class="ambig-nonchain">&lt;</span> <span class="ambig-nonchain">></span> <span class="ambig-nonchain">&lt;=</span> <span class="ambig-nonchain">>=</span> |
| 1943 | <span style="color: #419AFF;">and or</span></code></pre> | 1962 | <span class="ambig-chain">and or</span></code></pre> |
| 1944 | | 1963 | |
| 1945 | <p> | 1964 | <p> |
| 1946 | For null and error recovery operators: | 1965 | For null and error recovery operators: |
| 1947 | </p> | 1966 | </p> |
| 1948 | | 1967 | |
| 1949 | <pre><code><span style="color: #419AFF;">catch orelse</span></code></pre> | 1968 | <pre><code><span class="ambig-chain">catch orelse</span></code></pre> |
| 1950 | | 1969 | |
| 1951 | <p> | 1970 | <p> |
| 1952 | For error set operators: | 1971 | For error set operators: |