Class: CodeRay::Scanners::Groovy

### Home Classes Methods

### In Files

- lib/coderay/scanners/groovy.rb

### Parent

Java

### Methods

- #scan_tokens
- #setup

### Class/Module Index

Quicksearch

- CodeRay
- CodeRay::Duo
- CodeRay::Encoders
- CodeRay::Encoders::CommentFilter
- CodeRay::Encoders::Count
- CodeRay::Encoders::Debug
- CodeRay::Encoders::DebugLint
- CodeRay::Encoders::Div
- CodeRay::Encoders::Encoder
- CodeRay::Encoders::Filter
- CodeRay::Encoders::HTML
- CodeRay::Encoders::HTML::Output
- CodeRay::Encoders::JSON
- CodeRay::Encoders::LinesOfCode
- CodeRay::Encoders::Lint
- CodeRay::Encoders::Null
- CodeRay::Encoders::Page
- CodeRay::Encoders::Span
- CodeRay::Encoders::Statistic
- CodeRay::Encoders::Terminal
- CodeRay::Encoders::Text
- CodeRay::Encoders::TokenKindFilter
- CodeRay::Encoders::XML
- CodeRay::Encoders::YAML
- CodeRay::FileType
- CodeRay::ForRedCloth
- CodeRay::Plugin
- CodeRay::PluginHost
- CodeRay::Scanners
- CodeRay::Scanners::C
- CodeRay::Scanners::CPlusPlus
- CodeRay::Scanners::CSS
- CodeRay::Scanners::Clojure
- CodeRay::Scanners::Debug
- CodeRay::Scanners::Delphi
- CodeRay::Scanners::Diff
- CodeRay::Scanners::ERB
- CodeRay::Scanners::Go
- CodeRay::Scanners::Groovy
- CodeRay::Scanners::HAML
- CodeRay::Scanners::HTML
- CodeRay::Scanners::JSON
- CodeRay::Scanners::Java
- CodeRay::Scanners::JavaScript
- CodeRay::Scanners::Python
- CodeRay::Scanners::Raydebug
- CodeRay::Scanners::Ruby
- CodeRay::Scanners::SQL
- CodeRay::Scanners::Sass
- CodeRay::Scanners::Scanner
- CodeRay::Scanners::Taskpaper
- CodeRay::Scanners::Text
- CodeRay::Scanners::XML
- CodeRay::Scanners::YAML
- CodeRay::Styles
- CodeRay::Styles::Alpha
- CodeRay::Styles::Style
- CodeRay::Tokens
- CodeRay::TokensProxy
- CodeRay::WordList
- CodeRay::WordList::CaseIgnoring

No matching classes.

# CodeRay::Scanners::Groovy

Scanner for Groovy.

### Protected Instance Methods

scan_tokens(encoder, options) click to toggle source

    # File lib/coderay/scanners/groovy.rb, line 43
    def scan_tokens encoder, options
      state = options[:state] || @state
      inline_block_stack = []
      inline_block_paren_depth = nil
      string_delimiter = nil
      import_clause = class_name_follows = last_token = after_def = false
      value_expected = true

      until eos?

        case state

        when :initial

          if match = scan(/ \s+ | \\\n /)
            encoder.text_token match, :space
            if match.index \n\
              import_clause = after_def = false
              value_expected = true unless value_expected
            end
            next

          elsif match = scan(% // [^\n\\]* (?: \\. [^\n\\]* )* | /\* (?: .*? \*/ | .* ) !x)
            value_expected = true
            after_def = false
            encoder.text_token match, :comment

          elsif bol? && match = scan(/ \#!.* /)
            encoder.text_token match, :doctype

          elsif import_clause && match = scan(/ (?!as) #{IDENT} (?: \. #{IDENT} )* (?: \.\* )? /x)
            after_def = value_expected = false
            encoder.text_token match, :include

          elsif match = scan(/ #{IDENT} | \[\] /x)
            kind = IDENT_KIND[match]
            value_expected = (kind == :keyword) && KEYWORDS_EXPECTING_VALUE[match]
            if last_token == '.'
              kind = :ident
            elsif class_name_follows
              kind = :class
              class_name_follows = false
            elsif after_def && check(/\s*[({]/)
              kind = :method
              after_def = false
            elsif kind == :ident && last_token != '?' && check(/:/)
              kind = :key
            else
              class_name_follows = true if match == 'class' || (import_clause && match == 'as')
              import_clause = match == 'import'
              after_def = true if match == 'def'
            end
            encoder.text_token match, kind

          elsif match = scan(/;/)
            import_clause = after_def = false
            value_expected = true
            encoder.text_token match, :operator

          elsif match = scan(/\{/)
            class_name_follows = after_def = false
            value_expected = true
            encoder.text_token match, :operator
            if !inline_block_stack.empty?
              inline_block_paren_depth += 1
            end

          # TODO: ~'...', ~"..." and ~/.../ style regexps
          elsif match = scan(/ \.\.<? | \*?\.(?!\d)@? | \.& | \?:? | [,?:(\[] | -[->] | \+\+ |
              && | \|\| | \*\*=? | ==?~ | <=?>? | [-+*%^~&|>=!]=? | <<<?=? | >>>?=? /)
            value_expected = true
            value_expected = :regexp if match == '~'
            after_def = false
            encoder.text_token match, :operator

          elsif match = scan(/ [)\]}] /)
            value_expected = after_def = false
            if !inline_block_stack.empty? && match == '}'
              inline_block_paren_depth -= 1
              if inline_block_paren_depth == 0  # closing brace of inline block reached
                encoder.text_token match, :inline_delimiter
                encoder.end_group :inline
                state, string_delimiter, inline_block_paren_depth = inline_block_stack.pop
                next
              end
            end
            encoder.text_token match, :operator

          elsif check(/[\d.]/)
            after_def = value_expected = false
            if match = scan(/0[xX][0-9A-Fa-f]+/)
              encoder.text_token match, :hex
            elsif match = scan(/(?>0[0-7]+)(?![89.eEfF])/)
              encoder.text_token match, :octal
            elsif match = scan(/\d+[fFdD]|\d*\.\d+(?:[eE][+-]?\d+)?[fFdD]?|\d+[eE][+-]?\d+[fFdD]?/)
              encoder.text_token match, :float
            elsif match = scan(/\d+[lLgG]?/)
              encoder.text_token match, :integer
            end

          elsif match = scan(/'''|"""/)
            after_def = value_expected = false
            state = :multiline_string
            encoder.begin_group :string
            string_delimiter = match
            encoder.text_token match, :delimiter

          # TODO: record.'name' syntax
          elsif match = scan(/["']/)
            after_def = value_expected = false
            state = match == '/' ? :regexp : :string
            encoder.begin_group state
            string_delimiter = match
            encoder.text_token match, :delimiter

          elsif value_expected && match = scan(/\//)
            after_def = value_expected = false
            encoder.begin_group :regexp
            state = :regexp
            string_delimiter = '/'
            encoder.text_token match, :delimiter

          elsif match = scan(/ @ #{IDENT} /x)
            after_def = value_expected = false
            encoder.text_token match, :annotation

          elsif match = scan(/\//)
            after_def = false
            value_expected = true
            encoder.text_token match, :operator

          else
            encoder.text_token getch, :error

          end

        when :string, :regexp, :multiline_string
          if match = scan(STRING_CONTENT_PATTERN[string_delimiter])
            encoder.text_token match, :content

          elsif match = scan(state == :multiline_string ? /'''|"""/ : /["'\/]/)
            encoder.text_token match, :delimiter
            if state == :regexp
              # TODO: regexp modifiers? s, m, x, i?
              modifiers = scan(/[ix]+/)
              encoder.text_token modifiers, :modifier if modifiers && !modifiers.empty?
            end
            state = :string if state == :multiline_string
            encoder.end_group state
            string_delimiter = nil
            after_def = value_expected = false
            state = :initial
            next

          elsif (state == :string || state == :multiline_string) &&
              (match = scan(/ \\ (?: #{ESCAPE} | #{UNICODE_ESCAPE} ) /ox))
            if string_delimiter[0] == '' && !(match == "\\\\" || match == "\\'")
              encoder.text_token match, :content
            else
              encoder.text_token match, :char
            end
          elsif state == :regexp && match = scan(/ \\ (?: #{REGEXP_ESCAPE} | #{UNICODE_ESCAPE} ) /ox)
            encoder.text_token match, :char

          elsif match = scan(/ \$ #{IDENT} /ox)
            encoder.begin_group :inline
            encoder.text_token '$', :inline_delimiter
            match = match[1..-1]
            encoder.text_token match, IDENT_KIND[match]
            encoder.end_group :inline
            next
          elsif match = scan(/ \$ \{ /)
            encoder.begin_group :inline
            encoder.text_token match, :inline_delimiter
            inline_block_stack << [state, string_delimiter, inline_block_paren_depth]
            inline_block_paren_depth = 1
            state = :initial
            next

          elsif match = scan(/ \$ /x)
            encoder.text_token match, :content

          elsif match = scan(/ \\. /x)
            encoder.text_token match, :content  # TODO: Shouldn't this be :error?

          elsif match = scan(/ \\ | \n /)
            encoder.end_group state == :regexp ? :regexp : :string
            encoder.text_token match, :error
            after_def = value_expected = false
            state = :initial

          else
            raise_inspect "else case \" reached; %p not handled." % peek(1), encoder

          end

        else
          raise_inspect 'Unknown state', encoder

        end

        last_token = match unless [:space, :comment, :doctype].include? kind

      end

      if [:multiline_string, :string, :regexp].include? state
        encoder.end_group state == :regexp ? :regexp : :string
      end

      if options[:keep_state]
        @state = state
      end

      until inline_block_stack.empty?
        state, = *inline_block_stack.pop
        encoder.end_group :inline
        encoder.end_group state == :regexp ? :regexp : :string
      end

      encoder
    end

setup() click to toggle source

    # File lib/coderay/scanners/groovy.rb, line 39
    def setup
      @state = :initial
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.