authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2026-10-16 00:03:55-07:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-10-22 12:21:43+02:00
log29f793b3bf0316efba5085d9c3f4c9ca98e1b2cf
tree461314d371e86f6308e527309421c5f330636b45
parenta2ce4c1bfbf28d1bd2f0b783ee6bef083327e98f

langref: another pass at the precedence tables section


1 files changed, 35 insertions(+), 16 deletions(-)

doc/langref.html.in+35-16
...@@ -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#}
19071907
1908 <p>1908 <p>
1909 Simplified operator precedence tables are provided below, each tailored to a general group of1909 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 are1910 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>
19131912
1914 <pre>{#syntax#}x() x[] x.y x.* x.?1913 <pre>{#syntax#}x() x[] x.y x.* x.?
1915a!b1914a!b
1916x{}1915x{}
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>
19181918
1919 <p>1919 <p>
1920 For the tables below, the operators that have ambiguous precedence or semantic errors with the1920 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> and1922 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 operators1923 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 ambiguous1924 </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>
19271946
1928 <p>1947 <p>
1929 For arithmetic operators:1948 For arithmetic operators:
1930 </p>1949 </p>
19311950
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>
19361955
1937 <p>1956 <p>
1938 For bitwise operators:1957 For bitwise operators:
1939 </p>1958 </p>
19401959
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>
19441963
1945 <p>1964 <p>
1946 For null and error recovery operators:1965 For null and error recovery operators:
1947 </p>1966 </p>
19481967
1949 <pre><code><span style="color: #419AFF;">catch orelse</span></code></pre>1968 <pre><code><span class="ambig-chain">catch orelse</span></code></pre>
19501969
1951 <p>1970 <p>
1952 For error set operators:1971 For error set operators: