Ejemplo n.º 1
0
        /// <summary>
        /// Sets the header as the first line in the collection, the last line as the footer, and the code in between as the body
        /// </summary>
        /// <param name="blockLines"></param>
        protected void LoadFromCollection(LineCollection blockLines)
        {
            LineCollection body = blockLines.Clone();

            Header = blockLines[0];
            Footer = blockLines[blockLines.Count - 1];
            body.Remove(Header);
            body.Remove(Footer);
            Body = body;
        }
Ejemplo n.º 2
0
        internal static LineCollection ScanLines(string[] lines, out CodeBlock[] userFunctions)
        {
            LineCollection allLines = new LineCollection();
            List <uint>    funLines = new List <uint>();

            for (uint lineNumber = 0; lineNumber < lines.Length; ++lineNumber)
            {
                Line current = new Line(lineNumber + 1, lines[lineNumber]); // Tag all lines with its line number (index + 1)

                if (string.IsNullOrEmpty(current.Text) || current.Text[0] == ';')
                {
                    continue;
                }
                if (current.Name[current.Name.Length - 1] == '$' || current.Name[current.Name.Length - 1] == ']')
                {
                    current.Text = "LET " + current.Text; // add the word LET if it's an equality, but use the original name as visible name
                }
                else if (current.Name.EqualsIgnoreCase("FUNCTION"))
                {
                    funLines.Add(current.LineNumber);
                }
                else
                {
                    current.VisibleName = current.VisibleName.ToUpper();
                }

                while (current.Text[current.Text.Length - 1] == '_')   // line continuation
                {
                    lineNumber++;
                    if (lineNumber >= lines.Length)
                    {
                        throw new EndOfCodeException("line continuation character '_' cannot end script");
                    }
                    current = new Line(current.LineNumber, current.Text.Remove(current.Text.LastIndexOf('_')) + lines[lineNumber].Trim());
                }

                allLines.Add(current);
            }

            List <CodeBlock> userFuncs = new List <CodeBlock>();

            foreach (uint funcLine in funLines)
            {
                FuncBlock func = new FuncBlock(allLines.IndexOf(funcLine), allLines);
                userFuncs.Add(func);
                allLines.Remove(func.Header);
                allLines.Remove(func.Body);
                allLines.Remove(func.Footer);
            }
            userFunctions = userFuncs.ToArray();
            return(allLines);
        }