diff --git a/.changeset/brave-hairs-dress.md b/.changeset/brave-hairs-dress.md new file mode 100644 index 0000000..9b6490c --- /dev/null +++ b/.changeset/brave-hairs-dress.md @@ -0,0 +1,5 @@ +--- +"@ast-grep/lang-bash": patch +--- + +Added @ast-grep/lang-bash diff --git a/packages/bash/README.md b/packages/bash/README.md new file mode 100644 index 0000000..4fb2717 --- /dev/null +++ b/packages/bash/README.md @@ -0,0 +1,24 @@ +# ast-grep napi language for bash + +## Installation + +In a pnpm project, run: + +```bash +pnpm install @ast-grep/lang-bash +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 bash from '@ast-grep/lang-bash' +import { registerDynamicLanguage, parse } from '@ast-grep/napi' + +registerDynamicLanguage({ bash }) + +const sg = parse('bash', `your code`) +sg.root().kind() +``` diff --git a/packages/bash/index.d.ts b/packages/bash/index.d.ts new file mode 100644 index 0000000..11140a6 --- /dev/null +++ b/packages/bash/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/bash/index.js b/packages/bash/index.js new file mode 100644 index 0000000..9056f2d --- /dev/null +++ b/packages/bash/index.js @@ -0,0 +1,21 @@ +const path = require('node:path') +const libPath = path.join(__dirname, 'parser.so') + +module.exports = { + libraryPath: libPath, + extensions: [ + 'bash', + 'bats', + 'cgi', + 'command', + 'env', + 'fcgi', + 'ksh', + 'sh', + 'tmux', + 'tool', + 'zsh', + ], + languageSymbol: 'tree_sitter_bash', + expandoChar: '$', +} diff --git a/packages/bash/nursery.js b/packages/bash/nursery.js new file mode 100644 index 0000000..6feaa8c --- /dev/null +++ b/packages/bash/nursery.js @@ -0,0 +1,16 @@ +const { setup } = require('@ast-grep/nursery') +const assert = require('node:assert') +const languageRegistration = require('./index') + +setup({ + dirname: __dirname, + name: 'bash', + treeSitterPackage: 'tree-sitter-bash', + languageRegistration, + testRunner: parse => { + const sg = parse('echo test') + const root = sg.root() + const node = root.find('echo $A') + assert.equal(node.kind(), 'command') + }, +}) diff --git a/packages/bash/package.json b/packages/bash/package.json new file mode 100644 index 0000000..f49b65c --- /dev/null +++ b/packages/bash/package.json @@ -0,0 +1,47 @@ +{ + "name": "@ast-grep/lang-bash", + "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-bash": "0.23.3", + "tree-sitter-cli": "0.24.6" + }, + "publishConfig": { + "access": "public", + "registry": "https://registry.npmjs.org/" + }, + "pnpm": { + "onlyBuiltDependencies": ["@ast-grep/lang-bash", "tree-sitter-cli"] + } +} diff --git a/packages/bash/postinstall.js b/packages/bash/postinstall.js new file mode 100644 index 0000000..b9141ff --- /dev/null +++ b/packages/bash/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 08634c8..82d59be 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -34,6 +34,22 @@ importers: specifier: 0.24.6 version: 0.24.6 + packages/bash: + 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-bash: + specifier: 0.23.3 + version: 0.23.3(tree-sitter@0.21.1) + tree-sitter-cli: + specifier: 0.24.6 + version: 0.24.6 + packages/c: dependencies: '@ast-grep/setup-lang': @@ -789,6 +805,14 @@ packages: tree_sitter: optional: true + tree-sitter-bash@0.23.3: + resolution: {integrity: sha512-36cg/GQ2YmIbeiBeqeuh4fBJ6i4kgVouDaqTxqih5ysPag+zHufyIaxMOFeM8CeplwAK/Luj1o5XHqgdAfoCZg==} + peerDependencies: + tree-sitter: ^0.21.1 + peerDependenciesMeta: + tree-sitter: + optional: true + tree-sitter-c-sharp@0.23.1: resolution: {integrity: sha512-9zZ4FlcTRWWfRf6f4PgGhG8saPls6qOOt75tDfX7un9vQZJmARjPrAC6yBNCX2T/VKcCjIDbgq0evFaB3iGhQw==} peerDependencies: @@ -1447,6 +1471,13 @@ snapshots: tree-sitter: 0.21.1 tree-sitter-html: 0.20.4(tree-sitter@0.21.1) + tree-sitter-bash@0.23.3(tree-sitter@0.21.1): + dependencies: + node-addon-api: 8.3.1 + node-gyp-build: 4.8.4 + optionalDependencies: + tree-sitter: 0.21.1 + tree-sitter-c-sharp@0.23.1(tree-sitter@0.21.1): dependencies: node-addon-api: 8.3.0