コード例 #1
0
        private Cobject ParseObject(Cursor <Cobject> current)
        {
            if (TryParseSequence(current, out var sequence))
            {
                return(sequence);
            }

            if (TryParseDefiner(current, out var binder))
            {
                return(binder);
            }

            if (TryParseAssigner(current, out var assigner))
            {
                return(assigner);
            }

            if (current.Item is Symbol symbol && current.Next && Equals(current.Next.Item, Symbol.ToBind))
            {
                current.Advance();  // symbol
                current.Advance();  // ':='

                var value = ParseObject(current);

                return(Special.Define(symbol, value));
            }

            if (Equals(current.Item, Symbol.Quoter))
            {
                current.Advance();
                if (!current)
                {
                    throw new ParserException($"dangling `{Symbol.Quoter}´ at end of input");
                }

                return(SequenceLiteral.Quote(ParseObject(current)));
            }

            if (Equals(current.Item, Symbol.RightParent))
            {
                throw new ParserException($"unbalanced `{Symbol.RightParent}´ in input");
            }

            var @object = current.Item;

            current.Advance();

            return(@object);
        }