private void WriteAliases(TransitionTable table)
        {
            _writer.Write(table.Aliases.Count);

            foreach (var pair in table.Aliases)
            {
                _writer.Write(pair.Key);
                _writer.Write(pair.Value);
            }
        }
        private void WriteTransitions(TransitionTable table)
        {
            _writer.Write(table.Transitions.Length);

            foreach (var map in table.Transitions)
            {
                _writer.Write(map.Count);
                foreach (var pair in map)
                {
                    _writer.Write(pair.Key);
                    _writer.Write(pair.Value);
                }
            }
        }
Beispiel #3
0
        private string GetAliasesSourceCode(TransitionTable table)
        {
            var sb = new StringBuilder();

            sb.AppendFormat("var aliases = new Dictionary<ushort, string>({0});", table.Aliases.Count);
            sb.AppendLine();

            foreach (var alias in table.Aliases)
            {
                sb.AppendFormat("aliases[{0}] = \"{1}\";", alias.Key, alias.Value);
                sb.AppendLine();
            }

            return(sb.ToString());
        }
Beispiel #4
0
        private string GetTransitionsSourceCode(TransitionTable table)
        {
            var length = table.Transitions.Length;
            var sb     = new StringBuilder();

            sb.AppendFormat("var transitions = new Dictionary<char, ushort>[{0}];", length);
            sb.AppendLine();

            for (ushort index = 0; index < length; index++)
            {
                var states = table.Transitions[index];
                AppendTransitionsSourceCode(sb, index, states);
            }

            return(sb.ToString());
        }
Beispiel #5
0
        public void Write(TransitionTable table)
        {
            _writer.WriteLine("using System.Collections.Generic;");
            _writer.WriteLine();
            _writer.WriteLine("namespace CSharpCompiler.Lexica.Regexp");
            _writer.WriteLine("{");
            _writer.WriteLine("public static class TransitionTableSource");
            _writer.WriteLine("{");
            _writer.WriteLine("public static TransitionTable GetTransitionTable()");
            _writer.WriteLine("{");

            _writer.WriteLine(GetHeadSourceCode(table));
            _writer.WriteLine(GetTransitionsSourceCode(table));
            _writer.WriteLine(GetAliasesSourceCode(table));
            _writer.WriteLine("return new TransitionTable(head, transitions, aliases);");

            _writer.WriteLine("}");
            _writer.WriteLine("}");
            _writer.WriteLine("}");
        }
Beispiel #6
0
 private string GetHeadSourceCode(TransitionTable table)
 {
     return(string.Format("ushort head = {0};", table.Head));
 }
 private void WriteHead(TransitionTable table)
 {
     _writer.Write(table.Head);
 }
 public void Write(TransitionTable table)
 {
     WriteHead(table);
     WriteTransitions(table);
     WriteAliases(table);
 }