Class: CodeRay::Scanners::SQL

### Home Classes Methods

### In Files

- lib/coderay/scanners/sql.rb

### Parent

CodeRay::Scanners::Scanner

### Methods

- #scan_tokens

### 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::SQL

by Josh Goebel

### Constants

COMMANDS
DIRECTIVES
ESCAPE
IDENT_KIND
KEYWORDS
OBJECTS
PREDEFINED_CONSTANTS
PREDEFINED_FUNCTIONS
PREDEFINED_TYPES
STRING_PREFIXES
UNICODE_ESCAPE

### Public Instance Methods

scan_tokens(encoder, options) click to toggle source

    # File lib/coderay/scanners/sql.rb, line 60
    def scan_tokens encoder, options

      state = :initial
      string_type = nil
      string_content = ''
      name_expected = false

      until eos?

        if state == :initial

          if match = scan(/ \s+ | \\\n /)
            encoder.text_token match, :space

          elsif match = scan(/(?:--\s?|#).*/)
            encoder.text_token match, :comment

          elsif match = scan(%( /\* (!)? (?: .*? \*/ | .* ) )x)
            encoder.text_token match, self[1] ? :directive : :comment

          elsif match = scan(/ [*\/=<>:;,!&^|()\[\]{}~%] | [-+\.](?!\d) /)
            name_expected = true if match == '.' && check(/[A-Za-z_]/)
            encoder.text_token match, :operator

          elsif match = scan(/(#{STRING_PREFIXES})?([`"'])/)
            prefix = self[1]
            string_type = self[2]
            encoder.begin_group :string
            encoder.text_token prefix, :modifier if prefix
            match = string_type
            state = :string
            encoder.text_token match, :delimiter

          elsif match = scan(/ @? [A-Za-z_][A-Za-z_0-9]* /)
            encoder.text_token match, name_expected ? :ident : (match[0] == @@ ? :variable : IDENT_KIND[match])
            name_expected = false

          elsif 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+)(?![.eEfF])/)
            encoder.text_token match, :integer

          elsif match = scan(/[-+]?(?:\d[fF]|\d*\.\d+(?:[eE][+-]?\d+)?|\d+[eE][+-]?\d+)/)
            encoder.text_token match, :float

          elsif match = scan(/\\N/)
            encoder.text_token match, :predefined_constant

          else
            encoder.text_token getch, :error

          end

        elsif state == :string
          if match = scan(/[^\\"'`]+/)
            string_content << match
            next
          elsif match = scan(/["'`]/)
            if string_type == match
              if peek(1) == string_type  # doubling means escape
                string_content << string_type << getch
                next
              end
              unless string_content.empty?
                encoder.text_token string_content, :content
                string_content = ''
              end
              encoder.text_token match, :delimiter
              encoder.end_group :string
              state = :initial
              string_type = nil
            else
              string_content << match
            end
          elsif match = scan(/ \\ (?: #{ESCAPE} | #{UNICODE_ESCAPE} ) /ox)
            unless string_content.empty?
              encoder.text_token string_content, :content
              string_content = ''
            end
            encoder.text_token match, :char
          elsif match = scan(/ \\ . /ox)
            string_content << match
            next
          elsif match = scan(/ \\ | $ /)
            unless string_content.empty?
              encoder.text_token string_content, :content
              string_content = ''
            end
            encoder.text_token match, :error unless match.empty?
            encoder.end_group :string
            state = :initial
          else
            raise "else case \" reached; %p not handled." % peek(1), encoder
          end

        else
          raise 'else-case reached', encoder

        end

      end

      if state == :string
        encoder.end_group state
      end

      encoder

    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.