Пример #1
0
        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));
        }
Пример #2
0
        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));
        }
Пример #3
0
        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);
        }
Пример #4
0
        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));
        }
Пример #5
0
        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
                       ));
        }
Пример #6
0
        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));
        }
Пример #7
0
        public Statement Parse(ScriptParser parser, ScriptToken token, out bool trailingSemicolon)
        {
            trailingSemicolon = true;

            var value = parser.ParseExpression();

            return(new ThrowStatement(token, value));
        }
Пример #8
0
 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;
 }
Пример #9
0
        public Expression Parse(ScriptParser parser, Expression left, ScriptToken token)
        {
            var index = parser.ParseExpression();

            parser.Take(ScriptTokenType.RightSquare);

            return(new IndexerExpression(parser.Previous, left, index));
        }
Пример #10
0
        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)));
        }
Пример #11
0
        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);
                }
            }
        }
Пример #12
0
 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;
 }
Пример #13
0
        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);
        }
Пример #14
0
        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));
        }
Пример #15
0
        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;
        }
Пример #16
0
        protected Expression(ScriptToken start, ScriptToken end = null)
        {
            if (start == null)
            {
                throw new ArgumentNullException("start");
            }

            Start = start;
            End   = end ?? start;
        }
Пример #17
0
        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();
        }
Пример #18
0
        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;
        }
Пример #19
0
        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();
        }
Пример #20
0
        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));
        }
Пример #21
0
 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;
 }
Пример #22
0
        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));
        }
Пример #23
0
        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));
        }
Пример #24
0
        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));
        }
Пример #25
0
        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));
        }
Пример #26
0
        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)
                       ));
        }
Пример #27
0
        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));
        }
Пример #28
0
        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);
        }
Пример #29
0
        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
                       ));
        }