Exemplo n.º 1
0
        public override Node VisitRuleset(DeltinScriptParser.RulesetContext context)
        {
            RuleNode[] rules = new RuleNode[context.ow_rule().Length];
            for (int i = 0; i < rules.Length; i++)
            {
                rules[i] = (RuleNode)VisitOw_rule(context.ow_rule()[i]);
            }

            Variable useGlobalVar;
            Variable usePlayerVar;

            Enum.TryParse <Variable>(context.useGlobalVar()?.PART().GetText(), out useGlobalVar);
            Enum.TryParse <Variable>(context.usePlayerVar()?.PART().GetText(), out usePlayerVar);

            DefinedNode[] definedVars = new DefinedNode[context.vardefine().Length];
            for (int i = 0; i < definedVars.Length; i++)
            {
                definedVars[i] = (DefinedNode)VisitVardefine(context.vardefine()[i]);
            }

            UserMethodNode[] userMethods = new UserMethodNode[context.user_method().Length];
            for (int i = 0; i < userMethods.Length; i++)
            {
                userMethods[i] = (UserMethodNode)VisitUser_method(context.user_method()[i]);
            }

            Node node = new RulesetNode(rules, useGlobalVar, usePlayerVar, definedVars, userMethods, Range.GetRange(context));

            CheckRange(node);
            return(node);
        }
Exemplo n.º 2
0
        public UserMethod(UserMethodNode node)
        {
            Name  = node.Name;
            Block = node.Block;

            Parameters = new Parameter[node.Parameters.Length];
            for (int i = 0; i < Parameters.Length; i++)
            {
                Parameters[i] = new Parameter(node.Parameters[i], Elements.ValueType.Any, null);
            }

            //UserMethodCollection.Add(this);
        }
        public UserMethod(ScopeGroup scope, UserMethodNode node)
        {
            Name           = node.Name;
            TypeString     = node.Type;
            Block          = node.Block;
            ParameterNodes = node.Parameters;
            IsRecursive    = node.IsRecursive;
            Documentation  = node.Documentation;
            Wiki           = new WikiMethod(Name, Documentation, null);
            AccessLevel    = node.AccessLevel;
            Node           = node;

            scope.In(this);
        }
Exemplo n.º 4
0
        public override Node VisitUser_method(DeltinScriptParser.User_methodContext context)
        {
            string name = context.PART(0).GetText();

            string[] parameters = new string[context.PART().Length - 1];
            for (int i = 0; i < parameters.Length; i++)
            {
                parameters[i] = context.PART(i + 1).GetText();
            }

            BlockNode block = (BlockNode)VisitBlock(context.block());

            Node node = new UserMethodNode(name, parameters, block, Range.GetRange(context));

            CheckRange(node);
            return(node);
        }
        public UserMethodBlock(ScopeGroup scope, UserMethodNode node) : base(scope, node)
        {
            List <ReturnNode> returnNodes = new List <ReturnNode>();

            ReturnNodes(node.Block, returnNodes);
            DoesReturn = node.Type != null || returnNodes.Any(returnNode => returnNode.Value != null);
            if (DoesReturn)
            {
                foreach (var returnNode in returnNodes)
                {
                    if (returnNode.Value == null)
                    {
                        throw new SyntaxErrorException("A return value is required.", returnNode.Location);
                    }
                }
                CheckContainer((IBlockContainer)node);
            }

            Block       = node.Block;
            IsRecursive = node.IsRecursive;
            TypeString  = node.Type;
        }
Exemplo n.º 6
0
        public RulesetNode(DeltinScriptParser.RulesetContext context, BuildAstVisitor visitor) : base(new Location(visitor.file, Range.GetRange(context)))
        {
            Imports = new ImportNode[context.import_file().Length];
            for (int i = 0; i < Imports.Length; i++)
            {
                Imports[i] = new ImportNode(context.import_file(i), visitor);
            }

            ObjectImports = new ImportObjectNode[context.import_object().Length];
            for (int i = 0; i < ObjectImports.Length; i++)
            {
                ObjectImports[i] = new ImportObjectNode(context.import_object(i), visitor);
            }

            Rules = new RuleNode[context.ow_rule().Length];
            for (int i = 0; i < Rules.Length; i++)
            {
                Rules[i] = (RuleNode)visitor.VisitOw_rule(context.ow_rule()[i]);
            }

            if (context.useGlobalVar() != null)
            {
                if (Enum.TryParse(context.useGlobalVar().PART().GetText(), out Variable temp))
                {
                    UseGlobalVar = temp;
                }
            }

            if (context.usePlayerVar() != null)
            {
                if (Enum.TryParse(context.usePlayerVar().PART().GetText(), out Variable temp))
                {
                    UsePlayerVar = temp;
                }
            }

            if (context.useDimVar() != null)
            {
                if (Enum.TryParse(context.useDimVar().PART().GetText(), out Variable temp))
                {
                    UseBuilderVar = temp;
                }
            }

            DefinedVars = new RuleDefineNode[context.rule_define().Length];
            for (int i = 0; i < DefinedVars.Length; i++)
            {
                DefinedVars[i] = (RuleDefineNode)visitor.VisitRule_define(context.rule_define(i));
            }

            UserMethods = new UserMethodNode[context.user_method().Length];
            for (int i = 0; i < UserMethods.Length; i++)
            {
                UserMethods[i] = (UserMethodNode)visitor.VisitUser_method(context.user_method(i));
            }

            DefinedTypes = new TypeDefineNode[context.type_define().Length];
            for (int i = 0; i < DefinedTypes.Length; i++)
            {
                DefinedTypes[i] = (TypeDefineNode)visitor.VisitType_define(context.type_define(i));
            }
        }