public static void Tokenize(Context ctx, diagn.Reporter reporter, H <mod.Unit> hUnit) { var unit = ctx[hUnit]; var src = unit.ReadSource(ctx); var index = 0; unit.tokens = new List <syn.Token>(); while (index < src.Length) { var match = TryMatchFixed(src, index) ?? TryMatchFilter(syn.TokenKind.Whitespace, src, index, IsWhitespace, IsWhitespace) ?? TryMatchFilter(syn.TokenKind.Identifier, src, index, IsIdentifierPrefix, IsIdentifier) ?? TryMatchFilter(syn.TokenKind.Number, src, index, IsNumberPrefix, IsNumber) ?? new Match(src[index].ToString(), syn.TokenKind.Error); var span = new diagn.Span(hUnit, index, index + match.excerpt.Length); if (match.kind == syn.TokenKind.Error) { reporter.Error("unexpected character", new diagn.Caret(span)); } unit.tokens.Add(new syn.Token { span = span, kind = match.kind, excerpt = match.excerpt }); index += match.excerpt.Length; } }
public void AddSpan(diagn.Span span) { if (this.span == null) { this.span = span; } else { this.span += span; } }
private void AddVoidInstruction(int segment, sema.Code.Lvalue destination, diagn.Span span) { if (destination is sema.Code.Lvalue.Discard) { return; } this.code.AddInstruction(segment, new sema.Code.Instruction.CopyLiteralTuple { destination = destination, span = span }); }
private static void ReportDuplicate(Context ctx, diagn.Reporter reporter, diagn.Span newSpan, sema.Namespace.Node originalNode) { var originalSpan = (diagn.Span)null; var originalItemDef = originalNode.item as sema.Namespace.Item.Def; if (originalItemDef != null) { originalSpan = ctx[originalItemDef.def].spanDefName; } if (originalSpan != null) { reporter.Error( "duplicate definition of `" + ctx.names.PrintableFullKeyOf(originalNode) + "`", new diagn.Caret(newSpan), new diagn.Caret(originalSpan, false)); } else { reporter.Error( "duplicate definition of `" + ctx.names.PrintableFullKeyOf(originalNode) + "`", new diagn.Caret(newSpan)); } }