Sha256: a2999b3c1dfd2ef73def6c0b8f206260ff9ecec2e1664e464bd52af241e320ca

Contents?: true

Size: 1.25 KB

Versions: 25

Compression:

Stored size: 1.25 KB

Contents

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

module Rouge
  module Lexers
    load_lexer 'php.rb'

    class Hack < PHP
      title 'Hack'
      desc 'The Hack programming language (hacklang.org)'
      tag 'hack'
      aliases 'hack', 'hh'
      filenames '*.php', '*.hh'

      def self.detect?(text)
        return true if /<\?hh/ =~ text
        return true if text.shebang?('hhvm')
        return true if /async function [a-zA-Z]/ =~ text
        return true if /\): Awaitable</ =~ text

        return false
      end

      def self.keywords
        @hh_keywords ||= super.merge Set.new %w(
          type newtype enum
          as super
          async await Awaitable
          vec dict keyset
          void int string bool float double
          arraykey num Stringish
        )
      end

      prepend :root do
        rule %r/<\?hh(\s*\/\/\s*(strict|decl|partial))?$/, Comment::Preproc, :php
      end

      prepend :php do
        rule %r((/\*\s*)(HH_(?:IGNORE_ERROR|FIXME)\[\d+\])([^*]*)(\*/)) do
          groups Comment::Preproc, Comment::Preproc, Comment::Multiline, Comment::Preproc
        end

        rule %r(// UNSAFE(?:_EXPR|_BLOCK)?), Comment::Preproc
        rule %r(/\*\s*UNSAFE_EXPR\s*\*/), Comment::Preproc
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 2 rubygems

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