Pārlūkot izejas kodu

Update syntaxes

David Peter 2 gadi atpakaļ
vecāks
revīzija
f46cd6a37f

+ 8 - 1
assets/numbat.sublime-syntax

@@ -7,7 +7,7 @@ file_extensions:
 scope: source.nbt
 contexts:
   main:
-    - match: \b(per|to|let|fn|dimension|unit|use|long|short|both|none|print|assert_eq|type|if|then|else|true|false|bool)\b
+    - match: \b(per|to|let|fn|dimension|unit|use|long|short|both|none|print|assert_eq|type|if|then|else|true|false|bool|str)\b
       scope: keyword.control.nbt
     - match: '#(.*)'
       scope: comment.line.nbt
@@ -25,3 +25,10 @@ contexts:
       scope: punctuation.definition.parenthesis.nbt
     - match: ','
       scope: punctuation.separator.comma.nbt
+    - match: '"'
+      scope: punctuation.definition.string.begin.nbt
+      push:
+        - meta_scope: string.quoted.double.nbt
+        - match: '"'
+          scope: punctuation.definition.string.end.nbt
+          pop: true

+ 5 - 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_eq type if then else true false bool
+syn keyword numbatKeywords per to let fn dimension unit use long short both none print assert_eq type if then else true false bool str
 highlight default link numbatKeywords Keyword
 
 " Physical dimensions (every capitalized word)
@@ -40,6 +40,10 @@ highlight default link numbatDecorator Constant
 syn match numbatSpecialUnits "[\u00B0]" " degree symbol
 highlight default link numbatSpecialUnits SpecialChar
 
+" Strings
+syntax match numbatString /"\([^"]*\)"/
+highlight link numbatString String
+
 " Load the matchit.vim script for the "%" matching, if it's available
 if exists(":DoMatchIt")
   DoMatchIt

+ 2 - 1
book/numbat.js

@@ -4,11 +4,12 @@ hljs.registerLanguage('numbat', function(hljs) {
     aliases: ['nbt'],
     case_insensitive: false,
     keywords: {
-      keyword: 'per to let fn dimension unit use long short both none print assert_eq type if then else true false bool',
+      keyword: 'per to let fn dimension unit use long short both none print assert_eq type if then else true false bool str',
     },
     contains: [
       hljs.HASH_COMMENT_MODE,
       hljs.BINARY_NUMBER_MODE,
+      hljs.QUOTE_STRING_MODE,
       {
         className: 'number',
         begin: /\b0o[0-7]+\b/

+ 2 - 0
book/src/example-numbat_syntax.md

@@ -99,6 +99,8 @@ fn step(x: Scalar) -> Scalar =   # The construct 'if <cond> then <expr> else <ex
 # 9. Procedures
 
 print(2 kilowarhol)              # Print the value of an expression
+print("hello world")             # Print a message
+print("value of pi = {pi}")      # String interpolation
 assert_eq(1 ft, 12 in)           # Assert that two quantities are equal
 assert_eq(1 yd, 1 m, 10 cm)      # Assert that two quantities are equal, up to
                                  # the given precision

+ 3 - 0
examples/numbat_syntax.nbt

@@ -62,6 +62,7 @@ let q3: Length / Time = 2 m/s      # more complex type annotation
 fn foo(z: Scalar) -> Scalar = 2 * z + 3                 # A simple function
 fn speed(len: Length, dur: Time) -> Speed = len / dur   # Two parameters
 fn my_sqrt<T>(q: T^2) -> T = q^(1/2)                    # A generic function
+fn is_non_negative(x: Scalar) -> bool = x ≥ 0           # Returns a bool
 
 # 6. Dimension definitions
 
@@ -94,6 +95,8 @@ fn step(x: Scalar) -> Scalar =   # The construct 'if <cond> then <expr> else <ex
 # 9. Procedures
 
 print(2 kilowarhol)              # Print the value of an expression
+print("hello world")             # Print a message
+print("value of pi = {pi}")      # String interpolation
 assert_eq(1 ft, 12 in)           # Assert that two quantities are equal
 assert_eq(1 yd, 1 m, 10 cm)      # Assert that two quantities are equal, up to
                                  # the given precision

+ 2 - 0
examples/print.nbt

@@ -1,2 +1,4 @@
 print(1)
 print(2 meter)
+print("hello world")
+print("pi = {pi}")

+ 9 - 1
vscode-extension/syntaxes/numbat.tmLanguage.json

@@ -22,6 +22,9 @@
         },
         {
             "include": "#identifier"
+        },
+        {
+            "include": "#strings"
         }
     ],
     "repository": {
@@ -29,7 +32,7 @@
             "patterns": [
                 {
                     "name": "keyword.control.numbat",
-                    "match": "\\b(per|to|let|fn|dimension|unit|use|long|short|both|none|print|assert_eq|type|if|then|else|true|false|bool)\\b"
+                    "match": "\\b(per|to|let|fn|dimension|unit|use|long|short|both|none|print|assert_eq|type|if|then|else|true|false|bool|str)\\b"
                 }
             ]
         },
@@ -80,6 +83,11 @@
                     "match": "\\b[\\p{Ll}½¼_][\\p{L}½¼_0-9]*\\b"
                 }
             ]
+        },
+        "strings": {
+            "name": "string.quoted.double",
+            "begin": "\"",
+            "end": "\""
         }
     },
     "scopeName": "source.numbat"