From 09affe23f2e4977a1225eaf27b2abf7fa6b4715f Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Sun, 19 Jul 2020 14:32:38 -0400 Subject: Handle bracket/parenthesis nesting in inline links --- docs/spec/literal.html | 2 +- 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 @@ mantissa = "¯"? ( "∞" | "π" | digit+ ( "." digit+ )? ) digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" -

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 indicates infinity and π indicates the ratio pi) of a circle's circumference to its diameter (or, for modern mathematicians, the smallest positive real number at which the function {0j1×𝕩} attains a real part of 0). The high minus symbol ¯ indicates that the number containing it is to be negated.

+

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 indicates infinity and π indicates the ratio pi of a circle's circumference to its diameter (or, for modern mathematicians, the smallest positive real number at which the function {0j1×𝕩} attains a real part of 0). The high minus symbol ¯ indicates that the number containing it is to be negated.

When an exponent is provided (with e or E), the corresponding mantissa is multiplied by ten to that power, giving the value mantissa×10exponent. If a second component is present (using i or I), that component's value is multiplied by the imaginary unit i and added to the first component; otherwise the value is the first component's value without modification. If complex numbers are not supported, then i should not be allowed in numeric literals, even when followed by 0.

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.

diff --git a/md.bqn b/md.bqn index a15c19ad..15a4f254 100644 --- a/md.bqn +++ b/md.bqn @@ -261,12 +261,18 @@ Markdown ← {𝕊𝕩:1𝕊𝕩; extensions𝕊𝕩: ReplaceMDSub ← { ¯2 ("README"•_r_"index"∘↓∾"html"˜)⍟(("md"≡↑)∧':'∧´∘≠⊢) 𝕩 } ReplaceMD ← { ReplaceMDSub⌾((⊑𝕩⊐"#")⊸↑) 𝕩 } ProcLink ← { ∾⟨"",𝕨,""⟩ } - brak ← /∘(unused ∧ 𝕩⊸=)¨ "]()[" - link ← (∊/⊣)´ 0‿¯1 + 2 ↑ brak - chains ← (⍋˜ ⊏ ⊢∾(≠𝕩)˜)` ¯1 ⌽ ( (∧´ (∊ ∧ <⟜(≠𝕩))¨ 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 ⊔ 𝕩 -- cgit v1.2.3