public IvyTokenTag(IvyTokenKind kind) { this.Kind = kind; }
public TokenRegion(SnapshotPoint start, SnapshotPoint end, IvyTokenKind kind) { Start = start; End = end; Kind = kind; }
private static SnapshotPoint Scan(string txt, SnapshotPoint start, List <TokenRegion> newRegions, ITextSnapshot newSnapshot) { SnapshotPoint commentStart = new SnapshotPoint(); int N = txt.Length; bool done = false; while (!done) { N = txt.Length; // length of the current buffer int cur = 0; // offset into the current buffer // repeatedly get the remaining tokens from this buffer int end; // offset into the current buffer for (; ; cur = end) { // advance to the first character of a keyword or token IvyTokenKind ty = IvyTokenKind.Keyword; for (; ; cur++) { if (N <= cur) { // we've looked at everything in this buffer goto OUTER_CONTINUE; } char ch = txt[cur]; if ('a' <= ch && ch <= 'z') { break; } if ('A' <= ch && ch <= 'Z') { break; } if ('0' <= ch && ch <= '9') { ty = IvyTokenKind.Number; break; } if (ch == '_' || ch == '?' || ch == '\\') { break; // parts of identifiers } if (ch == '\"') { ty = IvyTokenKind.String; break; } if (ch == '#') { ty = IvyTokenKind.Comment; break; } } // advance to the end of the token end = cur + 1; // offset into the current buffer if (ty == IvyTokenKind.Number) { // scan the rest of this number for (; end < N; end++) { char ch = txt[end]; if ('0' <= ch && ch <= '9' || 'a' <= ch && ch <= 'z' || 'A' <= ch && ch <= 'Z' || ch == '_') { } else { break; } } } else if (ty == IvyTokenKind.String) { // scan the rest of this string, but not past the end-of-buffer for (; end < N; end++) { char ch = txt[end]; if (ch == '\"') { end++; break; } else if (ch == '\\') { // escape sequence end++; if (end == N) { break; } ch = txt[end]; if (ch == 'u') { end += 4; if (N <= end) { end = N; break; } } } } } else if (ty == IvyTokenKind.Comment) { if (end == N) { continue; // this was not the start of a comment; it was just a single "/" and we don't care to color it } char ch = txt[end]; // a short comment, to the end of the line. (it's all we have) end = newSnapshot.GetLineFromPosition(start + end).End.Position - start; } else { int trailingDigits = 0; for (; end < N; end++) { char ch = txt[end]; if ('a' <= ch && ch <= 'z') { trailingDigits = 0; } else if ('A' <= ch && ch <= 'Z') { trailingDigits = 0; } else if ('0' <= ch && ch <= '9') { trailingDigits++; } else if (ch == '_') { trailingDigits = 0; } else { break; } } // we have a keyword or an identifier string s = txt.Substring(cur, end - cur); { switch (s) { #region keywords case "relation": case "individual": case "function": case "axiom": case "conjecture": case "schema": case "instantiate": case "instance": case "derived": case "concept": case "init": case "action": case "method": case "state": case "assume": case "assert": case "set": case "null": case "old": case "from": case "update": case "params": case "in": case "match": case "ensures": case "requires": case "modifies": case "true": case "false": case "fresh": case "module": case "object": case "class": case "type": case "if": case "else": case "local": case "let": case "call": case "entry": case "macro": case "interpret": case "forall": case "exists": case "returns": case "mixin": case "execute": case "before": case "after": case "isolate": case "with": case "export": case "delegate": case "import": case "using": case "include": case "progress": case "rely": case "mixord": case "extract": case "destructor": case "some": case "maximizing": case "minimizing": case "private": case "implement": case "property": case "while": case "invariant": case "struct": case "definition": case "ghost": case "alias": case "trusted": case "this": case "var": case "attribute": case "variant": case "of": #endregion break; #region keywords for built-in types case "bool": #endregion ty = IvyTokenKind.BuiltInType; break; default: continue; // it was an identifier, so we don't color it } } } newRegions.Add(new TokenRegion(new SnapshotPoint(newSnapshot, start + cur), new SnapshotPoint(newSnapshot, start + end), ty)); } OUTER_CONTINUE: done = true; } return(new SnapshotPoint(newSnapshot, start + N)); }