From e873370e16943dbbadb70222e272eff6c7c7da33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BAnar=20Berg?= Date: Thu, 13 Mar 2025 07:43:49 -0700 Subject: [PATCH] Ease restrictions on when infix base becomes double pipe fenced fixes #142 --- demo/test-cases.html | 1 + src/compiler/parser/handlers/infix.js | 9 +++++---- test/snapshots/sub-supscripts.js.md | 6 ++++++ test/snapshots/sub-supscripts.js.snap | Bin 800 -> 842 bytes test/sub-supscripts.js | 4 ++++ 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/demo/test-cases.html b/demo/test-cases.html index 67a25c3..4348358 100644 --- a/demo/test-cases.html +++ b/demo/test-cases.html @@ -283,6 +283,7 @@

Super and Subscripts

(X^T)_ i.,j = X_ j.,i ||bf a||^2 |bf b|_i + ||a*b||^2 ln x = int_1^x 1/t dt diff --git a/src/compiler/parser/handlers/infix.js b/src/compiler/parser/handlers/infix.js index dc23403..8a5cccb 100644 --- a/src/compiler/parser/handlers/infix.js +++ b/src/compiler/parser/handlers/infix.js @@ -210,15 +210,16 @@ function rightAssociate(op, [left, right]) { * @returns {boolean} */ function isPipeDelimited(nodes) { - if (nodes.length !== 3) { + if (nodes.length < 3) { return false; } - const [open, , close] = nodes; + const open = nodes.at(0); + const close = nodes.at(-1); return ( - open.type === "OperatorLiteral" && - close.type === "OperatorLiteral" && + open?.type === "OperatorLiteral" && + close?.type === "OperatorLiteral" && (open.value === "|" || open.value === "โˆฅ" || open.value === "โ€–") && open.value === close.value ); diff --git a/test/snapshots/sub-supscripts.js.md b/test/snapshots/sub-supscripts.js.md index 81db9b3..6f94c99 100644 --- a/test/snapshots/sub-supscripts.js.md +++ b/test/snapshots/sub-supscripts.js.md @@ -99,3 +99,9 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 '|๐›|i' + +## Norm of the dot product square + +> Snapshot 1 + + 'โ€–aยทbโ€–2' diff --git a/test/snapshots/sub-supscripts.js.snap b/test/snapshots/sub-supscripts.js.snap index eea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_F)VO!e}Ip?+MNtc2VdY06bJI#;ua)ZmQ2ivP&cU7E|u3Pg1~^QSeF z9e+j_Rs)fQKH>rpNJ;?p*4KN8SY1=CmwOh@tpX<#ow5i#-u>=$B4MNCh$hG7D#yk~ zFRhl|#&*u*&hmVIn!Rs1jWIe5nmix3^7ZU|0`)2P=wb_GLR)zJc2B3&LgkP*Sx84C zX>r2?wY&uZ83;)UM-WgUX;gLogUNQ{bz|On6$yML2Q5O~*`bT2P;Z_o7(XN+*(hxl zu418Rh5kwNu7!WIY4>HV!xu{|UEM!x)9D{qzq@3cUa~$C$P0;5i>;I(iQA07V2ZgR zZ7UiRNkGUJ9`AhBr@L7ym<-wU%C-0k!OedaELUjF9k&)x#0eylgeVjPA{hiVMf1yY z{iiM(Rzm70d~!jwnNK;iaLBdSBi%&Cev5J$@BYwTzK|8j^pol6iTaXwr64GR^0lG_ zq>4#;me*VO=wN?en*ud$o4YYw7Q^%k6nzxyHyDblADdQ#Kec;E*Z8sjtKDEf%-&di zo)Ae>B7(S(HHYL|P>*e>+!j23`B7VObnyPubhH%6 diff --git a/test/sub-supscripts.js b/test/sub-supscripts.js index 3c276cb..fd4aa4e 100644 --- a/test/sub-supscripts.js +++ b/test/sub-supscripts.js @@ -68,3 +68,7 @@ test("Square of a norm", (t) => { test("Index of a magnitute", (t) => { t.snapshot(render("|bf b|_i")); }); + +test("Norm of the dot product square", (t) => { + t.snapshot(render("||a*b||^2")); +});