Class: CodeRay::WordList

### Home Classes Methods

### In Files

- lib/coderay/helpers/word_list.rb

### Parent

Hash

### Namespace

- CLASS CodeRay::WordList::CaseIgnoring

### Methods

- ::new
- #add

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

# WordList

A Hash subclass designed for mapping word lists to token types.

A WordList is a Hash with some additional features. It is intended to be used for keyword recognition.

WordList is optimized to be used in Scanners, typically to decide whether a given ident is a special token.

For case insensitive words use WordList::CaseIgnoring.

Example:

    # define word arrays
    RESERVED_WORDS = %w[
      asm break case continue default do else
    ]

    PREDEFINED_TYPES = %w[
      int long short char void
    ]

    # make a WordList
    IDENT_KIND = WordList.new(:ident).
      add(RESERVED_WORDS, :reserved).
      add(PREDEFINED_TYPES, :predefined_type)

    ...

    def scan_tokens tokens, options
      ...

      elsif scan(/[A-Za-z_][A-Za-z_0-9]*/)
        # use it
        kind = IDENT_KIND[match]
        ...

### Public Class Methods

new(default = false) click to toggle source

Create a new WordList with `default` as default value.

    # File lib/coderay/helpers/word_list.rb, line 43
    def initialize default = false
      super default
    end

### Public Instance Methods

add(words, value = true) click to toggle source

Add words to the list and associate them with `value`.

Returns `self`, so you can concat add calls.

    # File lib/coderay/helpers/word_list.rb, line 50
    def add words, value = true
      words.each { |word| self[word] = value }
      self
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.