Sha256: cdfd06f943eb1a9c958c5b87810ff3c519f929bf21a58e81057f8edaf7e33d05

Contents?: true

Size: 1.53 KB

Versions: 14

Compression:

Stored size: 1.53 KB

Contents

module Rouge
  module Lexers
    class Prolog < RegexLexer
      desc "The Prolog programming language (http://en.wikipedia.org/wiki/Prolog)"
      tag 'prolog'
      aliases 'prolog'
      filenames '*.pro', '*.P', '*.prolog', '*.pl'
      mimetypes 'text/x-prolog'

      def self.analyze_text(text)
        return 0.1 if text =~ /\A\w+(\(\w+\,\s*\w+\))*\./
        return 0.1 if text.include? ':-'
      end

      state :basic do
        rule /\s+/, Text
        rule /^#.*/, Comment::Single
        rule /\/\*/, Comment::Multiline, :nested_comment

        rule /[\[\](){}|.,;!]/, Punctuation
        rule /:-|-->/, Punctuation

        rule /"[^"]*"/, Str::Double

        rule /\d+\.\d+/, Num::Float
        rule /\d+/, Num
      end

      state :atoms do
        rule /[[:lower:]]([_[:lower:][:digit:]])*/, Str::Symbol
        rule /'[^']*'/, Str::Symbol
      end

      state :operators do
        rule /(<|>|=<|>=|==|=:=|=|\/|\/\/|\*|\+|-)(?=\s|[a-zA-Z0-9\[])/,
          Operator
        rule /is/, Operator
        rule /(mod|div|not)/, Operator
        rule /[#&*+-.\/:<=>?@^~]+/, Operator
      end

      state :variables do
        rule /[A-Z]+\w*/, Name::Variable
        rule /_[[:word:]]*/, Name::Variable
      end

      state :root do
        mixin :basic
        mixin :atoms
        mixin :variables
        mixin :operators
      end

      state :nested_comment do
        rule /\/\*/, Comment::Multiline, :push
        rule /\s*\*[^*\/]+/, Comment::Multiline
        rule /\*\//, Comment::Multiline, :pop!
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
rouge-1.5.0 lib/rouge/lexers/prolog.rb
rouge-1.4.0 lib/rouge/lexers/prolog.rb
rouge-1.3.4 lib/rouge/lexers/prolog.rb
rouge-1.3.3 lib/rouge/lexers/prolog.rb
rouge-1.3.2 lib/rouge/lexers/prolog.rb
rouge-1.3.1 lib/rouge/lexers/prolog.rb
rouge-1.3.0 lib/rouge/lexers/prolog.rb
rouge-1.2.0 lib/rouge/lexers/prolog.rb
rouge-1.1.0 lib/rouge/lexers/prolog.rb
rouge-0.5.4 lib/rouge/lexers/prolog.rb
rouge-0.5.3 lib/rouge/lexers/prolog.rb
rouge-0.5.2 lib/rouge/lexers/prolog.rb
rouge-0.5.1 lib/rouge/lexers/prolog.rb
rouge-0.5.0 lib/rouge/lexers/prolog.rb