-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added code highlight for ftd
in ide
#113
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@top ImportCommand { "--" "import" ":" Name } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can create p1 level grammar only, try to port our old grammar, instead of creating full parser. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would love full parser, but it would be more work. Also the language support for fastn should be in fastn-stack org, so others can also use it. |
||
|
||
Name { | ||
identifier | ||
} | ||
|
||
@tokens { | ||
identifier { $[a-zA-Z0-9_\-]+ } | ||
// QuotedString { '"' (!["\\] | "\\" _)* '"' } | ||
LineComment { ";;" ![\n]* } | ||
// space { $[ \t\n\r]+ } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be ideally a standalone npm package. |
||
// Define a basic FTD grammar with "-- import:" keyword | ||
import {LanguageSupport, LRLanguage, syntaxTree} from "@codemirror/language"; | ||
import {styleTags, tags as t} from "@lezer/highlight"; | ||
import {parser} from "./ftd.grammar"; | ||
|
||
const ftdLanguage = LRLanguage.define({ | ||
parser: parser.configure({ | ||
// Basic tokenizer for FTD import grammar | ||
props: [ | ||
styleTags({ | ||
Name: t.literal | ||
}) | ||
] | ||
}), | ||
}); | ||
|
||
// Autocomplete support for FTD packages | ||
const ftdAutocomplete = ftdLanguage.data.of({ | ||
autocomplete: (context) => { | ||
let nodeBefore = syntaxTree(context.state).resolveInner(context.pos, -1); | ||
if (nodeBefore.name == "Import") { | ||
return { | ||
from: nodeBefore.from, | ||
options: [ | ||
{label: "ftd_core", type: "variable"}, | ||
{label: "ftd_ui", type: "variable"}, | ||
{label: "ftd_utils", type: "variable"}, | ||
{label: "ftd_data", type: "variable"} | ||
] | ||
}; | ||
} | ||
return null; | ||
} | ||
}); | ||
|
||
// Create a language support extension | ||
function ftd() { | ||
return new LanguageSupport(ftdLanguage, [ftdAutocomplete]); | ||
} | ||
|
||
export {ftd} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's call it
./fastn/language
etc. FTD is no longer the name, we want to use fastn language terminology everywhere.