Example #1
0
 // 初始化参数
 public void Clear()
 {
     m_file    = null;
     m_factory = null;
     m_regex_skip.Clear();
     m_line_comment_skip.Clear();
     m_block_comment_skip.Clear();
     m_stat          = null;
     m_root          = null;
     m_line_comment  = null;
     m_block_comment = null;
     m_rule.Clear();
     m_symbol_check.Clear();
 }
Example #2
0
        public ABnfNodeElement Analysis(ABnfFile file)
        {
            if (m_root == null)
            {
                return(null);
            }

            // 清空缓存
            m_regex_skip.Clear();
            m_line_comment_skip.Clear();
            m_block_comment_skip.Clear();
            // m_stat = new ABnfRuleStat();
            // 保存字符串
            m_file = file;

            // 初始化位置
            int  line       = 0;
            int  col        = 0;
            int  offset     = 0;
            int  pin_offset = -1;
            bool not_key    = false;

            m_stop_stack.Clear();

            // 创建跟节点,然后开始解析
            var node = CreateNodeElement(line, col, offset, m_root.id.value);

            while (true)
            {
                if (!AnalysisABnfNode(m_root, m_root.node, node, not_key
                                      , ref line, ref col, ref offset
                                      , ref pin_offset, false))
                {
                    if (offset >= m_file.m_text.Length && m_file.m_text.Length > 0)
                    {
                        --offset;
                    }
                }
                else
                {
                    AnalysisSkip(ref line, ref col, ref offset);
                    if (offset >= m_file.m_text.Length)
                    {
                        break;
                    }
                }
                node.AddChild(new ABnfErrorElement(m_factory, m_file, line, col, offset, "语法错误", null));

                // 跳到下一行
                if (!JumpToNextLine(ref line, ref col, ref offset))
                {
                    break;
                }
            }

            if (m_stat != null)
            {
                StatElement(node);
                m_stat.CalcRate();
            }

            // 清空缓存
            m_regex_skip.Clear();
            m_line_comment_skip.Clear();
            m_block_comment_skip.Clear();
            m_stat = null;
            m_file = null;

            // 返回结果
            return(node);
        }