1
0
Эх сурвалжийг харах

Update documentation, syntaxes

David Peter 2 жил өмнө
parent
commit
bb7491c641

+ 1 - 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)\b
+    - match: \b(per|to|let|fn|dimension|unit|use|long|short|both|none|print|assert_eq|type|if|then|else|true|false|bool)\b
       scope: keyword.control.nbt
     - match: '#(.*)'
       scope: comment.line.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_eq type
+syn keyword numbatKeywords per to let fn dimension unit use long short both none print assert_eq type if then else true false bool
 highlight default link numbatKeywords Keyword
 
 " Physical dimensions (every capitalized word)

+ 1 - 1
book/numbat.js

@@ -4,7 +4,7 @@ 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',
+      keyword: 'per to let fn dimension unit use long short both none print assert_eq type if then else true false bool',
     },
     contains: [
       hljs.HASH_COMMENT_MODE,

+ 1 - 0
book/src/SUMMARY.md

@@ -27,6 +27,7 @@
   - [Printing, testing, debugging](./procedures.md)
   - [Variable definitions]()
   - [Function definitions]()
+  - [Conditionals](./conditionals.md)
 - [Advanced](./advanced.md)
   - [Unit definitions](./unit-definitions.md)
   - [Dimension definitions](./dimension-definitions.md)

+ 21 - 0
book/src/conditionals.md

@@ -0,0 +1,21 @@
+# Conditionals
+
+Numbat has `if-then-else` conditional expressions with the following
+syntax
+``` nbt
+if <cond> then <expr1> else <expr2>
+```
+where `<cond>` is a condition that evaluates to a Boolean value, like
+`3 ft < 3 m`. The types of `<expr1>` and `<expr2>` need to match.
+
+## Example: step function
+
+```nbt
+fn step(x: Scalar) -> Scalar = if x < 0 then 0 else 1
+```
+
+## Example: min function
+
+```nbt
+fn min<T>(x: T, y: T) -> T = if x < y then x else y
+```

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

@@ -29,7 +29,7 @@
             "patterns": [
                 {
                     "name": "keyword.control.numbat",
-                    "match": "\\b(per|to|let|fn|dimension|unit|use|long|short|both|none|print|assert_eq|type)\\b"
+                    "match": "\\b(per|to|let|fn|dimension|unit|use|long|short|both|none|print|assert_eq|type|if|then|else|true|false|bool)\\b"
                 }
             ]
         },