Skip to content
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

Syntax lookup tool #114

Merged
merged 82 commits into from
Jan 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
8d0366d
Add github-slugger bindings
ryyppy Nov 18, 2020
77b0a27
Add syntax lookup widget / page
ryyppy Nov 18, 2020
4163453
Add uncurried function misc docs
ryyppy Nov 18, 2020
02b6da1
Improved Searchbox / UI
ryyppy Nov 18, 2020
8de27ee
Improve text input focus tabbing, fix React key errors
ryyppy Nov 19, 2020
213668c
Use common SearchBox
ryyppy Dec 30, 2020
7a04b3c
Fix import
ryyppy Jan 2, 2021
0a7d303
Add item.id to use as syntax lookup widget slug
Jan 3, 2021
90ee93f
Merge pull request #163 from kevanstannard/syntax-lookup-widget-slug
ryyppy Jan 3, 2021
0c52467
Add basic operators to the syntax widget
Jan 4, 2021
1da0c4a
Add metadata to frontmatter
Jan 4, 2021
bd2a478
Merge pull request #165 from kevanstannard/syntax-widget-basic-operators
ryyppy Jan 4, 2021
ee0e39b
Syntax lookup dynamic include
Jan 5, 2021
d522445
Add extract-syntax to update-index script
Jan 5, 2021
6bc52ba
Remove unused remark-slug import
Jan 5, 2021
f4c479b
Remove unnecessary catch
Jan 5, 2021
c5551ab
Merge pull request #170 from kevanstannard/syntax-lookup-dynamic-include
ryyppy Jan 5, 2021
8baa22d
Add get decorator syntax
Jan 8, 2021
4987d0a
Add set decorator syntax
Jan 8, 2021
f1f36e8
Add set index decorator syntax
Jan 8, 2021
916b5d0
Add get index decorator syntax
Jan 8, 2021
f288353
Add val decorator syntax
Jan 8, 2021
622dd12
Add new decorator syntax
Jan 8, 2021
dfe1cda
Add send decorator syntax
Jan 8, 2021
33a7370
Add scope decorator syntax
Jan 8, 2021
46a97e8
Add string decorator syntax
Jan 8, 2021
1cb11a3
Add int decorator syntax
Jan 8, 2021
3557fa6
Add unwrap decorator syntax
Jan 8, 2021
49a7b7d
Add as decorator syntax
Jan 8, 2021
55d7ff3
Add module decorator syntax
Jan 8, 2021
c5332f5
Tweak as decorator syntax
Jan 8, 2021
f9d4ea3
Tweak get decorator syntax
Jan 8, 2021
c5bd2f9
Tweak get index decorator syntax
Jan 8, 2021
37ca04e
Tweak get index decorator syntax
Jan 8, 2021
d60db1f
Tweak int decorator syntax
Jan 8, 2021
f24d471
Tweak string decorator syntax
Jan 8, 2021
f73643e
Tweak module decorator syntax
Jan 8, 2021
c674341
Tweak new decorator syntax
Jan 8, 2021
43b6e34
Tweak scope decorator syntax
Jan 8, 2021
b6502fb
Tweak send decorator syntax
Jan 8, 2021
6f53ab3
Tweak set index decorator syntax
Jan 8, 2021
ff5f05e
Tweak set decorator syntax
Jan 8, 2021
f424dd0
Tweak unwrap decorator syntax
Jan 8, 2021
ae11d2a
Tweak val decorator syntax
Jan 8, 2021
3af0c98
Add deriving decorator syntax
Jan 8, 2021
00e08c8
Tweak as decorator syntax
Jan 8, 2021
ff60735
Tweak string decorator syntax
Jan 8, 2021
0f08e50
Add variadic decorator syntax
Jan 8, 2021
a225816
Add inline decorator syntax
Jan 8, 2021
1218319
Add meth decorator syntax
Jan 8, 2021
fc454f5
Add return decorator syntax
Jan 8, 2021
1c43255
Enable wrapping of tags
Jan 8, 2021
5e51a46
Update syntax lookup meta
Jan 8, 2021
e8c8ba0
Add unboxed decorator syntax
Jan 8, 2021
520155f
Apply suggestions from code review
kevanstannard Jan 8, 2021
2bb206e
Replace "re" with "res" in code snippet types
Jan 8, 2021
6cc597e
Tweak as decorator
Jan 9, 2021
037a8a1
Tweak as decorator
Jan 9, 2021
bf26f7e
Simplify the deriving decorator
Jan 9, 2021
b5ece09
Tweak as decorator formatting
Jan 9, 2021
8de8283
Update get and set decorators
Jan 9, 2021
3a2f7f4
Update inline decorator
Jan 9, 2021
0684575
Update int decorator
Jan 9, 2021
98b316d
Simplify meth decorator
Jan 9, 2021
e248f6d
Update module decorator
Jan 9, 2021
f634206
Simplify new decorator
Jan 9, 2021
8d58c6c
Simplify return decorator
Jan 9, 2021
c764884
Update scope decorator
Jan 9, 2021
0be5313
Update send decorator
Jan 9, 2021
7598d86
Update string and int decorators
Jan 9, 2021
3a779bf
Update unboxed
Jan 9, 2021
43e81dc
Update unwrap decorator
Jan 9, 2021
1d02953
Update val decorator
Jan 9, 2021
9be40cf
Update variadic decorator
Jan 9, 2021
5141b49
Clean up, standardise, simplify
Jan 9, 2021
f0bc375
Update val decorator
Jan 9, 2021
97ddb3a
Add obj decorator
Jan 9, 2021
f8b7a78
Fix deriving typo
Jan 9, 2021
3aa8029
Merge pull request #177 from kevanstannard/syntax-lookup-decorators
ryyppy Jan 9, 2021
dad2200
SyntaxLookupWidget -> src/SyntaxLookup
ryyppy Jan 9, 2021
9138922
Activate href checks for misc_docs
ryyppy Jan 9, 2021
4186122
Add hover behavior for item tags
ryyppy Jan 9, 2021
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
20 changes: 20 additions & 0 deletions misc_docs/syntax/controlflow_ifelse.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
id: "if-else"
keywords: ["if", "else"]
name: "if / else"
summary: "This is the `if / else` control flow."
category: "controlflow"
---

Use `if / else` expressions to express a value trough a `true` / `false` condition.

```res
let user = "Anna"
let ret = if user === "Anna" {
"Hi Anna!"
}
else {
"Hi unknown!"
}
```
36 changes: 36 additions & 0 deletions misc_docs/syntax/decorator_as.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
id: "as-decorator"
keywords: ["as", "decorator"]
name: "@as"
summary: "This is the `@as` decorator."
category: "decorators"
---

The `@as` decorator is commonly used on record types to alias record field names to a different JavaScript attribute name.

This is useful to map to JavaScript attribute names that cannot be expressed in ReScript (such as keywords).

### Example

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

```res
type action = {
@as("type") type_: string
}
let action = {type_: "ADD_USER"}
```

```js
var action = {
type: "ADD_USER"
};
```

</CodeTab>

### References

* [Constrain Arguments Better](/docs/manual/latest/bind-to-js-function#constrain-arguments-better)
* [Fixed Arguments](/docs/manual/latest/bind-to-js-function#fixed-arguments)
52 changes: 52 additions & 0 deletions misc_docs/syntax/decorator_deriving.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
id: "deriving-decorator"
keywords: ["deriving", "decorator"]
name: "@deriving"
summary: "This is the `@deriving` decorator."
category: "decorators"
---

When the `@deriving` decorator is applied to a **record** type,
it expands the type into a factory function plus a set of
getter/setter functions for its fields.

> Note that this is an outdated decorator and you may no longer need to use it.
> See [Convert Record Type to Abstract Record](/docs/manual/latest/generate-converters-accessors#convert-record-type-to-abstract-record) for more details.
### Example

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

```res
@deriving(abstract)
type person = {
name: string,
age: int,
job: string,
}
let joe = person(~name="Joe", ~age=20, ~job="teacher")
let joeName = nameGet(joe)
let joeAge = ageGet(joe)
let joeJob = jobGet(joe)
```

```js
var joe = {
name: "Joe",
age: 20,
job: "teacher"
};

var joeName = joe.name;
var joeAge = joe.age;
var joeJob = joe.job;
```

</CodeTab>

### References

* [Convert Record Type to Abstract Record](/docs/manual/latest/generate-converters-accessors#convert-record-type-to-abstract-record)

31 changes: 31 additions & 0 deletions misc_docs/syntax/decorator_get.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
id: "get-decorator"
keywords: ["get", "decorator"]
name: "@get"
summary: "This is the `@get` decorator."
category: "decorators"
---

The `@get` decorator is used to bind to a property of an object.

### Example

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

```res
type window
@bs.val external window: window = "window"
@bs.get external getName: window => string = "name"
let name = getName(window)
```

```js
var name = window.name;
```

</CodeTab>

### References

- [Bind using Special `@bs` Getters & Setters](/docs/manual/latest/bind-to-js-object#bind-using-special-bs-getters--setters)
45 changes: 45 additions & 0 deletions misc_docs/syntax/decorator_get_index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
id: "get-index-decorator"
keywords: ["get", "index", "decorator"]
name: "@get_index"
summary: "This is the `@get_index` decorator."
category: "decorators"
---

The `@get_index` decorator is used to access a dynamic property on an object,
or an index of an array.

### Example

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

```res
type t

@new external create: unit => t = "Object"
@set_index external set: (t, string, int) => unit = ""
@get_index external get: (t, string) => int = ""

let o = create()
o->set("x", 1)
o->set("y", 3)
o->set("z", 5)

let value = o->get("y")
```

```js
var o = new Object();

o["x"] = 1;
o["y"] = 3;
o["z"] = 5;

var value = o["y"];
```

</CodeTab>

### References

- [Bind using Special `@bs` Getters & Setters](/docs/manual/latest/bind-to-js-object#bind-using-special-bs-getters--setters)
39 changes: 39 additions & 0 deletions misc_docs/syntax/decorator_inline.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
id: "inline-decorator"
keywords: ["inline", "decorator"]
name: "@inline"
summary: "This is the `@inline` decorator."
category: "decorators"
---

The `@inline` decorator tells the compiler to inline its value
in every place the binding is being used, rather than use a variable.

### Example

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

```res
module Colors = {
@inline
let green = "green"
@inline
let red = "red"
}
let allowedColors = [Colors.green, Colors.red]
```

```js
var allowedColors = [
"green",
"red"
];
```

</CodeTab>

### References

- [Inlining Constants](/docs/manual/latest/inlining-constants)
35 changes: 35 additions & 0 deletions misc_docs/syntax/decorator_int.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
id: "int-decorator"
keywords: ["int", "decorator"]
name: "@int"
summary: "This is the `@int` decorator."
category: "decorators"
---

The `@int` decorator can be used with [polymorphic variants](/docs/manual/latest/polymorphic-variant) and the `@as` decorator on *externals* to modify the compiled JavaScript to use integers for the values instead of strings.

### Example

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

```res
@val external setStatus: @int[
@as(0) #NotStarted |
@as(1) #Started |
@as(2) #Done
] => unit = "setStatus"
setStatus(#Done)
```

```js
setStatus(2);
```

</CodeTab>

### References

* [Constrain Arguments Better](/docs/manual/latest/bind-to-js-function#constrain-arguments-better)


45 changes: 45 additions & 0 deletions misc_docs/syntax/decorator_meth.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
id: "meth-decorator"
keywords: ["meth", "decorator"]
name: "@meth"
summary: "This is the `@meth` decorator."
category: "decorators"
---

The `@meth` decorator is used to call a function on a JavaScript object,
and avoid issues with currying.

### Example

Suppose we have the following JavaScript:

```js
function say (a, b) {
console.log(a, b);
};

var john = {
say
};
```

We can model and bind to this object as follows.

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

```res
type person = {@meth "say": (string, string) => unit}
@val external john: person = "john"
john["say"]("hey", "jude")
```

```js
john.say("hey", "jude");
```

</CodeTab>



32 changes: 32 additions & 0 deletions misc_docs/syntax/decorator_module.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
id: "module-decorator"
keywords: ["module", "decorator"]
name: "@module"
summary: "This is the `@module` decorator."
category: "decorators"
---

The `@module` decorator is used to bind to a JavaScript module.

### Example

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

```res
@module("path")
external dirname: string => string = "dirname"
let root = dirname("/User/github")
```

```js
var Path = require("path");

var root = Path.dirname("/User/github");
```

</CodeTab>

### References

* [Import from JavaScript](/docs/manual/latest/import-from-export-to-js#import-from-javascript)
32 changes: 32 additions & 0 deletions misc_docs/syntax/decorator_new.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
id: "new-decorator"
keywords: ["new", "decorator"]
name: "@new"
summary: "This is the `@new` decorator."
category: "decorators"
---

The `@new` decorator is used whenever you need to bind to a JavaScript
class constructor that requires the `new` keword for instantiation.

### Example

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

```res
type t
@new external create: unit => t = "Date"
let now = create()
```

```js
var now = new Date();
```

</CodeTab>

### References

* [Bind to a JS Object That's a Class](/docs/manual/latest/bind-to-js-object#bind-to-a-js-object-thats-a-class)
Loading