Beispiel #1
0
        // 1.52a改変部分 (単位の差し替えおよび前置、後置のためのコンフィグ処理)
        public void LoadReplaceFile(string filename)
        {
            var eReader = new EraStreamReader(false);

            if (!eReader.Open(filename))
            {
                return;
            }
            ScriptPosition pos = null;

            try
            {
                string line = null;
                while ((line = eReader.ReadLine()) != null)
                {
                    if (line.Length == 0 || line[0] == ';')
                    {
                        continue;
                    }
                    pos = new ScriptPosition(eReader.Filename, eReader.LineNo, line);
                    var tokens = line.Split(',', ':');
                    if (tokens.Length < 2)
                    {
                        continue;
                    }
                    var itemName = tokens[0].Trim();
                    tokens[1] = line.Substring(tokens[0].Length + 1);
                    if (string.IsNullOrEmpty(tokens[1].Trim()))
                    {
                        continue;
                    }
                    var item = GetReplaceItem(itemName);
                    if (item != null)
                    {
                        item.TryParse(tokens[1]);
                    }
                }
            }
            catch (EmueraException ee)
            {
                ParserMediator.Warn(ee.Message, pos, 1);
            }
            catch (Exception exc)
            {
                ParserMediator.Warn(exc.GetType() + ":" + exc.Message, pos, 1, exc.StackTrace);
            }
            finally
            {
                eReader.Dispose();
            }
        }
Beispiel #2
0
        public VariableToken GetVariableToken(string key, string subKey, bool allowPrivate)
        {
            VariableToken ret = null;

            if (Config.ICVariable)
            {
                key = key.ToUpper();
            }
            if (allowPrivate)
            {
                LogicalLine line = GlobalStatic.Process.GetScaningLine();
                if ((line != null) && (line.ParentLabelLine != null))
                {
                    ret = line.ParentLabelLine.GetPrivateVariable(key);
                    if (ret != null)
                    {
                        if (subKey != null)
                        {
                            throw new CodeEE("プライベート変数" + key + "に対して@が使われました");
                        }
                        return(ret);
                    }
                }
            }
            if (localvarTokenDic.ContainsKey(key))
            {
                if (localvarTokenDic[key].IsForbid)
                {
                    throw new CodeEE("呼び出された変数\"" + key + "\"は設定により使用が禁止されています");
                }
                LogicalLine line = GlobalStatic.Process.GetScaningLine();
                if (string.IsNullOrEmpty(subKey))
                {
                    //システムの入力待ち中にデバッグコマンドからLOCALを呼んだとき。
                    if ((line == null) || (line.ParentLabelLine == null))
                    {
                        throw new CodeEE("実行中の関数が存在しないため" + key + "を取得又は変更できませんでした");
                    }
                    subKey = line.ParentLabelLine.LabelName;
                }
                else
                {
                    ParserMediator.Warn("コード中でローカル変数を@付きで呼ぶことは推奨されません(代わりに*.ERHファイルの利用を検討してください)", line, 1, false, false);
                    if (Config.ICFunction)
                    {
                        subKey = subKey.ToUpper();
                    }
                }
                LocalVariableToken retLocal = localvarTokenDic[key].GetExistLocalVariableToken(subKey);
                if (retLocal == null)
                {
                    retLocal = localvarTokenDic[key].GetNewLocalVariableToken(subKey, line.ParentLabelLine);
                }
                return(retLocal);
            }
            if (varTokenDic.TryGetValue(key, out ret))
            {
                //一文字変数の禁止オプションを考えた名残
                //if (Config.ForbidOneCodeVariable && ret.CanForbid)
                //    throw new CodeEE("設定によりシステム一文字数値変数の使用が禁止されています(呼び出された変数:" + ret.Name +")");
                if (ret.IsForbid)
                {
                    if (!ret.CanForbid)
                    {
                        throw new ExeEE("CanForbidでない変数\"" + ret.Name + "\"にIsForbidがついている");
                    }
                    throw new CodeEE("呼び出された変数\"" + ret.Name + "\"は設定により使用が禁止されています");
                }
                if (subKey != null)
                {
                    throw new CodeEE("ローカル変数でない変数" + key + "に対して@が使われました");
                }
                return(ret);
            }
            if (subKey != null)
            {
                throw new CodeEE("@の使い方が不正です");
            }
            return(null);
        }