public new static Zmienna Parsuj(ITokenizer tokenizer)
        {
            Zmienna   zmienna = new Zmienna();
            HCPSToken token   = tokenizer.Next();

            if (token == HCPSToken.Variable)
            {
                zmienna.Nazwa = tokenizer.Value;
                if (tokenizer.Next() == HCPSToken.BlockBegin)
                {
                    while ((token = tokenizer.Next()) != HCPSToken.BlockEnd)
                    {
                        if (token == HCPSToken.Comment)
                        {
                            continue;
                        }
                        SimpleAssignment sa = tokenizer.ReadSimpleAssignment(token, tokenizer.Value);
                        if (sa == null || sa.Left == null || sa.Right == null)
                        {
                            throw new ParsingScriptException(string.Format(UI.Language.Instance.GetString(UI.UIStrings.IncorrectVariableDefinition), zmienna.Nazwa));
                        }
                        switch (sa.Left.ToLowerInvariant())
                        {
                        case "module":
                            zmienna.Modul = sa.Right;
                            break;

                        case "id":
                            zmienna.ID = sa.Right;
                            break;

                        case "direct":
                            zmienna.Kierunek = Utils.KierunekZmiennejFromString(sa.Right);
                            break;

                        case "type":
                            zmienna.Typ = Utils.VariableTypeFromString(sa.Right);
                            break;

                        case "value":
                            zmienna._Wartosc = zmienna._WartoscPoczatkowa = sa.Right;
                            break;

                        case "function":
                            zmienna._funkcjaNazwa = sa.Right;
                            break;

                        default:
                            throw new ParsingScriptException(string.Format(UI.Language.Instance.GetString(UI.UIStrings.InvalidVariableDefinitionProperty), sa.Left, zmienna.Nazwa, tokenizer.GetPosition(tokenizer.Position)));
                        }
                    }
                    zmienna.Check();
                    return(zmienna);

                    throw new ParsingScriptException(string.Format(UI.Language.Instance.GetString(UI.UIStrings.CannotParseVariableDefinition), zmienna.Nazwa));
                }
            }
            throw new ParsingScriptException(string.Format(UI.Language.Instance.GetString(UI.UIStrings.InvalidVariableDefinition), tokenizer.GetPosition(tokenizer.Position)));
        }
Exemple #2
0
        public new static Stala Parsuj(ITokenizer tokenizer)
        {
            Stala     stala = new Stala();
            HCPSToken token = tokenizer.Next();

            if (token == HCPSToken.Variable)
            {
                stala.Nazwa = tokenizer.Value;
                if (tokenizer.Next() == HCPSToken.BlockBegin)
                {
                    while ((token = tokenizer.Next()) != HCPSToken.BlockEnd)
                    {
                        SimpleAssignment sa = tokenizer.ReadSimpleAssignment(token, tokenizer.Value);
                        if (sa == null || sa.Left == null || sa.Right == null)
                        {
                            throw new ParsingScriptException(string.Format(UI.Language.Instance.GetString(UI.UIStrings.IncorrectConstantDefinition), stala.Nazwa));
                        }
                        switch (sa.Left.ToLowerInvariant())
                        {
                        case "type":
                            stala.Typ = Utils.VariableTypeFromString(sa.Right);
                            switch (stala.Typ)
                            {
                            case HomeSimCockpitSDK.VariableType.Bool:
                            case HomeSimCockpitSDK.VariableType.Int:
                            case HomeSimCockpitSDK.VariableType.Double:
                            case HomeSimCockpitSDK.VariableType.String:
                                break;

                            default:
                                throw new ParsingScriptException(string.Format(UI.Language.Instance.GetString(UI.UIStrings.InvalidConstantType), Utils.VariableTypeToString(stala.Typ), stala.Nazwa));
                            }
                            break;

                        case "value":
                            stala._Wartosc = sa.Right;
                            break;

                        default:
                            throw new ParsingScriptException(string.Format(UI.Language.Instance.GetString(UI.UIStrings.InvalidConstantDefinitionProperty), sa.Left, stala.Nazwa, tokenizer.GetPosition(tokenizer.Position)));
                        }
                    }
                    stala.Check();
                    return(stala);
                }
            }
            throw new ParsingScriptException(string.Format(UI.Language.Instance.GetString(UI.UIStrings.CannotParseConstantDefinition), tokenizer.GetPosition(tokenizer.Position)));
        }
Exemple #3
0
        public static IncludeStatement Parsuj(ITokenizer tokenizer)
        {
            IncludeStatement result = new IncludeStatement();
            HCPSToken        token  = tokenizer.Next();

            if (token == HCPSToken.BlockBegin)
            {
                while ((token = tokenizer.Next()) != HCPSToken.BlockEnd)
                {
                    if (token == HCPSToken.Comment)
                    {
                        continue;
                    }
                    SimpleAssignment sa = tokenizer.ReadSimpleAssignment(token, tokenizer.Value);
                    if (sa == null || sa.Left == null || sa.Right == null)
                    {
                        throw new ParsingScriptException(UI.Language.Instance.GetString(UI.UIStrings.IncorrectIncludeDefinition));
                    }
                    switch (sa.Left.ToLowerInvariant())
                    {
                    case "file":
                        result.FilePath = sa.Right;
                        break;

                    case "script":
                        result.ScriptName = sa.Right;
                        break;

                    default:
                        throw new ParsingScriptException(string.Format(UI.Language.Instance.GetString(UI.UIStrings.InvalidIncludePropertyDefinition), sa.Left, tokenizer.GetPosition(tokenizer.Position)));
                    }
                }
                // sprawdzenie czy file i script są różne od null i ""
                if (string.IsNullOrEmpty(result.FilePath) || string.IsNullOrEmpty(result.ScriptName))
                {
                    throw new ParsingScriptException(UI.Language.Instance.GetString(UI.UIStrings.MissingFileOrScriptPropertyInIncludeDefinition));
                }
                return(result);
            }
            throw new ParsingScriptException(string.Format(UI.Language.Instance.GetString(UI.UIStrings.CannotReadIncludeDefinition), tokenizer.GetPosition(tokenizer.Position)));
        }