Exemplo n.º 1
0
    private IRegExNode <char> ParsePostfix()
    {
        var atom = this.ParseAtom();

        if (this.Match('?'))
        {
            return(RegEx.Opt(atom));
        }
        if (this.Match('*'))
        {
            return(RegEx.Rep0(atom));
        }
        if (this.Match('+'))
        {
            return(RegEx.Rep1(atom));
        }
        if (this.Match('{'))
        {
            if (this.Match(','))
            {
                var atMost = this.ParseNumber();
                this.Expect('}');
                return(RegEx.AtMost(atMost, atom));
            }
            else
            {
                var atLeast = this.ParseNumber();
                if (this.Match('}'))
                {
                    return(RegEx.Exactly(atLeast, atom));
                }
                if (this.Match(','))
                {
                    if (this.Match('}'))
                    {
                        return(RegEx.AtLeast(atLeast, atom));
                    }
                    var atMost = this.ParseNumber();
                    this.Expect('}');
                    return(RegEx.Between(atLeast, atMost, atom));
                }
            }
        }
        return(atom);
    }