Skip to content

Releases: nemesissoft/Nemesis.TextParsers

Add code gen package

25 Feb 14:24
Compare
Choose a tag to compare

Add code generation package that automatically generates necessary transformers

C# 9.0 Code generation

With introduction of new code-gen engine, you can opt to have your transformer generated automatically without any imperative code.

//1. use specially provided (via code-gen) Auto.AutoDeconstructable attribute
[Auto.AutoDeconstructable]
//2. provide deconstructable aspect options or leave this attribute out - default options will be engaged 
[DeconstructableSettings('_', '∅', '%', '〈', '〉')]
readonly partial /*3. partial modifier is VERY important - you need this cause generated code is placed in different file*/ struct StructPoint3d
{
    public double X { get; }
    public double Y { get; }
    public double Z { get; }

    //4. specify constructor and matching deconstructor 
    public StructPoint3d(double x, double y, double z) { X = x; Y = y; Z = z; }

    public void Deconstruct(out double x, out double y, out double z) { x = X; y = Y; z = Z; }
}

//5. sit back, relax and enjoy - code-gen will do the job for you :-)

This in turn might generate the following (parts of code ommited for brevity)

using /* ... */;
[Transformer(typeof(StructPoint3dTransformer))]
readonly partial struct StructPoint3d { }

sealed class StructPoint3dTransformer : TransformerBase<StructPoint3d>
{
    private readonly ITransformer<double> _transformer_x = TextTransformer.Default.GetTransformer<double>();
    /* specify remaining transformers... */
    private const int ARITY = 3;
    private readonly TupleHelper _helper = new TupleHelper('_', '∅', '%', '〈', '〉');

    protected override StructPoint3d ParseCore(in ReadOnlySpan<char> input)
    {
        var enumerator = _helper.ParseStart(input, ARITY);
        var t1 = _helper.ParseElement(ref enumerator, _transformer_x);        
        /* parse Y and Z... */
        _helper.ParseEnd(ref enumerator, ARITY);
        return new StructPoint3d(t1, t2, t3);
    }

    public override string Format(StructPoint3d element)
    {
        Span<char> initialBuffer = stackalloc char[32];
        var accumulator = new ValueSequenceBuilder<char>(initialBuffer);
        try
        {
             _helper.StartFormat(ref accumulator);
             var (x, y, z) = element;
            _helper.FormatElement(_transformer_x, x, ref accumulator);
            /* format Y and Z... */
            _helper.EndFormat(ref accumulator);
            return accumulator.AsSpan().ToString();
        }
        finally { accumulator.Dispose(); }
    }
}

Code gen diagnositcs

Various diagnositcs exist to guide end user in creation of proper types that can be consumed by automatic generation. They might for example:

  1. check if types decorated with Auto* attributes are declared partial (prerequisite for additive code generation)
  2. validate settings passed via declarative syntax
  3. validate internal structure of type (i.e. check if constructor has matching Deconstruct method)
  4. check if external dependencies are included

Add code gen package

25 Feb 13:49
Compare
Choose a tag to compare
v2.6

Fix unit tests for code gen

Rework settings to records

31 Dec 14:34
Compare
Choose a tag to compare
  • Rework settings to records with native support for with operator.
  • Code gen: Add full debugging support.

Code gen capabilities

30 Nov 22:27
Compare
Choose a tag to compare
  • General .NET 5 standards cleanup
  • Add code gen capabilities
  • Fix unit tests
  • Fix LeanCollection operators
  • Add support for System.Half type
  • Add settings for automatic Deconstructable pattern
  • Improve Deconstructable generation

Upgrade to net5.0

16 Nov 16:15
Compare
Choose a tag to compare
  • Upgrade to net5.0
  • Make NumberTransformerCache helper public
  • Add diagnostic clues for transformer creators
  • Demonstrate using records with automatic/custom serialization

TextSyntaxProvider rename

15 May 09:08
Compare
Choose a tag to compare
v2.2.1

TextSyntaxProvider rename

Format grammar discovery feature based on TransformationStore and settings

14 May 22:33
Compare
Choose a tag to compare
Format grammar discovery feature based on TransformationStore and set…

…tings

Introduce transforming of ArraySegment<>

12 May 22:59
Compare
Choose a tag to compare
v2.1.2

Introduce transforming of ArraySegment<>

Add TryParse to transformers. Reuse number transformers to double duty as enum parsers

01 May 20:28
Compare
Choose a tag to compare
Add TryParse to transformers. Reuse number transformers to double dut…

…y as enum parsers

Add support for transforming Version, IPAddress, Regex

28 Apr 22:05
Compare
Choose a tag to compare
v2.1.0

Add support for transforming Version, IPAddress, Regex