From 60caac45ab53345076f3e73a30d1007d24096b12 Mon Sep 17 00:00:00 2001 From: Jonatan Heyman Date: Tue, 26 Dec 2023 01:31:36 +0100 Subject: [PATCH] Add TOML support --- README.md | 1 + public/langdetect-worker.js | 1 + src/editor/lang-heynote/heynote.grammar | 2 +- src/editor/lang-heynote/parser.js | 2 +- src/editor/languages.js | 7 +++++++ tests/language-detection.spec.js | 16 ++++++++++++++++ 6 files changed, 27 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b9e8fa6..fa4e2db 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ Available for Mac, Windows, and Linux. - JavaScript - JSX - TypeScript + - TOML - TSX - JSON - Lezer diff --git a/public/langdetect-worker.js b/public/langdetect-worker.js index 127e430..9712d63 100644 --- a/public/langdetect-worker.js +++ b/public/langdetect-worker.js @@ -21,6 +21,7 @@ GUESSLANG_LANGUAGES = [ "go", "clj", "erl", + "toml", ] const guessLang = new self.GuessLang() diff --git a/src/editor/lang-heynote/heynote.grammar b/src/editor/lang-heynote/heynote.grammar index 84ae21e..292842b 100644 --- a/src/editor/lang-heynote/heynote.grammar +++ b/src/editor/lang-heynote/heynote.grammar @@ -11,7 +11,7 @@ NoteDelimiter { @tokens { noteDelimiterMark { "∞∞∞" } - NoteLanguage { "text" | "math" | "javascript" | "typescript" | "jsx" | "tsx" | "json" | "python" | "html" | "sql" | "markdown" | "java" | "php" | "css" | "xml" | "cpp" | "rust" | "csharp" | "ruby" | "shell" | "yaml" | "golang" | "clojure" | "erlang" | "lezer" } + NoteLanguage { "text" | "math" | "javascript" | "typescript" | "jsx" | "tsx" | "json" | "python" | "html" | "sql" | "markdown" | "java" | "php" | "css" | "xml" | "cpp" | "rust" | "csharp" | "ruby" | "shell" | "yaml" | "golang" | "clojure" | "erlang" | "lezer" | "toml" } Auto { "-a" } noteDelimiterEnter { "\n" } //NoteContent { String } diff --git a/src/editor/lang-heynote/parser.js b/src/editor/lang-heynote/parser.js index 908676d..d73968c 100644 ---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i)w#l#m$}#m#n*v%&x%&y*|~!YOX~~!]P#T#U!`~!eOU~~!hR#`#a!q#d#e#f#g#h#l~!tP#c#d!w~!zP#^#_!}~#QP#i#j#T~#WP#f#g#Z~#^P#X#Y#a~#fOT~~#iP#d#e#a~#oQ#[#]#u#g#h#a~#xP#T#U#{~$OP#f#g#f~$UP#f#g$X~$[P#`#a$_~$bP#T#U$e~$hP#b#c$k~$nP#Z#[#a~$tP#c#d$X~$zP#h#i$}~%QP#a#b%T~%WP#`#a#a~%^Q#T#U%d#g#h&h~%gP#j#k%j~%mP#T#U%p~%uPT~#g#h%x~%{P#V#W&O~&RP#f#g&U~&XP#]#^&[~&_P#d#e&b~&eP#h#i#a~&kQ#c#d&q#l#m#a~&tP#b#c#a~&zP#X#Y&}~'QP#n#o'T~'WP#X#Y'Z~'^P#f#g#a~'dP#T#U'g~'jQ#f#g'p#h#i(Y~'sP#_#`'v~'yP#W#X'|~(PP#c#d(S~(VP#k#l&q~(]P#[#]#a~(cQ#[#]#f#m#n(i~(lP#h#i(o~(rP#[#](u~(xP#c#d&q~)OP#i#j)R~)UQ#U#V)[#g#h&b~)_P#m#n#a~)eQ#[#])k#e#f%T~)nP#X#Y)q~)tP#`#a%T~)zS#X#Y*W#c#d$}#g#h*^#m#n*d~*ZP#l#m&b~*aP#l#m#a~*gP#d#e*j~*mP#X#Y*p~*sP#g#h%x~*yP#T#U$}~+PP%&x%&y+S~+VP%&x%&y+Y~+_OY~", tokenizers: [0, noteContent], topRules: {"Document":[0,2]}, tokenPrec: 0 diff --git a/src/editor/languages.js b/src/editor/languages.js index f07824a..c7f5848 100644 --- a/src/editor/languages.js +++ b/src/editor/languages.js @@ -20,6 +20,7 @@ import { yaml } from "@codemirror/legacy-modes/mode/yaml" import { go } from "@codemirror/legacy-modes/mode/go" import { clojure } from "@codemirror/legacy-modes/mode/clojure" import { erlang } from "@codemirror/legacy-modes/mode/erlang" +import { toml } from "@codemirror/legacy-modes/mode/toml" import typescriptPlugin from "prettier/plugins/typescript.mjs" import babelPrettierPlugin from "prettier/plugins/babel.mjs" @@ -165,6 +166,12 @@ export const LANGUAGES = [ guesslang: "yaml", prettier: {parser:"yaml", plugins: [yamlPrettierPlugin]}, }), + new Language({ + token: "toml", + name: "TOML", + parser: StreamLanguage.define(toml).parser, + guesslang: "toml", + }), new Language({ token: "golang", name: "Go", diff --git a/tests/language-detection.spec.js b/tests/language-detection.spec.js index ae625f4..6d5868d 100644 --- a/tests/language-detection.spec.js +++ b/tests/language-detection.spec.js @@ -37,3 +37,19 @@ print('The solution are {0} and {1}'.format(sol1,sol2)) `) await expect(page.locator("css=.status .status-block.lang")).toHaveText("Python (auto)") }) + +test("TOML detection", async ({ page }) => { + await page.locator("body").pressSequentially(` +[build-system] +requires = ["setuptools>=61", "wheel", "setuptools_scm>=6.2"] +build-backend = "setuptools.build_meta" + +[project] +name = "locust" +license = { text = "MIT" } +description = "Developer friendly load testing framework" +dynamic = ["version"] +requires-python = ">=3.8" +`) + await expect(page.locator("css=.status .status-block.lang")).toHaveText("TOML (auto)") +})