Ejemplo n.º 1
0
        public override bool Lex(GrammarDefinition grammar, string source, ref int offset)
        {
            for (int i = 0; i < Literal.Length; i++)
            {
                if ((offset + i) >= source.Length)
                {
                    return(false);
                }

                if (grammar.IsCaseInsensitive)
                {
                    if (char.ToLowerInvariant(source[offset + i]) != char.ToLowerInvariant(Literal[i]) &&
                        char.ToUpperInvariant(source[offset + i]) != char.ToUpperInvariant(Literal[i]))
                    {
                        return(false);
                    }
                }
                else
                {
                    if (source[offset + i] != Literal[i])
                    {
                        return(false);
                    }
                }
            }

            offset += Literal.Length;
            return(true);
        }
Ejemplo n.º 2
0
        public override bool Lex(GrammarDefinition grammar, string source, ref int offset)
        {
            switch (Type)
            {
            case QuantificationType.ZeroOrMore:
                while (Quantified.Lex(grammar, source, ref offset))
                {
                }
                return(true);

            case QuantificationType.OneOrMore:
                if (!Quantified.Lex(grammar, source, ref offset))
                {
                    return(false);
                }
                while (Quantified.Lex(grammar, source, ref offset))
                {
                }
                return(true);

            case QuantificationType.ZeroOrOne:
                Quantified.Lex(grammar, source, ref offset);
                return(true);

            default:
                throw new InvalidOperationException();
            }
        }
Ejemplo n.º 3
0
 public bool Contains(GrammarDefinition grammar, char c)
 {
     if (grammar.IsCaseInsensitive)
     {
         return(ContainsSensitive(char.ToLowerInvariant(c)) || ContainsSensitive(char.ToUpperInvariant(c)));
     }
     else
     {
         return(ContainsSensitive(c));
     }
 }
Ejemplo n.º 4
0
 public override bool Lex(GrammarDefinition grammar, string source, ref int offset)
 {
     foreach (var alt in Alternatives)
     {
         if (alt.Lex(grammar, source, ref offset))
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 5
0
        public override bool Lex(GrammarDefinition grammar, string source, ref int offset)
        {
            var original = offset;

            foreach (var item in Sequences)
            {
                if (!item.Lex(grammar, source, ref offset))
                {
                    offset = original;
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 6
0
        public override bool Lex(GrammarDefinition grammar, string source, ref int offset)
        {
            if (offset >= source.Length)
            {
                return(false);
            }

            if (CharsetContains(grammar, CharsetName, source[offset]))
            {
                offset++;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 7
0
        public override bool Contains(GrammarDefinition grammar, char c)
        {
            switch (Operator)
            {
            case CharsetBinaryOperator.Minus:
                return(Left.Contains(grammar, c) && !Right.Contains(grammar, c));

            case CharsetBinaryOperator.Plus:
                return(Left.Contains(grammar, c) || Right.Contains(grammar, c));

            case CharsetBinaryOperator.Div:
                return(Left.Contains(grammar, c) && Right.Contains(grammar, c));

            default:
                throw new InvalidOperationException();
            }
        }
Ejemplo n.º 8
0
        public override bool Contains(GrammarDefinition grammar, char c)
        {
            switch (Name)
            {
            case "Any":
                return(true);

            case "None":
                return(false);

            case "Digit":
                return(char.IsDigit(c));

            case "Letter":
                return(char.IsLetter(c));

            case "LetterOrDigit":
                return(char.IsLetterOrDigit(c));

            case "Number":
                return(char.IsNumber(c));

            case "Punctuation":
                return(char.IsPunctuation(c));

            case "Separator":
                return(char.IsSeparator(c));

            case "Symbol":
                return(char.IsSymbol(c));

            case "Upper":
                return(grammar.IsCaseInsensitive || char.IsUpper(c));

            case "Whitespace":
                return(char.IsWhiteSpace(c));

            case "Lower":
                return(grammar.IsCaseInsensitive || char.IsLower(c));

            default:
                return(grammar.CharsetByName[Name].Expression.Contains(grammar, c));
            }
        }
Ejemplo n.º 9
0
 public abstract bool Lex(GrammarDefinition grammar, string source, ref int offset);
Ejemplo n.º 10
0
 public override bool Lex(GrammarDefinition grammar, string source, ref int offset)
 {
     return(grammar.RegexByName[Reference].Regex.Lex(grammar, source, ref offset));
 }
Ejemplo n.º 11
0
 public override bool Contains(GrammarDefinition grammar, char c)
 {
     return(ClassRegex.Contains(grammar, c));
 }
Ejemplo n.º 12
0
 public abstract bool Contains(GrammarDefinition grammar, char c);