public CharacterCategory(TaskMaster task_master, SourceReference source_ref, Context context, Frame self, Frame container) : base(task_master) { this.source_reference = source_ref; this.context = context; this.container = self; }
public DbQuery(TaskMaster task_master, SourceReference source_ref, Context context, Frame self, Frame container) : base(task_master) { this.source_ref = source_ref; this.context = context; this.self = self; }
public StringToCodepoints(TaskMaster task_master, SourceReference source_ref, Context context, Frame self, Frame container) : base(task_master) { this.source_reference = source_ref; this.context = context; this.container = self; }
public ParseInt(TaskMaster task_master, SourceReference source_ref, Context context, Frame self, Frame container) : base(task_master) { this.source_reference = source_ref; this.context = context; }
void LookupString(Frame frame, string name, ConsumeString consume) { var lookup = new Lookup(task_master, source_ref, new []{name}, Context.Prepend(frame, null)); lookup.Notify(result => { if (result is Stringish) { var str = result.ToString(); consume(str); } else { task_master.ReportOtherError(source_ref, String.Format("Expected “{0}” to be a string. Got {1} instead.", name, Stringish.NameForType(result.GetType()))); } }); }
void LookupChar(Frame frame, string name, ConsumeChar consume) { LookupString(frame, name, str => { if (str.Length == 1 || str.Length == 2 && Char.IsSurrogatePair(str, 0)) { consume(Char.ConvertToUtf32(str, 0)); } else { task_master.ReportOtherError(source_ref, String.Format("String “{0}” for “{1}” must be a single codepoint.", str, name)); } }); }
void HandleSubstition(Frame spec) { LookupChar(spec, "char", c => { LookupString(spec, "replacement", replacement => { single_substitutions[c] = replacement; if (Interlocked.Decrement(ref interlock) == 0) { task_master.Slot(this); } }); }); }
void HandleRange(Frame spec) { LookupChar(spec, "start", start => { LookupChar(spec, "end", end => { LookupString(spec, "format_str", replacement => { ranges.Add(start, new Range() { start = start, end = end, replacement = replacement }); if (Interlocked.Decrement(ref interlock) == 0) { task_master.Slot(this); } }); }); }); }
public static Frame Through(TaskMaster task_master, long id, SourceReference source_ref, long start, long end, Context context, Frame container) { var result = new Frame(task_master, id, source_ref, context, container); if (end < start) return result; for (long it = 0; it <= (end - start); it++) { result[TaskMaster.OrdinalNameStr(it + 1)] = start + it; } return result; }
protected override bool Run() { if (input == null) { Computation input_lookup = new Lookup(master, source_reference, new []{"arg"}, context); input_lookup.Notify(input_result => { if (input_result is Stringish) { input = input_result.ToString(); if (Interlocked.Decrement(ref interlock) == 0) { master.Slot(this); } } else { master.ReportOtherError(source_reference, "Input argument must be a string."); } }); master.Slot(input_lookup); if (Interlocked.Decrement(ref interlock) > 0) { return false; } } var frame = new Frame(master, master.NextId(), source_reference, context, container); for(int it = 0; it < input.Length; it++) { frame[TaskMaster.OrdinalNameStr(it + 1)] = (long) Char.ConvertToUtf32(input, it); } result = frame; return true; }
public ParseDouble(TaskMaster master, SourceReference source_ref, Context context, Frame self, Frame container) { this.master = master; this.source_reference = source_ref; this.context = context; }
protected override bool Run() { if (!state) { var input_lookup = new Lookup(master, source_ref, new []{"args"}, context); input_lookup.Notify(HandleArgs); master.Slot(input_lookup); var transformation_lookup = new Lookup(master, source_ref, new []{"transformations"}, context); transformation_lookup.Notify(HandleTransformations); master.Slot(transformation_lookup); state = true; if (Interlocked.Decrement(ref interlock) > 0) { return false; } } var output_frame = new Frame(master, master.NextId(), source_ref, context, self); for (var index = 0; index < input.Length; index++) { var buffer = new StringBuilder(); for(var it = 0; it < input[index].Length; it += Char.IsSurrogatePair(input[index], it) ? 2 : 1) { var c = Char.ConvertToUtf32(input[index], it); var is_surrogate = Char.IsSurrogatePair(input[index], it); string replacement; if (single_substitutions.TryGetValue(c, out replacement)) { buffer.Append(replacement); } else { bool matched = false; foreach(var range in ranges.Values) { if (c >= range.start && c <= range.end) { var utf8 = new byte[4]; Encoding.UTF8.GetBytes(input[index], it, is_surrogate ? 2 : 1, utf8, 0); buffer.Append(String.Format(range.replacement, c, (int) input[index][it], is_surrogate ? (int) input[index][it + 1] : 0, (int) utf8[0], (int) utf8[1], (int) utf8[2], (int) utf8[3])); matched = true; break; } } if (!matched) { buffer.Append(Char.ConvertFromUtf32(c)); } } } output_frame[TaskMaster.OrdinalNameStr(index)] = new SimpleStringish(buffer.ToString()); } result = output_frame; return true; }
public Escape(TaskMaster master, SourceReference source_ref, Context context, Frame self, Frame container) { this.master = master; this.source_ref = source_ref; this.context = context; this.self = self; }
public static Context Prepend(Frame head, Context tail) { if (head == null) { throw new InvalidOperationException("Cannot prepend a null frame to a context."); } var list = new List<Frame>(tail == null ? 1 : (tail.Length + 1)); list.Add(head); if (tail != null) { list.AddRange(tail.frames.Where(frame => head != frame)); } return new Context(list); }
public Template(SourceReference source_ref, Context context, Frame container) { SourceReference = source_ref; Context = context; Container = container; }
protected override bool Run() { if (mappings.Count == 0) { interlock = categories.Count + 2; Computation input_lookup = new Lookup(master, source_reference, new []{"arg"}, context); input_lookup.Notify(input_result => { if (input_result is Stringish) { input = input_result.ToString(); if (Interlocked.Decrement(ref interlock) == 0) { master.Slot(this); } } else { master.ReportOtherError(source_reference, "Input argument must be a string."); } }); master.Slot(input_lookup); foreach (var entry in categories) { var lookup = new Lookup(master, source_reference, new []{ entry.Value }, context); lookup.Notify(cat_result => { mappings[entry.Key] = cat_result; if (Interlocked.Decrement(ref interlock) == 0) { master.Slot(this); } }); master.Slot(lookup); } if (Interlocked.Decrement(ref interlock) > 0) { return false; } } var frame = new Frame(master, master.NextId(), source_reference, context, container); for(int it = 0; it < input.Length; it++) { frame[TaskMaster.OrdinalNameStr(it + 1)] = mappings[Char.GetUnicodeCategory(input[it])]; } result = frame; return true; }
public Frame(TaskMaster task_master, long id, SourceReference source_ref, Context context, Frame container) { this.task_master = task_master; SourceReference = source_ref; Context = Context.Prepend(this, context); Container = container ?? this; Id = TaskMaster.OrdinalName(id); }