public codeBuilder(syntaxDeclaration __syntax) { _syntax = __syntax; // _source = __source; prepare(); }
/// <summary> /// Generates source code string for this line /// </summary> /// <param name="syntax"></param> /// <returns></returns> public String render(syntaxDeclaration syntax) { //if (__declaration == null) __declaration = declaration; // __declaration.className String output = ""; if (declaration == null) { output = "# error [" + name + "]:[" + GetType().Name + "]" + Environment.NewLine; } else { syntaxLineClassDeclaration lineclass = syntax.lineClasses.getClass(declaration.className); syntaxBlockLineDeclaration sLD = null; if (parent != null) { syntaxBlockDeclaration sBD = syntax.blocks.find(parent.name) as syntaxBlockDeclaration; sLD = sBD.lines.find(name); if (sLD == null) { output = "# not supported: [" + name + "]:[" + GetType().Name + "]" + Environment.NewLine; return(output); } } //syntax.blocks.find() List <String> values = new List <String>(); foreach (codeLineToken tk in children.items) { values.Add(tk.getValue()); } if (sLD != null) { values[0] = sLD.name; } else { } if (!String.IsNullOrEmpty(values[0])) { output = String.Format(lineclass.template, values.ToArray()); } else { } } return(output); }
public void deployCode(codeSourceElement el, syntaxDeclaration syntax) { codeSourceElementCollection subElements = new codeSourceElementCollection(el, syntax); syntaxBlockDeclaration sb; foreach (codeSourceElement subEl in subElements.codeElements) { if (subEl.lineClass != null) { switch (subEl.lineClass.lineType) { case syntaxBlockLineType.normal: codeLine cl = children.getElement <codeLine>(subEl.name); if (cl == null) { syntaxBlockLineDeclaration cld = declaration.lines.Find(x => x.name == subEl.name); cl = new codeLine(subEl.name, cld); children.Add(cl); } cl.deployDeclaration(syntax); cl.deployCode(subEl); break; case syntaxBlockLineType.block: sb = syntax.blocks.find(subEl.name); codeBlock cb = children.getElement <codeBlock>(subEl.name); if (cb == null) { cb = new codeBlock(subEl.name, sb); children.Add(cb); } // cb.deployDeclaration(syntax); cb.deployCode(subEl, syntax); ////// ovde poziva obradu koda break; case syntaxBlockLineType.emptyLine: break; default: break; } } } }
//public String renderInto(syntaxDeclaration syntax) //{ // String output = ""; // String inner = ""; // syntaxBlockDeclaration blockclass = syntax.blocks.find(name); // if (blockclass == null) return output; // syntaxBlockRenderMode mode = blockclass.render; // String tab = "\t".Repeat(level); // switch (mode) // { // case syntaxBlockRenderMode.complete: // tab = "\t".Repeat(level); // break; // case syntaxBlockRenderMode.inner: // tab = ""; // break; // } // foreach (ICodeElement cl in children.items) // { // String cls = cl.renderInto(syntax); // if (!string.IsNullOrEmpty(cls)) // { // inner = inner + tab + cls; // } // } // switch (mode) // { // case syntaxBlockRenderMode.complete: // output = String.Format(syntax.blockClass.template, new object[] { name, inner }); // break; // case syntaxBlockRenderMode.inner: // output = inner; // break; // } // return output; //} public String render(syntaxDeclaration syntax) { String output = ""; String inner = ""; syntaxBlockDeclaration blockclass = syntax.blocks.find(name); if (blockclass == null) { return(output); } syntaxBlockRenderMode mode = blockclass.render; String tab = "\t".Repeat(level); switch (mode) { case syntaxBlockRenderMode.complete: tab = "\t".Repeat(level); break; case syntaxBlockRenderMode.inner: tab = ""; break; } foreach (ICodeElement cl in children.items) { String cls = cl.render(syntax); if (!string.IsNullOrEmpty(cls)) { inner = inner + tab + cls; } } switch (mode) { case syntaxBlockRenderMode.complete: output = String.Format(syntax.blockClass.template, new object[] { name, inner }); break; case syntaxBlockRenderMode.inner: output = inner; break; } return(output); }
public void processMetaSource(String metaSource, syntaxDeclaration syntax) { var sl = metaSource.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); items.AddRange(sl); codeSourceElement cSE = null; foreach (String it in items) { if (regexPlaceholderToName.IsMatch(it)) { Match mch = regexPlaceholderToName.Match(it); String blockname = mch.Groups[1].Value; Int32 i = Int32.Parse(blockname); cSE = this[i]; if (regexPlaceholderToName.IsMatch(cSE.source)) { MatchCollection submch = regexPlaceholderToName.Matches(cSE.source); foreach (Match mc in submch) { String sid = mc.Groups[1].Value; Int32 si = Int32.Parse(sid); cSE.subElements.Add(si, this[si]); } } } else { if (String.IsNullOrWhiteSpace(it)) { cSE = new codeSourceElement(); cSE._type = codeSourceElementType.empty; cSE._source = it; } else { cSE = new codeSourceElement(); cSE._type = codeSourceElementType.unknown; cSE._source = it; } } codeElements.Add(cSE); } }
//public String renderInto(syntaxDeclaration syntax) //{ // //if (__declaration != null) __declaration = declaration; // //__declaration.className // String output = ""; // String inner = ""; // codeBlock cb = null; // syntaxBlockDeclaration sb; // foreach (codeBlock sl in children.items) // { // output = output + sl.renderInto(syntax).Trim(Environment.NewLine.ToCharArray()) + Environment.NewLine; // } // return output; //} public String render(syntaxDeclaration syntax) { //if (__declaration != null) __declaration = declaration; //__declaration.className String output = ""; String inner = ""; codeBlock cb = null; syntaxBlockDeclaration sb; foreach (codeBlock sl in children.items) { output = output + sl.render(syntax).Trim(Environment.NewLine.ToCharArray()) + Environment.NewLine; } return(output); }
public String processSource(string __source, syntaxDeclaration syntax) { String metaSource = __source; foreach (syntaxLineClassDeclaration lclass in syntax.lineClasses) { Match mch; do { mch = lclass.getRegex().Match(metaSource); //syntax.getBlockRegex().Match(metaSource); if (!mch.Success) { break; } codeSourceElement cel = new codeSourceElement(); cel._source = mch.Groups[0].Value; cel._lineClass = lclass; for (Int32 i = 1; i < mch.Groups.Count; i++) { cel._tokens.Add(mch.Groups[i].Value); } if (cel._tokens.Count > lclass.nameToken) { cel._name = cel._tokens[lclass.nameToken]; } Add(cel); // metaSource = metaSource.Substring(0, mch.Index); String preSource = metaSource.Substring(0, mch.Index); String postSource = metaSource.Substring(mch.Index + mch.Length); String bnamePlaceholder = makePlaceholder(IndexOf(cel).ToString()); metaSource = preSource.add(bnamePlaceholder, Environment.NewLine).add(postSource, Environment.NewLine); } while (mch.Success); } return(metaSource); }
/// <summary> /// Populates content using declaration data and syntax /// </summary> /// <param name="syntax"></param> public void deployDeclaration(syntaxDeclaration syntax) { if (declaration != null) { foreach (var tn in declaration.tokens) { if (!children.hasElement(tn.name)) { codeLineToken tk = new codeLineToken(tn.name, tn); children.Add(tk); tk.deployDeclaration(syntax); } else { } } } }
internal codeSourceElementCollection(codeSourceElement el, syntaxDeclaration syntax) { String subSource = el.source; if (el.lineClass.lineType == syntaxBlockLineType.block) { subSource = el.tokens[1]; } //foreach (var kv in el.subElements) //{ //} Match submch; do { submch = regexPlaceholderToName.Match(subSource); //syntax.getBlockRegex().Match(metaSource); if (!submch.Success) { break; } String sid = submch.Groups[1].Value; Int32 si = Int32.Parse(sid); codeSourceElement subEl = el.subElements[si]; Add(subEl); si = IndexOf(subEl); String preSource = subSource.Substring(0, submch.Index); String postSource = subSource.Substring(submch.Index + submch.Length); String bnamePlaceholder = makePlaceholderAlt(si.ToString()); subSource = preSource.add(bnamePlaceholder, Environment.NewLine).add(postSource, Environment.NewLine); } while (submch.Success); subSource = subSource.Replace("===", "$$$"); String metaSource = processSource(subSource, syntax); processMetaSource(metaSource, syntax); }
public String render(syntaxDeclaration syntax) { //if (__declaration == null) __declaration = declaration; // __declaration.className String output = ""; output = getValue(); /* * syntaxLineClassDeclaration lineclass = syntax.lineClasses.getClass(declaration.className); * * List<String> values = new List<String>(); * * foreach (codeLineToken tk in children.items) * { * values.Add(tk.getValue()); * } * * output = String.Format(lineclass.template, values.ToArray()); */ return(output); }
public void deployDeclaration(syntaxDeclaration syntax) { foreach (syntaxBlockLineDeclaration ln in declaration.lines) { switch (ln.render) { case syntaxBlockLineType.block: syntaxBlockDeclaration bls = syntax.blocks.find(ln.name); codeBlock cb = new codeBlock(ln.name, bls); children.Add(cb); cb.deployDeclaration(syntax); break; case syntaxBlockLineType.comment: case syntaxBlockLineType.custom: case syntaxBlockLineType.normal: codeLine cl = new codeLine(ln.name, ln); children.Add(cl); cl.deployDeclaration(syntax); break; } } }
internal codeSourceElementCollection(String __source, syntaxDeclaration syntax) { String metaSource = processSource(__source, syntax); processMetaSource(metaSource, syntax); }
/// <summary> /// Code DOM instance - using supplied declaration /// </summary> /// <param name="__syntax"></param> public code(syntaxDeclaration __syntax) { _declarationBase = __syntax; _children = new codeElementCollection(this, typeof(codeBlock), typeof(codeLine)); }
public void build(String __source, syntaxDeclaration syntax) { }
public void deployDeclaration(syntaxDeclaration syntax) { _tokenType = syntax.types.getType(declaration.typeName); // declaration.typeName.getTypeFromName(); }