class CodeRay::Scanners::Clojure

Clojure scanner by Licenser.

Constants

BASIC_IDENTIFIER
COMPLEX10
COMPLEX16
COMPLEX2
COMPLEX8
DECIMAL
DIGIT
DIGIT10
DIGIT16
DIGIT2
DIGIT8
EXACTNESS
EXP
EXP_MARK
IDENTIFIER
IDENT_KIND
IMAG10
IMAG16
IMAG2
IMAG8
KEYWORD_NEXT_TOKEN_KIND
NUM
NUM10
NUM16
NUM2
NUM8
PREFIX10
PREFIX16
PREFIX2
PREFIX8
RADIX10
RADIX16
RADIX2
RADIX8
REAL10
REAL16
REAL2
REAL8
SIGN
SUFFIX
SYMBOL
UINT10
UINT16
UINT2
UINT8
UREAL10
UREAL16
UREAL2
UREAL8

Protected Instance Methods

scan_tokens(encoder, options) click to toggle source
# File lib/coderay/scanners/clojure.rb, line 144
def scan_tokens encoder, options
  
  state = :initial
  kind = nil
  
  until eos?
    
    case state
    when :initial
      if match = scan(%r \s+ | \\\n | , /)
        encoder.text_token match, :space
      elsif match = scan(%r['`\(\[\)\]\{\}]|\#[({]|~@?|[@\^]/)
        encoder.text_token match, :operator
      elsif match = scan(%r;.*/)
        encoder.text_token match, :comment  # TODO: recognize (comment ...) too
      elsif match = scan(%r\#?\\(?:newline|space|.?)/)
        encoder.text_token match, :char
      elsif match = scan(%r\#[ft]/)
        encoder.text_token match, :predefined_constant
      elsif match = scan(%r#{IDENTIFIER}/)
        kind = IDENT_KIND[match]
        encoder.text_token match, kind
        if rest? && kind == :keyword
          if kind = KEYWORD_NEXT_TOKEN_KIND[match]
            encoder.text_token match, :space if match = scan(%r\s+/)
            encoder.text_token match, kind if match = scan(%r#{IDENTIFIER}/)
          end
        end
      elsif match = scan(%r#{SYMBOL}/)
        encoder.text_token match, :symbol
      elsif match = scan(%r\./)
        encoder.text_token match, :operator
      elsif match = scan(%r \# \^ #{IDENTIFIER} /x)
        encoder.text_token match, :type
      elsif match = scan(%r (\#)? " /)
        state = self[1] ? :regexp : :string
        encoder.begin_group state
        encoder.text_token match, :delimiter
      elsif match = scan(%r#{NUM}/) and not matched.empty?
        encoder.text_token match, match[%r[.e\/]/] ? :float : :integer
      else
        encoder.text_token getch, :error
      end
      
    when :string, :regexp
      if match = scan(%r[^"\\]+|\\.?/)
        encoder.text_token match, :content
      elsif match = scan(%r"/)
        encoder.text_token match, :delimiter
        encoder.end_group state
        state = :initial
      else
        raise_inspect "else case \" reached; %p not handled." % peek(1),
          encoder, state
      end
      
    else
      raise 'else case reached'
      
    end
    
  end
  
  if [:string, :regexp].include? state
    encoder.end_group state
  end
  
  encoder
  
end