Skip to content

Commit a4bd70e

Browse files
authored
Merge pull request #232 from kevanstannard/syntax-lookup-placeholder
Syntax Lookup placeholder
2 parents 7209fc4 + f92b520 commit a4bd70e

File tree

3 files changed

+72
-7
lines changed

3 files changed

+72
-7
lines changed
+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
id: "placeholder"
3+
keywords: ["placeholder"]
4+
name: "_"
5+
summary: "This is a `placeholder`."
6+
category: "languageconstructs"
7+
---
8+
9+
Placeholders may be used for [ignoring parts of values](/docs/manual/latest/pattern-matching-destructuring#ignore-part-of-a-value) (including serving as a catch-all in `switch` statements), and [specifying the position of an argument](/docs/manual/latest/pipe#pipe-placeholders).
10+
11+
### Example: Ignoring values
12+
13+
<CodeTab labels={["ReScript", "JS Output"]}>
14+
15+
```res
16+
switch person1 {
17+
| Teacher(_) => Js.log("Hi teacher")
18+
| Student(_) => Js.log("Hey student")
19+
}
20+
```
21+
22+
```js
23+
if (person1.TAG === /* Teacher */ 0) {
24+
console.log("Hi teacher");
25+
} else {
26+
console.log("Hey student");
27+
}
28+
```
29+
30+
</CodeTab>
31+
32+
### Example: Specifying an argument position
33+
34+
35+
<CodeTab labels={["ReScript", "JS Output"]}>
36+
37+
```res
38+
let greet = (greeting, name) => greeting ++ " " ++ name
39+
40+
// Pipe the value "John" into the second argument of the greet() function.
41+
let greetJohn = "John"->greet("Hello", _)
42+
```
43+
44+
```js
45+
function greet(greeting, name) {
46+
return greeting + " " + name;
47+
}
48+
49+
var greetJohn = "Hello John";
50+
```
51+
52+
</CodeTab>
53+
54+
### References
55+
56+
* [Ignore part of a value](/docs/manual/latest/pattern-matching-destructuring#ignore-part-of-a-value)
57+
* [Pipe placeholders](/docs/manual/latest/pipe#pipe-placeholders)

src/SyntaxLookup.js

+11-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/SyntaxLookup.res

+4-1
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ let requireSyntaxFile: string => MdxComp.t = %raw(`
3131
`)
3232

3333
module Category = {
34-
type t = Decorators | ControlFlow | Operators | SpecialValues | Other
34+
type t = Decorators | ControlFlow | Operators | LanguageConstructs | SpecialValues | Other
3535

3636
let toString = t =>
3737
switch t {
3838
| Decorators => "Decorators"
3939
| Operators => "Operators"
40+
| LanguageConstructs => "Language Constructs"
4041
| SpecialValues => "Special Values"
4142
| ControlFlow => "Control Flow"
4243
| Other => "Other"
@@ -48,6 +49,7 @@ module Category = {
4849
| "controlflow" => ControlFlow
4950
| "specialvalues" => SpecialValues
5051
| "operators" => Operators
52+
| "languageconstructs" => LanguageConstructs
5153
| _ => Other
5254
}
5355
}
@@ -241,6 +243,7 @@ let make = () => {
241243
let initial = [
242244
Decorators,
243245
Operators,
246+
LanguageConstructs,
244247
ControlFlow,
245248
SpecialValues,
246249
Other,

0 commit comments

Comments
 (0)