public FSMTokenFunction(string str, E_TokenType type, TagMethodTable methodTable) : base(str, type, GetTokenName(str)) { methodInfo = methodTable.GetMethodInfo(name); string temp = text; while (temp.StartsWith("!")) { temp = temp.Remove(0, 1); isNegative = !isNegative; } }
static FSMPage Parse(string path, System.Type handleType) { string text = (Resources.Load(path) as TextAsset).text; text = RemoveBlockComments(text); string[] lines = text.Split("\n".ToCharArray(), System.StringSplitOptions.None); FSMPage page = new FSMPage(); List<string> paragraph = null; TagMethodTable methodTable = new TagMethodTable(handleType); foreach (var entity in lines) { string line = entity.Trim(); if (line.StartsWith("//")) { continue; } if (line.Contains(":=")) { string[] keyValue = line.Split(new string[] { ":=", " ", }, System.StringSplitOptions.RemoveEmptyEntries); methodTable.RegistFunction(keyValue[0], keyValue[1]); continue; } if (!string.IsNullOrEmpty(line)) { if (paragraph == null) { paragraph = new List<string>(); } paragraph.Add(line); continue; } if (string.IsNullOrEmpty(line)) { if (paragraph != null) { page.Add(new FSMParagraph(paragraph.ToArray(), methodTable)); paragraph = null; } continue; } } return page; }
//readonly string text; public FSMSentence(string text, TagMethodTable methodTable) { //this.text = text; // ddong for title if (this is FSMStateTitle) { tokens.Add(new FSMTokenTitle(text, FSMToken.E_TokenType.Title)); } else { string[] split = text.Split(new string[] { "->", }, System.StringSplitOptions.RemoveEmptyEntries); foreach (var entity in split) { tokens.Add(FSMToken.Create(entity, methodTable)); } } }
public static FSMToken Create(string str, TagMethodTable methodTable) { str = str.Trim(); E_TokenType type = GetTokenType(str); if (type == E_TokenType.Function) { if (FSM.internalMethods.Contains(str)) { return new FSMTokenInternalFunction(str, type); } return new FSMTokenFunction(str, type, methodTable); } else if (type == E_TokenType.ChangeState || type == E_TokenType.PushState || type == E_TokenType.PopState) { return new FSMTokenTranstate(str, type); } else if (type == E_TokenType.SetTimer || type == E_TokenType.Sleep) { return new FSMTokenTimer(str, type); } else if (type == E_TokenType.Constant) { return new FSMTokenConstant(str, type); } else if (type == E_TokenType.Variable) { return new FSMTokenVariable(str, type); } else if (type == E_TokenType.Event) { return new FSMTokenEvent(str, type); } else { Debug.LogError("wrong token type"); return null; } }
public FSMParagraph(string[] text, TagMethodTable methodTable) { title = new FSMStateTitle(text[0]); name = title.name; for (int i = 1; i < text.Length; i++) { string entity = text[i]; if (entity.StartsWith("@" + FSMKeywords.OnCreate)) { events.Add("create", new FSMStateEvent(entity, methodTable)); } else if (entity.StartsWith("@" + FSMKeywords.OnDestroy)) { events.Add("destroy", new FSMStateEvent(entity, methodTable)); } else if (entity.StartsWith("@" + FSMKeywords.OnEnter)) { events.Add("enter", new FSMStateEvent(entity, methodTable)); } else if (entity.StartsWith("@" + FSMKeywords.OnExit)) { events.Add("exit", new FSMStateEvent(entity, methodTable)); } else if (entity.StartsWith("@" + FSMKeywords.OnTimer)) { events.Add("timer", new FSMStateEvent(entity, methodTable)); } else if (entity.StartsWith("(") && entity.Contains(")")) { FSMStateEvent sentence = new FSMStateEvent(entity, methodTable); events.Add(sentence.eventName, sentence); } else { sentences.Add(new FSMSentence(entity, methodTable)); } } }
static FSM() { internalMethods = new TagMethodTable(null); internalMethods.RegistFunction<FSM>(FSMKeywords.FuncLog, "Log"); }