From 3a4c5ae4b96ff5c2cd17a2f41a67398f21da0373 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 30 Jan 2023 18:29:09 +0100 Subject: [PATCH] Highlighting and docs fixes --- library/src/math/matrix.rs | 6 +++--- library/src/math/mod.rs | 40 +++++++++++++------------------------- src/ide/highlight.rs | 12 ++++++++---- src/syntax/parser.rs | 2 +- 4 files changed, 25 insertions(+), 35 deletions(-) diff --git a/library/src/math/matrix.rs b/library/src/math/matrix.rs index ca2fb9fd3..527cf3159 100644 --- a/library/src/math/matrix.rs +++ b/library/src/math/matrix.rs @@ -55,9 +55,9 @@ impl LayoutMath for VecNode { /// /// The elements of a row should be separated by commas, while the rows /// themselves should be separated by semicolons. The semicolon syntax merges -/// preceding arguments separated by commas into a array arguments. You -/// can also use this special syntax of math function calls to define custom -/// functions that take 2D data. +/// preceding arguments separated by commas into an array. You can also use this +/// special syntax of math function calls to define custom functions that take +/// 2D data. /// /// Content in cells that are in the same row can be aligned with the `&` symbol. /// diff --git a/library/src/math/mod.rs b/library/src/math/mod.rs index f24b80788..ab1fab136 100644 --- a/library/src/math/mod.rs +++ b/library/src/math/mod.rs @@ -107,26 +107,7 @@ pub fn module(sym: &Module) -> Module { /// # Formula /// A mathematical formula. /// -/// ## Syntax -/// This function also has dedicated syntax: Write mathematical markup within -/// dollar signs to create a formula. Starting and ending the formula with at -/// least one space lifts it into a separate block that is centered -/// horizontally. -/// -/// In math, single letters are always displayed as is. Multiple letters, -/// however, are interpreted as variables, symbols or functions. To display -/// multiple letters verbatim, you can place them into quotes. Math mode also -/// supports extra shorthands to easily type various arrows and other symbols. -/// The [text](/docs/reference/text/) and [math](/docs/reference/math/) sections -/// list all of them. -/// -/// When a variable and a symbol share the same name, the variable is preferred. -/// To force the symbol, surround it with colons. To access a variable with a -/// single letter name, you can prefix it with a `#`. -/// -/// In math mode, the arguments to a function call are always parsed as -/// mathematical content. To work with other kinds of values, you first need to -/// enter a code block using the `[$#{..}$]` syntax. +/// Can be displayed inline with text or as a separate block. /// /// ## Example /// ``` @@ -139,16 +120,21 @@ pub fn module(sym: &Module) -> Module { /// /// Prove by induction: /// $ sum_(k=1)^n k = (n(n+1)) / 2 $ -/// -/// We define the following set: -/// $ cal(A) := -/// { x in RR | x "is natural" } $ /// ``` /// -/// ## Parameters -/// - body: Content (positional, required) The contents of the formula. +/// ## Syntax +/// This function also has dedicated syntax: Write mathematical markup within +/// dollar signs to create a formula. Starting and ending the formula with at +/// least one space lifts it into a separate block that is centered +/// horizontally. For more details about math syntax, see the +/// [main math page](/docs/reference/math). /// -/// - block: bool (named) Whether the formula is displayed as a separate block. +/// ## Parameters +/// - body: Content (positional, required) +/// The contents of the formula. +/// +/// - block: bool (named) +/// Whether the formula is displayed as a separate block. /// /// ## Category /// math diff --git a/src/ide/highlight.rs b/src/ide/highlight.rs index 2e418e224..e00007f3c 100644 --- a/src/ide/highlight.rs +++ b/src/ide/highlight.rs @@ -256,9 +256,13 @@ pub fn highlight(node: &LinkedNode) -> Option { /// Highlight an identifier based on context. fn highlight_ident(node: &LinkedNode) -> Option { // Are we directly before an argument list? - let next_leaf_kind = node.next_leaf().map(|leaf| leaf.kind()); - if matches!(next_leaf_kind, Some(SyntaxKind::LeftParen | SyntaxKind::LeftBracket)) { - return Some(Category::Function); + let next_leaf = node.next_leaf(); + if let Some(next) = &next_leaf { + if node.range().end == next.offset() + && matches!(next.kind(), SyntaxKind::LeftParen | SyntaxKind::LeftBracket) + { + return Some(Category::Function); + } } // Are we in math? @@ -273,7 +277,7 @@ fn highlight_ident(node: &LinkedNode) -> Option { } // Are we directly before a show rule colon? - if next_leaf_kind == Some(SyntaxKind::Colon) + if next_leaf.map(|leaf| leaf.kind()) == Some(SyntaxKind::Colon) && ancestor.parent_kind() == Some(SyntaxKind::ShowRule) { return Some(Category::Function); diff --git a/src/syntax/parser.rs b/src/syntax/parser.rs index b51de59e9..1f9bdedd3 100644 --- a/src/syntax/parser.rs +++ b/src/syntax/parser.rs @@ -507,7 +507,7 @@ fn embedded_code_expr(p: &mut Parser) { fn code_expr_prec(p: &mut Parser, atomic: bool, min_prec: usize) { let m = p.marker(); - if let Some(op) = ast::UnOp::from_kind(p.current()) { + if let (false, Some(op)) = (atomic, ast::UnOp::from_kind(p.current())) { p.eat(); code_expr_prec(p, atomic, op.precedence()); p.wrap(m, SyntaxKind::Unary);