Sha256: 2423688a21fea5de61237cc216acdd2d461fa42c02ac877a322e32c7efc3cbe4

Contents?: true

Size: 1.6 KB

Versions: 26

Compression:

Stored size: 1.6 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'

            def self.constants
              @constants ||= Set.new %w(
                true false null
              )
            end

            def self.operators
              @operators ||= Set.new %w(
                as default else import not package some with
              )
            end

            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 :operators do
              rule %r/(=|!=|>=|<=|>|<|\+|-|\*|%|\/|\||&|:=)/, Operator
              rule %r/[\/:?@^~]+/, Operator
            end

            state :root do
              mixin :basic
              mixin :operators

              rule %r/[[:word:]]+/ do |m|
                if self.class.constants.include? m[0]
                  token Keyword::Constant
                elsif self.class.operators.include? m[0]
                  token Operator::Word
                else
                  token Name
                end
              end
            end
        end
    end
end

Version data entries

26 entries across 26 versions & 2 rubygems

Version Path
rouge-4.5.1 lib/rouge/lexers/rego.rb
rouge-4.5.0 lib/rouge/lexers/rego.rb
rouge-4.4.0 lib/rouge/lexers/rego.rb
rouge-4.3.0 lib/rouge/lexers/rego.rb
rouge-4.2.1 lib/rouge/lexers/rego.rb
rouge-4.2.0 lib/rouge/lexers/rego.rb
rouge-4.1.3 lib/rouge/lexers/rego.rb
rouge-4.1.2 lib/rouge/lexers/rego.rb
rouge-4.1.1 lib/rouge/lexers/rego.rb
mumukit-content-type-1.12.1 vendor/bundle/ruby/2.7.0/gems/rouge-3.30.0/lib/rouge/lexers/rego.rb
mumukit-content-type-1.12.0 vendor/bundle/ruby/2.7.0/gems/rouge-3.30.0/lib/rouge/lexers/rego.rb
rouge-4.1.0 lib/rouge/lexers/rego.rb
rouge-4.0.1 lib/rouge/lexers/rego.rb
rouge-4.0.0 lib/rouge/lexers/rego.rb
rouge-3.30.0 lib/rouge/lexers/rego.rb
rouge-3.29.0 lib/rouge/lexers/rego.rb
rouge-3.28.0 lib/rouge/lexers/rego.rb
rouge-3.27.0 lib/rouge/lexers/rego.rb
rouge-3.26.1 lib/rouge/lexers/rego.rb
mumukit-content-type-1.11.1 vendor/bundle/ruby/2.6.0/gems/rouge-3.26.0/lib/rouge/lexers/rego.rb