Sha256: df772f362b3502153b459fb931f7b7026af15b491a3b53fa968e44d5a7b96ccc

Contents?: true

Size: 1.94 KB

Versions: 16

Compression:

Stored size: 1.94 KB

Contents

# -*- coding: utf-8 -*- #

module Rouge
  module Lexers
    class Gobstones < RegexLexer
      title 'Gobstones'
      desc 'Gobstones language'
      tag 'gobstones'
      filenames '*.gbs'

      def self.analyze_text(_text)
        0.3
      end

      reserved = %w(program interactive is return record
                    field variant case if then else elseif switch to repeat while foreach
                    in match)

      atoms = %w(False True Verde Rojo Vermelho Azul Negro Preto Norte Sur Sul Este Leste Oeste)

      state :comments do
        def comment_between(start, finish)
          /#{start}.*?#{finish}/m
        end

        rule comment_between('{-', '-}'), Comment::Multiline
        rule comment_between('\/\*', '\*\/'), Comment::Multiline
        rule comment_between('"""', '"""'), Comment::Multiline
        rule /((?<!<)-(?!>)|#|\/).*$/, Comment::Single
      end

      state :root do
        def any(words)
          /#{words.map { |word| word.concat('\\b') }.join('|')}/
        end

        mixin :comments
        rule /\s+/, Text::Whitespace
        rule any(reserved), Keyword::Reserved
        rule any(atoms), Literal
        rule /(type)(\s+)(\w+)/ do |m|
          groups Keyword::Reserved, Text::Whitespace, Keyword::Type
        end
        mixin :functions
        mixin :symbols
        rule /\d+/, Literal::Number
        rule /".+?"/, Literal::String
      end

      state :functions do
        rule /(procedure|function)(\s+)(\w+)/ do
          groups Keyword::Reserved, Text::Whitespace, Name::Function
        end

        rule /([a-zA-Z][a-zA-Z'_0-9]*)(\()/ do |m|
          groups Name::Function, Text
        end
        rule /([a-z][a-zA-Z'_0-9]*)/, Name::Variable
      end

      state :symbols do
        rule /:=|\.\.|\+\+|\.|_|->|<-/, Operator
        rule /<=|<|>=|>|==|=/, Operator
        rule /\|\||&&|\+|\*|-|\^/, Operator
        rule /\(|\)|\{|\}/, Text
        rule /,|;|:|\||\[|\]/, Text
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
mumukit-content-type-1.12.1 lib/mumukit/content_type/gobstones.rb
mumukit-content-type-1.12.0 lib/mumukit/content_type/gobstones.rb
mumukit-content-type-1.11.1 lib/mumukit/content_type/gobstones.rb
mumukit-content-type-1.11.0 lib/mumukit/content_type/gobstones.rb
mumukit-content-type-1.10.0 lib/mumukit/content_type/gobstones.rb
mumukit-content-type-1.9.0 lib/mumukit/content_type/gobstones.rb
mumukit-content-type-1.8.1 lib/mumukit/content_type/gobstones.rb
mumukit-content-type-1.8.0 lib/mumukit/content_type/gobstones.rb
mumukit-content-type-1.7.0 lib/mumukit/content_type/gobstones.rb
mumukit-content-type-1.6.1 lib/mumukit/content_type/gobstones.rb
mumukit-content-type-1.6.0 lib/mumukit/content_type/gobstones.rb
mumukit-content-type-1.5.1 lib/mumukit/content_type/gobstones.rb
mumukit-content-type-1.5.0 lib/mumukit/content_type/gobstones.rb
mumukit-content-type-1.4.1 lib/mumukit/content_type/gobstones.rb
mumukit-content-type-1.4.0 lib/mumukit/content_type/gobstones.rb
mumukit-content-type-1.3.1 lib/mumukit/content_type/gobstones.rb