summaryrefslogtreecommitdiff
path: root/vendor/bundle/ruby/3.4.0/gems/rouge-4.7.0/lib/rouge/lexers/hocon.rb
blob: 881a969a00da115345cc53dd1ad5d3b44a3be087 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# -*- coding: utf-8 -*- #
# frozen_string_literal: true

module Rouge
  module Lexers
    load_lexer 'json.rb'

    class HOCON < JSON
      title 'HOCON'
      desc "Human-Optimized Config Object Notation (https://github.com/lightbend/config)"
      tag 'hocon'
      filenames '*.hocon'

      state :comments do
        # Comments
        rule %r(//.*?$), Comment::Single
        rule %r(#.*?$), Comment::Single
      end

      prepend :root do
        mixin :comments
      end

      prepend :object do
        # Keywords
        rule %r/\b(?:include|url|file|classpath)\b/, Keyword
      end

      state :name do
        rule %r/("(?:\"|[^"\n])*?")(\s*)([:=]|(?={))/ do
          groups Name::Label, Text::Whitespace, Punctuation
        end

        rule %r/([-\w.]+)(\s*)([:=]|(?={))/ do
          groups Name::Label, Text::Whitespace, Punctuation
        end
      end

      state :value do
        mixin :comments

        rule %r/\n/, Text::Whitespace
        rule %r/\s+/, Text::Whitespace

        mixin :constants

        # Interpolation
        rule %r/[$][{][?]?/, Literal::String::Interpol, :interpolation

        # Strings
        rule %r/"""/, Literal::String::Double, :multiline_string
        rule %r/"/, Str::Double, :string

        rule %r/\[/, Punctuation, :array
        rule %r/{/, Punctuation, :object

        # Symbols (only those not handled by JSON)
        rule %r/[()=]/, Punctuation

        # Values
        rule %r/[^$"{}\[\]:=,\+#`^?!@*&]+?/, Literal
      end

      state :interpolation do
        rule %r/[\w\-\.]+?/, Name::Variable
        rule %r/}/, Literal::String::Interpol, :pop!
      end

      prepend :string do
        rule %r/[$][{][?]?/, Literal::String::Interpol, :interpolation
        rule %r/[^\\"\${]+/, Literal::String::Double
      end

      state :multiline_string do
        rule %r/"[^"]{1,2}/, Literal::String::Double
        mixin :string
        rule %r/"""/, Literal::String::Double, :pop!
      end

      prepend :constants do
        # Numbers (handle the case where we have multiple periods, ie. IP addresses)
        rule %r/\d+\.(\d+\.?){3,}/, Literal
      end
    end
  end
end