Skip to content
 
 

Repository files navigation

dotnet-ast-parsef

Changed packager image to karthik one added debug and reverted manual change added build action packager - proto defination added A Roslyn-based command-line tool to parse C# and Razor source files and serialize their Abstract Syntax Trees (AST) to Protocol Buffer binary format.

Features

sssssfn

  • C# Parsing: Parse .cs files and serialize to Protobuf binary format
  • Razor Support: Parse .cshtml and .razor filesf
  • Batch Processing: Process entire directories recursively
  • AST Viewer: GUI tree view for visualizing AST structure
  • Console Output: Detailed recursive AST display with line numbers and span information d

Getting Started

Cloning the Repository

This project includes a Git submodule for Protocol Buffer definitions. When cloning, use the --recurse-submodules flag:

git clone --recurse-submodules <repository-url>

If you've already cloned the repository without submodules, initialize them:

git submodule update --init --recursive

To update the submodule to the latest version:

git submodule update --remote

Usage

Parse C# Files

Parse a single file:

dotnet-ast-parse parse MyFile.cs -o output.bin

Parse a directory:

dotnet-ast-parse parse ./src -o ./ast-output

View AST

Display AST in GUI:

dotnet-ast-view deserialize output.bin --gui

Display AST in console:

dotnet-ast-view deserialize output.bin

Commands

parse

Parse C# and Razor source files and serialize to Protobuf binary format.

Arguments:

  • file - Path to the source file(s) to parse (file or directory)

Options:

  • -o, --output - Output file path for the serialized Protobuf binary AST. If not specified, defaults to input filename(s) with .bin extension.

deserialize

Deserialize a Protobuf binary AST file and display all data.

Arguments:

  • file - Path to the Protobuf binary AST file to deserialize

Options:

  • -g, --gui - Display the AST in a graphical tree view window

Output Format

AST data is serialized using Protocol Buffers with the following schema:

  • Location: Span information including line number, span start, span length, and line length
  • SyntaxElement: Node/Token with kind, type, location, and trivia
  • Trivia: Leading and trailing trivia (comments, whitespace, etc.)
  • SyntaxTree: Root element with total node count

Building

dotnet build

License

This project uses the Roslyn compiler platform (Apache 2.0 license).

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages