public Declaration Parse(ScriptParser parser, ScriptToken token) { var returnType = parser.ParseType(token); var name = parser.Take(ScriptTokenType.Identifier).Contents; if (parser.MatchAndTake(ScriptTokenType.Assign)) { var value = parser.ParseExpression(); parser.Take(ScriptTokenType.Semicolon); return(new FieldDeclaration(token, parser.Previous, returnType, name, value, false, false)); } parser.Take(ScriptTokenType.LeftParen); var parameters = parser.ParseSeparatedBy(ScriptTokenType.Comma, (_, first) => { if (parser.Match(ScriptTokenType.RightParen)) { return(null); } ScriptType paramType; string paramName; parser.ParseNamedType(out paramType, out paramName); return(new MethodDeclaration.Parameter(paramType, paramName)); }).ToList(); parser.Take(ScriptTokenType.RightParen); var block = parser.ParseBlock(false); return(new MethodDeclaration(token, parser.Previous, returnType, name, parameters, block)); }
public Declaration Parse(ScriptParser parser, ScriptToken token) { var done = false; var tokens = parser.ParseSeparatedBy(ScriptTokenType.Dot, (_, first) => { if (done) { return(null); } if (parser.Match(ScriptTokenType.Multiply)) { done = true; return(parser.Take(ScriptTokenType.Multiply)); } return(parser.Take(ScriptTokenType.Identifier)); }); var name = string.Join(".", tokens.Select(t => t.Contents)); if (!parser.MatchAndTake(ScriptTokenType.Semicolon)) { Console.WriteLine("JFjngkjasnholjhnaskl"); } return(new IncludeDeclaration(token, parser.Previous, name)); }
private ScriptToken FindTokenInScript(Script script, string structName, string memberName) { ScriptToken found = null; if (structName != null) { ScriptStruct struc = script.AutoCompleteData.FindStruct(structName); if (struc != null) { found = struc.FindMemberFunction(memberName); if (found == null) { found = struc.FindMemberVariable(memberName); } } else { found = script.AutoCompleteData.FindFunction(_goToDefinition.Replace(".", "::")); } } else { found = script.AutoCompleteData.FindFunction(memberName); if (found == null) { found = script.AutoCompleteData.FindVariable(memberName); } if (found == null) { found = script.AutoCompleteData.FindStruct(memberName); } } return(found); }
public static IfStatementNode Parse(AstTreeNode lastNode, ScriptToken scriptToken, List <ScriptToken> tokens) { if (tokens[1].Type != EScriptTokenType.L_PAREN) { Console.WriteLine("If statement needs to be followed by a condition encased in parenthesis."); return(null); } List <ConditionalNode> nodes = new List <ConditionalNode>(); nodes.Add(ParseConditional(tokens)); while (tokens.Count > 0 && EScriptTokenType.ELSE_IF == tokens[0].Type) { nodes.Add(ParseConditional(tokens)); } if (tokens.Count > 0 && EScriptTokenType.ELSE == tokens[0].Type) { tokens.RemoveAt(0); // Consume else nodes.Add(new ConditionalNode( new LiteralNode <bool>(true), ScriptTree.ProcessTokens(ScriptTree.GetBlockTokens(tokens, EBlockType.BRACE, false)[0]) )); } return(new IfStatementNode(nodes)); }
public static ForStatementNode Parse(AstTreeNode lastNode, ScriptToken scriptToken, List <ScriptToken> tokens) { if (tokens[1].Type != EScriptTokenType.L_PAREN) { Console.WriteLine("Syntax error: Missing ('"); return(null); } if (tokens[3].Type != EScriptTokenType.OF) { Console.WriteLine("Syntax error: Missing of"); return(null); } tokens.RemoveAt(0); // consume for List <ScriptToken> loopDef = ScriptTree.GetEnclosedTokens(tokens); ScriptToken variableName = loopDef[0]; loopDef.RemoveAt(0); // consume variable name loopDef.RemoveAt(0); // consume of AstTreeNode list = ScriptTree.ProcessTokens(loopDef); AstTreeNode block = ScriptTree.ProcessTokens(ScriptTree.GetBlockTokens(tokens, EBlockType.BRACE, false)[0]); return(new ForStatementNode( new LiteralNode <string>(variableName.Value), list, block )); }
public Statement Parse(ScriptParser parser, ScriptToken token, out bool trailingSemicolon) { trailingSemicolon = true; var baseType = parser.ParseType(token); var definitions = parser.ParseSeparatedBy(ScriptTokenType.Comma, (_, first) => { var name = parser.Take(ScriptTokenType.Identifier).Contents; var arrayDims = 0; while (parser.MatchAndTake(ScriptTokenType.LeftSquare)) { parser.Take(ScriptTokenType.RightSquare); arrayDims++; } var type = baseType; if (arrayDims > 0) { type = new ScriptType(baseType.Name, baseType.ArrayDimensions + arrayDims, baseType.IsResizable); } Expression value = null; if (parser.MatchAndTake(ScriptTokenType.Assign)) { value = parser.ParseExpression(); } return(new VariableStatement.Definition(type, name, value)); }).ToList(); return(new VariableStatement(token, parser.Previous, baseType, false, definitions)); }
public Statement Parse(ScriptParser parser, ScriptToken token, out bool trailingSemicolon) { trailingSemicolon = true; var value = parser.ParseExpression(); return(new ThrowStatement(token, value)); }
public NewExpression(ScriptToken start, ScriptToken end, string type, int arrayDimensions, List <Expression> parameters, List <Expression> initializer = null) : base(start, end) { Type = type; ArrayDimensions = arrayDimensions; Parameters = parameters.AsReadOnly(); Initializer = initializer != null?initializer.AsReadOnly() : null; }
public Expression Parse(ScriptParser parser, Expression left, ScriptToken token) { var index = parser.ParseExpression(); parser.Take(ScriptTokenType.RightSquare); return(new IndexerExpression(parser.Previous, left, index)); }
public Expression Parse(ScriptParser parser, ScriptToken token) { var str = parser.Take(ScriptTokenType.String); var crc = (int)StringtoCrc(str.Contents); var crcStr = "0x" + crc.ToString("X8"); return(new NumberExpression(new ScriptToken(str, ScriptTokenType.Number, crcStr))); }
private void GoToDefinition(string structName, string memberName) { ScriptToken found = null; Script foundInScript = null; List <Script> scriptsToSearch = new List <Script>(); scriptsToSearch.AddRange(_agsEditor.GetAllScriptHeaders()); scriptsToSearch.Add(_script); foreach (Script script in scriptsToSearch) { found = FindTokenInScript(script, structName, memberName); foundInScript = script; if ((found != null) && (script.IsHeader)) { // Always prefer the definition in the main script to // the import in the header Script mainScript = _agsEditor.CurrentGame.Scripts.FindMatchingScriptOrHeader(script); if (!mainScript.AutoCompleteData.Populated) { AutoComplete.ConstructCache(mainScript); } ScriptToken foundInScriptBody = FindTokenInScript(mainScript, structName, memberName); if (foundInScriptBody != null) { found = foundInScriptBody; foundInScript = mainScript; } } if (found != null) { break; } } if ((found == null) && (structName == null)) { found = FindTokenAsLocalVariable(memberName, false); } if (found != null) { if (foundInScript.FileName == AGSEditor.BUILT_IN_HEADER_FILE_NAME) { Factory.GUIController.LaunchHelpForKeyword(_goToDefinition); } else if (foundInScript.FileName == Tasks.AUTO_GENERATED_HEADER_NAME) { Factory.GUIController.ShowMessage("This variable is internally defined by AGS and probably corresponds to an in-game entity such as a Character or Inventory Item.", MessageBoxIcon.Information); } else { Factory.GUIController.ZoomToFile(foundInScript.FileName, ZoomToFileZoomType.ZoomToCharacterPosition, found.StartsAtCharacterIndex); } } }
public FieldDeclaration(ScriptToken start, ScriptToken end, ScriptType type, string name, Expression value, bool isConst, bool isPublic) : base(start, end) { Type = type; Name = name; Value = value; IsConstant = isConst; IsPublic = isPublic; }
public ScriptToken Tokenize(string line) { ScriptToken st = new ScriptToken(); if (!Validator(line) || !preExract.IsMatch(line)) { throw new FormatException(); } MatchCollection mc = preExract.Matches(line); st.Command = mc[0].Groups[1].Value; string[] _cmd = st.Command.Split('.'); if (_cmd.Length <= 1) { st.Command = _cmd[0]; } else { st.Prefix = _cmd[0]; st.Command = _cmd[1]; } if (mc.Count > 2) { st.TailFix = mc[2].Groups[1].Value.AvailableEx() ? ScriptUtil.SanitaizeParameter(mc[2].Groups[1].Value) : "COUNT"; } List <string> args = new List <string>(); foreach (Match m in argExract.Matches(mc[1].Groups[1].Value)) { args.Add(ScriptUtil.SanitaizeParameter(m.Groups[0].Value)); } args.RemoveAll((x) => { return(x == "" || x == "\""); }); st.Args = args.ToArray(); args.Clear(); if (mc.Count > 3) { foreach (Match m in argExract.Matches(mc[3].Groups[1].Value)) { args.Add(ScriptUtil.SanitaizeParameter(m.Groups[0].Value)); } } else { st.TailFix = "COUNT"; args.Add("1"); } st.TailArgs = args.ToArray(); args.Clear(); return(st); }
public Expression Parse(ScriptParser parser, ScriptToken token) { var type = string.Join(".", parser.ParseSeparatedBy(ScriptTokenType.Dot, (_, first) => parser.Take(ScriptTokenType.Identifier).Contents)); if (type == "string") { type = "String"; } var isArray = parser.Match(ScriptTokenType.LeftSquare); parser.Take(isArray ? ScriptTokenType.LeftSquare : ScriptTokenType.LeftParen); var parameters = parser.ParseSeparatedBy(ScriptTokenType.Comma, (_, first) => { if (first && parser.Match(isArray ? ScriptTokenType.RightSquare : ScriptTokenType.RightParen)) { return(null); } return(parser.ParseExpression()); }).ToList(); parser.Take(isArray ? ScriptTokenType.RightSquare : ScriptTokenType.RightParen); List <Expression> values = null; if (isArray && parser.MatchAndTake(ScriptTokenType.LeftBrace)) { values = parser.ParseSeparatedBy(ScriptTokenType.Comma, (_, first) => { if (parser.Match(ScriptTokenType.RightBrace)) { return(null); } return(parser.ParseExpression()); }).ToList(); parser.MatchAndTake(ScriptTokenType.RightBrace); } int arrayDimensions = isArray ? 1 : 0; if (isArray) { while (parser.Match(ScriptTokenType.LeftSquare) && parser.Match(ScriptTokenType.RightSquare, 1)) { parser.Take(ScriptTokenType.LeftSquare); parser.Take(ScriptTokenType.RightSquare); arrayDimensions++; } } return(new NewExpression(token, parser.Previous, type, arrayDimensions, parameters, values)); }
public ForStatement(ScriptToken start, ScriptToken end, List <Statement> initializers, Expression condition, List <Expression> increment, BlockStatement block) : base(start, end) { Initializers = initializers != null?initializers.AsReadOnly() : null; Condition = condition; Increment = increment != null?increment.AsReadOnly() : null; Block = block; }
protected Expression(ScriptToken start, ScriptToken end = null) { if (start == null) { throw new ArgumentNullException("start"); } Start = start; End = end ?? start; }
public TryStatement(ScriptToken start, ScriptToken end, BlockStatement block, List <Branch> branches) : base(start, end) { if (branches.Count < 1) { throw new ArgumentException("need at least 1 branch", "branches"); } Block = block; Branches = branches.AsReadOnly(); }
public BlockStatement(ScriptToken start, ScriptToken end, List <Statement> statements, bool isSwitch = false) : base(start, end) { if (statements == null) { throw new ArgumentNullException("statements"); } Statements = statements.AsReadOnly(); IsSwitch = isSwitch; }
public VariableStatement(ScriptToken start, ScriptToken end, ScriptType baseType, bool final, List <Definition> definitions) : base(start, end) { if (definitions.Count < 1) { throw new ArgumentException("need at least 1 definition", "definitions"); } BaseType = baseType; Final = final; Definitions = definitions.AsReadOnly(); }
public Statement Parse(ScriptParser parser, ScriptToken token, out bool trailingSemicolon) { trailingSemicolon = true; if (parser.Match(ScriptTokenType.Semicolon)) { return(new ReturnStatement(token, parser.Previous, null)); } var value = parser.ParseExpression(); return(new ReturnStatement(token, parser.Previous, value)); }
public ScriptToken FindTokenAsLocalVariable(string memberName, bool searchWholeFunction) { ScriptToken found = null; List<ScriptVariable> localVars = scintilla.GetListOfLocalVariablesForCurrentPosition(searchWholeFunction); foreach (ScriptVariable localVar in localVars) { if (localVar.VariableName == memberName) { found = localVar; } } return found; }
public Statement Parse(ScriptParser parser, ScriptToken token, out bool trailingSemicolon) { trailingSemicolon = false; parser.Take(ScriptTokenType.LeftParen); var condition = parser.ParseExpression(); parser.Take(ScriptTokenType.RightParen); var block = parser.ParseBlock(); return(new WhileStatement(token, parser.Previous, condition, block)); }
public Declaration Parse(ScriptParser parser, ScriptToken token) { var tokens = parser.ParseSeparatedBy(ScriptTokenType.Dot, (_, first) => parser.Take(ScriptTokenType.Identifier)); var name = string.Join(".", tokens.Select(t => t.Contents)); if (!parser.MatchAndTake(ScriptTokenType.Semicolon)) { Console.WriteLine("fkshgnbkashnkhnasb"); } return(new InheritsDeclaration(token, parser.Previous, name)); }
public Expression Parse(ScriptParser parser, ScriptToken token) { var values = parser.ParseSeparatedBy(ScriptTokenType.Comma, (_, first) => { if (parser.Match(ScriptTokenType.RightBrace)) { return(null); } return(parser.ParseExpression()); }).ToList(); parser.Take(ScriptTokenType.RightBrace); return(new ArrayInitializerExpression(token, parser.Previous, values)); }
public Statement Parse(ScriptParser parser, ScriptToken token, out bool trailingSemicolon) { trailingSemicolon = false; var statements = new List <Statement>(); while (!parser.Match(ScriptTokenType.RightBrace)) { statements.Add(parser.ParseStatement()); } parser.Take(ScriptTokenType.RightBrace); return(new BlockStatement(token, parser.Previous, statements)); }
public static AssignmentNode Parse(AstTreeNode lastNode, ScriptToken scriptToken, List <ScriptToken> tokens) { if (!(lastNode is IScopeMemberNode)) { Console.WriteLine("Invalid assignment syntax."); return(null); } tokens.RemoveAt(0); // consume = List <ScriptToken> assignmentTokens = ScriptTree.GetStatementTokens(tokens, false); return(new AssignmentNode( (IScopeMemberNode)lastNode, ScriptTree.ProcessTokens(assignmentTokens) )); }
public Declaration Parse(ScriptParser parser, ScriptToken token) { ScriptType type; string name; parser.ParseNamedType(out type, out name); parser.Take(ScriptTokenType.Assign); var value = parser.ParseExpression(); parser.Take(ScriptTokenType.Semicolon); return(new FieldDeclaration(token, parser.Previous, type, name, value, true, true)); }
public Expression Parse(ScriptParser parser, ScriptToken token) { if (IsCast(parser)) { var type = parser.ParseType(); parser.Take(ScriptTokenType.RightParen); var value = parser.ParseExpression((int)PrecedenceValue.Cast - 1); return(new CastExpression(token, type, value)); } var expression = parser.ParseExpression(); parser.Take(ScriptTokenType.RightParen); return(expression); }
private ActionToken _interpret(ScriptToken token) { ActionToken at = new ActionToken(); at.CommandType = (int)Cmd2DefinedCmd(token.Command); at.ct_args = ConvertArgs(at.CommandType, ParameterPattern[at.CommandType], token.Args, token.Command); at.SuffixType = (int)Suf2DefinedSuf(token.TailFix); at.st_args = ConvertArgs(at.SuffixType, ParameterPattern[at.SuffixType], token.TailArgs, token.Command); if (at.ct_args == null || at.st_args == null) { return(null); } return(at); }
public static ArithmeticAssignmentNode Parse(AstTreeNode lastNode, ScriptToken scriptToken, List <ScriptToken> tokens) { if (lastNode == null || !(lastNode is IScopeMemberNode)) { Console.WriteLine("Invalid assignment syntax."); return(null); } tokens.RemoveAt(0); // consume += List <ScriptToken> assignmentTokens = ScriptTree.GetEnclosedTokens(tokens); return(new ArithmeticAssignmentNode( (IScopeMemberNode)Convert.ChangeType(lastNode, lastNode is RootScopeMemberNode ? typeof(RootScopeMemberNode) : typeof(ScopeMemberNode)), ScriptTree.ProcessTokens(assignmentTokens), scriptToken.Type )); }