Sha256: 5f4829888b0c61b0bf756585d10bddb48ed2cec00e5189378a59a9954d6b8865

Contents?: true

Size: 1.81 KB

Versions: 20

Compression:

Stored size: 1.81 KB

Contents

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

module Rouge
  module Lexers
    load_lexer 'ocaml/common.rb'

    class ReasonML < OCamlCommon
      title "ReasonML"
      desc 'New syntax on top of OCaml ecosystem (reasonml.github.io)'
      tag 'reasonml'
      filenames '*.re', '*.rei'
      mimetypes 'text/x-reasonml'

      def self.keywords
        @keywords ||= super + Set.new(%w(
          switch
        ))
      end

      state :root do
        rule %r/\s+/m, Text
        rule %r/false|true|[(][)]|\[\]/, Name::Builtin::Pseudo
        rule %r/#{@@upper_id}(?=\s*[.])/, Name::Namespace, :dotted
        rule %r/`#{@@id}/, Name::Tag
        rule @@upper_id, Name::Class
        rule %r/[\/][*](?![\/])/, Comment, :comment
        rule @@id do |m|
          match = m[0]
          if self.class.keywords.include? match
            token Keyword
          elsif self.class.word_operators.include? match
            token Operator::Word
          elsif self.class.primitives.include? match
            token Keyword::Type
          else
            token Name
          end
        end

        rule %r/[(){}\[\];]+/, Punctuation
        rule @@operator, Operator

        rule %r/-?\d[\d_]*(.[\d_]*)?(e[+-]?\d[\d_]*)/i, Num::Float
        rule %r/0x\h[\h_]*/i, Num::Hex
        rule %r/0o[0-7][0-7_]*/i, Num::Oct
        rule %r/0b[01][01_]*/i, Num::Bin
        rule %r/\d[\d_]*/, Num::Integer

        rule %r/'(?:(\\[\\"'ntbr ])|(\\[0-9]{3})|(\\x\h{2}))'/, Str::Char
        rule %r/'[^'\/]'/, Str::Char
        rule %r/'/, Keyword
        rule %r/"/, Str::Double, :string
        rule %r/[~?]#{@@id}/, Name::Variable
      end

      state :comment do
        rule %r|[^/*)]+|, Comment
        rule %r|[/][*]|, Comment, :push
        rule %r|[*][/]|, Comment, :pop!
        rule %r|[*/]|, Comment
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
rouge-3.25.0 lib/rouge/lexers/reasonml.rb
rouge-3.24.0 lib/rouge/lexers/reasonml.rb
rouge-3.23.0 lib/rouge/lexers/reasonml.rb
rouge-3.22.0 lib/rouge/lexers/reasonml.rb
rouge-3.21.0 lib/rouge/lexers/reasonml.rb
rouge-3.20.0 lib/rouge/lexers/reasonml.rb
rouge-3.19.0 lib/rouge/lexers/reasonml.rb
rouge-3.18.0 lib/rouge/lexers/reasonml.rb
rouge-3.17.0 lib/rouge/lexers/reasonml.rb
rouge-3.16.0 lib/rouge/lexers/reasonml.rb
rouge-3.15.0 lib/rouge/lexers/reasonml.rb
rouge-3.14.0 lib/rouge/lexers/reasonml.rb
rouge-3.13.0 lib/rouge/lexers/reasonml.rb
rouge-3.12.0 lib/rouge/lexers/reasonml.rb
rouge-3.11.1 lib/rouge/lexers/reasonml.rb
rouge-3.11.0 lib/rouge/lexers/reasonml.rb
rouge-3.10.0 lib/rouge/lexers/reasonml.rb
rouge-3.9.0 lib/rouge/lexers/reasonml.rb
rouge-3.8.0 lib/rouge/lexers/reasonml.rb
rouge-3.7.0 lib/rouge/lexers/reasonml.rb