Skip to content

Commit

Permalink
Syntax highlighting and hello world
Browse files Browse the repository at this point in the history
  • Loading branch information
Rigidity committed Jul 6, 2024
1 parent 82d61fc commit ec6f4c6
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 3 deletions.
21 changes: 21 additions & 0 deletions docs/getting-started/hello-world.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
slug: /hello-world
---

# Hello World

The simplest example of a program in Rue is the classic hello world example.

Write the following program in a file named `hello.rue`:

```rue title="hello.rue"
fun main() -> Bytes {
"Hello, world!"
}
```

Now, run the following command to run the file:

```bash
rue build hello.rue --run
```
6 changes: 6 additions & 0 deletions docs/getting-started/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ You can install the Rue CLI with this command:
cargo install rue-cli
```

It's also useful to install [clvm_tools_rs](https://github.com/Chia-Network/clvm_tools_rs):

```bash
cargo install clvm_tools_rs
```

## VSCode

Currently the only editor with support for Rue is [Visual Studio Code](https://code.visualstudio.com).
Expand Down
2 changes: 1 addition & 1 deletion docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const config: Config = {
},
prism: {
theme: prismThemes.github,
darkTheme: prismThemes.dracula,
darkTheme: prismThemes.oneDark,
additionalLanguages: ["bash"],
},
} satisfies Preset.ThemeConfig,
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@
"@mdx-js/react": "^3.0.0",
"clsx": "^2.0.0",
"prism-react-renderer": "^2.3.0",
"prismjs": "^1.29.0",
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"devDependencies": {
"@docusaurus/module-type-aliases": "3.4.0",
"@docusaurus/tsconfig": "3.4.0",
"@docusaurus/types": "3.4.0",
"@types/prismjs": "^1.26.4",
"prettier": "^3.3.2",
"typescript": "~5.2.2"
"typescript": "~5.2.2",
"utility-types": "^3.11.0"
},
"browserslist": {
"production": [
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

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

2 changes: 1 addition & 1 deletion sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const sidebars: SidebarsConfig = {
{
type: "category",
label: "Getting Started",
items: ["getting-started/installation"],
items: ["getting-started/installation", "getting-started/hello-world"],
},
],
};
Expand Down
27 changes: 27 additions & 0 deletions src/theme/prism-include-languages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import siteConfig from "@generated/docusaurus.config";
import type * as PrismNamespace from "prismjs";
import type { Optional } from "utility-types";

export default function prismIncludeLanguages(
PrismObject: typeof PrismNamespace,
): void {
const {
themeConfig: { prism },
} = siteConfig;
const { additionalLanguages } = prism as { additionalLanguages: string[] };

globalThis.Prism = PrismObject;

additionalLanguages.forEach((lang) => {
if (lang === "php") {
// eslint-disable-next-line global-require
require("prismjs/components/prism-markup-templating.js");
}
// eslint-disable-next-line global-require, import/no-dynamic-require
require(`prismjs/components/prism-${lang}`);
});

require("./prism-rue");

delete (globalThis as Optional<typeof globalThis, "Prism">).Prism;
}
56 changes: 56 additions & 0 deletions src/theme/prism-rue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
Prism.languages.rue = {
function: {
pattern: /(\bfun\s+)[a-zA-Z_][a-zA-Z0-9_]*/,
lookbehind: true,
},
"function-call": {
pattern: /\b[a-zA-Z_][a-zA-Z0-9_]*(?=\s*(?:\(|<.*?>\())/,
alias: "function",
},
field: {
pattern: /\b[a-zA-Z_][a-zA-Z0-9_]*(?=\s*:)/,
alias: "property",
},
"field-access": {
pattern: /\b(\.)([a-zA-Z_][a-zA-Z0-9_]*)/,
lookbehind: true,
alias: "property",
},
string: {
pattern: /"[^"]*"/,
lookbehind: true,
greedy: true,
},
comment: {
pattern: /\/\/.*|\/\*[^]*?\*\//,
multiline: true,
greedy: true,
},
number: /\b[0-9][0-9_]*\b/,
operator: /[+\-*?%!\^]|<[<=]?|>[>=]?|=[=>]?|!=?|\.(?:\.\.)?|::|->?|&&?|\|\|?/,
punctuation: /[(){}[\],:]/,
"control-flow": {
pattern: /\b(?:if|else|return|raise|assert|assume)\b/,
alias: "keyword",
},
binding: {
pattern: /\b(?:let|const|fun)\b/,
alias: "keyword",
},
type: {
pattern: /\b(?:type|struct|enum|as|is)\b/,
alias: "keyword",
},
module: {
pattern: /\b(?:import|mod)\b/,
alias: "keyword",
},
modifier: { pattern: /\b(?:inline|export)\b/, alias: "keyword" },
boolean: /\b(?:false|true)\b/,
null: {
pattern: /\bnil\b/,
alias: "constant",
},
builtin: /\b(?:Int|Any|Bytes32|Bytes|PublicKey|Nil|Bool)\b/,
"class-name": /\b[A-Z][a-z][a-zA-Z0-9_]*\b/,
};

0 comments on commit ec6f4c6

Please sign in to comment.