summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-02-18 15:19:29 +0100
committerLaurenz <laurmaedje@gmail.com>2021-02-18 15:19:29 +0100
commit927341d93ae29678095e3b874bd68bfc57d4bc05 (patch)
treeda2bc2cf737987f67d3551c214bdb57d72fe9a90
parented81049ddc8fcef3ddf6f6f69d95bb52512bf698 (diff)
Update coma example ⬆️
-rw-r--r--src/parse/mod.rs10
-rw-r--r--tests/full/ref/coma.pngbin27418 -> 61297 bytes
-rw-r--r--tests/full/typ/coma.typ33
-rw-r--r--tests/res/graph.pngbin0 -> 18008 bytes
4 files changed, 34 insertions, 9 deletions
diff --git a/src/parse/mod.rs b/src/parse/mod.rs
index 1d3b8be7..8d6958cf 100644
--- a/src/parse/mod.rs
+++ b/src/parse/mod.rs
@@ -91,7 +91,7 @@ fn node(p: &mut Parser, at_start: &mut bool) -> Option<Node> {
// Block.
Token::LeftBrace => {
*at_start = false;
- return Some(Node::Expr(block(p, false)?));
+ return Some(Node::Expr(block(p, false)));
}
// Template.
@@ -194,7 +194,7 @@ fn primary(p: &mut Parser) -> Option<Expr> {
Some(Token::For) => expr_for(p),
// Structures.
- Some(Token::LeftBrace) => block(p, true),
+ Some(Token::LeftBrace) => Some(block(p, true)),
Some(Token::LeftBracket) => Some(template(p)),
Some(Token::LeftParen) => Some(parenthesized(p)),
@@ -238,7 +238,7 @@ fn template(p: &mut Parser) -> Expr {
}
/// Parse a block expression: `{...}`.
-fn block(p: &mut Parser, scopes: bool) -> Option<Expr> {
+fn block(p: &mut Parser, scopes: bool) -> Expr {
p.start_group(Group::Brace, TokenMode::Code);
let mut exprs = vec![];
while !p.eof() {
@@ -253,7 +253,7 @@ fn block(p: &mut Parser, scopes: bool) -> Option<Expr> {
p.skip_white();
}
let span = p.end_group();
- Some(Expr::Block(ExprBlock { span, exprs, scoping: scopes }))
+ Expr::Block(ExprBlock { span, exprs, scoping: scopes })
}
/// Parse an expression.
@@ -434,7 +434,7 @@ fn ident(p: &mut Parser) -> Option<Ident> {
fn body(p: &mut Parser) -> Option<Expr> {
match p.peek() {
Some(Token::LeftBracket) => Some(template(p)),
- Some(Token::LeftBrace) => block(p, true),
+ Some(Token::LeftBrace) => Some(block(p, true)),
_ => {
p.expected_at("body", p.end());
None
diff --git a/tests/full/ref/coma.png b/tests/full/ref/coma.png
index 0c18b810..081defeb 100644
--- a/tests/full/ref/coma.png
+++ b/tests/full/ref/coma.png
Binary files differ
diff --git a/tests/full/typ/coma.typ b/tests/full/typ/coma.typ
index 7cf62da7..03f6dcc3 100644
--- a/tests/full/typ/coma.typ
+++ b/tests/full/typ/coma.typ
@@ -1,17 +1,36 @@
-#page(width: 450pt, height: 300pt, margins: 1cm)
+// Configuration with `page` and `font` functions.
+#page(width: 450pt, height: 380pt, margins: 1cm)
+#font("CMU Serif")
+// There are variables and they can take normal values like strings, ...
+#let city = "Berlin"
+
+// ... but also "template" values. While these contain markup,
+// they are also values and can be summed, stored in arrays etc.
+// There are also more standard control flow structures, like #if and #for.
+#let university = [*Technische Universität {city}*]
+#let faculty = [*Fakultät II, Institut for Mathematik*]
+
+// The `box` function just places content into a rectangular container. When
+// the only argument to a function is a template, the parentheses can be omitted
+// (i.e. `f[a]` is the same as `f([a])`).
#box[
- *Technische Universität Berlin* \
- *Fakultät II, Institut for Mathematik* \
+ // Backslash adds a forced line break.
+ #university \
+ #faculty \
Sekretariat MA \
Dr. Max Mustermann \
Ola Nordmann, John Doe
]
-#align(right, box[*WiSe 2019/2020* \ Woche 3])
+#align(right, box([*WiSe 2019/2020* \ Woche 3]))
+// Adds vertical spacing.
#v(6mm)
+// If the last argument to a function is a template, we can also place it behind
+// the parentheses.
#align(center)[
+ // Markdown-like syntax for headings.
==== 3. Übungsblatt Computerorientierte Mathematik II #v(2mm)
*Abgabe: 03.05.2019* (bis 10:10 Uhr in MA 001) #v(2mm)
*Alle Antworten sind zu beweisen.*
@@ -23,3 +42,9 @@ Ein _Binärbaum_ ist ein Wurzelbaum, in dem jeder Knoten ≤ 2 Kinder hat.
Die Tiefe eines Knotens _v_ ist die Länge des eindeutigen Weges von der Wurzel
zu _v_, und die Höhe von _v_ ist die Länge eines längsten (absteigenden) Weges
von _v_ zu einem Blatt. Die Höhe des Baumes ist die Höhe der Wurzel.
+
+#v(6mm)
+
+// The `image` function returns a "template" value of the same type as
+// the `[...]` literals.
+#align(center, image("res/graph.png", width: 75%))
diff --git a/tests/res/graph.png b/tests/res/graph.png
new file mode 100644
index 00000000..069b0cbc
--- /dev/null
+++ b/tests/res/graph.png
Binary files differ