Exemplo n.º 1
0
        public void ParseTextAndApplyCommands(
            string s,
            bool lineBreak = false,
            string tmps    = "",
            bool doNotEvalutatePrintDirectives = false,
            EchoSequenceList printSequences    = null,
            int startIndex = 0)
        {
            lock (Writer.Lock)
            {
                int i = 0;
                KeyValuePair <string, (SimpleCommandDelegate simpleCommand, CommandDelegate command, object parameter)>?cmd = null;
                int  n             = s.Length;
                bool isAssignation = false;
                int  cmdindex      = -1;

                //var tmpsb = new StringBuilder(tmps, s.Length * 20);
                tmpsb.Clear();
                tmpsb.Append(tmps);

                while (cmd == null && i < n)
                {
                    if (s[i] == Console.CommandBlockBeginChar)
                    {
                        foreach (var ccmd in CommandMap.Map)
                        {
                            if (s.IndexOf(Console.CommandBlockBeginChar + ccmd.Key, i) == i)
                            {
                                cmd           = ccmd;
                                cmdindex      = i;
                                isAssignation = ccmd.Key.EndsWith("=");
                            }
                        }
                        if (cmd == null)
                        {
                            //tmps += s[i];
                            tmpsb.Append(s[i]);
                        }
                    }
                    else
                    {
                        //tmps += s[i];
                        tmpsb.Append(s[i]);
                    }
                    i++;
                }

                var stmps = tmpsb.ToString();

                if (cmd == null)
                {
                    Writer.ConsolePrint(/*tmps*/ stmps, false);

                    printSequences?.Add(new EchoSequence(Console, (string)null, 0, i - 1, null, /*tmps*/ stmps, startIndex));
                    return;
                }
                else
                {
                    i = cmdindex;
                }

                if (!string.IsNullOrEmpty(/*tmps*/ stmps))
                {
                    Writer.ConsolePrint(/*tmps*/ stmps);

                    printSequences?.Add(new EchoSequence(Console, (string)null, 0, i - 1, null, /*tmps*/ stmps, startIndex));
                }

                tmpsb.Clear();
                //tmpsb = null;

                int    firstCommandEndIndex = 0;
                int    k     = -1;
                string value = null;
                if (isAssignation)
                {
                    firstCommandEndIndex = s.IndexOf(Console.CommandValueAssignationChar, i + 1);
                    if (firstCommandEndIndex > -1)
                    {
                        firstCommandEndIndex++;
                        var subs = s[firstCommandEndIndex..];
        public void ParseTextAndApplyCommands(
            string s,
            bool lineBreak = false,
            string tmps    = "",
            bool doNotEvalutatePrintDirectives = false,
            EchoSequenceList printSequences    = null,
            int startIndex = 0)
        {
            lock (Writer.Lock)
            {
                int i = 0;
                KeyValuePair <string, (SimpleCommandDelegate simpleCommand, CommandDelegate command, object parameter)>?cmd = null;
                int  n             = s.Length;
                bool isAssignation = false;
                int  cmdindex      = -1;
                var  tmpsb         = new StringBuilder(tmps, s.Length * 2);

                while (cmd == null && i < n)
                {
                    if (s[i] == CommandBlockBeginChar)
                    {
                        foreach (var ccmd in CommandMap.Map)
                        {
                            if (s.IndexOf(CommandBlockBeginChar + ccmd.Key, i) == i)
                            {
                                cmd           = ccmd;
                                cmdindex      = i;
                                isAssignation = ccmd.Key.EndsWith("=");
                            }
                        }
                        if (cmd == null)
                        {
                            //tmps += s[i];
                            tmpsb.Append(s[i]);
                        }
                    }
                    else
                    {
                        //tmps += s[i];
                        tmpsb.Append(s[i]);
                    }
                    i++;
                }

                var stmps = tmpsb.ToString();

                if (cmd == null)
                {
                    Writer.ConsolePrint(/*tmps*/ stmps, false);

                    printSequences?.Add(new EchoSequence((string)null, 0, i - 1, null, /*tmps*/ stmps, startIndex));
                    return;
                }
                else
                {
                    i = cmdindex;
                }

                if (!string.IsNullOrEmpty(/*tmps*/ stmps))
                {
                    Writer.ConsolePrint(/*tmps*/ stmps);

                    printSequences?.Add(new EchoSequence((string)null, 0, i - 1, null, /*tmps*/ stmps, startIndex));
                }

                tmpsb.Clear();
                tmpsb = null;

                int    firstCommandEndIndex = 0;
                int    k     = -1;
                string value = null;
                if (isAssignation)
                {
                    firstCommandEndIndex = s.IndexOf(CommandValueAssignationChar, i + 1);
                    if (firstCommandEndIndex > -1)
                    {
                        firstCommandEndIndex++;
                        var subs = s.Substring(firstCommandEndIndex);
                        if (subs.StartsWith(CodeBlockBegin))
                        {
                            firstCommandEndIndex += CodeBlockBegin.Length;
                            k = s.IndexOf(CodeBlockEnd, firstCommandEndIndex);
                            if (k > -1)
                            {
#pragma warning disable IDE0057
                                value = s.Substring(firstCommandEndIndex, k - firstCommandEndIndex);
#pragma warning restore IDE0057
                                k += CodeBlockEnd.Length;
                            }
                            else
                            {
                                Writer.ConsolePrint(s);

                                printSequences?.Add(new EchoSequence((string)null, i, s.Length - 1, null, s, startIndex));
                                return;
                            }
                        }
                    }
                }

                int  j     = i + cmd.Value.Key.Length;
                bool inCmt = false;
                int  firstCommandSeparatorCharIndex = -1;
                while (j < s.Length)
                {
                    if (inCmt && s.IndexOf(CodeBlockEnd, j) == j)
                    {
                        inCmt = false;
                        j    += CodeBlockEnd.Length - 1;
                    }
                    if (!inCmt && s.IndexOf(CodeBlockBegin, j) == j)
                    {
                        inCmt = true;
                        j    += CodeBlockBegin.Length - 1;
                    }
                    if (!inCmt && s.IndexOf(CommandSeparatorChar, j) == j && firstCommandSeparatorCharIndex == -1)
                    {
                        firstCommandSeparatorCharIndex = j;
                    }
                    if (!inCmt && s.IndexOf(CommandBlockEndChar, j) == j)
                    {
                        break;
                    }
                    j++;
                }
                if (j == s.Length)
                {
                    Writer.ConsolePrint(s);

                    printSequences?.Add(new EchoSequence((string)null, i, j, null, s, startIndex));
                    return;
                }

                var cmdtxt = s[i..j];