From 5e08028fb36aa766957cba64c5c665edf9b96fb7 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sun, 21 Mar 2021 17:46:09 +0100 Subject: =?UTF-8?q?Syntax=20functions=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds overridable functions that markup desugars into. Specifically: - \ desugars into linebreak - Two newlines desugar into parbreak - * desugars into strong - _ desugars into emph - = .. desugars into heading - `..` desugars into raw --- tests/ref/markup/emph.png | Bin 3053 -> 3387 bytes tests/ref/markup/heading.png | Bin 4540 -> 5288 bytes tests/ref/markup/linebreak.png | Bin 3770 -> 4307 bytes tests/ref/markup/parbreak.png | Bin 0 -> 1654 bytes tests/ref/markup/raw.png | Bin 7291 -> 8299 bytes tests/ref/markup/strong.png | Bin 2824 -> 3374 bytes tests/typ/expr/ops.typ | 3 --- tests/typ/library/paragraph.typ | 4 ++-- tests/typ/markup/emph.typ | 13 +++++++++++-- tests/typ/markup/heading.typ | 8 ++++++++ tests/typ/markup/linebreak.typ | 8 ++++++++ tests/typ/markup/parbreak.typ | 11 +++++++++++ tests/typ/markup/raw.typ | 8 ++++++++ tests/typ/markup/strong.typ | 12 ++++++++++-- tests/typeset.rs | 2 +- 15 files changed, 59 insertions(+), 10 deletions(-) create mode 100644 tests/ref/markup/parbreak.png create mode 100644 tests/typ/markup/parbreak.typ (limited to 'tests') diff --git a/tests/ref/markup/emph.png b/tests/ref/markup/emph.png index 75231a62..f43eeecb 100644 Binary files a/tests/ref/markup/emph.png and b/tests/ref/markup/emph.png differ diff --git a/tests/ref/markup/heading.png b/tests/ref/markup/heading.png index 3473f798..515788f3 100644 Binary files a/tests/ref/markup/heading.png and b/tests/ref/markup/heading.png differ diff --git a/tests/ref/markup/linebreak.png b/tests/ref/markup/linebreak.png index 4e4702f9..aa01c99a 100644 Binary files a/tests/ref/markup/linebreak.png and b/tests/ref/markup/linebreak.png differ diff --git a/tests/ref/markup/parbreak.png b/tests/ref/markup/parbreak.png new file mode 100644 index 00000000..008afca2 Binary files /dev/null and b/tests/ref/markup/parbreak.png differ diff --git a/tests/ref/markup/raw.png b/tests/ref/markup/raw.png index 59a4e3dd..1aebc02d 100644 Binary files a/tests/ref/markup/raw.png and b/tests/ref/markup/raw.png differ diff --git a/tests/ref/markup/strong.png b/tests/ref/markup/strong.png index 7e62f0f3..20e29b1f 100644 Binary files a/tests/ref/markup/strong.png and b/tests/ref/markup/strong.png differ diff --git a/tests/typ/expr/ops.typ b/tests/typ/expr/ops.typ index 2390b7b4..ef249c43 100644 --- a/tests/typ/expr/ops.typ +++ b/tests/typ/expr/ops.typ @@ -122,10 +122,7 @@ #test((1, 2, 3) == (1, 2.0) + (3,), true) #test((:) == (a: 1), false) #test((a: 2 - 1.0, b: 2) == (b: 2, a: 1), true) -#test([*Hi*] == [*Hi*], true) - #test("a" != "a", false) -#test([*] != [_], true) --- // Test comparison operators. diff --git a/tests/typ/library/paragraph.typ b/tests/typ/library/paragraph.typ index 3ce946bd..74fb8189 100644 --- a/tests/typ/library/paragraph.typ +++ b/tests/typ/library/paragraph.typ @@ -3,11 +3,11 @@ --- // Test configuring paragraph properties. -#paragraph(spacing: 10pt, leading: 25%, word-spacing: 1pt) +#par(spacing: 10pt, leading: 25%, word-spacing: 1pt) But, soft! what light through yonder window breaks? It is the east, and Juliet is the sun. --- // Test that it finishes an existing paragraph. -Hello #paragraph(word-spacing: 0pt) t h e r e ! +Hello #par(word-spacing: 0pt) t h e r e ! diff --git a/tests/typ/markup/emph.typ b/tests/typ/markup/emph.typ index 500381c1..8e25e7d3 100644 --- a/tests/typ/markup/emph.typ +++ b/tests/typ/markup/emph.typ @@ -10,5 +10,14 @@ Partly em_phas_ized. // Scoped to body. #rect[_Scoped] to body. -// Unterminated is fine. -_The End +--- +#let emph = strong +_Strong_ + +#let emph() = "Hi" +_, _! + +#let emph = "hi" + +// Error: 1-2 expected function, found string +_ diff --git a/tests/typ/markup/heading.typ b/tests/typ/markup/heading.typ index 15c391d1..9bbe3415 100644 --- a/tests/typ/markup/heading.typ +++ b/tests/typ/markup/heading.typ @@ -42,3 +42,11 @@ No = heading // Escaped. \= No heading + +--- +// Make small, but double heading. +#let heading(contents) = heading(contents + contents, level: 6) + +// The new heading's argument list doesn't contain `level`. +// Error: 1-11 unexpected argument +=== Twice. diff --git a/tests/typ/markup/linebreak.typ b/tests/typ/markup/linebreak.typ index e6392992..a0a501b6 100644 --- a/tests/typ/markup/linebreak.typ +++ b/tests/typ/markup/linebreak.typ @@ -21,3 +21,11 @@ Trailing 2 // Trailing before end of document. Trailing 3 \ + +--- +#let linebreak() = [ + // Inside the old line break definition is still active. + #circle(radius: 2pt, fill: #000) \ +] + +A \ B \ C \ diff --git a/tests/typ/markup/parbreak.typ b/tests/typ/markup/parbreak.typ new file mode 100644 index 00000000..b9b8a222 --- /dev/null +++ b/tests/typ/markup/parbreak.typ @@ -0,0 +1,11 @@ +// Test paragraph breaks. + +--- +// Paragraph breaks don't exist! +#let parbreak() = [ ] + +No more + +paragraph breaks + +for you! diff --git a/tests/typ/markup/raw.typ b/tests/typ/markup/raw.typ index 005d413e..cae3d261 100644 --- a/tests/typ/markup/raw.typ +++ b/tests/typ/markup/raw.typ @@ -45,6 +45,14 @@ def hi(): print("Hi!") ``` +--- +// Make everything block-level. +#let raw(text) = raw(text, block: true) + +// The new raw's argument list doesn't contain `block`. +// Error: 6-10 unexpected argument +This `is` block-level. + --- // Unterminated. // Error: 2:1 expected backtick(s) diff --git a/tests/typ/markup/strong.typ b/tests/typ/markup/strong.typ index a56e0e1c..6a6fc04a 100644 --- a/tests/typ/markup/strong.typ +++ b/tests/typ/markup/strong.typ @@ -10,5 +10,13 @@ Partly str*ength*ened. // Scoped to body. #rect[*Scoped] to body. -// Unterminated is fine. -*The End +--- +#let strong = emph +*Emph* + +#let strong() = "Bye" +*, *! + +#let strong = 123 +// Error: 1-2 expected function, found integer +* diff --git a/tests/typeset.rs b/tests/typeset.rs index 2cf6bfb6..0a22c96b 100644 --- a/tests/typeset.rs +++ b/tests/typeset.rs @@ -209,7 +209,7 @@ fn test_part( let (local_compare_ref, ref_diags) = parse_metadata(src, &map); let compare_ref = local_compare_ref.unwrap_or(compare_ref); - let mut scope = library::new(); + let mut scope = library::_new(); let panics = Rc::new(RefCell::new(vec![])); register_helpers(&mut scope, Rc::clone(&panics)); -- cgit v1.2.3