File: prolog.rb

package info (click to toggle)
ruby-rouge 4.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,844 kB
  • sloc: ruby: 38,489; sed: 2,071; perl: 152; makefile: 8
file content (67 lines) | stat: -rw-r--r-- 1,643 bytes parent folder | download | duplicates (4)
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
# -*- coding: utf-8 -*- #
# frozen_string_literal: true

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

      start { push :bol }

      state :bol do
        rule %r/#.*/, Comment::Single
        rule(//) { pop! }
      end

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

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

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

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

      state :atoms do
        rule %r/[[:lower:]]([[:word:]])*/, Str::Symbol
        rule %r/'[^']*'/, Str::Symbol
      end

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

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

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

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