Exemple #1
0
        public static DjangoBlock Parse(BlockParseInfo parseInfo) {
            string[] words = parseInfo.Args.Split(' ');
            IList<BlockClassification> argClassifications = new List<BlockClassification>();
            IList<string> usedNamedParameters = new List<string>();

            int wordStart = parseInfo.Start + parseInfo.Command.Length;
            string urlName = null;
            foreach (string word in words) {
                if (!string.IsNullOrEmpty(word)) {
                    Classification currentArgKind = word.Equals("as") ? Classification.Keyword : Classification.Identifier;
                    argClassifications.Add(new BlockClassification(new Span(wordStart, word.Length), currentArgKind));

                    // Get url name
                    if (urlName == null) {
                        if (word.StartsWith("'")) {
                            urlName = word.TrimStart('\'').TrimEnd('\'');
                        } else if (word.StartsWith("\"")) {
                            urlName = word.TrimStart('"').TrimEnd('"');
                        }
                    }

                    // Test if word is a named parameter (but not in a string)
                    if (word.Contains('=') && !word.StartsWith("'") && !word.StartsWith("\"")) {
                        usedNamedParameters.Add(word.Split('=').First());
                    }
                }
                wordStart += word.Length + 1;
            }

            return new DjangoUrlBlock(parseInfo, argClassifications.ToArray(), urlName, usedNamedParameters.ToArray());
        }
Exemple #2
0
 public DjangoLoadBlock(BlockParseInfo parseInfo, int fromStart, int nameStart, int fromNameStart)
     : base(parseInfo)
 {
     _fromStart     = fromStart;
     _nameStart     = nameStart;
     _fromNameStart = fromNameStart;
 }
 public static DjangoBlock Parse(BlockParseInfo parseInfo)
 {
     return(new DjangoIfOrIfNotEqualBlock(
                parseInfo,
                ParseVariables(parseInfo.Args.Split(' '), parseInfo.Start + parseInfo.Command.Length, 2)
                ));
 }
Exemple #4
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));
        }
Exemple #5
0
 public DjangoUrlBlock(BlockParseInfo parseInfo, BlockClassification[] args, string urlName = null, string[] definedNamedParameters = null)
     : base(parseInfo)
 {
     Args     = args;
     _urlName = urlName;
     _definedNamedParameters = definedNamedParameters != null ? definedNamedParameters : Array.Empty <string>();
 }
        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));
        }
Exemple #7
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;
 }
Exemple #8
0
        public static DjangoBlock Parse(BlockParseInfo parseInfo)
        {
            string[] words = parseInfo.Args.Split(' ');
            IList <BlockClassification> argClassifications = new List <BlockClassification>();
            IList <string> usedNamedParameters             = new List <string>();
            uint           nbParameters = 0;
            bool           afterUrl = false, beforeAsKeyword = true;

            int    wordStart = parseInfo.Start + parseInfo.Command.Length;
            string urlName = null;

            foreach (string word in words)
            {
                if (!string.IsNullOrEmpty(word))
                {
                    Classification currentArgKind;
                    if (word.Equals("as"))
                    {
                        currentArgKind  = Classification.Keyword;
                        beforeAsKeyword = false;
                    }
                    else
                    {
                        currentArgKind = Classification.Identifier;
                    }
                    argClassifications.Add(new BlockClassification(new Span(wordStart, word.Length), currentArgKind));

                    if (afterUrl && beforeAsKeyword)
                    {
                        ++nbParameters;
                    }

                    // Get url name
                    if (urlName == null)
                    {
                        if (word.StartsWith("'"))
                        {
                            urlName  = word.TrimStart('\'').TrimEnd('\'');
                            afterUrl = true;
                        }
                        else if (word.StartsWith("\""))
                        {
                            urlName  = word.TrimStart('"').TrimEnd('"');
                            afterUrl = true;
                        }
                    }

                    // Test if word is a named parameter (but not in a string)
                    if (word.Contains('=') && !word.StartsWith("'") && !word.StartsWith("\""))
                    {
                        usedNamedParameters.Add(word.Split('=').First());
                    }
                }
                wordStart += word.Length + 1;
            }

            return(new DjangoUrlBlock(parseInfo, argClassifications.ToArray(), urlName, usedNamedParameters.ToArray(), nbParameters));
        }
Exemple #9
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;
 }
        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)));
        }
Exemple #11
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);
        }
Exemple #12
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()));
        }
Exemple #13
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));
        }
        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);
        }
        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);
        }
        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));
        }
Exemple #17
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());
        }
Exemple #18
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);
        }
Exemple #19
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.StartsWithOrdinal("\r") || word.StartsWithOrdinal("\n"))
                    {
                        // unterminated tag
                        break;
                    }
                    argStart  = parseInfo.Start + parseInfo.Command.Length + i;
                    argLength = args[i].Length;
                    break;
                }
            }

            return(new DjangoAutoEscapeBlock(parseInfo, argStart, argLength));
        }
Exemple #20
0
 public DjangoFilterBlock(BlockParseInfo parseInfo, DjangoVariable variable)
     : base(parseInfo)
 {
     _variable = variable;
 }
Exemple #21
0
 public DjangoUnknownBlock(BlockParseInfo parseInfo)
     : base(parseInfo) {
 }
Exemple #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());
        }
 public DjangoArgumentlessBlock(BlockParseInfo parseInfo)
     : base(parseInfo) {
 }
Exemple #24
0
 public DjangoUrlBlock(BlockParseInfo parseInfo, BlockClassification[] args, string urlName = null, string[] definedNamedParameters = null)
     : base(parseInfo) {
     Args = args;
     _urlName = urlName;
     _definedNamedParameters = definedNamedParameters != null ? definedNamedParameters : Array.Empty<string>();
 }
 public static DjangoBlock Parse(BlockParseInfo parseInfo) {
     return new DjangoArgumentlessBlock(parseInfo);
 }
 public static DjangoBlock Parse(BlockParseInfo parseInfo)
 {
     return(new DjangoWidthRatioBlock(parseInfo,
                                      ParseVariables(parseInfo.Args.Split(' '), parseInfo.Command.Length + parseInfo.Start, 3)));
 }
 public DjangoWidthRatioBlock(BlockParseInfo parseInfo, params DjangoVariable[] variables)
     : base(parseInfo)
 {
     _variables = variables;
 }
Exemple #28
0
 public DjangoSpacelessBlock(BlockParseInfo parseInfo)
     : base(parseInfo)
 {
 }
Exemple #29
0
 public static DjangoBlock Parse(BlockParseInfo parseInfo)
 {
     return(new DjangoUnknownBlock(parseInfo));
 }
 public DjangoAutoEscapeBlock(BlockParseInfo parseInfo, int argStart, int argLength)
     : base(parseInfo) {
     _argStart = argStart;
     _argLength = argLength;
 }
 public DjangoArgumentlessBlock(BlockParseInfo parseInfo)
     : base(parseInfo)
 {
 }
 public static DjangoBlock Parse(BlockParseInfo parseInfo)
 {
     return(new DjangoArgumentlessBlock(parseInfo));
 }
 public DjangoWidthRatioBlock(BlockParseInfo parseInfo, params DjangoVariable[] variables)
     : base(parseInfo) {
     _variables = variables;
 }
Exemple #34
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()));
        }
Exemple #35
0
 public DjangoFilterBlock(BlockParseInfo parseInfo, DjangoVariable variable)
     : base(parseInfo) {
     _variable = variable;
 }
 public DjangoTemplateTagBlock(BlockParseInfo parseInfo, int argStart, string tagType)
     : base(parseInfo)
 {
     _argStart = argStart;
     _tagType  = tagType;
 }
Exemple #37
0
 public DjangoIfBlock(BlockParseInfo parseInfo, params BlockClassification[] args)
     : base(parseInfo)
 {
     Args = args;
 }
 public static DjangoBlock Parse(BlockParseInfo parseInfo) {
     return new DjangoSpacelessBlock(parseInfo);
 }
Exemple #39
0
 public DjangoAutoEscapeBlock(BlockParseInfo parseInfo, int argStart, int argLength)
     : base(parseInfo)
 {
     _argStart  = argStart;
     _argLength = argLength;
 }
 public DjangoIfOrIfNotEqualBlock(BlockParseInfo parseInfo, params DjangoVariable[] args)
     : base(parseInfo)
 {
     _args = args;
 }
 public DjangoMultiVariableArgumentBlock(BlockParseInfo parseInfo, params DjangoVariable[] variables)
     : base(parseInfo)
 {
     _variables = variables;
 }
 public DjangoSpacelessBlock(BlockParseInfo parseInfo)
     : base(parseInfo) {
 }
 public DjangoTemplateTagBlock(BlockParseInfo parseInfo, int argStart, string tagType)
     : base(parseInfo) {
     _argStart = argStart;
     _tagType = tagType;
 }
 public static DjangoBlock Parse(BlockParseInfo parseInfo) {
     return new DjangoWidthRatioBlock(parseInfo,
         ParseVariables(parseInfo.Args.Split(' '), parseInfo.Command.Length + parseInfo.Start, 3));
 }
Exemple #45
0
 public static DjangoBlock Parse(BlockParseInfo parseInfo) {
     return new DjangoUnknownBlock(parseInfo);
 }
Exemple #46
0
 public DjangoIfBlock(BlockParseInfo parseInfo, params BlockClassification[] args)
     : base(parseInfo) {
     Args = args;
 }
Exemple #47
0
 public DjangoLoadBlock(BlockParseInfo parseInfo, int fromStart, int nameStart, int fromNameStart)
     : base(parseInfo) {
     _fromStart = fromStart;
     _nameStart = nameStart;
     _fromNameStart = fromNameStart;
 }
Exemple #48
0
 public static DjangoBlock Parse(BlockParseInfo parseInfo)
 {
     return(new DjangoSpacelessBlock(parseInfo));
 }
Exemple #49
0
 public DjangoUnknownBlock(BlockParseInfo parseInfo)
     : base(parseInfo)
 {
 }
 public DjangoMultiVariableArgumentBlock(BlockParseInfo parseInfo, params DjangoVariable[] variables)
     : base(parseInfo) {
     _variables = variables;
 }