From 00d38d564362a4d4fae7a9158c739fc1dfedc433 Mon Sep 17 00:00:00 2001 From: David Peter Date: Wed, 9 Oct 2024 11:20:47 +0200 Subject: [PATCH] Add '\cdot' as additional multiplication operator closes #596 --- assets/numbat.sublime-syntax | 2 +- assets/numbat.vim | 2 +- book/src/example-numbat_syntax.md | 2 +- examples/numbat_syntax.nbt | 2 +- numbat/src/parser.rs | 4 ++-- numbat/src/tokenizer.rs | 4 ++-- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/assets/numbat.sublime-syntax b/assets/numbat.sublime-syntax index 31a398c3..22d49cb8 100644 --- a/assets/numbat.sublime-syntax +++ b/assets/numbat.sublime-syntax @@ -19,7 +19,7 @@ contexts: scope: variable.other.nbt - match: '(@aliases|@metric_prefixes|@binary_prefixes|@name|@url)' scope: meta.annotation.attribute.nbt - - match: '[+\-/*=\^:<>·×÷²³]' + - match: '[+\-/*=\^:<>·⋅×÷²³]' scope: keyword.operator.nbt - match: '[\(\)]' scope: punctuation.definition.parenthesis.nbt diff --git a/assets/numbat.vim b/assets/numbat.vim index 37a58612..c0fe496e 100644 --- a/assets/numbat.vim +++ b/assets/numbat.vim @@ -29,7 +29,7 @@ syn match numbatNumber '\v<([0-9]*\.[0-9]*|[0-9]*\.[0-9]+)([eE][+-]?[0-9]+)?>' highlight default link numbatNumber Number " Operators -syn match numbatOperators "->\|[+*^=/\-:·×÷²³<>]" +syn match numbatOperators "->\|[+*^=/\-:·⋅×÷²³<>]" highlight default link numbatOperators Operator " Unit decorators diff --git a/book/src/example-numbat_syntax.md b/book/src/example-numbat_syntax.md index 9296c485..317994f1 100644 --- a/book/src/example-numbat_syntax.md +++ b/book/src/example-numbat_syntax.md @@ -38,7 +38,7 @@ inf # Infinity 3 + (4 - 3) # Addition and subtraction 1920 / 16 * 9 # Multiplication, division -1920 ÷ 16 × 9 # Unicode-style, '·' is also multiplication +1920 ÷ 16 × 9 # Unicode-style, '·' or '⋅' works as well 2 pi # Whitespace is implicit multiplication meter per second # 'per' keyword can be used for division diff --git a/examples/numbat_syntax.nbt b/examples/numbat_syntax.nbt index ca4c6244..5ac63c79 100644 --- a/examples/numbat_syntax.nbt +++ b/examples/numbat_syntax.nbt @@ -33,7 +33,7 @@ inf # Infinity 3 + (4 - 3) # Addition and subtraction 1920 / 16 * 9 # Multiplication, division -1920 ÷ 16 × 9 # Unicode-style, '·' is also multiplication +1920 ÷ 16 × 9 # Unicode-style, '·' or '⋅' works as well 2 pi # Whitespace is implicit multiplication meter per second # 'per' keyword can be used for division diff --git a/numbat/src/parser.rs b/numbat/src/parser.rs index e2146c6e..424ed8f9 100644 --- a/numbat/src/parser.rs +++ b/numbat/src/parser.rs @@ -57,7 +57,7 @@ //! boolean ::= "true" | "false" //! plus ::= "+" //! minus ::= "-" -//! multiply ::= "*" | "×" | "·" +//! multiply ::= "*" | "×" | "·" | "⋅" //! divide ::= "/" | "÷" //! string ::= '"' [^"]* '"' //! ``` @@ -2331,7 +2331,7 @@ mod tests { #[test] fn multiplication_and_division() { parse_as_expression( - &["1*2", " 1 * 2 ", "1 · 2", "1 × 2"], + &["1*2", " 1 * 2 ", "1 · 2", "1 ⋅ 2", "1 × 2"], binop!(scalar!(1.0), Mul, scalar!(2.0)), ); diff --git a/numbat/src/tokenizer.rs b/numbat/src/tokenizer.rs index eaa8e227..fbeb128d 100644 --- a/numbat/src/tokenizer.rs +++ b/numbat/src/tokenizer.rs @@ -210,7 +210,7 @@ fn is_identifier_continue(c: char) -> bool { || is_currency_char(c) || is_other_allowed_identifier_char(c)) && !is_exponent_char(c) - && c != '·' + && c != '·' && c != '⋅' } /// When scanning a string interpolation like `"foo = {foo}, and bar = {bar}."`, @@ -555,7 +555,7 @@ impl Tokenizer { '|' if self.match_char(input, '>') => TokenKind::PostfixApply, '*' if self.match_char(input, '*') => TokenKind::Power, '+' => TokenKind::Plus, - '*' | '·' | '×' => TokenKind::Multiply, + '*' | '·' | '⋅' | '×' => TokenKind::Multiply, '/' => TokenKind::Divide, '÷' => TokenKind::Divide, '^' => TokenKind::Power,