Ejemplo n.º 1
0
        public static DjangoBlock Parse(BlockParseInfo parseInfo)
        {
            // TODO: Need to handle whitespace better
            // TODO: Need to split identifiers into individual components
            var words         = parseInfo.Args.Split(' ');
            int fromNameStart = -1;
            int fromStart     = -1;
            int nameStart     = parseInfo.Start + 1;

            for (int i = 1; i < words.Length; i++)
            {
                if (String.IsNullOrWhiteSpace(words[i]))
                {
                    nameStart += words[i].Length + 1;
                }
                else
                {
                    break;
                }
            }

            if (words.Length >= 4 && words[words.Length - 2] == "from")
            {
                // load fob from oar
            }

            return(new DjangoLoadBlock(parseInfo, fromStart, nameStart, fromNameStart));
        }
Ejemplo n.º 2
0
 public static DjangoBlock Parse(BlockParseInfo parseInfo)
 {
     return(new DjangoIfOrIfNotEqualBlock(
                parseInfo,
                ParseVariables(parseInfo.Args.Split(' '), parseInfo.Start + parseInfo.Command.Length, 2)
                ));
 }
Ejemplo n.º 3
0
 public DjangoLoadBlock(BlockParseInfo parseInfo, int fromStart, int nameStart, int fromNameStart)
     : base(parseInfo)
 {
     _fromStart     = fromStart;
     _nameStart     = nameStart;
     _fromNameStart = fromNameStart;
 }
Ejemplo n.º 4
0
 public DjangoForBlock(BlockParseInfo parseInfo, int inStart, DjangoVariable variable, int argsEnd, int reversedStart, Tuple<string, int>[] definedVars)
     : base(parseInfo) {
     InStart = inStart;
     Variable = variable;
     ArgsEnd = argsEnd;
     ReversedStart = reversedStart;
     _definedVars = definedVars;
 }
Ejemplo n.º 5
0
        public static DjangoBlock Parse(BlockParseInfo parseInfo) {
            var words = parseInfo.Args.Split(' ');
            List<BlockClassification> argClassifications = new List<BlockClassification>();

            int wordStart = parseInfo.Start + parseInfo.Command.Length;

            return new DjangoMultiVariableArgumentBlock(parseInfo, ParseVariables(words, wordStart));
        }
Ejemplo n.º 6
0
        public static DjangoBlock Parse(BlockParseInfo parseInfo) {
            int start = 0;
            for (int i = 0; i < parseInfo.Args.Length && parseInfo.Args[i] == ' '; i++, start++) {
            }

            var variable = DjangoVariable.Parse(
                "var|" + parseInfo.Args.Substring(start),
                parseInfo.Start + start + parseInfo.Command.Length
            );

            return new DjangoFilterBlock(parseInfo, variable);
        }
Ejemplo n.º 7
0
        public static DjangoBlock Parse(BlockParseInfo parseInfo)
        {
            var words = parseInfo.Args.Split(' ');
            List <BlockClassification> argClassifications = new List <BlockClassification>();

            int wordStart = parseInfo.Start + parseInfo.Command.Length;

            foreach (var word in words)
            {
                bool hasNewline = false;
                if (word.Contains('\r') || word.Contains('\n'))
                {
                    hasNewline = true;
                    if (word.Trim().Length == 0)
                    {
                        break;
                    }
                }
                if (!String.IsNullOrEmpty(word))
                {
                    Classification curKind;
                    switch (word)
                    {
                    case "and":
                    case "or":
                    case "not": curKind = Classification.Keyword; break;

                    default: curKind = Classification.Identifier; break;
                    }

                    argClassifications.Add(
                        new BlockClassification(
                            new Span(wordStart, word.Length),
                            curKind
                            )
                        );
                }

                if (hasNewline)
                {
                    break;
                }

                wordStart += word.Length + 1;
            }

            return(new DjangoIfBlock(parseInfo, argClassifications.ToArray()));
        }
Ejemplo n.º 8
0
        public static DjangoBlock Parse(BlockParseInfo parseInfo) {
            var words = parseInfo.Args.Split(' ');
            int argStart = parseInfo.Command.Length + parseInfo.Start;
            string tagType = null;

            foreach (var word in words) {
                if (!String.IsNullOrEmpty(word)) {
                    tagType = word;
                    break;
                }
                argStart += 1;
            }
            // TODO: It'd be nice to report an error if we have more than one word
            // or if it's an unrecognized tag
            return new DjangoTemplateTagBlock(parseInfo, argStart, tagType);
        }
Ejemplo n.º 9
0
        public static DjangoBlock Parse(BlockParseInfo parseInfo) {
            var args = parseInfo.Args.Split(' ');
            int argStart = -1, argLength = -1;
            for (int i = 0; i < args.Length; i++) {
                var word = args[i];
                if (!String.IsNullOrEmpty(word)) {
                    if (word.StartsWith("\r") || word.StartsWith("\n")) {
                        // unterminated tag
                        break;
                    }
                    argStart = parseInfo.Start + parseInfo.Command.Length + i;
                    argLength = args[i].Length;
                    break;
                }
            }

            return new DjangoAutoEscapeBlock(parseInfo, argStart, argLength);
        }
Ejemplo n.º 10
0
 public DjangoMultiVariableArgumentBlock(BlockParseInfo parseInfo, params DjangoVariable[] variables)
     : base(parseInfo)
 {
     _variables = variables;
 }
Ejemplo n.º 11
0
 public DjangoIfBlock(BlockParseInfo parseInfo, params BlockClassification[] args)
     : base(parseInfo)
 {
     Args = args;
 }
Ejemplo n.º 12
0
 public DjangoIfOrIfNotEqualBlock(BlockParseInfo parseInfo, params DjangoVariable[] args)
     : base(parseInfo)
 {
     _args = args;
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Creates a new DjangoBlock capturing the start index of the block command (for, debug, etc...).
 /// </summary>
 /// <param name="blockStart"></param>
 public DjangoBlock(BlockParseInfo parseInfo)
 {
     ParseInfo = parseInfo;
 }
Ejemplo n.º 14
0
 public static DjangoBlock Parse(BlockParseInfo parseInfo)
 {
     return(new DjangoArgumentlessBlock(parseInfo));
 }
Ejemplo n.º 15
0
 public static DjangoBlock Parse(BlockParseInfo parseInfo)
 {
     return(new DjangoUnknownBlock(parseInfo));
 }
Ejemplo n.º 16
0
 public DjangoAutoEscapeBlock(BlockParseInfo parseInfo, int argStart, int argLength)
     : base(parseInfo)
 {
     _argStart  = argStart;
     _argLength = argLength;
 }
Ejemplo n.º 17
0
 public DjangoMultiVariableArgumentBlock(BlockParseInfo parseInfo, params DjangoVariable[] variables)
     : base(parseInfo) {
     _variables = variables;
 }
Ejemplo n.º 18
0
        public static DjangoBlock Parse(BlockParseInfo parseInfo) {
            var words = parseInfo.Args.Split(' ');
            List<BlockClassification> argClassifications = new List<BlockClassification>();

            int wordStart = parseInfo.Start + parseInfo.Command.Length;
            foreach (var word in words) {
                bool hasNewline = false;
                if (word.Contains('\r') || word.Contains('\n')) {
                    hasNewline = true;
                    if (word.Trim().Length == 0) {
                        break;
                    }
                }
                if (!String.IsNullOrEmpty(word)) {
                    Classification curKind;
                    switch (word) {
                        case "and":
                        case "or":
                        case "not": curKind = Classification.Keyword; break;
                        default: curKind = Classification.Identifier; break;
                    }

                    argClassifications.Add(
                        new BlockClassification(
                            new Span(wordStart, word.Length),
                            curKind
                        )
                    );
                }

                if (hasNewline) {
                    break;
                }

                wordStart += word.Length + 1;
            }

            return new DjangoIfBlock(parseInfo, argClassifications.ToArray());
        }
Ejemplo n.º 19
0
 public DjangoIfBlock(BlockParseInfo parseInfo, params BlockClassification[] args)
     : base(parseInfo) {
     Args = args;
 }
Ejemplo n.º 20
0
 public static DjangoBlock Parse(BlockParseInfo parseInfo) {
     return new DjangoIfOrIfNotEqualBlock(
         parseInfo,
         ParseVariables(parseInfo.Args.Split(' '), parseInfo.Start + parseInfo.Command.Length, 2)
     );
 }
Ejemplo n.º 21
0
 public DjangoIfOrIfNotEqualBlock(BlockParseInfo parseInfo, params DjangoVariable[] args)
     : base(parseInfo) {
     _args = args;
 }
Ejemplo n.º 22
0
        public static DjangoForBlock Parse(BlockParseInfo parseInfo) {
            var words = parseInfo.Args.Split(' ');
            int inStart = -1;

            int inOffset = 0, inIndex = -1;
            var definitions = new List<Tuple<string, int>>();
            for (int i = 0; i < words.Length; i++) {
                var word = words[i];
                if (word == "in") {
                    inStart = inOffset + parseInfo.Start + parseInfo.Command.Length;
                    inIndex = i;
                    break;
                } else if (words[i].IndexOfAny(NewLines) != -1) {
                    // unterminated tag
                    break;
                }

                if (!String.IsNullOrEmpty(word)) {
                    definitions.Add(new Tuple<string, int>(word, inOffset + parseInfo.Start + parseInfo.Command.Length));
                }
                inOffset += words[i].Length + 1;
            }

            // parse the arguments...
            int reversedStart = -1;
            DjangoVariable variable = null;
            int argsEnd = -1;
            if (inIndex != -1) {
                string filterText = "";
                argsEnd = inStart + "in".Length + 1;
                for (int i = inIndex + 1; i < words.Length; i++) {
                    int nlStart = words[i].IndexOfAny(NewLines);
                    string trimmed = words[i];
                    if (nlStart != -1) {
                        trimmed = words[i].Substring(0, nlStart);
                    }

                    if (i != inIndex + 1 && trimmed == words[i]) { // if we trimmed we don't have an extra space
                        filterText += " ";
                        argsEnd += 1;
                    }

                    if (trimmed == "reversed") {
                        reversedStart = argsEnd;
                        break;
                    }

                    filterText += trimmed;
                    argsEnd += trimmed.Length;
                    if (trimmed != words[i]) {
                        // unterminated tag
                        break;
                    }
                }

                var trimmedFilter = filterText.TrimStart(' ');

                variable = DjangoVariable.Parse(trimmedFilter,
                    inStart + "in".Length + 1 + filterText.Length - trimmedFilter.Length);
            }

            return new DjangoForBlock(parseInfo, inStart, variable, argsEnd, reversedStart, definitions.ToArray());
        }
Ejemplo n.º 23
0
 public DjangoFilterBlock(BlockParseInfo parseInfo, DjangoVariable variable)
     : base(parseInfo) {
     _variable = variable;
 }
Ejemplo n.º 24
0
 public static DjangoBlock Parse(BlockParseInfo parseInfo) {
     return new DjangoWidthRatioBlock(parseInfo,
         ParseVariables(parseInfo.Args.Split(' '), parseInfo.Command.Length + parseInfo.Start, 3));
 }
Ejemplo n.º 25
0
 public static DjangoBlock Parse(BlockParseInfo parseInfo) {
     return new DjangoArgumentlessBlock(parseInfo);
 }
Ejemplo n.º 26
0
 public DjangoUnknownBlock(BlockParseInfo parseInfo)
     : base(parseInfo)
 {
 }
Ejemplo n.º 27
0
 public DjangoLoadBlock(BlockParseInfo parseInfo, int fromStart, int nameStart, int fromNameStart)
     : base(parseInfo) {
     _fromStart = fromStart;
     _nameStart = nameStart;
     _fromNameStart = fromNameStart;
 }
Ejemplo n.º 28
0
 public DjangoArgumentlessBlock(BlockParseInfo parseInfo)
     : base(parseInfo)
 {
 }
Ejemplo n.º 29
0
        public static DjangoBlock Parse(BlockParseInfo parseInfo) {
            // TODO: Need to handle whitespace better
            // TODO: Need to split identifiers into individual components
            var words = parseInfo.Args.Split(' ');
            int fromNameStart = -1;
            int fromStart = -1;
            int nameStart = parseInfo.Start + 1;
            for (int i = 1; i < words.Length; i++) {
                if (String.IsNullOrWhiteSpace(words[i])) {
                    nameStart += words[i].Length + 1;
                } else {
                    break;
                }
            }

            if (words.Length >= 4 && words[words.Length - 2] == "from") {
                // load fob from oar

            }

            return new DjangoLoadBlock(parseInfo, fromStart, nameStart, fromNameStart);
        }
Ejemplo n.º 30
0
 public DjangoFilterBlock(BlockParseInfo parseInfo, DjangoVariable variable)
     : base(parseInfo)
 {
     _variable = variable;
 }
Ejemplo n.º 31
0
 public DjangoArgumentlessBlock(BlockParseInfo parseInfo)
     : base(parseInfo) {
 }
Ejemplo n.º 32
0
        public static DjangoForBlock Parse(BlockParseInfo parseInfo)
        {
            var words   = parseInfo.Args.Split(' ');
            int inStart = -1;

            int inOffset = 0, inIndex = -1;
            var definitions = new List <Tuple <string, int> >();

            for (int i = 0; i < words.Length; i++)
            {
                var word = words[i];
                if (word == "in")
                {
                    inStart = inOffset + parseInfo.Start + parseInfo.Command.Length;
                    inIndex = i;
                    break;
                }
                else if (words[i].IndexOfAny(NewLines) != -1)
                {
                    // unterminated tag
                    break;
                }

                if (!String.IsNullOrEmpty(word))
                {
                    definitions.Add(new Tuple <string, int>(word, inOffset + parseInfo.Start + parseInfo.Command.Length));
                }
                inOffset += words[i].Length + 1;
            }

            // parse the arguments...
            int            reversedStart = -1;
            DjangoVariable variable      = null;
            int            argsEnd       = -1;

            if (inIndex != -1)
            {
                string filterText = "";
                argsEnd = inStart + "in".Length + 1;
                for (int i = inIndex + 1; i < words.Length; i++)
                {
                    int    nlStart = words[i].IndexOfAny(NewLines);
                    string trimmed = words[i];
                    if (nlStart != -1)
                    {
                        trimmed = words[i].Substring(0, nlStart);
                    }

                    if (i != inIndex + 1 && trimmed == words[i])   // if we trimmed we don't have an extra space
                    {
                        filterText += " ";
                        argsEnd    += 1;
                    }

                    if (trimmed == "reversed")
                    {
                        reversedStart = argsEnd;
                        break;
                    }

                    filterText += trimmed;
                    argsEnd    += trimmed.Length;
                    if (trimmed != words[i])
                    {
                        // unterminated tag
                        break;
                    }
                }

                var trimmedFilter = filterText.TrimStart(' ');

                variable = DjangoVariable.Parse(trimmedFilter,
                                                inStart + "in".Length + 1 + filterText.Length - trimmedFilter.Length);
            }

            return(new DjangoForBlock(parseInfo, inStart, variable, argsEnd, reversedStart, definitions.ToArray()));
        }
Ejemplo n.º 33
0
 public static DjangoBlock Parse(BlockParseInfo parseInfo)
 {
     return(new DjangoSpacelessBlock(parseInfo));
 }
Ejemplo n.º 34
0
 public static DjangoBlock Parse(BlockParseInfo parseInfo) {
     return new DjangoUnknownBlock(parseInfo);
 }
Ejemplo n.º 35
0
 public DjangoWidthRatioBlock(BlockParseInfo parseInfo, params DjangoVariable[] variables)
     : base(parseInfo)
 {
     _variables = variables;
 }
Ejemplo n.º 36
0
 public DjangoUnknownBlock(BlockParseInfo parseInfo)
     : base(parseInfo) {
 }
Ejemplo n.º 37
0
 public DjangoWidthRatioBlock(BlockParseInfo parseInfo, params DjangoVariable[] variables)
     : base(parseInfo) {
     _variables = variables;
 }
Ejemplo n.º 38
0
 public DjangoSpacelessBlock(BlockParseInfo parseInfo)
     : base(parseInfo) {
 }
Ejemplo n.º 39
0
 /// <summary>
 /// Creates a new DjangoBlock capturing the start index of the block command (for, debug, etc...).
 /// </summary>
 /// <param name="blockStart"></param>
 public DjangoBlock(BlockParseInfo parseInfo) {
     ParseInfo = parseInfo;
 }
Ejemplo n.º 40
0
 public DjangoSpacelessBlock(BlockParseInfo parseInfo)
     : base(parseInfo)
 {
 }
Ejemplo n.º 41
0
 public static DjangoBlock Parse(BlockParseInfo parseInfo) {
     return new DjangoSpacelessBlock(parseInfo);
 }
Ejemplo n.º 42
0
 public DjangoTemplateTagBlock(BlockParseInfo parseInfo, int argStart, string tagType)
     : base(parseInfo)
 {
     _argStart = argStart;
     _tagType  = tagType;
 }
Ejemplo n.º 43
0
 public DjangoTemplateTagBlock(BlockParseInfo parseInfo, int argStart, string tagType)
     : base(parseInfo) {
     _argStart = argStart;
     _tagType = tagType;
 }
Ejemplo n.º 44
0
 public static DjangoBlock Parse(BlockParseInfo parseInfo)
 {
     return(new DjangoWidthRatioBlock(parseInfo,
                                      ParseVariables(parseInfo.Args.Split(' '), parseInfo.Command.Length + parseInfo.Start, 3)));
 }
Ejemplo n.º 45
0
 public DjangoAutoEscapeBlock(BlockParseInfo parseInfo, int argStart, int argLength)
     : base(parseInfo) {
     _argStart = argStart;
     _argLength = argLength;
 }