예제 #1
0
        private void ParseFilter(Stream stream, ISemanticModel semanticModel, Stack <Context> context, int depth)
        {
            if (stream.Peek() == '(')
            {
                stream.Advance();
                var classification = GetPropertyClassification(depth);

                semanticModel.Tokens.AddBrace(stream, classification);

                var block = stream.PeekBlock(1, '(', ')');

                if (block.Contains("=>") == false)
                {
                    semanticModel.Tokens.Add(Classifications.String, stream.Position + 1, block.Length);
                }

                stream.Advance(block.Length);

                if (stream.Peek() == ')')
                {
                    stream.Advance();
                    semanticModel.Tokens.AddBrace(stream, classification);
                }
            }
        }
예제 #2
0
        private void ParseCodeBlock(Stream stream)
        {
            if (stream.Current == '$' && stream.Peek() == '{' && context.Peek() == fileContext)
            {
                for (var i = 0; ; i--)
                {
                    var current = stream.Peek(i);
                    if (current == '`' || (current == '/' && stream.Peek(i - 1) == '/'))
                    {
                        return;
                    }
                    if (current == '\n' || current == char.MinValue)
                    {
                        break;
                    }
                }

                stream.Advance();

                var block = stream.PeekBlock(1, '{', '}');

                semanticModel.ContextSpans.Add(null, null, ContextType.CodeBlock, stream.Position + 1, stream.Position + block.Length + 1);

                var codeStream = new Stream(block, stream.Position + 1);

                ParseUsings(codeStream);
                ParseCode(codeStream);

                stream.Advance(block.Length);
            }
        }
예제 #3
0
        private static bool ParseCodeBlock(Stream stream, ShadowClass shadowClass)
        {
            if (stream.Current == '$' && stream.Peek() == '{')
            {
                for (var i = 0; ; i--)
                {
                    var current = stream.Peek(i);
                    if (current == '`' || (current == '/' && stream.Peek(i - 1) == '/'))
                    {
                        return(false);
                    }
                    if (current == '\n' || current == char.MinValue)
                    {
                        break;
                    }
                }

                stream.Advance();

                var block      = stream.PeekBlock(1, '{', '}');
                var codeStream = new Stream(block, stream.Position + 1);

                ParseUsings(codeStream, shadowClass);
                ParseCode(codeStream, shadowClass);

                stream.Advance(block.Length + 1);

                return(true);
            }

            return(false);
        }
예제 #4
0
        private void ParseFileOutput(Stream stream, ISemanticModel semanticModel, Stack <Context> context, int depth)
        {
            if (stream.Peek() == '<')
            {
                stream.Advance();
                var classification = GetPropertyClassification(depth);

                semanticModel.Tokens.AddBrace(stream, classification);

                var block = stream.PeekBlock(1, '<', '>');

                if (block.StartsWith("$") == false)
                {
                    semanticModel.Tokens.Add(Classifications.String, stream.Position + 1, block.Length);
                }

                stream.Advance(block.Length);

                if (stream.Peek() == '>')
                {
                    stream.Advance();
                    semanticModel.Tokens.AddBrace(stream, classification);
                }
            }
        }
예제 #5
0
        private void TerminateSymbol(Stream stream)
        {
            if (stream.Current == ' ' || stream.Current == '{' || stream.Current == ';' || stream.Current == '(' || stream.Current == ')' || stream.Current == ',')
            {
                _isSymbol = false;
            }

            // Find object literals
            if (stream.Current == '{')
            {
                var i = 0;
                while (true)
                {
                    if (stream.Peek(--i) != ' ')
                    {
                        break;
                    }
                }

                var peek = stream.Peek(i);

                if (peek == '=' || peek == '(' || peek == ',')
                {
                    var block = stream.PeekBlock(1, '{', '}');
                    _objectLiteralEnds = Math.Max(_objectLiteralEnds, stream.Position + block.Length);
                }
            }
        }
예제 #6
0
        private static bool ParseLambda(Stream stream, ShadowClass shadowClass, Contexts contexts, ref string template)
        {
            if (stream.Current == '$')
            {
                var identifier = stream.PeekWord(1);
                if (identifier != null)
                {
                    var filter = stream.PeekBlock(identifier.Length + 2, '(', ')');
                    if (filter != null && stream.Peek(filter.Length + 2 + identifier.Length + 1) == '[')
                    {
                        try
                        {
                            var index = filter.IndexOf("=>", StringComparison.Ordinal);

                            if (index > 0)
                            {
                                var name = filter.Substring(0, index);

                                var contextName = identifier;
                                // Todo: Make the TemplateCodeParser context aware
                                if (contextName == "TypeArguments")
                                {
                                    contextName = "Types";
                                }
                                else if (contextName.StartsWith("Nested", StringComparison.OrdinalIgnoreCase))
                                {
                                    contextName = contextName.Remove(0, 6);
                                }

                                var type = contexts.Find(contextName)?.Type.FullName;

                                if (type == null)
                                {
                                    return(false);
                                }

                                var methodIndex = counter++;

                                shadowClass.AddLambda(filter, type, name, methodIndex);

                                stream.Advance(filter.Length + 2 + identifier.Length);
                                template += $"${identifier}($__{methodIndex})";

                                return(true);
                            }
                        }
                        catch
                        {
                        }
                    }
                }
            }

            return(false);
        }
예제 #7
0
        private void ParseBlock(Stream stream)
        {
            if (stream.Peek() == '[')
            {
                stream.Advance();

                var block = stream.PeekBlock(1, '[', ']');
                Parse(block, stream.Position + 1);
                stream.Advance(block.Length);
            }
        }
예제 #8
0
        private void ParseBlock(Stream stream)
        {
            if (stream.Peek() == '[')
            {
                stream.Advance();

                var block = stream.PeekBlock(1, '[', ']');
                Parse(block, stream.Position + 1);
                stream.Advance(block.Length);
            }
        }
예제 #9
0
        private static string ParseBlock(Stream stream, char open, char close)
        {
            if (stream.Peek() == open)
            {
                var block = stream.PeekBlock(2, open, close);

                stream.Advance(block.Length);
                stream.Advance(stream.Peek(2) == close ? 2 : 1);

                return block;
            }

            return null;
        }
예제 #10
0
        private void ParseFileOutput(Stream stream)
        {
            if (stream.Peek() == '<')
            {
                stream.Advance();

                var block = stream.PeekBlock(1, '<', '>');
                stream.Advance(block.Length);

                if (stream.Peek() == '>')
                {
                    stream.Advance();
                }
            }
        }
예제 #11
0
        private static bool ParseLambda(Stream stream, ShadowClass shadowClass, ref string template)
        {
            if (stream.Current == '$')
            {
                var identifier = stream.PeekWord(1);
                if (identifier != null)
                {
                    var filter = stream.PeekBlock(identifier.Length + 2, '(', ')');
                    if (filter != null && stream.Peek(filter.Length + 2 + identifier.Length + 1) == '[')
                    {
                        try
                        {
                            var index = filter.IndexOf("=>", StringComparison.Ordinal);

                            if (index > 0)
                            {
                                var name = filter.Substring(0, index);

                                var contextName = identifier;
                                // Todo: Make the TemplateCodeParser context aware
                                if (contextName == "GenericTypeArguments") contextName = "Types";
                                else if (contextName.StartsWith("Nested")) contextName = contextName.Remove(0, 6);

                                var type = Contexts.Find(contextName)?.Type.FullName;

                                if (type == null) return false;

                                var methodIndex = counter++;

                                shadowClass.AddLambda(filter, type, name, methodIndex);

                                stream.Advance(filter.Length + 2 + identifier.Length);
                                template += $"${identifier}($__{methodIndex})";

                                return true;
                            }
                        }
                        catch
                        {
                        }
                    }
                }
            }

            return false;
        }
예제 #12
0
        //private void ParseDot(Stream stream, SemanticModel SemanticModel, Context context, Context parentContext)
        //{
        //    if (stream.Peek() == '.')
        //    {
        //        stream.Advance();

        //        var word = stream.PeekWord(1);
        //        var identifier = context.GetIdentifier(word);

        //        SemanticModel.AddContext(context, stream.Position+1, stream.Position + 2);

        //        if (identifier != null)
        //        {
        //            if (IsValidIdentifier(stream, identifier))
        //            {
        //                SemanticModel.AddToken(Classifications.Property, stream.Line, stream.Position);
        //                SemanticModel.AddToken(Classifications.Property, stream.Line, stream.Position + 1, word.Length, identifier.QuickInfo);
        //                stream.Advance(word.Length);

        //                if (identifier.IsCollection)
        //                {
        //                    var subContext = Contexts.Find(identifier.Context);
        //                    ParseFilter(stream, SemanticModel, subContext, braces);
        //                    ParseBlock(stream, SemanticModel, subContext, braces); // template
        //                    ParseBlock(stream, SemanticModel, context, braces); // separator
        //                }
        //                else if (identifier.IsBoolean)
        //                {
        //                    ParseBlock(stream, SemanticModel, parentContext, braces); // true
        //                    ParseBlock(stream, SemanticModel, parentContext, braces); // false
        //                }
        //                else if (identifier.HasContext)
        //                {
        //                    ParseDot(stream, SemanticModel, Contexts.Find(identifier.Context), parentContext, braces); // Identifier
        //                    ParseBlock(stream, SemanticModel, Contexts.Find(identifier.Context), braces); // template
        //                }
        //            }
        //        }
        //    }
        //}

        private void ParseBlock(Stream stream, SemanticModel semanticModel, Stack <Context> context)
        {
            if (stream.Peek() == '[')
            {
                stream.Advance();
                semanticModel.Tokens.AddBrace(stream, Classifications.Property);

                var block = stream.PeekBlock(1, '[', ']');
                Parse(block, semanticModel, context, stream.Position + 1);
                stream.Advance(block.Length);

                if (stream.Peek() == ']')
                {
                    stream.Advance();
                    semanticModel.Tokens.AddBrace(stream, Classifications.Property);
                }
            }
        }
예제 #13
0
        private void ParseCodeBlock(Stream stream)
        {
            if (stream.Current == '$' && stream.Peek() == '{' && context.Peek() == fileContext)
            {
                stream.Advance();

                var block = stream.PeekBlock(1, '{', '}');

                semanticModel.ContextSpans.Add(null, null, ContextType.CodeBlock, stream.Position + 1, stream.Position + block.Length + 1);

                var codeStream = new Stream(block, stream.Position + 1);

                ParseUsings(codeStream);
                ParseCode(codeStream);

                stream.Advance(block.Length);
            }
        }
예제 #14
0
        private void ParseCodeBlock(Stream stream)
        {
            if (stream.Current == '$' && stream.Peek() == '{' && context.Peek() == fileContext)
            {
                stream.Advance();

                var block = stream.PeekBlock(1, '{', '}');

                semanticModel.ContextSpans.Add(null, null, ContextType.CodeBlock, stream.Position + 1, stream.Position + block.Length + 1);
                
                var codeStream = new Stream(block, stream.Position + 1);

                ParseUsings(codeStream);
                ParseCode(codeStream);

                stream.Advance(block.Length);
            }
        }
예제 #15
0
        private static bool ParseCodeBlock(Stream stream, ShadowClass shadowClass)
        {
            if (stream.Current == '$' && stream.Peek() == '{')
            {
                stream.Advance();

                var block = stream.PeekBlock(1, '{', '}');
                var codeStream = new Stream(block, stream.Position + 1);

                ParseUsings(codeStream, shadowClass);
                ParseCode(codeStream, shadowClass);

                stream.Advance(block.Length + 1);

                return true;
            }

            return false;
        }
예제 #16
0
        private bool ParseCodeBlock(Stream stream, SemanticModel semanticModel, Stack<Context> context)
        {
            if (stream.Current == '$' && stream.Peek() == '{' && context.Peek() == fileContext)
            {
                semanticModel.Tokens.Add(Classifications.Property, stream.Position);

                stream.Advance();
                semanticModel.Tokens.AddBrace(stream, Classifications.Property);

                var block = stream.PeekBlock(1, '{', '}');
                stream.Advance(block.Length);

                if (stream.Peek() == '}')
                {
                    stream.Advance();
                    semanticModel.Tokens.AddBrace(stream, Classifications.Property);
                }

                return true;
            }

            return false;
        }
예제 #17
0
        private bool ParseCodeBlock(Stream stream, SemanticModel semanticModel, Stack <Context> context)
        {
            if (stream.Current == '$' && stream.Peek() == '{' && context.Peek() == _fileContext)
            {
                semanticModel.Tokens.Add(Classifications.Property, stream.Position);

                stream.Advance();
                semanticModel.Tokens.AddBrace(stream, Classifications.Property);

                var block = stream.PeekBlock(1, '{', '}');
                stream.Advance(block.Length);

                if (stream.Peek() == '}')
                {
                    stream.Advance();
                    semanticModel.Tokens.AddBrace(stream, Classifications.Property);
                }

                return(true);
            }

            return(false);
        }
예제 #18
0
        private void ParseFilter(Stream stream)
        {
            if (stream.Peek() == '(')
            {
                stream.Advance();

                var block = stream.PeekBlock(1, '(', ')');
                var index = block.IndexOf("=>", StringComparison.Ordinal);

                if (index > 0)
                {
                    var name = block.Substring(0, index);

                    semanticModel.ContextSpans.Add(null, null, ContextType.Lambda, stream.Position + 1, stream.Position + block.Length + 1);
                    semanticModel.ShadowClass.AddLambda(block, context.Peek().Name, name, stream.Position + 1);
                }
                stream.Advance(block.Length);

                if (stream.Peek() == ')')
                {
                    stream.Advance();
                }
            }
        }
예제 #19
0
        private bool ParseCodeBlock(Stream stream, ISemanticModel semanticModel, Stack <Context> context)
        {
            if (stream.Current == '$' && stream.Peek() == '{' && context.Peek() == _rootContext)
            {
                for (var i = 0; ; i--)
                {
                    var current = stream.Peek(i);
                    if (current == '`' || (current == '/' && stream.Peek(i - 1) == '/'))
                    {
                        return(false);
                    }
                    if (current == '\n' || current == char.MinValue)
                    {
                        break;
                    }
                }

                semanticModel.Tokens.Add(Classifications.Property, stream.Position);

                stream.Advance();
                semanticModel.Tokens.AddBrace(stream, Classifications.Property);

                var block = stream.PeekBlock(1, '{', '}');
                stream.Advance(block.Length);

                if (stream.Peek() == '}')
                {
                    stream.Advance();
                    semanticModel.Tokens.AddBrace(stream, Classifications.Property);
                }

                return(true);
            }

            return(false);
        }
예제 #20
0
        private void TerminateSymbol(Stream stream)
        {
            if (stream.Current == ' ' || stream.Current == '{' || stream.Current == ';' || stream.Current == '(' || stream.Current == ')' || stream.Current == ',')
            {
                _isSymbol = false;
            }

            // Find object literals
            if (stream.Current == '{')
            {
                var i = 0;
                while (true) if (stream.Peek(--i) != ' ') break;

                var peek = stream.Peek(i);

                if (peek == '=' || peek == '(' || peek == ',')
                {
                    var block = stream.PeekBlock(1, '{', '}');
                    _objectLiteralEnds = Math.Max(_objectLiteralEnds, stream.Position + block.Length);
                }
            }
        }
예제 #21
0
        private void ParseFilter(Stream stream, SemanticModel semanticModel, Stack<Context> context, int depth)
        {
            if (stream.Peek() == '(')
            {
                stream.Advance();
                var classification = GetPropertyClassification(depth);

                semanticModel.Tokens.AddBrace(stream, classification);

                var block = stream.PeekBlock(1, '(', ')');

                if (block.Contains("=>") == false)
                    semanticModel.Tokens.Add(Classifications.String, stream.Position + 1, block.Length);

                stream.Advance(block.Length);

                if (stream.Peek() == ')')
                {
                    stream.Advance();
                    semanticModel.Tokens.AddBrace(stream, classification);
                }
            }
        }
예제 #22
0
        //private void ParseDot(Stream stream, SemanticModel semanticModel, Stack<Context> context, int depth)
        //{
        //    if (stream.Peek() == '.')
        //    {
        //        stream.Advance();
        //        var identifier = GetIdentifier(stream, semanticModel, context);
        //        if (identifier != null)
        //        {
        //            var classification = GetPropertyClassification(depth);
        //            var parent = context.Skip(1).FirstOrDefault();
        //            semanticModel.Tokens.Add(classification, stream.Position);
        //            semanticModel.ContextSpans.Add(context.Peek(), parent, ContextType.Template, stream.Position, stream.Position + 1);
        //            if (identifier.IsParent)
        //            {
        //                semanticModel.Tokens.Add(classification, stream.Position + 1, identifier.Name.Length, identifier.QuickInfo.Replace("$parent", parent?.Name.ToLowerInvariant()));
        //                stream.Advance(identifier.Name.Length);
        //                var current = context.Pop();
        //                ParseDot(stream, semanticModel, context, depth); // identifier
        //                ParseBlock(stream, semanticModel, context, depth); // template
        //                context.Push(current);
        //            }
        //            else
        //            {
        //                semanticModel.Tokens.Add(classification, stream.Position + 1, identifier.Name.Length, identifier.QuickInfo);
        //                stream.Advance(identifier.Name.Length);
        //                if (identifier.IsCollection)
        //                {
        //                    context.Push(_contexts.Find(identifier.Context));
        //                    ParseFilter(stream, semanticModel, context, depth);
        //                    ParseBlock(stream, semanticModel, context, depth); // template
        //                    context.Pop();
        //                    ParseBlock(stream, semanticModel, context, depth); // separator
        //                }
        //                else if (identifier.IsBoolean)
        //                {
        //                    ParseBlock(stream, semanticModel, context, depth); // true
        //                    ParseBlock(stream, semanticModel, context, depth); // false
        //                }
        //                else if (identifier.HasContext)
        //                {
        //                    context.Push(_contexts.Find(identifier.Context));
        //                    ParseDot(stream, semanticModel, context, depth); // identifier
        //                    ParseBlock(stream, semanticModel, context, depth); // template
        //                    context.Pop();
        //                }
        //            }
        //        }
        //    }
        //}
        private void ParseBlock(Stream stream, SemanticModel semanticModel, Stack<Context> context, int depth)
        {
            if (stream.Peek() == '[')
            {
                stream.Advance();
                var classification = GetPropertyClassification(depth);

                semanticModel.Tokens.AddBrace(stream, classification);

                var block = stream.PeekBlock(1, '[', ']');
                Parse(block, semanticModel, context, stream.Position + 1, depth + 1);
                stream.Advance(block.Length);

                if (stream.Peek() == ']')
                {
                    stream.Advance();
                    semanticModel.Tokens.AddBrace(stream, classification);
                }
            }
        }
예제 #23
0
        private void ParseFilter(Stream stream)
        {
            if (stream.Peek() == '(')
            {
                stream.Advance();

                var block = stream.PeekBlock(1, '(', ')');
                var index = block.IndexOf("=>", StringComparison.Ordinal);

                if (index > 0)
                {
                    var name = block.Substring(0, index);

                    semanticModel.ContextSpans.Add(null, null, ContextType.Lambda, stream.Position + 1, stream.Position + block.Length + 1);
                    semanticModel.ShadowClass.AddLambda(block, context.Peek().Name, name, stream.Position + 1);
                }
                stream.Advance(block.Length);

                if (stream.Peek() == ')')
                {
                    stream.Advance();
                }
            }
        }