コード例 #1
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));
            }
        }
コード例 #2
0
        public RulesetNode(DeltinScriptParser.RulesetContext context, BuildAstVisitor visitor) : base(new Location(visitor.file, DocRange.GetRange(context)))
        {
            // Get imports
            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);
            }

            // Get rules
            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]);
            }

            // Get defined variables
            DefinedVars = new RuleDefineNode[context.rule_define().Length];
            var reservedGlobalIDs = new List <int>();
            var reservedPlayerIDs = new List <int>();

            for (int i = 0; i < DefinedVars.Length; i++)
            {
                DefinedVars[i] = new RuleDefineNode(context.rule_define(i), visitor);
                if (DefinedVars[i].OverrideID != -1)
                {
                    (DefinedVars[i].IsGlobal ? reservedGlobalIDs : reservedPlayerIDs).Add(DefinedVars[i].OverrideID);
                }
            }
            ReservedGlobalIDs = reservedGlobalIDs.ToArray();
            ReservedPlayerIDs = reservedPlayerIDs.ToArray();

            // Get user methods
            UserMethods = new UserMethodBase[context.user_method().Length + context.macro().Length];
            for (int i = 0; i < context.user_method().Length; i++)
            {
                UserMethods[i] = (UserMethodNode)visitor.VisitUser_method(context.user_method(i));
            }

            // Get macros
            for (int i = 0; i < context.macro().Length; i++)
            {
                UserMethods[i + context.user_method().Length] = new MacroNode(context.macro(i), visitor);
            }

            // Get types
            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));
            }

            // Get reserved global variables
            if (context.reserved_global()?.reserved_list() != null)
            {
                ReservedGlobal = new ReservedNode(context.reserved_global().reserved_list(), visitor);
            }

            // Get reserved player variables
            if (context.reserved_player()?.reserved_list() != null)
            {
                ReservedPlayer = new ReservedNode(context.reserved_player().reserved_list(), visitor);
            }
        }