From 55dd46871b8b4d7e1fdd44fc819cc649edade6a8 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Sun, 13 Sep 2020 15:20:47 -0400 Subject: =?UTF-8?q?Add=20dyadic=20=C2=AB=C2=BB=20to=20dzref?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dzref | 5 ++++- md.bqn | 32 ++++++++++++++------------------ 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/dzref b/dzref index 6fcc5f5f..a8e47626 100755 --- a/dzref +++ b/dzref @@ -1,6 +1,9 @@ #!/usr/bin/env dbqn impl ← " +» ← {!𝕨1⊸⌊⊸≤○=𝕩 ⋄ ( ≠𝕩)↑𝕨∾𝕩} +« ← {!𝕨1⊸⌊⊸≤○=𝕩 ⋄ (-≠𝕩)↑𝕩∾𝕨} + #⌜ # LAYER 4: Operators @@ -89,7 +92,7 @@ raw ← {⍎} X ← {F:≤4} {v: chrs←⟨ - "∾↕⊐⊒∊⍷" + "»«∾↕⊐⊒∊⍷" "" "⚇" ⟩ diff --git a/md.bqn b/md.bqn index 62c67555..3fdd087e 100644 --- a/md.bqn +++ b/md.bqn @@ -25,10 +25,6 @@ # Linefeed lf ← @+10 -# Shift cells 𝕨 into array 𝕩, maintaining its total length -Shl ← ≠∘⊢ ↑ ∾ # From the left -Shr ← -∘≠∘⊢ ↑ ∾˜ # From the right - # Index of first zero, or number of leading 1s in a boolean list Lead ← ⊑ ⊐⟜0 @@ -49,7 +45,7 @@ CountRuns ← { (1+↕≠𝕩) (⊣ - ⌈`∘×) ¬𝕩 } # is, preceded by an odd number of backslashes (since a backslash can # escape another backslash). IsEscaped ← { - 0 Shl 2 | CountRuns 𝕩 = '\' + 0 » 2 | CountRuns 𝕩 = '\' } # Remove leading (∧`) and trailing (∧`⌾⌽) spaces @@ -224,7 +220,7 @@ Markdown ← {filename𝕊𝕩: 𝕩 ↓˜↩ 𝕨+1 trsp ← ∧`⌾⌽ 𝕩=' ' tail ← ∧`⌾⌽ trsp∨𝕩='#' # Mask of trailing hashes - f ← tail < 0 Shr tail # Character before trailing hashes + f ← tail < 0 « tail # Character before trailing hashes 𝕩 /˜↩ ¬ f (⊑⟨"\"," ",""⟩⊐ 0 Shl '\' = 𝕩 # Non-escaped bars + r ← b > 0 » '\' = 𝕩 # Non-escaped bars 1 -˜ (¬r∨1⌽b>r) × o + +` r } ProcTable ← { @@ -315,12 +311,12 @@ Markdown ← {filename𝕊𝕩: # Code spans tick ← 𝕩 = '`' - tend ← / (⊢ > 0⊸Shr) tick + tend ← / (⊢ > 0⊸«) tick tcount ← CountRuns tick # 𝕨 are tick lengths and 𝕩 are positions, both sorted by length MatchTicks ← { # Tick runs other than the last of each length - notLast ← (⊢=0⊸Shr) 𝕨 + notLast ← (⊢=0⊸«) 𝕨 # Ticks preceded by backslashes can't start code blocks, but can # end them. This approach is wrong for multiple ticks with a # leading backslash in front, which are excluded but should just @@ -352,7 +348,7 @@ Markdown ← {filename𝕊𝕩: # Find matched-depth [] and () pairs, then join adjacent ones brak ← (unused ∧ 𝕩⊸=)¨ 2‿2⥊"[]()" depth ← (+`-0⌊⊢)∘(-´)˘ brak - FindPairs ← ∘‿2 ⥊ 1⊸⊏ /˜ 2⊸⊏ ≠ (¯∞⊸Shl⊸=(∧+⊢)∞⊸Shr⊸=)∘⊏ + FindPairs ← ∘‿2 ⥊ 1⊸⊏ /˜ 2⊸⊏ ≠ (¯∞⊸»⊸=(∧+⊢)∞⊸«⊸=)∘⊏ pairs ← depth <∘(FindPairs⍟(0<≠))∘⍉∘(∧(⊏˜≍˘⊢)⟜∾∾˘·/≠¨∘⊢)˘ /¨brak JoinPairs ← { e←1+1⊏˘𝕨 ⋄ b←⊏˘𝕩 ⋄ m←(≠b)>i←b⊐e @@ -367,7 +363,7 @@ Markdown ← {filename𝕊𝕩: # Emphasis (still rudimentary) eMasks ← (unused ∧ 𝕩⊸=)¨ "*_" - eMasks ↩ 0⊸Shr⊸∧¨⊸(⊣∾˜0⊸Shl⊸∨⊸<¨) eMasks + eMasks ↩ 0⊸«⊸∧¨⊸(⊣∾˜0⊸»⊸∨⊸<¨) eMasks eInds ← (⊢-2|⊢)∘≠⊸↑∘/¨ eMasks include ∧↩ ¬ I2M ∧ ∾ eInds∾1+2↓eInds eInds ∾↩ ⟨codeBounds⟩ @@ -429,7 +425,7 @@ Markdown ← {filename𝕊𝕩: # Lines continue blocks if they are part of the same multi-line # type as the previous line, and otherwise start new ones. # Headers (type 1) always start new blocks. - blockStart ← nonEmptyMask ∧ (1 = lineType) ∨ ¯1⊸Shl⊸≠ lineType + blockStart ← nonEmptyMask ∧ (1 = lineType) ∨ ¯1⊸»⊸≠ lineType # Headers and paragraphs ignore leading blanks. drop ← blanks × lineType < 2 # Group blocks based on blockStart, with type ¯1 lines excluded. @@ -511,9 +507,9 @@ GetHighlights ← { le← /(𝕩=lf)∾1 # Line endings (le) end every comment (/c) on the line, so take a copy # for each # before that line but not the previous. - ce← le /˜ -⟜(0⊸Shl) c/⊸⍋le + ce← le /˜ -⟜(0⊸») c/⊸⍋le # A single quote can only be used if there's another two places down. - s ← /0‿0⊸Shr⊸∧𝕩=''' + s ← /0‿0⊸«⊸∧𝕩=''' d ← /𝕩='"' css ← ⟨ s ⋄ ¯1↓d ⋄ /c ⟩ # Comment or string start cse ← ⟨ 2+s ⋄ 1↓d ⋄ ce ⟩ # Corresponding end indices @@ -531,15 +527,15 @@ GetHighlights ← { # Color numeric literals and identifiers id ← col=5 # ←→ 𝕩∊idChars - w ← 0⊸Shl⊸< id # Word (identifier or number) beginning mask + w ← 0⊸»⊸< id # Word (identifier or number) beginning mask wt ← idChars FindGroup w/𝕩 # Type based on first character - wt+↩ '_' = (0⊸Shr⊸ (/start) {𝕨⊸+⌾(1⊸⊑)𝕩}⟜GetHighlights¨ ⊢) groups } -- cgit v1.2.3