tree-sitter-c-sharp icon indicating copy to clipboard operation
tree-sitter-c-sharp copied to clipboard

[BUG] Mis-alignment when parsing accents

Open nicolas-goyon opened this issue 8 months ago • 0 comments

Hi, I am unsure of what to put here so i'll try to put as much information as i can.

Context

I'm currently using the pip library.

The problem

Using accents create an offest in the AST.

I can't stop using them because I have user feedback (not in this code, but in general in my software)

Using accents

The Csharp script

using System.Text.RegularExpressions;

namespace HUBLoader.Types;


public class TypeArret
{
    private readonly string bits;

    public TypeArret(string rawBits)
    {
        if (rawBits.Length != 20)
            throw new ArgumentException($"TypeArret doit contenir exactement 20 caractères (reçu {rawBits.Length})");

        if (!Regex.IsMatch(rawBits, "^[ON]{20}$", RegexOptions.IgnoreCase))
            throw new ArgumentException("TypeArret ne doit contenir que des caractères 'O' ou 'N'.");

        bits = rawBits.ToUpperInvariant();
    }

    public bool EstActif(TypeArretFlag flag)
    {
        return bits[(int)flag] == 'O';
    }

    public override string ToString()
    {
        return bits;
    }
}

AST to JSON

Too long for github

Without accents

Csharp script

using System.Text.RegularExpressions;

namespace HUBLoader.Types;


public class TypeArret
{
    private readonly string bits;

    public TypeArret(string rawBits)
    {
        if (rawBits.Length != 20)
            throw new ArgumentException($"TypeArret doit contenir exactement 20 caracteres (recu {rawBits.Length})");

        if (!Regex.IsMatch(rawBits, "^[ON]{20}$", RegexOptions.IgnoreCase))
            throw new ArgumentException("TypeArret ne doit contenir que des caracteres 'O' ou 'N'.");

        bits = rawBits.ToUpperInvariant();
    }

    public bool EstActif(TypeArretFlag flag)
    {
        return bits[(int)flag] == 'O';
    }

    public override string ToString()
    {
        return bits;
    }
}

AST to JSON

Too long for github

nicolas-goyon avatar Apr 15 '25 14:04 nicolas-goyon