Skip to content

Add basic operators to the syntax widget #165

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 2 commits into from
Jan 4, 2021
Merged
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
23 changes: 23 additions & 0 deletions misc_docs/syntax/operators_float_addition.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
id: "float-addition"
keywords: ["plus", "add", "addition", "sum", "float"]
name: "+."
summary: "This is the `floating point addition` operator."
category: "operators"
---

This operator performs *floating point* addition.

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

```res
let result = 1.3 +. 0.5
```

```js
var result = 1.3 + 0.5;
```

</CodeTab>

For adding *integers* see the `+` operator.
23 changes: 23 additions & 0 deletions misc_docs/syntax/operators_float_division.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
id: "float-division"
keywords: ["divide", "division", "float"]
name: "/."
summary: "This is the `floating point division` operator."
category: "operators"
---

This operator performs *floating point* division.

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

```res
let result = 3.0 /. 2.5
```

```js
var result = 3.0 / 2.5;
```

</CodeTab>

For dividing *integers* see the `/` operator.
23 changes: 23 additions & 0 deletions misc_docs/syntax/operators_float_multiplication.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
id: "float-multiplication"
keywords: ["multiply", "multiplication", "float"]
name: "*."
summary: "This is the `floating point multiplication` operator."
category: "operators"
---

This operator performs *floating point* multiplication.

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

```res
let result = 1.5 *. 2.3
```

```js
var result = 1.5 * 2.3;
```

</CodeTab>

For multiplying *integers* see the `*` operator.
23 changes: 23 additions & 0 deletions misc_docs/syntax/operators_float_subtraction.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
id: "float-subtraction"
keywords: ["subtract", "minus", "subtraction", "float"]
name: "-."
summary: "This is the `floating point subtraction` operator."
category: "operators"
---

This operator performs *floating point* subtraction.

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

```res
let result = 3.0 -. 2.5
```

```js
var result = 3.0 - 2.5;
```

</CodeTab>

For subtracting *integers* see the `-` operator.
25 changes: 25 additions & 0 deletions misc_docs/syntax/operators_integer_addition.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
id: "integer-addition"
keywords: ["plus", "add", "addition", "sum", "int", "integer"]
name: "+"
summary: "This is the `integer addition` operator."
category: "operators"
---

This operator performs *integers* addition.

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

```res
let result = 1 + 2
```

```js
val result = 3;
```

</CodeTab>

For adding *floats* see the `+.` operator.

For contatenating *strings* see the `++` operator.
25 changes: 25 additions & 0 deletions misc_docs/syntax/operators_integer_division.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
id: "integer-division"
keywords: ["divide", "division", "int", "integer"]
name: "/"
summary: "This is the `integer division` operator."
category: "operators"
---

This operator performs *integer* division, with the result truncated to an integer value.

If the second argument is *zero* then a `Division_by_zero` exception is thrown. Refer to the [Exception](/docs/manual/latest/exception) section for handling exceptions.

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

```res
let result = 3 / 2
```

```js
var result = 1;
```

</CodeTab>

For dividing *floats* see the `/.` operator.
23 changes: 23 additions & 0 deletions misc_docs/syntax/operators_integer_multiplication.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
id: "integer-multiplication"
keywords: ["multiply", "multiplication", "int", "integer"]
name: "*"
summary: "This is the `integer multiplication` operator."
category: "operators"
---

This operator performs *integer* multiplication.

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

```res
let result = 2 * 3
```

```js
var result = 6;
```

</CodeTab>

For multiplying *floats* see the `*.` operator.
23 changes: 23 additions & 0 deletions misc_docs/syntax/operators_integer_subtraction.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
id: "integer-subtraction"
keywords: ["subtract", "minus", "subtraction", "int", "integer"]
name: "-"
summary: "This is the `integer subtraction` operator."
category: "operators"
---

This operator performs *integer* subtraction.

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

```res
let result = 3 - 2
```

```js
var result = 1;
```

</CodeTab>

For subtracting *floats* see the `-.` operator.
23 changes: 23 additions & 0 deletions misc_docs/syntax/operators_string_concatenation.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
id: "string-concatenation"
keywords: ["concat", "concatenation", "add", "string"]
name: "++"
summary: "This is the `string concatenation` operator."
category: "operators"
---

This operator concatenates two *strings* together.

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

```res
let greetings = "Hello " ++ "world!"
```

```js
var greetings = "Hello world!";
```

</CodeTab>


128 changes: 128 additions & 0 deletions src/components/SyntaxLookupWidget.js

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

99 changes: 99 additions & 0 deletions src/components/SyntaxLookupWidget.res
Original file line number Diff line number Diff line change
@@ -23,6 +23,33 @@ external decorator_as: MdxComp.t = "default"
@module("misc_docs/syntax/controlflow_ifelse.mdx")
external controlflow_ifelse: MdxComp.t = "default"

@module("misc_docs/syntax/operators_integer_addition.mdx")
external operators_integer_addition: MdxComp.t = "default"

@module("misc_docs/syntax/operators_integer_subtraction.mdx")
external operators_integer_subtraction: MdxComp.t = "default"

@module("misc_docs/syntax/operators_integer_multiplication.mdx")
external operators_integer_multiplication: MdxComp.t = "default"

@module("misc_docs/syntax/operators_integer_division.mdx")
external operators_integer_division: MdxComp.t = "default"

@module("misc_docs/syntax/operators_float_addition.mdx")
external operators_float_addition: MdxComp.t = "default"

@module("misc_docs/syntax/operators_float_subtraction.mdx")
external operators_float_subtraction: MdxComp.t = "default"

@module("misc_docs/syntax/operators_float_multiplication.mdx")
external operators_float_multiplication: MdxComp.t = "default"

@module("misc_docs/syntax/operators_float_division.mdx")
external operators_float_division: MdxComp.t = "default"

@module("misc_docs/syntax/operators_string_concatenation.mdx")
external operators_string_concatenation: MdxComp.t = "default"

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

@@ -87,6 +114,78 @@ let allItems = [
category: Other,
component: controlflow_ifelse,
},
{
id: "integer-addition",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this data is good for drafting and testing, but since we will include a ton of syntax constructs, I am pretty sure that this will not scale on a bundle level, so we need to factor everything out into some server side rendered solution of some sort.

So what I think would be best is to put the metadata in the frontmatter of each syntax construct file, e.g. operators_integer_addition.mdx:

---
id: "integer-addition"
keywords: ["plus", "add", "addition", "sum", "int", "integer"]
name: "+"
summary: "This is the `integer addition` operator."
category: "operators"
---

You can of course still hook your components up with the SyntaxLookupWidget to test your keywords, but we will remove that code pretty soon later on, just so you know.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ryyppy that makes sense, updated.

keywords: ["plus", "add", "addition", "sum", "int", "integer"],
name: "+",
summary: "This is the `integer addition` operator.",
category: Operators,
component: operators_integer_addition,
},
{
id: "integer-subtraction",
keywords: ["subtract", "minus", "subtraction", "int", "integer"],
name: "-",
summary: "This is the `integer subtraction` operator.",
category: Operators,
component: operators_integer_subtraction,
},
{
id: "integer-multiplication",
keywords: ["multiply", "multiplication", "int", "integer"],
name: "*",
summary: "This is the `integer multiplication` operator.",
category: Operators,
component: operators_integer_multiplication,
},
{
id: "integer-division",
keywords: ["divide", "division", "int", "integer"],
name: "/",
summary: "This is the `integer division` operator.",
category: Operators,
component: operators_integer_division,
},
{
id: "float-addition",
keywords: ["plus", "add", "addition", "sum", "float"],
name: "+.",
summary: "This is the `floating point addition` operator.",
category: Operators,
component: operators_float_addition,
},
{
id: "float-subtraction",
keywords: ["subtract", "minus", "subtraction", "float"],
name: "-.",
summary: "This is the `floating point subtraction` operator.",
category: Operators,
component: operators_float_subtraction,
},
{
id: "float-multiplication",
keywords: ["multiply", "multiplication", "float"],
name: "*.",
summary: "This is the `floating point multiplication` operator.",
category: Operators,
component: operators_float_multiplication,
},
{
id: "float-division",
keywords: ["divide", "division", "float"],
name: "/.",
summary: "This is the `floating point division` operator.",
category: Operators,
component: operators_float_division,
},
{
id: "string-concatenation",
keywords: ["concat", "concatenation", "add", "string"],
name: "++",
summary: "This is the `string concatenation` operator.",
category: Operators,
component: operators_string_concatenation,
},
]

let fuseOpts = Fuse.Options.t(