Esempio n. 1
0
        static ExpressionNode ParseProperty(string buffer, ref int offset, int endOffset, int baseOffset)
        {
            int start = offset - 2;

            ConsumeSpace(buffer, ref offset, endOffset);

            if (offset <= endOffset && buffer [offset] == '[')
            {
                return(ParsePropertyStaticFunction(start, buffer, ref offset, endOffset, baseOffset));
            }

            string name = ReadName(buffer, ref offset, endOffset);

            if (name == null)
            {
                return(new ExpressionError(baseOffset + offset, ExpressionErrorKind.ExpectingPropertyName));
            }

            ExpressionPropertyNode propRef = new ExpressionPropertyName(baseOffset + offset - name.Length, name.Length, name);

            ConsumeSpace(buffer, ref offset, endOffset);

            bool foundFunction = false;

            if (offset <= endOffset && buffer [offset] == '.')
            {
                if (WrapError(
                        ParsePropertyStringFunction(buffer, ref offset, endOffset, baseOffset, propRef),
                        out propRef,
                        out IncompleteExpressionError error,
                        (n, o) => new ExpressionProperty(baseOffset + start, o - baseOffset - start, n)
                        ))
                {
                    return(error);
                }
                foundFunction = true;
            }

            ConsumeSpace(buffer, ref offset, endOffset);

            if (offset > endOffset || buffer [offset] != ')')
            {
                return(new IncompleteExpressionError(
                           baseOffset + offset, offset > endOffset,
                           foundFunction? ExpressionErrorKind.ExpectingRightParen : ExpressionErrorKind.ExpectingRightParenOrPeriod,
                           new ExpressionProperty(baseOffset + start, offset - start, propRef)
                           ));
            }

            return(new ExpressionProperty(baseOffset + start, offset - start + 1, propRef));
        }
Esempio n. 2
0
        static ExpressionNode ParseProperty(string buffer, ref int offset, int endOffset, int baseOffset)
        {
            int start = offset - 2;

            ConsumeSpace(buffer, ref offset, endOffset);

            ExpressionPropertyNode propRef;

            if (offset <= endOffset && buffer [offset] == '[')
            {
                if (WrapError(
                        ParsePropertyStaticFunction(offset, buffer, ref offset, endOffset, baseOffset),
                        out propRef,
                        out IncompleteExpressionError error,
                        (n, o) => new ExpressionProperty(baseOffset + start, o - baseOffset - start, n)
                        ))
                {
                    return(error);
                }
            }
            else
            {
                string name = ReadName(buffer, ref offset, endOffset);
                if (name == null)
                {
                    return(new ExpressionError(baseOffset + offset, ExpressionErrorKind.ExpectingPropertyName));
                }

                propRef = new ExpressionPropertyName(baseOffset + offset - name.Length, name.Length, name);
            }

            ConsumeSpace(buffer, ref offset, endOffset);

            if (offset <= endOffset &&
                buffer [offset] == ':' &&
                propRef is ExpressionPropertyName regStr &&
                string.Equals("registry", regStr.Name, StringComparison.OrdinalIgnoreCase)
                )
            {
                offset++;
                ConsumeSpace(buffer, ref offset, endOffset);
                int regStart = offset;
                while (offset <= endOffset)
                {
                    char ch = buffer [offset];

                    switch (ch)
                    {
                    case '\\':
                    case '@':
                    case '_':
                    case '.':
                        offset++;
                        continue;

                    case ' ':
                        ConsumeSpace(buffer, ref offset, endOffset);
                        goto case ')';

                    case ')':
                        string value = buffer.Substring(regStart, offset - regStart);
                        propRef = new ExpressionPropertyRegistryValue(propRef.Offset, offset - propRef.Offset + baseOffset, value);
                        break;

                    default:
                        if (char.IsLetterOrDigit(ch))
                        {
                            goto case '.';
                        }
                        string v = buffer.Substring(regStart, offset - regStart);
                        propRef = new ExpressionPropertyRegistryValue(propRef.Offset, offset - propRef.Offset + baseOffset, v);
                        // as the current char is not ')', this will turn into an error
                        break;
                    }
                    break;
                }
            }