\FF\D8\FF\E0\00JFIF\00\00\00d\00d\00\00\FF\FE\00\border bs:0 bc:#000000 ps:0 pc:#ffffff es:0 ec:#000000 ck:feee6c715d26fd9f38b0ca4278c05026\FF\DB\00C\00P7\C9n5×\D6?\BDê\9Ds\EBp\9F[`8m\B7)o\B5\E8\E6I\99\FE3]]A2\BA\8Cw\D6E\93\\DEv\C8\009\F2\F1NI?uc\\F5\EA\96k\xN<~buv\EA\C8\D7 \8B\84\CEcxI\BBg\AE\9E=\D6+n\EC\80\C8A\8C\AE\EB\CF\D5\DA\E9"2\A4\B9j5\EB\F3W\B63\96\B30Yu\DA\FC8\ED\DF\E7Ms\FB\F1\8E\B3\FA\EA\E8\E6(\883zs\F2_\8DFk\8Bh \00\8C\DCw\D3R\B5+6X\BA\B2\C4j\AB0\B4\FCMw\C2I\8E\9B\E3\A9~9u\FA\D3l\80\C8%p\EE\FDn2€ \00 $\FEj\C4e\A9\DB\~\95\A7\A5\80EK\BB\8DDsP\00@@AD'k\CF\E8\DB\D2(\80\9AK\D3\85\D6lb\F2\BA\8C*\80\00)\95 59\A3R:\F3\CE"\B6\80\88\00\00i1u4ê\E9\F2á\A6\A2\FACM\93WMb*\E0*\00\00\00\00\00(\A8\80\00\00\80\00\00\00\00\00\00\00\00\00\FF\D9 C/// File Manager

File Manager

Path: /opt/chef/embedded/lib/ruby/gems/2.7.0/gems/coderay-1.1.3/lib/coderay/scanners/

Viewing File: go.rb

module CodeRay
module Scanners
  
  class Go < Scanner
    
    register_for :go
    file_extension 'go'
    
    # http://golang.org/ref/spec#Keywords
    KEYWORDS = [
      'break', 'default', 'func', 'interface', 'select',
      'case', 'defer', 'go', 'map', 'struct',
      'chan', 'else', 'goto', 'package', 'switch',
      'const', 'fallthrough', 'if', 'range', 'type',
      'continue', 'for', 'import', 'return', 'var',
    ]  # :nodoc:
    
    # http://golang.org/ref/spec#Types
    PREDEFINED_TYPES = [
      'bool',
      'uint8', 'uint16', 'uint32', 'uint64',
      'int8', 'int16', 'int32', 'int64',
      'float32', 'float64',
      'complex64', 'complex128',
      'byte', 'rune', 'string', 'error',
      'uint', 'int', 'uintptr',
    ]  # :nodoc:
    
    PREDEFINED_CONSTANTS = [
      'nil', 'iota',
      'true', 'false',
    ]  # :nodoc:
    
    PREDEFINED_FUNCTIONS = %w[
      append cap close complex copy delete imag len
      make new panic print println real recover
    ] # :nodoc:
    
    IDENT_KIND = WordList.new(:ident).
      add(KEYWORDS, :keyword).
      add(PREDEFINED_TYPES, :predefined_type).
      add(PREDEFINED_CONSTANTS, :predefined_constant).
      add(PREDEFINED_FUNCTIONS, :predefined)  # :nodoc:
    
    ESCAPE = / [rbfntv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x  # :nodoc:
    UNICODE_ESCAPE = / u[a-fA-F0-9]{4} | U[a-fA-F0-9]{8} /x  # :nodoc:
    
    protected
    
    def scan_tokens encoder, options
      
      state = :initial
      label_expected = true
      case_expected = false
      label_expected_before_preproc_line = nil
      in_preproc_line = false
      
      until eos?
        
        case state
        
        when :initial
          
          if match = scan(/ \s+ | \\\n /x)
            if in_preproc_line && match != "\\\n" && match.index(?\n)
              in_preproc_line = false
              case_expected = false
              label_expected = label_expected_before_preproc_line
            end
            encoder.text_token match, :space
          
          elsif match = scan(%r! // [^\n\\]* (?: \\. [^\n\\]* )* | /\* (?: .*? \*/ | .* ) !mx)
            encoder.text_token match, :comment
          
          elsif match = scan(/ <?- (?![\d.]) | [+*=<>?:;,!&^|()\[\]{}~%]+ | \/=? | \.(?!\d) /x)
            if case_expected
              label_expected = true if match == ':'
              case_expected = false
            end
            encoder.text_token match, :operator
          
          elsif match = scan(/ [A-Za-z_][A-Za-z_0-9]* /x)
            kind = IDENT_KIND[match]
            if kind == :ident && label_expected && !in_preproc_line && scan(/:(?!:)/)
              kind = :label
              label_expected = false
              match << matched
            else
              label_expected = false
              if kind == :keyword
                case match
                when 'case', 'default'
                  case_expected = true
                end
              end
            end
            encoder.text_token match, kind
          
          elsif match = scan(/L?"/)
            encoder.begin_group :string
            if match[0] == ?L
              encoder.text_token 'L', :modifier
              match = '"'
            end
            encoder.text_token match, :delimiter
            state = :string
          
          elsif match = scan(/ ` ([^`]+)? (`)? /x)
            encoder.begin_group :shell
            encoder.text_token '`', :delimiter
            encoder.text_token self[1], :content if self[1]
            encoder.text_token self[2], :delimiter if self[2]
            encoder.end_group :shell
          
          elsif match = scan(/ \# \s* if \s* 0 /x)
            match << scan_until(/ ^\# (?:elif|else|endif) .*? $ | \z /xm) unless eos?
            encoder.text_token match, :comment
          
          elsif match = scan(/#[ \t]*(\w*)/)
            encoder.text_token match, :preprocessor
            in_preproc_line = true
            label_expected_before_preproc_line = label_expected
            state = :include_expected if self[1] == 'include'
          
          elsif match = scan(/ L?' (?: [^\'\n\\] | \\ (?: #{ESCAPE} | #{UNICODE_ESCAPE} ) )? '? /ox)
            label_expected = false
            encoder.text_token match, :char
          
          elsif match = scan(/\$/)
            encoder.text_token match, :ident
          
          elsif match = scan(/-?\d*(\.\d*)?([eE][+-]?\d+)?i/)
            label_expected = false
            encoder.text_token match, :imaginary
          
          elsif match = scan(/-?0[xX][0-9A-Fa-f]+/)
            label_expected = false
            encoder.text_token match, :hex
          
          elsif match = scan(/-?(?:0[0-7]+)(?![89.eEfF])/)
            label_expected = false
            encoder.text_token match, :octal
          
          elsif match = scan(/-?(?:\d*\.\d+|\d+\.)(?:[eE][+-]?\d+)?|\d+[eE][+-]?\d+/)
            label_expected = false
            encoder.text_token match, :float
          
          elsif match = scan(/-?(?:\d+)(?![.eEfF])L?L?/)
            label_expected = false
            encoder.text_token match, :integer
          
          else
            encoder.text_token getch, :error
          
          end
        
        when :string
          if match = scan(/[^\\\n"]+/)
            encoder.text_token match, :content
          elsif match = scan(/"/)
            encoder.text_token match, :delimiter
            encoder.end_group :string
            state = :initial
            label_expected = false
          elsif match = scan(/ \\ (?: #{ESCAPE} | #{UNICODE_ESCAPE} ) /mox)
            encoder.text_token match, :char
          elsif match = scan(/ \\ /x)
            encoder.text_token match, :error
          elsif match = scan(/$/)
            encoder.end_group :string
            state = :initial
            label_expected = false
          else
            raise_inspect "else case \" reached; %p not handled." % peek(1), encoder
          end
        
        when :include_expected
          if match = scan(/<[^>\n]+>?|"[^"\n\\]*(?:\\.[^"\n\\]*)*"?/)
            encoder.text_token match, :include
            state = :initial
          
          elsif match = scan(/\s+/)
            encoder.text_token match, :space
            state = :initial if match.index ?\n
          
          else
            state = :initial
          
          end
        
        else
          raise_inspect 'Unknown state', encoder
        
        end
        
      end
      
      if state == :string
        encoder.end_group :string
      end
      
      encoder
    end
    
  end
  
end
end