diff options
| author | Elizabeth Hunt <me@liz.coffee> | 2026-01-04 23:37:57 -0800 |
|---|---|---|
| committer | Elizabeth Hunt <me@liz.coffee> | 2026-01-04 23:39:56 -0800 |
| commit | f2aec5ca1434ff4dc43c51b47faa8347e1ebf3e2 (patch) | |
| tree | 087b028bf56f008823d5f135888ac0252fa8fc66 /src/index.ts | |
| parent | 1f5d5ae9de3c87be7faf60b0a0f028e7b7c3507e (diff) | |
| download | codemirror-lang-tabloid-f2aec5ca1434ff4dc43c51b47faa8347e1ebf3e2.tar.gz codemirror-lang-tabloid-f2aec5ca1434ff4dc43c51b47faa8347e1ebf3e2.zip | |
Better impl
Diffstat (limited to 'src/index.ts')
| -rw-r--r-- | src/index.ts | 76 |
1 files changed, 40 insertions, 36 deletions
diff --git a/src/index.ts b/src/index.ts index 14b4ffe..690572b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,51 +1,55 @@ -import {parser} from "./syntax.grammar" -import {LRLanguage, LanguageSupport, indentNodeProp, foldNodeProp, foldInside, delimitedIndent} from "@codemirror/language" -import {styleTags, tags as t} from "@lezer/highlight" +import { parser } from "./syntax.grammar"; +import { + LRLanguage, + LanguageSupport, + indentNodeProp, + foldNodeProp, + foldInside, + delimitedIndent, +} from "@codemirror/language"; +import { highlighting } from "./highlight"; +import { tabloidCompletion } from "./autocomplete"; +import { autocompletion } from "@codemirror/autocomplete"; + +// Wrap parser to debug +const originalParse = parser.parse.bind(parser); +parser.parse = function (input, fragments, ranges) { + console.log( + "[PARSER] parse called with input:", + typeof input === "string" ? input.substring(0, 100) : input, + ); + const result = originalParse(input, fragments, ranges); + console.log("[PARSER] parse result:", result.toString()); + return result; +}; export const tabloidLanguage = LRLanguage.define({ parser: parser.configure({ props: [ indentNodeProp.add({ - Block: delimitedIndent({closing: "endOfStory", align: false}), - ParenBlock: delimitedIndent({closing: ")", align: false}), - FunctionDecl: context => context.baseIndent + context.unit, - IfStatement: context => context.baseIndent + context.unit, + Block: delimitedIndent({ closing: "endOfStory", align: false }), + ParenBlock: delimitedIndent({ closing: ")", align: false }), + FunctionDecl: (context) => context.baseIndent + context.unit, + IfStatement: (context) => context.baseIndent + context.unit, }), foldNodeProp.add({ Block: foldInside, ParenBlock: foldInside, }), - styleTags({ - Identifier: t.variableName, - NumberLiteral: t.number, - StringLiteral: t.string, - BooleanLiteral: t.bool, - FunctionCall: t.function(t.variableName), - discoverHowTo: t.definitionKeyword, - expertsClaim: t.definitionKeyword, - toBe: t.operatorKeyword, - rumorHasIt: t.keyword, - endOfStory: t.keyword, - whatIf: t.controlKeyword, - liesBang: t.controlKeyword, - shockingDevelopment: t.controlKeyword, - youWontWantToMiss: t.keyword, - latestNewsOn: t.keyword, - pleaseLikeAndSubscribe: t.keyword, - "with of": t.keyword, - "isActually beats smallerThan": t.compareOperator, - "and or": t.logicOperator, - "plus minus times dividedBy modulo": t.arithmeticOperator, - "( )": t.paren, - ",": t.separator - }) - ] + highlighting, + ], }), languageData: { - commentTokens: {} - } -}) + commentTokens: {}, + closeBrackets: { brackets: ["(", '"', "'"] }, + autocomplete: tabloidCompletion, + }, +}); export function tabloid() { - return new LanguageSupport(tabloidLanguage) + return new LanguageSupport(tabloidLanguage, [ + autocompletion({ override: [tabloidCompletion] }), + ]); } + +export { tabloidCompletion }; |
