Пример #1
0
        public static SourceObject Compute(
            Compiler compiler,
            Source src,
            AmbientParser.IUnoCodeReader codeReader,
            AmbientParser.ParseResult parseResult,
            out int rangeStart,
            out int rangeLength,
            out string memberExp)
        {
            var cc = new CodeCompleter.CodeCompleter(compiler, src, codeReader, codeReader.Offset, parseResult);

            return(Compute(src, codeReader, cc, out rangeStart, out rangeLength, out memberExp));
        }
Пример #2
0
 public static SourceObject TryGetSourceObject(Compiler compiler, Source src, AmbientParser.IUnoCodeReader codeReader, AmbientParser.ParseResult parseResult)
 {
     try
     {
         int    start, length;
         string memberExp;
         return(Compute(compiler, src, codeReader, parseResult, out start, out length, out memberExp));
     }
     catch (MaxErrorException)
     {
         return(null);
     }
 }
Пример #3
0
        static SourceObject Compute(
            Source src,
            AmbientParser.IUnoCodeReader codeReader,
            CodeCompleter.CodeCompleter codeCompleter,
            out int rangeStart,
            out int rangeLength,
            out string memberExp)
        {
            memberExp   = "";
            rangeStart  = 0;
            rangeLength = 0;
            try
            {
                memberExp = FindMemberExpression(codeReader, out rangeStart, out rangeLength, codeCompleter);

                if (memberExp == null || codeCompleter.Context.NodePath == null)
                {
                    return(null);
                }

                var methodNode = codeCompleter.Context.NodePath.LastOrDefault(x => AmbientParser.NodeTypeHelpers.IsMethodNode(x.Type));

                var fc = codeCompleter.CreateFunctionCompiler(methodNode);
                var pe = codeCompleter.ResolveStringInFunctionContext(methodNode, memberExp, src, fc);

                if ((pe == null || pe.IsInvalid) && fc.Namescope != null)
                {
                    var compute = ResolveStringWhenClassDeclaration(memberExp, fc);
                    if (compute != null)
                    {
                        return(compute);
                    }
                }

                return(ResolvePartialExpression(pe));
            }
            catch (Exception e)
            {
                if (e is MaxErrorException)
                {
                    throw;
                }
                return(null);
            }
        }
Пример #4
0
        public static string FindMemberExpression(
            AmbientParser.IUnoCodeReader codeReader,
            out int rangeStart,
            out int rangeLength,
            CodeCompleter.CodeCompleter cc)
        {
            rangeStart  = codeReader.Offset;
            rangeLength = codeReader.Offset;

            // Skip to end of identifier;
            while (true)
            {
                var cs = codeReader.PeekText(1);
                if (string.IsNullOrEmpty(cs))
                {
                    return(null);
                }
                var c = cs[0];
                if (char.IsLetterOrDigit(c) || c == '_')
                {
                    codeReader.ReadText(1);
                }
                else
                {
                    break;
                }
            }
            int rangeEnd = codeReader.Offset;

            if (cc.Context.NodePath == null)
            {
                return(null);
            }

            TokenType tt;
            var       memberExp = cc.FindMemberExpression(out tt, false, false);

            rangeStart  = rangeEnd - memberExp.Length;
            rangeLength = memberExp.Length;

            return(memberExp);
        }