Skip to content

Commit

Permalink
Add support for more languages:
Browse files Browse the repository at this point in the history
Clojure, Erlang, Golang, Lezer, Ruby, Shell, YAML
  • Loading branch information
heyman committed Dec 25, 2023
1 parent 5318ab8 commit c1ff51f
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 3 deletions.
10 changes: 10 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"@codemirror/lang-sql": "^6.5.4",
"@codemirror/lang-xml": "^6.0.2",
"@codemirror/language": "^6.9.3",
"@codemirror/legacy-modes": "^6.3.3",
"@codemirror/lint": "^6.4.2",
"@codemirror/search": "^6.5.5",
"@codemirror/state": "^6.3.3",
Expand Down
6 changes: 6 additions & 0 deletions public/langdetect-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ GUESSLANG_LANGUAGES = [
"rs",
"md",
"cs",
"rb",
"sh",
"yaml",
"go",
"clj",
"erl",
]

const guessLang = new self.GuessLang()
Expand Down
2 changes: 1 addition & 1 deletion src/editor/lang-heynote/heynote.grammar
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ NoteDelimiter {

@tokens {
noteDelimiterMark { "∞∞∞" }
NoteLanguage { "text" | "math" | "javascript" | "json" | "python" | "html" | "sql" | "markdown" | "java" | "php" | "css" | "xml" | "cpp" | "rust" | "csharp" }
NoteLanguage { "text" | "math" | "javascript" | "json" | "python" | "html" | "sql" | "markdown" | "java" | "php" | "css" | "xml" | "cpp" | "rust" | "csharp" | "ruby" | "shell" | "yaml" | "golang" | "clojure" | "erlang" | "lezer" }
Auto { "-a" }
noteDelimiterEnter { "\n" }
//NoteContent { String }
Expand Down
2 changes: 1 addition & 1 deletion src/editor/lang-heynote/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const parser = LRParser.deserialize({
maxTerm: 10,
skippedNodes: [0],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'Q~'TP#X#Y'W~'ZP#f#g#a~'aP#T#U'd~'gQ#f#g'm#h#i(V~'pP#_#`'s~'vP#W#X'y~'|P#c#d(P~(SP#k#l&n~(YP#[#]#a~(`Q#[#]#f#m#n(f~(iP#h#i(l~(oP#[#]&h~(uP#i#j(x~({Q#U#V)R#g#h&b~)UP#m#n#a~)[Q#[#])b#e#f%T~)eP#X#Y)h~)kP#`#a%T~)qP#X#Y)t~)wP#l#m&b~)}P#T#U$}~*TP%&x%&y*W~*ZP%&x%&y*^~*cOY~",
tokenizers: [0, noteContent],
topRules: {"Document":[0,2]},
tokenPrec: 0
Expand Down
17 changes: 16 additions & 1 deletion src/editor/languages.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ import { xmlLanguage } from "@codemirror/lang-xml"
import { rustLanguage } from "@codemirror/lang-rust"
import { csharpLanguage } from "@replit/codemirror-lang-csharp"

import { StreamLanguage } from "@codemirror/language"
import { ruby } from "@codemirror/legacy-modes/mode/ruby"
import { shell } from "@codemirror/legacy-modes/mode/shell"
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"


class Language {
constructor(token, name, parser, guesslang, supportsFormat = false) {
this.token = token
Expand All @@ -33,11 +42,17 @@ export const LANGUAGES = [
new Language("sql", "SQL", StandardSQL.language.parser, "sql"),
new Language("markdown", "Markdown", markdownLanguage.parser, "md", true),
new Language("java", "Java", javaLanguage.parser, "java"),
//new Language("lezer", "Lezer", lezerLanguage.parser, "lezer"),
new Language("lezer", "Lezer", lezerLanguage.parser, null),
new Language("php", "PHP", phpLanguage.parser, "php"),
new Language("css", "CSS", cssLanguage.parser, "css", true),
new Language("xml", "XML", xmlLanguage.parser, "xml"),
new Language("cpp", "C++", cppLanguage.parser, "cpp"),
new Language("rust", "Rust", rustLanguage.parser, "rust"),
new Language("csharp", "C#", csharpLanguage.parser, "cs"),
new Language("ruby", "Ruby", StreamLanguage.define(ruby).parser, "rb"),
new Language("shell", "Shell", StreamLanguage.define(shell).parser, "sh"),
new Language("yaml", "YAML", StreamLanguage.define(yaml).parser, "yaml"),
new Language("golang", "Go", StreamLanguage.define(go).parser, "go"),
new Language("clojure", "Clojure", StreamLanguage.define(clojure).parser, "clj"),
new Language("erlang", "Erlang", StreamLanguage.define(erlang).parser, "erl"),
]

0 comments on commit c1ff51f

Please sign in to comment.