Skip to content

✨ Bash #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 4, 2025
Merged
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
5 changes: 5 additions & 0 deletions .changeset/brave-hairs-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ast-grep/lang-bash": patch
---

Added @ast-grep/lang-bash
24 changes: 24 additions & 0 deletions packages/bash/README.md
Original file line number Diff line number Diff line change
@@ -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()
```
10 changes: 10 additions & 0 deletions packages/bash/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
type LanguageRegistration = {
libraryPath: string
extensions: string[]
languageSymbol?: string
metaVarChar?: string
expandoChar?: string
}

declare const registration: LanguageRegistration
export default registration
21 changes: 21 additions & 0 deletions packages/bash/index.js
Original file line number Diff line number Diff line change
@@ -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: '$',
}
16 changes: 16 additions & 0 deletions packages/bash/nursery.js
Original file line number Diff line number Diff line change
@@ -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')
},
})
47 changes: 47 additions & 0 deletions packages/bash/package.json
Original file line number Diff line number Diff line change
@@ -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"
],
Comment on lines +13 to +20
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Verify the existence of type.d.ts and consider adding nursery.js to files.

The files list appears to include most necessary files, but has potential issues.


🏁 Script executed:

#!/bin/bash
# Check if type.d.ts exists and if nursery.js is needed in the files array

# Check for type.d.ts
echo "Checking for type.d.ts file..."
if [ -f "packages/bash/type.d.ts" ]; then
  echo "type.d.ts exists."
else
  echo "type.d.ts is listed in files array but does not exist."
fi

# Check for nursery.js
echo "Checking for nursery.js file..."
if [ -f "packages/bash/nursery.js" ]; then
  echo "nursery.js exists but is not included in the files array."
else
  echo "nursery.js does not exist."
fi

Length of output: 462


Action Required: Update Files Array in packages/bash/package.json

  • Missing File: The entry type.d.ts is listed but does not exist in the repository. Please either create this file if it's needed or remove the entry from the files array.
  • Omitted File: The file nursery.js exists in the repository but is not included in the files array. Please consider adding it if it’s meant to be part of the package distribution.

"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"]
}
}
4 changes: 4 additions & 0 deletions packages/bash/postinstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const { postinstall } = require('@ast-grep/setup-lang')
postinstall({
dirname: __dirname,
})
31 changes: 31 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.