private PlainBlock TranslatePlain(ICodeBlock parent, int start, int finish) { var translated = new List <MultiTreeNode <Value> >(); for (var i = start; i < finish; i++) { if (Empty.IsMatch(Code[i]) || Comment.IsMatch(Code[i])) { continue; } translated.Add(Parser.ParseLine(Code[i])); } return(translated.Count == 0 ? null : new PlainBlock(parent, translated)); }
public ICodeBlock Translate(ICodeBlock parent = null, int start = 0, int finish = -1) { if (finish == -1) { finish = Code.Count; } ICodeBlock result; if (parent != null) { result = new ComplexBlock(parent); } else { result = new NamespaceBlock(null); } var interpreted = new List <ICodeBlock>(); var startPlainBlock = start; for (var i = start; i < finish; i++) { if (Empty.IsMatch(Code[i]) || Comment.IsMatch(Code[i])) { continue; } var match = Condition.Match(Code[i]); if (match.Success) { CheckForPlain(result, startPlainBlock, i, interpreted); interpreted.Add(TranslateCondition(result, match.Groups["condition"].ToString(), i, out i)); startPlainBlock = i; continue; } match = WhileCycle.Match(Code[i]); if (match.Success) { CheckForPlain(result, startPlainBlock, i, interpreted); interpreted.Add(TranslateWhile(result, match.Groups["condition"].ToString(), i, out i)); startPlainBlock = i + 1; continue; } } CheckForPlain(result, startPlainBlock, finish, interpreted); if (interpreted.Count == 1 && parent != null) { result = interpreted[0]; result.ParentBlock = parent; } else if (result is ComplexBlock complexBlock) { complexBlock.Code = interpreted; } else { ((NamespaceBlock)result).Code = interpreted; } return(result); }