Skip to content
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/tired-comics-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ast-grep/lang-scala": patch
---

Add @ast-grep/lang-scala
24 changes: 24 additions & 0 deletions packages/scala/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# ast-grep napi language for scala

## Installation

In a pnpm project, run:

```bash
pnpm install @ast-grep/lang-scala
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 scala from '@ast-grep/lang-scala'
import { registerDynamicLanguage, parse } from '@ast-grep/napi'

registerDynamicLanguage({ scala })

const sg = parse('scala', `your code`)
sg.root().kind()
```
10 changes: 10 additions & 0 deletions packages/scala/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
9 changes: 9 additions & 0 deletions packages/scala/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const path = require('node:path')
const libPath = path.join(__dirname, 'parser.so')

module.exports = {
libraryPath: libPath,
extensions: ['scala', 'sc', 'sbt'],
languageSymbol: 'tree_sitter_scala',
expandoChar: '$',
}
16 changes: 16 additions & 0 deletions packages/scala/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: 'scala',
treeSitterPackage: 'tree-sitter-scala',
languageRegistration,
testRunner: parse => {
const sg = parse('val a = 0')
const root = sg.root()
const node = root.find('val $A = 0')
assert.equal(node.kind(), 'val_definition')
},
})
47 changes: 47 additions & 0 deletions packages/scala/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "@ast-grep/lang-scala",
"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

Confirm all necessary files are included in the package.

The files array includes index.js, type definitions, and postinstall.js, but there's no reference to parser.so which is used in index.js. Make sure this file gets included either through the build process or by adding it explicitly to the files array.


🏁 Script executed:

#!/bin/bash
# Check if parser.so gets created during build and where it's located
ls -la packages/scala/

Length of output: 507


Action Required: Ensure parser.so is Included in the Package

The parser.so file referenced in index.js was not found in the package directory output. Please verify that:

  • It is generated by the build process and placed within an included folder (e.g., inside src or prebuilds),
  • Or, if not automatically generated, explicitly add it to the "files" array in packages/scala/package.json (for example, by appending "parser.so").

"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-scala": "0.23.4"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
},
"pnpm": {
"onlyBuiltDependencies": ["@ast-grep/lang-scala", "tree-sitter-cli"]
}
}
4 changes: 4 additions & 0 deletions packages/scala/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.