fabro/apps/arc-web/app/data/dot-grammar.ts
Bryan Helmkamp 615a3a2dbf Replace direct Shiki usage with @pierre/diffs File component
Use the File component from @pierre/diffs/react instead of manually
creating a Shiki highlighter instance. Register the custom DOT grammar
via attachResolvedLanguages and drop the direct shiki dependency.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-28 16:49:43 -05:00

106 lines
3.5 KiB
TypeScript

import type { LanguageRegistration } from "@pierre/diffs";
export const dotLanguage: LanguageRegistration = {
name: "dot",
scopeName: "source.dot",
fileTypes: ["dot", "DOT", "gv"],
firstLineMatch: "digraph.*",
patterns: [
{
match: " ?(digraph)[ \\t]+([A-Za-z0-9]+) ?(\\{)",
captures: {
"1": { name: "storage.type.dot" },
"2": { name: "variable.other.dot" },
"3": { name: "punctuation.section.dot" },
},
},
{
match: "(<|-)(>|-)",
name: "keyword.operator.dot",
},
{
match: "\\b(node|edge|graph|digraph|subgraph|strict)\\b",
name: "storage.type.dot",
},
{
match:
"\\b(bottomlabel|color|comment|distortion|fillcolor|fixedsize|fontcolor|fontname|fontsize|group|height|label|layer|orientation|peripheries|regular|shape|shapefile|sides|skew|style|toplabel|URL|width|z)\\b",
name: "support.constant.attribute.node.dot",
},
{
match:
"\\b(arrowhead|arrowsize|arrowtail|color|comment|constraint|decorate|dir|fontcolor|fontname|fontsize|headlabel|headport|headURL|label|labelangle|labeldistance|labelfloat|labelcolor|labelfontname|labelfontsize|layer|lhead|ltail|minlen|samehead|sametail|splines|style|taillabel|tailport|tailURL|weight)\\b",
name: "support.constant.attribute.edge.dot",
},
{
match:
"\\b(bgcolor|center|clusterrank|color|comment|compound|concentrate|fillcolor|fontname|fontpath|fontsize|label|labeljust|labelloc|layers|margin|mclimit|nodesep|nslimit|nslimit1|ordering|orientation|page|pagedir|quantum|rank|rankdir|ranksep|ratio|remincross|rotate|samplepoints|searchsize|size|style|URL)\\b",
name: "support.constant.attribute.graph.dot",
},
{
match:
"\\b(box|polygon|ellipse|circle|point|egg|triangle|plaintext|diamond|trapezium|parallelogram|house|pentagon|hexagon|septagon|octagon|doublecircle|doubleoctagon|tripleoctagon|invtriangle|invtrapezium|invhouse|Mdiamond|Msquare|Mcircle|rect|rectangle|none|note|tab|folder|box3d|component|max|min|same)\\b",
name: "variable.other.dot",
},
{
begin: '"',
beginCaptures: {
"0": { name: "punctuation.definition.string.begin.dot" },
},
end: '"',
endCaptures: {
"0": { name: "punctuation.definition.string.end.dot" },
},
name: "string.quoted.double.dot",
patterns: [
{
match: "\\\\.",
name: "constant.character.escape.dot",
},
],
},
{
begin: "(^[ \\t]+)?(?=//)",
beginCaptures: {
"1": { name: "punctuation.whitespace.comment.leading.dot" },
},
end: "(?!\\G)",
patterns: [
{
begin: "//",
beginCaptures: {
"0": { name: "punctuation.definition.comment.dot" },
},
end: "\\n",
name: "comment.line.double-slash.dot",
},
],
},
{
begin: "(^[ \\t]+)?(?=#)",
beginCaptures: {
"1": { name: "punctuation.whitespace.comment.leading.dot" },
},
end: "(?!\\G)",
patterns: [
{
begin: "#",
beginCaptures: {
"0": { name: "punctuation.definition.comment.dot" },
},
end: "\\n",
name: "comment.line.number-sign.dot",
},
],
},
{
begin: "/\\*",
captures: {
"0": { name: "punctuation.definition.comment.dot" },
},
end: "\\*/",
name: "comment.block.dot",
},
],
repository: {},
};