summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-01-30 18:29:09 +0100
committerLaurenz <laurmaedje@gmail.com>2023-01-30 18:29:09 +0100
commit3a4c5ae4b96ff5c2cd17a2f41a67398f21da0373 (patch)
tree8ac95426ccfe6bb0843a146878864919a8f55c04
parent1d86f418315a2dd632016c32bfedfcf2af1b0369 (diff)
Highlighting and docs fixes
-rw-r--r--library/src/math/matrix.rs6
-rw-r--r--library/src/math/mod.rs38
-rw-r--r--src/ide/highlight.rs12
-rw-r--r--src/syntax/parser.rs2
4 files changed, 24 insertions, 34 deletions
diff --git a/library/src/math/matrix.rs b/library/src/math/matrix.rs
index ca2fb9fd..527cf315 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 f24b8078..ab1fab13 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" } $
/// ```
///
+/// ## 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).
+///
/// ## Parameters
-/// - body: Content (positional, required) The contents of the formula.
+/// - body: Content (positional, required)
+/// The contents of the formula.
///
-/// - block: bool (named) Whether the formula is displayed as a separate block.
+/// - 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 2e418e22..e00007f3 100644
--- a/src/ide/highlight.rs
+++ b/src/ide/highlight.rs
@@ -256,9 +256,13 @@ pub fn highlight(node: &LinkedNode) -> Option<Category> {
/// Highlight an identifier based on context.
fn highlight_ident(node: &LinkedNode) -> Option<Category> {
// 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<Category> {
}
// 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 b51de59e..1f9bdedd 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);