XSharp.VsParser.Helpers 24.18.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package XSharp.VsParser.Helpers --version 24.18.0                
NuGet\Install-Package XSharp.VsParser.Helpers -Version 24.18.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="XSharp.VsParser.Helpers" Version="24.18.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add XSharp.VsParser.Helpers --version 24.18.0                
#r "nuget: XSharp.VsParser.Helpers, 24.18.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install XSharp.VsParser.Helpers as a Cake Addin
#addin nuget:?package=XSharp.VsParser.Helpers&version=24.18.0

// Install XSharp.VsParser.Helpers as a Cake Tool
#tool nuget:?package=XSharp.VsParser.Helpers&version=24.18.0                

XSharp.Parser.Helpers

Introduction

XSharp.VsParser.Helpers contains some helper classes, that simplify the parsing and rewriting of XSharp code files. It uses the VsParser.Dll of the XSharp project.

Requirements

In order to use this Nuget, you must install a version of the XSharp Compiler and accept the terms and conditions of the XSharp project.

Classes

ProjectHelper

  • Get the Options for the parser initialisiation
  • Get a list of all the files in the project

ParserHelper

  • Parses a xsharp file and exposes it as tree
  • Tree
    • Can be enumerated
    • Exposes a Rewriter to change the source code
    • Can dump the tree as Xml or Yaml
  • Comments

CacheHelper

  • Caches serializable data objects for source files
  • Is helpful to store calculated data to reduce the amount of files to parse

FileExtensionHelper

  • Detects the most likely encoding of a file

Extension Methods

A series of IParseTree extension methods like

  • WhereType or WhereTypeWithChildren to filter the tree
  • FirstParentOrDefault to get a specific parent matching the type
  • ToValues Methods for Class, Method, ... to give easy access to important values

Check the IParseTreeExtensions, ToIndexExtensions and ToValueExtensions files in the Parser folder for the complete list.

RewriteFor extension methods

A series of helper methods for code rewriting. Check the Rewriter folder for the complete list.

Examples

This is a simple example on how to use the ParserHelper to parse source code and extract information from the tree.

string sampleSourceCode = @"
// Example Class
class Example inherit BaseExample
    
    // Dummy Method
    method Dummy(value)
        System.Console.WriteLine(value)
        return
end class
";

// For this example, we initialize the parser with the default options. Normally, the options should be loaded usind the ProjectHelper
var parser = ParserHelper.BuildWithVoDefaultOptions();

// To get access to the tree, we have to parse the source code first
var result = parser.ParseText(sampleSourceCode, "dummy.prg");
if (!result.OK)
    throw new Exception("File can not be parsed");

// Now we can access the tree. The first step is normaly to dump the tree to yaml to get a better understanding of the IParseTree items, that were created based on our source code
var dump = parser.Tree.DumpYaml();
Console.WriteLine(dump);

// in the dump we noticed, that the parser creates a class_context for every class. We can use that to find the first class_context.
var classContext = parser.Tree.FirstOrDefaultType<Class_Context>();

// from the class context we can extract the class name using the ToValue extension method
var className = classContext?.ToValues().Name;
Console.WriteLine(className);

// to get all the child nodes of the classContext, whe use AsEnumerable 
var classChilds = classContext.AsEnumerable();

// now we want to count methods of the class. we use whereType and Count
var methodsCount = classChilds.WhereType<MethodContext>().Count();
Console.WriteLine(methodsCount);

Check the XSharp.VsParser.Helpers.Tests project for additional samples on how to use the parser helper

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
24.25.1 116 6/21/2024
24.18.8 134 4/29/2024
24.18.0 109 4/29/2024
23.42.0 195 10/19/2023
23.28.0 178 7/13/2023
23.27.8 159 7/3/2023
22.38.1 465 9/19/2022
22.37.1 440 9/15/2022
22.28.0 434 7/15/2022