Skip to content

Commit

Permalink
WIP: adding Elixir
Browse files Browse the repository at this point in the history
  • Loading branch information
jc00ke committed Dec 28, 2024
1 parent ff88091 commit 826f096
Show file tree
Hide file tree
Showing 8 changed files with 353 additions and 300 deletions.
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Apart from the default Scratch buffer, you can now create and switch between mul
* TOML
* C#
* Clojure
* Elixir
* Erlang
* Golang
* Lezer
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Available for Mac, Windows, and Linux.
- Block-based
- Syntax highlighting:

C++, C#, Clojure, CSS, Erlang, Dart, Go, Groovy, HTML, Java, JavaScript, JSX, Kotlin, TypeScript, TOML, TSX, JSON, Lezer, Markdown, PHP, Python, Ruby, Rust, Shell, SQL, Swift, Vue, XML, YAML
C++, C#, Clojure, CSS, Elixir, Erlang, Dart, Go, Groovy, HTML, Java, JavaScript, JSX, Kotlin, TypeScript, TOML, TSX, JSON, Lezer, Markdown, PHP, Python, Ruby, Rust, Shell, SQL, Swift, Vue, XML, YAML

- Language auto-detection
- Auto-formatting
Expand Down
22 changes: 22 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@
"@rollup/plugin-node-resolve": "^15.0.1",
"@types/node": "^20.10.5",
"@vitejs/plugin-vue": "^4.0.0",
"codemirror-lang-elixir": "^4.0.0",
"debounce": "^1.2.1",
"electron": "^31.1.0",
"electron-builder": "^23.6.0",
"electron-builder-notarize": "^1.5.1",
"electron-store": "^8.1.0",
"electron-updater": "^6.1.7",
"fs-jetpack": "^5.1.0",
"lezer-elixir": "^1.1.2",
"prettier": "^3.3.2",
"rollup-plugin-license": "^3.0.1",
"sass": "^1.57.1",
Expand Down
2 changes: 1 addition & 1 deletion public/langdetect-worker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
importScripts("guesslang.min.js")

GUESSLANG_LANGUAGES = ["json","py","html","sql","md","java","php","css","xml","cpp","rs","cs","rb","sh","yaml","toml","go","clj","erl","js","ts","swift","kt","groovy","ps1","dart"]
GUESSLANG_LANGUAGES = ["json","py","html","sql","md","java","php","css","xml","cpp","rs","cs","rb","sh","yaml","toml","go","clj","ex","erl","js","ts","swift","kt","groovy","ps1","dart"]

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" | "typescript" | "jsx" | "tsx" | "json" | "python" | "html" | "sql" | "markdown" | "java" | "php" | "css" | "xml" | "cpp" | "rust" | "csharp" | "ruby" | "shell" | "yaml" | "golang" | "clojure" | "erlang" | "lezer" | "toml" | "swift" | "kotlin" | "groovy" | "diff" | "powershell" | "vue" | "dart" }
NoteLanguage { "text" | "math" | "javascript" | "typescript" | "jsx" | "tsx" | "json" | "python" | "html" | "sql" | "markdown" | "java" | "php" | "css" | "xml" | "cpp" | "rust" | "csharp" | "ruby" | "shell" | "yaml" | "golang" | "clojure" | "elixir" | "erlang" | "lezer" | "toml" | "swift" | "kotlin" | "groovy" | "diff" | "powershell" | "vue" | "dart" }
Auto { "-a" }
noteDelimiterEnter { "\n" }
//NoteContent { String }
Expand Down
75 changes: 40 additions & 35 deletions src/editor/lang-heynote/nested-parser.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,46 @@
import { parseMixed } from "@lezer/common"
import { parseMixed } from "@lezer/common";

import { jsonLanguage } from "@codemirror/lang-json"
import { pythonLanguage } from "@codemirror/lang-python"
import { javascriptLanguage } from "@codemirror/lang-javascript"
import { htmlLanguage } from "@codemirror/lang-html"
import { StandardSQL } from "@codemirror/lang-sql"
import { markdownLanguage } from "@codemirror/lang-markdown"
import { javaLanguage } from "@codemirror/lang-java"
import { lezerLanguage } from "@codemirror/lang-lezer"
import { phpLanguage } from "@codemirror/lang-php"
import { jsonLanguage } from "@codemirror/lang-json";
import { pythonLanguage } from "@codemirror/lang-python";
import { javascriptLanguage } from "@codemirror/lang-javascript";
import { htmlLanguage } from "@codemirror/lang-html";
import { StandardSQL } from "@codemirror/lang-sql";
import { markdownLanguage } from "@codemirror/lang-markdown";
import { javaLanguage } from "@codemirror/lang-java";
import { lezerLanguage } from "@codemirror/lang-lezer";
import { phpLanguage } from "@codemirror/lang-php";
import { elixirLanguage } from "codemirror-lang-elixir";

import { NoteContent, NoteLanguage } from "./parser.terms.js"
import { LANGUAGES } from "../languages.js"

const languageMapping = Object.fromEntries(LANGUAGES.map(l => [l.token, l.parser]))
import { NoteContent, NoteLanguage } from "./parser.terms.js";
import { LANGUAGES } from "../languages.js";

const languageMapping = Object.fromEntries(
LANGUAGES.map((l) => [l.token, l.parser]),
);

export function configureNesting() {
return parseMixed((node, input) => {
let id = node.type.id
if (id == NoteContent) {
let noteLang = node.node.parent.firstChild.getChildren(NoteLanguage)[0]
let langName = input.read(noteLang?.from, noteLang?.to)

// if the NoteContent is empty, we don't want to return a parser, since that seems to cause an
// error for StreamLanguage parsers when the buffer size is large (e.g >300 kb)
if (node.node.from == node.node.to) {
return null
}

if (langName in languageMapping && languageMapping[langName] !== null) {
//console.log("found parser for language:", langName)
return {
parser:languageMapping[langName],
}
}
}
return null
})
return parseMixed((node, input) => {
let id = node.type.id;
if (id == NoteContent) {
let noteLang = node.node.parent.firstChild.getChildren(NoteLanguage)[0];
let langName = input.read(noteLang?.from, noteLang?.to);

// if the NoteContent is empty, we don't want to return a parser, since that seems to cause an
// error for StreamLanguage parsers when the buffer size is large (e.g >300 kb)
if (node.node.from == node.node.to) {
return null;
}

if (
langName in languageMapping &&
languageMapping[langName] !== null
) {
//console.log("found parser for language:", langName)
return {
parser: languageMapping[langName],
};
}
}
return null;
});
}
Loading

0 comments on commit 826f096

Please sign in to comment.