public override bool Equals(object obj) { if (obj == null) { return(false); } StrIntIndex index = obj as StrIntIndex; if ((object)index == null) { return(false); } return(AreValuesEqual(this, index)); }
private static ArrayContentDef Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo) { ArrayContentDef arrayDef = new ArrayContentDef(); ScopeGroup group = (ScopeGroup)parentInfo.Current; MoveInfo moveInfo = new MoveInfo(group, SearchTree.ContentBlock, 0, parentInfo); IElement tryNext = moveInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible); // only for strIndex MoveInfo strIndexerInfo = new MoveInfo(moveInfo); IElement tryAssign = strIndexerInfo.FindNextBlack(SearchDirection.LeftToRight); if (tryNext == null) // { } { arrayDef._isEmpty = true; } while (!arrayDef._isEmpty) { if (tryNext == null) { throw new SyntaxException("Could not find next element in ArrayContentDef", parentInfo.GetErrorInfo()); } else if (tryNext is ScopeGroup) // { {...} } { ArrayContentDef contentDef = ArrayContentDef.Parse(moveInfo, parsingInfo, scriptInfo); arrayDef._content.Add(new StrIntIndex(arrayDef._contentIntsCount++), contentDef); tryNext = moveInfo.FindNextBlack(SearchDirection.LeftToRight); } else if (tryNext.IsTT(TokenType.Word) && tryAssign != null && tryAssign.IsTT(TokenType.Assign)) // { Name = "MyName" } { string strIndex = tryNext.ToString(); IElement strValue = null; IElement strValueTry = strIndexerInfo.FindNextBlack(SearchDirection.LeftToRight); // move behind "=" if (strValueTry == null) { throw new SyntaxException("Could not find value for strIndex in ArrayContentDef", parentInfo.GetErrorInfo()); } if (strValueTry is ScopeGroup) // { Name = {...} } { strValue = ArrayContentDef.Parse(strIndexerInfo, parsingInfo, scriptInfo); } else { strValue = Expression.Parse(strIndexerInfo, parsingInfo, scriptInfo); if (strValue == null) { throw new SyntaxException("Could not parse expression for strIndex in ArrayContentDef", parentInfo.GetErrorInfo()); } } StrIntIndex newIndex = new StrIntIndex(strIndex); StrIntIndex createdIndex = arrayDef._content.Keys.FirstOrDefault(a => a == newIndex); // index may have been already defined in this def.. if (createdIndex != null) { scriptInfo.SF.Errors.Add(new SemanticError("ArrayContentDef already contains key '" + strIndex + "'", new ErrorInfo(moveInfo.GetErrorInfo()))); } else { arrayDef._content.Add(newIndex, strValue); } tryNext = strIndexerInfo.FindNextBlack(SearchDirection.LeftToRight); moveInfo = strIndexerInfo; } else // { 1, "dawd", self GetGuid() } { Expression simpleExp = Expression.Parse(moveInfo, parsingInfo, scriptInfo); if (simpleExp == null) { throw new SyntaxException("Could not parse expression in ArrayContentDef", parentInfo.GetErrorInfo()); } arrayDef._content.Add(new StrIntIndex(arrayDef._contentIntsCount++), simpleExp); tryNext = moveInfo.FindNextBlack(SearchDirection.LeftToRight); } if (tryNext == null) // end of def { break; } else if (tryNext.IsTT(TokenType.Comma)) // new elem... { tryNext = moveInfo.FindNextBlack(SearchDirection.LeftToRight); // only for strIndex strIndexerInfo = new MoveInfo(moveInfo); tryAssign = strIndexerInfo.FindNextBlack(SearchDirection.LeftToRight); continue; } else // WTF?! { throw new SyntaxException("Unexpected token '" + tryNext.ToString() + "' in ArrayContentDef", parentInfo.GetErrorInfo()); } } arrayDef.AddChildren(group); parentInfo.Replace(1, arrayDef); return(arrayDef); }