Adapt languages to new syntax token scheme

This commit is contained in:
Nilay Majorwar 2022-02-03 22:39:02 +05:30
parent 24c384c4a8
commit 8d979ef111
5 changed files with 45 additions and 26 deletions

View File

@ -66,13 +66,13 @@ export const sampleProgram = [
export const editorTokensProvider: MonacoTokensProvider = { export const editorTokensProvider: MonacoTokensProvider = {
tokenizer: { tokenizer: {
root: [ root: [
[/[\>\^<v\?]/, "red"], [/[\>\^<v\?]/, "variable"],
[/[\+\-\*\/%!`]/, "orange"], [/[\+\-\*\/%!`]/, "operators"],
[/[|_]/, "blue"], [/[|_]/, "meta"],
[/[":\\#]/, "green"], [/[":\\#]/, "tag"],
[/[\$\.,]/, "violet"], [/[\$\.,]/, "keyword"],
[/[gp@]/, "indigo"], [/[gp@]/, "attribute"],
[/[&~0-9]/, "turquoise"], [/[&~0-9]/, "string"],
], ],
}, },
defaultToken: "plain", defaultToken: "plain",

View File

@ -71,10 +71,10 @@ export const sampleProgram = [
export const editorTokensProvider: MonacoTokensProvider = { export const editorTokensProvider: MonacoTokensProvider = {
tokenizer: { tokenizer: {
root: [ root: [
[/[-\+]/, "plain"], [/[-\+]/, ""],
[/[<>]/, "green"], [/[<>]/, "tag"],
[/[\[\]]/, "violet"], [/[\[\]]/, "keyword"],
[/[\,\.]/, "orange"], [/[\,\.]/, "identifier"],
], ],
}, },
defaultToken: "comment", defaultToken: "comment",

View File

@ -27,10 +27,6 @@ const styles: { [k: string]: CSSProperties } = {
justifyContent: "center", justifyContent: "center",
alignItems: "center", alignItems: "center",
}, },
activeCell: {
background: "#CED9E0",
color: "#182026",
},
}; };
/** Component for displaying a single tape cell */ /** Component for displaying a single tape cell */

View File

@ -17,7 +17,8 @@ export const isSyntaxError = (error: any): error is SyntaxError => {
export const sampleProgram = [ export const sampleProgram = [
"Hello World Souffle.", "Hello World Souffle.",
"", "",
'This recipe prints the immortal words "Hello world!", in a basically brute force way. It also makes a lot of food for one person.', 'This recipe prints the immortal words "Hello world!", in a basically ',
"brute force way. It also makes a lot of food for one person.",
"", "",
"Ingredients.", "Ingredients.",
"72 g haricot beans", "72 g haricot beans",
@ -49,15 +50,37 @@ export const sampleProgram = [
"Serves 1.", "Serves 1.",
].join("\n"); ].join("\n");
/** Syntax highlighting provider */
export const editorTokensProvider: MonacoTokensProvider = { export const editorTokensProvider: MonacoTokensProvider = {
tokenizer: { tokenizer: {
root: [ root: [
[/Ingredients./, "red"], [/^\s*$/, { token: "" }],
[/Method./, "red"], [/^.+$/, { token: "variable.function", next: "@recipe" }],
[/mixing bowl/, "green"], ],
[/baking dish/, "blue"], recipe: [
[/\d(st|nd|rd|th)?/, "orange"], [/^\s*Ingredients\.\s*$/, { token: "annotation", next: "@ingredients" }],
[/^\s*Method\.\s*$/, { token: "annotation", next: "@method" }],
[
/(^\s*)(Serves )(\d+)(\.\s*$)/,
["", "", "number", { token: "", next: "@popall" }] as any,
],
[/^.+$/, { token: "comment" }],
],
ingredients: [
[/\d+/, "number"],
[/ (g|kg|pinch(?:es)?|ml|l|dash(?:es)?) /, "type"],
[/ ((heaped|level) )?(cups?|teaspoons?|tablespoons?) /, "type"],
[/^\s*$/, { token: "", next: "@pop" }],
],
method: [
[/mixing bowl/, "tag"],
[/baking dish/, "meta"],
[
/(^|\.\s*)(Take|Put|Fold|Add|Remove|Combine|Divide|Liquefy|Stir|Mix|Clean|Pour|Set aside|Serve with|Refrigerate)($| )/,
["", "keyword", ""],
],
[/^\s*$/, { token: "", next: "@pop" }],
], ],
}, },
defaultToken: "plain", defaultToken: "",
}; };

View File

@ -35,10 +35,10 @@ export const sampleProgram = [
export const editorTokensProvider: MonacoTokensProvider = { export const editorTokensProvider: MonacoTokensProvider = {
tokenizer: { tokenizer: {
root: [ root: [
[/i/, "orange"], [/i/, "identifier"],
[/d/, "red"], [/d/, "variable"],
[/s/, "blue"], [/s/, "meta"],
[/o/, "green"], [/o/, "tag"],
], ],
}, },
defaultToken: "comment", defaultToken: "comment",