Example #1
0
        private IReq <ValueNode> Value(ICommentsContext cctx)
        {
            var value = SimpleValue()
                        .Or(Array)
                        .Or(InlineTable)
                        .OrNode(() => SyntaxErrorNode.Unexpected("Expected TOML value", this.input.Current));

            if (this.settings.IsFeautureEnabled(ExperimentalFeature.ValueWithUnit) && value.HasNode)
            {
                var unit = this.input.Accept(t => t.Type == TokenType.BareKey || t.Type == TokenType.Unit)
                           .CreateNode(t => new TerminalNode(t.Trimmed()).Opt());
                if (unit.HasNode)
                {
                    return(value.SyntaxNode().WithUnitAttached(unit));
                }
            }

            return(value);

            IOpt <ValueNode> SimpleValue()
            => this.input
            .Accept(t => t.Type == TokenType.Float ||
                    t.Type == TokenType.Integer ||
                    t.Type == TokenType.HexInteger ||
                    t.Type == TokenType.BinaryInteger ||
                    t.Type == TokenType.OctalInteger ||
                    t.Type == TokenType.Bool ||
                    t.Type == TokenType.LocalDate ||
                    t.Type == TokenType.OffsetDateTime ||
                    t.Type == TokenType.LocalTime ||
                    t.Type == TokenType.LocalDateTime ||
                    t.Type == TokenType.Duration ||
                    t.Type == TokenType.String ||
                    t.Type == TokenType.LiteralString ||
                    t.Type == TokenType.MultilineString ||
                    t.Type == TokenType.MultilineLiteralString)
            .CreateNode(t => ValueNode.CreateTerminalValue(t).Opt());

            IOpt <ValueNode> Array()
            => this.input
            .Accept(t => t.Type == TokenType.LBrac)
            .CreateNode(t => ValueNode.CreateNonTerminalValue(this.Array(t)).Opt());

            IOpt <ValueNode> InlineTable()
            {
                return(this.input
                       .Accept(t => t.Type == TokenType.LCurly)
                       .CreateNode(t => ValueNode.CreateNonTerminalValue(this.InlineTable(t, cctx.Consume())).Opt()));
            }
        }
Example #2
0
        private IReq <ValueNode> Value(ICommentsContext cctx)
        {
            return(SimpleValue()
                   .Or(Array)
                   .Or(InlineTable)
                   .OrNode(() => SyntaxErrorNode.Unexpected("Expected TOML value", this.input.Current)));

            IOpt <ValueNode> SimpleValue()
            => this.input
            .Accept(t => t.Type == TokenType.Float ||
                    t.Type == TokenType.Integer ||
                    t.Type == TokenType.HexInteger ||
                    t.Type == TokenType.BinaryInteger ||
                    t.Type == TokenType.OctalInteger ||
                    t.Type == TokenType.Bool ||
                    t.Type == TokenType.LocalDate ||
                    t.Type == TokenType.OffsetDateTime ||
                    t.Type == TokenType.LocalTime ||
                    t.Type == TokenType.LocalDateTime ||
                    t.Type == TokenType.Duration ||
                    t.Type == TokenType.String ||
                    t.Type == TokenType.LiteralString ||
                    t.Type == TokenType.MultilineString ||
                    t.Type == TokenType.MultilineLiteralString)
            .CreateNode(t => ValueNode.CreateTerminalValue(t).Opt());

            IOpt <ValueNode> Array()
            => this.input
            .Accept(t => t.Type == TokenType.LBrac)
            .CreateNode(t => ValueNode.CreateNonTerminalValue(this.Array(t)).Opt());

            IOpt <ValueNode> InlineTable()
            {
                return(this.input
                       .Accept(t => t.Type == TokenType.LCurly)
                       .CreateNode(t => ValueNode.CreateNonTerminalValue(this.InlineTable(t, cctx.Consume())).Opt()));
            }
        }