public static bool TryParse(string content, int start, int length, out KirinNode result) { result = null; if (content != "That's what I did") { return(false); } result = new KirinLoopEnd(start, length); return(true); }
public static KirinWhileLoop ParseNodes( KirinWhileLoop startNode, KirinNode[] nodes, KirinLoopEnd endNode, string content) { var statement = startNode; if (endNode != null) { statement.Length = (endNode.Start + endNode.Length) - startNode.Start; statement.Statement = FiMLexer.ParseStatement(nodes, content); } return(statement); }
public static KirinSwitch ParseNodes( KirinSwitchStart startNode, KirinNode[] nodes, KirinLoopEnd endNode, string content) { var statement = new KirinSwitch(-1, -1); statement.RawVariable = startNode.RawVariable; statement.Start = startNode.Start; statement.Length = (endNode.Start + endNode.Length) - startNode.Start; string currentCase = string.Empty; bool isDefault = false; List <KirinNode> subStatement = new List <KirinNode>(); foreach (var subnode in nodes) { if (subnode.NodeType == "KirinSwitchCase") { if (subStatement.Count > 0) { var s = FiMLexer.ParseStatement(subStatement.ToArray(), content); if (currentCase != string.Empty) { statement.AddCase(s, currentCase); } else if (isDefault) { statement.AddCase(s); } subStatement.Clear(); } var cNode = subnode as KirinSwitchCase; currentCase = cNode.RawCase; isDefault = false; } else if (subnode.NodeType == "KirinSwitchCaseDefault") { if (subStatement.Count > 0) { var s = FiMLexer.ParseStatement(subStatement.ToArray(), content); if (currentCase != string.Empty) { statement.AddCase(s, currentCase); } else if (isDefault) { statement.AddCase(s); } subStatement.Clear(); } currentCase = string.Empty; isDefault = true; } else { if (currentCase == string.Empty && !isDefault) { throw new FiMException("Switch case not found"); } subStatement.Add(subnode); } } if (subStatement.Count > 0) { var s = FiMLexer.ParseStatement(subStatement.ToArray(), content); if (currentCase != string.Empty) { statement.AddCase(s, currentCase); } else if (isDefault) { statement.AddCase(s); } subStatement.Clear(); } return(statement); }