aboutsummaryrefslogtreecommitdiffstats
path: root/QtVsTools.RegExpr/expression/RegExprSequence.cs
blob: b4fa6e43414edee38d0178e3481bd2788f01edc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QtVsTools.SyntaxAnalysis
{
    /// <summary>
    /// Sequential composition
    /// </summary>
    public partial class RegExprSequence : RegExpr
    {
        public IEnumerable<RegExpr> Exprs { get; set; }

        protected override IEnumerable<RegExpr> OnRender(RegExpr defaultTokenWs, RegExpr parent,
            StringBuilder pattern, ref RenderMode mode, Stack<Token> tokenStack)
        {
            base.OnRender(defaultTokenWs, parent, pattern, ref mode, tokenStack);
            return Exprs;
        }
    }

    public abstract partial class RegExpr
    {
        public static RegExprSequence Concat(params RegExpr[] rxs)
        {
            return new RegExprSequence
            {
                Exprs = rxs.SelectMany(rx => rx is RegExprSequence sequence
                    ? sequence.Exprs
                    : Items(rx))
            };
        }

        public static RegExprSequence operator &(RegExpr rx1, RegExpr rx2)
        {
            return Concat(rx1, rx2);
        }
    }
}