Skip to content

✨ Haskell #50

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 3 commits into from
Apr 4, 2025
Merged

Conversation

NatoBoram
Copy link
Collaborator

@NatoBoram NatoBoram commented Apr 2, 2025

Summary by CodeRabbit

  • New Features

    • Introduced Haskell language support to enhance code parsing and analysis capabilities in the project.
  • Documentation

    • Added comprehensive installation instructions and usage examples to facilitate integration of the new Haskell support.
  • Tests

    • Implemented automated tests to verify the correct parsing and recognition of Haskell code constructs.

Copy link

coderabbitai bot commented Apr 2, 2025

Walkthrough

This pull request introduces a new Haskell language support package into the system. A changeset entry records the inclusion of @ast-grep/lang-haskell. Alongside, new documentation is provided along with type definitions, code exports, and a testing setup. Additionally, package metadata, build scripts, and post-install routines specific to the package are added. These changes collectively establish language registration, integration, and testing capabilities for Haskell in the project.

Changes

File(s) Change Summary
.changeset/slow-rocks-ask.md Added a patch entry recording the inclusion of @ast-grep/lang-haskell.
packages/haskell/README.md Introduced documentation with installation instructions and usage examples for the Haskell language support package.
packages/haskell/index.{js,d.ts} Added language registration definitions: new type LanguageRegistration in TypeScript and an exported object (with libraryPath, extensions, etc.) in JavaScript.
packages/haskell/nursery.js Created a testing setup using @ast-grep/nursery, including a test runner that parses Haskell code and asserts syntax node types.
packages/haskell/{package.json, postinstall.js} Added package metadata with dependencies and scripts in package.json and introduced a postinstall script to execute configuration setup.

Sequence Diagram(s)

sequenceDiagram
    participant Tester
    participant Nursery
    participant Parser
    Tester->>Nursery: Initiate Haskell test setup
    Nursery->>Parser: Parse sample "let x = 3 in x + x"
    Parser-->>Nursery: Return syntax tree
    Nursery->>Tester: Validate node type "let_in"
Loading
sequenceDiagram
    participant App
    participant HaskellModule
    App->>HaskellModule: Import language registration details
    HaskellModule-->>App: Provide libraryPath, extensions, languageSymbol, expandoChar
Loading

Suggested reviewers

  • HerringtonDarkholme

Poem

I'm a rabbit with hops so high,
Coding under a bright blue sky,
New Haskell support makes me sing,
In docs and tests, joy I bring,
With every nibble of fresh code delight,
I dance through changes, morning to night! 🐰🌟

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (5)
packages/haskell/README.md (1)

1-25: Enhance README with more comprehensive documentation.

While the README provides basic installation and usage instructions, consider enhancing it with:

  1. A more descriptive introduction about what ast-grep does and why Haskell support is valuable
  2. Information about prerequisites/requirements
  3. More detailed examples showing pattern matching or other key features
  4. Links to related documentation or the main ast-grep project
 # ast-grep napi language for haskell
+
+This package provides Haskell language support for [ast-grep](https://github.com/ast-grep/ast-grep), enabling structural search and pattern matching on Haskell code.
 
 ## Installation
 
 In a pnpm project, run:
 
 ```bash
 pnpm install @ast-grep/lang-haskell
 pnpm install @ast-grep/napi
 # install the tree-sitter-cli if no prebuild is available
 pnpm install @tree-sitter/cli --save-dev

+### Prerequisites
+
+- Node.js 14 or later
+- pnpm package manager

Usage

import haskell from '@ast-grep/lang-haskell'
import { registerDynamicLanguage, parse } from '@ast-grep/napi'

registerDynamicLanguage({ haskell })

const sg = parse('haskell', `your code`)
sg.root().kind()

+### Pattern Matching Example
+
+js +import haskell from '@ast-grep/lang-haskell' +import { registerDynamicLanguage, parse, match } from '@ast-grep/napi' + +registerDynamicLanguage({ haskell }) + +// Parse Haskell code +const code = ` +factorial :: Integer -> Integer +factorial 0 = 1 +factorial n = n * factorial (n - 1) +` + +const sg = parse('haskell', code) + +// Match function definitions +const matches = match(sg, `factorial $_`) +console.log(matches.length) // 2 - matches both factorial patterns +
+
+## Related Links
+
+- ast-grep Documentation
+- Tree-sitter Haskell Grammar


</blockquote></details>
<details>
<summary>packages/haskell/nursery.js (1)</summary><blockquote>

`10-15`: **Consider adding error handling to the test runner.**

While the current test is straightforward, it would be more robust to include error handling for the case where the pattern might not be found.

```diff
  testRunner: parse => {
    const sg = parse('let x = 3 in x + x')
    const root = sg.root()
    const node = root.find('let $A = $B in $A + $A')
+   if (!node) {
+     throw new Error('Expected pattern was not found in the parsed tree')
+   }
    assert.equal(node.kind(), 'let_in')
  },
packages/haskell/index.js (1)

6-6: Consider adding support for literate Haskell files.

Haskell code can also be written in literate style with the .lhs extension. Adding this extension would provide more complete language support.

-  extensions: ['hs'],
+  extensions: ['hs', 'lhs'],
packages/haskell/package.json (2)

4-4: Add a meaningful description to the package.

The description field is currently empty. Adding a concise description would make the package's purpose clearer to users.

-  "description": "",
+  "description": "Haskell language support for ast-grep",

22-22: Add author information to the package.

The author field is currently empty. Consider adding appropriate author information.

-  "author": "",
+  "author": "ast-grep contributors",
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e7a802d and cc33798.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (7)
  • .changeset/slow-rocks-ask.md (1 hunks)
  • packages/haskell/README.md (1 hunks)
  • packages/haskell/index.d.ts (1 hunks)
  • packages/haskell/index.js (1 hunks)
  • packages/haskell/nursery.js (1 hunks)
  • packages/haskell/package.json (1 hunks)
  • packages/haskell/postinstall.js (1 hunks)
🔇 Additional comments (6)
.changeset/slow-rocks-ask.md (1)

1-6: Changeset looks good.

The changeset correctly identifies the new package and uses the appropriate format with package name, version bump type (patch), and a concise description.

packages/haskell/postinstall.js (1)

1-4: Implementation looks clean and follows best practices.

The post-installation script is concise and follows the correct pattern for language setup. It properly imports the necessary function and passes the current directory.

packages/haskell/index.d.ts (1)

1-10: Type definitions are clear and well-structured.

The LanguageRegistration type correctly defines the required and optional properties needed for language registration. The export pattern follows TypeScript conventions.

packages/haskell/nursery.js (1)

1-16: LGTM. Basic test setup for Haskell language support.

The nursery setup looks good with a appropriate test case that verifies the Haskell parser correctly identifies the structure of a simple let-in expression.

packages/haskell/index.js (1)

4-9: LGTM. Proper language registration configuration.

The language registration exports all the necessary properties for integrating Haskell with ast-grep.

packages/haskell/package.json (1)

1-47: LGTM. Package configuration looks correct.

The package.json contains all the necessary configurations for building, testing, and publishing the Haskell language support package.

@HerringtonDarkholme HerringtonDarkholme merged commit 3a65b70 into ast-grep:main Apr 4, 2025
3 checks passed
@NatoBoram NatoBoram deleted the feature/haskell branch April 5, 2025 02:44
This was referenced Apr 5, 2025
@coderabbitai coderabbitai bot mentioned this pull request Apr 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants