Skip to content

GroupSeparator gets in the way of parsing lists #223

@emayevski

Description

@emayevski

When parsing a construct like "1, 2, 3" and group separators are enabled for numbers, the parser treats a comma as a group separator. Then it does return just a number, but the "separator" itself (not a separator at all) is lost. The problem is in this code of ReadDecimal() in Scanner.cs:

        // Number can be empty if we have a decimal separator directly, in this case don't expect group separators
        if (!number.IsEmpty && allowGroupSeparator && Cursor.Current == groupSeparator)
        {
            // Group separators can be repeated as many times
            while (true)
            {
                if (Cursor.Current == groupSeparator)
                {
                    Cursor.AdvanceNoNewLines(1);
                }
                else
                if (!ReadInteger())
                {
                    break;
                }
            }
        }

The solution is to restore the cursor to point at the first "group separator" as follows:

        // Number can be empty if we have a decimal separator directly, in this case don't expect group separators
        if (!number.IsEmpty && allowGroupSeparator && Cursor.Current == groupSeparator)
        {
            var savedCursor = Cursor.Position;
            // Group separators can be repeated as many times
            while (true)
            {
                if (Cursor.Current == groupSeparator)
                {
                    Cursor.AdvanceNoNewLines(1);
                }
                else
                if (!ReadInteger())
                {
                    // it was not a group separator, really, so go back where the symbol was and stop
                    Cursor.ResetPosition(savedCursor);
                    break;
                }
            }
        }

I will create a separate pull request for this fix later.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions