Esempio n. 1
0
        /// <summary>
        /// Checks the modifier set for errors.
        /// </summary>
        private static void CheckMachineStateModifierSet(ModifierSet modSet)
        {
            if (modSet.AccessModifier == AccessModifier.Public)
            {
                throw new ParsingException("A machine state cannot be public.");
            }
            else if (modSet.AccessModifier == AccessModifier.Internal)
            {
                throw new ParsingException("A machine state cannot be internal.");
            }

            if (modSet.InheritanceModifier == InheritanceModifier.Virtual)
            {
                throw new ParsingException("A machine state cannot be virtual.");
            }
            else if (modSet.InheritanceModifier == InheritanceModifier.Override)
            {
                throw new ParsingException("A machine state cannot be overriden.");
            }

            if (modSet.IsAsync)
            {
                throw new ParsingException("A machine state cannot be async.");
            }

            if (modSet.IsPartial)
            {
                throw new ParsingException("A machine state cannot be partial.");
            }
        }
        /// <summary>
        /// Checks the modifier set for errors.
        /// </summary>
        private void CheckMachineFieldModifierSet(ModifierSet modSet)
        {
            if (modSet.AccessModifier == AccessModifier.Public)
            {
                throw new ParsingException("A machine field cannot be public.", this.TokenStream.Peek());
            }
            else if (modSet.AccessModifier == AccessModifier.Internal)
            {
                throw new ParsingException("A machine field cannot be internal.", this.TokenStream.Peek());
            }

            if (modSet.InheritanceModifier == InheritanceModifier.Abstract)
            {
                throw new ParsingException("A machine field cannot be abstract.", this.TokenStream.Peek());
            }
            else if (modSet.InheritanceModifier == InheritanceModifier.Virtual)
            {
                throw new ParsingException("A machine field cannot be virtual.", this.TokenStream.Peek());
            }
            else if (modSet.InheritanceModifier == InheritanceModifier.Override)
            {
                throw new ParsingException("A machine field cannot be overriden.", this.TokenStream.Peek());
            }

            if (modSet.IsAsync)
            {
                throw new ParsingException("A machine field cannot be async.", this.TokenStream.Peek());
            }

            if (modSet.IsPartial)
            {
                throw new ParsingException("A machine field cannot be partial.", this.TokenStream.Peek());
            }
        }
Esempio n. 3
0
            private static void Postfix(ModifierSet __instance)
            {
                // плохой сон - свет
                Effect effectBadSleep = __instance.effects.Get("BadSleep");

                effectBadSleep.Add(new AttributeModifier(HeartAttackMonitor.ATTRIBUTE_ID, +0.05f, effectBadSleep.Name));

                // плохой сон - храп
                Effect effectTerribleSleep = __instance.effects.Get("TerribleSleep");

                effectTerribleSleep.Add(new AttributeModifier(HeartAttackMonitor.ATTRIBUTE_ID, +0.1f, effectTerribleSleep.Name));

                // лечение на койке
                Effect effectMedicalCot = __instance.effects.Get("MedicalCot");

                effectMedicalCot.Add(new AttributeModifier(HeartAttackMonitor.ATTRIBUTE_ID, -0.1f, effectMedicalCot.Name));

                // лечение на койке с доктором
                Effect effectMedicalCotDoctored = __instance.effects.Get("MedicalCotDoctored");

                effectMedicalCotDoctored.Add(new AttributeModifier(HeartAttackMonitor.ATTRIBUTE_ID, -0.2f, effectMedicalCotDoctored.Name));
                effectMedicalCotDoctored.Add(new AttributeModifier(HeartAttackSickness.ID + "CureSpeed", 0.25f, effectMedicalCotDoctored.Name));

                // красная тревога
                Effect effectRedAlert = __instance.effects.Get("RedAlert");

                effectRedAlert.Add(new AttributeModifier(HeartAttackMonitor.ATTRIBUTE_ID, +0.25f, effectRedAlert.Name));
            }
Esempio n. 4
0
        /// <summary>
        /// Checks the modifier set for errors.
        /// </summary>
        /// <param name="modSet">ModifierSet</param>
        /// <param name="isInMachine">Is declared inside a machine</param>
        private void CheckEventModifierSet(ModifierSet modSet, bool isInMachine)
        {
            if (!isInMachine && modSet.AccessModifier == AccessModifier.Private)
            {
                throw new ParsingException("An event declared in the scope of a namespace cannot be private.",
                                           new List <TokenType>());
            }

            if (modSet.AccessModifier == AccessModifier.Protected)
            {
                throw new ParsingException("An event cannot be declared as protected.",
                                           new List <TokenType>());
            }

            if (modSet.InheritanceModifier == InheritanceModifier.Abstract)
            {
                throw new ParsingException("An event cannot be declared as abstract.",
                                           new List <TokenType>());
            }

            if (modSet.IsPartial)
            {
                throw new ParsingException("An event cannot be declared as partial.",
                                           new List <TokenType>());
            }
        }
Esempio n. 5
0
 public static void Postfix(ModifierSet __instance)
 {
     foreach (var effect in InspiredEffects.GetEffectsList())
     {
         __instance.effects.Add(effect);
     }
 }
        /// <summary>
        /// Visits a group level declaration.
        /// </summary>
        private void VisitGroupLevelDeclaration(StateGroupDeclaration parentNode, TokenRange tokenRange)
        {
            ModifierSet modSet = ModifierSet.CreateDefault();

            while (!this.TokenStream.Done &&
                   this.TokenStream.Peek().Type != TokenType.StateDecl &&
                   this.TokenStream.Peek().Type != TokenType.StateGroupDecl &&
                   this.TokenStream.Peek().Type != TokenType.MachineDecl)
            {
                new ModifierVisitor(this.TokenStream).Visit(modSet);

                this.TokenStream.Index++;
                this.TokenStream.SkipWhiteSpaceAndCommentTokens();
            }

            if (this.TokenStream.Done ||
                (this.TokenStream.Peek().Type != TokenType.StateDecl &&
                 this.TokenStream.Peek().Type != TokenType.StateGroupDecl))
            {
                throw new ParsingException("Expected state or group declaration.", this.TokenStream.Peek(), TokenType.StateDecl, TokenType.StateGroupDecl);
            }

            if (this.TokenStream.Peek().Type == TokenType.StateDecl)
            {
                new StateDeclarationVisitor(this.TokenStream).Visit(parentNode.Machine, parentNode, modSet, tokenRange.Start());
            }
            else if (this.TokenStream.Peek().Type == TokenType.StateGroupDecl)
            {
                new StateGroupDeclarationVisitor(this.TokenStream).Visit(parentNode.Machine, parentNode, modSet, tokenRange.Start());
            }
        }
Esempio n. 7
0
            public static void Postfix(ModifierSet __instance)
            {
                var effects = Effects.GenerateEffectsList(ConfigManager.Config.DebuffTier);

                foreach (var e in effects)
                {
                    __instance.effects.Add(e);
                }
            }
Esempio n. 8
0
        /// <summary>
        /// Checks the modifier set for errors.
        /// </summary>
        /// <param name="modSet">ModifierSet</param>
        private void CheckStateGroupModifierSet(ModifierSet modSet)
        {
            if (modSet.AccessModifier == AccessModifier.Public)
            {
                throw new ParsingException("A machine state group cannot be public.",
                                           new List <TokenType>());
            }
            else if (modSet.AccessModifier == AccessModifier.Internal)
            {
                throw new ParsingException("A machine state group cannot be internal.",
                                           new List <TokenType>());
            }

            if (modSet.InheritanceModifier == InheritanceModifier.Abstract)
            {
                throw new ParsingException("A machine state group cannot be abstract.",
                                           new List <TokenType>());
            }
            else if (modSet.InheritanceModifier == InheritanceModifier.Virtual)
            {
                throw new ParsingException("A machine state group cannot be virtual.",
                                           new List <TokenType>());
            }
            else if (modSet.InheritanceModifier == InheritanceModifier.Override)
            {
                throw new ParsingException("A machine state group cannot be overriden.",
                                           new List <TokenType>());
            }

            if (modSet.IsAsync)
            {
                throw new ParsingException("A machine state group cannot be async.",
                                           new List <TokenType>());
            }

            if (modSet.IsPartial)
            {
                throw new ParsingException("A machine state group cannot be partial.",
                                           new List <TokenType>());
            }

            if (modSet.IsStart)
            {
                throw new ParsingException("A machine state group cannot be marked start.",
                                           new List <TokenType>());
            }
            else if (modSet.IsHot)
            {
                throw new ParsingException("A machine state group cannot be hot.",
                                           new List <TokenType>());
            }
            else if (modSet.IsCold)
            {
                throw new ParsingException("A machine state group cannot be cold.",
                                           new List <TokenType>());
            }
        }
Esempio n. 9
0
 /// <summary>
 /// Checks the modifier set for errors.
 /// </summary>
 private void CheckMonitorModifierSet(ModifierSet modSet)
 {
     if (modSet.AccessModifier == AccessModifier.Private)
     {
         throw new ParsingException("A monitor cannot be declared as private.", this.TokenStream.Peek());
     }
     else if (modSet.AccessModifier == AccessModifier.Protected)
     {
         throw new ParsingException("A monitor cannot be declared as protected.", this.TokenStream.Peek());
     }
 }
Esempio n. 10
0
 /// <summary>
 /// Checks the modifier set for errors.
 /// </summary>
 private static void CheckMonitorModifierSet(ModifierSet modSet)
 {
     if (modSet.AccessModifier == AccessModifier.Private)
     {
         throw new ParsingException("A monitor cannot be declared as private.");
     }
     else if (modSet.AccessModifier == AccessModifier.Protected)
     {
         throw new ParsingException("A monitor cannot be declared as protected.");
     }
 }
 /// <summary>
 /// Checks the modifier set for errors.
 /// </summary>
 private static void CheckMachineMethodModifierSet(ModifierSet modSet)
 {
     if (modSet.AccessModifier == AccessModifier.Public)
     {
         throw new ParsingException("A machine method cannot be public.");
     }
     else if (modSet.AccessModifier == AccessModifier.Internal)
     {
         throw new ParsingException("A machine method cannot be internal.");
     }
 }
 /// <summary>
 /// Checks the modifier set for errors.
 /// </summary>
 private void CheckMachineMethodModifierSet(ModifierSet modSet)
 {
     if (modSet.AccessModifier == AccessModifier.Public)
     {
         throw new ParsingException("A machine method cannot be public.", this.TokenStream.Peek());
     }
     else if (modSet.AccessModifier == AccessModifier.Internal)
     {
         throw new ParsingException("A machine method cannot be internal.", this.TokenStream.Peek());
     }
 }
Esempio n. 13
0
 /// <summary>
 /// Checks the modifier set for errors.
 /// </summary>
 /// <param name="modSet">ModifierSet</param>
 private void CheckMachineModifierSet(ModifierSet modSet)
 {
     if (modSet.AccessModifier == AccessModifier.Private)
     {
         throw new ParsingException("A machine cannot be declared as private.",
                                    new List <TokenType>());
     }
     else if (modSet.AccessModifier == AccessModifier.Protected)
     {
         throw new ParsingException("A machine cannot be declared as protected.",
                                    new List <TokenType>());
     }
 }
        /// <summary>
        /// Visits the syntax node.
        /// </summary>
        /// <param name="parentNode">Node</param>
        /// <param name="modSet">Modifier set</param>
        internal void Visit(MachineDeclaration parentNode, ModifierSet modSet)
        {
            TextUnit textUnit = null;

            new TypeIdentifierVisitor(base.TokenStream).Visit(ref textUnit);
            var typeIdentifier = new Token(textUnit, TokenType.TypeIdentifier);

            if (base.TokenStream.Done ||
                base.TokenStream.Peek().Type != TokenType.Identifier)
            {
                throw new ParsingException("Expected field or method identifier.",
                                           new List <TokenType>
                {
                    TokenType.Identifier
                });
            }

            var identifierToken = base.TokenStream.Peek();

            base.TokenStream.Index++;
            base.TokenStream.SkipWhiteSpaceAndCommentTokens();

            if (base.TokenStream.Done ||
                (base.TokenStream.Peek().Type != TokenType.LeftParenthesis &&
                 base.TokenStream.Peek().Type != TokenType.Semicolon))
            {
                throw new ParsingException("Expected \"(\" or \";\".",
                                           new List <TokenType>
                {
                    TokenType.LeftParenthesis,
                    TokenType.Semicolon
                });
            }

            if (base.TokenStream.Peek().Type == TokenType.LeftParenthesis)
            {
                new MachineMethodDeclarationVisitor(base.TokenStream).Visit(parentNode, typeIdentifier,
                                                                            identifierToken, modSet);
            }
            else if (base.TokenStream.Peek().Type == TokenType.Semicolon)
            {
                this.CheckMachineFieldModifierSet(modSet);

                var node = new FieldDeclaration(base.TokenStream.Program, parentNode, modSet);
                node.TypeIdentifier = typeIdentifier;
                node.Identifier     = identifierToken;
                node.SemicolonToken = base.TokenStream.Peek();

                parentNode.FieldDeclarations.Add(node);
            }
        }
Esempio n. 15
0
 /// <summary>
 /// Visits the syntax node.
 /// </summary>
 internal void Visit(ModifierSet modSet)
 {
     if (this.TokenStream.Peek().Type == TokenType.Public)
     {
         modSet.AccessModifier = AccessModifier.Public;
     }
     else if (this.TokenStream.Peek().Type == TokenType.Private)
     {
         modSet.AccessModifier = AccessModifier.Private;
     }
     else if (this.TokenStream.Peek().Type == TokenType.Protected)
     {
         modSet.AccessModifier = AccessModifier.Protected;
     }
     else if (this.TokenStream.Peek().Type == TokenType.Internal)
     {
         modSet.AccessModifier = AccessModifier.Internal;
     }
     else if (this.TokenStream.Peek().Type == TokenType.Abstract)
     {
         modSet.InheritanceModifier = InheritanceModifier.Abstract;
     }
     else if (this.TokenStream.Peek().Type == TokenType.Virtual)
     {
         modSet.InheritanceModifier = InheritanceModifier.Virtual;
     }
     else if (this.TokenStream.Peek().Type == TokenType.Override)
     {
         modSet.InheritanceModifier = InheritanceModifier.Override;
     }
     else if (this.TokenStream.Peek().Type == TokenType.StartState)
     {
         modSet.IsStart = true;
     }
     else if (this.TokenStream.Peek().Type == TokenType.HotState)
     {
         modSet.IsHot = true;
     }
     else if (this.TokenStream.Peek().Type == TokenType.ColdState)
     {
         modSet.IsCold = true;
     }
     else if (this.TokenStream.Peek().Type == TokenType.Async)
     {
         modSet.IsAsync = true;
     }
     else if (this.TokenStream.Peek().Type == TokenType.Partial)
     {
         modSet.IsPartial = true;
     }
 }
Esempio n. 16
0
        internal void VisitExternDeclaration(NamespaceDeclaration namespaceNode, MachineDeclaration machineNode)
        {
            // Skip over "extern".
            this.TokenStream.Index++;
            this.TokenStream.SkipWhiteSpaceAndCommentTokens();

            if (this.TokenStream.Done ||
                this.TokenStream.Peek().Type != TokenType.EventDecl)
            {
                throw new ParsingException("\"extern\" applies only to events and can have no access modifiers.", this.TokenStream.Peek(), TokenType.EventDecl);
            }

            this.VisitEventDeclaration(namespaceNode, machineNode, ModifierSet.CreateDefault(), isExtern: true);
        }
Esempio n. 17
0
        /// <summary>
        /// Creates a default modifier set.
        /// </summary>
        /// <returns>ModifierSet</returns>
        public static ModifierSet CreateDefault()
        {
            ModifierSet modSet = new ModifierSet();

            modSet.AccessModifier      = AccessModifier.None;
            modSet.InheritanceModifier = InheritanceModifier.None;
            modSet.IsAsync             = false;
            modSet.IsPartial           = false;
            modSet.IsStart             = false;
            modSet.IsHot  = false;
            modSet.IsCold = false;

            return(modSet);
        }
Esempio n. 18
0
 /// <summary>
 /// Checks the modifier set for errors.
 /// </summary>
 /// <param name="modSet">ModifierSet</param>
 private void CheckModifierSet(ModifierSet modSet)
 {
     if (modSet.AccessModifier != AccessModifier.None &&
         (base.TokenStream.Peek().Type == TokenType.Public ||
          base.TokenStream.Peek().Type == TokenType.Private ||
          base.TokenStream.Peek().Type == TokenType.Protected ||
          base.TokenStream.Peek().Type == TokenType.Internal))
     {
         throw new ParsingException("More than one protection modifier.",
                                    new List <TokenType>());
     }
     else if (modSet.InheritanceModifier != InheritanceModifier.None &&
              base.TokenStream.Peek().Type == TokenType.Abstract)
     {
         throw new ParsingException("Duplicate abstract modifier.",
                                    new List <TokenType>());
     }
     else if (modSet.IsStart && base.TokenStream.Peek().Type == TokenType.StartState)
     {
         throw new ParsingException("Duplicate start state modifier.",
                                    new List <TokenType>());
     }
     else if (modSet.IsHot && base.TokenStream.Peek().Type == TokenType.HotState)
     {
         throw new ParsingException("Duplicate hot state liveness modifier.",
                                    new List <TokenType>());
     }
     else if (modSet.IsCold && base.TokenStream.Peek().Type == TokenType.ColdState)
     {
         throw new ParsingException("Duplicate cold state liveness modifier.",
                                    new List <TokenType>());
     }
     else if ((modSet.IsCold && base.TokenStream.Peek().Type == TokenType.HotState) ||
              (modSet.IsHot && base.TokenStream.Peek().Type == TokenType.ColdState))
     {
         throw new ParsingException("More than one state liveness modifier.",
                                    new List <TokenType>());
     }
     else if (modSet.IsAsync && base.TokenStream.Peek().Type == TokenType.Async)
     {
         throw new ParsingException("Duplicate async modifier.",
                                    new List <TokenType>());
     }
     else if (modSet.IsPartial && base.TokenStream.Peek().Type == TokenType.Partial)
     {
         throw new ParsingException("Duplicate partial modifier.",
                                    new List <TokenType>());
     }
 }
Esempio n. 19
0
        public HeartAttackSickness() : base(ID, SicknessType.Ailment, Severity.Critical, 0.00025f, new List <InfectionVector> {
            InfectionVector.Exposure
        }, DISEASE.DURATION.NORMAL)
        {
            fatalityDuration = 0.5f * Constants.SECONDS_PER_CYCLE;

            // понижение атрибутов
            LocString name = STRINGS.DUPLICANTS.DISEASES.HEARTATTACKSICKNESS.NAME;

            AddSicknessComponent(new AttributeModifierSickness(new AttributeModifier[]
            {
                new AttributeModifier(Db.Get().Attributes.Athletics.Id, ATTRIBUTE_PENALTY, name, false, false, true),
                new AttributeModifier(Db.Get().Attributes.Strength.Id, ATTRIBUTE_PENALTY, name, false, false, true),
                new AttributeModifier(Db.Get().Attributes.Digging.Id, ATTRIBUTE_PENALTY, name, false, false, true),
                new AttributeModifier(Db.Get().Attributes.Construction.Id, ATTRIBUTE_PENALTY, name, false, false, true),
                new AttributeModifier(Db.Get().Attributes.Art.Id, ATTRIBUTE_PENALTY, name, false, false, true),
                new AttributeModifier(Db.Get().Attributes.Caring.Id, ATTRIBUTE_PENALTY, name, false, false, true),
                new AttributeModifier(Db.Get().Attributes.Learning.Id, ATTRIBUTE_PENALTY, name, false, false, true),
                new AttributeModifier(Db.Get().Attributes.Machinery.Id, ATTRIBUTE_PENALTY, name, false, false, true),
                new AttributeModifier(Db.Get().Attributes.Cooking.Id, ATTRIBUTE_PENALTY, name, false, false, true),
                new AttributeModifier(Db.Get().Attributes.Botanist.Id, ATTRIBUTE_PENALTY, name, false, false, true),
                new AttributeModifier(Db.Get().Attributes.Ranching.Id, ATTRIBUTE_PENALTY, name, false, false, true),
                new AttributeModifier(Db.Get().Amounts.Stamina.deltaAttribute.Id, ModifierSet.ConvertValue(-100, Units.PerDay), name, false, false, true)
            }));

            // для дополнительного описания симптомов
            AddSicknessComponent(new HeartAttackComponent());

            // анимация :
            AddSicknessComponent(new CommonSickEffectSickness());
            //AddSicknessComponent(new CustomSickEffectSickness("spore_fx_kanim", "working_loop"));

            AddSicknessComponent(new AnimatedSickness(new HashedString[]
            {
                "anim_idle_cold_kanim",
                "anim_loco_run_cold_kanim",
                "anim_loco_walk_cold_kanim"
            }, Db.Get().Expressions.SickCold));

            AddSicknessComponent(new PeriodicEmoteSickness("anim_idle_cold_kanim", new HashedString[]
            {
                "idle_pre",
                "idle_default",
                "idle_pst"
            }, BUILDINGS.WORK_TIME_SECONDS.SHORT_WORK_TIME));
        }
Esempio n. 20
0
        /// <summary>
        /// Visits an event or machine declaration.
        /// </summary>
        /// <param name="parentNode">Node</param>
        private void VisitEventOrMachineDeclaration(NamespaceDeclaration parentNode)
        {
            ModifierSet modSet = ModifierSet.CreateDefault();

            while (!base.TokenStream.Done &&
                   base.TokenStream.Peek().Type != TokenType.EventDecl &&
                   base.TokenStream.Peek().Type != TokenType.MachineDecl &&
                   base.TokenStream.Peek().Type != TokenType.Monitor)
            {
                new ModifierVisitor(base.TokenStream).Visit(modSet);

                base.TokenStream.Index++;
                base.TokenStream.SkipWhiteSpaceAndCommentTokens();
            }

            if (base.TokenStream.Done ||
                (base.TokenStream.Peek().Type != TokenType.EventDecl &&
                 base.TokenStream.Peek().Type != TokenType.MachineDecl &&
                 base.TokenStream.Peek().Type != TokenType.Monitor))
            {
                throw new ParsingException("Expected event, machine or monitor declaration.",
                                           new List <TokenType>
                {
                    TokenType.EventDecl,
                    TokenType.MachineDecl,
                    TokenType.Monitor
                });
            }

            if (base.TokenStream.Peek().Type == TokenType.EventDecl)
            {
                new EventDeclarationVisitor(base.TokenStream).Visit(parentNode, null, modSet);
            }
            else if (base.TokenStream.Peek().Type == TokenType.MachineDecl)
            {
                new MachineDeclarationVisitor(base.TokenStream).Visit(null, parentNode, false, modSet);
            }
            else if (base.TokenStream.Peek().Type == TokenType.Monitor)
            {
                new MachineDeclarationVisitor(base.TokenStream).Visit(null, parentNode, true, modSet);
            }
        }
Esempio n. 21
0
        private static void Postfix(ModifierSet __instance)
        {
            //Klei.AI.Effect resource1 = new Klei.AI.Effect("Ranched", (string)STRINGS.CREATURES.MODIFIERS.RANCHED.NAME, (string)STRINGS.CREATURES.MODIFIERS.RANCHED.TOOLTIP, 1200f, true, true, false, (string)null, 0.0f, (string)null);
            //resource1.Add(new AttributeModifier(Db.Get().Amounts.Wildness.deltaAttribute.Id, -0.09166667f, (string)STRINGS.CREATURES.MODIFIERS.RANCHED.NAME, false, false, true));
            //__instance.effects.Remove("Ranched");
            //for (int i = 0; i < __instance.effects.Count; i++)
            //{
            //    Klei.AI.Effect effect = (Klei.AI.Effect)__instance.effects.GetResource(i);
            //    if (effect == null)
            //    {
            //        Debug.LogWarning("CRITICAL");
            //        continue;
            //    }
            //    if (effect.Id == "Ranched")
            //        effect.duration = 1200f;
            //}
            //__instance.effects.Add(resource1);

            __instance.effects.Get("Ranched").duration = 60000f;
        }
Esempio n. 22
0
        /// <summary>
        /// Visits an event or machine declaration.
        /// </summary>
        /// <param name="parentNode">Node</param>
        /// <param name="tokenRange">The range of accumulated tokens</param>
        private void VisitEventOrMachineDeclaration(NamespaceDeclaration parentNode, TokenRange tokenRange)
        {
            ModifierSet modSet = ModifierSet.CreateDefault();

            while (!this.TokenStream.Done &&
                   this.TokenStream.Peek().Type != TokenType.EventDecl &&
                   this.TokenStream.Peek().Type != TokenType.MachineDecl &&
                   this.TokenStream.Peek().Type != TokenType.MonitorDecl)
            {
                new ModifierVisitor(this.TokenStream).Visit(modSet);

                this.TokenStream.Index++;
                this.TokenStream.SkipWhiteSpaceAndCommentTokens();
            }

            if (this.TokenStream.Done ||
                (this.TokenStream.Peek().Type != TokenType.EventDecl &&
                 this.TokenStream.Peek().Type != TokenType.MachineDecl &&
                 this.TokenStream.Peek().Type != TokenType.MonitorDecl))
            {
                throw new ParsingException("Expected event, machine or monitor declaration.", this.TokenStream.Peek(),
                                           TokenType.EventDecl,
                                           TokenType.MachineDecl,
                                           TokenType.MonitorDecl);
            }

            if (this.TokenStream.Peek().Type == TokenType.EventDecl)
            {
                new EventDeclarationVisitor(this.TokenStream).Visit(parentNode, null, modSet);
            }
            else if (this.TokenStream.Peek().Type == TokenType.MachineDecl)
            {
                new MachineDeclarationVisitor(this.TokenStream).Visit(parentNode, false, modSet, tokenRange.Start());
            }
            else if (this.TokenStream.Peek().Type == TokenType.MonitorDecl)
            {
                new MachineDeclarationVisitor(this.TokenStream).Visit(parentNode, true, modSet, tokenRange.Start());
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Visits a group level declaration.
        /// </summary>
        /// <param name="parentNode">Node</param>
        private void VisitGroupLevelDeclaration(StateGroupDeclaration parentNode)
        {
            ModifierSet modSet = ModifierSet.CreateDefault();

            while (!base.TokenStream.Done &&
                   base.TokenStream.Peek().Type != TokenType.StateDecl &&
                   base.TokenStream.Peek().Type != TokenType.StateGroupDecl &&
                   base.TokenStream.Peek().Type != TokenType.MachineDecl)
            {
                new ModifierVisitor(base.TokenStream).Visit(modSet);

                base.TokenStream.Index++;
                base.TokenStream.SkipWhiteSpaceAndCommentTokens();
            }

            if (base.TokenStream.Done ||
                (base.TokenStream.Peek().Type != TokenType.StateDecl &&
                 base.TokenStream.Peek().Type != TokenType.StateGroupDecl))
            {
                throw new ParsingException("Expected state or group declaration.",
                                           new List <TokenType>
                {
                    TokenType.StateDecl,
                    TokenType.StateGroupDecl
                });
            }

            if (base.TokenStream.Peek().Type == TokenType.StateDecl)
            {
                new StateDeclarationVisitor(base.TokenStream).Visit(parentNode.Machine, parentNode, modSet);
            }
            else if (base.TokenStream.Peek().Type == TokenType.StateGroupDecl)
            {
                new StateGroupDeclarationVisitor(base.TokenStream).Visit(parentNode.Machine, parentNode, modSet);
            }
        }
        /// <summary>
        /// Visits the syntax node.
        /// </summary>
        internal void Visit(MachineDeclaration parentNode, StateGroupDeclaration groupNode, ModifierSet modSet, TokenRange tokenRange)
        {
            this.CheckStateGroupModifierSet(modSet);

            var node = new StateGroupDeclaration(this.TokenStream.Program, parentNode, groupNode);

            node.AccessModifier    = modSet.AccessModifier;
            node.StateGroupKeyword = this.TokenStream.Peek();

            this.TokenStream.Index++;
            this.TokenStream.SkipWhiteSpaceAndCommentTokens();

            if (this.TokenStream.Done ||
                this.TokenStream.Peek().Type != TokenType.Identifier)
            {
                throw new ParsingException("Expected state group identifier.", this.TokenStream.Peek(), TokenType.Identifier);
            }

            this.TokenStream.Swap(TokenType.StateGroupIdentifier);
            node.Identifier       = this.TokenStream.Peek();
            node.HeaderTokenRange = tokenRange.FinishAndClone();

            this.TokenStream.Index++;
            this.TokenStream.SkipWhiteSpaceAndCommentTokens();

            if (this.TokenStream.Done ||
                this.TokenStream.Peek().Type != TokenType.LeftCurlyBracket)
            {
                throw new ParsingException("Expected \"{\".", this.TokenStream.Peek(), TokenType.LeftCurlyBracket);
            }

            this.TokenStream.Swap(TokenType.StateGroupLeftCurlyBracket);

            node.LeftCurlyBracketToken = this.TokenStream.Peek();

            this.TokenStream.Index++;
            this.TokenStream.SkipWhiteSpaceAndCommentTokens();

            this.VisitNextPSharpIntraGroupDeclaration(node);

            if (groupNode is null)
            {
                parentNode.StateGroupDeclarations.Add(node);
            }
            else
            {
                groupNode.StateGroupDeclarations.Add(node);
            }

            var stateDeclarations = node.GetAllStateDeclarations();

            if (stateDeclarations.Count == 0)
            {
                throw new ParsingException("A state group must declare at least one state.", this.TokenStream.Peek());
            }
        }
Esempio n. 25
0
        /// <summary>
        /// Visits the syntax node.
        /// </summary>
        /// <param name="parentNode">Containing machine</param>
        /// <param name="groupNode">Containing group</param>
        /// <param name="modSet">Modifier set</param>
        internal void Visit(MachineDeclaration parentNode, StateGroupDeclaration groupNode, ModifierSet modSet)
        {
            this.CheckMachineStateModifierSet(modSet);

            var node = new StateDeclaration(base.TokenStream.Program, parentNode, groupNode, modSet);

            node.StateKeyword = base.TokenStream.Peek();

            base.TokenStream.Index++;
            base.TokenStream.SkipWhiteSpaceAndCommentTokens();

            if (base.TokenStream.Done ||
                base.TokenStream.Peek().Type != TokenType.Identifier)
            {
                throw new ParsingException("Expected state identifier.",
                                           new List <TokenType>
                {
                    TokenType.Identifier
                });
            }

            base.TokenStream.Swap(new Token(base.TokenStream.Peek().TextUnit,
                                            TokenType.StateIdentifier));

            node.Identifier = base.TokenStream.Peek();

            base.TokenStream.Index++;
            base.TokenStream.SkipWhiteSpaceAndCommentTokens();

            if (base.TokenStream.Done ||
                base.TokenStream.Peek().Type != TokenType.LeftCurlyBracket)
            {
                throw new ParsingException("Expected \"{\".",
                                           new List <TokenType>
                {
                    TokenType.LeftCurlyBracket
                });
            }

            base.TokenStream.Swap(new Token(base.TokenStream.Peek().TextUnit,
                                            TokenType.StateLeftCurlyBracket));

            node.LeftCurlyBracketToken = base.TokenStream.Peek();

            base.TokenStream.Index++;
            base.TokenStream.SkipWhiteSpaceAndCommentTokens();

            if (base.TokenStream.Program is PSharpProgram)
            {
                this.VisitNextPSharpIntraStateDeclaration(node);
            }
            else
            {
                this.VisitNextPIntraStateDeclaration(node);
            }

            // Insert into (immediately) containing group or machine declaration.
            if (groupNode != null)
            {
                groupNode.StateDeclarations.Add(node);
            }
            else
            {
                parentNode.StateDeclarations.Add(node);
            }
        }
Esempio n. 26
0
        /// <summary>
        /// Visits the syntax node.
        /// </summary>
        internal void Visit(NamespaceDeclaration parentNode, bool isMonitor, ModifierSet modSet, TokenRange tokenRange)
        {
            if (isMonitor)
            {
                this.CheckMonitorModifierSet(modSet);
            }
            else
            {
                this.CheckMachineModifierSet(modSet);
            }

            var node = new MachineDeclaration(this.TokenStream.Program, parentNode, isMonitor, modSet);

            node.MachineKeyword = this.TokenStream.Peek();

            this.TokenStream.Index++;
            this.TokenStream.SkipWhiteSpaceAndCommentTokens();

            if (this.TokenStream.Done ||
                this.TokenStream.Peek().Type != TokenType.Identifier)
            {
                throw new ParsingException("Expected machine identifier.", this.TokenStream.Peek(), TokenType.Identifier);
            }

            this.TokenStream.Swap(TokenType.MachineIdentifier);

            node.Identifier       = this.TokenStream.Peek();
            node.HeaderTokenRange = tokenRange.FinishAndClone();

            this.TokenStream.Index++;
            this.TokenStream.SkipWhiteSpaceAndCommentTokens();

            var nameVisitor = new NameVisitor(this.TokenStream);

            node.TemplateParameters = nameVisitor.ConsumeTemplateParams();

            if (this.TokenStream.Program is PSharpProgram)
            {
                if (this.TokenStream.Done ||
                    (this.TokenStream.Peek().Type != TokenType.Colon &&
                     this.TokenStream.Peek().Type != TokenType.LeftCurlyBracket))
                {
                    throw new ParsingException("Expected \":\" or \"{\".", this.TokenStream.Peek(), TokenType.Colon, TokenType.LeftCurlyBracket);
                }

                if (this.TokenStream.Peek().Type == TokenType.Colon)
                {
                    node.ColonToken = this.TokenStream.Peek();

                    this.TokenStream.Index++;
                    this.TokenStream.SkipWhiteSpaceAndCommentTokens();

                    var baseNameTokensVisitor = new NameVisitor(this.TokenStream, node.HeaderTokenRange);
                    node.BaseNameTokens = baseNameTokensVisitor.ConsumeGenericName(TokenType.MachineIdentifier);
                }
            }

            if (this.TokenStream.Done ||
                this.TokenStream.Peek().Type != TokenType.LeftCurlyBracket)
            {
                throw new ParsingException("Expected \"{\".", this.TokenStream.Peek(), TokenType.LeftCurlyBracket);
            }

            this.TokenStream.Swap(TokenType.MachineLeftCurlyBracket);

            node.LeftCurlyBracketToken = this.TokenStream.Peek();

            this.TokenStream.Index++;
            this.TokenStream.SkipWhiteSpaceAndCommentTokens();

            this.VisitNextPSharpIntraMachineDeclaration(node);
            parentNode.MachineDeclarations.Add(node);

            var stateDeclarations = node.GetAllStateDeclarations();

            if (stateDeclarations.Count == 0 && node.BaseNameTokens.Count == 0)
            {
                throw new ParsingException("A machine must declare at least one state.", this.TokenStream.Peek());
            }

            var startStates = stateDeclarations.FindAll(s => s.IsStart);

            if (startStates.Count == 0 && node.BaseNameTokens.Count == 0)
            {
                throw new ParsingException("A machine must declare a start state.", this.TokenStream.Peek());
            }
            else if (startStates.Count > 1)
            {
                throw new ParsingException("A machine can declare only a single start state.", this.TokenStream.Peek());
            }
        }
Esempio n. 27
0
        /// <summary>
        /// Visits a machine level declaration.
        /// </summary>
        private void VisitMachineLevelDeclaration(MachineDeclaration parentNode, TokenRange tokenRange)
        {
            var modSet = ModifierSet.CreateDefault();

            while (!this.TokenStream.Done &&
                   this.TokenStream.Peek().Type != TokenType.EventDecl &&
                   this.TokenStream.Peek().Type != TokenType.StateDecl &&
                   this.TokenStream.Peek().Type != TokenType.StateGroupDecl &&
                   this.TokenStream.Peek().Type != TokenType.MachineDecl &&
                   this.TokenStream.Peek().Type != TokenType.Void &&
                   this.TokenStream.Peek().Type != TokenType.Object &&
                   this.TokenStream.Peek().Type != TokenType.String &&
                   this.TokenStream.Peek().Type != TokenType.Sbyte &&
                   this.TokenStream.Peek().Type != TokenType.Byte &&
                   this.TokenStream.Peek().Type != TokenType.Short &&
                   this.TokenStream.Peek().Type != TokenType.Ushort &&
                   this.TokenStream.Peek().Type != TokenType.Int &&
                   this.TokenStream.Peek().Type != TokenType.Uint &&
                   this.TokenStream.Peek().Type != TokenType.Long &&
                   this.TokenStream.Peek().Type != TokenType.Ulong &&
                   this.TokenStream.Peek().Type != TokenType.Char &&
                   this.TokenStream.Peek().Type != TokenType.Bool &&
                   this.TokenStream.Peek().Type != TokenType.Decimal &&
                   this.TokenStream.Peek().Type != TokenType.Float &&
                   this.TokenStream.Peek().Type != TokenType.Double &&
                   this.TokenStream.Peek().Type != TokenType.Identifier)
            {
                new ModifierVisitor(this.TokenStream).Visit(modSet);

                this.TokenStream.Index++;
                this.TokenStream.SkipWhiteSpaceAndCommentTokens();
            }

            if (this.TokenStream.Done ||
                (this.TokenStream.Peek().Type != TokenType.EventDecl &&
                 this.TokenStream.Peek().Type != TokenType.StateDecl &&
                 this.TokenStream.Peek().Type != TokenType.StateGroupDecl &&
                 this.TokenStream.Peek().Type != TokenType.MachineDecl &&
                 this.TokenStream.Peek().Type != TokenType.Void &&
                 this.TokenStream.Peek().Type != TokenType.Object &&
                 this.TokenStream.Peek().Type != TokenType.String &&
                 this.TokenStream.Peek().Type != TokenType.Sbyte &&
                 this.TokenStream.Peek().Type != TokenType.Byte &&
                 this.TokenStream.Peek().Type != TokenType.Short &&
                 this.TokenStream.Peek().Type != TokenType.Ushort &&
                 this.TokenStream.Peek().Type != TokenType.Int &&
                 this.TokenStream.Peek().Type != TokenType.Uint &&
                 this.TokenStream.Peek().Type != TokenType.Long &&
                 this.TokenStream.Peek().Type != TokenType.Ulong &&
                 this.TokenStream.Peek().Type != TokenType.Char &&
                 this.TokenStream.Peek().Type != TokenType.Bool &&
                 this.TokenStream.Peek().Type != TokenType.Decimal &&
                 this.TokenStream.Peek().Type != TokenType.Float &&
                 this.TokenStream.Peek().Type != TokenType.Double &&
                 this.TokenStream.Peek().Type != TokenType.Identifier))
            {
                throw new ParsingException("Expected event, state, group or method declaration.", this.TokenStream.Peek(),
                                           TokenType.EventDecl,
                                           TokenType.StateDecl,
                                           TokenType.StateGroupDecl,
                                           TokenType.MachineDecl,
                                           TokenType.Void,
                                           TokenType.Object,
                                           TokenType.String,
                                           TokenType.Sbyte,
                                           TokenType.Byte,
                                           TokenType.Short,
                                           TokenType.Ushort,
                                           TokenType.Int,
                                           TokenType.Uint,
                                           TokenType.Long,
                                           TokenType.Ulong,
                                           TokenType.Char,
                                           TokenType.Bool,
                                           TokenType.Decimal,
                                           TokenType.Float,
                                           TokenType.Double,
                                           TokenType.Identifier);
            }

            if (this.TokenStream.Peek().Type == TokenType.EventDecl)
            {
                new EventDeclarationVisitor(this.TokenStream).Visit(parentNode.Namespace, parentNode, modSet);
            }
            else if (this.TokenStream.Peek().Type == TokenType.StateDecl)
            {
                new StateDeclarationVisitor(this.TokenStream).Visit(parentNode, null, modSet, tokenRange.Start());
            }
            else if (this.TokenStream.Peek().Type == TokenType.StateGroupDecl)
            {
                new StateGroupDeclarationVisitor(this.TokenStream).Visit(parentNode, null, modSet, tokenRange.Start());
            }
            else
            {
                new MachineMemberDeclarationVisitor(this.TokenStream).Visit(parentNode, modSet);
            }
        }
Esempio n. 28
0
 /// <summary>
 /// Visits the syntax node.
 /// </summary>
 /// <param name="namespaceNode">Containing namespace</param>
 /// <param name="machineNode">Containing machine</param>
 /// <param name="modSet">Modifier set</param>
 internal void Visit(NamespaceDeclaration namespaceNode, MachineDeclaration machineNode, ModifierSet modSet)
 {
     this.CheckEventModifierSet(modSet, (machineNode != null));
     var node = VisitEventDeclaration(namespaceNode, machineNode, modSet, isExtern: false);
 }
Esempio n. 29
0
        private EventDeclaration VisitEventDeclaration(NamespaceDeclaration namespaceNode, MachineDeclaration machineNode, ModifierSet modSet, bool isExtern)
        {
            // Lookup or Insert into (immediately) containing namespace or machine declaration.
            var declarations = (machineNode != null) ? machineNode.EventDeclarations : namespaceNode.EventDeclarations;
            var node         = new EventDeclaration(base.TokenStream.Program, machineNode, modSet)
            {
                EventKeyword = base.TokenStream.Peek()
            };

            base.TokenStream.Index++;
            base.TokenStream.SkipWhiteSpaceAndCommentTokens();

            if (base.TokenStream.Done ||
                (base.TokenStream.Peek().Type != TokenType.Identifier &&
                 base.TokenStream.Peek().Type != TokenType.HaltEvent &&
                 base.TokenStream.Peek().Type != TokenType.DefaultEvent))
            {
                throw new ParsingException("Expected event identifier.",
                                           new List <TokenType>
                {
                    TokenType.Identifier,
                    TokenType.HaltEvent,
                    TokenType.DefaultEvent
                });
            }

            node.Identifier = NameVisitor.VisitSimpleQualifiedName(base.TokenStream, TokenType.EventIdentifier);

            if (declarations.Find(node.Identifier.Text, out var existingDecl))
            {
                var details = existingDecl.IsExtern ? "declared \"extern\"" : "defined";
                throw new ParsingException($"Event {node.Identifier.Text} has already been {details} earlier in this file.",
                                           new List <TokenType> {
                });
            }

            if (base.TokenStream.Done ||
                (base.TokenStream.Peek().Type != TokenType.Assert &&
                 base.TokenStream.Peek().Type != TokenType.Assume &&
                 base.TokenStream.Peek().Type != TokenType.LeftAngleBracket &&
                 base.TokenStream.Peek().Type != TokenType.LeftParenthesis &&
                 base.TokenStream.Peek().Type != TokenType.Colon &&
                 base.TokenStream.Peek().Type != TokenType.Semicolon))
            {
                // TODO: Create an overload of ParsingException ctor that generates the message with a predefined format enum.
                var expectedTokenTypes = new List <TokenType>
                {
                    TokenType.Assert,
                    TokenType.Assume,
                    TokenType.LeftAngleBracket,
                    TokenType.LeftParenthesis,
                    TokenType.Semicolon,
                    TokenType.Colon
                };
                var itemsString = string.Join("\", \"", expectedTokenTypes.Select(l => TokenTypeRegistry.GetText(l)).ToArray());
                throw new ParsingException($"Expected one of: \"{itemsString}\".", expectedTokenTypes);
            }

            VisitGenericType(node);
            VisitBaseEventDeclaration(node, declarations);

            if (base.TokenStream.Done ||
                (base.TokenStream.Peek().Type != TokenType.Assert &&
                 base.TokenStream.Peek().Type != TokenType.Assume &&
                 base.TokenStream.Peek().Type != TokenType.LeftParenthesis &&
                 base.TokenStream.Peek().Type != TokenType.Semicolon))
            {
                throw new ParsingException("Expected \"(\" or \";\".",
                                           new List <TokenType>
                {
                    TokenType.Assert,
                    TokenType.Assume,
                    TokenType.LeftParenthesis,
                    TokenType.Semicolon
                });
            }

            if (base.TokenStream.Peek().Type == TokenType.Assert ||
                base.TokenStream.Peek().Type == TokenType.Assume)
            {
                if (isExtern)
                {
                    throw new ParsingException("\"extern\" cannot have an Assert or Assume specification.",
                                               new List <TokenType> {
                    });
                }
                bool isAssert = true;
                if (base.TokenStream.Peek().Type == TokenType.Assert)
                {
                    node.AssertKeyword = base.TokenStream.Peek();
                }
                else
                {
                    node.AssumeKeyword = base.TokenStream.Peek();
                    isAssert           = false;
                }

                base.TokenStream.Index++;
                base.TokenStream.SkipWhiteSpaceAndCommentTokens();

                if (base.TokenStream.Done ||
                    base.TokenStream.Peek().Type != TokenType.Identifier ||
                    !int.TryParse(base.TokenStream.Peek().TextUnit.Text, out int value))
                {
                    throw new ParsingException("Expected integer.",
                                               new List <TokenType>
                    {
                        TokenType.Identifier
                    });
                }

                if (isAssert)
                {
                    node.AssertValue = value;
                }
                else
                {
                    node.AssumeValue = value;
                }

                base.TokenStream.Index++;
                base.TokenStream.SkipWhiteSpaceAndCommentTokens();

                if (base.TokenStream.Done ||
                    (base.TokenStream.Peek().Type != TokenType.LeftParenthesis &&
                     base.TokenStream.Peek().Type != TokenType.Semicolon))
                {
                    throw new ParsingException("Expected \"(\" or \";\".",
                                               new List <TokenType>
                    {
                        TokenType.LeftParenthesis,
                        TokenType.Semicolon
                    });
                }
            }

            if (base.TokenStream.Peek().Type == TokenType.LeftParenthesis)
            {
                node.LeftParenthesis = base.TokenStream.Peek();

                base.TokenStream.Index++;
                base.TokenStream.SkipWhiteSpaceAndCommentTokens();

                bool isType = false;
                while (!base.TokenStream.Done &&
                       base.TokenStream.Peek().Type != TokenType.RightParenthesis)
                {
                    if (isType &&
                        base.TokenStream.Peek().Type != TokenType.Colon &&
                        base.TokenStream.Peek().Type != TokenType.Comma)
                    {
                        TextUnit textUnit = null;
                        new TypeIdentifierVisitor(base.TokenStream).Visit(ref textUnit);
                        var typeIdentifier = new Token(textUnit, TokenType.TypeIdentifier);
                        node.PayloadTypes.Add(typeIdentifier);
                    }
                    else if (base.TokenStream.Peek().Type != TokenType.Colon &&
                             base.TokenStream.Peek().Type != TokenType.Comma)
                    {
                        node.PayloadIdentifiers.Add(base.TokenStream.Peek());

                        isType = true;
                        base.TokenStream.Index++;
                        base.TokenStream.SkipWhiteSpaceAndCommentTokens();
                    }

                    if (!base.TokenStream.Done)
                    {
                        if (base.TokenStream.Peek().Type == TokenType.Comma)
                        {
                            isType = false;
                            base.TokenStream.Index++;
                            base.TokenStream.SkipWhiteSpaceAndCommentTokens();
                        }
                        else if (base.TokenStream.Peek().Type == TokenType.Colon)
                        {
                            base.TokenStream.Index++;
                            base.TokenStream.SkipWhiteSpaceAndCommentTokens();
                        }
                    }
                }

                if (node.PayloadIdentifiers.Count != node.PayloadTypes.Count)
                {
                    throw new ParsingException("The payload type of event '" + node.Identifier.TextUnit.Text +
                                               "' was not declared correctly.\n" +
                                               "  You must declare both a type and a name identifier, for example:\n\n" +
                                               "    event e (a:int, b:bool)\n",
                                               new List <TokenType>
                    {
                        TokenType.RightParenthesis
                    });
                }

                if (base.TokenStream.Done ||
                    base.TokenStream.Peek().Type != TokenType.RightParenthesis)
                {
                    throw new ParsingException("Expected \")\".",
                                               new List <TokenType>
                    {
                        TokenType.RightParenthesis
                    });
                }

                node.RightParenthesis = base.TokenStream.Peek();

                base.TokenStream.Index++;
                base.TokenStream.SkipWhiteSpaceAndCommentTokens();
            }

            if (base.TokenStream.Done ||
                base.TokenStream.Peek().Type != TokenType.Semicolon)
            {
                throw new ParsingException("Expected \";\".",
                                           new List <TokenType>
                {
                    TokenType.Semicolon
                });
            }

            node.SemicolonToken = base.TokenStream.Peek();
            declarations.Add(node, isExtern);
            return(node);
        }
Esempio n. 30
0
        /// <summary>
        /// Visits the syntax node.
        /// </summary>
        /// <param name="program">Program</param>
        /// <param name="parentNode">Node</param>
        /// <param name="isMonitor">Is a monitor</param>
        /// <param name="modSet">Modifier set</param>
        internal void Visit(IPSharpProgram program, NamespaceDeclaration parentNode, bool isMonitor, ModifierSet modSet)
        {
            if (isMonitor)
            {
                this.CheckMonitorModifierSet(modSet);
            }
            else
            {
                this.CheckMachineModifierSet(modSet);
            }

            var node = new MachineDeclaration(base.TokenStream.Program, parentNode, isMonitor, modSet);

            node.MachineKeyword = base.TokenStream.Peek();

            base.TokenStream.Index++;
            base.TokenStream.SkipWhiteSpaceAndCommentTokens();

            if (base.TokenStream.Done ||
                base.TokenStream.Peek().Type != TokenType.Identifier)
            {
                throw new ParsingException("Expected machine identifier.",
                                           new List <TokenType>
                {
                    TokenType.Identifier
                });
            }

            base.TokenStream.Swap(new Token(base.TokenStream.Peek().TextUnit,
                                            TokenType.MachineIdentifier));

            node.Identifier = base.TokenStream.Peek();

            base.TokenStream.Index++;
            base.TokenStream.SkipWhiteSpaceAndCommentTokens();

            if (base.TokenStream.Program is PSharpProgram)
            {
                if (base.TokenStream.Done ||
                    (base.TokenStream.Peek().Type != TokenType.Colon &&
                     base.TokenStream.Peek().Type != TokenType.LeftCurlyBracket))
                {
                    throw new ParsingException("Expected \":\" or \"{\".",
                                               new List <TokenType>
                    {
                        TokenType.Colon,
                        TokenType.LeftCurlyBracket
                    });
                }

                if (base.TokenStream.Peek().Type == TokenType.Colon)
                {
                    node.ColonToken = base.TokenStream.Peek();

                    base.TokenStream.Index++;
                    base.TokenStream.SkipWhiteSpaceAndCommentTokens();

                    if (base.TokenStream.Done ||
                        base.TokenStream.Peek().Type != TokenType.Identifier)
                    {
                        throw new ParsingException("Expected base machine identifier.",
                                                   new List <TokenType>
                        {
                            TokenType.Identifier
                        });
                    }

                    while (!base.TokenStream.Done &&
                           base.TokenStream.Peek().Type != TokenType.LeftCurlyBracket)
                    {
                        if (base.TokenStream.Peek().Type != TokenType.Identifier &&
                            base.TokenStream.Peek().Type != TokenType.Dot &&
                            base.TokenStream.Peek().Type != TokenType.NewLine)
                        {
                            throw new ParsingException("Expected base machine identifier.",
                                                       new List <TokenType>
                            {
                                TokenType.Identifier,
                                TokenType.Dot
                            });
                        }
                        else
                        {
                            node.BaseNameTokens.Add(base.TokenStream.Peek());
                        }

                        base.TokenStream.Index++;
                        base.TokenStream.SkipWhiteSpaceAndCommentTokens();
                    }
                }
            }

            if (base.TokenStream.Done ||
                base.TokenStream.Peek().Type != TokenType.LeftCurlyBracket)
            {
                throw new ParsingException("Expected \"{\".",
                                           new List <TokenType>
                {
                    TokenType.LeftCurlyBracket
                });
            }

            base.TokenStream.Swap(new Token(base.TokenStream.Peek().TextUnit,
                                            TokenType.MachineLeftCurlyBracket));

            node.LeftCurlyBracketToken = base.TokenStream.Peek();

            base.TokenStream.Index++;
            base.TokenStream.SkipWhiteSpaceAndCommentTokens();

            this.VisitNextPSharpIntraMachineDeclaration(node);
            parentNode.MachineDeclarations.Add(node);

            var stateDeclarations = node.GetAllStateDeclarations();

            if (stateDeclarations.Count == 0 && node.BaseNameTokens.Count == 0)
            {
                throw new ParsingException("A machine must declare at least one state.",
                                           new List <TokenType>());
            }

            var startStates = stateDeclarations.FindAll(s => s.IsStart);

            if (startStates.Count == 0 && node.BaseNameTokens.Count == 0)
            {
                throw new ParsingException("A machine must declare a start state.",
                                           new List <TokenType>());
            }
            else if (startStates.Count > 1)
            {
                throw new ParsingException("A machine can declare only a single start state.",
                                           new List <TokenType>());
            }
        }