Skip to content

Syntax Lookup placeholder #232

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 1 commit into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions misc_docs/syntax/language_placeholder.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
id: "placeholder"
keywords: ["placeholder"]
name: "_"
summary: "This is a `placeholder`."
category: "languageconstructs"
---

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).

### Example: Ignoring values

<CodeTab labels={["ReScript", "JS Output"]}>

```res
switch person1 {
| Teacher(_) => Js.log("Hi teacher")
| Student(_) => Js.log("Hey student")
}
```

```js
if (person1.TAG === /* Teacher */ 0) {
console.log("Hi teacher");
} else {
console.log("Hey student");
}
```

</CodeTab>

### Example: Specifying an argument position


<CodeTab labels={["ReScript", "JS Output"]}>

```res
let greet = (greeting, name) => greeting ++ " " ++ name

// Pipe the value "John" into the second argument of the greet() function.
let greetJohn = "John"->greet("Hello", _)
```

```js
function greet(greeting, name) {
return greeting + " " + name;
}

var greetJohn = "Hello John";
```

</CodeTab>

### References

* [Ignore part of a value](/docs/manual/latest/pattern-matching-destructuring#ignore-part-of-a-value)
* [Pipe placeholders](/docs/manual/latest/pipe#pipe-placeholders)
17 changes: 11 additions & 6 deletions src/SyntaxLookup.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/SyntaxLookup.res
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ let requireSyntaxFile: string => MdxComp.t = %raw(`
`)

module Category = {
type t = Decorators | ControlFlow | Operators | SpecialValues | Other
type t = Decorators | ControlFlow | Operators | LanguageConstructs | SpecialValues | Other

let toString = t =>
switch t {
| Decorators => "Decorators"
| Operators => "Operators"
| LanguageConstructs => "Language Constructs"
| SpecialValues => "Special Values"
| ControlFlow => "Control Flow"
| Other => "Other"
Expand All @@ -48,6 +49,7 @@ module Category = {
| "controlflow" => ControlFlow
| "specialvalues" => SpecialValues
| "operators" => Operators
| "languageconstructs" => LanguageConstructs
| _ => Other
}
}
Expand Down Expand Up @@ -241,6 +243,7 @@ let make = () => {
let initial = [
Decorators,
Operators,
LanguageConstructs,
ControlFlow,
SpecialValues,
Other,
Expand Down