Bläddra i källkod

Add '\cdot' as additional multiplication operator

closes #596
David Peter 1 år sedan
förälder
incheckning
fae47e8183

+ 1 - 1
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

+ 1 - 1
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

+ 1 - 1
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
 

+ 1 - 1
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
 

+ 2 - 2
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)),
         );
 

+ 2 - 1
numbat/src/tokenizer.rs

@@ -211,6 +211,7 @@ fn is_identifier_continue(c: char) -> bool {
         || is_other_allowed_identifier_char(c))
         && !is_exponent_char(c)
         && c != '·'
+        && c != '⋅'
 }
 
 /// When scanning a string interpolation like `"foo = {foo}, and bar = {bar}."`,
@@ -555,7 +556,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,