/// <summary> /// Generates the code for a StateEvent node. /// </summary> /// <param name="se">The StateEvent node.</param> /// <param name="parentStateName">The name of the parent state.</param> /// <returns>String containing C# code for StateEvent se.</returns> private string GenerateStateEvent(StateEvent se, string parentStateName) { StringBuilder retstr = new StringBuilder(); // we need to separate the argument declaration list from other kids List<SYMBOL> argumentDeclarationListKids = new List<SYMBOL>(); List<SYMBOL> remainingKids = new List<SYMBOL>(); LSL2CSCodeTransformer.FixEventName(this.OriginalScript, ref se); _currentLocalFunctionDeclaration = se; MethodVariables.Clear(); VariablesToRename.Clear(); foreach (SYMBOL kid in se.kids) if (kid is ArgumentDeclarationList) argumentDeclarationListKids.Add(kid); else remainingKids.Add(kid); // "state" (function) declaration retstr.Append(GenerateIndented( String.Format("public System.Collections.IEnumerator {0}_event_{1}(", parentStateName, se.Name), se)); IsParentEnumerable = true; // print the state arguments, if any List<ArgumentDeclarationList> args = new List<ArgumentDeclarationList>(); foreach (SYMBOL kid in argumentDeclarationListKids) { args.Add(((ArgumentDeclarationList) kid)); retstr.Append(GenerateArgumentDeclarationList((ArgumentDeclarationList) kid)); } m_allMethods.Add(String.Format("{0}_event_{1}", parentStateName, se.Name), args); retstr.Append(GenerateLine(")")); foreach (SYMBOL kid in remainingKids) retstr.Append(GenerateNode(kid)); if (retstr[retstr.Length - 2] == '}') retstr.Insert(retstr.Length - 2, GenerateLine(" yield break;")); return retstr.ToString(); }
public StateBody(Parser yyp, StateEvent se) : base((yyp)) { kids.Add(se); }
public static void FixEventName(string script, ref StateEvent evt) { if (evt.Name == "remote_data") { string[] lines = script.Split(new [] { '\n' }); string line = lines[evt.Line-1]; if (line.IndexOf('(') > 0) { line = line.Substring(0, line.IndexOf('(')).Trim(); if(_newLSLEvents.Any((ev) => ev.Name == line)) evt.Name = line; } } }
public StateBody(Parser yyp, StateBody sb, StateEvent se) : base((yyp)) { while (0 < sb.kids.Count) kids.Add(sb.kids.Pop()); kids.Add(se); }