Example #1
0
    public static void buyItemUtilits(Items _item, float _moneyItem)
    {
        if (_moneyItem <= WalletController.getValue(ItemsType.coin))
        {
            WalletController.removeItems(ItemsType.coin, _moneyItem);

            foreach (Items _args  in DictionaryItems.listItems)
            {
                if (_args.Item == ItemsType.redCard)
                {
                    if (_item.Item == ItemsType.redCard)
                    {
                        _args.Level++;
                    }
                }
                else if (_args.Item == ItemsType.life)
                {
                    if (_item.Item == ItemsType.life)
                    {
                        _args.Level++;
                    }
                }
            }
        }
        else
        {
            WarningManager.noMoney();
        }
    }
        public void NoWarningsToConsole()
        {
            string warningMessage = "I'm a warning you want to ignore; it hurts.";

            var warningManager = new WarningManager();

            warningManager.SetState((int)EventId.WarningEvent, WarningState.Suppressed);


            // suppress the warning and check that it is not printed
            using (var console = new MockConsole())
            {
                using (var listener = new ConsoleEventListener(Events.Log, console, DateTime.UtcNow, false, warningMapper: warningManager.GetState))
                {
                    Events.Log.WarningEvent(warningMessage);
                    console.ValidateNoCall();
                }
            }

            // allow the warning
            using (var console = new MockConsole())
            {
                using (var listener = new ConsoleEventListener(Events.Log, console, DateTime.UtcNow, false))
                {
                    Events.Log.WarningEvent(warningMessage);
                    console.ValidateCall(MessageLevel.Warning, warningMessage);
                }
            }
        }
Example #3
0
        public void WarningMapping()
        {
            TestEvents log = TestEvents.Log;

            var wm = new WarningManager();

            using (var listener = new TrackingEventListener(Events.Log, warningMapper: wm.GetState))
            {
                listener.RegisterEventSource(TestEvents.Log);

                // should log as a warning
                XAssert.AreEqual(0, listener.WarningCount);
                log.WarningEvent("1");
                XAssert.AreEqual(1, listener.WarningCount);
                XAssert.AreEqual(0, listener.TotalErrorCount);

                wm.SetState(WarningEventId, WarningState.AsError);

                // should log as an error
                log.WarningEvent("1");
                XAssert.AreEqual(1, listener.TotalErrorCount);
                XAssert.AreEqual(1, listener.WarningCount);

                wm.SetState(WarningEventId, WarningState.Suppressed);

                // should be suppressed
                log.WarningEvent("1");
                XAssert.AreEqual(1, listener.WarningCount);
                XAssert.AreEqual(1, listener.TotalErrorCount);
            }

            using (var listener = new TrackingEventListener(Events.Log, warningMapper: wm.GetState))
            {
                listener.RegisterEventSource(TestEvents.Log);

                // should log as a info
                XAssert.AreEqual(0, listener.InformationalCount);
                log.InfoEvent("1");
                XAssert.AreEqual(1, listener.InformationalCount);
                XAssert.AreEqual(0, listener.WarningCount);
                XAssert.AreEqual(0, listener.TotalErrorCount);

                wm.SetState(InfoEventId, WarningState.AsError);

                // should not log as an error (only warnings are managed by warning mapper)
                log.InfoEvent("1");
                XAssert.AreEqual(2, listener.InformationalCount);
                XAssert.AreEqual(0, listener.TotalErrorCount);

                wm.SetState(InfoEventId, WarningState.Suppressed);

                // should not be suppressed (only warnings are managed by warning mapper)
                log.InfoEvent("1");
                XAssert.AreEqual(3, listener.InformationalCount);
                XAssert.AreEqual(0, listener.TotalErrorCount);
            }
        }
Example #4
0
 public PouringState()
 {
     InitializeComponent();
     adamHelper       = AdamHelper.GetInstance();
     dataStoreManager = DataStoreManager.GetInstance();
     warningManager   = WarningManager.GetInstance();
     config           = ConfigManager.GetInstance();
     //timer1.Enabled = false;
 }
Example #5
0
 void Start()
 {
     roadsManager = GetComponent <RoadsManager>();
     roadsManager.StartSpawning();
     wiperManager    = GetComponent <WiperManager>();
     tutorialManager = GetComponent <TutorialManager>();
     warningManager  = FindObjectOfType <WarningManager>();
     particleManager = FindObjectOfType <ParticleSystemsManager>();
 }
Example #6
0
 void Awake()
 {
     instance                       = this;
     foodWarning.enabled            = false;
     woodPanelGoldWarning.enabled   = false;
     troopsPanelGoldWarning.enabled = false;
     shipsPanelGoldWarning.enabled  = false;
     shipsPanelWoodWarning.enabled  = false;
     foodPanelGoldWarning.enabled   = false;
 }
        public static IEnumerable <CodeInstruction> Update_Transpiler(IEnumerable <CodeInstruction> instructions, ILGenerator il)
        {
            CodeMatcher matcher = new CodeMatcher(instructions, il)
                                  // find for loop increment and exit condition
                                  .MatchForward(false,
                                                new CodeMatch(OpCodes.Stloc_0),
                                                new CodeMatch(OpCodes.Ldloc_0),
                                                new CodeMatch(OpCodes.Ldarg_0),
                                                new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(LogisticShipRenderer), "transport")),
                                                new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(GalacticTransport), "stationCursor")),
                                                new CodeMatch(OpCodes.Blt))
                                  .Advance(-3)
                                  .CreateLabel(out Label jmpToForCompare)
                                  .Start()
                                  // find stationPool access (which produces IndexOutOfBounds in rare cases)
                                  .MatchForward(false,
                                                new CodeMatch(OpCodes.Ldarg_0),
                                                new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(LogisticShipRenderer), "transport")),
                                                new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(GalacticTransport), "stationPool")),
                                                new CodeMatch(OpCodes.Ldloc_0))
                                  .InsertAndAdvance(new CodeInstruction(OpCodes.Ldarg_0))
                                  .InsertAndAdvance(new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(LogisticShipRenderer), "transport")))
                                  .InsertAndAdvance(new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(GalacticTransport), "stationPool")))
                                  .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloc_0))
                                  .InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate <IsOutOfBounds>((StationComponent[] stationComponent, int index) =>
            {
                if (index >= stationComponent.Length && Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsClient)
                {
                    WarningManager.DisplayCriticalWarning("IndexOutOfBounds in LogisticShipRenderer. Consider reconnecting!");
                }
                return(index < stationComponent.Length);
            }))
                                  .Insert(new CodeInstruction(OpCodes.Brfalse, jmpToForCompare))
                                  // find start of our injected code
                                  .MatchBack(false,
                                             new CodeMatch(OpCodes.Ldarg_0),
                                             new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(LogisticShipRenderer), "transport")),
                                             new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(GalacticTransport), "stationPool")),
                                             new CodeMatch(OpCodes.Ldloc_0))
                                  .CreateLabel(out Label jmpToOverflowCheck)
                                  .Start()
                                  // exchange loop start ptr with our index checking
                                  .MatchForward(true,
                                                new CodeMatch(OpCodes.Stloc_0),
                                                new CodeMatch(OpCodes.Ldloc_0),
                                                new CodeMatch(OpCodes.Ldarg_0),
                                                new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(LogisticShipRenderer), "transport")),
                                                new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(GalacticTransport), "stationCursor")),
                                                new CodeMatch(OpCodes.Blt))
                                  .SetOperandAndAdvance(jmpToOverflowCheck);

            return(matcher.InstructionEnumeration());
        }
Example #8
0
    /* private void OnCollisionEnter(Collision collision)
     * {
     *   if (collision.collider.CompareTag("Enemy"))
     *   {
     *       health -= 25;
     *       enemy.WalkForward = false;
     *       enemy.GotStick();
     *   }
     *
     * } */

    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Enemy"))
        {
            Health -= 25;
            other.gameObject.GetComponent <EnemyMover>().WalkForward = false;
            other.gameObject.GetComponent <EnemyMover>().GotStick();
            BurgDamageTaken();

            WarningManager warn = WarningManager.FindClosestWarningManager(other.transform.position);
            warn.StartCoroutine(warn.ColorWarnObjects("damage"));
        }
    }
Example #9
0
 public static bool InternalUpdate_Prefix(MonitorComponent __instance, CargoTraffic _traffic, EntityData[] _entityPool, SpeakerComponent[] _speakerPool, AnimData[] _animPool)
 {
     if (Multiplayer.IsActive && __instance.targetBeltId > _traffic.beltPool.Length)
     {
         if (Multiplayer.Session.LocalPlayer.IsHost)
         {
             _traffic.factory.RemoveEntityWithComponents(__instance.entityId);
             WarningManager.DisplayTemporaryWarning($"Broken Traffic Monitor detected on {_traffic.factory.planet.displayName}\nIt was removed, clients should reconnect!", 15000);
         }
         return(false);
     }
     return(true);
 }
Example #10
0
    void Start()
    {
        GM               = GameManager.Instance;
        alarmAudio       = GetComponent <AudioSource>();
        warningManager   = FindObjectOfType <WarningManager>();
        historyWaterBar  = MakeHistoryBar(WaterBar);
        historyEngineBar = MakeHistoryBar(EngineBar);

        gasContainer    = GasBar.parent.GetComponent <Image>();
        powerContainer  = PowerBar.parent.GetComponent <Image>();
        waterContainer  = WaterBar.parent.GetComponent <Image>();
        heatContainer   = HeatBar.parent.GetComponent <Image>();
        engineContainer = EngineBar.parent.GetComponent <Image>();
    }
Example #11
0
        private void TestForm_Load(object sender, EventArgs e)
        {
            List <AdamOperation> list = new List <AdamOperation>
            {
                new Adam6217Operation("192.168.1.3", 0)
            };

            try
            {
                AdamHelper.Initialize(list);
                adamHelper = AdamHelper.GetInstance();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.GetType());
            }

            bool isResetDb = true;

            try
            {
                DBHelper dbHelper = DBHelper.GetInstance();
                if (isResetDb)
                {
                    ConfigManager.Initialize(dbHelper, false);
                    ConfigManager.GetInstance().RecreateDbTable();
                }
                else
                {
                    ConfigManager.Initialize(dbHelper);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"无法初始化配置管理系统,程序将退出。\n错误:\n {ex.Message}\n {ex.StackTrace}",
                                "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            try
            {
                warningManager = WarningManager.GetInstance();
                warningDialog  = WarningDialog.GetInstance(warningManager);
                configManager  = ConfigManager.GetInstance();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #12
0
        public static WarningDialog GetInstance(WarningManager manager)
        {
            if (instance == null)
            {
                lock (obj)
                {
                    if (instance == null)
                    {
                        instance = new WarningDialog(manager);
                    }
                }
            }

            return(instance);
        }
Example #13
0
    public static void buyItemLevelUp(Items _item, float _moneyItem)
    {
        if (_moneyItem <= WalletController.getValue(ItemsType.coin))
        {
            WalletController.removeItems(ItemsType.coin, _moneyItem);

            DictionaryItems.LevelUp(_item);

            DictionaryItems.playInitItems();

            StoreInterface.updateCoin();
        }
        else
        {
            WarningManager.noMoney();
        }
    }
        public void NoWarningsToConsole(bool isFromWorker)
        {
            string warningMessage = "I'm a warning you want to ignore; it hurts.";
            string warningName    = "IgnoreWarning";
            var    warningManager = new WarningManager();

            warningManager.SetState((int)TestEvents.EventId.WarningEvent, WarningState.Suppressed);

            // suppress the warning and check that it is not printed
            using (var console = new MockConsole())
                using (var listener = new ConsoleEventListener(Events.Log, console, DateTime.UtcNow, false, CancellationToken.None, warningMapper: warningManager.GetState))
                {
                    logWarning(console, listener);
                    console.ValidateNoCall();
                }

            // allow the warning
            using (var console = new MockConsole())
                using (var listener = new ConsoleEventListener(Events.Log, console, DateTime.UtcNow, false, CancellationToken.None))
                {
                    logWarning(console, listener);
                    console.ValidateCall(MessageLevel.Warning, warningMessage);
                }

            void logWarning(MockConsole console, ConsoleEventListener listener)
            {
                listener.RegisterEventSource(TestEvents.Log);
                listener.RegisterEventSource(global::BuildXL.Engine.ETWLogger.Log);
                if (isFromWorker)
                {
                    global::BuildXL.Engine.Tracing.Logger.Log.DistributionWorkerForwardedWarning(BuildXLTestBase.CreateLoggingContextForTest(), new WorkerForwardedEvent()
                    {
                        EventId       = (int)TestEvents.EventId.WarningEvent,
                        EventName     = warningName,
                        EventKeywords = 0,
                        Text          = warningMessage,
                    });
                }
                else
                {
                    TestEvents.Log.WarningEvent(warningMessage);
                }
            }
        }
Example #15
0
        public void WarningManager()
        {
            var wm = new WarningManager();

            // ensure the defaults are cool...
            Assert.False(wm.AllWarningsAreErrors);
            for (int i = 0; i < 10000; i++)
            {
                Assert.Equal(WarningState.AsWarning, wm.GetState(i));
            }

            // make sure setting warning as error has the desired effect
            wm.AllWarningsAreErrors = true;
            for (int i = 0; i < 10000; i++)
            {
                Assert.Equal(WarningState.AsError, wm.GetState(i));
            }

            // make sure unsetting warning as error has the desired effect
            wm.AllWarningsAreErrors = false;
            for (int i = 0; i < 10000; i++)
            {
                Assert.Equal(WarningState.AsWarning, wm.GetState(i));
            }

            // change the state of a warning
            wm.SetState(123, WarningState.Suppressed);
            Assert.Equal(WarningState.AsWarning, wm.GetState(122));
            Assert.Equal(WarningState.Suppressed, wm.GetState(123));
            Assert.Equal(WarningState.AsWarning, wm.GetState(124));

            // make sure suppression trumps warnings as errors
            wm.AllWarningsAreErrors = true;
            Assert.Equal(WarningState.Suppressed, wm.GetState(123));
            wm.AllWarningsAreErrors = false;

            // make sure warning as error doesn't mess up error state
            wm.SetState(321, WarningState.AsError);
            Assert.Equal(WarningState.AsError, wm.GetState(321));
            wm.AllWarningsAreErrors = true;
            Assert.Equal(WarningState.AsError, wm.GetState(321));
            wm.AllWarningsAreErrors = false;
            Assert.Equal(WarningState.AsError, wm.GetState(321));
        }
Example #16
0
        public TokenStream Parse(string[] characterStream, bool RealTokenStream = false)
        {
            ErrorManager.Reset();
            WarningManager.Reset();

            var scanner     = new Scanner(characterStream);
            var tokenStream = new Queue <Token>();

            this.allTokens = new Queue <Token>();

            Token token;

            do
            {
                token = RealTokenStream ? this.NextRealTokenFromScanner(scanner) : this.NextTokenFromScanner(scanner);
                tokenStream.Enqueue(token);
            } while (token.Type != TokenType.EndOfStream);

            return(new TokenStream(tokenStream));
        }
Example #17
0
 public void OnTriggerEnter(Collider other)
 {
     if (other.CompareTag("Projectile") && !gotHit)
     {
         WalkForward = false;
         if (StoleStick)
         {
             GameObject.Find("Burg").GetComponent <BurgScript>().Health += 25;
             GameObject.Find("Burg").GetComponent <BurgScript>().BurgHealthReceived();
             GameObject.Find("GameManager").GetComponent <ScoreScript>().EnemyHit(5);
             StoleStick = false;
             gameObject.GetComponentInChildren <Animator>().SetBool("StoleStick", false);
             killWithStick++;
             PlayerPrefs.SetInt("KillWithStickKey", killWithStick);
         }
         else
         {
             GameObject.Find("GameManager").GetComponent <ScoreScript>().EnemyHit(5);
             GameObject.Find("GameManager").GetComponent <ScoreScript>().EnemyHit(5);
             killWithoutStick++;
             PlayerPrefs.SetInt("KillWithoutStickKey", killWithoutStick);
         }
         gotHit = true;
         GameObject.Find("Treffer").GetComponent <AudioSource>().pitch = Random.Range(0.6f, 0.9f);
         GameObject.Find("Treffer").GetComponent <AudioSource>().Play();
         gameObject.GetComponentInChildren <Animator>().SetBool("SpatOn", true);
     }
     else if (other.CompareTag("CloseWarning"))
     {
         WarningManager warn = WarningManager.FindClosestWarningManager(gameObject.transform.position);
         warn.StartCoroutine(warn.ColorWarnObjects("close"));
     }
     else if (other.CompareTag("FarWarning"))
     {
         WarningManager warn = WarningManager.FindClosestWarningManager(gameObject.transform.position);
         warn.StartCoroutine(warn.ColorWarnObjects("far"));
     }
 }
Example #18
0
 public WarningDialog(WarningManager manager)
 {
     InitializeComponent();
     this.manager = manager;
     // this.pictureBox1.Image = i;
 }
 public void setWarningManager(WarningManager warningmanager)
 {
     this.warningmanager = warningmanager;
 }
Example #20
0
        public static IEnumerable <CodeInstruction> Import_Transpiler(IEnumerable <CodeInstruction> instructions, ILGenerator il)
        {
            CodeMatcher matcher = new CodeMatcher(instructions, il)
                                  .MatchForward(false,
                                                new CodeMatch(OpCodes.Ldloc_S),
                                                new CodeMatch(OpCodes.Ldc_I4_1),
                                                new CodeMatch(OpCodes.Add),
                                                new CodeMatch(OpCodes.Stloc_S),
                                                new CodeMatch(OpCodes.Ldloc_S),
                                                new CodeMatch(OpCodes.Ldarg_0),
                                                new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(PlanetFactory), "veinCursor")),
                                                new CodeMatch(OpCodes.Blt))
                                  .CreateLabel(out Label jmpForLoopIncrement)
                                  .Start()
                                  .MatchForward(false,
                                                new CodeMatch(OpCodes.Ldarg_0),
                                                new CodeMatch(i => i.opcode == OpCodes.Call && ((MethodInfo)i.operand).Name == "get_planet"),
                                                new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(PlanetData), "veinGroups")),
                                                new CodeMatch(OpCodes.Ldarg_0),
                                                new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(PlanetFactory), "veinPool")),
                                                new CodeMatch(OpCodes.Ldloc_S),
                                                new CodeMatch(OpCodes.Ldelema),
                                                new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(VeinData), "groupIndex")),
                                                new CodeMatch(OpCodes.Ldelema),
                                                new CodeMatch(OpCodes.Ldflda),
                                                new CodeMatch(OpCodes.Dup))
                                  .InsertAndAdvance(
                new CodeInstruction(OpCodes.Ldarg_0),
                new CodeInstruction(OpCodes.Ldloc_S, 29))
                                  .InsertAndAdvance(HarmonyLib.Transpilers.EmitDelegate <BoundsChecker>((PlanetFactory factory, int index) =>
            {
                if (factory.veinPool[index].groupIndex >= factory.planet.veinGroups.Length && Multiplayer.IsActive)
                {
                    if (Multiplayer.Session.LocalPlayer.IsHost)
                    {
                        if (FaultyVeins.ContainsKey(factory.planetId))
                        {
                            FaultyVeins[factory.planetId].Add(index);
                        }
                        else
                        {
                            List <int> veins = new List <int>();
                            veins.Add(index);
                            FaultyVeins.Add(factory.planetId, veins);
                        }
                    }
                    if (index == factory.veinCursor - 1)
                    {
                        if (Multiplayer.Session.LocalPlayer.IsClient && !CheckPopupPresent.Contains(factory.planetId))
                        {
                            WarningManager.DisplayTemporaryWarning("IndexOutOfBounds while importing factory data. Host should fix his savefile.", 15000);
                            CheckPopupPresent.Add(factory.planetId);
                        }
                        else if (Multiplayer.Session.LocalPlayer.IsHost && !CheckPopupPresent.Contains(factory.planetId))
                        {
                            InGamePopup.ShowError("IndexOutOfBounds", $"Nebula detected an IndexOutOfBounds error while importing PlanetFactory data. This is very weird and rare, but we can try to fix it. Keep in mind this will possibly end in weird results but may makes this save usable again. We would need to remove {FaultyVeins[factory.planetId].Count} veins from {factory.planet.displayName}. Make a backup before trying the fix!", "Ignore", "Try to fix it", new Action(delegate() { }), new Action(delegate()
                            {
                                for (int i = 0; i < FaultyVeins[factory.planetId].Count; i++)
                                {
                                    factory.RemoveVeinWithComponents(FaultyVeins[factory.planetId][i]);
                                }
                                WarningManager.DisplayTemporaryWarning("Done performing the fix, hopefully you dont see me again.", 15000);
                                FaultyVeins[factory.planetId].Clear();
                            }));
                            CheckPopupPresent.Add(factory.planetId);
                        }
                    }
                    return(false);
                }
                return(true);
            }))
                                  .Insert(new CodeInstruction(OpCodes.Brfalse, jmpForLoopIncrement));

            return(matcher.InstructionEnumeration());
        }
Example #21
0
 // Use this for initialization
 void Start()
 {
     mapSaver       = new MapSaver();
     warningManager = warningManagerObj.GetComponent <WarningManager>();
 }
Example #22
0
 private void Awake()
 {
     playerHealth   = PlayerHealth.Instance;
     warningManager = WarningManager.Instance;
 }
Example #23
0
        public IEnumerable <Section> GetReportSections(string inputFileName)
        {
            bool validProgram        = this.Verify();
            var  validProgramSection = new Section("Valid Program");

            validProgramSection.AddRow("<p style='font-weight:lighter;'>This section displays whether or not the given program is lexically and syntactically correct.</p><hr style='margin-top:0'>");
            validProgramSection.AddRow(validProgram ? "Program is valid." : "Program is invalid: " + ErrorManager.Count() + " errors were found.");
            yield return(validProgramSection);

            foreach (var section in ErrorManager.GetReportSection())
            {
                yield return(section);
            }

            foreach (var section in WarningManager.GetReportSection())
            {
                yield return(section);
            }

            foreach (var section in this._tokenizer.GetReportSections(inputFileName))
            {
                yield return(section);
            }

            var atoccStreamInput = new Section("Pruned Lexical AToCC Input Stream");

            atoccStreamInput.AddRow("<p style='font-weight:lighter;'>This section contains the original token stream converted into AToCC format with comments removed.</p><hr style='margin-top:0'>");
            atoccStreamInput.AddRow($"<code style='color:black'>{this.TokenStream.FullAToCCFormat}</code>");
            yield return(atoccStreamInput);


            var atoccStreamOutput = new Section("Last Derivation in AToCC Format");

            atoccStreamOutput.AddRow("<p style='font-weight:lighter;'>This section contains the last derivation done in the syntactic analysis converted into AToCC format.</p><hr style='margin-top:0'>");
            atoccStreamOutput.AddRow($"<code style='color:black'>{this.Derivations.Last().SententialForm.Replace(' ', '\0').Replace('\'', '\0')}</code>");
            if (validProgram)
            {
                yield return(atoccStreamOutput);
            }


            var absStream = new Section("Abstract Syntax Tree Traversal", true);

            absStream.AddRow("<p style='font-weight:lighter;'>Displays the reconstruction of the original program through the traversal of the Abstract Syntax Tree data structure." +
                             " Note that minor non-errors may occur in the reconstruction such as: missing or additional semi-colons, and missing or additional whitespace.</p><hr style='margin-top:0'>");
            absStream.AddRow($"<code style='color:black'>{this.AbstractSyntaxTree?.ToString().Replace(">", "&gt;").Replace("<", "&lt;").Replace("\n", "<br>").Replace("\t", "&nbsp;&nbsp;")}</code>");
            if (validProgram)
            {
                yield return(absStream);
            }


            using (var fs = new FileStream(inputFileName + ".xml", FileMode.Create)) {
                var serializer = new XmlSerializer(typeof(Program), new System.Type[] {
                    typeof(AddOp),
                    typeof(Nodes.AParams),
                    typeof(AssignStat),
                    typeof(ClassDecl),
                    typeof(ClassList),
                    typeof(DataMember),
                    typeof(FCall),
                    typeof(ForStat),
                    typeof(FParam),
                    typeof(FuncDecl),
                    typeof(FuncDef),
                    typeof(FuncDefList),
                    typeof(GetStat),
                    typeof(IfStat),
                    typeof(IndexList),
                    typeof(InherList),
                    typeof(MultOp),
                    typeof(Not),
                    typeof(PutStat),
                    typeof(RelExpr),
                    typeof(ReturnStat),
                    typeof(ScopeSpec),
                    typeof(Sign),
                    typeof(StatBlock),
                    typeof(MainStatBlock),
                    typeof(Var),
                    typeof(VarDecl),
                    typeof(Integer),
                    typeof(Float)
                });
                serializer.Serialize(fs, this.AbstractSyntaxTree);
            }

            var astSection = new Section("Abstract Syntax Tree");

            astSection.AddRow("<p style='font-weight:lighter;'>Displays the Abstract Syntax Tree data structure in a tree format. You can click on nodes to expand or collapse their children.</p><hr style='margin-top:0'>");
            astSection.AddRow("<button class='btn btn-danger' onclick=\"" +
                              @"
var clickEvent = new MouseEvent('click', {
'view': window,
'bubbles': true,
'cancelable': false
});
var elements = document.getElementsByTagName('circle');
for (var i = 0; i < elements.length; i++) {
    var element = elements[i];
    if (element.style.fill != 'rgb(255, 255, 255)') {
        elements[i].dispatchEvent(clickEvent);
    }
}
" +
                              "\">Expand - MAY TAKE A LONG TIME</button>");
            astSection.AddRow($"<div id='AST' class='AST' style='background-color:rgb(150, 150, 150);'><script>xml2tree('AST', '{inputFileName + ".xml"}', [], false, false);</script></div>");

            if (validProgram)
            {
                yield return(astSection);
            }



            var derivSection = new Section("Derivations", true);

            derivSection.AddRow("<p style='font-weight:lighter;'>Contains the full derivation of the program that was parsed, and details each rule that was applied and the resulting sentential form as a result of its application.</p><hr style='margin-top:0'>");
            derivSection.AddRowStart();
            derivSection.Add("<table class='table table-hover' style='color:red'><tr style='color:black'><th>Rule Applied</th><th>Sentential Form</th></tr>");

            string terminalRule(string str) => Regex.Replace(str, "\'(\\S+)\'", "<span style=' color:black'>'$1'</span>");
            string epsilonRule(string str) => Regex.Replace(str, "EPSILON", "<span style=' color:blue'>EPSILON</span>");

            foreach (var derivation in this.Derivations)
            {
                string rule           = terminalRule(epsilonRule(derivation.Rule.Replace("->", "<span style=' color:black'>-></span>")));
                string sententialForm = terminalRule(epsilonRule(derivation.SententialForm));

                derivSection.Add($"<tr><td>{rule}</td><td>{sententialForm}</td></tr>");
            }
            derivSection.Add("</table>");
            derivSection.AddRowEnd();

            if (validProgram)
            {
                yield return(derivSection);
            }
        }
Example #24
0
 private void Awake()
 {
     Instance = this;
 }