Exemplo n.º 1
0
        public static bool TryParse(TextAndLocation textAndLocation, out TemplateParameter result)
        {
            var text  = textAndLocation.Text;
            var start = text.IndexOf('{');

            if (start < 0 ||
                text.IndexOf('}') < start ||
                text.IndexOf('{', start) > 0)
            {
                result = default(TemplateParameter);
                return(false);
            }

            start++;
            SkipWhiteSpace(text, ref start);

            var end = text.IndexOf('}', start);

            if (end < 0)
            {
                result = default(TemplateParameter);
                return(false);
            }

            BackWhiteSpace(text, ref end);

            for (var i = start; i < end; i++)
            {
                switch (text[i])
                {
                case '?':
                case ':':
                    end = i;
                    break;
                }
            }

            result = new TemplateParameter(textAndLocation.Substring(start, end - start), text.Contains("?"), Type());
            return(true);

            TextAndLocation?Type()
            {
                var typeStart = text.IndexOf(':', start);

                if (typeStart < 0)
                {
                    return(null);
                }

                typeStart++;
                SkipWhiteSpace(text, ref typeStart);
                var typeEnd = text.IndexOf('}', typeStart);

                if (typeEnd < 0)
                {
                    return(null);
                }

                BackWhiteSpace(text, ref typeEnd);
                return(textAndLocation.Substring(typeStart, typeEnd - typeStart));
            }
        }
Exemplo n.º 2
0
 public TemplateParameter(TextAndLocation name, bool isOptional, TextAndLocation?type)
 {
     this.Name       = name;
     this.IsOptional = isOptional;
     this.Type       = type;
 }
 public bool Equals(TextAndLocation other)
 {
     return(this.literal.Equals(other.literal) && this.start == other.start && this.end == other.end);
 }