Sha256: 41f07f2a9163f7033d0210e9580c64661dbe42ec6b3faaf361c65eea760c73d7

Contents?: true

Size: 1.28 KB

Versions: 3

Compression:

Stored size: 1.28 KB

Contents

# -*- coding: utf-8 -*- #
# frozen_string_literal: true

module Rouge
    module Lexers
        class Rego < RegexLexer
            title "Rego"
            desc "The Rego open-policy-agent (OPA) policy language (openpolicyagent.org)"
            tag 'rego'
            filenames '*.rego'

            state :basic do
              rule %r/\s+/, Text
              rule %r/#.*/, Comment::Single
      
              rule %r/[\[\](){}|.,;!]/, Punctuation
      
              rule %r/"[^"]*"/, Str::Double
      
              rule %r/-?\d+\.\d+([eE][+-]?\d+)?/, Num::Float
              rule %r/-?\d+([eE][+-]?\d+)?/, Num

              rule %r/\\u[0-9a-fA-F]{4}/, Num::Hex
              rule %r/\\["\/bfnrt]/, Str::Escape
            end
      
            state :atoms do
              rule %r/(true|false|null)/, Keyword::Constant
              rule %r/[[:word:]]*/, Str::Symbol
            end
      
            state :operators do
              rule %r/(=|!=|>=|<=|>|<|\+|-|\*|%|\/|\||&|:=)/, Operator
              rule %r/(default|not|package|import|as|with|else|some)/, Operator
              rule %r/[\/:?@^~]+/, Operator
            end
      
            state :root do
              mixin :basic
              mixin :operators
              mixin :atoms
            end
        end
    end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rouge-3.20.0 lib/rouge/lexers/rego.rb
rouge-3.19.0 lib/rouge/lexers/rego.rb
rouge-3.18.0 lib/rouge/lexers/rego.rb