コード例 #1
0
        private static bool IntegerTerminatorPredicate(char c)
        {
            if (LexingHelper.IsInlineWhiteSpaceOrCaretControl(c))
            {
                return(true);
            }

            if (TinyLispHelper.IsPunctuation(c))
            {
                return(true);
            }

            return(false);
        }
コード例 #2
0
        public static PseudoList GetAllKeywordArguments(
            this Element shouldBePseudoList,
            string argumentName,
            bool absenceIsAllowed = false)
        {
            if (shouldBePseudoList == null)
            {
                throw new ArgumentNullException(nameof(shouldBePseudoList));
            }

            var list = shouldBePseudoList as PseudoList;

            if (list == null)
            {
                throw new ArgumentException(
                          $"Argument is not of type '{typeof(PseudoList).FullName}'.",
                          nameof(shouldBePseudoList));
            }

            if (argumentName == null)
            {
                throw new ArgumentNullException(nameof(argumentName));
            }

            if (!TinyLispHelper.IsValidSymbolName(argumentName, true))
            {
                throw new ArgumentException($"'{argumentName}' is not a valid keyword.", nameof(argumentName));
            }

            var wantedKeyword = Symbol.Create(argumentName);
            var index         = list.FindFirstIndex(wantedKeyword);

            if (index == -1)
            {
                if (absenceIsAllowed)
                {
                    return(new PseudoList()); // empty
                }
                else
                {
                    throw new TinyLispException($"No argument for keyword '{argumentName}'.");
                }
            }

            index++; // move forward from keyword.
            var startIndex = index;

            while (true)
            {
                if (index == list.Count)
                {
                    break;
                }

                var element = list[index];
                if (element is Keyword)
                {
                    break;
                }

                index++;
            }

            var lastIndex = index - 1;

            var result = new PseudoList();

            for (var i = startIndex; i <= lastIndex; i++)
            {
                result.AddElement(list[i]);
            }

            return(result);
        }
コード例 #3
0
        public static Element GetSingleKeywordArgument(
            this Element shouldBePseudoList,
            string argumentName,
            bool absenceIsAllowed = false)
        {
            if (shouldBePseudoList == null)
            {
                throw new ArgumentNullException(nameof(shouldBePseudoList));
            }

            var list = shouldBePseudoList as PseudoList;

            if (list == null)
            {
                throw new ArgumentException(
                          $"Argument is not of type '{typeof(PseudoList).FullName}'.",
                          nameof(shouldBePseudoList));
            }

            if (argumentName == null)
            {
                throw new ArgumentNullException(nameof(argumentName));
            }

            if (!TinyLispHelper.IsValidSymbolName(argumentName, true))
            {
                throw new ArgumentException($"'{argumentName}' is not a valid keyword.", nameof(argumentName));
            }

            var wantedKeyword = Symbol.Create(argumentName);
            int wantedIndex;
            var index = list.FindFirstIndex(wantedKeyword);

            if (index < 0)
            {
                if (absenceIsAllowed)
                {
                    return(null);
                }
                else
                {
                    throw new TinyLispException($"No argument for keyword '{argumentName}'.");
                }
            }
            else
            {
                wantedIndex = index + 1;
            }

            if (wantedIndex == list.Count)
            {
                throw new TinyLispException($"Keyword '{argumentName}' was found, but at the end of the list.");
            }

            var wantedElement = list[wantedIndex];

            if (wantedElement is Keyword)
            {
                throw new TinyLispException($"Keyword '{argumentName}' was found, but next element is a keyword too.");
            }

            return(wantedElement);
        }