-
-
Notifications
You must be signed in to change notification settings - Fork 257
Syntax lookup overhaul + add missing constructs #1204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| --- | ||
| id: "and" | ||
| keywords: ["and", "let rec and", "type rec and", "mutual recursion"] | ||
| name: "and" | ||
| summary: "This is the `and` keyword for mutually recursive definitions." | ||
| category: "languageconstructs" | ||
| --- | ||
|
|
||
| Use `and` to define multiple items in one mutually-recursive group. | ||
|
|
||
| ### Example 1: `let rec ... and ...` | ||
|
|
||
| <CodeTab labels={["ReScript", "JS Output"]}> | ||
|
|
||
| ```res | ||
| let rec isEven = n => n == 0 || isOdd(n - 1) | ||
| and isOdd = n => n != 0 && isEven(n - 1) | ||
| ``` | ||
|
|
||
| ```js | ||
| function isEven(n) { | ||
| return n === 0 || isOdd((n - 1) | 0); | ||
| } | ||
|
|
||
| function isOdd(n) { | ||
| return n !== 0 && isEven((n - 1) | 0); | ||
| } | ||
| ``` | ||
|
|
||
| </CodeTab> | ||
|
|
||
| ### Example 2: `type rec ... and ...` | ||
|
|
||
| <CodeTab labels={["ReScript", "JS Output"]}> | ||
|
|
||
| ```res | ||
| type rec expr = Add(expr, term) | Term(term) | ||
| and term = Int(int) | ||
| ``` | ||
|
|
||
| ```js | ||
| // Type declarations are erased from JavaScript output. | ||
| ``` | ||
|
|
||
| </CodeTab> | ||
|
|
||
| ### References | ||
|
|
||
| - [Recursive Functions](../docs/manual/function.mdx#recursive-functions) | ||
| - [Type](../docs/manual/type.mdx) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
markdown-pages/syntax-lookup/language_attached_doc_comment.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| --- | ||
| id: "attached-doc-comment" | ||
| keywords: ["doc comment", "attached doc comment", "/**"] | ||
| name: "/** ... */" | ||
| summary: "This is the `attached doc comment` syntax." | ||
| category: "languagecomments" | ||
| --- | ||
|
|
||
| Use an attached doc comment directly before a value or type declaration. | ||
|
|
||
| ### Example | ||
|
|
||
| <CodeTab labels={["ReScript", "JS Output"]}> | ||
|
|
||
| ```res | ||
| /** Returns the full name. */ | ||
| let fullName = (first, last) => first ++ " " ++ last | ||
| ``` | ||
|
|
||
| ```js | ||
| function fullName(first, last) { | ||
| return first + " " + last; | ||
| } | ||
| ``` | ||
|
|
||
| </CodeTab> | ||
|
|
||
| ### References | ||
|
|
||
| - [Overview](../docs/manual/overview.mdx#comments) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| --- | ||
| id: "block-comment" | ||
| keywords: ["comment", "block comment", "/*", "*/"] | ||
| name: "/* ... */" | ||
| summary: "This is the `block comment` syntax." | ||
| category: "languagecomments" | ||
| --- | ||
|
|
||
| Use `/* ... */` for multi-line comments. | ||
|
|
||
| ### Example | ||
|
|
||
| <CodeTab labels={["ReScript", "JS Output"]}> | ||
|
|
||
| ```res | ||
| /* | ||
| This is a block comment. | ||
| */ | ||
| let greeting = "hello" | ||
| ``` | ||
|
|
||
| ```js | ||
| var greeting = "hello"; | ||
| ``` | ||
|
|
||
| </CodeTab> | ||
|
|
||
| ### References | ||
|
|
||
| - [Overview](../docs/manual/overview.mdx#comments) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
markdown-pages/syntax-lookup/language_covariant_type_parameter.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| --- | ||
| id: "covariant-type-parameter" | ||
| keywords: ["<+a>", "+'a", "covariant", "variance", "type parameter"] | ||
| name: "<+a>" | ||
| summary: "This is a `covariant type parameter` annotation." | ||
| category: "languagetypes" | ||
| --- | ||
|
|
||
| Use a `+` variance annotation on a type parameter to mark it as covariant. | ||
|
|
||
| ### Example | ||
|
|
||
| <CodeTab labels={["ReScript", "JS Output"]}> | ||
|
|
||
| ```res | ||
| type source<+'a> = unit => 'a | ||
|
|
||
| let fromValue = (x: 'a): source<'a> => () => x | ||
| ``` | ||
|
|
||
| ```js | ||
| function fromValue(x) { | ||
| return (_) => x; | ||
| } | ||
| ``` | ||
|
|
||
| </CodeTab> | ||
|
|
||
| ### References | ||
|
|
||
| - [Type Parameters](../docs/manual/type.mdx#type-parameter-aka-generic) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| --- | ||
| id: "doc-comment" | ||
| keywords: ["doc comment", "documentation comment", "/**", "/***"] | ||
| name: "/*** ... */" | ||
| summary: "This is the `standalone doc comment` syntax." | ||
| category: "languagecomments" | ||
| --- | ||
|
|
||
| Use a standalone doc comment to write documentation text that is not attached to a specific value or type declaration. | ||
|
|
||
| ### Example | ||
|
|
||
| <CodeTab labels={["ReScript", "JS Output"]}> | ||
|
|
||
| ```res | ||
| /*** This module contains utility helpers for date formatting. */ | ||
| module DateUtils = { | ||
| let formatIso = date => date | ||
| } | ||
| ``` | ||
|
|
||
| ```js | ||
| var DateUtils = { | ||
| formatIso: (date) => date, | ||
| }; | ||
| ``` | ||
|
|
||
| </CodeTab> | ||
|
|
||
| ### References | ||
|
|
||
| - [Overview](../docs/manual/overview.mdx#comments) |
29 changes: 29 additions & 0 deletions
29
markdown-pages/syntax-lookup/language_empty_object_type.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| --- | ||
| id: "empty-object-type" | ||
| keywords: ["{.}", "empty object type", "object type"] | ||
| name: "{.}" | ||
| summary: "This is the `empty object type` syntax." | ||
| category: "languagetypes" | ||
| --- | ||
|
|
||
| Use `{.}` to describe an object type with no known fields. | ||
|
|
||
| ### Example | ||
|
|
||
| <CodeTab labels={["ReScript", "JS Output"]}> | ||
|
|
||
| ```res | ||
| type empty = {.} | ||
|
|
||
| let acceptEmpty = (_value: empty) => () | ||
| ``` | ||
|
|
||
| ```js | ||
| function acceptEmpty(_value) {} | ||
| ``` | ||
|
|
||
| </CodeTab> | ||
|
|
||
| ### References | ||
|
|
||
| - [Object](../docs/manual/object.mdx) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| --- | ||
| id: "exception" | ||
| keywords: ["exception", "exn", "throw", "try", "catch"] | ||
| name: "exception" | ||
| summary: "This is the `exception` syntax." | ||
| category: "languagecontrolflow" | ||
| --- | ||
|
|
||
| Use `exception` to declare custom exception constructors. | ||
|
|
||
| ### Example | ||
|
|
||
| <CodeTab labels={["ReScript", "JS Output"]}> | ||
|
|
||
| ```res | ||
| exception NotFound(string) | ||
|
|
||
| let message = try { | ||
| throw(NotFound("Missing value")) | ||
| } catch { | ||
| | NotFound(text) => text | ||
| } | ||
| ``` | ||
|
|
||
| ```js | ||
| var message = "Missing value"; | ||
| ``` | ||
|
|
||
| </CodeTab> | ||
|
|
||
| ### References | ||
|
|
||
| - [Exception](../docs/manual/exception.mdx) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so satisfying!!