diff --git a/packages/yaml/README.md b/packages/yaml/README.md new file mode 100644 index 0000000..565ac16 --- /dev/null +++ b/packages/yaml/README.md @@ -0,0 +1,24 @@ +# ast-grep napi language for yaml + +## Installation + +In a pnpm project, run: + +```bash +pnpm install @ast-grep/lang-yaml +pnpm install @ast-grep/napi +# install the tree-sitter-cli if no prebuild is available +pnpm install @tree-sitter/cli --save-dev +``` + +## Usage + +```js +import yaml from '@ast-grep/lang-yaml' +import { registerDynamicLanguage, parse } from '@ast-grep/napi' + +registerDynamicLanguage({ yaml }) + +const sg = parse('yaml', `your code`) +sg.root().kind() +``` diff --git a/packages/yaml/index.d.ts b/packages/yaml/index.d.ts new file mode 100644 index 0000000..11140a6 --- /dev/null +++ b/packages/yaml/index.d.ts @@ -0,0 +1,10 @@ +type LanguageRegistration = { + libraryPath: string + extensions: string[] + languageSymbol?: string + metaVarChar?: string + expandoChar?: string +} + +declare const registration: LanguageRegistration +export default registration diff --git a/packages/yaml/index.js b/packages/yaml/index.js new file mode 100644 index 0000000..28b7724 --- /dev/null +++ b/packages/yaml/index.js @@ -0,0 +1,9 @@ +const path = require('node:path') +const libPath = path.join(__dirname, 'parser.so') + +module.exports = { + libraryPath: libPath, + extensions: ['yaml', 'yml'], + languageSymbol: 'tree_sitter_yaml', + expandoChar: '$', +} diff --git a/packages/yaml/nursery.js b/packages/yaml/nursery.js new file mode 100644 index 0000000..c011c87 --- /dev/null +++ b/packages/yaml/nursery.js @@ -0,0 +1,12 @@ +const { setup } = require('@ast-grep/nursery') +const languageRegistration = require('./index') + +setup({ + dirname: __dirname, + name: 'yaml', + treeSitterPackage: 'tree-sitter-yaml', + languageRegistration, + testRunner: parse => { + // add test here + }, +}) diff --git a/packages/yaml/package.json b/packages/yaml/package.json new file mode 100644 index 0000000..adfb3b6 --- /dev/null +++ b/packages/yaml/package.json @@ -0,0 +1,47 @@ +{ + "name": "@ast-grep/lang-yaml", + "version": "0.0.1", + "description": "", + "main": "index.js", + "scripts": { + "build": "tree-sitter build -o parser.so", + "source": "node nursery.js source", + "prepublishOnly": "node nursery.js source", + "postinstall": "node postinstall.js", + "test": "node nursery.js test" + }, + "files": [ + "index.js", + "index.d.ts", + "type.d.ts", + "postinstall.js", + "src", + "prebuilds" + ], + "keywords": ["ast-grep"], + "author": "", + "license": "ISC", + "dependencies": { + "@ast-grep/setup-lang": "0.0.3" + }, + "peerDependencies": { + "tree-sitter-cli": "0.24.6" + }, + "peerDependenciesMeta": { + "tree-sitter-cli": { + "optional": true + } + }, + "devDependencies": { + "@ast-grep/nursery": "0.0.2", + "tree-sitter-cli": "0.24.6", + "tree-sitter-yaml": "0.5.0" + }, + "publishConfig": { + "access": "public", + "registry": "https://registry.npmjs.org/" + }, + "pnpm": { + "onlyBuiltDependencies": ["@ast-grep/lang-yaml", "tree-sitter-cli"] + } +} diff --git a/packages/yaml/postinstall.js b/packages/yaml/postinstall.js new file mode 100644 index 0000000..b9141ff --- /dev/null +++ b/packages/yaml/postinstall.js @@ -0,0 +1,4 @@ +const { postinstall } = require('@ast-grep/setup-lang') +postinstall({ + dirname: __dirname, +}) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 788f16e..7b603d6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -402,6 +402,22 @@ importers: specifier: 0.24.6 version: 0.24.6 + packages/yaml: + dependencies: + '@ast-grep/setup-lang': + specifier: 0.0.3 + version: 0.0.3 + devDependencies: + '@ast-grep/nursery': + specifier: 0.0.2 + version: 0.0.2 + tree-sitter-cli: + specifier: 0.24.6 + version: 0.24.6 + tree-sitter-yaml: + specifier: 0.5.0 + version: 0.5.0 + scripts/create-lang: dependencies: prompts: @@ -442,64 +458,125 @@ importers: packages: + '@ast-grep/napi-darwin-arm64@0.33.0': + resolution: {integrity: sha512-FsBQiBNGbqeU6z2sjFgnV6MXuBa0wYUb4PViMnqsKLeWiO7kRii5crmXLCtdTD2hufXTG6Rll8X46AkYOAwGGQ==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [darwin] + '@ast-grep/napi-darwin-arm64@0.36.2': resolution: {integrity: sha512-0dzW+5SRuUxAlfwgMiUWXSvvyVD3nffzLtH5RhH2a1VXbQxi2UFWZqtfhv6e27iIUTnPfZDnZGNRw8FZgttMfQ==} engines: {node: '>= 10'} cpu: [arm64] os: [darwin] + '@ast-grep/napi-darwin-x64@0.33.0': + resolution: {integrity: sha512-rWo1wG7fc7K20z9ExIeN6U4QqjHhoQSpBDDnmxKTR0nIwPfyMq338sS4sWZomutxprcZDtWrekxH1lXjNvfuiA==} + engines: {node: '>= 10'} + cpu: [x64] + os: [darwin] + '@ast-grep/napi-darwin-x64@0.36.2': resolution: {integrity: sha512-7TPdnq55OBXGcJLDARObI5BUFbp0AVRMGEzjnIBMWbRSowlDVTH7qBWwNAYk4auCdkwG8EBL40BUIHmagzpoCw==} engines: {node: '>= 10'} cpu: [x64] os: [darwin] + '@ast-grep/napi-linux-arm64-gnu@0.33.0': + resolution: {integrity: sha512-3ZnA2k57kxfvLg4s9+6rHaCx1FbWt0EF8fumJMf5nwevu7GbVOOhCkzAetZe80FBgZuIOSR4IS2QMj9ZHI0UdQ==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [linux] + '@ast-grep/napi-linux-arm64-gnu@0.36.2': resolution: {integrity: sha512-/h51eEnEYCq4bclzhynH+964LQXDKXgNb2Un+Y9TLOU8VRaGNawTkZkFq+iBp8T1hl0CznnsQQsg+9pHDHprHQ==} engines: {node: '>= 10'} cpu: [arm64] os: [linux] + '@ast-grep/napi-linux-arm64-musl@0.33.0': + resolution: {integrity: sha512-oUGZgCaVCijFgvC+X52ttgoWUqgrIsSVJZgn+1VBY3n4mpzcoYAghFomSUbRTBUL2ebvZweA33Klqks4okY61w==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [linux] + '@ast-grep/napi-linux-arm64-musl@0.36.2': resolution: {integrity: sha512-RIuk0VaQW2b5uOPJzuYFQBwMZIEVnp6maXPjnatUHxfniirSI172E7LtOU/FIEpCjU9Fpq23A79S43ImFt1KLA==} engines: {node: '>= 10'} cpu: [arm64] os: [linux] + '@ast-grep/napi-linux-x64-gnu@0.33.0': + resolution: {integrity: sha512-QTAkfxQSsOGRza0hnkeAgJDQqR00iDerRNq42dOGIzgF+Kse491By3UmBEMG4oCbv17yYcBBlknQkzKSKtigjw==} + engines: {node: '>= 10'} + cpu: [x64] + os: [linux] + '@ast-grep/napi-linux-x64-gnu@0.36.2': resolution: {integrity: sha512-Xmb50HPfRNi+iLtHp+8/dqiTd8tjArYxOdj1tZzjRndpKhFpQDVrcOnPFObDCRgxVeLovdql9A1ad6BMcEL01Q==} engines: {node: '>= 10'} cpu: [x64] os: [linux] + '@ast-grep/napi-linux-x64-musl@0.33.0': + resolution: {integrity: sha512-PW6bZO7MyQsBNZv0idI/Ah6ak66T8LqZ21wBGjtQp9NDGViOtkLeu+eJJGaZjMqUdidKHKgmMKXksZHl2m8ulQ==} + engines: {node: '>= 10'} + cpu: [x64] + os: [linux] + '@ast-grep/napi-linux-x64-musl@0.36.2': resolution: {integrity: sha512-RSnqCsl3OBfJWh2rETtv3o7xd4QnbB2YTh6H6oYfFhhX0tlon/V+bUXI77hU2/W73hj9GHqWZsygsF43NXn/Hw==} engines: {node: '>= 10'} cpu: [x64] os: [linux] + '@ast-grep/napi-win32-arm64-msvc@0.33.0': + resolution: {integrity: sha512-ijmFQcFc32JOIQlSfnhDJpb3qFb2RhrRqfeY0EHHN1xRSGwZHfsHTSS66nKR2sREmxTIMgxXOtylKicbyyMVKA==} + engines: {node: '>= 10'} + cpu: [arm64] + os: [win32] + '@ast-grep/napi-win32-arm64-msvc@0.36.2': resolution: {integrity: sha512-/Q85h8F9K2G8qig0lndZWb+ykCfhfpSN27F3i7Aw5C0Ph7S6vFH76xn3l3dJTZb2CwUSsv4JNoqmFmY4B8DExQ==} engines: {node: '>= 10'} cpu: [arm64] os: [win32] + '@ast-grep/napi-win32-ia32-msvc@0.33.0': + resolution: {integrity: sha512-NNIb2VK3Z2BwKp0QJSw8gkhwOUp85SgTsxJ38p+wIUAA/KzAKCJOmyOaZ301qGHt4gL+jTHgTIvJJX+9eT/REg==} + engines: {node: '>= 10'} + cpu: [ia32] + os: [win32] + '@ast-grep/napi-win32-ia32-msvc@0.36.2': resolution: {integrity: sha512-bDdwErB7zf9DvRx3kNZyMKJb9by5ra24WAXSiVzI8MR387ibZP9UCTzKuGqPrbuZADYWiOgsg3nXMklyPFtmhQ==} engines: {node: '>= 10'} cpu: [ia32] os: [win32] + '@ast-grep/napi-win32-x64-msvc@0.33.0': + resolution: {integrity: sha512-gW7viQQjdPA1HoCkpCqoonC81TOwcpP828w/XqZFE/L6uhD8SF2usul8KNBQOiX3O7/fqYEOnbtWMCrwZIqG1Q==} + engines: {node: '>= 10'} + cpu: [x64] + os: [win32] + '@ast-grep/napi-win32-x64-msvc@0.36.2': resolution: {integrity: sha512-LVZ2DqP9fRfyUceE0BGnlKoPmSx3dYYApSEUdt82Pn7jEVWpFFyTLFmZ9ILiCSaVc6urMJpKWdxAHFqDNNlGfg==} engines: {node: '>= 10'} cpu: [x64] os: [win32] + '@ast-grep/napi@0.33.0': + resolution: {integrity: sha512-6heRMmomhSD0dkummRQ+R4xWXXmc41OaDPoPI49mKJXPyvwJPdPZUcQjXdIitOVL4uJV+qM2ZBucDPENDBSixw==} + engines: {node: '>= 10'} + '@ast-grep/napi@0.36.2': resolution: {integrity: sha512-ByenQQ0BtqqY0pvlmipvkDv/cKl/9vVjBydS7hloXOdmXPoUF0pHdlilC7ZfrRW97EzPQQZT2jgHl2tu7zg9QA==} engines: {node: '>= 10'} + '@ast-grep/nursery@0.0.2': + resolution: {integrity: sha512-Epb5KpdiXbHEOegPvEGejGI8UFtpK44Uz8lSb03mVbtBMB1VflMJ6/3wZz2CsZ65S0cdq5YQqt1Rm7E+S68oHQ==} + '@ast-grep/nursery@0.0.3': resolution: {integrity: sha512-fIOozkRrRHcDMv5t06SqUjQMkAwFgn1aiAtpXtOVpF19VE4oWK5MJOXbjI034cNGFDGGmCyMh7r0y2iWlTRRLw==} @@ -1172,6 +1249,9 @@ packages: tree_sitter: optional: true + tree-sitter-yaml@0.5.0: + resolution: {integrity: sha512-POJ4ZNXXSWIG/W4Rjuyg36MkUD4d769YRUGKRqN+sVaj/VCo6Dh6Pkssn1Rtewd5kybx+jT1BWMyWN0CijXnMA==} + tree-sitter@0.21.1: resolution: {integrity: sha512-7dxoA6kYvtgWw80265MyqJlkRl4yawIjO7S5MigytjELkX43fV2WsAXzsNfO7sBpPPCF5Gp0+XzHk0DwLCq3xQ==} @@ -1194,33 +1274,72 @@ packages: snapshots: + '@ast-grep/napi-darwin-arm64@0.33.0': + optional: true + '@ast-grep/napi-darwin-arm64@0.36.2': optional: true + '@ast-grep/napi-darwin-x64@0.33.0': + optional: true + '@ast-grep/napi-darwin-x64@0.36.2': optional: true + '@ast-grep/napi-linux-arm64-gnu@0.33.0': + optional: true + '@ast-grep/napi-linux-arm64-gnu@0.36.2': optional: true + '@ast-grep/napi-linux-arm64-musl@0.33.0': + optional: true + '@ast-grep/napi-linux-arm64-musl@0.36.2': optional: true + '@ast-grep/napi-linux-x64-gnu@0.33.0': + optional: true + '@ast-grep/napi-linux-x64-gnu@0.36.2': optional: true + '@ast-grep/napi-linux-x64-musl@0.33.0': + optional: true + '@ast-grep/napi-linux-x64-musl@0.36.2': optional: true + '@ast-grep/napi-win32-arm64-msvc@0.33.0': + optional: true + '@ast-grep/napi-win32-arm64-msvc@0.36.2': optional: true + '@ast-grep/napi-win32-ia32-msvc@0.33.0': + optional: true + '@ast-grep/napi-win32-ia32-msvc@0.36.2': optional: true + '@ast-grep/napi-win32-x64-msvc@0.33.0': + optional: true + '@ast-grep/napi-win32-x64-msvc@0.36.2': optional: true + '@ast-grep/napi@0.33.0': + optionalDependencies: + '@ast-grep/napi-darwin-arm64': 0.33.0 + '@ast-grep/napi-darwin-x64': 0.33.0 + '@ast-grep/napi-linux-arm64-gnu': 0.33.0 + '@ast-grep/napi-linux-arm64-musl': 0.33.0 + '@ast-grep/napi-linux-x64-gnu': 0.33.0 + '@ast-grep/napi-linux-x64-musl': 0.33.0 + '@ast-grep/napi-win32-arm64-msvc': 0.33.0 + '@ast-grep/napi-win32-ia32-msvc': 0.33.0 + '@ast-grep/napi-win32-x64-msvc': 0.33.0 + '@ast-grep/napi@0.36.2': optionalDependencies: '@ast-grep/napi-darwin-arm64': 0.36.2 @@ -1233,6 +1352,10 @@ snapshots: '@ast-grep/napi-win32-ia32-msvc': 0.36.2 '@ast-grep/napi-win32-x64-msvc': 0.36.2 + '@ast-grep/nursery@0.0.2': + dependencies: + '@ast-grep/napi': 0.33.0 + '@ast-grep/nursery@0.0.3': dependencies: '@ast-grep/napi': 0.36.2 @@ -1882,6 +2005,10 @@ snapshots: tree-sitter-cli: 0.23.2 which: 2.0.2 + tree-sitter-yaml@0.5.0: + dependencies: + nan: 2.22.2 + tree-sitter@0.21.1: dependencies: node-addon-api: 8.3.1