Sha256: f9875362b12b0ce21a7baced12093491b86a4e3112d40ade3360dc7e156b64f0

Contents?: true

Size: 1.67 KB

Versions: 33

Compression:

Stored size: 1.67 KB

Contents

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

module Rouge
  module Lexers
    class IO < RegexLexer
      tag 'io'
      title "Io"
      desc 'The IO programming language (http://iolanguage.com)'
      mimetypes 'text/x-iosrc'
      filenames '*.io'

      def self.detect?(text)
        return true if text.shebang? 'io'
      end

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

      def self.builtins
        @builtins ||= Set.new %w(
          args call clone do doFile doString else elseif for if list
          method return super then
        )
      end

      state :root do
        rule %r/\s+/m, Text
        rule %r(//.*), Comment::Single
        rule %r(#.*), Comment::Single
        rule %r(/(\\\n)?[*].*?[*](\\\n)?/)m, Comment::Multiline
        rule %r(/[+]), Comment::Multiline, :nested_comment

        rule %r/"(\\\\|\\"|[^"])*"/, Str

        rule %r(:?:=), Keyword
        rule %r/[()]/, Punctuation

        rule %r([-=;,*+><!/|^.%&\[\]{}]), Operator

        rule %r/[A-Z]\w*/, Name::Class

        rule %r/[a-z_]\w*/ do |m|
          name = m[0]

          if self.class.constants.include? name
            token Keyword::Constant
          elsif self.class.builtins.include? name
            token Name::Builtin
          else
            token Name
          end
        end

        rule %r((\d+[.]?\d*|\d*[.]\d+)(e[+-]?[0-9]+)?)i, Num::Float
        rule %r/\d+/, Num::Integer

        rule %r/@@?/, Keyword
      end

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

Version data entries

33 entries across 33 versions & 2 rubygems

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