private static MatchingBracePair FindMatchingBracePair(IndexTokenNode tokenNode) { IndexToken matchingBrace = ScanForMatchingBrace(tokenNode); if (matchingBrace == null) { return(new MatchingBracePair(tokenNode.IndexToken, null)); } return(new MatchingBracePair(tokenNode.IndexToken, matchingBrace)); }
public IndexServices() { database = new Database(Settings.ProtocolConfiguration.ChainFolderName); OwnerIndex = new IndexOwner(database); TokenIndex = new IndexToken(database); string nativeTokenSymbol = null; if (TokenIndex.GetNative() != null) { nativeTokenSymbol = TokenIndex.GetNative().Symbol; } BalanceIndex = new IndexBalance(database, nativeTokenSymbol); OrderIndex = new IndexOrder(database); }
public TokenChangedEventArgs(IndexToken indexToken) { _indexToken = indexToken; }
/// <summary> /// Handle writing the markdown documentation for a single XML element. /// </summary> /// <param name="child"></param> /// <param name="docString"></param> /// <param name="luaNamespace"></param> private static IndexToken ParseToken(XmlNode child, StringBuilder docString, ref string luaNamespace) { IndexToken indexEntry = null; XmlElement luaNameTag = child["LuaName"]; if (luaNameTag != null) { luaNamespace = luaNameTag.InnerText; XmlElement markdownDoc = child["mdDoc"]; if (markdownDoc != null) { string innerText = markdownDoc.InnerText.Replace("<", "<").Replace(">", ">"); docString.AppendLine(innerText); docString.AppendLine(); } } XmlElement methodName = child["method"]; if (methodName != null) { indexEntry = new IndexToken(); indexEntry.indexType = IndexToken.IndexType.INDEX_FUNCTION; indexEntry.decoratedName = new StringBuilder(); docString.Append("### "); if (!string.IsNullOrEmpty(luaNamespace)) { docString.Append(luaNamespace); docString.Append('.'); indexEntry.decoratedName.Append(luaNamespace).Append('.'); } indexEntry.rawName = methodName.InnerText; indexEntry.decoratedName.Append(methodName.InnerText); docString.AppendLine(methodName.InnerText); docString.AppendLine(); int paramCount = 0; XmlNode param = child["param"]; while (param != null) { if (param is XmlElement && !string.IsNullOrEmpty(param.InnerText.Trim())) { XmlAttribute attr = param.Attributes["name"]; if (attr != null) { docString.Append("* `"); docString.Append(attr.Value); docString.Append("`: "); docString.AppendLine(param.InnerText.Trim()); ++paramCount; } } param = param.NextSibling; } if (paramCount > 0) { docString.AppendLine(); } XmlElement returns = child["returns"]; if (returns != null && !string.IsNullOrEmpty(returns.InnerText.Trim())) { docString.Append("**Returns**: "); docString.AppendLine(returns.InnerText.Trim()); docString.AppendLine(); } XmlElement seealso = child["seealso"]; if (seealso != null && !string.IsNullOrEmpty(seealso.InnerText.Trim())) { docString.Append("**Supported Mod(s)**: "); docString.AppendLine(seealso.InnerText.Trim()); docString.AppendLine(); } XmlElement summary = child["summary"]; if (summary != null && methodName != null) { string innerText = summary.InnerText.Replace("<", "<").Replace(">", ">"); indexEntry.summary = innerText; indexEntry.summary = indexEntry.summary.Replace(Environment.NewLine, " ").Replace("`", " ").Trim(' '); if (indexEntry.summary.Length > 32) { indexEntry.summary = indexEntry.summary.Substring(0, 32); indexEntry.summary += "..."; } docString.AppendLine(innerText); docString.AppendLine(); } } XmlElement regionName = child["region"]; if (regionName != null) { indexEntry = new IndexToken(); indexEntry.indexType = IndexToken.IndexType.INDEX_REGION; indexEntry.decoratedName = new StringBuilder(); docString.AppendLine("***"); docString.Append("## "); docString.Append(regionName.InnerText); indexEntry.rawName = regionName.InnerText; if (!string.IsNullOrEmpty(luaNamespace)) { indexEntry.decoratedName.Append(luaNamespace); } docString.AppendLine(" Category"); docString.AppendLine(); XmlElement summary = child["summary"]; if (summary != null && regionName != null) { string innerText = summary.InnerText.Replace("<", "<").Replace(">", ">"); indexEntry.summary = innerText; indexEntry.summary = indexEntry.summary.Replace(Environment.NewLine, " ").Replace("`", " ").Trim(' '); if (indexEntry.summary.Length > 64) { indexEntry.summary = indexEntry.summary.Substring(0, 64); indexEntry.summary += "..."; } docString.AppendLine(innerText); docString.AppendLine(); } } return(indexEntry); }
/// <summary> /// Do the documentation parsing. /// </summary> /// <param name="sourceFile"></param> static void Documentify(string sourceFile) { int tail = sourceFile.LastIndexOf('.'); if (tail <= 0) { throw new Exception("Can't find a file name dot in sourceFile"); } int backslash = sourceFile.LastIndexOf('\\'); string mdStr = sourceFile.Substring(0, tail) + ".md"; // Read the file. string[] lines = File.ReadAllLines(sourceFile, Encoding.UTF8); //string xmlStr = sourceFile.Substring(0, tail) + ".xml"; bool inComments = false; DocumentToken docToken = null; // Iterate over the lines to assemble the list of potential documentations. for (int i = 0; i < lines.Length; ++i) { string token = lines[i].Trim(); if (inComments) { if (token.StartsWith("///")) { docToken.rawSummary.AppendLine(token.Substring(3)); } else { if (token != "[MoonSharpHidden]") { docToken.rawName = token; tokens.Add(docToken); } inComments = false; } } else { if (token.StartsWith("///")) { inComments = true; docToken = new DocumentToken(); docToken.rawSummary = new StringBuilder(); docToken.rawSummary.AppendLine("<token>"); docToken.rawSummary.AppendLine(token.Substring(3)); } } } docToken = null; List <string> contents = new List <string>(); //System.Console.WriteLine("Potential Tokens:"); StringBuilder docString = new StringBuilder(); docString.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); docString.Append("<documentor file=\""); string sourceFileName = sourceFile.Substring(backslash + 1); docString.Append(sourceFileName); docString.AppendLine("\">"); for (int i = 0; i < tokens.Count; ++i) { //System.Console.WriteLine(string.Format("[{0,3}]: {1}", i, tokens[i].rawName)); int openParen = tokens[i].rawName.IndexOf('('); if (openParen > 0) { int lastSpace = tokens[i].rawName.LastIndexOf(' ', openParen); if (lastSpace >= 0) { tokens[i].rawSummary.Append("<method>"); tokens[i].rawSummary.Append(tokens[i].rawName.Substring(lastSpace + 1)); tokens[i].rawSummary.AppendLine("</method>"); } } else if (tokens[i].rawName.StartsWith("#region")) { tokens[i].rawSummary.Append("<region>"); string regionName = tokens[i].rawName.Substring(tokens[i].rawName.IndexOf(' ') + 1); contents.Add(regionName); tokens[i].rawSummary.Append(regionName); tokens[i].rawSummary.AppendLine("</region>"); } tokens[i].rawSummary.AppendLine("</token>"); docString.Append(tokens[i].rawSummary.ToString()); } docString.AppendLine("</documentor>"); string rawDocument = docString.ToString(); // Uncomment to spew the XML document to a file for perusal. //File.WriteAllText(xmlStr, rawDocument, Encoding.UTF8); XmlDocument doc = new XmlDocument(); doc.PreserveWhitespace = true; try { doc.LoadXml(rawDocument); } catch (Exception e) { System.Console.WriteLine(e); tokens.Clear(); return; } string luaNamespace = string.Empty; XmlNode root = doc.DocumentElement; docString = new StringBuilder(); docString.Append("# "); docString.AppendLine(sourceFileName); docString.AppendLine(); if (contents.Count > 1) { docString.AppendLine("## Contents"); docString.AppendLine(); for (int i = 0; i < contents.Count; ++i) { docString.Append("* ["); docString.Append(contents[i]); docString.Append("](#"); string anchor = contents[i].ToLower().Replace(' ', '-'); string[] finalAnchor = anchor.Split(','); foreach (string a in finalAnchor) { docString.Append(a); } docString.AppendLine("-category)"); } docString.AppendLine(); } if (root.HasChildNodes) { XmlNode child = root.FirstChild; while (child != null) { if (child is XmlElement && child.Name == "token") { IndexToken indexEntry = ParseToken(child, docString, ref luaNamespace); if (indexEntry != null) { indexEntry.sourceFile = sourceFileName; if (indexEntry.indexType == IndexToken.IndexType.INDEX_FUNCTION) { index.Add(indexEntry); } else if (indexEntry.indexType == IndexToken.IndexType.INDEX_REGION) { region.Add(indexEntry); } } //System.Console.WriteLine(child.Name); } child = child.NextSibling; } } docString.AppendLine("***"); DateTime now = DateTime.UtcNow; docString.AppendLine(string.Format("*This documentation was automatically generated from source code at {0,2:00}:{1,2:00} UTC on {2}/{3}/{4}.*", now.Hour, now.Minute, now.Day, MonthAbbr[now.Month], now.Year)); docString.AppendLine(); if (!File.Exists(mdStr) || (File.Exists(mdStr) && File.GetLastWriteTimeUtc(mdStr) <= File.GetLastWriteTimeUtc(sourceFile))) { File.WriteAllText(mdStr, docString.ToString(), Encoding.UTF8); anyWritten = true; } tokens.Clear(); }
public MatchingBracePair(IndexToken start, IndexToken end) { _start = start; _end = end; }
public override void Analy(AnalyStmtContext context) { //base.LoadRefTypes(context); int foreachIndex = context.MethodContext.CreateForeachIndex(); if (ListExp == null) { error("'循环每一个语句'不存在要循环的列表"); } if (ElementToken == null) { error("'循环每一个语句'不存在成员名称"); } if (ListExp == null || ElementToken == null) { return; } this.AnalyStmtContext = context; var symbols = context.Symbols; ListExp = AnalyExp(ListExp); if (ListExp == null) { TrueAnalyed = false; return; } if (ListExp.RetType == null) { TrueAnalyed = false; return; } else if (!canForeach(ListExp.RetType)) { error(ListExp.Postion, "该结果不能用作循环每一个"); return; } if (ReflectionUtil.IsExtends(ListExp.RetType, typeof(列表 <>))) { startIndex = 1; compareMethod = typeof(Calculater).GetMethod("LEInt", new Type[] { typeof(int), typeof(int) }); } else { startIndex = 0; compareMethod = typeof(Calculater).GetMethod("LTInt", new Type[] { typeof(int), typeof(int) }); } //PropertyInfo countProperty = ListExp.RetType.GetProperty("Count"); ExPropertyInfo countProperty = GclUtil.SearchExProperty("Count", ListExp.RetType); getCountMethod = new ExMethodInfo(countProperty.Property.GetGetMethod(), countProperty.IsSelf); //PropertyInfo itemProperty = ListExp.RetType.GetProperty("Item"); ExPropertyInfo itemProperty = GclUtil.SearchExProperty("Item", ListExp.RetType); diMethod = new ExMethodInfo(itemProperty.Property.GetGetMethod(), itemProperty.IsSelf); elementName = ElementToken.GetText(); if (IndexToken != null) { indexName = IndexToken.GetText(); } else { indexName = "$$$foreach_" + foreachIndex + "_index"; } createForeachSymbols(context, symbols, foreachIndex, ListExp.RetType); analySubStmt(Body); }
public override string ToCode() { StringBuilder buf = new StringBuilder(); buf.Append(getStmtPrefix()); buf.AppendFormat("循环每一个( {0},{1} , {2} )", this.ListExp.ToCode(), ElementToken.ToCode(), IndexToken != null?("," + IndexToken.GetText()):""); buf.AppendLine(); buf.Append(Body.ToString()); return(buf.ToString()); }