private static void NonLecsicAnalys(DuCode code) { //Blocks work code.Text = code.Text.Replace(StartBlockString, "\r\n" + StartBlockString + "\r\n"); code.Text = code.Text.Replace(EndBlockString, "\r\n" + EndBlockString + "\r\n"); while (code.Text.Contains("\r\n\r\n") || code.Text.Contains("\t") || code.Text.Contains(" ")) { //White spaces //code.Text = string.Join("\n", code.Text.Split('\n').Select(s => s.Trim())); //Lines shortify code.Text = code.Text.Replace("\r\n\r\n", "\r\n"); //Tabulation remove code.Text = code.Text.Replace("\t", ""); //Spaces shortify code.Text = code.Text.Replace(" ", " "); } if (string.IsNullOrWhiteSpace(code.Text.Split("\r\n")[^ 1]))
public DuAnalysedCode(DuCode baseCode) : base(baseCode.FileInfo) { }
private static DuAnalysedCode BlockSplitingAndTypping(DuCode code) { var instConstructors = definedInstructions.Select(s => s.GetConstructor(Array.Empty <Type>())).ToList(); var instNames = definedInstructions.Select(s => s.GetField("CODEDEFINE", BindingFlags.Static | BindingFlags.Public).GetValue(null) as string).ToList(); var blocksConstructors = definedBlocks.Select(s => s.GetConstructor(new Type[] { typeof(IEnumerable <CodeExecutable>) })).ToList(); var blocksNames = definedBlocks.Select(s => s.GetField("CODEDEFINE", BindingFlags.Static | BindingFlags.Public).GetValue(null) as string).ToList(); var result = new NullBlock(Array.Empty <CodeExecutable>(), null); var blockStack = new Stack <CodeBlock>(4); blockStack.Push(result); var lines = code.Text.Split("\r\n"); for (int i = 0; i < lines.Length; i++) { var line = lines[i]; if (i != lines.Length - 1 && lines[i + 1] == StartBlockString) { continue; } if (line == StartBlockString) { string[] innerCodeAttrs = null; int selectedVariant = -1; var block = blocksConstructors[blocksNames.FindIndex(s => MatchCodeObjectNameWithPattern(lines[i - 1], s, out innerCodeAttrs, out selectedVariant))].Invoke(new object[] { Array.Empty <CodeExecutable>() }) as CodeBlock; block.DefineBlock = blockStack.Peek(); block.InnerCodeAttributes = innerCodeAttrs; block.SelectedVariant = selectedVariant; blockStack.Peek().Executables.Add(block); blockStack.Push(block); } else if (line == EndBlockString) { blockStack.Pop(); } else { string[] innerCodeAttrs = null; int selectedVariant = -1; var inst = instConstructors[instNames.FindIndex(s => MatchCodeObjectNameWithPattern(line, s, out innerCodeAttrs, out selectedVariant))].Invoke(Array.Empty <object>()) as CodeInstruction; inst.DefineBlock = blockStack.Peek(); inst.InnerCodeAttributes = innerCodeAttrs; inst.SelectedVariant = selectedVariant; blockStack.Peek().Executables.Add(inst); } } return(new DuAnalysedCode(code) { Executables = result.Executables }); }