public static bool Check(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo) { // local if (parentInfo.Current.IsTT(TokenType.Namespace)) { MoveInfo localInfo = new MoveInfo(parentInfo); IElement next = localInfo.FindNextBlack(SearchDirection.LeftToRight); if (next.IsTT(TokenType.Word)) { ParseLocal(parentInfo, parsingInfo, scriptInfo); return(true); } } // extern if (parentInfo.Current.IsTT(TokenType.Word)) { MoveInfo externInfo = new MoveInfo(parentInfo); Path.MoveToEnd(externInfo, SearchDirection.LeftToRight); IElement next = externInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible); if (next.IsTT(TokenType.Namespace)) { next = externInfo.FindNextBlack(SearchDirection.LeftToRight); if (next.IsTT(TokenType.Word)) { ParseExtern(parentInfo, parsingInfo, scriptInfo); return(true); } } } return(false); }
/// <summary> /// Vráti path a pridá ho do stromu /// Mal by fungovať oboma smermi. /// </summary> /// <param name="moveInfo"></param> /// <param name="dir"></param> /// <param name="startIndex"></param> /// <param name="length"></param> /// <returns></returns> public static Path Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo) // TODO: otestovať oboma smermi! { // TODO: funguješ správne? skontrolovať! MoveInfo moveInfo = new MoveInfo(parentInfo); IElement next = moveInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible); if (next == null) { return(null); } int startIndex = moveInfo.CurrentIndex; MoveToEnd(moveInfo, SearchDirection.LeftToRight); int length = moveInfo.CurrentIndex - startIndex; if (length == 0) { return(null); } Path path = new Path(parentInfo.CurrentElements.GetRange(startIndex, length)); parentInfo.MoveToIndex(startIndex); parentInfo.Replace(length, path); return(path); }
public static bool Check(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo) { if (parentInfo.Current is ParenthesesGroup) { ParenthesesGroup group = (ParenthesesGroup)parentInfo.Current; MoveInfo moveInfo = new MoveInfo(group, SearchTree.ContentBlock, 0, parentInfo); int i; for (i = 0; i < 2; i++) { IElement next = moveInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible, a => a.IsTT(TokenType.Comma)); if (next == null) { break; } moveInfo.Move(SearchDirection.LeftToRight); } if (i == 0) { return(false); } else if (i == 2) { Parse(parentInfo, parsingInfo, scriptInfo); return(true); } else { throw new SyntaxException("Only 3D vector is allowed", parentInfo.GetErrorInfo()); } } return(false); }
public static bool Check(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo) { if (parentInfo.Current.IsTT(TokenType.Word)) { // local function MoveInfo localInfo = new MoveInfo(parentInfo); IElement behindName = localInfo.FindNextBlack(SearchDirection.LeftToRight); if (behindName is ParenthesesGroup) { ParseLocal(parentInfo, parsingInfo, scriptInfo); return(true); } // extern function MoveInfo externInfo = new MoveInfo(parentInfo); Path.MoveToEnd(externInfo, SearchDirection.LeftToRight); IElement behindPath = externInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible); if (behindPath.IsTT(TokenType.Namespace)) { IElement name = externInfo.FindNextBlack(SearchDirection.LeftToRight); if (name.IsTT(TokenType.Word)) { IElement args = externInfo.FindNextBlack(SearchDirection.LeftToRight); if (args is ParenthesesGroup) { ParseExtern(parentInfo, parsingInfo, scriptInfo); return(true); } } } } return(false); }
private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo) { FuncArgs funcArgs = new FuncArgs(); ParenthesesGroup group = (ParenthesesGroup)parentInfo.Current; MoveInfo groupInfo = new MoveInfo(group, SearchTree.ContentBlock, 0, parentInfo); IElement next = groupInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible); while (next != null) { Expression exp = Expression.Parse(groupInfo, parsingInfo, scriptInfo); next = groupInfo.FindNextBlack(SearchDirection.LeftToRight); // jump behind funcArg if (exp == null || (next != null && !next.IsTT(TokenType.Comma))) { throw new SyntaxException("Could not parse funcArg", parentInfo.GetErrorInfo()); } if (next != null) { next = groupInfo.FindNextBlack(SearchDirection.LeftToRight); // jump behind , if (next == null) { throw new SyntaxException("Could not parse funcArg", parentInfo.GetErrorInfo()); } } CheckOutParam(parsingInfo, exp, parentInfo); if (parsingInfo.CurrentCall != null && parsingInfo.CurrentCallArgIndex != null) { if (parsingInfo.CurrentCall is FuncCall) { ((FuncCall)parsingInfo.CurrentCall).Arguments.Add(exp); parsingInfo.CurrentCallArgIndex++; } else if (parsingInfo.CurrentCall is DelegateCall) { ((DelegateCall)parsingInfo.CurrentCall).Arguments.Add(exp); parsingInfo.CurrentCallArgIndex++; } else { throw new ArgumentException("parsingInfo.CurrentCall"); } } } funcArgs.AddChildren(group); parentInfo.Replace(1, funcArgs); }
public static new bool Check(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo) { if (parentInfo.Current is SQBracketGroup) { MoveInfo groupInfo = new MoveInfo((SQBracketGroup)parentInfo.Current, SearchTree.ContentBlock, 0, parentInfo); IElement first = groupInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible); if (first is SQBracketGroup && groupInfo.FindNextBlack(SearchDirection.LeftToRight) == null) { Parse(parentInfo, parsingInfo, scriptInfo); return(true); } } return(false); }
private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo) { SQBracketGroup group = (SQBracketGroup)parentInfo.Current; MoveInfo moveInfo = new MoveInfo(group, SearchTree.ContentBlock, 0, parentInfo); if (moveInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible) != null) { throw new SyntaxException("Unknown tokens in ArrayDef", parentInfo.GetErrorInfo()); } ArrayDef arrayDef = new ArrayDef(); arrayDef.AddChildren(group); parentInfo.Replace(1, arrayDef); }
public static bool Check(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo) { IElement next = parentInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible); if (next == null) { return(false); } if (DevCode.Check(parentInfo, parsingInfo, scriptInfo) || PreProcessorRegion.Check(parentInfo, parsingInfo, scriptInfo)) { return(true); } if (EmptyStatement.Check(parentInfo, parsingInfo, scriptInfo) || BlockStatement.Check(parentInfo, parsingInfo, scriptInfo) ) { return(true); } if (IfElseStatement.Check(parentInfo, parsingInfo, scriptInfo) || SwitchStatement.Check(parentInfo, parsingInfo, scriptInfo) || WhileStatement.Check(parentInfo, parsingInfo, scriptInfo) || DoWhileStatement.Check(parentInfo, parsingInfo, scriptInfo) || ForStatement.Check(parentInfo, parsingInfo, scriptInfo) || ForEachStatement.Check(parentInfo, parsingInfo, scriptInfo) || ReturnStatement.Check(parentInfo, parsingInfo, scriptInfo) || BreakStatement.Check(parentInfo, parsingInfo, scriptInfo) || ContinueStatement.Check(parentInfo, parsingInfo, scriptInfo) || WaitStatement.Check(parentInfo, parsingInfo, scriptInfo) || WaittillFrameEndStatement.Check(parentInfo, parsingInfo, scriptInfo) ) { return(true); } if (ExpressionStatement.Check(parentInfo, parsingInfo, scriptInfo, true)) // nikdy nevráti false? { return(true); } return(false); }
/// <summary> /// Vytvorí grupu s obsahom [[ ]] a prepíše ju v strome. /// </summary> /// <param name="moveInfo"></param> /// <param name="dir"></param> /// <param name="startIndex"></param> /// <param name="length"></param> /// <returns></returns> private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo) { SQBracketGroup outerGroup = (SQBracketGroup)parentInfo.Current; List <IElement> outerGroupChildren = outerGroup.GetChildren(); MoveInfo outerGroupInfo = new MoveInfo(outerGroup, SearchTree.ContentBlock, 0, parentInfo); SQBracketGroup innerGroup = (SQBracketGroup)outerGroupInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible); List <IElement> innerGroupChildren = innerGroup.GetChildren(); int startElemsCount = outerGroupChildren.IndexOf(innerGroup) + 1; int endElemsCount = outerGroupChildren.Count - startElemsCount + 1; outerGroupInfo.Replace(1, innerGroupChildren); List <IElement> children = outerGroup.GetChildren(); DelegateCallGroup delegateCall = new DelegateCallGroup(children, startElemsCount, endElemsCount); parentInfo.Replace(1, delegateCall); }
public static FuncDefParam Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo) { FuncDefParam param = new FuncDefParam(); MoveInfo moveInfo = new MoveInfo(parentInfo); MoveInfo wordMoveInfo = moveInfo; IElement wordTry = moveInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible); int startIndex = moveInfo.CurrentIndex; if (wordTry == null) { throw new SyntaxException("Could not parse FuncDef param", parentInfo.GetErrorInfo()); } if (wordTry is SQBracketGroup) { param._group = (SQBracketGroup)wordTry; param.Optional = true; MoveInfo bracketInfo = new MoveInfo((SQBracketGroup)wordTry, SearchTree.ContentBlock, 0, moveInfo); wordTry = bracketInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible); wordMoveInfo = bracketInfo; } if (wordTry == null || !wordTry.IsTT(TokenType.Word)) { throw new SyntaxException("Could not parse FuncDef param", parentInfo.GetErrorInfo()); } VarName.Parse(wordMoveInfo, parsingInfo, scriptInfo); param.VarName = (VarName)wordMoveInfo.Current; param.Name = wordTry.ToString(); param.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, moveInfo.CurrentIndex - startIndex + 1)); parentInfo.Replace((moveInfo.CurrentIndex + 1) - startIndex, param); return(param); }
private static List <FuncDefParam> GetParameterList(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo) { MoveInfo moveInfo = new MoveInfo(parentInfo); string error = "Could not parse function parameters"; List <FuncDefParam> defParams = new List <FuncDefParam>(); bool? isSeparator = null; IElement curElem = moveInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible); while (curElem != null) { if (isSeparator == false || isSeparator == null) { FuncDefParam param = FuncDefParam.Parse(moveInfo, parsingInfo, scriptInfo); defParams.Add(param); isSeparator = true; } else { if (!curElem.IsTT(TokenType.Comma)) { throw new SyntaxException(error, parentInfo.GetErrorInfo()); } isSeparator = false; } curElem = moveInfo.FindNextBlack(SearchDirection.LeftToRight); } if (isSeparator == false) { throw new SyntaxException(error, parentInfo.GetErrorInfo()); } return(defParams); }
public static void ParseRegion(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo) { MoveInfo moveInfo = new MoveInfo(parentInfo); List <IElement> content = new List <IElement>(); content.Add(moveInfo.Current); content.Add(moveInfo.Move(SearchDirection.LeftToRight)); moveInfo.Move(SearchDirection.LeftToRight); int nameStart = moveInfo.CurrentIndex; IElement end = moveInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Unvisible, IsRegionEnd); if (end == null) { throw new SyntaxException("Bad region syntax", parentInfo.GetErrorInfo()); } content.AddRange(moveInfo.CurrentElements.GetRange(nameStart, moveInfo.CurrentIndex - nameStart)); IBlock region = new PreProcessorRegion(content); parentInfo.Replace(moveInfo.CurrentIndex - parentInfo.CurrentIndex, region); }
private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo) { ForStatement forStatement = new ForStatement(); MoveInfo moveInfo = new MoveInfo(parentInfo); // expGroup IElement tryExpGroup = moveInfo.FindNextBlack(SearchDirection.LeftToRight); if (tryExpGroup == null || !(tryExpGroup is ParenthesesGroup)) { throw new SyntaxException("Could not find for expressions", parentInfo.GetErrorInfo()); } ParenthesesGroup expGroup = (ParenthesesGroup)tryExpGroup; MoveInfo expGroupInfo = new MoveInfo(expGroup, SearchTree.ContentBlock, 0, parentInfo); // initializer IElement tryInitializer = expGroupInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible); if (tryInitializer == null) { throw new SyntaxException("Could not parse for initializer", parentInfo.GetErrorInfo()); } if (!tryInitializer.IsTT(TokenType.SemiColon)) { if (!ExpressionStatement.Check(expGroupInfo, parsingInfo, scriptInfo, false)) { throw new SyntaxException("Could not parse for initializer", parentInfo.GetErrorInfo()); } expGroupInfo.FindNextBlack(SearchDirection.LeftToRight); } if (expGroupInfo.Current == null || !expGroupInfo.Current.IsTT(TokenType.SemiColon)) { throw new SyntaxException("Missing for first directive ';'?", parentInfo.GetErrorInfo()); } // expression IElement tryExpression = expGroupInfo.FindNextBlack(SearchDirection.LeftToRight); if (tryExpression == null) { throw new SyntaxException("Could not parse for expression", parentInfo.GetErrorInfo()); } if (!tryExpression.IsTT(TokenType.SemiColon)) { Expression exp = Expression.Parse(expGroupInfo, parsingInfo, scriptInfo); if (exp == null) { throw new SyntaxException("Could not parse for expression", parentInfo.GetErrorInfo()); } expGroupInfo.FindNextBlack(SearchDirection.LeftToRight); } if (expGroupInfo.Current == null || !expGroupInfo.Current.IsTT(TokenType.SemiColon)) { throw new SyntaxException("Missing for second directive ';'?", parentInfo.GetErrorInfo()); } // iterator IElement tryIterator = expGroupInfo.FindNextBlack(SearchDirection.LeftToRight); if (tryIterator != null) { if (!ExpressionStatement.Check(expGroupInfo, parsingInfo, scriptInfo, false)) { throw new SyntaxException("Could not parse for iterator", parentInfo.GetErrorInfo()); } IElement end = expGroupInfo.FindNextBlack(SearchDirection.LeftToRight); if (end != null) { throw new SyntaxException("Could not parse for iterator", parentInfo.GetErrorInfo()); } } // statement moveInfo.FindNextBlack(SearchDirection.LeftToRight); if (!Statement.Check(moveInfo, parsingInfo, scriptInfo)) { throw new SyntaxException("Could not parse for statement", parentInfo.GetErrorInfo()); } // build int startIndex = parentInfo.CurrentIndex; int length = (moveInfo.CurrentIndex + 1) - startIndex; forStatement.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length)); parentInfo.Replace(length, forStatement); }
public static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo) { FuncDef function = new FuncDef(parentInfo.Current.CharIndex, parentInfo.Current.CharLength, parentInfo.Current.LineIndex, parsingInfo.SF); // začiatok názvu MoveInfo moveInfo = new MoveInfo(parentInfo); int startIndex = parentInfo.CurrentIndex; // modifier MemberAccess access; AccessModifier modifier = AccessModifier.GetModifier(moveInfo, out access); if (modifier != null) { startIndex = moveInfo.CurrentIndex; } else { moveInfo = new MoveInfo(parentInfo); } // xml XMLBlock xml = XMLBlock.GetXMLSummary(moveInfo); function.xmlBlock = xml; if (xml != null) { startIndex = moveInfo.CurrentIndex; } // začiatok názvu moveInfo = new MoveInfo(parentInfo); IElement nameElem = moveInfo.Current; moveInfo.Move(SearchDirection.LeftToRight); // parametry IElement paramsTry = moveInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible); if (!(paramsTry is ParenthesesGroup)) { throw new SyntaxException("Could not find FuncDef parameters", parentInfo.GetErrorInfo()); } ParenthesesGroup paramsGroup = (ParenthesesGroup)paramsTry; // získaj zoznam parametrov MoveInfo paramsMoveInfo = new MoveInfo(paramsGroup, SearchTree.ContentBlock, 0, moveInfo); List <FuncDefParam> defParams = GetParameterList(paramsMoveInfo, parsingInfo, scriptInfo); // pridaj zoznam parametrov do stromu a posuň sa zaň moveInfo.Move(SearchDirection.LeftToRight); // body IElement bodyTry = moveInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible); if (!(bodyTry is ScopeGroup)) { throw new SyntaxException("Could not find FuncDef body", parentInfo.GetErrorInfo()); } ScopeGroup bodyGroup = (ScopeGroup)bodyTry; List <IElement> bodyGroupChildren = bodyGroup.GetChildren(); moveInfo.Move(SearchDirection.LeftToRight); // skoč za telo // add func to tree int totalLength = moveInfo.CurrentIndex - startIndex; List <IElement> children = parentInfo.CurrentElements.GetRange(startIndex, totalLength); function.AddChildren(children); foreach (FuncDefParam p in defParams) { function.LocalVars.Add(new LocalVarInfo(parsingInfo.SF, p.Name, (int)function.ImportantCharIndex, (int)function.ImportantCharLength, null, p.VarName)); // it must be after function.AddChildren() !! } parentInfo.MoveToIndex(startIndex); parentInfo.Replace(totalLength, function); // set current function parsingInfo.CurrentFunc = function; parsingInfo.FuncDefList.Add(function); // go inside body MoveInfo bodyInfo = new MoveInfo(bodyGroup, SearchTree.ContentBlock, 0, parentInfo); Statement.ParseStatementList(bodyInfo, parsingInfo, scriptInfo); // info string name = nameElem.ToString(); /*if (scriptInfo.) * if (scriptInfo.Functions.FindIndex(a => a.Name.EqualCode(name)) != -1) * { * ErrorManager.Semantic("Function '" + name + "' already defined", new ErrorInfo(parentInfo.ErrorInfo)); * return; * }*/ FuncInfo funcInfo = GetInfo(name, access, defParams, xml, parsingInfo, function); scriptInfo.AddFunction(funcInfo); function.funcInfo = funcInfo; }
public static Expression Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo, bool isExpStatement, bool isArrayContentDefEnabled, bool isArrayDefEnabled) { Expression expression = new Expression(); IElement next = parentInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible); if (next == null) { return(null); } MoveInfo moveInfo = new MoveInfo(parentInfo); int startIndex = moveInfo.CurrentIndex; //int lastIndex = startIndex; //int curLength; bool isNextOperand = true; bool isNextNeeded = true; bool isSingleOperand; IElement cur = moveInfo.Current; while (cur != null) { //if (cur.IsTT(TokenType.SemiColon)) //break; if (!ExpressionMember.Check(moveInfo, parsingInfo, scriptInfo, ref isNextOperand, ref isNextNeeded, out isSingleOperand, isExpStatement, isArrayContentDefEnabled, isArrayDefEnabled)) { break; } // pridá súčasný elem + predchádzajúce medzery //curLength = (moveInfo.CurrentIndex + 1) - lastIndex; //expression.AddChildren(parentInfo.CurrentElements.GetRange(lastIndex, curLength)); //lastIndex = moveInfo.CurrentIndex + 1; cur = moveInfo.FindNextBlack(SearchDirection.LeftToRight); if (isSingleOperand) { // TODO: fixnúť! ..nejak... //if (found > 1) //throw new SyntaxException("Could not parse expression", parentInfo.ErrorInfo); break; } } int length = moveInfo.CurrentIndex - startIndex; if (length == 0) { return(null); } expression.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length)); parentInfo.Replace(length, expression); return(expression); }
private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo) { ForEachStatement foreachStatement = new ForEachStatement(); MoveInfo moveInfo = new MoveInfo(parentInfo); foreachStatement._foreachKeyword = (Token)moveInfo.Current; // expression IElement expGroupTry = moveInfo.FindNextBlack(SearchDirection.LeftToRight); if (expGroupTry == null || !(expGroupTry is ParenthesesGroup)) { throw new SyntaxException("Could not find foreach expression", parentInfo.GetErrorInfo()); } ParenthesesGroup expGroup = (ParenthesesGroup)expGroupTry; MoveInfo expGroupInfo = new MoveInfo(expGroup, SearchTree.ContentBlock, 0, parentInfo); foreachStatement._foreachGroup = expGroup; // var define IElement tryVar = expGroupInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible); if (tryVar == null || !tryVar.IsTT(TokenType.Word)) { throw new SyntaxException("Could not parse foreach var", parentInfo.GetErrorInfo()); } VarName.Parse(expGroupInfo, parsingInfo, scriptInfo); VarName varName = (VarName)expGroupInfo.Current; LocalVarInfo localVar = parsingInfo.CurrentFunc.LocalVars.Find(a => a.Name.EqualCode(tryVar.ToString())); // there is already var with this name... if (localVar == null) { parsingInfo.CurrentFunc.LocalVars.Add(new LocalVarInfo(scriptInfo.SF, tryVar.ToString(), tryVar.CharIndex, tryVar.CharLength, null, varName)); } foreachStatement._currentVar = varName; // in keyword IElement tryIn = expGroupInfo.FindNextBlack(SearchDirection.LeftToRight); if (tryIn == null || !tryIn.IsTT(TokenType.Word) || !tryIn.ToString().EqualCode("in")) { throw new SyntaxException("Could not find foreach 'in'", parentInfo.GetErrorInfo()); } // array IElement tryArray = expGroupInfo.FindNextBlack(SearchDirection.LeftToRight); Expression tryArrayExp = Expression.Parse(expGroupInfo, parsingInfo, scriptInfo); if (tryArrayExp == null || expGroupInfo.FindNextBlack(SearchDirection.LeftToRight) != null) { throw new SyntaxException("Could not parse foreach array", parentInfo.GetErrorInfo()); } foreachStatement._array = tryArrayExp; // statement moveInfo.FindNextBlack(SearchDirection.LeftToRight); if (!Statement.Check(moveInfo, parsingInfo, scriptInfo)) { throw new SyntaxException("Could not parse foreach statement", parentInfo.GetErrorInfo()); } foreachStatement._statement = (Statement)moveInfo.Current; // build int startIndex = parentInfo.CurrentIndex; int length = (moveInfo.CurrentIndex + 1) - startIndex; foreachStatement.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length)); parentInfo.Replace(length, foreachStatement); }
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); }
private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo) { SwitchStatement switchStatement = new SwitchStatement(); MoveInfo moveInfo = new MoveInfo(parentInfo); // expression IElement tryExpGroup = moveInfo.FindNextBlack(SearchDirection.LeftToRight); if (!(tryExpGroup is ParenthesesGroup)) { throw new SyntaxException("Could not find switch expression", parentInfo.GetErrorInfo()); } ParenthesesGroup expGroup = (ParenthesesGroup)tryExpGroup; MoveInfo expGroupInfo = new MoveInfo(expGroup, SearchTree.ContentBlock, 0, parentInfo); Expression exp = Expression.Parse(expGroupInfo, parsingInfo, scriptInfo); if (exp == null || expGroupInfo.FindNextBlack(SearchDirection.LeftToRight) != null) { throw new SyntaxException("Could not parse switch expression", parentInfo.GetErrorInfo()); } // scope group IElement tryScopeGroup = moveInfo.FindNextBlack(SearchDirection.LeftToRight); if (!(tryScopeGroup is ScopeGroup)) { throw new SyntaxException("Could not find switch ScopeGroup", parentInfo.GetErrorInfo()); } ScopeGroup scopeGroup = (ScopeGroup)tryScopeGroup; MoveInfo scopeGroupInfo = new MoveInfo(scopeGroup, SearchTree.ContentBlock, 0, parentInfo); IElement nextCase = scopeGroupInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible); if (nextCase == null) { throw new SyntaxException("Could not find any switch case", parentInfo.GetErrorInfo()); } while (nextCase != null) { if (!( DefaultSwitchStatement.Check(scopeGroupInfo, parsingInfo, scriptInfo, true) || CaseSwitchStatement.Check(scopeGroupInfo, parsingInfo, scriptInfo, true) )) { throw new SyntaxException("Could not parse switch case/default", parentInfo.GetErrorInfo()); } nextCase = scopeGroupInfo.FindNextBlack(SearchDirection.LeftToRight); } // build int startIndex = parentInfo.CurrentIndex; int length = (moveInfo.CurrentIndex + 1) - startIndex; switchStatement.AddChildren(parentInfo.CurrentElements.GetRange(startIndex, length)); parentInfo.Replace(length, switchStatement); }
private static void Parse(MoveInfo parentInfo, ParsingInfo parsingInfo, ScriptInfo scriptInfo) { PreProcessorInclude include = new PreProcessorInclude(); int startIndex = parentInfo.CurrentIndex; MoveInfo moveInfo = new MoveInfo(parentInfo); moveInfo.Move(SearchDirection.LeftToRight); // "include" moveInfo.Move(SearchDirection.LeftToRight); // after "include" moveInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible); Path path = Path.Parse(moveInfo, parsingInfo, scriptInfo); if (path == null) { throw new SyntaxException("Bad path", parentInfo.GetErrorInfo()); } include.Path = path; moveInfo.Move(SearchDirection.LeftToRight); IElement terminal = moveInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible); if (terminal == null || !terminal.IsTT(TokenType.SemiColon)) { throw new SyntaxException("Could not find ;", parentInfo.GetErrorInfo()); } int length = (moveInfo.CurrentIndex + 1) - startIndex; List <IElement> children = parentInfo.CurrentElements.GetRange(startIndex, length); include.AddChildren(children); parentInfo.Replace(length, include); // include file string SFPath = path.ToString(); if (scriptInfo.Includes.Find(a => a.SFPath.EqualCode(SFPath)) != null) { scriptInfo.SF.Errors.Add( new SemanticError("File '" + SFPath + "' already included", parentInfo.GetErrorInfo(include))); } ScriptFile includeFile = scriptInfo.SF.Manager.GetSF(SFPath); if (includeFile != null) { IncludeInfo includeInfo = new IncludeInfo(includeFile); scriptInfo.AddInclude(includeInfo); parsingInfo.IncludeDefList.Add(include); } else { scriptInfo.SF.Errors.Add( new SemanticError("Could not include file '" + SFPath + "'", parentInfo.GetErrorInfo(include))); } }