Exemple #1
0
        public void Alias(string name, string alias)
        {
            _logs.FindByName(name)
            .Add(_provenance, "Added alias {0}".ToFormat(alias));

            _logs.FindByName(alias)
            .Add(_provenance, "Is an alias for {0}".ToFormat(name));

            _inner.Alias(name, alias);
        }
Exemple #2
0
        public void ReadLine(string text)
        {
            if (text.Trim().IsEmpty())
            {
                return;
            }
            if (text.Trim().StartsWith("#"))
            {
                return;
            }

            var tokens = new Queue <string>(StringTokenizer.Tokenize(text.Replace(',', ' ')));

            if (tokens.Count == 1)
            {
                if (_readerAction == null)
                {
                    throw new InvalidSyntaxException("Not enough tokens in the command line");
                }

                _readerAction(tokens.First());
                return;
            }

            _lastName     = null;
            _readerAction = null;

            if (tokens.Count() < 3)
            {
                throw new InvalidSyntaxException("Not enough tokens in the command line");
            }

            var key  = tokens.Dequeue();
            var verb = tokens.Dequeue();

            if (key == "ordered")
            {
                handleOrderedSet(tokens, verb);
                return;
            }

            // TODO -- time for something more sophisticated here
            if (key == "apply")
            {
                readPolicy(tokens, verb);
                return;
            }

            if (key == "combine")
            {
                readCombination(tokens, verb);
                return;
            }

            switch (verb)
            {
            case "is":
                if (tokens.Count > 1)
                {
                    throw new InvalidSyntaxException("Only one name can appear on the right side of the 'is' verb");
                }
                _registration.Alias(tokens.Dequeue(), key);
                break;

            case "requires":
                tokens.Each(name => _registration.Dependency(key, name));
                break;

            case "extends":
                if (tokens.Count > 1)
                {
                    throw new InvalidSyntaxException("Only one name can appear on the right side of the 'extends' verb");
                }

                _registration.Extension(key, tokens.Single());
                break;

            case "includes":
                tokens.Each(name => _registration.AddToSet(key, name));
                break;

            case "preceeds":
                tokens.Each(name => _registration.Preceeding(key, name));
                break;

            default:
                string message = "'{0}' is an invalid verb".ToFormat(verb);
                throw new InvalidSyntaxException(message);
            }
        }