Browse Source

Update Numbat syntaxes

David Peter 1 year ago
parent
commit
8856826a88

+ 4 - 4
assets/numbat.sublime-syntax

@@ -7,17 +7,17 @@ file_extensions:
 scope: source.nbt
 contexts:
   main:
-    - match: \b(per|to|let|fn|dimension|unit|use|long|short|both|none|print|assert|assert_eq|type|if|then|else|true|false)\b
+    - match: \b(per|to|let|fn|dimension|unit|use|struct|long|short|both|none|if|then|else|true|false|print|assert|assert_eq|type)\b
       scope: keyword.control.nbt
     - match: '#(.*)'
       scope: comment.line.nbt
+    - match: \b([0-9][0-9_]*(\.[0-9][0-9_]*)?(e[+\-]?[0-9]+)?|0b[01]+|0o[0-7]+|0x[0-9a-fA-F]+|NaN|inf)\b
+      scope: constant.numeric.nbt
     - match: \b([A-Z][a-zA-Z]*)\b
       scope: storage.type.nbt
     - match: \b([a-z][a-zA-Z_0-9]*)\b
       scope: variable.other.nbt
-    - match: \b([0-9]+(\.[0-9]+)?)\b
-      scope: constant.numeric.nbt
-    - match: '(@aliases(\_short)?|@metric_prefixes|@binary_prefixes)'
+    - match: '(@aliases|@metric_prefixes|@binary_prefixes|@name|@url)'
       scope: meta.annotation.attribute.nbt
     - match: '[+\-/*=\^:<>·×÷²³]'
       scope: keyword.operator.nbt

+ 1 - 1
assets/numbat.vim

@@ -5,7 +5,7 @@ if exists("b:current_syntax")
 endif
 
 " Numbat Keywords
-syn keyword numbatKeywords per to let fn dimension unit use long short both none print assert assert_eq type if then else true false Bool String
+syn keyword numbatKeywords per to let fn dimension unit use struct long short both none if then else true false NaN inf print assert assert_eq type
 highlight default link numbatKeywords Keyword
 
 " Physical dimensions (every capitalized word)

+ 9 - 8
numbat/src/keywords.rs

@@ -18,22 +18,23 @@ pub const KEYWORDS: &[&str] = &[
     "if",
     "then",
     "else",
-    "Bool",
     "true",
     "false",
-    "String",
-    "DateTime",
     "NaN",
     "inf",
+    // procedures
+    "print(",
+    "assert(",
+    "assert_eq(",
+    "type(",
+    // Type names
+    "Bool",
+    "String",
+    "DateTime",
     // decorators
     "metric_prefixes",
     "binary_prefixes",
     "aliases",
     "name",
     "url",
-    // procedures
-    "print(",
-    "assert_eq(",
-    "assert(",
-    "type(",
 ];

+ 3 - 3
vscode-extension/syntaxes/numbat.tmLanguage.json

@@ -32,7 +32,7 @@
             "patterns": [
                 {
                     "name": "keyword.control.numbat",
-                    "match": "\\b(per|to|let|fn|dimension|unit|use|long|short|both|none|print|assert|assert_eq|type|if|then|else|true|false)\\b"
+                    "match": "\\b(per|to|let|fn|dimension|unit|use|struct|long|short|both|none|if|then|else|true|false|print|assert|assert_eq|type)\\b"
                 }
             ]
         },
@@ -40,7 +40,7 @@
             "patterns": [
                 {
                     "name": "support.function.numbat",
-                    "match": "@(metric_prefixes|binary_prefixes|aliases)\\b"
+                    "match": "@(metric_prefixes|binary_prefixes|aliases|name|url)\\b"
                 }
             ]
         },
@@ -56,7 +56,7 @@
             "patterns": [
                 {
                     "name": "constant.numeric",
-                    "match": "\\b[0-9]+(\\.[0-9]+)?(e[+\\-]?[0-9]+)?\\b"
+                    "match": "\\b([0-9][0-9_]*(\\.[0-9][0-9_]*)?(e[+\\-]?[0-9]+)?|0b[01]+|0o[0-7]+|0x[0-9a-fA-F]+|NaN|inf)\\b"
                 }
             ]
         },