Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/extraction/grammars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const WASM_GRAMMAR_FILES: Record<GrammarLanguage, string> = {
kotlin: 'tree-sitter-kotlin.wasm',
dart: 'tree-sitter-dart.wasm',
pascal: 'tree-sitter-pascal.wasm',
mql5: 'tree-sitter-mql5.wasm',
scala: 'tree-sitter-scala.wasm',
lua: 'tree-sitter-lua.wasm',
r: 'tree-sitter-r.wasm',
Expand Down Expand Up @@ -102,6 +103,9 @@ export const EXTENSION_MAP: Record<string, Language> = {
'.lpr': 'pascal',
'.dfm': 'pascal',
'.fmx': 'pascal',
'.mq5': 'mql5',
'.mqh': 'mql5',
'.mql5': 'mql5',
'.scala': 'scala',
'.sc': 'scala',
'.lua': 'lua',
Expand Down Expand Up @@ -221,7 +225,7 @@ export async function loadGrammarsForLanguages(languages: Language[]): Promise<v
// `class Foo(...)` as an ERROR that swallows the whole class (#237); we
// vendor the upstream ABI-15 tree-sitter-c-sharp 0.23.5 wasm, which parses
// primary constructors natively.
const wasmPath = (lang === 'pascal' || lang === 'scala' || lang === 'lua' || lang === 'luau' || lang === 'csharp' || lang === 'r')
const wasmPath = (lang === 'pascal' || lang === 'mql5' || lang === 'scala' || lang === 'lua' || lang === 'luau' || lang === 'csharp' || lang === 'r')
? path.join(__dirname, 'wasm', wasmFile)
: require.resolve(`tree-sitter-wasms/out/${wasmFile}`);
const language = await WasmLanguage.load(wasmPath);
Expand Down Expand Up @@ -428,6 +432,7 @@ export function getLanguageDisplayName(language: Language): string {
astro: 'Astro',
liquid: 'Liquid',
pascal: 'Pascal / Delphi',
mql5: 'MQL5',
scala: 'Scala',
lua: 'Lua',
luau: 'Luau',
Expand Down
2 changes: 2 additions & 0 deletions src/extraction/languages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { luaExtractor } from './lua';
import { rExtractor } from './r';
import { luauExtractor } from './luau';
import { objcExtractor } from './objc';
import { mql5Extractor } from './mql5';

export const EXTRACTORS: Partial<Record<Language, LanguageExtractor>> = {
typescript: typescriptExtractor,
Expand All @@ -51,4 +52,5 @@ export const EXTRACTORS: Partial<Record<Language, LanguageExtractor>> = {
r: rExtractor,
luau: luauExtractor,
objc: objcExtractor,
mql5: mql5Extractor,
};
61 changes: 61 additions & 0 deletions src/extraction/languages/mql5.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import type { Node as SyntaxNode } from 'web-tree-sitter';
import { getNodeText, getChildByField } from '../tree-sitter-helpers';
import type { LanguageExtractor } from '../tree-sitter-types';

export const mql5Extractor: LanguageExtractor = {
functionTypes: ['declProc'],
classTypes: ['declClass'],
methodTypes: ['declProc'],
interfaceTypes: ['declIntf'],
structTypes: [],
enumTypes: ['declEnum'],
typeAliasTypes: ['declType'],
importTypes: ['declUses'],
callTypes: ['exprCall'],
variableTypes: ['declField', 'declConst'],
nameField: 'name',
bodyField: 'body',
paramsField: 'args',
returnField: 'type',
getSignature: (node, source) => {
const args = getChildByField(node, 'args');
const returnType = node.namedChildren.find(
(c: SyntaxNode) => c.type === 'typeref'
);
if (!args && !returnType) return undefined;
let sig = '';
if (args) sig = getNodeText(args, source);
if (returnType) {
sig += ': ' + getNodeText(returnType, source);
}
return sig || undefined;
},
getVisibility: (node) => {
let current = node.parent;
while (current) {
if (current.type === 'declSection') {
for (let i = 0; i < current.childCount; i++) {
const child = current.child(i);
if (child?.type === 'kPublic' || child?.type === 'kPublished')
return 'public';
if (child?.type === 'kPrivate') return 'private';
if (child?.type === 'kProtected') return 'protected';
}
}
current = current.parent;
}
return undefined;
},
isExported: (_node, _source) => {
return false;
},
isStatic: (node) => {
for (let i = 0; i < node.childCount; i++) {
if (node.child(i)?.type === 'kClass') return true;
}
return false;
},
isConst: (node) => {
return node.type === 'declConst';
},
};
Binary file added src/extraction/wasm/tree-sitter-mql5.wasm
Binary file not shown.
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export const LANGUAGES = [
'astro',
'liquid',
'pascal',
'mql5',
'scala',
'lua',
'luau',
Expand Down