diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2020-07-19 14:32:38 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2020-07-19 14:38:35 -0400 |
| commit | 09affe23f2e4977a1225eaf27b2abf7fa6b4715f (patch) | |
| tree | 8412984c7c8d10ab1e9944940f271c481dbfcc2b | |
| parent | 8b2806ea128128e0ff411b71a973909c6f9a022d (diff) | |
Handle bracket/parenthesis nesting in inline links
| -rw-r--r-- | docs/spec/literal.html | 2 | ||||
| -rw-r--r-- | md.bqn | 18 |
2 files changed, 13 insertions, 7 deletions
diff --git a/docs/spec/literal.html b/docs/spec/literal.html index 1a8e3406..8cac38c5 100644 --- a/docs/spec/literal.html +++ b/docs/spec/literal.html @@ -10,7 +10,7 @@ <span class='Value'>mantissa</span> <span class='Function'>=</span> <span class='String'>"¯"</span><span class='Value'>?</span> <span class='Paren'>(</span> <span class='String'>"∞"</span> <span class='Function'>|</span> <span class='String'>"π"</span> <span class='Function'>|</span> <span class='Value'>digit</span><span class='Function'>+</span> <span class='Paren'>(</span> <span class='String'>"."</span> <span class='Value'>digit</span><span class='Function'>+</span> <span class='Paren'>)</span><span class='Value'>?</span> <span class='Paren'>)</span> <span class='Value'>digit</span> <span class='Function'>=</span> <span class='String'>"0"</span> <span class='Function'>|</span> <span class='String'>"1"</span> <span class='Function'>|</span> <span class='String'>"2"</span> <span class='Function'>|</span> <span class='String'>"3"</span> <span class='Function'>|</span> <span class='String'>"4"</span> <span class='Function'>|</span> <span class='String'>"5"</span> <span class='Function'>|</span> <span class='String'>"6"</span> <span class='Function'>|</span> <span class='String'>"7"</span> <span class='Function'>|</span> <span class='String'>"8"</span> <span class='Function'>|</span> <span class='String'>"9"</span> </pre> -<p>The digits or arabic numerals correspond to the numbers from 0 to 9 in the conventional way (also, each corresponds to its code point value minus 48). A sequence of digits gives a natural number by evaluating it in base 10: the number is 0 for an empty sequence, and otherwise the last digit's numerical value plus ten times the number obtained from the remaining digits. The symbol <code><span class='Number'>∞</span></code> indicates infinity and <code><span class='Number'>π</span></code> indicates the ratio <a href="https://en.wikipedia.org/wiki/Pi_(mathematics">pi</a>) of a circle's circumference to its diameter (or, for modern mathematicians, the smallest positive real number at which the function <code><span class='Brace'>{</span><span class='Function'>⋆</span><span class='Number'>0j1</span><span class='Function'>×</span><span class='Value'>𝕩</span><span class='Brace'>}</span></code> attains a real part of 0). The <a href="https://aplwiki.com/wiki/High_minus">high minus</a> symbol <code><span class='Number'>¯</span></code> indicates that the number containing it is to be negated.</p> +<p>The digits or arabic numerals correspond to the numbers from 0 to 9 in the conventional way (also, each corresponds to its code point value minus 48). A sequence of digits gives a natural number by evaluating it in base 10: the number is 0 for an empty sequence, and otherwise the last digit's numerical value plus ten times the number obtained from the remaining digits. The symbol <code><span class='Number'>∞</span></code> indicates infinity and <code><span class='Number'>π</span></code> indicates the ratio <a href="https://en.wikipedia.org/wiki/Pi_(mathematics)">pi</a> of a circle's circumference to its diameter (or, for modern mathematicians, the smallest positive real number at which the function <code><span class='Brace'>{</span><span class='Function'>⋆</span><span class='Number'>0j1</span><span class='Function'>×</span><span class='Value'>𝕩</span><span class='Brace'>}</span></code> attains a real part of 0). The <a href="https://aplwiki.com/wiki/High_minus">high minus</a> symbol <code><span class='Number'>¯</span></code> indicates that the number containing it is to be negated.</p> <p>When an exponent is provided (with <code><span class='Value'>e</span></code> or <code><span class='Function'>E</span></code>), the corresponding mantissa is multiplied by ten to that power, giving the value <code><span class='Value'>mantissa</span><span class='Function'>×</span><span class='Number'>10</span><span class='Function'>⋆</span><span class='Value'>exponent</span></code>. If a second component is present (using <code><span class='Value'>i</span></code> or <code><span class='Function'>I</span></code>), that component's value is multiplied by the <a href="https://en.wikipedia.org/wiki/Imaginary_unit">imaginary unit</a> <em>i</em> and added to the first component; otherwise the value is the first component's value without modification. If complex numbers are not supported, then <code><span class='Value'>i</span></code> should not be allowed in numeric literals, even when followed by 0.</p> <p>The above specification describes exactly a complex number with extended real components. To obtain a BQN number, each component is rounded to its nearest representative by the rules of the number system used: for IEEE 754, smallest distance, with ties rounding to the option with even mantissa.</p> @@ -261,12 +261,18 @@ Markdown ← {𝕊𝕩:1𝕊𝕩; extensions𝕊𝕩: ReplaceMDSub ← { ¯2 ("README"•_r_"index"∘↓∾"html"˜)⍟(("md"≡↑)∧':'∧´∘≠⊢) 𝕩 } ReplaceMD ← { ReplaceMDSub⌾((⊑𝕩⊐"#")⊸↑) 𝕩 } ProcLink ← { ∾⟨"<a href=""",(ReplaceMD 𝕩),""">",𝕨,"</a>"⟩ } - brak ← /∘(unused ∧ 𝕩⊸=)¨ "]()[" - link ← (∊/⊣)´ 0‿¯1 + 2 ↑ brak - chains ← (⍋˜ ⊏ ⊢∾(≠𝕩)˜)` ¯1 ⌽ (<link) ∾ 2 ↓ brak - chains ↩ > (∧´ (∊ ∧ <⟜(≠𝕩))¨ 1 ↓ chains)⊸/¨ chains - linkPos ← 0 ⊏ chains - lInds ← 1‿0‿2‿0⊸+˘ (⥊2⊸↕)˘ ⍉ chains + # Find matched-depth [] and () pairs, then join adjacent ones + brak ← (unused ∧ 𝕩⊸=)¨ 2‿2⥊"[]()" + depth ← (+`-0⌊⊢)∘(-´)˘ brak + FindPairs ← ⟨⟩‿2 ⥊ 1⊸⊏ /˜ 2⊸⊏ ≠ (¯∞⊸Shl⊸=(∧+⊢)∞⊸Shr⊸=)∘⊏ + pairs ← depth <∘(FindPairs⍟(0<≠))∘⍉∘(∧(⊏˜≍˘⊢)⟜∾∾˘·/≠¨∘⊢)˘ /¨brak + JoinPairs ← { + e←1+1⊏˘𝕨 ⋄ b←⊏˘𝕩 ⋄ m←(≠b)>i←b⊐e + (m/𝕨) ∾˘ (m/i)⊏𝕩 + } + lInds ← ∧○(0<≠)◶(0‿4⥊0)‿JoinPairs´ pairs + linkPos ← ⊏˘ lInds + lInds +⎉1↩ 1‿0‿1‿0 unused ∧↩ include ∧↩ ¬ ≠` I2M ⥊ (¯1‿1+0‿3⊸⊏)˘ lInds linkGroup ← 1 -˜ (1‿0⥊˜≢)⊸(/ (⊣×>)○(+`I2M) ¬⊸/) ⥊lInds links ← <∘ProcLink´˘ (lInds≠⊸∾2) (⊣⥊×´⊸↑) linkGroup ⊔ 𝕩 |
