Beispiel #1
0
 /// <summary>Evaluate lines till we run out</summary>
 internal static Value Do(ILineRequestor requestor, IScope scope)
 {
     int lineNumber = 0;
     try
     {
         Value value = null;
         while (requestor.HasCurrent())
         {
             lineNumber = requestor.GetCurrentLineNumber();
             value = EvalLines.DoOne(requestor, scope);
         }
         return value;
     }
     catch (Loki3Exception e)
     {
         e.AddLineNumber(lineNumber);
         throw e;
     }
 }
Beispiel #2
0
        /// <summary>
        /// Get the body following the current line.
        /// 'requestor' will be positioned on the last line of the body.
        /// </summary>
        internal static List<DelimiterList> DoGetBody(IScope scope, ILineRequestor requestor)
        {
            List<DelimiterList> body = new List<DelimiterList>();

            // if we have a subset of all lines, we should simply use them as-is
            if (requestor.IsSubset())
            {
                while (requestor.HasCurrent())
                {
                    DelimiterList dline = requestor.GetCurrentLine(scope);
                    dline.Scope = scope;	// use this scope when evaling later
                    body.Add(dline);
                    requestor.Advance();
                }
                return body;
            }

            // else just grab indented lines
            DelimiterList pline = requestor.GetCurrentLine(scope);
            int parentIndent = pline.Indent;
            while (requestor.HasCurrent())
            {
                requestor.Advance();
                DelimiterList childLine = requestor.GetCurrentLine(scope);
                if (childLine == null || childLine.Indent <= parentIndent)
                {
                    requestor.Rewind();
                    break;	// now we have the body
                }
                childLine.Scope = scope;	// use this scope when evaling later

                // keep adding to the body
                body.Add(childLine);
            }
            return body;
        }