diff --git a/src/parse/mod.rs b/src/parse/mod.rs index 1d3b8be7e..8d6958cf8 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 { // 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 { 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 { +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 { 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 { fn body(p: &mut Parser) -> Option { 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 0c18b810c..081defeb0 100644 Binary files a/tests/full/ref/coma.png and b/tests/full/ref/coma.png differ diff --git a/tests/full/typ/coma.typ b/tests/full/typ/coma.typ index 7cf62da72..03f6dcc31 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 000000000..069b0cbc2 Binary files /dev/null and b/tests/res/graph.png differ