Skip to content

Commit

Permalink
Merge pull request #608 from sharkdp/add-cdot-operator
Browse files Browse the repository at this point in the history
Add '\cdot' as additional multiplication operator
  • Loading branch information
sharkdp authored Oct 9, 2024
2 parents a4eadb6 + fae47e8 commit 359e50a
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion assets/numbat.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion assets/numbat.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion book/src/example-numbat_syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/numbat_syntax.nbt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions numbat/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
//! boolean ::= "true" | "false"
//! plus ::= "+"
//! minus ::= "-"
//! multiply ::= "*" | "×" | "·"
//! multiply ::= "*" | "×" | "·" | "⋅"
//! divide ::= "/" | "÷"
//! string ::= '"' [^"]* '"'
//! ```
Expand Down Expand Up @@ -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)),
);

Expand Down
3 changes: 2 additions & 1 deletion numbat/src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}."`,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 359e50a

Please sign in to comment.