GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - s97712/TypeScriptParser at ff05e904c7c9a639ee1c92ca6bc87e0be0e28595

BranchesTags
Open more actions menu

Latest commit

 

History

16 Commits
16 Commits

Folders and files

NameName
Last commit message
Last commit date
TypeScriptParser.Tests
TypeScriptParser.Tests
 
 
TypeScriptParser
TypeScriptParser
 
 
tree-sitter
tree-sitter
 
 
.gitignore
.gitignore
 
 
.gitmodules
.gitmodules
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
TypeScriptParser.sln
TypeScriptParser.sln
 
 

Repository files navigation

TypeScriptParser

Introduction

TypeScriptParser provides C# bindings for the Tree-sitter parsing library, specifically optimized for TypeScript language parsing. Through P/Invoke calls, C# developers can directly use the powerful Tree-sitter parsing functionality in the .NET environment.

Project Structure

  • TypeScriptParser: Main library project containing complete Tree-sitter C# bindings and TypeScript parser
  • TypeScriptParser.Tests: xUnit test project ensuring parser correctness

Features

  • Complete Tree-sitter API C# bindings
  • Dedicated TypeScript language support
  • Syntax tree traversal and querying
  • Memory-safe resource management
  • Support for incremental parsing and syntax tree editing

Requirements

  • .NET 9.0 or higher
  • Windows/Linux/macOS (cross-platform support)
  • x64 architecture

Setup

Pull the required submodules:

git submodule update --init --recursive

Building

  1. Build native dependency libraries:

    cd tree-sitter
    make  # Linux/macOS
    # or use nmake on Windows
    cd ..
  2. Build the .NET project:

    dotnet build

Usage

Basic Usage Example

using TreeSitter.TypeScript;

// Create parser instance
using var parser = new TypeScriptParser();

// Parse TypeScript code
string sourceCode = "const message: string = 'Hello, World!';";
using var tree = parser.ParseString(sourceCode);

// Get root node
var rootNode = tree.root_node();

// Create cursor for tree traversal
using var cursor = parser.CreateCursor(tree);

Syntax Tree Traversal

using var parser = new TypeScriptParser();
string code = @"
function greet(name: string): string {
    return `Hello, ${name}!`;
}
";

using var tree = parser.ParseString(code);
using var cursor = parser.CreateCursor(tree);

// Traverse syntax tree
while (cursor.goto_first_child())
{
    var node = cursor.current_node();
    Console.WriteLine($"Node: {node.type()}, Text: {node.text(code)}");
}

API Documentation

TypeScriptParser Class

  • ParseString(string sourceCode): Parse string and return syntax tree
  • CreateCursor(TSTree tree): Create syntax tree cursor
  • Language: Get TypeScript language object
  • IsAvailable: Check if parser is available

Core Types

  • TSTree: Syntax tree object
  • TSNode: Syntax tree node
  • TSCursor: Syntax tree cursor
  • TSLanguage: Language definition
  • TSParser: Underlying parser

Testing

Run unit tests:

dotnet test

Tests cover core parser functionality:

  • Basic parsing functionality
  • Error handling
  • Resource management
  • Syntax tree traversal

Performance Features

  • Incremental parsing: Support for incremental updates to existing syntax trees
  • Memory efficiency: Uses reference counting and automatic garbage collection
  • High-speed parsing: Based on LR parsing algorithm
  • Error recovery: Able to recover from syntax errors and continue parsing

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

Issues and Pull Requests are welcome! Before contributing, please ensure:

  1. All tests run and pass
  2. Follow existing code style
  3. Add appropriate test cases for new features

Technology Stack

  • Language: C# (.NET 9.0)
  • Test Framework: xUnit
  • Native Interop: P/Invoke
  • Package Management: NuGet
  • Build System: MSBuild

For more information, visit the Tree-sitter official documentation

About

基于Tree-sitter的TypeScript解析器 - .NET绑定

Resources

Readme
License
Activity

Stars

1 star

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.