Exemplo n.º 1
0
        public static LispObject GetNarrowestChild(this LispObject obj, LispSourcePosition position)
        {
            if (!obj.SourceLocation.HasValue ||
                !obj.SourceLocation.Value.ContainsPosition(position))
            {
                return(null);
            }

            var children = obj.GetChildren().ToList();

            if (children.Count == 0)
            {
                // can't delve any deeper
                return(obj);
            }

            // otherwise try to find the child that contains the position and recurse
            foreach (var child in children)
            {
                if (child.SourceLocation.HasValue &&
                    child.SourceLocation.Value.ContainsPosition(position))
                {
                    return(child.GetNarrowestChild(position));
                }
            }

            // no child was more specific, just return this
            return(obj);
        }
Exemplo n.º 2
0
        public LispParseResult ParseUntilSourceLocation(string code, LispSourcePosition position)
        {
            var        sourceBindings   = new LispSourceBindings(Host.CurrentPackage);
            LispObject containingObject = null;
            var        eofValue         = new LispError("EOF");
            var        textReader       = new StringReader(code);
            var        textStream       = new LispTextStream("", textReader, TextWriter.Null);

            Host.ObjectReader.SetReaderStream(textStream);
            while (true)
            {
                var result = Host.ObjectReader.Read(false, eofValue, true);
                if (ReferenceEquals(result.LastResult, eofValue))
                {
                    break;
                }

                sourceBindings.TryAddSourceBinding(result.LastResult);

                if (result.LastResult.SourceLocation.HasValue &&
                    result.LastResult.SourceLocation.Value.ContainsPosition(position))
                {
                    containingObject = result.LastResult;
                    break;
                }
            }

            var narrowestChild = containingObject?.GetNarrowestChild(position);
            var parseResult    = new LispParseResult(Host, narrowestChild, sourceBindings);

            return(parseResult);
        }
Exemplo n.º 3
0
 public bool ContainsPosition(LispSourcePosition position)
 {
     return(position >= Start && position < End);
 }
Exemplo n.º 4
0
 public LispSourceLocation(string filePath, LispSourcePosition start, LispSourcePosition end)
 {
     FilePath = filePath;
     Start    = start;
     End      = end;
 }