123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
-
- namespace Yuuna.Contracts.Patterns
- {
- using System;
- using System.Collections;
- using System.Collections.Concurrent;
- using System.Collections.Generic;
- using System.Collections.Immutable;
- using System.Diagnostics;
- using System.Diagnostics.CodeAnalysis;
- using System.Linq;
- using System.Text;
- using Yuuna.Contracts.Interaction;
- using Yuuna.Contracts.Optimization;
- using Yuuna.Contracts.Semantics;
- internal sealed class PatternBuilder : IGrammarSet, IPatternBuilder
- {
- private readonly ImmutableDictionary<IGrammar, Behaviour>.Builder _rules;
- internal PatternBuilder()
- {
- this._rules = ImmutableDictionary.CreateBuilder<IGrammar, Behaviour>(EqualityComparer<IGrammar>.Default);
- }
- public IImmutableList<IGrammar> ToImmutable()
- {
- return this._rules.Keys.ToImmutableArray();
- }
- public bool TryGet(IGrammar grammar, out Behaviour behaviour)
- {
- return this._rules.TryGetValue(grammar, out behaviour);
- }
- IBehaviourBuilder IPatternBuilder.Build(IGroup group, params IGroup[] rest)
- {
- if (group is null)
- throw new ArgumentNullException(nameof(group));
- var g = new Grammar();
- g.Add(group);
- if (rest != null)
- foreach (var item in rest)
- {
- g.Add(item);
- }
- g.Immute();
- return new BehaviourBuilder(this._rules.Add, g);
- }
- }
- }
|