Example #1
0
        //-------------------------------------------//

        /// <summary>
        /// Initialize an element rule with a tag to parse and parameters to return.
        /// </summary>
        public ParseElement(ExtractElement extract)
        {
            _extract = extract;

            // set up the tag section search
            _section = new ExtractSection(new ActionSet <char[]>(OnSection));
            foreach (string tag in _extract.Tags)
            {
                _section.AddPrefix(Chars.LessThan + tag);
                _section.AddSuffix(Chars.ForwardSlash + tag + Chars.GreaterThan);
            }

            // setup the parsing
            _sectionParse = new ParseSection(_section);

            // setup the parameter dynamic search
            if (_extract.GetAttributes != null)
            {
                _attributeGetSearch = new TreeSearch <char, string> .DynamicSearch(_extract.GetAttributes);
            }
            if (_extract.FilterAttributes != null)
            {
                _attributeFilterSearch = new TreeSearch <char, string> .DynamicSearch(_extract.FilterAttributes);

                _attributeFilterCount = _extract.FilterAttributesCount;
            }
        }
Example #2
0
        //-------------------------------------------//

        /// <summary>
        /// Initialize a new scheme parser instance.
        /// </summary>
        public ParseSection(ExtractSection extract)
        {
            _extract = extract;

            // initialize the dynamic searches
            if (_extract.Prefixes != null)
            {
                _prefixSearch = new TreeSearch <char, string> .DynamicSearch(_extract.Prefixes);
            }
            if (_extract.Suffixes != null)
            {
                _suffixSearch = new TreeSearch <char, string> .DynamicSearch(_extract.Suffixes);
            }

            _suffixesSet = _suffixSearch != null;
            _prefixesSet = _prefixSearch != null;

            // initialize the section stack
            Sections          = new ArrayRig <ArrayRig <char> >();
            _currentSection   = new ArrayRig <char>(_prefixesSet ^ _suffixesSet ? _extract.MaxCharacters : 2);
            _activeSubParsers = new ArrayRig <Parse>();

            _subParsersSet = _extract.SubExtracts != null && _extract.SubExtracts.Count != 0;
            _reqParsersSet = _extract.ReqExtracts != null && _extract.ReqExtracts.Count != 0;

            if (_subParsersSet)
            {
                _subParsers = new ArrayRig <Parse>();
                foreach (Extract ext in _extract.SubExtracts)
                {
                    _subParsers.Add(ext.GetParser());
                }
            }
            if (_reqParsersSet)
            {
                _reqParsers = new ArrayRig <Parse>();
                foreach (Extract ext in _extract.ReqExtracts)
                {
                    _reqParsers.Add(ext.GetParser());
                }
            }
        }