Exemplo n.º 1
0
        public void ParseComplexList()
        {
            Datum complexList = new ListDatum
                                (
                new Datum[]
            {
                BooleanDatum.True,
                NullDatum.Value,
                new FloatDatum(-3.75),
                new ListDatum
                (
                    new Datum[]
                {
                    BooleanDatum.True,
                    BooleanDatum.False,
                }
                    .ToImmutableList()
                )
            }
                .ToImmutableList()
                                );

            var result = CharParserContext.TryParse
                         (
                Parser.ParseConvert
                (
                    parseDatum,
                    d => DatumEqualityComparer.Instance.Equals(d, complexList),
                    null
                ),
                " ( #t #nil -3.75\r\n (#t #f) )"
                         );

            Assert.AreEqual("{ success, pos = 0, len = 28, value = True }", formatBoolResult(result));
        }
Exemplo n.º 2
0
        public void ParseCharacterList()
        {
            Datum characterList = new ListDatum
                                  (
                new Datum[]
            {
                new CharDatum('a'),
                new CharDatum('\uFEFF'),
                new CharDatum('\n'),
            }
                .ToImmutableList()
                                  );

            var result = CharParserContext.TryParse
                         (
                Parser.ParseConvert
                (
                    parseDatum,
                    d => DatumEqualityComparer.Instance.Equals(d, characterList),
                    null
                ),
                "(#\\a #\\xFEFF #\\newline)"
                         );

            Assert.AreEqual("{ success, pos = 0, len = 23, value = True }", formatBoolResult(result));
        }
Exemplo n.º 3
0
            public Datum Build(ImmutableDictionary <int, MutableBoxDatum> boxes)
            {
                ListDatum result = ListDatum.Empty;

                foreach (IDatumBuilder value in values)
                {
                    result = result.Add(value.Build(boxes));
                }
                return(result);
            }
Exemplo n.º 4
0
        public void ToStringFromSymbols()
        {
            Datum d = new ListDatum
                      (
                new Datum[]
            {
                new SymbolDatum("ImASymbol"),
                new SymbolDatum("me too")
            }
                .ToImmutableList()
                      );

            Assert.AreEqual("(ImASymbol |me too|)", d.ToString());
        }
Exemplo n.º 5
0
        public void ParseQuasiQuoteUnquote()
        {
            Datum d = new ListDatum
                      (
                ImmutableList <Datum> .Empty
                .Add(new SymbolDatum("quasiquote"))
                .Add
                (
                    new ListDatum
                    (
                        ImmutableList <Datum> .Empty
                        .Add(new SymbolDatum("a"))
                        .Add(new SymbolDatum("b"))
                        .Add
                        (
                            new ListDatum
                            (
                                ImmutableList <Datum> .Empty
                                .Add(new SymbolDatum("unquote"))
                                .Add(new SymbolDatum("x"))
                            )
                        )
                        .Add
                        (
                            new ListDatum
                            (
                                ImmutableList <Datum> .Empty
                                .Add(new SymbolDatum("unquote-splicing"))
                                .Add(new SymbolDatum("y"))
                            )
                        )
                    )
                )
                      );

            var result = CharParserContext.TryParse
                         (
                Parser.ParseConvert
                (
                    Parser.ParseDatum,
                    a => DatumEqualityComparer.Instance.Equals(a, d),
                    null
                ),
                " `(a b ,x ,@y)"
                         );

            Assert.AreEqual("{ success, pos = 0, len = 14, value = True }", formatBoolResult(result));
        }
Exemplo n.º 6
0
        public void ToStringFromListOfIntAndRational()
        {
            Datum d = new ListDatum
                      (
                new Datum[]
            {
                new IntDatum(new BigInteger(13)),
                new RationalDatum(new BigRational(new BigInteger(-1), new BigInteger(3))),
                new ListDatum
                (
                    new Datum[]
                {
                    new IntDatum(new BigInteger(20)),
                    new IntDatum(new BigInteger(134))
                }
                    .ToImmutableList()
                )
            }.ToImmutableList()
                      );

            Assert.AreEqual("(13 -1/3 (20 134))", d.ToString());
        }