using Implab;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace Implab.Automaton.RegularExpressions {
///
///
public class RegularExpressionVisitor : RegularExpressionVisitor {
readonly Dictionary m_tags = new Dictionary();
readonly ITaggedDFABuilder m_builder;
public RegularExpressionVisitor(ITaggedDFABuilder builder) : base(builder) {
m_builder = builder;
}
public override void Visit(EndToken token) {
base.Visit(token);
var tagged = token as EndToken;
if (tagged != null)
m_tags.Add(Index, tagged.Tag);
}
protected override void MarkFinalState(HashSet state) {
base.MarkFinalState(state);
m_builder.SetStateTag(Translate(state), GetStateTags(state));
}
TTag[] GetStateTags(IEnumerable state) {
Debug.Assert(state != null);
return state.Where(m_tags.ContainsKey).Select(pos => m_tags[pos]).ToArray();
}
}
}