예제 #1
0
		/// <summary>
		/// Read char set information.
		/// </summary>
		/// <param name="context"></param>
		private void ReadRangeCharset(LoadContext context) {
			int index = context.ReadIntegerEntry();
			context.ReadIntegerEntry(); // unicode plane
			int rangeCount = context.ReadIntegerEntry();
			context.ReadEmptyEntry(); // reserved
			Debug.Assert(rangeCount == context.EntryCount/2);
			StringBuilder result = new StringBuilder();
			while (context.EntryCount > 0) {
				char ch = (char)context.ReadIntegerEntry();
				char end = (char)context.ReadIntegerEntry();
				while (ch <= end) {
					result.Append(ch++);
				}
			}
			charSetTable[index] = new DfaCharset(this, index, result.ToString());
		}
예제 #2
0
		/// <summary>
		/// Read char set information.
		/// </summary>
		/// <param name="context"></param>
		private void ReadCharset(LoadContext context) {
			int index = context.ReadIntegerEntry();
			charSetTable[index] = new DfaCharset(this, index, context.ReadStringEntry());
		}
예제 #3
0
		/// <summary>
		/// Read char set information.
		/// </summary>
		/// <param name="context"></param>
		private void ReadPackedCharset(LoadContext context) {
			int index = context.ReadIntegerEntry();
			char sequenceStart = (char)context.ReadIntegerEntry();
			char sequenceEnd = (char)context.ReadIntegerEntry();
			StringBuilder result = new StringBuilder(context.ReadStringEntry());
			result.Capacity = result.Length+(sequenceEnd-sequenceStart)+1;
			for (char c = sequenceStart; c <= sequenceEnd; c++) {
				result.Append(c);
			}
			charSetTable[index] = new DfaCharset(this, index, result.ToString());
		}
예제 #4
0
		public static void Pack(BinaryReader input, BinaryWriter output) {
			if (input == null) {
				throw new ArgumentNullException("input");
			}
			if (output == null) {
				throw new ArgumentNullException("output");
			}
			CgtReader reader = new CgtReader(input);
			CgtWriter writer = new CgtWriter(output);
			string header = reader.ReadHeaderString();
			Match headerMatch = FileHeader.Match(header);
			if (headerMatch.Groups["version"].Value != "1.0") {
				throw new FileLoadException("The File Header is invalid or of an unsupported version for packing, only uncompressed V1.0 Compiled Grammar Files are supported");
			}
			writer.WriteHeaderString(header);
			while (reader.HasMoreData()) {
				CgtRecordType recordType = reader.ReadNextRecord();
				switch (recordType) {
				case CgtRecordType.Charsets:
					int index = reader.ReadIntegerEntry();
					string chars = reader.ReadStringEntry();
					DfaCharset charset = new DfaCharset(null, index, chars);
					if (charset.SequenceLength >= 4) {
						writer.WriteNextRecord(CgtRecordType.PackedCharsets, 4);
						writer.WriteIntegerEntry(index);
						writer.WriteIntegerEntry(charset.SequenceStart);
						writer.WriteIntegerEntry(charset.SequenceEnd);
						writer.WriteStringEntry(new string(charset.CharactersExcludingSequence));
					} else {
						writer.WriteNextRecord(CgtRecordType.Charsets, 2);
						writer.WriteIntegerEntry(index);
						writer.WriteStringEntry(chars);
					}
					break;
				default:
					writer.WriteNextRecord(recordType, reader.EntryCount);
					while (reader.EntryCount > 0) {
						reader.CopyEntry(writer);
					}
					break;
				}
			}
			output.Flush();
		}