Пример #1
0
        private static void ParseVariables(List <string> lst)
        {
            string key     = string.Empty;
            string value   = string.Empty;
            string comment = string.Empty;

            foreach (string line in lst)
            {
                string str = line.Trim();

                //_vm.host.WriteLog(str);

                if (UtilIO.SkipLine(str))
                {
                    //_vm.host.WriteLog("Line '" + str + "' skipped.");
                }
                else
                {
                    //_vm.host.WriteLog("Parsing line: '" + str + "'");

                    // look 4 comment
                    int index = line.LastIndexOf(@"//");

                    string[] result = new string[2];

                    if (-1 == index) // no comment
                    {
                        result[0] = line;
                        result[1] = "";
                    }
                    else
                    {
                        result[0] = line.Substring(0, index);
                        result[1] = line.Substring(index, line.Length - index);
                    }

                    if (2 == result.Length)
                    {
                        comment = result[1].Trim();
                    }
                    else
                    {
                        comment = "";
                    }

                    key   = ParseKey(result[0]);
                    value = string.Empty;

                    string tmp = result[0].Replace(key, "");

                    bool write = false;
                    for (int i = 0; i < tmp.Length; ++i)
                    {
                        if (write)
                        {
                            value += tmp[i];
                        }
                        else
                        {
                            if (tmp[i] == '=')
                            {
                                write = true;
                            }
                        }
                    }

                    value = value.Trim();
                    value = value.Substring(1, value.Length - 2);

                    items.Add(key, value);
                    comments.Add(comment);
                }
            }
        }
Пример #2
0
        private static void ProcessLines()
        {
            string line         = string.Empty;
            bool   blockComment = false;

            _lineNum = -1;

            for (int i = 0; i < _lines.Count; ++i)
            {
                ++_lineNum;

                _raw = _lines[i];
                line = _lines[i].Trim();

                if (!blockComment)
                {
                    line = InlineBlockComment(line);
                }

                if (blockComment && line.StartsWith(@"*/"))
                {
                    blockComment = false;
                    continue;
                }

                if (blockComment)
                {
                    continue;
                }

                if (!blockComment && line.StartsWith(@"/*"))
                {
                    blockComment = true;
                    continue;
                }

                if (line.Contains(_ImportEndMark))
                {
                    _script.GoBackToGlobalScope();
                    _LoadedFiles.Pop();
                    _lineNum = _LineNumbers.Pop();
                }

                if (UtilIO.SkipLine(line))
                {
                    if (_bWriteLog)
                    {
                        _vm.host.WriteLog("Skipped\t" + line);
                    }

                    continue;
                }

                if (_bWriteLog)
                {
                    _vm.host.WriteLog("Parsing\t" + line);
                }

                List <string> rawTokens = Tokenizer.Init(line);

                SeparateComment(rawTokens);
                _tokens = Compatibility.CreateTokens(_tokens); // compatibility layer

                ProcessTokens(_lineNum);
            }
        }