annotate Implab/Automaton/RegularExpressions/RegularExpressionVisitorT.cs @ 273:79110a16cab7 v3

Working on Unity xml configuration: Refactoring in progress
author cin
date Thu, 26 Apr 2018 19:35:01 +0300
parents d5c5db0335ee
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
178
d5c5db0335ee working on JSON parser
cin
parents:
diff changeset
1 using Implab;
d5c5db0335ee working on JSON parser
cin
parents:
diff changeset
2 using System;
d5c5db0335ee working on JSON parser
cin
parents:
diff changeset
3 using System.Collections.Generic;
d5c5db0335ee working on JSON parser
cin
parents:
diff changeset
4 using System.Diagnostics;
d5c5db0335ee working on JSON parser
cin
parents:
diff changeset
5 using System.Linq;
d5c5db0335ee working on JSON parser
cin
parents:
diff changeset
6
d5c5db0335ee working on JSON parser
cin
parents:
diff changeset
7 namespace Implab.Automaton.RegularExpressions {
d5c5db0335ee working on JSON parser
cin
parents:
diff changeset
8 /// <summary>
d5c5db0335ee working on JSON parser
cin
parents:
diff changeset
9 /// </summary>
d5c5db0335ee working on JSON parser
cin
parents:
diff changeset
10 public class RegularExpressionVisitor<TTag> : RegularExpressionVisitor {
d5c5db0335ee working on JSON parser
cin
parents:
diff changeset
11 readonly Dictionary<int, TTag> m_tags = new Dictionary<int, TTag>();
d5c5db0335ee working on JSON parser
cin
parents:
diff changeset
12
d5c5db0335ee working on JSON parser
cin
parents:
diff changeset
13 readonly ITaggedDFABuilder<TTag> m_builder;
d5c5db0335ee working on JSON parser
cin
parents:
diff changeset
14
d5c5db0335ee working on JSON parser
cin
parents:
diff changeset
15 public RegularExpressionVisitor(ITaggedDFABuilder<TTag> builder) : base(builder) {
d5c5db0335ee working on JSON parser
cin
parents:
diff changeset
16 m_builder = builder;
d5c5db0335ee working on JSON parser
cin
parents:
diff changeset
17 }
d5c5db0335ee working on JSON parser
cin
parents:
diff changeset
18
d5c5db0335ee working on JSON parser
cin
parents:
diff changeset
19 public override void Visit(EndToken token) {
d5c5db0335ee working on JSON parser
cin
parents:
diff changeset
20 base.Visit(token);
d5c5db0335ee working on JSON parser
cin
parents:
diff changeset
21 var tagged = token as EndToken<TTag>;
d5c5db0335ee working on JSON parser
cin
parents:
diff changeset
22 if (tagged != null)
d5c5db0335ee working on JSON parser
cin
parents:
diff changeset
23 m_tags.Add(Index, tagged.Tag);
d5c5db0335ee working on JSON parser
cin
parents:
diff changeset
24 }
d5c5db0335ee working on JSON parser
cin
parents:
diff changeset
25
d5c5db0335ee working on JSON parser
cin
parents:
diff changeset
26 protected override void MarkFinalState(HashSet<int> state) {
d5c5db0335ee working on JSON parser
cin
parents:
diff changeset
27 base.MarkFinalState(state);
d5c5db0335ee working on JSON parser
cin
parents:
diff changeset
28 m_builder.SetStateTag(Translate(state), GetStateTags(state));
d5c5db0335ee working on JSON parser
cin
parents:
diff changeset
29 }
d5c5db0335ee working on JSON parser
cin
parents:
diff changeset
30
d5c5db0335ee working on JSON parser
cin
parents:
diff changeset
31 TTag[] GetStateTags(IEnumerable<int> state) {
d5c5db0335ee working on JSON parser
cin
parents:
diff changeset
32 Debug.Assert(state != null);
d5c5db0335ee working on JSON parser
cin
parents:
diff changeset
33 return state.Where(m_tags.ContainsKey).Select(pos => m_tags[pos]).ToArray();
d5c5db0335ee working on JSON parser
cin
parents:
diff changeset
34 }
d5c5db0335ee working on JSON parser
cin
parents:
diff changeset
35
d5c5db0335ee working on JSON parser
cin
parents:
diff changeset
36 }
d5c5db0335ee working on JSON parser
cin
parents:
diff changeset
37 }