summaryrefslogtreecommitdiff
path: root/vendor/bundle/ruby/3.4.0/gems/rouge-4.5.2/lib/rouge/lexers/dot.rb
blob: 56d5c5bb9d1e4a1880aeba72d112059de7fd878d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# -*- coding: utf-8 -*- #
# frozen_string_literal: true

module Rouge
  module Lexers
    class Dot < RegexLexer
      title "DOT"
      desc "graph description language"

      tag 'dot'
      aliases 'graphviz'
      filenames '*.dot'
      mimetypes 'text/vnd.graphviz'

      start do
        @html = HTML.new(options)
      end

      state :comments_and_whitespace do
        rule %r/\s+/, Text
        rule %r(#.*), Comment::Single
        rule %r(//.*?$), Comment::Single
        rule %r(/(\\\n)?[*].*?[*](\\\n)?/)m, Comment::Multiline
      end

      state :html do
        rule %r/[^<>]+/ do
          delegate @html
        end
        rule %r/<.+?>/m do
          delegate @html
        end
        rule %r/>/, Punctuation, :pop!
      end

      state :ID do
        rule %r/([a-zA-Z][a-zA-Z_0-9]*)(\s*)(=)/ do |m|
          token Name, m[1]
          token Text, m[2]
          token Punctuation, m[3]
        end
        rule %r/[a-zA-Z][a-zA-Z_0-9]*/, Name::Variable
        rule %r/([0-9]+)?\.[0-9]+/, Num::Float
        rule %r/[0-9]+/, Num::Integer
        rule %r/"(\\"|[^"])*"/, Str::Double
        rule %r/</ do
          token Punctuation
          @html.reset!
          push :html
        end
      end

      state :a_list do
        mixin :comments_and_whitespace
        mixin :ID
        rule %r/[=;,]/, Punctuation
        rule %r/\]/, Operator, :pop!
      end

      state :root do
        mixin :comments_and_whitespace
        rule %r/\b(strict|graph|digraph|subgraph|node|edge)\b/i, Keyword
        rule %r/[{};:=]/, Punctuation
        rule %r/-[->]/, Operator
        rule %r/\[/, Operator, :a_list
        mixin :ID
      end
    end
  end
end