mirror of
https://github.com/Nexoniarz/Finch.git
synced 2026-11-03 00:44:27 +00:00
VS Code extension (highlighting, snippets, language client, Run/Build); LF line endings; LNK1181
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
5972d805aa
commit
eaacf70e42
19 changed files with 4821 additions and 3 deletions
2
editors/vscode/.gitignore
vendored
Normal file
2
editors/vscode/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
node_modules/
|
||||
*.vsix
|
||||
8
editors/vscode/.vscodeignore
Normal file
8
editors/vscode/.vscodeignore
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
.vscodeignore
|
||||
test/**
|
||||
node_modules/.package-lock.json
|
||||
node_modules/vscode-textmate/**
|
||||
node_modules/vscode-oniguruma/**
|
||||
node_modules/@vscode/**
|
||||
**/*.map
|
||||
.gitignore
|
||||
5
editors/vscode/CHANGELOG.md
Normal file
5
editors/vscode/CHANGELOG.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# Changelog
|
||||
|
||||
## 2.3.0
|
||||
|
||||
- First release: highlighting, snippets, language server, Run and Build.
|
||||
202
editors/vscode/LICENSE
Normal file
202
editors/vscode/LICENSE
Normal file
|
|
@ -0,0 +1,202 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
15
editors/vscode/README.md
Normal file
15
editors/vscode/README.md
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# Finch for Visual Studio Code
|
||||
|
||||
Support for the [Finch](https://github.com/Nexoniarz/Finch) programming language (`.fch` files):
|
||||
|
||||
- **Syntax highlighting**, bracket matching, comments with `Ctrl+/`
|
||||
- **Errors as you type**: the real compiler checks the file (`finch lsp`)
|
||||
- **Completion**: variables, functions, structs, keywords, built-ins, struct fields and array/str methods after `.`, names from imported C headers
|
||||
- **Hover** shows types and signatures; **Go to Definition** (F12); **Outline** of functions and structs; **parameter hints**
|
||||
- **Run** button (▶ in the editor title, or `Ctrl+F5`) and **Finch: Build This File**; compile errors land in the Problems panel
|
||||
- Snippets: `main`, `fn`, `fnr`, `struct`, `if`, `ife`, `for`, `foreach`, `while`, `input`, …
|
||||
|
||||
## Requirements
|
||||
|
||||
Finch 2.3 or newer. The extension runs `finch` from your PATH; if it lives somewhere else,
|
||||
set **Finch: Path** (`finch.path`) to the full path of `finch` / `finch.exe`.
|
||||
77
editors/vscode/extension.js
Normal file
77
editors/vscode/extension.js
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
// The Finch extension: starts `finch lsp` for editor features and adds Run / Build.
|
||||
const vscode = require('vscode');
|
||||
const { LanguageClient, TransportKind } = require('vscode-languageclient/node');
|
||||
|
||||
let client = null;
|
||||
|
||||
function finchPath() {
|
||||
return vscode.workspace.getConfiguration('finch').get('path') || 'finch';
|
||||
}
|
||||
|
||||
async function startServer(context) {
|
||||
if (!vscode.workspace.getConfiguration('finch').get('languageServer')) return;
|
||||
const command = finchPath();
|
||||
client = new LanguageClient(
|
||||
'finch',
|
||||
'Finch',
|
||||
{ command, args: ['lsp'], transport: TransportKind.stdio },
|
||||
{ documentSelector: [{ scheme: 'file', language: 'finch' }] }
|
||||
);
|
||||
try {
|
||||
await client.start();
|
||||
} catch (err) {
|
||||
client = null;
|
||||
const pick = await vscode.window.showErrorMessage(
|
||||
`Finch: couldn't start "${command} lsp". Is Finch installed? You can set its path in the settings.`,
|
||||
'Open Settings'
|
||||
);
|
||||
if (pick) vscode.commands.executeCommand('workbench.action.openSettings', 'finch.path');
|
||||
}
|
||||
}
|
||||
|
||||
// Run or build the current file as a task: no shell quoting, and the problem matcher
|
||||
// turns compile errors into entries in the Problems panel.
|
||||
async function finchTask(verb) {
|
||||
const editor = vscode.window.activeTextEditor;
|
||||
if (!editor || editor.document.languageId !== 'finch') {
|
||||
vscode.window.showWarningMessage('Finch: open a .fch file first.');
|
||||
return;
|
||||
}
|
||||
if (editor.document.isDirty) await editor.document.save();
|
||||
const file = editor.document.uri.fsPath;
|
||||
const folder = vscode.workspace.getWorkspaceFolder(editor.document.uri);
|
||||
const task = new vscode.Task(
|
||||
{ type: 'finch', verb, file },
|
||||
folder || vscode.TaskScope.Workspace,
|
||||
`${verb} ${require('path').basename(file)}`,
|
||||
'finch',
|
||||
new vscode.ProcessExecution(finchPath(), [verb, file], { cwd: require('path').dirname(file) }),
|
||||
'$finch'
|
||||
);
|
||||
task.presentationOptions = { reveal: vscode.TaskRevealKind.Always, focus: verb === 'run', clear: true };
|
||||
vscode.tasks.executeTask(task);
|
||||
}
|
||||
|
||||
async function activate(context) {
|
||||
context.subscriptions.push(
|
||||
vscode.commands.registerCommand('finch.run', () => finchTask('run')),
|
||||
vscode.commands.registerCommand('finch.build', () => finchTask('build')),
|
||||
vscode.commands.registerCommand('finch.restartServer', async () => {
|
||||
if (client) await client.stop();
|
||||
await startServer(context);
|
||||
}),
|
||||
vscode.workspace.onDidChangeConfiguration(async (e) => {
|
||||
if (e.affectsConfiguration('finch')) {
|
||||
if (client) await client.stop();
|
||||
await startServer(context);
|
||||
}
|
||||
})
|
||||
);
|
||||
await startServer(context);
|
||||
}
|
||||
|
||||
async function deactivate() {
|
||||
if (client) await client.stop();
|
||||
}
|
||||
|
||||
module.exports = { activate, deactivate };
|
||||
23
editors/vscode/images/file-dark.svg
Normal file
23
editors/vscode/images/file-dark.svg
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="512" height="512">
|
||||
<title>Finch</title>
|
||||
<g transform="translate(0 -26)">
|
||||
<!-- tail: two feathers -->
|
||||
<path d="M178 316 L60 360 Q50 374 64 382 L192 348 Z" fill="#F5F3EF"/>
|
||||
<path d="M182 334 L78 398 Q72 412 88 414 L200 360 Z" fill="#C9C4BC"/>
|
||||
<!-- body -->
|
||||
<path d="M150 330 C150 220 240 140 330 140 C400 140 440 190 440 245 C440 330 370 392 280 395 C220 398 168 372 150 330 Z" fill="#FF7A1A"/>
|
||||
<!-- belly light -->
|
||||
<path d="M236 390 C336 398 428 330 438 254 C432 300 404 330 372 350 C336 372 290 384 236 390 Z" fill="#FFA24D"/>
|
||||
<!-- wing, swept back -->
|
||||
<path d="M352 256 C306 232 228 256 160 340 C244 336 318 316 352 256 Z" fill="#1B1F2A"/>
|
||||
<path d="M330 260 C292 252 246 270 206 306" fill="none" stroke="#FFFFFF" stroke-width="9" stroke-linecap="round"/>
|
||||
<!-- beak -->
|
||||
<path d="M434 212 L494 234 L434 254 Z" fill="#FFC145"/>
|
||||
<!-- eye -->
|
||||
<circle cx="382" cy="206" r="16" fill="#1B1F2A"/>
|
||||
<circle cx="388" cy="200" r="5" fill="#FFFFFF"/>
|
||||
<!-- legs and branch -->
|
||||
<path d="M276 394 L270 420 M316 390 L318 420" stroke="#F5F3EF" stroke-width="10" stroke-linecap="round"/>
|
||||
<path d="M120 424 L440 424" stroke="#F5F3EF" stroke-width="14" stroke-linecap="round"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
23
editors/vscode/images/file-light.svg
Normal file
23
editors/vscode/images/file-light.svg
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="512" height="512">
|
||||
<title>Finch</title>
|
||||
<g transform="translate(0 -26)">
|
||||
<!-- tail: two feathers -->
|
||||
<path d="M178 316 L60 360 Q50 374 64 382 L192 348 Z" fill="#1B1F2A"/>
|
||||
<path d="M182 334 L78 398 Q72 412 88 414 L200 360 Z" fill="#2E3445"/>
|
||||
<!-- body -->
|
||||
<path d="M150 330 C150 220 240 140 330 140 C400 140 440 190 440 245 C440 330 370 392 280 395 C220 398 168 372 150 330 Z" fill="#FF7A1A"/>
|
||||
<!-- belly light -->
|
||||
<path d="M236 390 C336 398 428 330 438 254 C432 300 404 330 372 350 C336 372 290 384 236 390 Z" fill="#FFA24D"/>
|
||||
<!-- wing, swept back -->
|
||||
<path d="M352 256 C306 232 228 256 160 340 C244 336 318 316 352 256 Z" fill="#1B1F2A"/>
|
||||
<path d="M330 260 C292 252 246 270 206 306" fill="none" stroke="#FFFFFF" stroke-width="9" stroke-linecap="round"/>
|
||||
<!-- beak -->
|
||||
<path d="M434 212 L494 234 L434 254 Z" fill="#FFC145"/>
|
||||
<!-- eye -->
|
||||
<circle cx="382" cy="206" r="16" fill="#1B1F2A"/>
|
||||
<circle cx="388" cy="200" r="5" fill="#FFFFFF"/>
|
||||
<!-- legs and branch -->
|
||||
<path d="M276 394 L270 420 M316 390 L318 420" stroke="#1B1F2A" stroke-width="10" stroke-linecap="round"/>
|
||||
<path d="M120 424 L440 424" stroke="#1B1F2A" stroke-width="14" stroke-linecap="round"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
BIN
editors/vscode/images/icon.png
Normal file
BIN
editors/vscode/images/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.7 KiB |
19
editors/vscode/language-configuration.json
Normal file
19
editors/vscode/language-configuration.json
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"comments": { "lineComment": "//", "blockComment": ["/*", "*/"] },
|
||||
"brackets": [["{", "}"], ["[", "]"], ["(", ")"]],
|
||||
"autoClosingPairs": [
|
||||
{ "open": "{", "close": "}" },
|
||||
{ "open": "[", "close": "]" },
|
||||
{ "open": "(", "close": ")" },
|
||||
{ "open": "\"", "close": "\"", "notIn": ["string", "comment"] },
|
||||
{ "open": "'", "close": "'", "notIn": ["string", "comment"] },
|
||||
{ "open": "/*", "close": " */", "notIn": ["string"] }
|
||||
],
|
||||
"surroundingPairs": [["{", "}"], ["[", "]"], ["(", ")"], ["\"", "\""], ["'", "'"]],
|
||||
"indentationRules": {
|
||||
"increaseIndentPattern": "^.*\\{[^}\"']*$|^.*\\([^)\"']*$|^.*\\[[^\\]\"']*$",
|
||||
"decreaseIndentPattern": "^\\s*[}\\])]"
|
||||
},
|
||||
"wordPattern": "[A-Za-z_][A-Za-z0-9_]*|-?\\d[\\d_]*(\\.\\d+)?",
|
||||
"folding": { "markers": { "start": "^\\s*//\\s*#?region\\b", "end": "^\\s*//\\s*#?endregion\\b" } }
|
||||
}
|
||||
3957
editors/vscode/package-lock.json
generated
Normal file
3957
editors/vscode/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
154
editors/vscode/package.json
Normal file
154
editors/vscode/package.json
Normal file
|
|
@ -0,0 +1,154 @@
|
|||
{
|
||||
"name": "finch-lang",
|
||||
"displayName": "Finch",
|
||||
"description": "The Finch programming language: highlighting, errors as you type, completion, hover, go to definition, and a Run button.",
|
||||
"version": "2.3.0",
|
||||
"publisher": "nexoniarz",
|
||||
"license": "Apache-2.0",
|
||||
"icon": "images/icon.png",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Nexoniarz/Finch"
|
||||
},
|
||||
"homepage": "https://github.com/Nexoniarz/Finch",
|
||||
"bugs": {
|
||||
"url": "https://github.com/Nexoniarz/Finch/issues"
|
||||
},
|
||||
"engines": {
|
||||
"vscode": "^1.85.0"
|
||||
},
|
||||
"categories": [
|
||||
"Programming Languages",
|
||||
"Linters",
|
||||
"Snippets"
|
||||
],
|
||||
"keywords": [
|
||||
"finch",
|
||||
"llvm",
|
||||
"compiler",
|
||||
"language"
|
||||
],
|
||||
"main": "./extension.js",
|
||||
"activationEvents": [
|
||||
"onLanguage:finch"
|
||||
],
|
||||
"contributes": {
|
||||
"languages": [
|
||||
{
|
||||
"id": "finch",
|
||||
"aliases": [
|
||||
"Finch",
|
||||
"finch"
|
||||
],
|
||||
"extensions": [
|
||||
".fch"
|
||||
],
|
||||
"configuration": "./language-configuration.json",
|
||||
"icon": {
|
||||
"light": "./images/file-light.svg",
|
||||
"dark": "./images/file-dark.svg"
|
||||
}
|
||||
}
|
||||
],
|
||||
"grammars": [
|
||||
{
|
||||
"language": "finch",
|
||||
"scopeName": "source.finch",
|
||||
"path": "./syntaxes/finch.tmLanguage.json"
|
||||
}
|
||||
],
|
||||
"snippets": [
|
||||
{
|
||||
"language": "finch",
|
||||
"path": "./snippets/finch.json"
|
||||
}
|
||||
],
|
||||
"configuration": {
|
||||
"title": "Finch",
|
||||
"properties": {
|
||||
"finch.path": {
|
||||
"type": "string",
|
||||
"default": "finch",
|
||||
"description": "The finch compiler: a command on your PATH, or the full path to finch / finch.exe."
|
||||
},
|
||||
"finch.languageServer": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "Use `finch lsp` for errors as you type, completion, hover and go to definition."
|
||||
}
|
||||
}
|
||||
},
|
||||
"commands": [
|
||||
{
|
||||
"command": "finch.run",
|
||||
"title": "Finch: Run This File",
|
||||
"icon": "$(play)"
|
||||
},
|
||||
{
|
||||
"command": "finch.build",
|
||||
"title": "Finch: Build This File",
|
||||
"icon": "$(tools)"
|
||||
},
|
||||
{
|
||||
"command": "finch.restartServer",
|
||||
"title": "Finch: Restart Language Server"
|
||||
}
|
||||
],
|
||||
"menus": {
|
||||
"editor/title/run": [
|
||||
{
|
||||
"command": "finch.run",
|
||||
"when": "resourceLangId == finch",
|
||||
"group": "navigation"
|
||||
}
|
||||
],
|
||||
"commandPalette": [
|
||||
{
|
||||
"command": "finch.run",
|
||||
"when": "editorLangId == finch"
|
||||
},
|
||||
{
|
||||
"command": "finch.build",
|
||||
"when": "editorLangId == finch"
|
||||
}
|
||||
]
|
||||
},
|
||||
"keybindings": [
|
||||
{
|
||||
"command": "finch.run",
|
||||
"key": "ctrl+f5",
|
||||
"mac": "cmd+f5",
|
||||
"when": "editorLangId == finch"
|
||||
}
|
||||
],
|
||||
"problemMatchers": [
|
||||
{
|
||||
"name": "finch",
|
||||
"owner": "finch",
|
||||
"fileLocation": [
|
||||
"autoDetect",
|
||||
"${workspaceFolder}"
|
||||
],
|
||||
"pattern": {
|
||||
"regexp": "^(.*?):(\\d+):(\\d+): error: (.*)$",
|
||||
"file": 1,
|
||||
"line": 2,
|
||||
"column": 3,
|
||||
"message": 4
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"vscode-languageclient": "^9.0.1"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node test/grammar.js",
|
||||
"package": "vsce package"
|
||||
},
|
||||
"devDependencies": {
|
||||
"vscode-textmate": "^9.2.0",
|
||||
"vscode-oniguruma": "^2.0.1",
|
||||
"@vscode/vsce": "^3.2.0"
|
||||
}
|
||||
}
|
||||
16
editors/vscode/snippets/finch.json
Normal file
16
editors/vscode/snippets/finch.json
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"main": { "prefix": "main", "body": ["fn main() {", "\t$0", "}"], "description": "The program's start" },
|
||||
"main with arguments": { "prefix": "mainargs", "body": ["fn main([]str args) {", "\t$0", "}"], "description": "main that gets the command-line arguments" },
|
||||
"function": { "prefix": "fn", "body": ["fn ${1:name}(${2}) {", "\t$0", "}"], "description": "A function" },
|
||||
"function with result": { "prefix": "fnr", "body": ["fn ${1:name}(${2}) -> ${3:int} {", "\t$0", "}"], "description": "A function that returns a value" },
|
||||
"struct": { "prefix": "struct", "body": ["struct ${1:Name} {", "\t${2:int} ${3:field}", "}"], "description": "A struct" },
|
||||
"if": { "prefix": "if", "body": ["if ${1:condition} {", "\t$0", "}"] },
|
||||
"if else": { "prefix": "ife", "body": ["if ${1:condition} {", "\t$2", "} else {", "\t$0", "}"] },
|
||||
"for range": { "prefix": "for", "body": ["for ${1:i} in ${2:0}..${3:n} {", "\t$0", "}"], "description": "Count from start to end-1" },
|
||||
"for each": { "prefix": "foreach", "body": ["for ${1:item} in ${2:list} {", "\t$0", "}"], "description": "Every element of an array or str" },
|
||||
"while": { "prefix": "while", "body": ["while ${1:condition} {", "\t$0", "}"] },
|
||||
"print": { "prefix": "print", "body": ["print(${1})"] },
|
||||
"input": { "prefix": "input", "body": ["${1:answer} := input(\"${2:Question? }\")"] },
|
||||
"import C header": { "prefix": "importc", "body": ["import \"${1:stdio.h}\""] },
|
||||
"defer": { "prefix": "defer", "body": ["defer ${1}"], "description": "Run this when the block ends" }
|
||||
}
|
||||
241
editors/vscode/syntaxes/finch.tmLanguage.json
Normal file
241
editors/vscode/syntaxes/finch.tmLanguage.json
Normal file
|
|
@ -0,0 +1,241 @@
|
|||
{
|
||||
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
|
||||
"name": "Finch",
|
||||
"scopeName": "source.finch",
|
||||
"fileTypes": [
|
||||
"fch"
|
||||
],
|
||||
"patterns": [
|
||||
{
|
||||
"include": "#comments"
|
||||
},
|
||||
{
|
||||
"include": "#imports"
|
||||
},
|
||||
{
|
||||
"include": "#struct"
|
||||
},
|
||||
{
|
||||
"include": "#function"
|
||||
},
|
||||
{
|
||||
"include": "#statements"
|
||||
}
|
||||
],
|
||||
"repository": {
|
||||
"comments": {
|
||||
"patterns": [
|
||||
{
|
||||
"name": "comment.line.double-slash.finch",
|
||||
"match": "//.*$"
|
||||
},
|
||||
{
|
||||
"name": "comment.block.finch",
|
||||
"begin": "/\\*",
|
||||
"end": "\\*/"
|
||||
}
|
||||
]
|
||||
},
|
||||
"imports": {
|
||||
"patterns": [
|
||||
{
|
||||
"match": "^\\s*(import)\\s+(\"[^\"]*\")",
|
||||
"captures": {
|
||||
"1": {
|
||||
"name": "keyword.control.import.finch"
|
||||
},
|
||||
"2": {
|
||||
"name": "string.quoted.double.include.finch"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"match": "^\\s*(import)\\s+([A-Za-z_][A-Za-z0-9_]*)",
|
||||
"captures": {
|
||||
"1": {
|
||||
"name": "keyword.control.import.finch"
|
||||
},
|
||||
"2": {
|
||||
"name": "entity.name.namespace.finch"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"match": "^\\s*(link)\\s+(\"[^\"]*\")",
|
||||
"captures": {
|
||||
"1": {
|
||||
"name": "keyword.control.import.finch"
|
||||
},
|
||||
"2": {
|
||||
"name": "string.quoted.double.finch"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"struct": {
|
||||
"match": "\\b(struct)\\s+([A-Za-z_][A-Za-z0-9_]*)",
|
||||
"captures": {
|
||||
"1": {
|
||||
"name": "storage.type.struct.finch"
|
||||
},
|
||||
"2": {
|
||||
"name": "entity.name.type.struct.finch"
|
||||
}
|
||||
}
|
||||
},
|
||||
"function": {
|
||||
"match": "\\b(fn)\\s+([A-Za-z_][A-Za-z0-9_]*)",
|
||||
"captures": {
|
||||
"1": {
|
||||
"name": "storage.type.function.finch"
|
||||
},
|
||||
"2": {
|
||||
"name": "entity.name.function.finch"
|
||||
}
|
||||
}
|
||||
},
|
||||
"statements": {
|
||||
"patterns": [
|
||||
{
|
||||
"include": "#comments"
|
||||
},
|
||||
{
|
||||
"include": "#strings"
|
||||
},
|
||||
{
|
||||
"include": "#chars"
|
||||
},
|
||||
{
|
||||
"include": "#numbers"
|
||||
},
|
||||
{
|
||||
"name": "keyword.control.finch",
|
||||
"match": "\\b(if|else|while|for|in|break|continue|return|defer)\\b"
|
||||
},
|
||||
{
|
||||
"name": "storage.type.function.finch",
|
||||
"match": "\\bfn\\b"
|
||||
},
|
||||
{
|
||||
"name": "storage.type.struct.finch",
|
||||
"match": "\\bstruct\\b"
|
||||
},
|
||||
{
|
||||
"name": "constant.language.finch",
|
||||
"match": "\\b(true|false|null)\\b"
|
||||
},
|
||||
{
|
||||
"name": "storage.type.primitive.finch",
|
||||
"match": "\\b(int|float|bool|char|str|ptr|i8|i16|i32|i64|u8|u16|u32|u64|f32|f64)\\b"
|
||||
},
|
||||
{
|
||||
"match": "\\b(print|input|read_file|write_file|file_exists|delete_file|shell|exit|addr|new|free)\\s*(?=\\()",
|
||||
"captures": {
|
||||
"1": {
|
||||
"name": "support.function.builtin.finch"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"match": "(?<=\\.)(len|ptr|value)\\b(?!\\s*\\()",
|
||||
"captures": {
|
||||
"1": {
|
||||
"name": "variable.other.property.finch"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"match": "\\b([A-Z][A-Za-z0-9_]*)\\s*(?=\\()",
|
||||
"captures": {
|
||||
"1": {
|
||||
"name": "entity.name.type.finch"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"match": "\\b([a-z_][A-Za-z0-9_]*)\\s*(?=\\()",
|
||||
"captures": {
|
||||
"1": {
|
||||
"name": "entity.name.function.call.finch"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "entity.name.type.finch",
|
||||
"match": "\\b[A-Z][A-Za-z0-9_]*\\b"
|
||||
},
|
||||
{
|
||||
"name": "keyword.operator.assignment.finch",
|
||||
"match": ":=|\\+=|-=|\\*=|/=|%=|(?<![=!<>])=(?!=)"
|
||||
},
|
||||
{
|
||||
"name": "keyword.operator.comparison.finch",
|
||||
"match": "==|!=|<=|>=|<|>"
|
||||
},
|
||||
{
|
||||
"name": "keyword.operator.logical.finch",
|
||||
"match": "&&|\\|\\||!"
|
||||
},
|
||||
{
|
||||
"name": "keyword.operator.arrow.finch",
|
||||
"match": "->"
|
||||
},
|
||||
{
|
||||
"name": "keyword.operator.range.finch",
|
||||
"match": "\\.\\."
|
||||
},
|
||||
{
|
||||
"name": "keyword.operator.arithmetic.finch",
|
||||
"match": "<<|>>|[-+*/%&|^~]"
|
||||
},
|
||||
{
|
||||
"name": "variable.other.finch",
|
||||
"match": "\\b[a-z_][A-Za-z0-9_]*\\b"
|
||||
}
|
||||
]
|
||||
},
|
||||
"strings": {
|
||||
"name": "string.quoted.double.finch",
|
||||
"begin": "\"",
|
||||
"end": "\"|$",
|
||||
"patterns": [
|
||||
{
|
||||
"name": "constant.character.escape.finch",
|
||||
"match": "\\\\[ntr0\\\\\"']"
|
||||
},
|
||||
{
|
||||
"name": "invalid.illegal.escape.finch",
|
||||
"match": "\\\\."
|
||||
}
|
||||
]
|
||||
},
|
||||
"chars": {
|
||||
"name": "string.quoted.single.finch",
|
||||
"begin": "'",
|
||||
"end": "'|$",
|
||||
"patterns": [
|
||||
{
|
||||
"name": "constant.character.escape.finch",
|
||||
"match": "\\\\[ntr0\\\\\"']"
|
||||
}
|
||||
]
|
||||
},
|
||||
"numbers": {
|
||||
"patterns": [
|
||||
{
|
||||
"name": "constant.numeric.hex.finch",
|
||||
"match": "\\b0[xX][0-9A-Fa-f_]+\\b"
|
||||
},
|
||||
{
|
||||
"name": "constant.numeric.float.finch",
|
||||
"match": "\\b\\d[\\d_]*\\.\\d[\\d_]*\\b"
|
||||
},
|
||||
{
|
||||
"name": "constant.numeric.integer.finch",
|
||||
"match": "\\b\\d[\\d_]*\\b"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
51
editors/vscode/test/grammar.js
Normal file
51
editors/vscode/test/grammar.js
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
// Tokenizes Finch code with the same engine VS Code uses and checks the scopes.
|
||||
const fs = require('fs'), path = require('path');
|
||||
const vsctm = require('vscode-textmate'), oniguruma = require('vscode-oniguruma');
|
||||
const grammarPath = path.join(__dirname, "..", "syntaxes", "finch.tmLanguage.json");
|
||||
const wasm = fs.readFileSync(require.resolve("vscode-oniguruma/release/onig.wasm")).buffer;
|
||||
const onigLib = oniguruma.loadWASM(wasm).then(() => ({
|
||||
createOnigScanner: (s) => new oniguruma.OnigScanner(s),
|
||||
createOnigString: (s) => new oniguruma.OnigString(s),
|
||||
}));
|
||||
const registry = new vsctm.Registry({ onigLib, loadGrammar: async () => vsctm.parseRawGrammar(fs.readFileSync(grammarPath, 'utf8'), grammarPath) });
|
||||
const code = [
|
||||
'import "stdio.h"',
|
||||
'import shapes',
|
||||
'struct Point {',
|
||||
' int x = 0x1F',
|
||||
'}',
|
||||
'fn add(int a, float b) -> int {',
|
||||
' s := "hi\\n" + str(a) // note',
|
||||
' for i in 0..10 { print(i, \'c\', 3.5, true, null) }',
|
||||
' p := Point(x: 1)',
|
||||
' return a + p.x',
|
||||
'}',
|
||||
];
|
||||
const expect = [ // [line, token text, scope that must be present]
|
||||
[0, 'import', 'keyword.control.import'], [0, '"stdio.h"', 'string.quoted.double'],
|
||||
[1, 'shapes', 'entity.name.namespace'],
|
||||
[2, 'struct', 'storage.type.struct'], [2, 'Point', 'entity.name.type.struct'],
|
||||
[3, 'int', 'storage.type.primitive'], [3, '0x1F', 'constant.numeric.hex'],
|
||||
[5, 'fn', 'storage.type.function'], [5, 'add', 'entity.name.function'], [5, 'float', 'storage.type.primitive'], [5, '->', 'keyword.operator.arrow'],
|
||||
[6, ':=', 'keyword.operator.assignment'], [6, '\\n', 'constant.character.escape'], [6, '// note', 'comment.line'], [6, 'str', 'storage.type.primitive'],
|
||||
[7, 'for', 'keyword.control'], [7, 'in', 'keyword.control'], [7, '..', 'keyword.operator.range'], [7, 'print', 'support.function.builtin'],
|
||||
[7, 'c', 'string.quoted.single'], [7, '3.5', 'constant.numeric.float'], [7, 'true', 'constant.language'], [7, 'null', 'constant.language'],
|
||||
[8, 'Point', 'entity.name.type'],
|
||||
[9, 'return', 'keyword.control'],
|
||||
];
|
||||
registry.loadGrammar('source.finch').then((g) => {
|
||||
let state = vsctm.INITIAL, toks = [];
|
||||
code.forEach((line, i) => {
|
||||
const r = g.tokenizeLine(line, state);
|
||||
r.tokens.forEach((t) => toks.push([i, line.substring(t.startIndex, t.endIndex), t.scopes.join(' ')]));
|
||||
state = r.ruleStack;
|
||||
});
|
||||
let bad = 0;
|
||||
for (const [line, text, scope] of expect) {
|
||||
const hit = toks.find((t) => t[0] === line && t[1].trim() === text);
|
||||
const ok = hit && hit[2].includes(scope);
|
||||
if (!ok) { bad++; console.log('FAIL', line, JSON.stringify(text), 'wanted', scope, 'got', hit ? hit[2] : '(no token)'); }
|
||||
}
|
||||
console.log(bad ? `grammar: ${bad} failed` : `grammar: all ${expect.length} ok`);
|
||||
process.exit(bad ? 1 : 0);
|
||||
});
|
||||
Loading…
Reference in a new issue