Beispiel #1
0
        public void Add(string name, Parser definition)
        {
            if (_namespace.Count > 0)
            {
                name = $"{_namespace.Peek()}.{name}";
            }

            NamedParser parser;

            if (_namedParsers.TryGetValue(name, out parser))
            {
                parser.Define(parser.ResolvedParser | definition, parser.CollapseIfSingleElement);
            }
            else
            {
                parser = new NamedParser(name);
                _namedParsers.Add(name, parser);
                parser.Define(definition);
            }
        }
Beispiel #2
0
        public bool ResolveDefinition(NamedParser named)
        {
            if (named.Namespace == null)
            {
                var existing = GetExisting(named.Name);
                if (existing != null)
                {
                    named.ResolvedName = existing.Name;
                    named.Define(existing.ResolvedParser, existing.CollapseIfSingleElement);
                    return(true);
                }

                return(false);
            }

            var splitIndex = named.Namespace.Length;

            while (true)
            {
                var name     = splitIndex <= 0 ? named.Name : $"{named.Namespace.Substring( 0, splitIndex )}.{named.Name}";
                var existing = GetExisting(name);
                if (existing != null)
                {
                    named.ResolvedName = existing.Name;
                    named.Define(existing.ResolvedParser, existing.CollapseIfSingleElement);
                    return(true);
                }
                if (splitIndex <= 0)
                {
                    break;
                }

                splitIndex = named.Namespace.LastIndexOf(".", splitIndex - 1);
            }

            return(false);
        }
Beispiel #3
0
 public Parser this[NamedParser parser]
 {
     get { return(parser); }
     set { parser.Define(value); }
 }